From e5a1cdd6da69179b7b916274e717daaf060af2a2 Mon Sep 17 00:00:00 2001 From: Epicalert Date: Fri, 2 Jul 2021 03:45:19 +0800 Subject: [PATCH] Changed config file path Config file is now stored under ~/.config in Linux, and %AppData%\Roaming in Windows. Custom prefix has been changed to %AppData%\Local\Facecam2D in Windows, instead of the improper %AppData%\Facecam2D. MacOS paths remain unchanged. --- src/configfile.cpp | 2 +- src/fc2dconfig.cpp | 3 +-- src/paths.cpp | 11 ++++++++--- src/paths.hpp | 1 + 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/configfile.cpp b/src/configfile.cpp index 9e95d3c..8666627 100644 --- a/src/configfile.cpp +++ b/src/configfile.cpp @@ -7,7 +7,7 @@ #include bool configFileOpen(struct optData* data) { - auto configFile = toml::parseFile(prefixCustom + "config.toml"); + auto configFile = toml::parseFile(prefixConfig + "config.toml"); if (!configFile.table) { return false; } diff --git a/src/fc2dconfig.cpp b/src/fc2dconfig.cpp index 6d86956..92c0dda 100644 --- a/src/fc2dconfig.cpp +++ b/src/fc2dconfig.cpp @@ -62,7 +62,6 @@ ConfigurationFrame::ConfigurationFrame() : wxFrame(NULL, wxID_ANY, "Configure " bottomButtonSizer->Add(applyButton, 0, wxALL, 5); wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); - sizer->Add(placeholderText, 0, wxALL | wxALIGN_LEFT, 10); sizer->Add(useHaarCheckBox, 0, wxALL | wxALIGN_LEFT, 5); sizer->Add(modelNameChoice, 0, wxALL | wxALIGN_LEFT, 5); sizer->AddStretchSpacer(1); @@ -77,7 +76,7 @@ ConfigurationFrame::ConfigurationFrame() : wxFrame(NULL, wxID_ANY, "Configure " void ConfigurationFrame::OnApply(wxCommandEvent& event) { // write options to config file std::ofstream configFile; - configFile.open(prefixCustom + "config.toml"); + configFile.open(prefixConfig + "config.toml"); configFile << "use_haar = " << (useHaarCheckBox->GetValue() ? "true" : "false") << std::endl; // janky edge case lmao // if user did not select any model, don't write the line in the config file! diff --git a/src/paths.cpp b/src/paths.cpp index e1ef84c..6969309 100644 --- a/src/paths.cpp +++ b/src/paths.cpp @@ -9,18 +9,23 @@ #define READABLE(p) access(p.c_str(),R_OK)==0 #endif -std::string prefixCustom; -std::string prefixDefault; +std::string prefixConfig; // directory to store config.toml in +std::string prefixCustom; // directory for user-accessible models and cvdata +std::string prefixDefault; // directory for pre-installed models and cvdata void initPrefixes() { #if defined (__gnu_linux__) + prefixConfig = getenv("HOME") + std::string("/.config/facecam2d/"); prefixCustom = getenv("HOME") + std::string("/.local/share/facecam2d/"); prefixDefault = "/usr/share/facecam2d/"; #elif defined (__APPLE__) + // config and supporting files are both stored in Library on MacOS + prefixConfig = getenv("HOME") + std::string("/Library/Facecam2D/"); prefixCustom = getenv("HOME") + std::string("/Library/Facecam2D/"); prefixDefault = "/Applications/Facecam2D.app/"; #elif defined (_WIN32) - prefixCustom = getenv("AppData") + std::string("\\Facecam2D\\"); + prefixConfig = getenv("AppData") + std::string("\\Roaming\\Facecam2D\\"); + prefixCustom = getenv("AppData") + std::string("\\Local\\Facecam2D\\"); prefixDefault = getenv("ProgramFiles") + std::string("\\Facecam2D\\"); #endif } diff --git a/src/paths.hpp b/src/paths.hpp index 31ba82f..71edec5 100644 --- a/src/paths.hpp +++ b/src/paths.hpp @@ -3,6 +3,7 @@ #include +extern std::string prefixConfig; extern std::string prefixCustom; extern std::string prefixDefault;