FileUtils code moved. Refactor eventually

This commit is contained in:
R2DLiu 2020-06-30 23:00:55 -04:00
commit 89275f3126
7 changed files with 78 additions and 14 deletions

View file

@ -1,7 +1,7 @@
#include "SlippiGame.h" #include "SlippiGame.h"
namespace Slippi { namespace Slippi {
// TODO: maybe refactor with std::byte and std::filesystem // SLIPPITODO: maybe refactor with std::byte and std::filesystem
//********************************************************************** //**********************************************************************
//* Event Handlers * //* Event Handlers *
@ -526,8 +526,8 @@ namespace Slippi {
#ifdef _WIN32 #ifdef _WIN32
// On Windows, we need to convert paths to std::wstring to deal with UTF-8 // 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 // SLIPPITODO: codecvt is deprecated. C++17 msvc support std::filesystem::u8path
// TODO: c++20 std::filesystem::path natively supports utf8 // SLIPPITODO: c++20 std::filesystem::path natively supports utf8
std::wstring convertedPath = std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes(path); std::wstring convertedPath = std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes(path);
result->file = std::make_unique<std::ifstream>(convertedPath, std::ios::in | std::ios::binary); result->file = std::make_unique<std::ifstream>(convertedPath, std::ios::in | std::ios::binary);
#else #else

View file

@ -15,7 +15,7 @@ Please read the [FAQ](https://dolphin-emu.org/docs/faq/) before using Dolphin.
* OS * OS
* Windows (7 SP1 or higher). * Windows (7 SP1 or higher).
* Linux. * 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. * Unix-like systems other than Linux are not officially supported but might work.
* Processor * Processor
* A CPU with SSE2 support. * 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 ## 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.
Visual Studio 2019 16.3 or later is a hard requirement. Other compilers might be Open the folder that contains the base CMakeLists.txt file to build Dolphin on Windows.
able to build Dolphin on Windows but have not been tested and are not 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. recommended to be used. Git and Windows 10 SDK must be installed when building.
Make sure to pull submodules before building: Make sure to pull submodules before building:
@ -90,7 +90,7 @@ Useful for development as root access is not required.
2. `cd Build` 2. `cd Build`
3. `cmake .. -DLINUX_LOCAL_DEV=true` 3. `cmake .. -DLINUX_LOCAL_DEV=true`
4. `make` 4. `make`
5. `ln -s ../../Data/Sys Binaries/` 5. `ln -s ../../Overwrite/{Sys,User} Binaries/`
### Linux Portable Build Steps: ### Linux Portable Build Steps:
@ -101,7 +101,7 @@ Or useful for having multiple distinct Dolphin setups for testing/development/TA
2. `cd Build` 2. `cd Build`
3. `cmake .. -DLINUX_LOCAL_DEV=true` 3. `cmake .. -DLINUX_LOCAL_DEV=true`
4. `make` 4. `make`
5. `cp -r ../Data/Sys/ Binaries/` 5. `cp -r ../Overwrite/{Sys,User} Binaries/`
6. `touch Binaries/portable.txt` 6. `touch Binaries/portable.txt`
## Building for Android ## Building for Android

View file

@ -25,7 +25,7 @@
#define NOMEDIA_FILE ".nomedia" #define NOMEDIA_FILE ".nomedia"
#else #else
#define USERDATA_DIR "user" #define USERDATA_DIR "user"
#define DOLPHIN_DATA_DIR "dolphin-emu" #define DOLPHIN_DATA_DIR "SlippiOnline"
#endif #endif
// Dirs in both User and Sys // Dirs in both User and Sys

View file

@ -10,6 +10,9 @@ namespace ENetUtil
{ {
void WakeupThread(ENetHost* host) void WakeupThread(ENetHost* host)
{ {
if (!host)
return;
// Send ourselves a spurious message. This is hackier than it should be. // Send ourselves a spurious message. This is hackier than it should be.
// comex reported this as https://github.com/lsalzman/enet/issues/23, so // 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. // hopefully there will be a better way to do it in the future.

View file

@ -30,6 +30,8 @@
#include <io.h> #include <io.h>
#include <objbase.h> // guid stuff #include <objbase.h> // guid stuff
#include <shellapi.h> #include <shellapi.h>
#include <ShlObj.h>
#include <winerror.h>
#else #else
#include <dirent.h> #include <dirent.h>
#include <errno.h> #include <errno.h>
@ -531,6 +533,28 @@ bool DeleteDirRecursively(const std::string& directory)
return success; 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) // Create directory and copy contents (does not overwrite existing files)
void CopyDir(const std::string& source_path, const std::string& dest_path, bool destructive) void CopyDir(const std::string& source_path, const std::string& dest_path, bool destructive)
{ {
@ -709,6 +733,32 @@ std::string GetExePath()
return dolphin_path; 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 GetExeDirectory()
{ {
std::string exe_path = GetExePath(); std::string exe_path = GetExePath();
@ -736,16 +786,22 @@ std::string GetSysDirectory()
#endif #endif
#if defined(__APPLE__) #if defined(__APPLE__)
sysDir = GetBundleDirectory() + DIR_SEP + SYSDATA_DIR; sysDir = GetBundleDirectory() + DIR_SEP + SYSDATA_DIR + DIR_SEP;
#elif defined(_WIN32) || defined(LINUX_LOCAL_DEV) #elif defined(_WIN32) || defined(LINUX_LOCAL_DEV)
sysDir = GetExeDirectory() + DIR_SEP + SYSDATA_DIR; sysDir = GetExeDirectory() + DIR_SEP + SYSDATA_DIR + DIR_SEP;
#elif defined ANDROID #elif defined ANDROID
sysDir = s_android_sys_directory; sysDir = s_android_sys_directory;
ASSERT_MSG(COMMON, !sysDir.empty(), "Sys directory has not been set"); ASSERT_MSG(COMMON, !sysDir.empty(), "Sys directory has not been set");
#else #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 #endif
sysDir += DIR_SEP;
INFO_LOG(COMMON, "GetSysDirectory: Setting to %s:", sysDir.c_str()); INFO_LOG(COMMON, "GetSysDirectory: Setting to %s:", sysDir.c_str());
return sysDir; return sysDir;

View file

@ -163,6 +163,9 @@ bool DeleteDirRecursively(const std::string& directory);
// Returns the current directory // Returns the current directory
std::string GetCurrentDir(); 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) // Create directory and copy contents (optionally overwrites existing files)
void CopyDir(const std::string& source_path, const std::string& dest_path, void CopyDir(const std::string& source_path, const std::string& dest_path,
bool destructive = false); bool destructive = false);
@ -200,6 +203,7 @@ std::string GetBundleDirectory();
std::string GetExePath(); std::string GetExePath();
std::string GetExeDirectory(); std::string GetExeDirectory();
std::string GetHomeDirectory();
bool WriteStringToFile(const std::string& filename, std::string_view str); bool WriteStringToFile(const std::string& filename, std::string_view str);
bool ReadFileToString(const std::string& filename, std::string& str); bool ReadFileToString(const std::string& filename, std::string& str);

View file

@ -15,4 +15,5 @@ extern const std::string scm_rev_str;
extern const std::string scm_rev_git_str; extern const std::string scm_rev_git_str;
extern const std::string scm_distributor_str; extern const std::string scm_distributor_str;
extern const std::string netplay_dolphin_ver; extern const std::string netplay_dolphin_ver;
extern const std::string scm_slippi_semver_str;
} // namespace Common } // namespace Common