Skip to content

Commit

Permalink
SporeModManager: improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed Jan 24, 2024
1 parent 08482a9 commit 5bf3ded
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 34 deletions.
10 changes: 5 additions & 5 deletions SporeModManager/SporeModManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static bool get_installedsporemodlist(void)
{
if (!SporeMod::Xml::GetInstalledModList(l_InstalledSporeMods))
{
std::cerr << "Error: SporeMod::Xml::GetInstalledMostList() Failed!" << std::endl;
std::cerr << "Error: failed to retrieve installed mod list!" << std::endl;
return false;
}
l_HasInstalledSporeMods = true;
Expand All @@ -53,7 +53,7 @@ static bool save_installedsporemodlist(void)
{
if (!SporeMod::Xml::SaveInstalledModList(l_InstalledSporeMods))
{
std::cerr << "Error: SporeMod::Xml::SaveInstalledModList() Failed!" << std::endl;
std::cerr << "Error: failed to save installed mod list!" << std::endl;
return false;
}
}
Expand All @@ -69,7 +69,7 @@ static bool get_sporemodinfo(const std::filesystem::path& path, const std::strin
{
if (!Zip::OpenFile(zipFile, path))
{
std::cerr << "Error: Zip::OpenFile() Failed!" << std::endl;
std::cerr << "Error: failed to open zip file!" << std::endl;
return false;
}

Expand All @@ -83,14 +83,14 @@ static bool get_sporemodinfo(const std::filesystem::path& path, const std::strin
{ // has modinfo.xml
if (!Zip::ExtractFile(zipFile, "", modInfoFileBuffer))
{
std::cerr << "Error: Zip::ExtractFile() Failed!" << std::endl;
std::cerr << "Error: failed to extract ModInfo.xml from zip file!" << std::endl;
Zip::CloseFile(zipFile);
return false;
}

if (!SporeMod::Xml::ParseSporeModInfo(modInfoFileBuffer, sporeModInfo))
{
std::cerr << "Error: SporeMod::Xml::ParseSporeModInfo() Failed!" << std::endl;
std::cerr << "Error: failed to parse ModInfo.xml!" << std::endl;
Zip::CloseFile(zipFile);
return false;
}
Expand Down
12 changes: 6 additions & 6 deletions SporeModManager/SporeModManagerHelpers/FileVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bool FileVersion::GetCoreLibFileVersionInfo(FileVersionInfo& fileVersionInfo)

if (!FileVersion::ParseFile(coreLibPath, fileVersionInfo))
{
std::cerr << "Error: FileVersion::ParseFile() Failed!" << std::endl;
std::cerr << "Error: failed to parse file version!" << std::endl;
return false;
}

Expand All @@ -64,13 +64,13 @@ bool FileVersion::CheckIfCoreLibMatchesVersion(FileVersionInfo& modFileVersionIn

if (!GetCoreLibFileVersionInfo(coreLibFileVersionInfo))
{
std::cerr << "Error: FileVersion::GetCoreLibFileVersionInfo() Failed!" << std::endl;
std::cerr << "Error: failed to retrieve SporeModAPI.dll version!" << std::endl;
return false;
}

if (modFileVersionInfo > coreLibFileVersionInfo)
{
std::cerr << "Error: \"" << modName << "\" requires newer Spore ModAPI DLL (\"" << modFileVersionInfo.to_string() <<
std::cerr << "Error: \"" << modName << "\" requires newer SporeModAPI.dll (\"" << modFileVersionInfo.to_string() <<
"\") than what's currently installed (\"" << coreLibFileVersionInfo.to_string() << "\")" << std::endl;
return false;
}
Expand Down Expand Up @@ -122,7 +122,7 @@ bool FileVersion::ParseFile(std::filesystem::path path, FileVersionInfo& fileVer
fileStream.open(path, std::ios_base::in | std::ios_base::binary);
if (!fileStream.is_open())
{
std::cerr << "Error: fileStream.open() Failed!" << std::endl;
std::cerr << "Error: failed to open " << path << std::endl;
return false;
}

Expand All @@ -143,7 +143,7 @@ bool FileVersion::ParseFile(std::filesystem::path path, FileVersionInfo& fileVer

if (fileStream.fail())
{
std::cerr << "Error: fileStream.fail()!" << std::endl;
std::cerr << "Error: failed to read data from " << path << std::endl;
return false;
}

Expand All @@ -157,7 +157,7 @@ bool FileVersion::ParseFile(std::filesystem::path path, FileVersionInfo& fileVer
auto bufferIter = std::search(buffer.begin(), buffer.end(), searchBytes.begin(), searchBytes.end());
if (bufferIter == buffer.end())
{
std::cout << "Error: std::search() didn't find the required bytes!" << std::endl;
std::cout << "Error: failed to find file version bytes!" << std::endl;
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions SporeModManager/SporeModManagerHelpers/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool Path::CheckIfPathsExist(void)

if (!SporeMod::Xml::GetDirectories(coreLibsPath, modLibsPath, galacticAdventuresDataPath, coreSporeDataPath))
{
std::cerr << "Error: SporeMod::Xml::GetDirectories() Failed!" << std::endl;
std::cerr << "Error: failed to retrieve directories from configuration file!" << std::endl;
return false;
}

Expand Down Expand Up @@ -155,7 +155,7 @@ std::filesystem::path Path::GetCurrentExecutablePath(void)

if (GetModuleFileNameW(nullptr, currentExecutablePathBuf, MAX_PATH) == 0)
{ // fallback to current path
std::cerr << "Error: GetModuleFileNameW() Failed!" << std::endl;
std::cerr << "Error: failed to retrieve path of current executable!" << std::endl;
std::exit(1);
}

Expand Down
4 changes: 2 additions & 2 deletions SporeModManager/SporeModManagerHelpers/SporeMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ bool SporeMod::ConfigureSporeMod(Zip::ZipFile zipFile, const Xml::SporeModInfo&

if (!Zip::GetFileList(zipFile, zipFileList))
{
std::cerr << "Zip::GetFileList() Failed!" << std::endl;
std::cerr << "Error: failed to retrieve file list from zip file!" << std::endl;
return false;
}

Expand Down Expand Up @@ -319,7 +319,7 @@ bool SporeMod::InstallSporeMod(Zip::ZipFile zipFile, const Xml::InstalledSporeMo

if (!Zip::ExtractFile(zipFile, sourcePath, installPath))
{
std::cerr << "Error: Zip::ExtractFile() Failed!" << std::endl;
std::cerr << "Error: failed to extract file from zip file!" << std::endl;
// cleanup installed files that were left over
for (const auto& installedFileToRemove : installedSporeMod.InstalledFiles)
{
Expand Down
22 changes: 11 additions & 11 deletions SporeModManager/SporeModManagerHelpers/SporeModXml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,14 @@ bool SporeMod::Xml::ParseSporeModInfo(const std::vector<char>& buffer, SporeModI
error = xmlDocument.Parse(buffer.data(), buffer.size());
if (error != tinyxml2::XMLError::XML_SUCCESS)
{
std::cerr << "Error: XmlDocument.Parse() Failed!" << std::endl;
std::cerr << "Error: failed to parse XML: " << xmlDocument.ErrorName() << std::endl;
return false;
}

xmlElement = xmlDocument.RootElement();
if (xmlElement == nullptr)
{
std::cerr << "Error: XMLDocument.RootElement() Failed!" << std::endl;
std::cerr << "Error: failed to retrieve root element from XML: " << xmlDocument.ErrorName() << std::endl;
return false;
}

Expand All @@ -312,7 +312,7 @@ bool SporeMod::Xml::ParseSporeModInfo(const std::vector<char>& buffer, SporeModI
ret = FileVersion::ParseString(xmlAttributeText, sporeModInfo.InstallerVersion);
if (!ret)
{
std::cerr << "Error: FileVersion::ParseString() Failed!" << std::endl;
std::cerr << "Error: failed to parse installerSystemVersion attribute!" << std::endl;
return false;
}
else
Expand Down Expand Up @@ -342,7 +342,7 @@ bool SporeMod::Xml::ParseSporeModInfo(const std::vector<char>& buffer, SporeModI
ret = FileVersion::ParseString(xmlAttributeText, sporeModInfo.MinimumModAPILibVersion);
if (!ret)
{
std::cerr << "Error: FileVersion::ParseString() Failed!" << std::endl;
std::cerr << "Error: failed to parse dllsBuild attribute!" << std::endl;
return false;
}
}
Expand Down Expand Up @@ -392,22 +392,22 @@ bool SporeMod::Xml::GetDirectories(std::filesystem::path& coreLibsPath, std::fil
Path::Combine({ "..", "..", "DataEP1" }),
Path::Combine({ "..", "..", "Data" })))
{
std::cerr << "Error: Xml::SaveDirectories() Failed!" << std::endl;
std::cerr << "Error: failed to save configuration file!" << std::endl;
return false;
}
}

error = xmlDocument.LoadFile(configFilePath.string().c_str());
if (error != tinyxml2::XMLError::XML_SUCCESS)
{
std::cerr << "Error: XmlDocument.LoadFile() Failed!" << std::endl;
std::cerr << "Error: failed to load XML file: " << xmlDocument.ErrorName() << std::endl;
return false;
}

xmlElement = xmlDocument.RootElement();
if (xmlElement == nullptr)
{
std::cerr << "Error: XMLDocument.RootElement() Failed!" << std::endl;
std::cerr << "Error: failed to retrieve root element from XML: " << xmlDocument.ErrorName() << std::endl;
return false;
}

Expand Down Expand Up @@ -486,7 +486,7 @@ bool SporeMod::Xml::SaveDirectories(std::filesystem::path coreLibsPath, std::fil
xmlElement = xmlDocument.RootElement();
if (xmlElement == nullptr)
{
std::cerr << "Error: XMLDocument.RootElement() Failed!" << std::endl;
std::cerr << "Error: failed to retrieve root element from XML: " << xmlDocument.ErrorName() << std::endl;
return false;
}

Expand Down Expand Up @@ -547,14 +547,14 @@ bool SporeMod::Xml::GetInstalledModList(std::vector<InstalledSporeMod>& installe
error = xmlDocument.LoadFile(configFilePath.string().c_str());
if (error != tinyxml2::XMLError::XML_SUCCESS)
{
std::cerr << "Error: XmlDocument.LoadFile() Failed!" << std::endl;
std::cerr << "Error: failed to load XML file: " << xmlDocument.ErrorName() << std::endl;
return false;
}

xmlElement = xmlDocument.RootElement();
if (xmlElement == nullptr)
{
std::cerr << "Error: XMLDocument.RootElement() Failed!" << std::endl;
std::cerr << "Error: failed to retrieve root element from XML: " << xmlDocument.ErrorName() << std::endl;
return false;
}

Expand Down Expand Up @@ -608,7 +608,7 @@ bool SporeMod::Xml::SaveInstalledModList(const std::vector<InstalledSporeMod>& i
error = xmlDocument.LoadFile(configFilePath.string().c_str());
if (error != tinyxml2::XMLError::XML_SUCCESS)
{
std::cerr << "Error: XmlDocument.LoadFile() Failed!" << std::endl;
std::cerr << "Error: failed to load XML file: " << xmlDocument.ErrorName() << std::endl;
return false;
}

Expand Down
14 changes: 7 additions & 7 deletions SporeModManager/SporeModManagerHelpers/Zip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ bool Zip::GetFileList(ZipFile zipFile, std::vector<std::filesystem::path>& fileL
ret = unzGetGlobalInfo64(zipFile, &zipInfo);
if (ret != UNZ_OK)
{
std::cerr << "Error: unzGetGlobalInfo64() Failed: " << ret << std::endl;
std::cerr << "Error: failed to retrieve zip file info: " << ret << std::endl;
return false;
}

Expand Down Expand Up @@ -181,7 +181,7 @@ bool Zip::GetFileList(ZipFile zipFile, std::vector<std::filesystem::path>& fileL
ret = unzGoToNextFile(zipFile);
if (ret != UNZ_OK)
{
std::cerr << "Error: unzGoToNextFile() Failed: " << ret << std::endl;
std::cerr << "Error: failed to advance to next file in zip file: " << ret << std::endl;
return false;
}
}
Expand All @@ -207,14 +207,14 @@ bool Zip::ExtractFile(ZipFile zipFile, std::filesystem::path file, std::filesyst
outputFileStream.open(outputFile, std::ofstream::trunc | std::ofstream::binary);
if (!outputFileStream.is_open())
{
std::cerr << "Error: ofstream.open() Failed!" << std::endl;
std::cerr << "Error: failed to open " << outputFile << std::endl;
return false;
}

bytesRead = unzOpenCurrentFile(zipFile);
if (bytesRead != UNZ_OK)
{
std::cerr << "Error: unzOpenCurrentFile() Failed: " << bytesRead << std::endl;
std::cerr << "Error: failed to open file in zip file: " << bytesRead << std::endl;
return false;
}

Expand All @@ -224,7 +224,7 @@ bool Zip::ExtractFile(ZipFile zipFile, std::filesystem::path file, std::filesyst
if (bytesRead < 0)
{
unzCloseCurrentFile(zipFile);
std::cerr << "Error: unzReadCurrentFile() Failed: " << bytesRead << std::endl;
std::cerr << "Error: failed to read data from file in zip file: " << bytesRead << std::endl;
return false;
}
else if (bytesRead > 0)
Expand Down Expand Up @@ -258,7 +258,7 @@ bool Zip::ExtractFile(ZipFile zipFile, std::filesystem::path file, std::vector<c
bytesRead = unzOpenCurrentFile(zipFile);
if (bytesRead != UNZ_OK)
{
std::cerr << "Error: unzOpenCurrentFile() Failed: " << bytesRead << std::endl;
std::cerr << "Error: failed to open file in zip file: " << bytesRead << std::endl;
return false;
}

Expand All @@ -268,7 +268,7 @@ bool Zip::ExtractFile(ZipFile zipFile, std::filesystem::path file, std::vector<c
if (bytesRead < 0)
{
unzCloseCurrentFile(zipFile);
std::cerr << "Error: unzReadCurrentFile() Failed: " << bytesRead << std::endl;
std::cerr << "Error: failed to read data from file in zip file: " << bytesRead << std::endl;
return false;
}
else if (bytesRead > 0)
Expand Down
2 changes: 1 addition & 1 deletion SporeModManager/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ int main(int argc, char** argv)
{
if (!SporeMod::Xml::SaveDirectories(coreLibsPath, modLibsPath, ep1Path, dataPath))
{
std::cerr << "Error: SporeMod::Xml::SaveDirectories() Failed!" << std::endl;
std::cerr << "Error: failed to save directories to configuration file!" << std::endl;
return 1;
}
}
Expand Down

0 comments on commit 5bf3ded

Please sign in to comment.