From 41c3c66eb7acb2405cf5478bda427cdbda96756a Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 27 Jul 2020 14:23:40 +0200 Subject: [PATCH] (Windows) Added support for setting the root of a drive as the home folder. This is mostly usable for portable installations, for example on a USB memory stick. --- es-app/src/main.cpp | 5 +++++ es-core/src/Settings.cpp | 2 ++ es-core/src/utils/FileSystemUtil.cpp | 19 +++++++++++++++++++ es-core/src/utils/FileSystemUtil.h | 1 + 4 files changed, 27 insertions(+) diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index 076c965d1..51797005d 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -148,7 +148,12 @@ bool parseArgs(int argc, char* argv[]) std::cerr << "Error: No home path supplied with \'--home'.\n"; return false; } + #ifdef _WIN64 + if (!Utils::FileSystem::exists(argv[i + 1]) && + (!Utils::FileSystem::driveExists(argv[i + 1]))) { + #else if (!Utils::FileSystem::exists(argv[i + 1])) { + #endif std::cerr << "Error: Home path \'" << argv[i + 1] << "\' does not exist.\n"; return false; } diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index 80805d336..13631788b 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -187,6 +187,8 @@ void Settings::setDefaults() mStringMap["SaveGamelistsMode"] = "always"; #ifdef _WIN64 mBoolMap["HideTaskbar"] = false; + // Set this to true as default as it's unreliable to suspend ES during game launches + // on some Windows versions/installations. mBoolMap["RunInBackground"] = true; #endif mStringMap["MediaDirectory"] = ""; diff --git a/es-core/src/utils/FileSystemUtil.cpp b/es-core/src/utils/FileSystemUtil.cpp index a8e331012..f60156c8a 100644 --- a/es-core/src/utils/FileSystemUtil.cpp +++ b/es-core/src/utils/FileSystemUtil.cpp @@ -706,6 +706,25 @@ namespace Utils #endif } + bool driveExists(const std::string& _path) + { + #ifdef _WIN64 + std::string path = getGenericPath(_path); + // Try to add a dot or a backslash and a dot depending on how the drive + // letter was defined by the user. + if (path.length() == 2 && path.at(1) == ':') + path += "\\."; + else if (path.length() == 3 && path.at(1) == ':') + path += "."; + + struct _stat64 info; + return (_wstat64(Utils::String::stringToWideString(path).c_str(), &info) == 0); + + #else + return false; + #endif + } + bool isAbsolute(const std::string& _path) { std::string path = getGenericPath(_path); diff --git a/es-core/src/utils/FileSystemUtil.h b/es-core/src/utils/FileSystemUtil.h index be9739225..234d34602 100644 --- a/es-core/src/utils/FileSystemUtil.h +++ b/es-core/src/utils/FileSystemUtil.h @@ -55,6 +55,7 @@ namespace Utils bool createDirectory(const std::string& _path); bool exists(const std::string& _path); + bool driveExists(const std::string& _path); bool isAbsolute(const std::string& _path); bool isRegularFile(const std::string& _path); bool isDirectory(const std::string& _path);