From 0d34de269c1e1fc7a4975757b7ad932bc8c89b16 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Sun, 24 Mar 2019 16:31:16 -0230 Subject: [PATCH] Finalized 'basedir' and 'baseinappdir' in Windows. - This still needs some testing and doc updates, but it seems to be working great - Hopefully people will now stop asking for this feature --- src/emucore/OSystem.cxx | 4 ++-- src/windows/HomeFinder.hxx | 41 ++++++++++++++++++++++------------ src/windows/OSystemWINDOWS.cxx | 30 +++++++++---------------- 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 76b73c836..cdd4cbb5c 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -179,12 +179,12 @@ void OSystem::loadConfig(const Settings::Options& options) FilesystemNode save(myDefaultSaveDir); if(!save.isDirectory()) save.makeDir(); - myDefaultSaveDir = node.getPath(); + myDefaultSaveDir = save.getShortPath(); FilesystemNode load(myDefaultLoadDir); if(!load.isDirectory()) load.makeDir(); - myDefaultLoadDir = node.getPath(); + myDefaultLoadDir = load.getShortPath(); logMessage("Loading config options ...", 2); mySettings->load(configFile(), options); diff --git a/src/windows/HomeFinder.hxx b/src/windows/HomeFinder.hxx index a651817e2..ec52e4197 100644 --- a/src/windows/HomeFinder.hxx +++ b/src/windows/HomeFinder.hxx @@ -30,19 +30,6 @@ class HomeFinder HomeFinder() = default; ~HomeFinder() = default; - // Return the 'HOME/User' folder, or an empty string if the folder couldn't be determined. - const string& getHomePath() const - { - if(ourHomePath == "") - { - char folder_path[MAX_PATH]; - HRESULT const result = SHGetFolderPathA(NULL, CSIDL_PROFILE | CSIDL_FLAG_CREATE, - NULL, 0, folder_path); - ourHomePath = (result == S_OK) ? folder_path : EmptyString; - } - return ourHomePath; - } - // Return the 'APPDATA' folder, or an empty string if the folder couldn't be determined. const string& getAppDataPath() const { @@ -56,6 +43,19 @@ class HomeFinder return ourAppDataPath; } + // Return the 'Desktop' folder, or an empty string if the folder couldn't be determined. + const string& getDesktopPath() const + { + if(ourDesktopPath == "") + { + char folder_path[MAX_PATH]; + HRESULT const result = SHGetFolderPathA(NULL, CSIDL_DESKTOPDIRECTORY | CSIDL_FLAG_CREATE, + NULL, 0, folder_path); + ourDesktopPath = (result == S_OK) ? folder_path : EmptyString; + } + return ourDesktopPath; + } + // Return the 'My Documents' folder, or an empty string if the folder couldn't be determined. const string& getDocumentsPath() const { @@ -69,8 +69,21 @@ class HomeFinder return ourDocumentsPath; } + // Return the 'HOME/User' folder, or an empty string if the folder couldn't be determined. + const string& getHomePath() const + { + if(ourHomePath == "") + { + char folder_path[MAX_PATH]; + HRESULT const result = SHGetFolderPathA(NULL, CSIDL_PROFILE | CSIDL_FLAG_CREATE, + NULL, 0, folder_path); + ourHomePath = (result == S_OK) ? folder_path : EmptyString; + } + return ourHomePath; + } + private: - static string ourHomePath, ourAppDataPath, ourDocumentsPath, ourDesktopPath; + static string ourHomePath, ourAppDataPath, ourDesktopPath, ourDocumentsPath; // Following constructors and assignment operators not supported HomeFinder(const HomeFinder&) = delete; diff --git a/src/windows/OSystemWINDOWS.cxx b/src/windows/OSystemWINDOWS.cxx index 7726ca5bf..503dd26c1 100644 --- a/src/windows/OSystemWINDOWS.cxx +++ b/src/windows/OSystemWINDOWS.cxx @@ -35,31 +35,21 @@ void OSystemWINDOWS::getBaseDirAndConfig(string& basedir, string& cfgfile, basedir += '\\'; basedir += "Stella\\"; } - savedir = loaddir = "~/"; // FIXME - change this to 'Desktop' + FilesystemNode defaultLoadSaveDir(homefinder.getDesktopPath()); + savedir = loaddir = defaultLoadSaveDir.getShortPath(); // Check to see if basedir overrides are active if(useappdir) - cout << "ERROR: base dir in app folder not supported" << endl; - else if(usedir != "") { - basedir = FilesystemNode(usedir).getPath(); - savedir = loaddir = basedir; + char filename[MAX_PATH]; + GetModuleFileNameA(NULL, filename, sizeof(filename)); + FilesystemNode appdir(filename); + appdir = appdir.getParent(); + if(appdir.isDirectory()) + savedir = loaddir = basedir = appdir.getPath(); } + else if(usedir != "") + savedir = loaddir = basedir = FilesystemNode(usedir).getPath(); cfgfile = basedir + "stella.ini"; } -#if 0 -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string OSystemWINDOWS::defaultSaveDir() const -{ - HomeFinder homefinder; - FilesystemNode documents(homefinder.getDocumentsPath()); - return documents.isDirectory() ? documents.getShortPath() + "\\Stella\\" : "~\\"; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string OSystemWINDOWS::defaultLoadDir() const -{ - return defaultSaveDir(); -} -#endif