From 61141c09e807b6a36636baa515af81fa2ec7d025 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 10 Apr 2024 17:04:49 -0400 Subject: [PATCH] Added custom hash for filesystem path strings --- tools/dkr_assets_tool_src/helpers/fileHelper.cpp | 2 +- tools/dkr_assets_tool_src/helpers/fileHelper.h | 9 ++++++++- .../dkr_assets_tool_src/prebuild/compileAssets/compile.h | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/dkr_assets_tool_src/helpers/fileHelper.cpp b/tools/dkr_assets_tool_src/helpers/fileHelper.cpp index e3efeeab..32d6cd89 100644 --- a/tools/dkr_assets_tool_src/helpers/fileHelper.cpp +++ b/tools/dkr_assets_tool_src/helpers/fileHelper.cpp @@ -373,7 +373,7 @@ std::string FileHelper::get_last_modified_timestamp(const fs::path &path) { return out; } -void FileHelper::insert_timestamps_from_directory(const fs::path &dirPath, std::unordered_map ×tamps) { +void FileHelper::insert_timestamps_from_directory(const fs::path &dirPath, std::unordered_map ×tamps) { // TODO: Make this multithreaded? for (const auto &filepath : fs::recursive_directory_iterator(dirPath)) { timestamps[filepath] = get_last_modified_timestamp(filepath); diff --git a/tools/dkr_assets_tool_src/helpers/fileHelper.h b/tools/dkr_assets_tool_src/helpers/fileHelper.h index 2c75cb1b..7f411adb 100644 --- a/tools/dkr_assets_tool_src/helpers/fileHelper.h +++ b/tools/dkr_assets_tool_src/helpers/fileHelper.h @@ -12,6 +12,13 @@ #include namespace fs = std::filesystem; +// Using path as a key doesn't seem to work on raspberry pi OS? +struct PathHash { + std::size_t operator()(const std::filesystem::__cxx11::path& p) const { + return std::filesystem::hash_value(p); + } +}; + class FileHelper { public: static std::vector read_binary_file(const fs::path &filename); @@ -60,7 +67,7 @@ public: static void endianswap(std::vector &bytes); static std::string get_last_modified_timestamp(const fs::path &path); - static void insert_timestamps_from_directory(const fs::path &dirPath, std::unordered_map ×tamps); + static void insert_timestamps_from_directory(const fs::path &dirPath, std::unordered_map ×tamps); private: }; diff --git a/tools/dkr_assets_tool_src/prebuild/compileAssets/compile.h b/tools/dkr_assets_tool_src/prebuild/compileAssets/compile.h index a485441a..e8017d5b 100644 --- a/tools/dkr_assets_tool_src/prebuild/compileAssets/compile.h +++ b/tools/dkr_assets_tool_src/prebuild/compileAssets/compile.h @@ -20,8 +20,8 @@ private: JsonFile *_modOrderFile; size_t _modOrderCount; - std::unordered_map _lastModifiedDates; - std::unordered_map> _modFiles; + std::unordered_map _lastModifiedDates; + std::unordered_map, PathHash> _modFiles; std::vector _modFilesModified; void _check_mod_path(fs::path &modPath);