Alias filesystem namespace + attempt at fixing Windows compilation

This commit is contained in:
Simone Coco
2022-12-19 15:25:01 +01:00
committed by GitHub
parent 03c6231742
commit ba62db8f12
5 changed files with 24 additions and 23 deletions

View File

@@ -8,7 +8,7 @@
#include <execution>
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<u8> 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") {

View File

@@ -4,11 +4,11 @@
#include <utilities.hpp>
#include <nfd.h>
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);

View File

@@ -7,6 +7,7 @@
#include <iostream>
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);

View File

@@ -19,3 +19,18 @@ 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<type>(); \
name = value; \
} else { \
settingsFile.clear(); \
settings[param1][param2] = defaultVal; \
settingsFile << settings; \
name = defaultVal; \
} \
} while(0)
}

View File

@@ -324,18 +324,3 @@ 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<type>(); \
name = value; \
} else { \
settingsFile.clear(); \
settings[param1][param2] = defaultVal; \
settingsFile << settings; \
name = defaultVal; \
} \
} while(0)
}