From a4b4cc62b6d7e32fec0d1ce7c6d65dae51a341db Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Sun, 3 Jul 2022 18:25:11 -0230 Subject: [PATCH] Remove 'HomeFinder' from various parts of code, restrict to Win-specific class. --- src/common/FSNodeREGULAR.cxx | 10 ---------- src/common/FSNodeZIP.cxx | 9 --------- src/gui/FileListWidget.cxx | 16 ++-------------- src/gui/FileListWidget.hxx | 2 -- src/windows/OSystemWINDOWS.cxx | 9 +++++++++ src/windows/OSystemWINDOWS.hxx | 2 +- 6 files changed, 12 insertions(+), 36 deletions(-) diff --git a/src/common/FSNodeREGULAR.cxx b/src/common/FSNodeREGULAR.cxx index fd9835549..feafcffef 100644 --- a/src/common/FSNodeREGULAR.cxx +++ b/src/common/FSNodeREGULAR.cxx @@ -23,8 +23,6 @@ #endif #elif defined(BSPF_WINDOWS) #define ROOT_DIR "C:\\" - #include "HomeFinder.hxx" - static HomeFinder ourHomeFinder; #else #define ROOT_DIR "" #endif @@ -45,11 +43,7 @@ FSNodeREGULAR::FSNodeREGULAR(const string& path, bool verify) // Expand '~' to the HOME environment variable if (_path[0] == '~') { - #if defined(BSPF_WINDOWS) - const char* home = ourHomeFinder.getHomePath().c_str(); - #else const char* home = std::getenv("HOME"); - #endif if (home != nullptr) _path.replace(0, 1, home); } @@ -100,11 +94,7 @@ void FSNodeREGULAR::setFlags() string FSNodeREGULAR::getShortPath() const { // If the path starts with the home directory, replace it with '~' -#if defined(BSPF_WINDOWS) - const char* env_home = ourHomeFinder.getHomePath().c_str(); -#else const char* env_home = std::getenv("HOME"); -#endif const string& home = env_home != nullptr ? env_home : EmptyString; if (home != EmptyString && BSPF::startsWithIgnoreCase(_path, home)) diff --git a/src/common/FSNodeZIP.cxx b/src/common/FSNodeZIP.cxx index 80adcdf6f..6a30aaca0 100644 --- a/src/common/FSNodeZIP.cxx +++ b/src/common/FSNodeZIP.cxx @@ -25,11 +25,6 @@ #include "FSNodeFactory.hxx" #include "FSNodeZIP.hxx" -#if defined(BSPF_WINDOWS) - #include "HomeFinder.hxx" - static HomeFinder ourHomeFinder; -#endif - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FSNodeZIP::FSNodeZIP(const string& p) { @@ -43,13 +38,9 @@ FSNodeZIP::FSNodeZIP(const string& p) // Expand '~' to the users 'home' directory if (_zipFile[0] == '~') { -#if defined(BSPF_UNIX) || defined(BSPF_MACOS) const char* home = std::getenv("HOME"); if (home != nullptr) _zipFile.replace(0, 1, home); -#elif defined(BSPF_WINDOWS) - _zipFile.replace(0, 1, ourHomeFinder.getHomePath()); -#endif } // cerr << " => p: " << p << endl; diff --git a/src/gui/FileListWidget.cxx b/src/gui/FileListWidget.cxx index 39f51deea..c30bee31f 100644 --- a/src/gui/FileListWidget.cxx +++ b/src/gui/FileListWidget.cxx @@ -284,17 +284,8 @@ void FileListWidget::reload() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const FSNode& FileListWidget::selected() { - if(_fileList.size() > 0) - { - _selected = BSPF::clamp(_selected, 0U, static_cast(_fileList.size()-1)); - return _fileList[_selected]; - } - else - { - // This should never happen, but we'll error-check out-of-bounds - // array access anyway - return ourDefaultNode; - } + _selected = BSPF::clamp(_selected, 0U, static_cast(_fileList.size()-1)); + return _fileList[_selected]; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -727,6 +718,3 @@ string FileListWidget::getToolTip(const Common::Point& pos) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt64 FileListWidget::_QUICK_SELECT_DELAY = 300; - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -FSNode FileListWidget::ourDefaultNode = FSNode("~"); diff --git a/src/gui/FileListWidget.hxx b/src/gui/FileListWidget.hxx index 7cca110cf..c6c4df0c4 100644 --- a/src/gui/FileListWidget.hxx +++ b/src/gui/FileListWidget.hxx @@ -187,8 +187,6 @@ class FileListWidget : public StringListWidget unique_ptr myProgressDialog; - static FSNode ourDefaultNode; - private: // Following constructors and assignment operators not supported FileListWidget() = delete; diff --git a/src/windows/OSystemWINDOWS.cxx b/src/windows/OSystemWINDOWS.cxx index 8e33e9b0f..36c92fabc 100644 --- a/src/windows/OSystemWINDOWS.cxx +++ b/src/windows/OSystemWINDOWS.cxx @@ -21,6 +21,15 @@ #include "OSystemWINDOWS.hxx" +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +OSystemWINDOWS::OSystemWINDOWS() +{ + // Make sure 'HOME' environment variable exists; other parts of the + // codebase depend on it + HomeFinder homefinder; + _putenv_s("HOME", homefinder.getHomePath().c_str()); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void OSystemWINDOWS::getBaseDirectories(string& basedir, string& homedir, bool useappdir, const string& usedir) diff --git a/src/windows/OSystemWINDOWS.hxx b/src/windows/OSystemWINDOWS.hxx index 8336d07e9..4ca5e53d5 100644 --- a/src/windows/OSystemWINDOWS.hxx +++ b/src/windows/OSystemWINDOWS.hxx @@ -30,7 +30,7 @@ class OSystemWINDOWS : public OSystemStandalone { public: - OSystemWINDOWS() = default; + OSystemWINDOWS(); ~OSystemWINDOWS() override = default; /**