mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-02-21 18:39:57 +00:00
cellGame: minor refactoring
This commit is contained in:
parent
9dc9378bcc
commit
c9abab6828
@ -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 <typename Dir, typename Sfo>
|
||||
content_permission(Dir&& dir, Sfo&& sfo, bool is_temp = false)
|
||||
content_permission(Dir&& dir, Sfo&& sfo)
|
||||
: dir(std::forward<Dir>(dir))
|
||||
, sfo(std::forward<Sfo>(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<u32> 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<u32>(fs::get_dir_size(local_dir) / 1024);
|
||||
|
||||
return CELL_OK;
|
||||
}
|
||||
@ -209,16 +209,16 @@ s32 cellGameDataGetSizeKB(vm::ptr<u32> 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<u32>(fs::get_dir_size(local_dir) / 1024);
|
||||
|
||||
return CELL_OK;
|
||||
|
||||
}
|
||||
|
||||
s32 cellGameDataSetSystemVer()
|
||||
@ -383,7 +383,7 @@ error_code cellGameContentPermit(vm::ptr<char[CELL_GAME_PATH_MAX]> 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<char[CELL_GAME_PATH_MAX]> 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<char[CELL_GAME_PATH_MAX]> 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<CellGameSetInitParams> init, vm::ptr<c
|
||||
strcpy_trunc(*tmp_contentInfoPath, tmp_contentInfo);
|
||||
strcpy_trunc(*tmp_usrdirPath, tmp_usrdir);
|
||||
|
||||
prm->temp = 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<char> buf)
|
||||
return CELL_OK;
|
||||
}
|
||||
|
||||
s32 cellGameGetSizeKB(vm::ptr<s32> size)
|
||||
error_code cellGameGetSizeKB(vm::ptr<s32> size)
|
||||
{
|
||||
cellGame.warning("cellGameGetSizeKB(size=*0x%x)", size);
|
||||
|
||||
const auto prm = fxm::get<content_permission>();
|
||||
|
||||
if (!prm)
|
||||
@ -724,13 +725,14 @@ s32 cellGameGetSizeKB(vm::ptr<s32> 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<u32>(fs::get_dir_size(local_dir) / 1024);
|
||||
|
||||
return CELL_OK;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user