From b98ad13cbc93cb5e05f7675cdd53345788c1a123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henri=20Hyyryl=C3=A4inen?= Date: Mon, 11 May 2020 10:31:56 +0300 Subject: [PATCH] Fixed pck file path generation on Windows now when using wine on Linux the Windows version can make pck files from scratch that Godot can load --- CMakeLists.txt | 2 +- src/pck/PckFile.cpp | 11 ++++++++++- src/pck/PckFile.h | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03397dd..05e0b4f 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 1) +set(GODOT_PCK_TOOL_VERSION_MINOR 2) 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 9c81704..b7e33cf 100644 --- a/src/pck/PckFile.cpp +++ b/src/pck/PckFile.cpp @@ -213,8 +213,11 @@ bool PckFile::AddFilesFromFilesystem(const std::string& path, const std::string& return true; } -void PckFile::AddSingleFile(const std::string& filesystemPath, const std::string& pckPath) +void PckFile::AddSingleFile(const std::string& filesystemPath, std::string pckPath) { + if(pckPath.empty()) + throw std::runtime_error("path inside pck is empty to add file to"); + std::cout << "Adding " << filesystemPath << " as " << pckPath << "\n"; ContainedFile file; @@ -253,6 +256,12 @@ std::string PckFile::PreparePckPath(std::string path, const std::string& stripPr path = path.substr(stripPrefix.size()); } + // Fix Windows paths to make this work on Windows + for(size_t i = 0; i < path.size(); ++i) { + if(path[i] == '\\') + path[i] = '/'; + } + while(path.size() > 0 && path.front() == '/') { path.erase(path.begin()); } diff --git a/src/pck/PckFile.h b/src/pck/PckFile.h index 82cd0ae..b928999 100644 --- a/src/pck/PckFile.h +++ b/src/pck/PckFile.h @@ -54,8 +54,9 @@ class PckFile { //! \brief Adds recursively files from path to this pck bool AddFilesFromFilesystem(const std::string& path, const std::string& stripPrefix); - void AddSingleFile(const std::string& filesystemPath, const std::string& pckPath); + void AddSingleFile(const std::string& filesystemPath, std::string pckPath); + //! \note Automatically converts \'s in the path to /'s std::string PreparePckPath(std::string path, const std::string& stripPrefix); void ChangePath(const std::string& path);