From ba62db8f127bf42cfabcb9bed40715ea51e5bf5f Mon Sep 17 00:00:00 2001 From: Simone Coco <91993281+CocoSimone@users.noreply.github.com> Date: Mon, 19 Dec 2022 15:25:01 +0100 Subject: [PATCH] Alias filesystem namespace + attempt at fixing Windows compilation --- src/frontend/imgui/GameList.cpp | 4 ++-- src/frontend/imgui/Settings.cpp | 10 +++++----- src/frontend/imgui/Window.cpp | 3 ++- src/frontend/imgui/utilities.hpp | 15 +++++++++++++++ src/util.hpp | 15 --------------- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/frontend/imgui/GameList.cpp b/src/frontend/imgui/GameList.cpp index 711f60ba..f826dcec 100644 --- a/src/frontend/imgui/GameList.cpp +++ b/src/frontend/imgui/GameList.cpp @@ -8,7 +8,7 @@ #include using namespace nlohmann; -using namespace std::filesystem; +namespace fs = std::filesystem; GameList::GameList(const std::string& path) { if(!path.empty()) { @@ -16,7 +16,7 @@ GameList::GameList(const std::string& path) { json gameDb = json::parse(gameDbFile); std::vector rom{}; - for(const auto& p : directory_iterator{path}) { + for(const auto& p : fs::directory_iterator{path}) { const auto filename = p.path().string(); if(p.path().extension() == ".n64" || p.path().extension() == ".z64" || p.path().extension() == ".v64" || p.path().extension() == ".N64" || p.path().extension() == ".Z64" || p.path().extension() == ".V64") { diff --git a/src/frontend/imgui/Settings.cpp b/src/frontend/imgui/Settings.cpp index 5c309bca..9cb0c246 100644 --- a/src/frontend/imgui/Settings.cpp +++ b/src/frontend/imgui/Settings.cpp @@ -4,11 +4,11 @@ #include #include -using namespace std::filesystem; +namespace fs = std::filesystem; Settings::Settings(n64::Core& core) { auto modes = std::fstream::in | std::fstream::out; - auto fileExists = exists("resources/settings.json"); + auto fileExists = fs::exists("resources/settings.json"); if(!fileExists) { modes |= std::fstream::trunc; } @@ -57,9 +57,9 @@ Settings::Settings(n64::Core& core) { Settings::~Settings() { auto modes = std::fstream::out; - auto fileExists = exists("resources/settings.json"); + auto fileExists = fs::exists("resources/settings.json"); if(fileExists) { - modes |= std::fstream::trunc; + modes = modes | std::fstream::trunc; std::fstream settingsFile{"resources/settings.json", modes}; @@ -88,7 +88,7 @@ void Settings::RenderWidget(bool& show) { ImGui::SameLine(); if(ImGui::Button("Select...")) { nfdchar_t *outpath; - nfdresult_t result = NFD_PickFolderN(&outpath, nullptr); + nfdresult_t result = NFD_PickFolder(&outpath, nullptr); if (result == NFD_OKAY) { gamesDir = outpath; NFD_FreePath(outpath); diff --git a/src/frontend/imgui/Window.cpp b/src/frontend/imgui/Window.cpp index c334e51b..4c188b9e 100644 --- a/src/frontend/imgui/Window.cpp +++ b/src/frontend/imgui/Window.cpp @@ -7,6 +7,7 @@ #include VkInstance instance{}; +using fs = std::filesystem; Window::Window(n64::Core& core) : settings(core), gameList(settings.GetGamesDir()) { InitSDL(); @@ -175,7 +176,7 @@ void Window::LoadROM(n64::Core& core, const std::string &path) { }; if(gameName.empty()) { - gameName = std::filesystem::path(path).stem().string(); + gameName = fs::path(path).stem().string(); } util::UpdateRPC(util::Playing, gameName); diff --git a/src/frontend/imgui/utilities.hpp b/src/frontend/imgui/utilities.hpp index 022aa624..d3640d73 100644 --- a/src/frontend/imgui/utilities.hpp +++ b/src/frontend/imgui/utilities.hpp @@ -18,4 +18,19 @@ inline bool CreateComboList(const char* label, int* index, const char** items, i } return false; +} + +#define checkjsonentry(name, type, param1, param2, defaultVal) \ + do { \ + auto name##Entry = settings[param1][param2]; \ + if(!name##Entry.empty()) { \ + auto value = name##Entry.get(); \ + name = value; \ + } else { \ + settingsFile.clear(); \ + settings[param1][param2] = defaultVal; \ + settingsFile << settings; \ + name = defaultVal; \ + } \ + } while(0) } \ No newline at end of file diff --git a/src/util.hpp b/src/util.hpp index 8b0281d8..d0b0fb83 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -323,19 +323,4 @@ inline void UpdateRPC(State state, const std::string& game = "") { inline void ClearRPC() { Discord_ClearPresence(); -} - -#define checkjsonentry(name, type, param1, param2, defaultVal) \ - do { \ - auto name##Entry = settings[param1][param2]; \ - if(!name##Entry.empty()) { \ - auto value = name##Entry.get(); \ - name = value; \ - } else { \ - settingsFile.clear(); \ - settings[param1][param2] = defaultVal; \ - settingsFile << settings; \ - name = defaultVal; \ - } \ - } while(0) } \ No newline at end of file