Fill game list from all locations

This commit is contained in:
Nekotekina 2017-07-12 16:58:48 +03:00
parent 08e9400870
commit 3cd4256b9e
5 changed files with 45 additions and 28 deletions

View File

@ -2,7 +2,7 @@
struct GameInfo struct GameInfo
{ {
std::string root; std::string path;
std::string icon_path; std::string icon_path;
std::string name; std::string name;
@ -24,7 +24,7 @@ struct GameInfo
void Reset() void Reset()
{ {
root = ""; path = "";
name = "Unknown"; name = "Unknown";
serial = "Unknown"; serial = "Unknown";

View File

@ -260,12 +260,12 @@ bool Emulator::BootGame(const std::string& path, bool direct)
return false; return false;
} }
std::string Emulator::GetGameDir() std::string Emulator::GetHddDir()
{ {
const std::string& emu_dir_ = g_cfg.vfs.emulator_dir; const std::string& emu_dir_ = g_cfg.vfs.emulator_dir;
const std::string& emu_dir = emu_dir_.empty() ? fs::get_config_dir() : emu_dir_; const std::string& emu_dir = emu_dir_.empty() ? fs::get_config_dir() : emu_dir_;
return fmt::replace_all(g_cfg.vfs.dev_hdd0, "$(EmulatorDir)", emu_dir) + "game/"; return fmt::replace_all(g_cfg.vfs.dev_hdd0, "$(EmulatorDir)", emu_dir);
} }
std::string Emulator::GetLibDir() std::string Emulator::GetLibDir()

View File

@ -232,7 +232,7 @@ public:
bool BootGame(const std::string& path, bool direct = false); bool BootGame(const std::string& path, bool direct = false);
static std::string GetGameDir(); static std::string GetHddDir();
static std::string GetLibDir(); static std::string GetLibDir();
void Load(); void Load();

View File

@ -9,7 +9,9 @@
#include "Utilities/types.h" #include "Utilities/types.h"
#include <algorithm> #include <algorithm>
#include <iterator>
#include <memory> #include <memory>
#include <set>
#include <QDesktopServices> #include <QDesktopServices>
#include <QDir> #include <QDir>
@ -353,16 +355,32 @@ void game_list_frame::Refresh(bool fromDrive)
m_game_data.clear(); m_game_data.clear();
const std::string& game_path = Emu.GetGameDir(); const std::string _hdd = Emu.GetHddDir();
for (const auto& entry : fs::dir(Emu.GetGameDir())) std::vector<std::string> path_list;
const auto add_dir = [&](const std::string& path)
{ {
if (!entry.is_directory) for (const auto& entry : fs::dir(path))
{ {
continue; if (entry.is_directory)
{
path_list.emplace_back(path + entry.name);
}
} }
};
const std::string& dir = game_path + entry.name; add_dir(_hdd + "game/");
add_dir(_hdd + "disc/");
for (auto pair : YAML::Load(fs::file{fs::get_config_dir() + "/games.yml", fs::read + fs::create}.to_string()))
{
path_list.push_back(pair.second.Scalar());
}
// std::set is used to remove duplicates from the list
for (const auto& dir : std::set<std::string>(std::make_move_iterator(path_list.begin()), std::make_move_iterator(path_list.end())))
{
const std::string& sfb = dir + "/PS3_DISC.SFB"; const std::string& sfb = dir + "/PS3_DISC.SFB";
const std::string& sfo = dir + (fs::is_file(sfb) ? "/PS3_GAME/PARAM.SFO" : "/PARAM.SFO"); const std::string& sfo = dir + (fs::is_file(sfb) ? "/PS3_GAME/PARAM.SFO" : "/PARAM.SFO");
@ -375,7 +393,7 @@ void game_list_frame::Refresh(bool fromDrive)
const auto& psf = psf::load_object(sfo_file); const auto& psf = psf::load_object(sfo_file);
GameInfo game; GameInfo game;
game.root = entry.name; game.path = dir;
game.serial = psf::get_string(psf, "TITLE_ID", ""); game.serial = psf::get_string(psf, "TITLE_ID", "");
game.name = psf::get_string(psf, "TITLE", sstr(category::unknown)); game.name = psf::get_string(psf, "TITLE", sstr(category::unknown));
game.app_ver = psf::get_string(psf, "APP_VER", sstr(category::unknown)); game.app_ver = psf::get_string(psf, "APP_VER", sstr(category::unknown));
@ -534,24 +552,23 @@ void game_list_frame::doubleClickedSlot(const QModelIndex& index)
if (1) if (1)
{ {
const std::string& path = Emu.GetGameDir() + m_game_data[i].info.root; RequestIconPathSet(m_game_data[i].info.path);
RequestIconPathSet(path);
Emu.Stop(); Emu.Stop();
if (!Emu.BootGame(path)) if (!Emu.BootGame(m_game_data[i].info.path))
{ {
LOG_ERROR(LOADER, "Failed to boot /dev_hdd0/game/%s", m_game_data[i].info.root); LOG_ERROR(LOADER, "Failed to boot %s", m_game_data[i].info.path);
} }
else else
{ {
LOG_SUCCESS(LOADER, "Boot from gamelist per doubleclick: done"); LOG_SUCCESS(LOADER, "Boot from gamelist per doubleclick: done");
RequestAddRecentGame(q_string_pair(qstr(path), qstr("[" + m_game_data[i].info.serial + "] " + m_game_data[i].info.name))); RequestAddRecentGame(q_string_pair(qstr(m_game_data[i].info.path), qstr("[" + m_game_data[i].info.serial + "] " + m_game_data[i].info.name)));
} }
} }
else else
{ {
open_dir(Emu.GetGameDir() + m_game_data[i].info.root); open_dir(m_game_data[i].info.path);
} }
} }
@ -619,16 +636,17 @@ void game_list_frame::ShowSpecifiedContextMenu(const QPoint &pos, int row)
connect(configure, &QAction::triggered, [=]() { connect(configure, &QAction::triggered, [=]() {
settings_dialog (xgui_settings, m_Render_Creator, 0, this, &currGame).exec(); settings_dialog (xgui_settings, m_Render_Creator, 0, this, &currGame).exec();
}); });
connect(removeGame, &QAction::triggered, [=]() { connect(removeGame, &QAction::triggered, [=]()
{
if (QMessageBox::question(this, tr("Confirm Delete"), tr("Permanently delete files?")) == QMessageBox::Yes) if (QMessageBox::question(this, tr("Confirm Delete"), tr("Permanently delete files?")) == QMessageBox::Yes)
{ {
fs::remove_all(Emu.GetGameDir() + m_game_data[row].info.root); fs::remove_all(m_game_data[row].info.path);
m_game_data.erase(m_game_data.begin() + row); m_game_data.erase(m_game_data.begin() + row);
Refresh(); Refresh();
} }
}); });
connect(removeConfig, &QAction::triggered, [=]() {RemoveCustomConfiguration(row); }); connect(removeConfig, &QAction::triggered, [=]() {RemoveCustomConfiguration(row); });
connect(openGameFolder, &QAction::triggered, [=]() {open_dir(Emu.GetGameDir() + currGame.root); }); connect(openGameFolder, &QAction::triggered, [=]() {open_dir(currGame.path); });
connect(openConfig, &QAction::triggered, [=]() {open_dir(fs::get_config_dir() + "data/" + currGame.serial); }); connect(openConfig, &QAction::triggered, [=]() {open_dir(fs::get_config_dir() + "data/" + currGame.serial); });
connect(checkCompat, &QAction::triggered, [=]() { connect(checkCompat, &QAction::triggered, [=]() {
QString link = "https://rpcs3.net/compatibility?g=" + qstr(currGame.serial); QString link = "https://rpcs3.net/compatibility?g=" + qstr(currGame.serial);
@ -666,20 +684,19 @@ void game_list_frame::ShowSpecifiedContextMenu(const QPoint &pos, int row)
void game_list_frame::Boot(int row) void game_list_frame::Boot(int row)
{ {
const std::string& path = Emu.GetGameDir() + m_game_data[row].info.root; RequestIconPathSet(m_game_data[row].info.path);
RequestIconPathSet(path);
Emu.Stop(); Emu.Stop();
if (!Emu.BootGame(path)) if (!Emu.BootGame(m_game_data[row].info.path))
{ {
QMessageBox::warning(this, tr("Warning!"), tr("Failed to boot ") + qstr(m_game_data[row].info.root)); QMessageBox::warning(this, tr("Warning!"), tr("Failed to boot ") + qstr(m_game_data[row].info.path));
LOG_ERROR(LOADER, "Failed to boot /dev_hdd0/game/%s", m_game_data[row].info.root); LOG_ERROR(LOADER, "Failed to boot %s", m_game_data[row].info.path);
} }
else else
{ {
LOG_SUCCESS(LOADER, "Boot from gamelist per Boot: done"); LOG_SUCCESS(LOADER, "Boot from gamelist per Boot: done");
RequestAddRecentGame(q_string_pair(qstr(path), qstr("[" + m_game_data[row].info.serial + "] " + m_game_data[row].info.name))); RequestAddRecentGame(q_string_pair(qstr(m_game_data[row].info.path), qstr("[" + m_game_data[row].info.serial + "] " + m_game_data[row].info.name)));
} }
} }
@ -824,7 +841,7 @@ int game_list_frame::PopulateGameList()
gameList->setItem(row, 3, l_GetItem(game.info.fw)); gameList->setItem(row, 3, l_GetItem(game.info.fw));
gameList->setItem(row, 4, l_GetItem(game.info.app_ver)); gameList->setItem(row, 4, l_GetItem(game.info.app_ver));
gameList->setItem(row, 5, l_GetItem(game.info.category)); gameList->setItem(row, 5, l_GetItem(game.info.category));
gameList->setItem(row, 6, l_GetItem(game.info.root)); gameList->setItem(row, 6, l_GetItem(game.info.path));
gameList->setItem(row, 7, l_GetItem(GetStringFromU32(game.info.resolution, resolution::mode, true))); gameList->setItem(row, 7, l_GetItem(GetStringFromU32(game.info.resolution, resolution::mode, true)));
gameList->setItem(row, 8, l_GetItem(GetStringFromU32(game.info.sound_format, sound::format, true))); gameList->setItem(row, 8, l_GetItem(GetStringFromU32(game.info.sound_format, sound::format, true)));
gameList->setItem(row, 9, l_GetItem(GetStringFromU32(game.info.parental_lvl, parental::level))); gameList->setItem(row, 9, l_GetItem(GetStringFromU32(game.info.parental_lvl, parental::level)));

View File

@ -310,7 +310,7 @@ void main_window::InstallPkg()
pkg_f.seek(0); pkg_f.seek(0);
// Get full path // Get full path
const auto& local_path = Emu.GetGameDir() + std::string(std::begin(title_id), std::end(title_id)); const auto& local_path = Emu.GetHddDir() + "game/" + std::string(std::begin(title_id), std::end(title_id));
if (!fs::create_dir(local_path)) if (!fs::create_dir(local_path))
{ {