From 734ee0f6352fdb6077c142d90f191c11c32f98d2 Mon Sep 17 00:00:00 2001 From: Steph Enders Date: Sun, 26 Jun 2022 21:57:43 -0400 Subject: Alias filesystem library to allow for xp usage MacOS 10.14 still uses experimental/filesystem which is what we're currently targetting. If I can get my hands on a 10.15+ we can test that out --- src/main.cpp | 4 --- src/resources/Resources.cpp | 47 +++++++++++++++--------------------- src/resources/Resources.h | 15 ++++++------ src/resources/macos/MacResources.cpp | 2 +- src/resources/macos/MacResources.h | 16 ++++++------ 5 files changed, 38 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 51722dd..c8d7b2d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,16 +34,12 @@ #include "resources/Resources.h" #ifdef __linux__ #include "resources/linux/LinuxResources.h" -#include #endif // __linux__ #ifdef _WIN32 #include "resources/windows/WindowsResources.h" -#include #endif // _WIN32 #ifdef __APPLE__ #include "resources/macos/MacResources.h" -#include -namespace std::filesystem = std::experimental::filesystem; #endif // __APPLE__ #include #include diff --git a/src/resources/Resources.cpp b/src/resources/Resources.cpp index 3ae93f4..ee43002 100644 --- a/src/resources/Resources.cpp +++ b/src/resources/Resources.cpp @@ -30,18 +30,18 @@ #include Resources::Resources() { - this->font = std::make_shared(); - this->defaultsLua = std::make_shared(); + this->font = std::make_shared(); + this->defaultsLua = std::make_shared(); } void Resources::loadFontFiles() { // We will search 1 level deep for (auto &base : this->fontSearchDirs()) { - if (std::filesystem::exists(base) && std::filesystem::is_directory(base)) { - for (auto &item : std::filesystem::directory_iterator(base)) { + if (fs::exists(base) && fs::is_directory(base)) { + for (auto &item : fs::directory_iterator(base)) { // only 1 deep if (item.exists() && item.is_directory()) { - for (auto &file : std::filesystem::directory_iterator(item)) { + for (auto &file : fs::directory_iterator(item)) { if (file.exists() && file.is_regular_file()) { auto ext = file.path().extension(); bool matched = @@ -84,10 +84,10 @@ void Resources::loadFontFiles() { void Resources::loadLevels() { for (auto &base : this->levelSearchDirs()) { - if (std::filesystem::exists(base) && std::filesystem::is_directory(base)) { - for (auto &dir : std::filesystem::directory_iterator(base)) { + if (fs::exists(base) && fs::is_directory(base)) { + for (auto &dir : fs::directory_iterator(base)) { if (dir.exists() && dir.is_directory()) { - if (std::filesystem::exists(dir / DNG_MAP)) { + if (fs::exists(dir / DNG_MAP)) { this->levels.push_back(dir.path()); } } @@ -99,42 +99,35 @@ void Resources::loadLevels() { void Resources::loadDefaultLuaFile() { for (auto &base : this->defaultsSearchDirs()) { auto f = base / DEFAULT_LUA; - if (std::filesystem::exists(f)) { + if (fs::exists(f)) { *this->defaultsLua = f; break; } } } -std::vector Resources::getFontFiles() { - return this->fonts; -} -std::vector Resources::getLevels() { - return this->levels; -} -shared_ptr Resources::getFontFile() { - return this->font; -} -shared_ptr Resources::updateFont(int idx) { +std::vector Resources::getFontFiles() { return this->fonts; } +std::vector Resources::getLevels() { return this->levels; } +shared_ptr Resources::getFontFile() { return this->font; } +shared_ptr Resources::updateFont(int idx) { auto f = this->fonts[idx]; *this->font = f; return getFontFile(); } -shared_ptr Resources::getDefaultsLuaFile() { +shared_ptr Resources::getDefaultsLuaFile() { return this->defaultsLua; } -shared_ptr Resources::getLevelMap(int idx) { +shared_ptr Resources::getLevelMap(int idx) { auto lvlBase = this->levels[idx]; - std::filesystem::path dngMap = lvlBase / DNG_MAP; + fs::path dngMap = lvlBase / DNG_MAP; // existence of the level dng.map is asserted in the initializer - assert(std::filesystem::exists(dngMap)); - return std::make_shared(dngMap); + assert(fs::exists(dngMap)); + return std::make_shared(dngMap); } -std::optional> -Resources::getLevelProcLua(int idx) { +std::optional> Resources::getLevelProcLua(int idx) { auto lvlBase = this->levels[idx]; auto procLua = lvlBase / PROC_LUA; if (exists(procLua)) { - return std::make_shared(procLua); + return std::make_shared(procLua); } else { return nullopt; } diff --git a/src/resources/Resources.h b/src/resources/Resources.h index 21bf8a7..2e0e7c0 100644 --- a/src/resources/Resources.h +++ b/src/resources/Resources.h @@ -30,9 +30,10 @@ #ifdef __APPLE__ #include -namespace std::filesystem = std::experimental::filesystem; +namespace fs = std::experimental::filesystem; #else #include +namespace fs = std::filesystem; #endif #include #include @@ -53,7 +54,7 @@ static const char *DEFAULT_FONT = "PressStart2P-vaV7.ttf"; class Resources { protected: - shared_ptr font; // chosen font + shared_ptr font; // chosen font shared_ptr defaultsLua; // defaults lua file vector fonts; // all found maps vector levels; // all found maps @@ -68,11 +69,11 @@ public: void loadDefaultLuaFile(); vector getFontFiles(); vector getLevels(); - shared_ptr updateFont(int idx); - shared_ptr getFontFile(); - shared_ptr getDefaultsLuaFile(); - shared_ptr getLevelMap(int idx); - optional> getLevelProcLua(int idx); + shared_ptr updateFont(int idx); + shared_ptr getFontFile(); + shared_ptr getDefaultsLuaFile(); + shared_ptr getLevelMap(int idx); + optional> getLevelProcLua(int idx); /* Helper method to convert any path to a const char * * Windows uses wchar_t so this can help provide a common way to * interact with files diff --git a/src/resources/macos/MacResources.cpp b/src/resources/macos/MacResources.cpp index 90f43c8..2b41daa 100644 --- a/src/resources/macos/MacResources.cpp +++ b/src/resources/macos/MacResources.cpp @@ -26,7 +26,7 @@ //======================================================================== #include "MacResources.h" -namespace std::filesystem = std::experimental::filesystem; +namespace fs = std::experimental::filesystem; MacResources::MacResources() : Resources() { this->workingDir = std::filesystem::current_path(); diff --git a/src/resources/macos/MacResources.h b/src/resources/macos/MacResources.h index 7af24b6..1d19575 100644 --- a/src/resources/macos/MacResources.h +++ b/src/resources/macos/MacResources.h @@ -28,20 +28,22 @@ #ifndef DNG_MACRESOURCES_H #define DNG_MACRESOURCES_H #include "../Resources.h" -namespace std::filesystem = std::experimental::filesystem; + +namespace fs = std::experimental::filesystem; + class MacResources : public Resources { public: MacResources(); protected: public: - const char *convert_to_str(std::filesystem::path &path) override; + const char *convert_to_str(fs::path &path) override; protected: - std::filesystem::path exeDir; - std::filesystem::path workingDir; - std::vector levelSearchDirs() override; - std::vector defaultsSearchDirs() override; - std::vector fontSearchDirs() override; + fs::path exeDir; + fs::path workingDir; + std::vector levelSearchDirs() override; + std::vector defaultsSearchDirs() override; + std::vector fontSearchDirs() override; }; #endif // DNG_MACRESOURCES_H -- cgit v1.2.3-54-g00ecf