From 5bf3ded81c804f576f9e2656d005b8af04b430e9 Mon Sep 17 00:00:00 2001 From: Rosalie Wanders Date: Wed, 24 Jan 2024 13:31:33 +0100 Subject: [PATCH] SporeModManager: improve error messages --- SporeModManager/SporeModManager.cpp | 10 ++++----- .../SporeModManagerHelpers/FileVersion.cpp | 12 +++++----- .../SporeModManagerHelpers/Path.cpp | 4 ++-- .../SporeModManagerHelpers/SporeMod.cpp | 4 ++-- .../SporeModManagerHelpers/SporeModXml.cpp | 22 +++++++++---------- .../SporeModManagerHelpers/Zip.cpp | 14 ++++++------ SporeModManager/main.cpp | 2 +- 7 files changed, 34 insertions(+), 34 deletions(-) diff --git a/SporeModManager/SporeModManager.cpp b/SporeModManager/SporeModManager.cpp index b939514..19d896d 100644 --- a/SporeModManager/SporeModManager.cpp +++ b/SporeModManager/SporeModManager.cpp @@ -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; @@ -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; } } @@ -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; } @@ -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; } diff --git a/SporeModManager/SporeModManagerHelpers/FileVersion.cpp b/SporeModManager/SporeModManagerHelpers/FileVersion.cpp index dd92bc2..711d6d6 100644 --- a/SporeModManager/SporeModManagerHelpers/FileVersion.cpp +++ b/SporeModManager/SporeModManagerHelpers/FileVersion.cpp @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } diff --git a/SporeModManager/SporeModManagerHelpers/Path.cpp b/SporeModManager/SporeModManagerHelpers/Path.cpp index c9d9ada..389e76c 100644 --- a/SporeModManager/SporeModManagerHelpers/Path.cpp +++ b/SporeModManager/SporeModManagerHelpers/Path.cpp @@ -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; } @@ -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); } diff --git a/SporeModManager/SporeModManagerHelpers/SporeMod.cpp b/SporeModManager/SporeModManagerHelpers/SporeMod.cpp index 51ee2c6..e0e0b1f 100644 --- a/SporeModManager/SporeModManagerHelpers/SporeMod.cpp +++ b/SporeModManager/SporeModManagerHelpers/SporeMod.cpp @@ -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; } @@ -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) { diff --git a/SporeModManager/SporeModManagerHelpers/SporeModXml.cpp b/SporeModManager/SporeModManagerHelpers/SporeModXml.cpp index 58085f0..9f71788 100644 --- a/SporeModManager/SporeModManagerHelpers/SporeModXml.cpp +++ b/SporeModManager/SporeModManagerHelpers/SporeModXml.cpp @@ -285,14 +285,14 @@ bool SporeMod::Xml::ParseSporeModInfo(const std::vector& 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; } @@ -312,7 +312,7 @@ bool SporeMod::Xml::ParseSporeModInfo(const std::vector& 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 @@ -342,7 +342,7 @@ bool SporeMod::Xml::ParseSporeModInfo(const std::vector& 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; } } @@ -392,7 +392,7 @@ 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; } } @@ -400,14 +400,14 @@ bool SporeMod::Xml::GetDirectories(std::filesystem::path& coreLibsPath, std::fil 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; } @@ -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; } @@ -547,14 +547,14 @@ bool SporeMod::Xml::GetInstalledModList(std::vector& 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; } @@ -608,7 +608,7 @@ bool SporeMod::Xml::SaveInstalledModList(const std::vector& 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; } diff --git a/SporeModManager/SporeModManagerHelpers/Zip.cpp b/SporeModManager/SporeModManagerHelpers/Zip.cpp index f97a755..7d5be0c 100644 --- a/SporeModManager/SporeModManagerHelpers/Zip.cpp +++ b/SporeModManager/SporeModManagerHelpers/Zip.cpp @@ -151,7 +151,7 @@ bool Zip::GetFileList(ZipFile zipFile, std::vector& 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; } @@ -181,7 +181,7 @@ bool Zip::GetFileList(ZipFile zipFile, std::vector& 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; } } @@ -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; } @@ -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) @@ -258,7 +258,7 @@ bool Zip::ExtractFile(ZipFile zipFile, std::filesystem::path file, std::vector 0) diff --git a/SporeModManager/main.cpp b/SporeModManager/main.cpp index 6741006..114b1df 100644 --- a/SporeModManager/main.cpp +++ b/SporeModManager/main.cpp @@ -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; } }