1
0
mirror of https://git.suyu.dev/suyu/suyu synced 2025-09-02 01:16:32 -05:00

Rebrand Common FS Path functions

This commit is contained in:
JuanCStar
2024-03-07 09:21:59 +00:00
committed by Crimson Hawk
parent e8f646b0fd
commit 16dfc39f89
97 changed files with 347 additions and 369 deletions

View File

@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2018 yuzu Emulator Project
# SPDX-FileCopyrightText: 2018 yuzu Emulator Project & 2024 suyu Emulator Project
# SPDX-License-Identifier: GPL-2.0-or-later
if (DEFINED ENV{AZURECIREPO})
@@ -161,8 +161,8 @@ add_library(common STATIC
zstd_compression.h
)
if (YUZU_ENABLE_PORTABLE)
add_compile_definitions(YUZU_ENABLE_PORTABLE)
if (SUYU_ENABLE_PORTABLE)
add_compile_definitions(SUYU_ENABLE_PORTABLE)
endif()
if (WIN32)

View File

@@ -1,14 +1,14 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project & 2024 suyu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
// yuzu data directories
// suyu data directories
#define YUZU_DIR "suyu"
#define SUYU_DIR "suyu"
#define PORTABLE_DIR "user"
// Sub-directories contained within a yuzu data directory
// Sub-directories contained within a suyu data directory
#define AMIIBO_DIR "amiibo"
#define CACHE_DIR "cache"
@@ -26,6 +26,6 @@
#define TAS_DIR "tas"
#define ICONS_DIR "icons"
// yuzu-specific files
// suyu-specific files
#define LOG_FILE "suyu_log.txt"

View File

