Standardize game_data directory for game metadata. (#809)

This commit is contained in:
squidbus 2024-09-06 03:27:23 -07:00 committed by GitHub
parent bad3d5a68e
commit a48bfb0fa6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 17 additions and 12 deletions

View file

@ -116,6 +116,7 @@ static auto UserPaths = [] {
create_path(PathType::CheatsDir, user_dir / CHEATS_DIR); create_path(PathType::CheatsDir, user_dir / CHEATS_DIR);
create_path(PathType::PatchesDir, user_dir / PATCHES_DIR); create_path(PathType::PatchesDir, user_dir / PATCHES_DIR);
create_path(PathType::AddonsDir, user_dir / ADDONS_DIR); create_path(PathType::AddonsDir, user_dir / ADDONS_DIR);
create_path(PathType::MetaDataDir, user_dir / METADATA_DIR);
return paths; return paths;
}(); }();

View file

@ -23,6 +23,7 @@ enum class PathType {
CheatsDir, // Where cheats are stored. CheatsDir, // Where cheats are stored.
PatchesDir, // Where patches are stored. PatchesDir, // Where patches are stored.
AddonsDir, // Where additional content is stored. AddonsDir, // Where additional content is stored.
MetaDataDir, // Where game metadata (e.g. trophies and menu backgrounds) is stored.
}; };
constexpr auto PORTABLE_DIR = "user"; constexpr auto PORTABLE_DIR = "user";
@ -41,6 +42,7 @@ constexpr auto CAPTURES_DIR = "captures";
constexpr auto CHEATS_DIR = "cheats"; constexpr auto CHEATS_DIR = "cheats";
constexpr auto PATCHES_DIR = "patches"; constexpr auto PATCHES_DIR = "patches";
constexpr auto ADDONS_DIR = "addcont"; constexpr auto ADDONS_DIR = "addcont";
constexpr auto METADATA_DIR = "game_data";
// Filenames // Filenames
constexpr auto LOG_FILE = "shad_log.txt"; constexpr auto LOG_FILE = "shad_log.txt";

View file

