From c9abab6828c7b6eb9784fdf608d1718a25d0f8c5 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sat, 22 Jul 2017 16:16:49 +0300 Subject: [PATCH] cellGame: minor refactoring --- rpcs3/Emu/Cell/Modules/cellGame.cpp | 40 +++++++++++++++-------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellGame.cpp b/rpcs3/Emu/Cell/Modules/cellGame.cpp index b62faa46df..598319808d 100644 --- a/rpcs3/Emu/Cell/Modules/cellGame.cpp +++ b/rpcs3/Emu/Cell/Modules/cellGame.cpp @@ -80,14 +80,13 @@ struct content_permission final // SFO file psf::registry sfo; - // True if temporary directory is created and must be moved or deleted - bool is_temporary = false; + // Temporary directory path + std::string temp; template - content_permission(Dir&& dir, Sfo&& sfo, bool is_temp = false) + content_permission(Dir&& dir, Sfo&& sfo) : dir(std::forward(dir)) , sfo(std::forward(sfo)) - , is_temporary(is_temp) { } @@ -95,9 +94,9 @@ struct content_permission final { try { - if (is_temporary) + if (!temp.empty()) { - fs::remove_all(vfs::get("/dev_hdd1/game/" + dir)); + fs::remove_all(temp); } } catch (...) @@ -183,13 +182,14 @@ s32 cellHddGameGetSizeKB(vm::ptr size) { cellGame.warning("cellHddGameGetSizeKB(size=*0x%x)", size); - const std::string& local_dir = vfs::get("/dev_hdd0/game/" + Emu.GetTitleID()); + const std::string local_dir = vfs::get("/dev_hdd0/game/" + Emu.GetTitleID()); + if (!fs::is_dir(local_dir)) { return CELL_HDDGAME_ERROR_FAILURE; } - *size = (u32)(fs::get_dir_size(local_dir)/1024); + *size = ::narrow(fs::get_dir_size(local_dir) / 1024); return CELL_OK; } @@ -209,16 +209,16 @@ s32 cellGameDataGetSizeKB(vm::ptr size) { cellGame.warning("cellGameDataGetSizeKB(size=*0x%x)", size); - const std::string& local_dir = vfs::get("/dev_hdd0/game/" + Emu.GetTitleID()); + const std::string local_dir = vfs::get("/dev_hdd0/game/" + Emu.GetTitleID()); + if (!fs::is_dir(local_dir)) { return CELL_GAMEDATA_ERROR_FAILURE; } - *size = (u32)(fs::get_dir_size(local_dir)/1024); + *size = ::narrow(fs::get_dir_size(local_dir) / 1024); return CELL_OK; - } s32 cellGameDataSetSystemVer() @@ -383,7 +383,7 @@ error_code cellGameContentPermit(vm::ptr contentInfoPa const std::string dir = prm->dir.empty() ? "/dev_bdvd/PS3_GAME"s : "/dev_hdd0/game/" + prm->dir; - if (prm->is_temporary) + if (!prm->temp.empty()) { // Make temporary directory persistent const auto vdir = vfs::get(dir); @@ -393,7 +393,7 @@ error_code cellGameContentPermit(vm::ptr contentInfoPa fmt::throw_exception("cellGameContentPermit(): epic fail: directory '%s' already exists", dir); } - if (fs::rename(vfs::get("/dev_hdd1/game/" + prm->dir), vdir)) + if (fs::rename(prm->temp, vdir)) { cellGame.success("cellGameContentPermit(): directory '%s' has been created", dir); } @@ -406,7 +406,7 @@ error_code cellGameContentPermit(vm::ptr contentInfoPa psf::save_object(fs::file(vdir + "/PARAM.SFO", fs::rewrite), prm->sfo); // Disable deletion - prm->is_temporary = false; + prm->temp.clear(); } strcpy_trunc(*contentInfoPath, dir); @@ -570,8 +570,8 @@ error_code cellGameCreateGameData(vm::ptr init, vm::ptrtemp = vfs::get(tmp_contentInfo); cellGame.success("cellGameCreateGameData(): temporary directory '%s' has been created", tmp_contentInfo); - prm->is_temporary = true; // Initial PARAM.SFO parameters (overwrite) prm->sfo = @@ -714,9 +714,10 @@ error_code cellGameSetParamString(s32 id, vm::cptr buf) return CELL_OK; } -s32 cellGameGetSizeKB(vm::ptr size) +error_code cellGameGetSizeKB(vm::ptr size) { cellGame.warning("cellGameGetSizeKB(size=*0x%x)", size); + const auto prm = fxm::get(); if (!prm) @@ -724,13 +725,14 @@ s32 cellGameGetSizeKB(vm::ptr size) return CELL_GAME_ERROR_FAILURE; } - const std::string& local_dir = prm->is_temporary? vfs::get("/dev_hdd1/game/"s + prm->dir) : vfs::get("/dev_hdd0/game/"s + prm->dir); //should we check the temporary folder? + const std::string local_dir = !prm->temp.empty() ? prm->temp : vfs::get("/dev_hdd0/game/" + prm->dir); + if (!fs::is_dir(local_dir)) { - return CELL_GAME_ERROR_FAILURE; + return CELL_GAME_ERROR_ACCESS_ERROR; } - *size = (u32)(fs::get_dir_size(local_dir)/1024); + *size = ::narrow(fs::get_dir_size(local_dir) / 1024); return CELL_OK; }