Skip to content

Commit

Permalink
fix: revert to wx standard paths for appdata
Browse files Browse the repository at this point in the history
  • Loading branch information
butcherg committed Nov 3, 2018
1 parent a9b152a commit 4005184
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
16 changes: 10 additions & 6 deletions src/rawprocApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static const wxCmdLineEntryDesc cmdLineDesc[] =
bool rawprocFrmApp::OnInit()
{
wxString fname;
wxString psep = wxFileName::GetPathSeparator();

wxInitAllImageHandlers();
wxFileSystem::AddHandler(new wxZipFSHandler);
Expand All @@ -49,16 +50,19 @@ bool rawprocFrmApp::OnInit()

wxString configfile;
wxString conf_exe = wxFileName(wxStandardPaths::Get().GetExecutablePath()).GetPath()+wxFileName::GetPathSeparator()+"rawproc.conf";
//wxString conf_configd = wxStandardPaths::Get().GetUserDataDir()+wxFileName::GetPathSeparator()+"rawproc.conf";

wxString conf_cwd = wxString(getCwdConfigFilePath().c_str());
wxString conf_configd = wxString(getAppConfigFilePath().c_str());

#ifdef WIN32
wxString conf_configd = wxStandardPaths::Get().GetUserConfigDir()+psep+"rawproc"+psep+"rawproc.conf";
#else
wxString conf_configd = wxStandardPaths::Get().GetUserConfigDir()+psep+".rawproc"+psep+"rawproc.conf";
#endif

//config file search order:
// 1) path specified in the -c parameter;
// 2) current working directory;
// 3) executable directory;
// 4) OS-defined user data directory
// 2) current working directory (conf_cwd);
// 3) executable directory (conf_exe);
// 4) OS-defined user data directory (conf_configd)
if (cmdline.Found("c", &configfile)) {
if (wxFileName::FileExists(configfile)) {
wxFileName cfile(configfile);
Expand Down
27 changes: 20 additions & 7 deletions src/strutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include <iostream>
#include <sstream>

#include <locale>
#include <codecvt>

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
Expand All @@ -14,6 +17,7 @@
#ifdef WIN32
#include <direct.h>
#include <io.h>
#include <shlobj.h>
#define GetCurrentDir _getcwd

#define access _access_s
Expand All @@ -22,6 +26,12 @@
#define GetCurrentDir getcwd
#endif

std::string to_utf8(std::wstring wstr)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
return converter.to_bytes(wstr);
}


std::string tostr(double t)
{
Expand Down Expand Up @@ -66,23 +76,26 @@ std::string filepath_normalize(std::string str)
return str;
}

//don't use for Windows...
std::string getAppConfigFilePath()
{
std::string dir;
char *d;
char *d = NULL;
#ifdef WIN32
d = getenv("APPDATA");
if (d) dir = std::string(d) + "\\rawproc\\rawproc.conf";
// if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, (PWSTR*) d))
//d = getenv("APPDATA");
// dir = std::string(to_utf8(d)) + "\\rawproc\\rawproc.conf";
// else
dir = "c:\\Users\\glenn\\AppData\\Roaming\\rawproc\\rawproc.conf";
#else
d = getenv("HOME");
if (d) dir = std::string(d) + "/.rawproc/rawproc.conf";
#endif

if (access( dir.c_str(), 0 ) == 0)
// if (access( dir.c_str(), 0 ) == 0)
return dir;
else
return "";
// else
// return "";
}

std::string getCwdConfigFilePath()
Expand Down

0 comments on commit 4005184

Please sign in to comment.