diff options
Diffstat (limited to 'src/qt_common/util/game.cpp')
| -rw-r--r-- | src/qt_common/util/game.cpp | 170 |
1 files changed, 62 insertions, 108 deletions
diff --git a/src/qt_common/util/game.cpp b/src/qt_common/util/game.cpp index 3e07b9d6b5..e037fdae6c 100644 --- a/src/qt_common/util/game.cpp +++ b/src/qt_common/util/game.cpp @@ -18,40 +18,34 @@ #include <QUrl> #ifdef _WIN32 -#include "common/scope_exit.h" -#include "common/string_util.h" #include <shlobj.h> #include <windows.h> +#include "common/scope_exit.h" +#include "common/string_util.h" #else -#include "fmt/ostream.h" #include <fstream> +#include "fmt/ostream.h" #endif namespace QtCommon::Game { -bool CreateShortcutLink(const std::filesystem::path& shortcut_path, - const std::string& comment, +bool CreateShortcutLink(const std::filesystem::path& shortcut_path, const std::string& comment, const std::filesystem::path& icon_path, - const std::filesystem::path& command, - const std::string& arguments, - const std::string& categories, - const std::string& keywords, - const std::string& name) -try { + const std::filesystem::path& command, const std::string& arguments, + const std::string& categories, const std::string& keywords, + const std::string& name) try { #ifdef _WIN32 // Windows HRESULT hr = CoInitialize(nullptr); if (FAILED(hr)) { LOG_ERROR(Frontend, "CoInitialize failed"); return false; } - SCOPE_EXIT - { + SCOPE_EXIT { CoUninitialize(); }; IShellLinkW* ps1 = nullptr; IPersistFile* persist_file = nullptr; - SCOPE_EXIT - { + SCOPE_EXIT { if (persist_file != nullptr) { persist_file->Release(); } @@ -59,10 +53,7 @@ try { ps1->Release(); } }; - HRESULT hres = CoCreateInstance(CLSID_ShellLink, - nullptr, - CLSCTX_INPROC_SERVER, - IID_IShellLinkW, + HRESULT hres = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLinkW, reinterpret_cast<void**>(&ps1)); if (FAILED(hres)) { LOG_ERROR(Frontend, "Failed to create IShellLinkW instance"); @@ -142,10 +133,8 @@ try { return false; } -bool MakeShortcutIcoPath(const u64 program_id, - const std::string_view game_file_name, - std::filesystem::path& out_icon_path) -{ +bool MakeShortcutIcoPath(const u64 program_id, const std::string_view game_file_name, + std::filesystem::path& out_icon_path) { // Get path to Yuzu icons directory & icon extension std::string ico_extension = "png"; #if defined(_WIN32) @@ -166,46 +155,38 @@ bool MakeShortcutIcoPath(const u64 program_id, return true; } -void OpenEdenFolder(const Common::FS::EdenPath& path) -{ +void OpenEdenFolder(const Common::FS::EdenPath& path) { QDesktopServices::openUrl( QUrl::fromLocalFile(QString::fromStdString(Common::FS::GetEdenPathString(path)))); } -void OpenRootDataFolder() -{ +void OpenRootDataFolder() { OpenEdenFolder(Common::FS::EdenPath::EdenDir); } -void OpenNANDFolder() -{ +void OpenNANDFolder() { OpenEdenFolder(Common::FS::EdenPath::NANDDir); } -void OpenSaveFolder() -{ - const auto path = Common::FS::GetEdenPath(Common::FS::EdenPath::NANDDir) - / "user/save/0000000000000000"; +void OpenSaveFolder() { + const auto path = + Common::FS::GetEdenPath(Common::FS::EdenPath::NANDDir) / "user/save/0000000000000000"; QDesktopServices::openUrl(QUrl::fromLocalFile(QString::fromStdString(path.string()))); } -void OpenSDMCFolder() -{ +void OpenSDMCFolder() { OpenEdenFolder(Common::FS::EdenPath::SDMCDir); } -void OpenModFolder() -{ +void OpenModFolder() { OpenEdenFolder(Common::FS::EdenPath::LoadDir); } -void OpenLogFolder() -{ +void OpenLogFolder() { OpenEdenFolder(Common::FS::EdenPath::LogDir); } -static QString GetGameListErrorRemoving(QtCommon::Game::InstalledEntryType type) -{ +static QString GetGameListErrorRemoving(QtCommon::Game::InstalledEntryType type) { switch (type) { case QtCommon::Game::InstalledEntryType::Game: return tr("Error Removing Contents"); @@ -219,10 +200,9 @@ static QString GetGameListErrorRemoving(QtCommon::Game::InstalledEntryType type) } // Game Content // -void RemoveBaseContent(u64 program_id, InstalledEntryType type) -{ - const auto res = ContentManager::RemoveBaseContent(system->GetFileSystemController(), - program_id); +void RemoveBaseContent(u64 program_id, InstalledEntryType type) { + const auto res = + ContentManager::RemoveBaseContent(system->GetFileSystemController(), program_id); if (res) { QtCommon::Frontend::Information(tr("Successfully Removed"), tr("Successfully removed the installed base game.")); @@ -234,8 +214,7 @@ void RemoveBaseContent(u64 program_id, InstalledEntryType type) } } -void RemoveUpdateContent(u64 program_id, InstalledEntryType type) -{ +void RemoveUpdateContent(u64 program_id, InstalledEntryType type) { const auto res = ContentManager::RemoveUpdate(system->GetFileSystemController(), program_id); if (res) { QtCommon::Frontend::Information(tr("Successfully Removed"), @@ -246,8 +225,7 @@ void RemoveUpdateContent(u64 program_id, InstalledEntryType type) } } -void RemoveAddOnContent(u64 program_id, InstalledEntryType type) -{ +void RemoveAddOnContent(u64 program_id, InstalledEntryType type) { const size_t count = ContentManager::RemoveAllDLC(*system, program_id); if (count == 0) { QtCommon::Frontend::Warning(GetGameListErrorRemoving(type), @@ -261,8 +239,7 @@ void RemoveAddOnContent(u64 program_id, InstalledEntryType type) // Global Content // -void RemoveTransferableShaderCache(u64 program_id, GameListRemoveTarget target) -{ +void RemoveTransferableShaderCache(u64 program_id, GameListRemoveTarget target) { const auto target_file_name = [target] { switch (target) { case GameListRemoveTarget::GlShaderCache: @@ -291,8 +268,7 @@ void RemoveTransferableShaderCache(u64 program_id, GameListRemoveTarget target) } } -void RemoveVulkanDriverPipelineCache(u64 program_id) -{ +void RemoveVulkanDriverPipelineCache(u64 program_id) { static constexpr std::string_view target_file_name = "vulkan_pipelines.bin"; const auto shader_cache_dir = Common::FS::GetEdenPath(Common::FS::EdenPath::ShaderDir); @@ -308,8 +284,7 @@ void RemoveVulkanDriverPipelineCache(u64 program_id) } } -void RemoveAllTransferableShaderCaches(u64 program_id) -{ +void RemoveAllTransferableShaderCaches(u64 program_id) { const auto shader_cache_dir = Common::FS::GetEdenPath(Common::FS::EdenPath::ShaderDir); const auto program_shader_cache_dir = shader_cache_dir / fmt::format("{:016x}", program_id); @@ -329,14 +304,13 @@ void RemoveAllTransferableShaderCaches(u64 program_id) } } -void RemoveCustomConfiguration(u64 program_id, const std::string& game_path) -{ +void RemoveCustomConfiguration(u64 program_id, const std::string& game_path) { const auto file_path = std::filesystem::path(Common::FS::ToU8String(game_path)); - const auto config_file_name - = program_id == 0 ? Common::FS::PathToUTF8String(file_path.filename()).append(".ini") - : fmt::format("{:016X}.ini", program_id); - const auto custom_config_file_path = Common::FS::GetEdenPath(Common::FS::EdenPath::ConfigDir) - / "custom" / config_file_name; + const auto config_file_name = + program_id == 0 ? Common::FS::PathToUTF8String(file_path.filename()).append(".ini") + : fmt::format("{:016X}.ini", program_id); + const auto custom_config_file_path = + Common::FS::GetEdenPath(Common::FS::EdenPath::ConfigDir) / "custom" / config_file_name; if (!Common::FS::Exists(custom_config_file_path)) { QtCommon::Frontend::Warning(tr("Error Removing Custom Configuration"), @@ -353,20 +327,14 @@ void RemoveCustomConfiguration(u64 program_id, const std::string& game_path) } } -void RemoveCacheStorage(u64 program_id) -{ +void RemoveCacheStorage(u64 program_id) { const auto nand_dir = Common::FS::GetEdenPath(Common::FS::EdenPath::NANDDir); - auto vfs_nand_dir = vfs->OpenDirectory(Common::FS::PathToUTF8String(nand_dir), - FileSys::OpenMode::Read); - - const auto cache_storage_path - = FileSys::SaveDataFactory::GetFullPath({}, - vfs_nand_dir, - FileSys::SaveDataSpaceId::User, - FileSys::SaveDataType::Cache, - 0 /* program_id */, - {}, - 0); + auto vfs_nand_dir = + vfs->OpenDirectory(Common::FS::PathToUTF8String(nand_dir), FileSys::OpenMode::Read); + + const auto cache_storage_path = FileSys::SaveDataFactory::GetFullPath( + {}, vfs_nand_dir, FileSys::SaveDataSpaceId::User, FileSys::SaveDataType::Cache, + 0 /* program_id */, {}, 0); const auto path = Common::FS::ConcatPathSafe(nand_dir, cache_storage_path); @@ -400,8 +368,7 @@ void ResetMetadata(bool show_message) { // Uhhh // // Messages in pre-defined message boxes for less code spaghetti -inline constexpr bool CreateShortcutMessagesGUI(ShortcutMessages imsg, const QString& game_title) -{ +inline constexpr bool CreateShortcutMessagesGUI(ShortcutMessages imsg, const QString& game_title) { int result = 0; using namespace QtCommon::Frontend; int buttons; @@ -433,13 +400,9 @@ inline constexpr bool CreateShortcutMessagesGUI(ShortcutMessages imsg, const QSt } } -void CreateShortcut(const std::string& game_path, - const u64 program_id, - const std::string& game_title_, - const ShortcutTarget& target, - std::string arguments_, - const bool needs_title) -{ +void CreateShortcut(const std::string& game_path, const u64 program_id, + const std::string& game_title_, const ShortcutTarget& target, + std::string arguments_, const bool needs_title) { // Get path to Eden executable std::filesystem::path command = GetEdenCommand(); @@ -453,13 +416,11 @@ void CreateShortcut(const std::string& game_path, return; } - const FileSys::PatchManager pm{program_id, - QtCommon::system->GetFileSystemController(), + const FileSys::PatchManager pm{program_id, QtCommon::system->GetFileSystemController(), QtCommon::system->GetContentProvider()}; const auto control = pm.GetControlMetadata(); - const auto loader = Loader::GetLoader(*QtCommon::system, - QtCommon::vfs->OpenFile(game_path, - FileSys::OpenMode::Read)); + const auto loader = Loader::GetLoader( + *QtCommon::system, QtCommon::vfs->OpenFile(game_path, FileSys::OpenMode::Read)); std::string game_title{game_title_}; @@ -490,8 +451,8 @@ void CreateShortcut(const std::string& game_path, LOG_WARNING(Frontend, "Could not read icon from {:s}", game_path); } - QImage icon_data = QImage::fromData(icon_image_file.data(), - static_cast<int>(icon_image_file.size())); + QImage icon_data = + QImage::fromData(icon_image_file.data(), static_cast<int>(icon_image_file.size())); std::filesystem::path out_icon_path; if (QtCommon::Game::MakeShortcutIcoPath(program_id, game_title, out_icon_path)) { if (!SaveIconToFile(out_icon_path, icon_data)) { @@ -524,39 +485,32 @@ void CreateShortcut(const std::string& game_path, const std::string categories = "Game;Emulator;Qt;"; const std::string keywords = "Switch;Nintendo;"; - if (QtCommon::Game::CreateShortcutLink(shortcut_path, - comment, - out_icon_path, - command, - arguments, - categories, - keywords, - game_title)) { + if (QtCommon::Game::CreateShortcutLink(shortcut_path, comment, out_icon_path, command, + arguments, categories, keywords, game_title)) { CreateShortcutMessagesGUI(ShortcutMessages::Success, qgame_title); return; } CreateShortcutMessagesGUI(ShortcutMessages::Failed, qgame_title); } -// TODO: You want this to be constexpr? Well too bad, clang19 doesn't believe this is a string literal -std::string GetShortcutPath(ShortcutTarget target) -{ +// TODO: You want this to be constexpr? Well too bad, clang19 doesn't believe this is a string +// literal +std::string GetShortcutPath(ShortcutTarget target) { { std::string shortcut_path{}; if (target == ShortcutTarget::Desktop) { - shortcut_path - = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).toStdString(); + shortcut_path = + QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).toStdString(); } else if (target == ShortcutTarget::Applications) { - shortcut_path - = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation).toStdString(); + shortcut_path = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + .toStdString(); } return shortcut_path; } } -void CreateHomeMenuShortcut(ShortcutTarget target) -{ +void CreateHomeMenuShortcut(ShortcutTarget target) { constexpr u64 QLaunchId = static_cast<u64>(Service::AM::AppletProgramId::QLaunch); auto bis_system = QtCommon::system->GetFileSystemController().GetSystemNANDContents(); if (!bis_system) { |
