From b7bf3b79b2b455ccdf69745dba514cd1e3ecef1b Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Sat, 9 Sep 2017 15:06:21 -0230 Subject: [PATCH] First pass at a consistent default for load/saving files that don't have a pre-defined location (ROM files and disassemblies, etc). - Repurposed the snapshot load/save folders by changing OSystem::defaultSnapLoadDir to OSystem::defaultLoadDir, and similar for the save dir - In Windows, this directory will now be 'Documents\Stella', while in Linux/OSX it will be $HOME - Testing still required for Windows and OSX; only Linux is confirmed to work for now --- src/debugger/CartDebug.cxx | 10 +--------- src/emucore/OSystem.cxx | 4 ++-- src/emucore/OSystem.hxx | 14 +++++++------- src/gui/SnapshotDialog.cxx | 4 ++-- src/macosx/OSystemMACOSX.cxx | 12 ++++++------ src/macosx/OSystemMACOSX.hxx | 6 +++--- src/windows/HomeFinder.hxx | 16 ++++++++-------- src/windows/OSystemWINDOWS.cxx | 14 +++++++------- src/windows/OSystemWINDOWS.hxx | 6 +++--- 9 files changed, 39 insertions(+), 47 deletions(-) diff --git a/src/debugger/CartDebug.cxx b/src/debugger/CartDebug.cxx index 5b49deedd..dfa998a06 100644 --- a/src/debugger/CartDebug.cxx +++ b/src/debugger/CartDebug.cxx @@ -955,20 +955,12 @@ string CartDebug::saveDisassembly() if(myConsole.cartridge().bankCount() > 1) return DebuggerParser::red("disassembly for multi-bank ROM not yet supported"); - // Currently, the default naming/location for disassembly files is: - // 1) ROM dir based on properties entry name - if(myDisasmFile == "") { const string& propsname = myConsole.properties().get(Cartridge_Name) + ".asm"; - FilesystemNode case0(myOSystem.romFile().getParent().getPath() + propsname); - if(case0.getParent().isWritable()) - myDisasmFile = case0.getPath(); - else - return DebuggerParser::red("disassembly file not writable:\n " + - case0.getShortPath()); + myDisasmFile = FilesystemNode(myOSystem.defaultSaveDir() + propsname).getPath(); } FilesystemNode node(myDisasmFile); diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index dda845ba4..ea27471eb 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -190,8 +190,8 @@ void OSystem::setConfigPaths() string s; validatePath(myStateDir, "statedir", myBaseDir + "state"); - validatePath(mySnapshotSaveDir, "snapsavedir", defaultSnapSaveDir()); - validatePath(mySnapshotLoadDir, "snaploaddir", defaultSnapLoadDir()); + validatePath(mySnapshotSaveDir, "snapsavedir", defaultSaveDir()); + validatePath(mySnapshotLoadDir, "snaploaddir", defaultLoadDir()); validatePath(myNVRamDir, "nvramdir", myBaseDir + "nvram"); validatePath(myCfgDir, "cfgdir", myBaseDir + "cfg"); diff --git a/src/emucore/OSystem.hxx b/src/emucore/OSystem.hxx index 6610b2e91..b3b136467 100644 --- a/src/emucore/OSystem.hxx +++ b/src/emucore/OSystem.hxx @@ -403,14 +403,14 @@ class OSystem virtual void stateChanged(EventHandler::State state) { } /** - Returns the default save and load paths for the snapshot directory. - Since this varies greatly among different systems and is the one - directory that most end-users care about (vs. config file stuff - that usually isn't user-modifiable), we create a special method - for it. + Returns the default save and load paths for various files + (snapshots, disassembly, roms, etc). Since this varies greatly + among different systems and is the one directory that most end-users + care about (vs. config file stuff that usually isn't user-modifiable), + we create a special method for it. */ - virtual string defaultSnapSaveDir() { return string("~") + BSPF::PATH_SEPARATOR; } - virtual string defaultSnapLoadDir() { return string("~") + BSPF::PATH_SEPARATOR; } + virtual string defaultSaveDir() const { return string("~") + BSPF::PATH_SEPARATOR; } + virtual string defaultLoadDir() const { return string("~") + BSPF::PATH_SEPARATOR; } protected: /** diff --git a/src/gui/SnapshotDialog.cxx b/src/gui/SnapshotDialog.cxx index 6dd3a7aee..9acf94468 100644 --- a/src/gui/SnapshotDialog.cxx +++ b/src/gui/SnapshotDialog.cxx @@ -156,8 +156,8 @@ void SnapshotDialog::saveConfig() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void SnapshotDialog::setDefaults() { - mySnapSavePath->setText(instance().defaultSnapSaveDir()); - mySnapLoadPath->setText(instance().defaultSnapLoadDir()); + mySnapSavePath->setText(instance().defaultSaveDir()); + mySnapLoadPath->setText(instance().defaultLoadDir()); mySnapSingle->setState(false); mySnap1x->setState(false); diff --git a/src/macosx/OSystemMACOSX.cxx b/src/macosx/OSystemMACOSX.cxx index ab28d3f66..286fe7b4a 100644 --- a/src/macosx/OSystemMACOSX.cxx +++ b/src/macosx/OSystemMACOSX.cxx @@ -32,21 +32,21 @@ OSystemMACOSX::OSystemMACOSX() : OSystem() { - setBaseDir("~/Library/Application Support/Stella"); + setBaseDir("~/Library/Application Support/Stella/"); // This will be overridden, as OSX uses plist files for settings setConfigFile("~/Library/Application Support/Stella/stellarc"); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string OSystemMACOSX::defaultSnapSaveDir() +string OSystemMACOSX::defaultSaveDir() const { - FilesystemNode desktop("~/Desktop"); - return desktop.isDirectory() ? desktop.getShortPath() : "~"; + FilesystemNode desktop("~/Desktop/"); + return desktop.isDirectory() ? desktop.getShortPath() : "~/"; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string OSystemMACOSX::defaultSnapLoadDir() +string OSystemMACOSX::defaultLoadDir() const { - return defaultSnapSaveDir(); + return defaultSaveDir(); } diff --git a/src/macosx/OSystemMACOSX.hxx b/src/macosx/OSystemMACOSX.hxx index cfa4857a3..76fbe0f7f 100644 --- a/src/macosx/OSystemMACOSX.hxx +++ b/src/macosx/OSystemMACOSX.hxx @@ -35,10 +35,10 @@ class OSystemMACOSX : public OSystem virtual ~OSystemMACOSX() = default; /** - Returns the default paths for the snapshot directory. + Returns the default paths for loading/saving files. */ - string defaultSnapSaveDir() override; - string defaultSnapLoadDir() override; + string defaultSaveDir() const override; + string defaultLoadDir() const override; private: // Following constructors and assignment operators not supported diff --git a/src/windows/HomeFinder.hxx b/src/windows/HomeFinder.hxx index 7e34cf318..8d2409975 100644 --- a/src/windows/HomeFinder.hxx +++ b/src/windows/HomeFinder.hxx @@ -56,21 +56,21 @@ class HomeFinder return ourAppDataPath; } - // Return the 'DESKTOPDIRECTORY' folder, or an empty string if the folder couldn't be determined. - const string& getDesktopPath() const + // Return the 'My Documents' folder, or an empty string if the folder couldn't be determined. + const string& getDocumentsPath() const { - if(ourDesktopPath == "") + if(ourDocumentsPath == "") { char folder_path[MAX_PATH]; - HRESULT const result = SHGetFolderPathA(NULL, CSIDL_DESKTOPDIRECTORY | CSIDL_FLAG_CREATE, + HRESULT const result = SHGetFolderPathA(NULL, CSIDL_MYDOCUMENTS | CSIDL_FLAG_CREATE, NULL, 0, folder_path); - ourDesktopPath = (result == S_OK) ? folder_path : EmptyString; + ourDocumentsPath = (result == S_OK) ? folder_path : EmptyString; } - return ourDesktopPath; + return ourDocumentsPath; } private: - static string ourHomePath, ourAppDataPath, ourDesktopPath; + static string ourHomePath, ourAppDataPath, ourDocumentsPath; // Following constructors and assignment operators not supported HomeFinder(const HomeFinder&) = delete; @@ -81,6 +81,6 @@ class HomeFinder __declspec(selectany) string HomeFinder::ourHomePath = ""; __declspec(selectany) string HomeFinder::ourAppDataPath = ""; -__declspec(selectany) string HomeFinder::ourDesktopPath = ""; +__declspec(selectany) string HomeFinder::ourDocumentsPath = ""; #endif diff --git a/src/windows/OSystemWINDOWS.cxx b/src/windows/OSystemWINDOWS.cxx index 246e0e93a..787174083 100644 --- a/src/windows/OSystemWINDOWS.cxx +++ b/src/windows/OSystemWINDOWS.cxx @@ -74,23 +74,23 @@ OSystemWINDOWS::OSystemWINDOWS() basedir += "Stella"; } else - basedir = "."; // otherwise, default to current directory + basedir = ".\\"; // otherwise, default to current directory } setBaseDir(basedir); - setConfigFile(basedir + "\\stella.ini"); + setConfigFile(basedir + "stella.ini"); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string OSystemWINDOWS::defaultSnapSaveDir() +string OSystemWINDOWS::defaultSaveDir() const { HomeFinder homefinder; - FilesystemNode desktop(homefinder.getDesktopPath()); - return desktop.isDirectory() ? desktop.getShortPath() : "~"; + FilesystemNode desktop(homefinder.getDesktopPath() + "\\Stella"); + return desktop.isDirectory() ? desktop.getShortPath() : "~\\"; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string OSystemWINDOWS::defaultSnapLoadDir() +string OSystemWINDOWS::defaultLoadDir() const { - return defaultSnapSaveDir(); + return defaultSaveDir(); } diff --git a/src/windows/OSystemWINDOWS.hxx b/src/windows/OSystemWINDOWS.hxx index 16bfe37e3..fc7bec449 100644 --- a/src/windows/OSystemWINDOWS.hxx +++ b/src/windows/OSystemWINDOWS.hxx @@ -34,10 +34,10 @@ class OSystemWINDOWS : public OSystem public: /** - Returns the default paths for the snapshot directory. + Returns the default paths for loading/saving files. */ - string defaultSnapSaveDir() override; - string defaultSnapLoadDir() override; + string defaultSaveDir() const override; + string defaultLoadDir() const override; private: // Following constructors and assignment operators not supported