From cfdbdb4ef18089453d3d7b21f28999c869e4b27f Mon Sep 17 00:00:00 2001 From: Kenix3 Date: Fri, 17 Nov 2023 09:40:10 -0500 Subject: SWrapper error handling improvements. (#16) --- src/storm/SWrapper.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/storm/SWrapper.cpp b/src/storm/SWrapper.cpp index fbb2329..8ab1b68 100644 --- a/src/storm/SWrapper.cpp +++ b/src/storm/SWrapper.cpp @@ -14,8 +14,7 @@ SWrapper::SWrapper(const std::string& path) { } if(!SFileCreateArchive(path.c_str(), MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES | MPQ_CREATE_ARCHIVE_V2, 4096, &this->hMpq)){ - std::cout << "Failed to create archive: " << path << std::endl; - std::cout << GetLastError() << std::endl; + SPDLOG_ERROR("Failed to create archive {} with error code {}", path, GetLastError()); return; } } @@ -48,30 +47,28 @@ bool SWrapper::CreateFile(const std::string& path, std::vector data) { size_t size = data.size(); if(size == 0){ + SPDLOG_ERROR("File at path {} is empty", path); std::cout << "File empty: " << path << std::endl; return false; } if(size >> 32){ - std::cout << "File too large: " << path << std::endl; + SPDLOG_ERROR("File at path {} is too large with size {}", path, size); return false; } if(!SFileCreateFile(this->hMpq, path.c_str(), theTime, size, 0, MPQ_FILE_COMPRESS, &hFile)){ - std::cout << "Failed to create file: " << path << std::endl; - std::cout << GetLastError() << std::endl; + SPDLOG_ERROR("Failed to create file at path {} with error {}", path, GetLastError()); return false; } if(!SFileWriteFile(hFile, (void*) raw, size, MPQ_COMPRESSION_ZLIB)){ - std::cout << "Failed to write file: " << path << std::endl; - std::cout << GetLastError() << std::endl; + SPDLOG_ERROR("Failed to write file at path {} with error {}", path, GetLastError()); return false; } if(!SFileCloseFile(hFile)){ - std::cout << "Failed to close file: " << path << std::endl; - std::cout << GetLastError() << std::endl; + SPDLOG_ERROR("Failed to close file at path {} with error {}", path, GetLastError()); return false; } @@ -80,7 +77,7 @@ bool SWrapper::CreateFile(const std::string& path, std::vector data) { void SWrapper::Close() { if(this->hMpq == nullptr) { - std::cout << "Archive already closed" << std::endl; + SPDLOG_ERROR("Archive already closed"); return; } SFileCloseArchive(this->hMpq); -- cgit v1.2.3