diff options
-rw-r--r-- | src/common/common_funcs.h | 25 | ||||
-rw-r--r-- | src/common/fs/fs_util.cpp | 14 | ||||
-rw-r--r-- | src/common/fs/fs_util.h | 33 | ||||
-rw-r--r-- | src/common/fs/path_util.cpp | 6 | ||||
-rw-r--r-- | src/common/fs/path_util.h | 9 | ||||
-rw-r--r-- | src/core/hle/result.h | 25 | ||||
-rw-r--r-- | src/yuzu/configuration/config.cpp | 4 | ||||
-rw-r--r-- | src/yuzu/configuration/config.h | 4 | ||||
-rw-r--r-- | src/yuzu/configuration/configure_per_game.cpp | 9 | ||||
-rw-r--r-- | src/yuzu/configuration/configure_per_game.h | 3 | ||||
-rw-r--r-- | src/yuzu/game_list.cpp | 8 | ||||
-rw-r--r-- | src/yuzu/game_list.h | 3 | ||||
-rw-r--r-- | src/yuzu/main.cpp | 21 | ||||
-rw-r--r-- | src/yuzu/main.h | 5 |
14 files changed, 107 insertions, 62 deletions
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 17d1ee86b..53bd7da60 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h @@ -97,17 +97,6 @@ __declspec(dllimport) void __stdcall DebugBreak(void); return static_cast<T>(key) == 0; \ } -/// Evaluates a boolean expression, and returns a result unless that expression is true. -#define R_UNLESS(expr, res) \ - { \ - if (!(expr)) { \ - if (res.IsError()) { \ - LOG_ERROR(Kernel, "Failed with result: {}", res.raw); \ - } \ - return res; \ - } \ - } - #define YUZU_NON_COPYABLE(cls) \ cls(const cls&) = delete; \ cls& operator=(const cls&) = delete @@ -116,20 +105,6 @@ __declspec(dllimport) void __stdcall DebugBreak(void); cls(cls&&) = delete; \ cls& operator=(cls&&) = delete -#define R_SUCCEEDED(res) (res.IsSuccess()) - -/// Evaluates an expression that returns a result, and returns the result if it would fail. -#define R_TRY(res_expr) \ - { \ - const auto _tmp_r_try_rc = (res_expr); \ - if (_tmp_r_try_rc.IsError()) { \ - return _tmp_r_try_rc; \ - } \ - } - -/// Evaluates a boolean expression, and succeeds if that expression is true. -#define R_SUCCEED_IF(expr) R_UNLESS(!(expr), RESULT_SUCCESS) - namespace Common { [[nodiscard]] constexpr u32 MakeMagic(char a, char b, char c, char d) { diff --git a/src/common/fs/fs_util.cpp b/src/common/fs/fs_util.cpp index 0ddfc3131..357cf5855 100644 --- a/src/common/fs/fs_util.cpp +++ b/src/common/fs/fs_util.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include <algorithm> + #include "common/fs/fs_util.h" namespace Common::FS { @@ -10,4 +12,16 @@ std::u8string ToU8String(std::string_view utf8_string) { return std::u8string{utf8_string.begin(), utf8_string.end()}; } +std::u8string BufferToU8String(std::span<const u8> buffer) { + return std::u8string{buffer.begin(), std::ranges::find(buffer, u8{0})}; +} + +std::string ToUTF8String(std::u8string_view u8_string) { + return std::string{u8_string.begin(), u8_string.end()}; +} + +std::string PathToUTF8String(const std::filesystem::path& path) { + return ToUTF8String(path.u8string()); +} + } // namespace Common::FS diff --git a/src/common/fs/fs_util.h b/src/common/fs/fs_util.h index 951df53b6..ec9950ee7 100644 --- a/src/common/fs/fs_util.h +++ b/src/common/fs/fs_util.h @@ -5,9 +5,13 @@ #pragma once #include <concepts> +#include <filesystem> +#include <span> #include <string> #include <string_view> +#include "common/common_types.h" + namespace Common::FS { template <typename T> @@ -22,4 +26,33 @@ concept IsChar = std::same_as<T, char>; */ [[nodiscard]] std::u8string ToU8String(std::string_view utf8_string); +/** + * Converts a buffer of bytes to a UTF8-encoded std::u8string. + * This converts from the start of the buffer until the first encountered null-terminator. + * If no null-terminator is found, this converts the entire buffer instead. + * + * @param buffer Buffer of bytes + * + * @returns UTF-8 encoded std::u8string. + */ +[[nodiscard]] std::u8string BufferToU8String(std::span<const u8> buffer); + +/** + * Converts a std::u8string or std::u8string_view to a UTF-8 encoded std::string. + * + * @param u8_string UTF-8 encoded u8string + * + * @returns UTF-8 encoded std::string. + */ +[[nodiscard]] std::string ToUTF8String(std::u8string_view u8_string); + +/** + * Converts a filesystem path to a UTF-8 encoded std::string. + * + * @param path Filesystem path + * + * @returns UTF-8 encoded std::string. + */ +[[nodiscard]] std::string PathToUTF8String(const std::filesystem::path& path); + } // namespace Common::FS diff --git a/src/common/fs/path_util.cpp b/src/common/fs/path_util.cpp index 8b732a21c..6cdd14f13 100644 --- a/src/common/fs/path_util.cpp +++ b/src/common/fs/path_util.cpp @@ -129,12 +129,6 @@ private: std::unordered_map<YuzuPath, fs::path> yuzu_paths; }; -std::string PathToUTF8String(const fs::path& path) { - const auto utf8_string = path.u8string(); - - return std::string{utf8_string.begin(), utf8_string.end()}; -} - bool ValidatePath(const fs::path& path) { if (path.empty()) { LOG_ERROR(Common_Filesystem, "Input path is empty, path={}", PathToUTF8String(path)); diff --git a/src/common/fs/path_util.h b/src/common/fs/path_util.h index a9fadbceb..14e8c35d7 100644 --- a/src/common/fs/path_util.h +++ b/src/common/fs/path_util.h @@ -26,15 +26,6 @@ enum class YuzuPath { }; /** - * Converts a filesystem path to a UTF-8 encoded std::string. - * - * @param path Filesystem path - * - * @returns UTF-8 encoded std::string. - */ -[[nodiscard]] std::string PathToUTF8String(const std::filesystem::path& path); - -/** * Validates a given path. * * A given path is valid if it meets these conditions: diff --git a/src/core/hle/result.h b/src/core/hle/result.h index 43968386f..df3283fe3 100644 --- a/src/core/hle/result.h +++ b/src/core/hle/result.h @@ -358,3 +358,28 @@ ResultVal<std::remove_reference_t<Arg>> MakeResult(Arg&& arg) { return CONCAT2(check_result_L, __LINE__); \ } \ } while (false) + +#define R_SUCCEEDED(res) (res.IsSuccess()) + +/// Evaluates a boolean expression, and succeeds if that expression is true. +#define R_SUCCEED_IF(expr) R_UNLESS(!(expr), RESULT_SUCCESS) + +/// Evaluates a boolean expression, and returns a result unless that expression is true. +#define R_UNLESS(expr, res) \ + { \ + if (!(expr)) { \ + if (res.IsError()) { \ + LOG_ERROR(Kernel, "Failed with result: {}", res.raw); \ + } \ + return res; \ + } \ + } + +/// Evaluates an expression that returns a result, and returns the result if it would fail. +#define R_TRY(res_expr) \ + { \ + const auto _tmp_r_try_rc = (res_expr); \ + if (_tmp_r_try_rc.IsError()) { \ + return _tmp_r_try_rc; \ + } \ + } diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index eb58bfa5b..552454acf 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -16,7 +16,7 @@ namespace FS = Common::FS; -Config::Config(const std::string& config_name, ConfigType config_type) : type(config_type) { +Config::Config(std::string_view config_name, ConfigType config_type) : type(config_type) { global = config_type == ConfigType::GlobalConfig; Initialize(config_name); @@ -242,7 +242,7 @@ const std::array<UISettings::Shortcut, 17> Config::default_hotkeys{{ }}; // clang-format on -void Config::Initialize(const std::string& config_name) { +void Config::Initialize(std::string_view config_name) { const auto fs_config_loc = FS::GetYuzuPath(FS::YuzuPath::ConfigDir); const auto config_file = fmt::format("{}.ini", config_name); diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h index ce3355588..114a2eaa7 100644 --- a/src/yuzu/configuration/config.h +++ b/src/yuzu/configuration/config.h @@ -22,7 +22,7 @@ public: InputProfile, }; - explicit Config(const std::string& config_name = "qt-config", + explicit Config(std::string_view config_name = "qt-config", ConfigType config_type = ConfigType::GlobalConfig); ~Config(); @@ -45,7 +45,7 @@ public: static const std::array<UISettings::Shortcut, 17> default_hotkeys; private: - void Initialize(const std::string& config_name); + void Initialize(std::string_view config_name); void ReadValues(); void ReadPlayerValue(std::size_t player_index); diff --git a/src/yuzu/configuration/configure_per_game.cpp b/src/yuzu/configuration/configure_per_game.cpp index d89f1ad4b..7dfcf150c 100644 --- a/src/yuzu/configuration/configure_per_game.cpp +++ b/src/yuzu/configuration/configure_per_game.cpp @@ -4,6 +4,7 @@ #include <algorithm> #include <memory> +#include <string> #include <utility> #include <QAbstractButton> @@ -17,6 +18,7 @@ #include <QTimer> #include <QTreeView> +#include "common/fs/path_util.h" #include "core/core.h" #include "core/file_sys/control_metadata.h" #include "core/file_sys/patch_manager.h" @@ -29,10 +31,11 @@ #include "yuzu/uisettings.h" #include "yuzu/util/util.h" -ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id) +ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id, std::string_view file_name) : QDialog(parent), ui(std::make_unique<Ui::ConfigurePerGame>()), title_id(title_id) { - game_config = std::make_unique<Config>(fmt::format("{:016X}", title_id), - Config::ConfigType::PerGameConfig); + const auto config_file_name = + title_id == 0 ? Common::FS::GetFilename(file_name) : fmt::format("{:016X}", title_id); + game_config = std::make_unique<Config>(config_file_name, Config::ConfigType::PerGameConfig); Settings::SetConfiguringGlobal(false); diff --git a/src/yuzu/configuration/configure_per_game.h b/src/yuzu/configuration/configure_per_game.h index f6e6ab7c4..dc6b68763 100644 --- a/src/yuzu/configuration/configure_per_game.h +++ b/src/yuzu/configuration/configure_per_game.h @@ -5,6 +5,7 @@ #pragma once #include <memory> +#include <string> #include <vector> #include <QDialog> @@ -27,7 +28,7 @@ class ConfigurePerGame : public QDialog { Q_OBJECT public: - explicit ConfigurePerGame(QWidget* parent, u64 title_id); + explicit ConfigurePerGame(QWidget* parent, u64 title_id, std::string_view file_name); ~ConfigurePerGame() override; /// Save all button configurations to settings file diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp index 5fe4604e0..25bb066c9 100644 --- a/src/yuzu/game_list.cpp +++ b/src/yuzu/game_list.cpp @@ -558,11 +558,11 @@ void GameList::AddGamePopup(QMenu& context_menu, u64 program_id, const std::stri connect(remove_dlc, &QAction::triggered, [this, program_id]() { emit RemoveInstalledEntryRequested(program_id, InstalledEntryType::AddOnContent); }); - connect(remove_shader_cache, &QAction::triggered, [this, program_id]() { - emit RemoveFileRequested(program_id, GameListRemoveTarget::ShaderCache); + connect(remove_shader_cache, &QAction::triggered, [this, program_id, path]() { + emit RemoveFileRequested(program_id, GameListRemoveTarget::ShaderCache, path); }); - connect(remove_custom_config, &QAction::triggered, [this, program_id]() { - emit RemoveFileRequested(program_id, GameListRemoveTarget::CustomConfiguration); + connect(remove_custom_config, &QAction::triggered, [this, program_id, path]() { + emit RemoveFileRequested(program_id, GameListRemoveTarget::CustomConfiguration, path); }); connect(dump_romfs, &QAction::triggered, [this, program_id, path]() { emit DumpRomFSRequested(program_id, path); }); diff --git a/src/yuzu/game_list.h b/src/yuzu/game_list.h index 9c0a1a482..2867f6653 100644 --- a/src/yuzu/game_list.h +++ b/src/yuzu/game_list.h @@ -88,7 +88,8 @@ signals: const std::string& game_path); void OpenTransferableShaderCacheRequested(u64 program_id); void RemoveInstalledEntryRequested(u64 program_id, InstalledEntryType type); - void RemoveFileRequested(u64 program_id, GameListRemoveTarget target); + void RemoveFileRequested(u64 program_id, GameListRemoveTarget target, + std::string_view game_path); void DumpRomFSRequested(u64 program_id, const std::string& game_path); void CopyTIDRequested(u64 program_id); void NavigateToGamedbEntryRequested(u64 program_id, diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 0f0e228b0..dd8dd3233 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -1334,7 +1334,10 @@ void GMainWindow::BootGame(const QString& filename, std::size_t program_index) { if (!(loader == nullptr || loader->ReadProgramId(title_id) != Loader::ResultStatus::Success)) { // Load per game settings - Config per_game_config(fmt::format("{:016X}", title_id), Config::ConfigType::PerGameConfig); + const auto config_file_name = title_id == 0 + ? Common::FS::GetFilename(filename.toStdString()) + : fmt::format("{:016X}", title_id); + Config per_game_config(config_file_name, Config::ConfigType::PerGameConfig); } ConfigureVibration::SetAllVibrationDevices(); @@ -1795,7 +1798,8 @@ void GMainWindow::RemoveAddOnContent(u64 program_id, const QString& entry_type) tr("Successfully removed %1 installed DLC.").arg(count)); } -void GMainWindow::OnGameListRemoveFile(u64 program_id, GameListRemoveTarget target) { +void GMainWindow::OnGameListRemoveFile(u64 program_id, GameListRemoveTarget target, + std::string_view game_path) { const QString question = [this, target] { switch (target) { case GameListRemoveTarget::ShaderCache: @@ -1817,7 +1821,7 @@ void GMainWindow::OnGameListRemoveFile(u64 program_id, GameListRemoveTarget targ RemoveTransferableShaderCache(program_id); break; case GameListRemoveTarget::CustomConfiguration: - RemoveCustomConfiguration(program_id); + RemoveCustomConfiguration(program_id, game_path); break; } } @@ -1842,9 +1846,12 @@ void GMainWindow::RemoveTransferableShaderCache(u64 program_id) { } } -void GMainWindow::RemoveCustomConfiguration(u64 program_id) { - const auto custom_config_file_path = Common::FS::GetYuzuPath(Common::FS::YuzuPath::ConfigDir) / - "custom" / fmt::format("{:016X}.ini", program_id); +void GMainWindow::RemoveCustomConfiguration(u64 program_id, std::string_view game_path) { + const auto config_file_name = program_id == 0 + ? fmt::format("{:s}.ini", Common::FS::GetFilename(game_path)) + : fmt::format("{:016X}.ini", program_id); + const auto custom_config_file_path = + Common::FS::GetYuzuPath(Common::FS::YuzuPath::ConfigDir) / "custom" / config_file_name; if (!Common::FS::Exists(custom_config_file_path)) { QMessageBox::warning(this, tr("Error Removing Custom Configuration"), @@ -2635,7 +2642,7 @@ void GMainWindow::OpenPerGameConfiguration(u64 title_id, const std::string& file const auto v_file = Core::GetGameFileFromPath(vfs, file_name); const auto& system = Core::System::GetInstance(); - ConfigurePerGame dialog(this, title_id); + ConfigurePerGame dialog(this, title_id, file_name); dialog.LoadFromFile(v_file); const auto result = dialog.exec(); diff --git a/src/yuzu/main.h b/src/yuzu/main.h index b3a5033ce..135681d41 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -236,7 +236,8 @@ private slots: const std::string& game_path); void OnTransferableShaderCacheOpenFile(u64 program_id); void OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryType type); - void OnGameListRemoveFile(u64 program_id, GameListRemoveTarget target); + void OnGameListRemoveFile(u64 program_id, GameListRemoveTarget target, + std::string_view game_path); void OnGameListDumpRomFS(u64 program_id, const std::string& game_path); void OnGameListCopyTID(u64 program_id); void OnGameListNavigateToGamedbEntry(u64 program_id, @@ -275,7 +276,7 @@ private: void RemoveUpdateContent(u64 program_id, const QString& entry_type); void RemoveAddOnContent(u64 program_id, const QString& entry_type); void RemoveTransferableShaderCache(u64 program_id); - void RemoveCustomConfiguration(u64 program_id); + void RemoveCustomConfiguration(u64 program_id, std::string_view game_path); std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id); InstallResult InstallNSPXCI(const QString& filename); InstallResult InstallNCA(const QString& filename); |