From 89275f3126b56cb6ac91ed4fa24316bb3afd11b5 Mon Sep 17 00:00:00 2001 From: R2DLiu Date: Tue, 30 Jun 2020 23:00:55 -0400 Subject: [PATCH] FileUtils code moved. Refactor eventually --- Externals/Slippi/SlippiGame.cpp | 6 +-- Readme.md | 12 +++--- Source/Core/Common/CommonPaths.h | 2 +- Source/Core/Common/ENetUtil.cpp | 3 ++ Source/Core/Common/FileUtil.cpp | 64 ++++++++++++++++++++++++++++++-- Source/Core/Common/FileUtil.h | 4 ++ Source/Core/Common/Version.h | 1 + 7 files changed, 78 insertions(+), 14 deletions(-) diff --git a/Externals/Slippi/SlippiGame.cpp b/Externals/Slippi/SlippiGame.cpp index f25a23d594..2db051d789 100644 --- a/Externals/Slippi/SlippiGame.cpp +++ b/Externals/Slippi/SlippiGame.cpp @@ -1,7 +1,7 @@ #include "SlippiGame.h" namespace Slippi { - // TODO: maybe refactor with std::byte and std::filesystem + // SLIPPITODO: maybe refactor with std::byte and std::filesystem //********************************************************************** //* Event Handlers * @@ -526,8 +526,8 @@ namespace Slippi { #ifdef _WIN32 // On Windows, we need to convert paths to std::wstring to deal with UTF-8 - // TODO: codecvt is deprecated. C++17 msvc support std::filesystem::u8path - // TODO: c++20 std::filesystem::path natively supports utf8 + // SLIPPITODO: codecvt is deprecated. C++17 msvc support std::filesystem::u8path + // SLIPPITODO: c++20 std::filesystem::path natively supports utf8 std::wstring convertedPath = std::wstring_convert>().from_bytes(path); result->file = std::make_unique(convertedPath, std::ios::in | std::ios::binary); #else diff --git a/Readme.md b/Readme.md index 0d41dd937d..e45de29312 100644 --- a/Readme.md +++ b/Readme.md @@ -15,7 +15,7 @@ Please read the [FAQ](https://dolphin-emu.org/docs/faq/) before using Dolphin. * OS * Windows (7 SP1 or higher). * Linux. - * macOS (10.12 Sierra or higher). + * macOS (10.12 Sierra or higher). // TODO: figure this out * Unix-like systems other than Linux are not officially supported but might work. * Processor * A CPU with SSE2 support. @@ -38,9 +38,9 @@ Dolphin can only be installed on devices that satisfy the above requirements. At ## Building for Windows -Use the solution file `Source/dolphin-emu.sln` to build Dolphin on Windows. -Visual Studio 2019 16.3 or later is a hard requirement. Other compilers might be -able to build Dolphin on Windows but have not been tested and are not +Visual Studio 2019 16.3 or later is a hard requirement. +Open the folder that contains the base CMakeLists.txt file to build Dolphin on Windows. +Other compilers might able to build Dolphin on Windows but have not been tested and are not recommended to be used. Git and Windows 10 SDK must be installed when building. Make sure to pull submodules before building: @@ -90,7 +90,7 @@ Useful for development as root access is not required. 2. `cd Build` 3. `cmake .. -DLINUX_LOCAL_DEV=true` 4. `make` -5. `ln -s ../../Data/Sys Binaries/` +5. `ln -s ../../Overwrite/{Sys,User} Binaries/` ### Linux Portable Build Steps: @@ -101,7 +101,7 @@ Or useful for having multiple distinct Dolphin setups for testing/development/TA 2. `cd Build` 3. `cmake .. -DLINUX_LOCAL_DEV=true` 4. `make` -5. `cp -r ../Data/Sys/ Binaries/` +5. `cp -r ../Overwrite/{Sys,User} Binaries/` 6. `touch Binaries/portable.txt` ## Building for Android diff --git a/Source/Core/Common/CommonPaths.h b/Source/Core/Common/CommonPaths.h index 46a201d823..c3cd13d00b 100644 --- a/Source/Core/Common/CommonPaths.h +++ b/Source/Core/Common/CommonPaths.h @@ -25,7 +25,7 @@ #define NOMEDIA_FILE ".nomedia" #else #define USERDATA_DIR "user" -#define DOLPHIN_DATA_DIR "dolphin-emu" +#define DOLPHIN_DATA_DIR "SlippiOnline" #endif // Dirs in both User and Sys diff --git a/Source/Core/Common/ENetUtil.cpp b/Source/Core/Common/ENetUtil.cpp index 0781e1764b..0d81e10445 100644 --- a/Source/Core/Common/ENetUtil.cpp +++ b/Source/Core/Common/ENetUtil.cpp @@ -10,6 +10,9 @@ namespace ENetUtil { void WakeupThread(ENetHost* host) { + if (!host) + return; + // Send ourselves a spurious message. This is hackier than it should be. // comex reported this as https://github.com/lsalzman/enet/issues/23, so // hopefully there will be a better way to do it in the future. diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index 5fc633c5e9..c2a2151893 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -30,6 +30,8 @@ #include #include // guid stuff #include +#include +#include #else #include #include @@ -531,6 +533,28 @@ bool DeleteDirRecursively(const std::string& directory) return success; } +// SLIPPITODO: replace with C++17 https://en.cppreference.com/w/cpp/filesystem/last_write_time +u64 GetFileModTime(const std::string& filename) +{ + struct stat file_info; + + std::string copy(filename); + StripTailDirSlashes(copy); + +#ifdef _WIN32 + int result = _tstat64(UTF8ToTStr(copy).c_str(), &file_info); +#else + int result = stat(copy.c_str(), &file_info); +#endif + + if (result < 0) + { + return 0; + } + + return file_info.st_mtime; +} + // Create directory and copy contents (does not overwrite existing files) void CopyDir(const std::string& source_path, const std::string& dest_path, bool destructive) { @@ -709,6 +733,32 @@ std::string GetExePath() return dolphin_path; } +// SLIPPITODO: refactor with c++17 std::filesystem? +std::string GetHomeDirectory() +{ + std::string homeDir; +#ifdef _WIN32 + wchar_t* path = nullptr; + + if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Documents, 0, nullptr, &path))) { + char pathStr[MAX_PATH]; + wcstombs(pathStr, path, MAX_PATH); + + homeDir = std::string(pathStr); + CoTaskMemFree(path); + } + else { + const char* home = getenv("USERPROFILE"); + homeDir = std::string(home) + "\\Documents"; + } +#else + const char* home = getenv("HOME"); + homeDir = std::string(home); +#endif + + return homeDir; +} + std::string GetExeDirectory() { std::string exe_path = GetExePath(); @@ -736,16 +786,22 @@ std::string GetSysDirectory() #endif #if defined(__APPLE__) - sysDir = GetBundleDirectory() + DIR_SEP + SYSDATA_DIR; + sysDir = GetBundleDirectory() + DIR_SEP + SYSDATA_DIR + DIR_SEP; #elif defined(_WIN32) || defined(LINUX_LOCAL_DEV) - sysDir = GetExeDirectory() + DIR_SEP + SYSDATA_DIR; + sysDir = GetExeDirectory() + DIR_SEP + SYSDATA_DIR + DIR_SEP; #elif defined ANDROID sysDir = s_android_sys_directory; ASSERT_MSG(COMMON, !sysDir.empty(), "Sys directory has not been set"); #else - sysDir = SYSDATA_DIR; + const char* home = getenv("HOME"); + if (!home) home = getenv("PWD"); + if (!home) home = ""; + std::string home_path = std::string(home) + DIR_SEP; + const char* config_home = getenv("XDG_CONFIG_HOME"); + sysDir = std::string(config_home && config_home[0] == '/' + ? config_home : (home_path + ".config")) + + DIR_SEP DOLPHIN_DATA_DIR DIR_SEP "Sys" DIR_SEP; #endif - sysDir += DIR_SEP; INFO_LOG(COMMON, "GetSysDirectory: Setting to %s:", sysDir.c_str()); return sysDir; diff --git a/Source/Core/Common/FileUtil.h b/Source/Core/Common/FileUtil.h index 2c13ae07c0..0f451a19ec 100644 --- a/Source/Core/Common/FileUtil.h +++ b/Source/Core/Common/FileUtil.h @@ -163,6 +163,9 @@ bool DeleteDirRecursively(const std::string& directory); // Returns the current directory std::string GetCurrentDir(); +// Gets the last modified time of a file +u64 GetFileModTime(const std::string& path); + // Create directory and copy contents (optionally overwrites existing files) void CopyDir(const std::string& source_path, const std::string& dest_path, bool destructive = false); @@ -200,6 +203,7 @@ std::string GetBundleDirectory(); std::string GetExePath(); std::string GetExeDirectory(); +std::string GetHomeDirectory(); bool WriteStringToFile(const std::string& filename, std::string_view str); bool ReadFileToString(const std::string& filename, std::string& str); diff --git a/Source/Core/Common/Version.h b/Source/Core/Common/Version.h index 50c25d1dd4..07f0b958cf 100644 --- a/Source/Core/Common/Version.h +++ b/Source/Core/Common/Version.h @@ -15,4 +15,5 @@ extern const std::string scm_rev_str; extern const std::string scm_rev_git_str; extern const std::string scm_distributor_str; extern const std::string netplay_dolphin_ver; +extern const std::string scm_slippi_semver_str; } // namespace Common