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
This commit is contained in:
Stephen Anthony 2019-03-24 16:31:16 -02:30
parent 9c905bc53e
commit 0d34de269c
3 changed files with 39 additions and 36 deletions

View File

@ -179,12 +179,12 @@ void OSystem::loadConfig(const Settings::Options& options)
FilesystemNode save(myDefaultSaveDir); FilesystemNode save(myDefaultSaveDir);
if(!save.isDirectory()) if(!save.isDirectory())
save.makeDir(); save.makeDir();
myDefaultSaveDir = node.getPath(); myDefaultSaveDir = save.getShortPath();
FilesystemNode load(myDefaultLoadDir); FilesystemNode load(myDefaultLoadDir);
if(!load.isDirectory()) if(!load.isDirectory())
load.makeDir(); load.makeDir();
myDefaultLoadDir = node.getPath(); myDefaultLoadDir = load.getShortPath();
logMessage("Loading config options ...", 2); logMessage("Loading config options ...", 2);
mySettings->load(configFile(), options); mySettings->load(configFile(), options);

View File

@ -30,19 +30,6 @@ class HomeFinder
HomeFinder() = default; HomeFinder() = default;
~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. // Return the 'APPDATA' folder, or an empty string if the folder couldn't be determined.
const string& getAppDataPath() const const string& getAppDataPath() const
{ {
@ -56,6 +43,19 @@ class HomeFinder
return ourAppDataPath; 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. // Return the 'My Documents' folder, or an empty string if the folder couldn't be determined.
const string& getDocumentsPath() const const string& getDocumentsPath() const
{ {
@ -69,8 +69,21 @@ class HomeFinder
return ourDocumentsPath; 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: private:
static string ourHomePath, ourAppDataPath, ourDocumentsPath, ourDesktopPath; static string ourHomePath, ourAppDataPath, ourDesktopPath, ourDocumentsPath;
// Following constructors and assignment operators not supported // Following constructors and assignment operators not supported
HomeFinder(const HomeFinder&) = delete; HomeFinder(const HomeFinder&) = delete;

View File

@ -35,31 +35,21 @@ void OSystemWINDOWS::getBaseDirAndConfig(string& basedir, string& cfgfile,
basedir += '\\'; basedir += '\\';
basedir += "Stella\\"; 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 // Check to see if basedir overrides are active
if(useappdir) if(useappdir)
cout << "ERROR: base dir in app folder not supported" << endl;
else if(usedir != "")
{ {
basedir = FilesystemNode(usedir).getPath(); char filename[MAX_PATH];
savedir = loaddir = basedir; 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"; 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