@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project & 2024 suyu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <algorithm>
@@ -56,10 +56,10 @@ namespace fs = std::filesystem;
/**
* The PathManagerImpl is a singleton allowing to manage the mapping of
* YuzuPath enums to real filesystem paths.
* This class provides 2 functions: GetYuzuPathImpl and SetYuzuPathImpl.
* These are used by GetYuzuPath and SetYuzuPath respectively to get or modify
* the path mapped by the YuzuPath enum.
* SuyuPath enums to real filesystem paths.
* This class provides 2 functions: GetSuyuPathImpl and SetSuyuPathImpl.
* These are used by GetSuyuPath and SetSuyuPath respectively to get or modify
* the path mapped by the SuyuPath enum.
*/
class PathManagerImpl {
public:
@@ -75,62 +75,62 @@ public:
PathManagerImpl(PathManagerImpl&&) = delete;
PathManagerImpl& operator=(PathManagerImpl&&) = delete;
[[nodiscard]] const fs::path& GetYuzuPathImpl(YuzuPath yuzu_path) {
return yuzu_paths.at(yuzu_path);
[[nodiscard]] const fs::path& GetSuyuPathImpl(SuyuPath suyu_path) {
return suyu_paths.at(suyu_path);
}
void SetYuzuPathImpl(YuzuPath yuzu_path, const fs::path& new_path) {
yuzu_paths.insert_or_assign(yuzu_path, new_path);
void SetSuyuPathImpl(SuyuPath suyu_path, const fs::path& new_path) {
suyu_paths.insert_or_assign(suyu_path, new_path);
}
void Reinitialize(fs::path yuzu_path = {}) {
fs::path yuzu_path_cache;
fs::path yuzu_path_config;
void Reinitialize(fs::path suyu_path = {}) {
fs::path suyu_path_cache;
fs::path suyu_path_config;
#ifdef _WIN32
#ifdef YUZU_ENABLE_PORTABLE
yuzu_path = GetExeDirectory() / PORTABLE_DIR;
#ifdef SUYU_ENABLE_PORTABLE
suyu_path = GetExeDirectory() / PORTABLE_DIR;
#endif
if (!IsDir(yuzu_path)) {
yuzu_path = GetAppDataRoamingDirectory() / YUZU_DIR;
if (!IsDir(suyu_path)) {
suyu_path = GetAppDataRoamingDirectory() / SUYU_DIR;
}
yuzu_path_cache = yuzu_path / CACHE_DIR;
yuzu_path_config = yuzu_path / CONFIG_DIR;
suyu_path_cache = suyu_path / CACHE_DIR;
suyu_path_config = suyu_path / CONFIG_DIR;
#elif ANDROID
ASSERT(!yuzu_path.empty());
yuzu_path_cache = yuzu_path / CACHE_DIR;
yuzu_path_config = yuzu_path / CONFIG_DIR;
ASSERT(!suyu_path.empty());
suyu_path_cache = suyu_path / CACHE_DIR;
suyu_path_config = suyu_path / CONFIG_DIR;
#else
#ifdef YUZU_ENABLE_PORTABLE
yuzu_path = GetCurrentDir() / PORTABLE_DIR;
#ifdef SUYU_ENABLE_PORTABLE
suyu_path = GetCurrentDir() / PORTABLE_DIR;
#endif
if (Exists(yuzu_path) && IsDir(yuzu_path)) {
yuzu_path_cache = yuzu_path / CACHE_DIR;
yuzu_path_config = yuzu_path / CONFIG_DIR;
if (Exists(suyu_path) && IsDir(suyu_path)) {
suyu_path_cache = suyu_path / CACHE_DIR;
suyu_path_config = suyu_path / CONFIG_DIR;
} else {
yuzu_path = GetDataDirectory("XDG_DATA_HOME") / YUZU_DIR;
yuzu_path_cache = GetDataDirectory("XDG_CACHE_HOME") / YUZU_DIR;
yuzu_path_config = GetDataDirectory("XDG_CONFIG_HOME") / YUZU_DIR;
suyu_path = GetDataDirectory("XDG_DATA_HOME") / SUYU_DIR;
suyu_path_cache = GetDataDirectory("XDG_CACHE_HOME") / SUYU_DIR;
suyu_path_config = GetDataDirectory("XDG_CONFIG_HOME") / SUYU_DIR;
}
#endif
GenerateYuzuPath(YuzuPath::YuzuDir, yuzu_path);
GenerateYuzuPath(YuzuPath::AmiiboDir, yuzu_path / AMIIBO_DIR);
GenerateYuzuPath(YuzuPath::CacheDir, yuzu_path_cache);
GenerateYuzuPath(YuzuPath::ConfigDir, yuzu_path_config);
GenerateYuzuPath(YuzuPath::CrashDumpsDir, yuzu_path / CRASH_DUMPS_DIR);
GenerateYuzuPath(YuzuPath::DumpDir, yuzu_path / DUMP_DIR);
GenerateYuzuPath(YuzuPath::KeysDir, yuzu_path / KEYS_DIR);
GenerateYuzuPath(YuzuPath::LoadDir, yuzu_path / LOAD_DIR);
GenerateYuzuPath(YuzuPath::LogDir, yuzu_path / LOG_DIR);
GenerateYuzuPath(YuzuPath::NANDDir, yuzu_path / NAND_DIR);
GenerateYuzuPath(YuzuPath::PlayTimeDir, yuzu_path / PLAY_TIME_DIR);
GenerateYuzuPath(YuzuPath::ScreenshotsDir, yuzu_path / SCREENSHOTS_DIR);
GenerateYuzuPath(YuzuPath::SDMCDir, yuzu_path / SDMC_DIR);
GenerateYuzuPath(YuzuPath::ShaderDir, yuzu_path / SHADER_DIR);
GenerateYuzuPath(YuzuPath::TASDir, yuzu_path / TAS_DIR);
GenerateYuzuPath(YuzuPath::IconsDir, yuzu_path / ICONS_DIR);
GenerateSuyuPath(SuyuPath::SuyuDir, suyu_path);
GenerateSuyuPath(SuyuPath::AmiiboDir, suyu_path / AMIIBO_DIR);
GenerateSuyuPath(SuyuPath::CacheDir, suyu_path_cache);
GenerateSuyuPath(SuyuPath::ConfigDir, suyu_path_config);
GenerateSuyuPath(SuyuPath::CrashDumpsDir, suyu_path / CRASH_DUMPS_DIR);
GenerateSuyuPath(SuyuPath::DumpDir, suyu_path / DUMP_DIR);
GenerateSuyuPath(SuyuPath::KeysDir, suyu_path / KEYS_DIR);
GenerateSuyuPath(SuyuPath::LoadDir, suyu_path / LOAD_DIR);
GenerateSuyuPath(SuyuPath::LogDir, suyu_path / LOG_DIR);
GenerateSuyuPath(SuyuPath::NANDDir, suyu_path / NAND_DIR);
GenerateSuyuPath(SuyuPath::PlayTimeDir, suyu_path / PLAY_TIME_DIR);
GenerateSuyuPath(SuyuPath::ScreenshotsDir, suyu_path / SCREENSHOTS_DIR);
GenerateSuyuPath(SuyuPath::SDMCDir, suyu_path / SDMC_DIR);
GenerateSuyuPath(SuyuPath::ShaderDir, suyu_path / SHADER_DIR);
GenerateSuyuPath(SuyuPath::TASDir, suyu_path / TAS_DIR);
GenerateSuyuPath(SuyuPath::IconsDir, suyu_path / ICONS_DIR);
}
private:
@@ -140,13 +140,13 @@ private:
~PathManagerImpl() = default;
void GenerateYuzuPath(YuzuPath yuzu_path, const fs::path& new_path) {
void GenerateSuyuPath(SuyuPath suyu_path, const fs::path& new_path) {
void(FS::CreateDir(new_path));
SetYuzuPathImpl(yuzu_path, new_path);
SetSuyuPathImpl(suyu_path, new_path);
}
std::unordered_map<YuzuPath, fs::path> yuzu_paths;
std::unordered_map<SuyuPath, fs::path> suyu_paths;
};
bool ValidatePath(const fs::path& path) {
@@ -230,22 +230,22 @@ void SetAppDirectory(const std::string& app_directory) {
PathManagerImpl::GetInstance().Reinitialize(app_directory);
}
const fs::path& GetYuzuPath(YuzuPath yuzu_path) {
return PathManagerImpl::GetInstance().GetYuzuPathImpl(yuzu_path);
const fs::path& GetSuyuPath(SuyuPath suyu_path) {
return PathManagerImpl::GetInstance().GetSuyuPathImpl(suyu_path);
}
std::string GetYuzuPathString(YuzuPath yuzu_path) {
return PathToUTF8String(GetYuzuPath(yuzu_path));
std::string GetSuyuPathString(SuyuPath suyu_path) {
return PathToUTF8String(GetSuyuPath(suyu_path));
}
void SetYuzuPath(YuzuPath yuzu_path, const fs::path& new_path) {
void SetSuyuPath(SuyuPath suyu_path, const fs::path& new_path) {
if (!FS::IsDir(new_path)) {
LOG_ERROR(Common_Filesystem, "Filesystem object at new_path={} is not a directory",
PathToUTF8String(new_path));
return;
}
PathManagerImpl::GetInstance().SetYuzuPathImpl(yuzu_path, new_path);
PathManagerImpl::GetInstance().SetSuyuPathImpl(suyu_path, new_path);
}
#ifdef _WIN32

View File

@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project & 2024 suyu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
@@ -10,8 +10,8 @@
namespace Common::FS {
enum class YuzuPath {
YuzuDir, // Where yuzu stores its data.
enum class SuyuPath {
SuyuDir, // Where suyu stores its data.
AmiiboDir, // Where Amiibo backups are stored.
CacheDir, // Where cached filesystem data is stored.
ConfigDir, // Where config files are stored.
@@ -22,7 +22,7 @@ enum class YuzuPath {
LogDir, // Where log files are stored.
NANDDir, // Where the emulated NAND is stored.
PlayTimeDir, // Where play time data is stored.
ScreenshotsDir, // Where yuzu screenshots are stored.
ScreenshotsDir, // Where suyu screenshots are stored.
SDMCDir, // Where the emulated SDMC is stored.
ShaderDir, // Where shaders are stored.
TASDir, // Where TAS scripts are stored.
@@ -193,39 +193,39 @@ template <typename Path>
void SetAppDirectory(const std::string& app_directory);
/**
* Gets the filesystem path associated with the YuzuPath enum.
* Gets the filesystem path associated with the SuyuPath enum.
*
* @param yuzu_path YuzuPath enum
* @param suyu_path SuyuPath enum
*
* @returns The filesystem path associated with the YuzuPath enum.
* @returns The filesystem path associated with the SuyuPath enum.
*/
[[nodiscard]] const std::filesystem::path& GetYuzuPath(YuzuPath yuzu_path);
[[nodiscard]] const std::filesystem::path& GetSuyuPath(SuyuPath suyu_path);
/**
* Gets the filesystem path associated with the YuzuPath enum as a UTF-8 encoded std::string.
* Gets the filesystem path associated with the SuyuPath enum as a UTF-8 encoded std::string.
*
* @param yuzu_path YuzuPath enum
* @param suyu_path SuyuPath enum
*
* @returns The filesystem path associated with the YuzuPath enum as a UTF-8 encoded std::string.
* @returns The filesystem path associated with the SuyuPath enum as a UTF-8 encoded std::string.
*/
[[nodiscard]] std::string GetYuzuPathString(YuzuPath yuzu_path);
[[nodiscard]] std::string GetSuyuPathString(SuyuPath suyu_path);
/**
* Sets a new filesystem path associated with the YuzuPath enum.
* Sets a new filesystem path associated with the SuyuPath enum.
* If the filesystem object at new_path is not a directory, this function will not do anything.
*
* @param yuzu_path YuzuPath enum
* @param suyu_path SuyuPath enum
* @param new_path New filesystem path
*/
void SetYuzuPath(YuzuPath yuzu_path, const std::filesystem::path& new_path);
void SetSuyuPath(SuyuPath suyu_path, const std::filesystem::path& new_path);
#ifdef _WIN32
template <typename Path>
void SetYuzuPath(YuzuPath yuzu_path, const Path& new_path) {
void SetSuyuPath(SuyuPath suyu_path, const Path& new_path) {
if constexpr (IsChar<typename Path::value_type>) {
SetYuzuPath(yuzu_path, ToU8String(new_path));
SetSuyuPath(suyu_path, ToU8String(new_path));
} else {
SetYuzuPath(yuzu_path, std::filesystem::path{new_path});
SetSuyuPath(suyu_path, std::filesystem::path{new_path});
}
}
#endif
@@ -257,14 +257,14 @@ void SetYuzuPath(YuzuPath yuzu_path, const Path& new_path) {
[[nodiscard]] std::filesystem::path GetHomeDirectory();
/**
* Gets the relevant paths for yuzu to store its data based on the given XDG environment variable.
* Gets the relevant paths for suyu to store its data based on the given XDG environment variable.
* See https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
* Defaults to $HOME/.local/share for main application data,
* $HOME/.cache for cached data, and $HOME/.config for configuration files.
*
* @param env_name XDG environment variable name
*
* @returns The path where yuzu should store its data.
* @returns The path where suyu should store its data.
*/
[[nodiscard]] std::filesystem::path GetDataDirectory(const std::string& env_name);
@@ -288,11 +288,11 @@ enum class DirectorySeparator {
};
// Splits the path on '/' or '\' and put the components into a vector
// i.e. "C:\Users\Yuzu\Documents\save.bin" becomes {"C:", "Users", "Yuzu", "Documents", "save.bin" }
// i.e. "C:\Users\Suyu\Documents\save.bin" becomes {"C:", "Users", "Suyu", "Documents", "save.bin" }
[[nodiscard]] std::vector<std::string_view> SplitPathComponents(std::string_view filename);
// Splits the path on '/' or '\' and put the components into a vector
// i.e. "C:\Users\Yuzu\Documents\save.bin" becomes {"C:", "Users", "Yuzu", "Documents", "save.bin" }
// i.e. "C:\Users\Suyu\Documents\save.bin" becomes {"C:", "Users", "Suyu", "Documents", "save.bin" }
[[nodiscard]] std::vector<std::string> SplitPathComponentsCopy(std::string_view filename);
// Removes trailing slash, makes all '\\' into '/', and removes duplicate '/'. Makes '/' into '\\'

View File

@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2014 Citra Emulator Project
// SPDX-FileCopyrightText: 2014 Citra Emulator Project & 2024 suyu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <atomic>
@@ -195,7 +195,7 @@ public:
return;
}
using namespace Common::FS;
const auto& log_dir = GetYuzuPath(YuzuPath::LogDir);
const auto& log_dir = GetSuyuPath(SuyuPath::LogDir);
void(CreateDir(log_dir));
Filter filter;
filter.ParseFilterString(Settings::values.log_filter.GetValue());

View File

@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project & 2024 suyu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <cstdlib>
@@ -14,7 +14,7 @@ namespace Common {
void ConfigureNvidiaEnvironmentFlags() {
#ifdef _WIN32
const auto nvidia_shader_dir =
Common::FS::GetYuzuPath(Common::FS::YuzuPath::ShaderDir) / "nvidia";
Common::FS::GetSuyuPath(Common::FS::SuyuPath::ShaderDir) / "nvidia";
if (!Common::FS::CreateDirs(nvidia_shader_dir)) {
return;

View File

@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project & 2024 suyu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <version>
@@ -130,11 +130,11 @@ void LogSettings() {
log_setting(name, setting->Canonicalize());
}
}
log_path("DataStorage_CacheDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir));
log_path("DataStorage_ConfigDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::ConfigDir));
log_path("DataStorage_LoadDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::LoadDir));
log_path("DataStorage_NANDDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir));
log_path("DataStorage_SDMCDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::SDMCDir));
log_path("DataStorage_CacheDir", Common::FS::GetSuyuPath(Common::FS::SuyuPath::CacheDir));
log_path("DataStorage_ConfigDir", Common::FS::GetSuyuPath(Common::FS::SuyuPath::ConfigDir));
log_path("DataStorage_LoadDir", Common::FS::GetSuyuPath(Common::FS::SuyuPath::LoadDir));
log_path("DataStorage_NANDDir", Common::FS::GetSuyuPath(Common::FS::SuyuPath::NANDDir));
log_path("DataStorage_SDMCDir", Common::FS::GetSuyuPath(Common::FS::SuyuPath::SDMCDir));
}
void UpdateGPUAccuracy() {