diff --git a/src/common/config.cpp b/src/common/config.cpp index fd5514385..370a4d27a 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -35,7 +35,7 @@ static bool vkMarkers = false; static bool vkCrashDiagnostic = false; // Gui -std::string settings_install_dir = ""; +std::filesystem::path settings_install_dir = ""; u32 main_window_geometry_x = 400; u32 main_window_geometry_y = 400; u32 main_window_geometry_w = 1280; @@ -415,7 +415,8 @@ void load(const std::filesystem::path& path) { mw_themes = toml::find_or(gui, "theme", 0); m_window_size_W = toml::find_or(gui, "mw_width", 0); m_window_size_H = toml::find_or(gui, "mw_height", 0); - settings_install_dir = toml::find_or(gui, "installDir", ""); + settings_install_dir = + toml::find_or(gui, "installDir", {}); main_window_geometry_x = toml::find_or(gui, "geometry_x", 0); main_window_geometry_y = toml::find_or(gui, "geometry_y", 0); main_window_geometry_w = toml::find_or(gui, "geometry_w", 0); diff --git a/src/qt_gui/game_grid_frame.cpp b/src/qt_gui/game_grid_frame.cpp index 2b2d4ec71..e71e41fff 100644 --- a/src/qt_gui/game_grid_frame.cpp +++ b/src/qt_gui/game_grid_frame.cpp @@ -113,7 +113,8 @@ void GameGridFrame::SetGridBackgroundImage(int row, int column) { int itemID = (row * this->columnCount()) + column; QWidget* item = this->cellWidget(row, column); if (item) { - QString pic1Path = QString::fromStdString((*m_games_shared)[itemID].pic_path); + QString pic1Path; + Common::FS::PathToQString(pic1Path, (*m_games_shared)[itemID].pic_path); const auto blurredPic1Path = Common::FS::GetUserPath(Common::FS::PathType::MetaDataDir) / (*m_games_shared)[itemID].serial / "pic1.png"; QString blurredPic1PathQt; diff --git a/src/qt_gui/game_info.cpp b/src/qt_gui/game_info.cpp index 2821a0322..52aa64322 100644 --- a/src/qt_gui/game_info.cpp +++ b/src/qt_gui/game_info.cpp @@ -3,13 +3,15 @@ #include +#include "common/path_util.h" #include "game_info.h" GameInfoClass::GameInfoClass() = default; GameInfoClass::~GameInfoClass() = default; void GameInfoClass::GetGameInfo(QWidget* parent) { - QString installDir = QString::fromStdString(Config::getGameInstallDir()); + QString installDir; + Common::FS::PathToQString(installDir, Config::getGameInstallDir()); QStringList filePaths; QDir parentFolder(installDir); QFileInfoList fileList = parentFolder.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); diff --git a/src/qt_gui/game_info.h b/src/qt_gui/game_info.h index a4bcd20ee..7f60c37df 100644 --- a/src/qt_gui/game_info.h +++ b/src/qt_gui/game_info.h @@ -28,10 +28,11 @@ public: PSF psf; if (psf.Open(std::filesystem::path(game.path) / "sce_sys" / "param.sfo")) { - game.icon_path = game.path + "/sce_sys/icon0.png"; - QString iconpath = QString::fromStdString(game.icon_path); + game.icon_path = game.path / "sce_sys" / "icon0.png"; + QString iconpath; + Common::FS::PathToQString(iconpath, game.icon_path); game.icon = QImage(iconpath); - game.pic_path = game.path + "/sce_sys/pic1.png"; + game.pic_path = game.path / "sce_sys" / "pic1.png"; if (const auto title = psf.GetString("TITLE"); title.has_value()) { game.name = *title; } diff --git a/src/qt_gui/game_install_dialog.cpp b/src/qt_gui/game_install_dialog.cpp index 5f031bdec..4cfd66fb8 100644 --- a/src/qt_gui/game_install_dialog.cpp +++ b/src/qt_gui/game_install_dialog.cpp @@ -41,7 +41,9 @@ QWidget* GameInstallDialog::SetupGamesDirectory() { // Input. m_gamesDirectory = new QLineEdit(); - m_gamesDirectory->setText(QString::fromStdString(Config::getGameInstallDir())); + QString install_dir; + Common::FS::PathToQString(install_dir, Config::getGameInstallDir()); + m_gamesDirectory->setText(install_dir); m_gamesDirectory->setMinimumWidth(400); layout->addWidget(m_gamesDirectory); diff --git a/src/qt_gui/game_list_frame.cpp b/src/qt_gui/game_list_frame.cpp index f71728bc3..5551241c5 100644 --- a/src/qt_gui/game_list_frame.cpp +++ b/src/qt_gui/game_list_frame.cpp @@ -80,7 +80,9 @@ void GameListFrame::PopulateGameList() { SetTableItem(i, 4, QString::fromStdString(m_game_info->m_games[i].fw)); SetTableItem(i, 5, QString::fromStdString(m_game_info->m_games[i].size)); SetTableItem(i, 6, QString::fromStdString(m_game_info->m_games[i].version)); - SetTableItem(i, 7, QString::fromStdString(m_game_info->m_games[i].path)); + QString path; + Common::FS::PathToQString(path, m_game_info->m_games[i].path); + SetTableItem(i, 7, path); } } @@ -90,7 +92,8 @@ void GameListFrame::SetListBackgroundImage(QTableWidgetItem* item) { return; } - QString pic1Path = QString::fromStdString(m_game_info->m_games[item->row()].pic_path); + QString pic1Path; + Common::FS::PathToQString(pic1Path, m_game_info->m_games[item->row()].pic_path); const auto blurredPic1Path = Common::FS::GetUserPath(Common::FS::PathType::MetaDataDir) / m_game_info->m_games[item->row()].serial / "pic1.png"; QString blurredPic1PathQt; diff --git a/src/qt_gui/game_list_utils.h b/src/qt_gui/game_list_utils.h index 476c90035..28bcae610 100644 --- a/src/qt_gui/game_list_utils.h +++ b/src/qt_gui/game_list_utils.h @@ -3,10 +3,13 @@ #pragma once +#include "common/path_util.h" + struct GameInfo { - std::string path; // root path of game directory (normally directory that contains eboot.bin) - std::string icon_path; // path of icon0.png - std::string pic_path; // path of pic1.png + std::filesystem::path path; // root path of game directory + // (normally directory that contains eboot.bin) + std::filesystem::path icon_path; // path of icon0.png + std::filesystem::path pic_path; // path of pic1.png QImage icon; std::string size; // variables extracted from param.sfo @@ -43,7 +46,9 @@ public: } static void GetFolderSize(GameInfo& game) { - QDir dir(QString::fromStdString(game.path)); + QString dirPath; + Common::FS::PathToQString(dirPath, game.path); + QDir dir(dirPath); QDirIterator it(dir.absolutePath(), QDirIterator::Subdirectories); qint64 total = 0; while (it.hasNext()) { diff --git a/src/qt_gui/gui_context_menus.h b/src/qt_gui/gui_context_menus.h index a2f7f28ff..faefcac5d 100644 --- a/src/qt_gui/gui_context_menus.h +++ b/src/qt_gui/gui_context_menus.h @@ -74,7 +74,8 @@ public: } if (selected == &openFolder) { - QString folderPath = QString::fromStdString(m_games[itemID].path); + QString folderPath; + Common::FS::PathToQString(folderPath, m_games[itemID].path); QDesktopServices::openUrl(QUrl::fromLocalFile(folderPath)); } @@ -157,7 +158,9 @@ public: QString gameSerial = QString::fromStdString(m_games[itemID].serial); QString gameVersion = QString::fromStdString(m_games[itemID].version); QString gameSize = QString::fromStdString(m_games[itemID].size); - QPixmap gameImage(QString::fromStdString(m_games[itemID].icon_path)); + QString iconPath; + Common::FS::PathToQString(iconPath, m_games[itemID].icon_path); + QPixmap gameImage(iconPath); CheatsPatches* cheatsPatches = new CheatsPatches(gameName, gameSerial, gameVersion, gameSize, gameImage); cheatsPatches->show(); @@ -166,8 +169,9 @@ public: } if (selected == &openTrophyViewer) { - QString trophyPath = QString::fromStdString(m_games[itemID].serial); - QString gameTrpPath = QString::fromStdString(m_games[itemID].path); + QString trophyPath, gameTrpPath; + Common::FS::PathToQString(trophyPath, m_games[itemID].serial); + Common::FS::PathToQString(gameTrpPath, m_games[itemID].path); TrophyViewer* trophyViewer = new TrophyViewer(trophyPath, gameTrpPath); trophyViewer->show(); connect(widget->parent(), &QWidget::destroyed, trophyViewer, @@ -175,11 +179,13 @@ public: } if (selected == &createShortcut) { - QString targetPath = QString::fromStdString(m_games[itemID].path); + QString targetPath; + Common::FS::PathToQString(targetPath, m_games[itemID].path); QString ebootPath = targetPath + "/eboot.bin"; // Get the full path to the icon - QString iconPath = QString::fromStdString(m_games[itemID].icon_path); + QString iconPath; + Common::FS::PathToQString(iconPath, m_games[itemID].icon_path); QFileInfo iconFileInfo(iconPath); QString icoPath = iconFileInfo.absolutePath() + "/" + iconFileInfo.baseName() + ".ico"; diff --git a/src/qt_gui/main_window.cpp b/src/qt_gui/main_window.cpp index e63e5c25a..08a973c86 100644 --- a/src/qt_gui/main_window.cpp +++ b/src/qt_gui/main_window.cpp @@ -416,12 +416,14 @@ void MainWindow::CreateConnects() { .arg(" APP VERSION", -11) .arg(" Path"); for (const GameInfo& game : m_game_info->m_games) { + QString game_path; + Common::FS::PathToQString(game_path, game.path); out << QString("%1 %2 %3 %4 %5\n") .arg(QString::fromStdString(game.name), -50) .arg(QString::fromStdString(game.serial), -10) .arg(QString::fromStdString(game.fw), -4) .arg(QString::fromStdString(game.version), -11) - .arg(QString::fromStdString(game.path)); + .arg(game_path); } }); @@ -492,18 +494,18 @@ void MainWindow::StartGame() { if (table_mode == 0) { if (m_game_list_frame->currentItem()) { int itemID = m_game_list_frame->currentItem()->row(); - gamePath = QString::fromStdString(m_game_info->m_games[itemID].path + "/eboot.bin"); + Common::FS::PathToQString(gamePath, m_game_info->m_games[itemID].path / "eboot.bin"); } } else if (table_mode == 1) { if (m_game_grid_frame->cellClicked) { int itemID = (m_game_grid_frame->crtRow * m_game_grid_frame->columnCnt) + m_game_grid_frame->crtColumn; - gamePath = QString::fromStdString(m_game_info->m_games[itemID].path + "/eboot.bin"); + Common::FS::PathToQString(gamePath, m_game_info->m_games[itemID].path / "eboot.bin"); } } else { if (m_elf_viewer->currentItem()) { int itemID = m_elf_viewer->currentItem()->row(); - gamePath = QString::fromStdString(m_elf_viewer->m_elf_list[itemID].toStdString()); + gamePath = m_elf_viewer->m_elf_list[itemID]; } } if (gamePath != "") {