Skip to content

Commit

Permalink
Fixed reading not being in binary mode
Browse files Browse the repository at this point in the history
  • Loading branch information
hhyyrylainen committed May 11, 2020
1 parent 8fd8380 commit e870f8e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down
13 changes: 7 additions & 6 deletions src/pck/PckFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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();
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit e870f8e

Please sign in to comment.