From e870f8efe6d400a3d26da8f00cea190e33d51c16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henri=20Hyyryl=C3=A4inen?= Date: Mon, 11 May 2020 10:08:49 +0300 Subject: [PATCH] Fixed reading not being in binary mode --- CMakeLists.txt | 2 +- src/pck/PckFile.cpp | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d9f3c9..03397dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.10) project(GodotPckTool) set(GODOT_PCK_TOOL_VERSION_MAJOR 1) -set(GODOT_PCK_TOOL_VERSION_MINOR 0) +set(GODOT_PCK_TOOL_VERSION_MINOR 1) set(GODOT_PCK_TOOL_VERSION_STR "${GODOT_PCK_TOOL_VERSION_MAJOR}.${GODOT_PCK_TOOL_VERSION_MINOR}") diff --git a/src/pck/PckFile.cpp b/src/pck/PckFile.cpp index a1f8283..9c81704 100644 --- a/src/pck/PckFile.cpp +++ b/src/pck/PckFile.cpp @@ -12,7 +12,7 @@ bool PckFile::Load() { Contents.clear(); - File = std::fstream(Path, std::ios::in); + File = std::fstream(Path, std::ios::in | std::ios::binary); if(!File->good()) { std::cout << "ERROR: file is unreadable: " << Path << "\n"; @@ -22,9 +22,9 @@ bool PckFile::Load() File->exceptions(std::ifstream::failbit | std::ifstream::badbit); // Separate reader to make writing work - DataReader = std::ifstream(Path, std::ios::in); + DataReader = std::ifstream(Path, std::ios::in | std::ios::binary); - if(!DataReader.has_value() || !DataReader) + if(!DataReader || !DataReader->good()) throw std::runtime_error("second data reader opening failed"); uint32_t magic = Read32(); @@ -85,7 +85,7 @@ bool PckFile::Save() { const auto tmpWrite = Path + ".write"; - File = std::fstream(tmpWrite, std::ios::trunc | std::ios::out); + File = std::fstream(tmpWrite, std::ios::trunc | std::ios::out | std::ios::binary); if(!File->good()) { std::cout << "ERROR: file is unwriteable: " << tmpWrite << "\n"; @@ -229,7 +229,7 @@ void PckFile::AddSingleFile(const std::string& filesystemPath, const std::string // file.MD5 = {0}; file.GetData = [filesystemPath, size]() { - std::ifstream reader(filesystemPath, std::ios::in); + std::ifstream reader(filesystemPath, std::ios::in | std::ios::binary); if(!reader.good()) { std::cout << "ERROR: opening for reading: " << filesystemPath << "\n"; @@ -299,7 +299,8 @@ bool PckFile::Extract(const std::string& outputPrefix) return false; } - std::ofstream writer(targetFile.string(), std::ios::trunc | std::ios::out); + std::ofstream writer( + targetFile.string(), std::ios::trunc | std::ios::out | std::ios::binary); if(!writer.good()) { std::cout << "ERROR: opening file for writing: " << targetFile << "\n";