@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include "common/path_util.h"
#include "trp.h" #include "trp.h"
TRP::TRP() = default; TRP::TRP() = default;
@ -48,8 +49,9 @@ bool TRP::Extract(const std::filesystem::path& trophyPath) {
return false; return false;
s64 seekPos = sizeof(TrpHeader); s64 seekPos = sizeof(TrpHeader);
std::filesystem::path trpFilesPath(std::filesystem::current_path() / "user/game_data" / std::filesystem::path trpFilesPath(
title / "TrophyFiles" / it.path().stem()); Common::FS::GetUserPath(Common::FS::PathType::MetaDataDir) / title / "TrophyFiles" /
it.path().stem());
std::filesystem::create_directories(trpFilesPath / "Icons"); std::filesystem::create_directories(trpFilesPath / "Icons");
std::filesystem::create_directory(trpFilesPath / "Xml"); std::filesystem::create_directory(trpFilesPath / "Xml");

View file

@ -114,8 +114,8 @@ void GameGridFrame::SetGridBackgroundImage(int row, int column) {
QWidget* item = this->cellWidget(row, column); QWidget* item = this->cellWidget(row, column);
if (item) { if (item) {
QString pic1Path = QString::fromStdString((*m_games_shared)[itemID].pic_path); QString pic1Path = QString::fromStdString((*m_games_shared)[itemID].pic_path);
const auto blurredPic1Path = Common::FS::GetUserPath(Common::FS::PathType::UserDir) / const auto blurredPic1Path = Common::FS::GetUserPath(Common::FS::PathType::MetaDataDir) /
"game_data" / (*m_games_shared)[itemID].serial / "pic1.png"; (*m_games_shared)[itemID].serial / "pic1.png";
#ifdef _WIN32 #ifdef _WIN32
const auto blurredPic1PathQt = QString::fromStdWString(blurredPic1Path.wstring()); const auto blurredPic1PathQt = QString::fromStdWString(blurredPic1Path.wstring());
#else #else
@ -128,7 +128,8 @@ void GameGridFrame::SetGridBackgroundImage(int row, int column) {
backgroundImage = m_game_list_utils.BlurImage(image, image.rect(), 16); backgroundImage = m_game_list_utils.BlurImage(image, image.rect(), 16);
std::filesystem::path img_path = std::filesystem::path img_path =
std::filesystem::path("user/game_data/") / (*m_games_shared)[itemID].serial; Common::FS::GetUserPath(Common::FS::PathType::MetaDataDir) /
(*m_games_shared)[itemID].serial;
std::filesystem::create_directories(img_path); std::filesystem::create_directories(img_path);
if (!backgroundImage.save(blurredPic1PathQt, "PNG")) { if (!backgroundImage.save(blurredPic1PathQt, "PNG")) {
// qDebug() << "Error: Unable to save image."; // qDebug() << "Error: Unable to save image.";

View file

@ -90,9 +90,8 @@ void GameListFrame::SetListBackgroundImage(QTableWidgetItem* item) {
} }
QString pic1Path = QString::fromStdString(m_game_info->m_games[item->row()].pic_path); QString pic1Path = QString::fromStdString(m_game_info->m_games[item->row()].pic_path);
const auto blurredPic1Path = Common::FS::GetUserPath(Common::FS::PathType::UserDir) / const auto blurredPic1Path = Common::FS::GetUserPath(Common::FS::PathType::MetaDataDir) /
"game_data" / m_game_info->m_games[item->row()].serial / m_game_info->m_games[item->row()].serial / "pic1.png";
"pic1.png";
#ifdef _WIN32 #ifdef _WIN32
const auto blurredPic1PathQt = QString::fromStdWString(blurredPic1Path.wstring()); const auto blurredPic1PathQt = QString::fromStdWString(blurredPic1Path.wstring());
#else #else
@ -105,7 +104,8 @@ void GameListFrame::SetListBackgroundImage(QTableWidgetItem* item) {
backgroundImage = m_game_list_utils.BlurImage(image, image.rect(), 16); backgroundImage = m_game_list_utils.BlurImage(image, image.rect(), 16);
std::filesystem::path img_path = std::filesystem::path img_path =
std::filesystem::path("user/game_data/") / m_game_info->m_games[item->row()].serial; Common::FS::GetUserPath(Common::FS::PathType::MetaDataDir) /
m_game_info->m_games[item->row()].serial;
std::filesystem::create_directories(img_path); std::filesystem::create_directories(img_path);
if (!backgroundImage.save(blurredPic1PathQt, "PNG")) { if (!backgroundImage.save(blurredPic1PathQt, "PNG")) {
// qDebug() << "Error: Unable to save image."; // qDebug() << "Error: Unable to save image.";

View file

@ -16,7 +16,6 @@ int main(int argc, char* argv[]) {
// Load configurations and initialize Qt application // Load configurations and initialize Qt application
const auto user_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir); const auto user_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
Config::load(user_dir / "config.toml"); Config::load(user_dir / "config.toml");
std::filesystem::create_directory(user_dir / "game_data");
// Check if elf or eboot.bin path was passed as a command line argument // Check if elf or eboot.bin path was passed as a command line argument
bool has_command_line_argument = argc > 1; bool has_command_line_argument = argc > 1;

View file

@ -21,11 +21,11 @@ TrophyViewer::TrophyViewer(QString trophyPath, QString gameTrpPath) : QMainWindo
void TrophyViewer::PopulateTrophyWidget(QString title) { void TrophyViewer::PopulateTrophyWidget(QString title) {
#ifdef _WIN32 #ifdef _WIN32
const auto trophyDir = Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "game_data" / const auto trophyDir = Common::FS::GetUserPath(Common::FS::PathType::MetaDataDir) /
title.toStdWString() / "TrophyFiles"; title.toStdWString() / "TrophyFiles";
const auto trophyDirQt = QString::fromStdWString(trophyDir.wstring()); const auto trophyDirQt = QString::fromStdWString(trophyDir.wstring());
#else #else
const auto trophyDir = Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "game_data" / const auto trophyDir = Common::FS::GetUserPath(Common::FS::PathType::MetaDataDir) /
title.toStdString() / "TrophyFiles"; title.toStdString() / "TrophyFiles";
const auto trophyDirQt = QString::fromStdString(trophyDir.string()); const auto trophyDirQt = QString::fromStdString(trophyDir.string());
#endif #endif