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.
This commit is contained in:
Epicalert 2021-07-02 03:45:19 +08:00
parent 378bcf7f16
commit e5a1cdd6da
No known key found for this signature in database
GPG key ID: CAA46F858D0979BD
4 changed files with 11 additions and 6 deletions

View file

@ -7,7 +7,7 @@
#include <tomlcpp.hpp>
bool configFileOpen(struct optData* data) {
auto configFile = toml::parseFile(prefixCustom + "config.toml");
auto configFile = toml::parseFile(prefixConfig + "config.toml");
if (!configFile.table) {
return false;
}

View file

@ -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!

View file

@ -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
}

View file

@ -3,6 +3,7 @@
#include <string>
extern std::string prefixConfig;
extern std::string prefixCustom;
extern std::string prefixDefault;