summaryrefslogtreecommitdiff
path: root/src/archive/SWrapper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/archive/SWrapper.cpp')
-rw-r--r--src/archive/SWrapper.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/archive/SWrapper.cpp b/src/archive/SWrapper.cpp
index fab0caf..951b21f 100644
--- a/src/archive/SWrapper.cpp
+++ b/src/archive/SWrapper.cpp
@@ -16,11 +16,12 @@ int32_t SWrapper::CreateArchive() {
#ifndef USE_STORMLIB
throw std::runtime_error("StormLib is not enabled. Cannot create archive");
#else
- if(fs::exists(mPath)) {
+ if (fs::exists(mPath)) {
fs::remove(mPath);
}
- if(!SFileCreateArchive(mPath.c_str(), MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES | MPQ_CREATE_ARCHIVE_V2, 16 * 1024, &this->hMpq)){
+ if (!SFileCreateArchive(mPath.c_str(), MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES | MPQ_CREATE_ARCHIVE_V2,
+ 16 * 1024, &this->hMpq)) {
SPDLOG_ERROR("Failed to create archive {} with error code {}", mPath, GetLastError());
return -1;
}
@@ -33,10 +34,10 @@ bool SWrapper::AddFile(const std::string& path, std::vector<char> data) {
#ifndef USE_STORMLIB
throw std::runtime_error("StormLib is not enabled. Cannot create file");
#else
- if(Companion::Instance != nullptr && Companion::Instance->IsDebug()){
+ if (Companion::Instance != nullptr && Companion::Instance->IsDebug()) {
SPDLOG_INFO("Creating debug file: debug/{}", path);
std::string dpath = "debug/" + path;
- if(!fs::exists(fs::path(dpath).parent_path())){
+ if (!fs::exists(fs::path(dpath).parent_path())) {
fs::create_directories(fs::path(dpath).parent_path());
}
std::ofstream stream(dpath, std::ios::binary);
@@ -59,25 +60,27 @@ bool SWrapper::AddFile(const std::string& path, std::vector<char> data) {
char* raw = data.data();
size_t size = data.size();
- if(size == 0){
+ if (size == 0) {
SPDLOG_ERROR("File at path {} is empty", path);
return false;
}
- if(size >> 32){
+ if (size >> 32) {
throw std::runtime_error("File at path " + path + " is too large with size " + std::to_string(size));
}
- if(!SFileCreateFile(this->hMpq, path.c_str(), theTime, size, 0, MPQ_FILE_COMPRESS, &hFile)){
+ if (!SFileCreateFile(this->hMpq, path.c_str(), theTime, size, 0, MPQ_FILE_COMPRESS, &hFile)) {
return false;
}
- if(!SFileWriteFile(hFile, (void*) raw, size, MPQ_COMPRESSION_ZLIB)){
- throw std::runtime_error("Failed to write file at path " + path + " with error " + std::to_string(GetLastError()));
+ if (!SFileWriteFile(hFile, (void*)raw, size, MPQ_COMPRESSION_ZLIB)) {
+ throw std::runtime_error("Failed to write file at path " + path + " with error " +
+ std::to_string(GetLastError()));
}
- if(!SFileCloseFile(hFile)){
- throw std::runtime_error("Failed to close file at path " + path + " with error " + std::to_string(GetLastError()));
+ if (!SFileCloseFile(hFile)) {
+ throw std::runtime_error("Failed to close file at path " + path + " with error " +
+ std::to_string(GetLastError()));
}
return true;
@@ -88,7 +91,7 @@ int32_t SWrapper::Close(void) {
#ifndef USE_STORMLIB
throw std::runtime_error("StormLib is not enabled. Cannot close archive");
#else
- if(this->hMpq == nullptr) {
+ if (this->hMpq == nullptr) {
SPDLOG_ERROR("Archive already closed");
return -1;
}