@@ -11,6 +11,8 @@
#include < utility>
#include < vector>
#include < fmt/format.h>
#include " Common/CommonTypes.h"
#include " Common/File.h"
#include " Common/FileUtil.h"
@@ -25,13 +27,13 @@ namespace
{
std::string TitleIdStr (u64 tid)
{
return StringFromFormat ( " %c%c%c%c " , static_cast <char >(tid >> 24 ), static_cast <char >(tid >> 16 ),
static_cast <char >(tid >> 8 ), static_cast <char >(tid));
return fmt::format ( " {}{}{}{} " , static_cast <char >(tid >> 24 ), static_cast <char >(tid >> 16 ),
static_cast <char >(tid >> 8 ), static_cast <char >(tid));
}
std::string GroupIdStr (u16 gid)
{
return StringFromFormat ( " %c%c " , gid >> 8 , gid & 0xFF );
return fmt::format ( " {}{} " , static_cast < char >( gid >> 8 ), static_cast < char >( gid & 0xFF ) );
}
} // namespace
@@ -119,9 +121,8 @@ void WFSI::SetImportTitleIdAndGroupId(u64 tid, u16 gid)
void WFSI::FinalizePatchInstall ()
{
const std::string current_title_dir =
StringFromFormat (" /vol/%s/title/%s/%s" , m_device_name.c_str (), m_current_group_id_str.c_str (),
m_current_title_id_str.c_str ());
const std::string current_title_dir = fmt::format (" /vol/{}/title/{}/{}" , m_device_name,
m_current_group_id_str, m_current_title_id_str);
const std::string patch_dir = current_title_dir + " /_patch" ;
File::CopyDir (WFS::NativePath (patch_dir), WFS::NativePath (current_title_dir), true );
}
@@ -145,9 +146,8 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request)
if (m_patch_type == PatchType::PATCH_TYPE_2)
{
const std::string content_dir =
StringFromFormat (" /vol/%s/title/%s/%s/content" , m_device_name.c_str (),
m_current_group_id_str.c_str (), m_current_title_id_str.c_str ());
const std::string content_dir = fmt::format (" /vol/{}/title/{}/{}/content" , m_device_name,
m_current_group_id_str, m_current_title_id_str);
File::Rename (WFS::NativePath (content_dir + " /default.dol" ),
WFS::NativePath (content_dir + " /_default.dol" ));
@@ -185,7 +185,7 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request)
}
case IOCTL_WFSI_PREPARE_PROFILE:
m_base_extract_path = StringFromFormat (" /vol/%s /tmp/" , m_device_name. c_str () );
m_base_extract_path = fmt::format (" /vol/{} /tmp/" , m_device_name);
[[fallthrough]];
case IOCTL_WFSI_PREPARE_CONTENT:
@@ -274,14 +274,13 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request)
{
// Delete content's default.dol
const std::string title_content_dir =
StringFromFormat (" /vol/%s /title/%s/%s /content/" , m_device_name. c_str () ,
m_current_group_id_str. c_str (), m_current_title_id_str. c_str () );
fmt::format (" /vol/{} /title/{}/{} /content/" , m_device_name, m_current_group_id_str ,
m_current_title_id_str);
File::Delete (WFS::NativePath (title_content_dir + " default.dol" ));
// Copy content's _default.dol to patch's directory
const std::string patch_dir =
StringFromFormat (" /vol/%s/title/%s/%s/_patch/" , m_device_name.c_str (),
m_current_group_id_str.c_str (), m_current_title_id_str.c_str ());
const std::string patch_dir = fmt::format (" /vol/{}/title/{}/{}/_patch/" , m_device_name,
m_current_group_id_str, m_current_title_id_str);
const std::string patch_content_dir = patch_dir + " content/" ;
File::CreateDir (WFS::NativePath (patch_dir));
File::CreateDir (WFS::NativePath (patch_content_dir));
@@ -293,28 +292,24 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request)
}
case PATCH_TYPE_1:
{
std::string patch_dir =
StringFromFormat (" /vol/%s/title/%s/%s/_patch" , m_device_name.c_str (),
m_current_group_id_str.c_str (), m_current_title_id_str.c_str ());
const std::string patch_dir = fmt::format (" /vol/{}/title/{}/{}/_patch" , m_device_name,
m_current_group_id_str, m_current_title_id_str);
File::DeleteDirRecursively (WFS::NativePath (patch_dir));
tmd_path = StringFromFormat (" /vol/%s/title/%s/%s/meta/%016" PRIx64 " .tmd" ,
m_device_name.c_str (), m_current_group_id_str.c_str (),
m_current_title_id_str.c_str (), m_import_title_id);
tmd_path = fmt::format (" /vol/{}/title/{}/{}/meta/{:016x}.tmd" , m_device_name,
m_current_group_id_str, m_current_title_id_str, m_import_title_id);
break ;
}
case NOT_A_PATCH:
{
std::string title_install_dir = StringFromFormat (" /vol/%s/_install/%s" , m_device_name.c_str (),
m_import_title_id_str.c_str ());
std::string title_final_dir =
StringFromFormat (" /vol/%s/title/%s/%s" , m_device_name.c_str (),
m_import_group_id_str.c_str (), m_import_title_id_str.c_str ());
const std::string title_install_dir =
fmt::format (" /vol/{}/_install/{}" , m_device_name, m_import_title_id_str);
const std::string title_final_dir = fmt::format (" /vol/{}/title/{}/{}" , m_device_name,
m_import_group_id_str, m_import_title_id_str);
File::Rename (WFS::NativePath (title_install_dir), WFS::NativePath (title_final_dir));
tmd_path = StringFromFormat (" /vol/%s/title/%s/%s/meta/%016" PRIx64 " .tmd" ,
m_device_name.c_str (), m_import_group_id_str.c_str (),
m_import_title_id_str.c_str (), m_import_title_id);
tmd_path = fmt::format (" /vol/{}/title/{}/{}/meta/{:016x}.tmd" , m_device_name,
m_import_group_id_str, m_import_title_id_str, m_import_title_id);
break ;
}
}
@@ -348,9 +343,8 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request)
SetCurrentTitleIdAndGroupId (title_id, group_id);
// Change home directory
const std::string homedir_path =
StringFromFormat (" /vol/%s/title/%s/%s/" , m_device_name.c_str (),
m_current_group_id_str.c_str (), m_current_title_id_str.c_str ());
const std::string homedir_path = fmt::format (" /vol/{}/title/{}/{}/" , m_device_name,
m_current_group_id_str, m_current_title_id_str);
const u16 homedir_path_len = static_cast <u16>(homedir_path.size ());
INFO_LOG (IOS_WFS, " IOCTL_WFSI_CHANGE_TITLE: %s (path_len: 0x%x)" , homedir_path.c_str (),
homedir_path_len);
@@ -414,34 +408,32 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request)
if (m_patch_type == NOT_A_PATCH)
{
std::string install_directory = StringFromFormat (" /vol/%s /_install" , m_device_name. c_str () );
const std::string install_directory = fmt::format (" /vol/{} /_install" , m_device_name);
if (!m_continue_install && File::IsDirectory (WFS::NativePath (install_directory)))
{
File::DeleteDirRecursively (WFS::NativePath (install_directory));
}
m_base_extract_path = StringFromFormat (" %s/%s/content" , install_directory.c_str (),
m_import_title_id_str.c_str ());
m_base_extract_path = fmt::format (" {}/{}/content" , install_directory, m_import_title_id_str);
File::CreateFullPath (WFS::NativePath (m_base_extract_path));
File::CreateDir (WFS::NativePath (m_base_extract_path));
for (auto dir : {" work" , " meta" , " save" })
for (const auto dir : {" work" , " meta" , " save" })
{
std::string path = StringFromFormat ( " %s/%s/%s " , install_directory. c_str (),
m_import_title_id_str. c_str () , dir);
const std::string path =
fmt::format ( " {}/{}/{} " , install_directory, m_import_title_id_str, dir);
File::CreateDir (WFS::NativePath (path));
}
std::string group_path = StringFromFormat ( " /vol/%s/title/%s " , m_device_name. c_str (),
m_import_group_id_str. c_str () );
const std::string group_path =
fmt::format ( " /vol/{}/title/{} " , m_device_name, m_import_group_id_str);
File::CreateFullPath (WFS::NativePath (group_path));
File::CreateDir (WFS::NativePath (group_path));
}
else
{
m_base_extract_path =
StringFromFormat (" /vol/%s/title/%s/%s/_patch/content" , m_device_name.c_str (),
m_current_group_id_str.c_str (), m_current_title_id_str.c_str ());
m_base_extract_path = fmt::format (" /vol/{}/title/{}/{}/_patch/content" , m_device_name,
m_current_group_id_str, m_current_title_id_str);
File::CreateFullPath (WFS::NativePath (m_base_extract_path));
File::CreateDir (WFS::NativePath (m_base_extract_path));
}
@@ -489,21 +481,20 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request)
case IOCTL_WFSI_LOAD_DOL:
{
std::string path =
StringFromFormat (" /vol/%s/title/%s/%s/content" , m_device_name.c_str (),
m_current_group_id_str.c_str (), m_current_title_id_str.c_str ());
std::string path = fmt::format (" /vol/{}/title/{}/{}/content" , m_device_name,
m_current_group_id_str, m_current_title_id_str);
u32 dol_addr = Memory::Read_U32 (request.buffer_in + 0x18 );
u32 max_dol_size = Memory::Read_U32 (request.buffer_in + 0x14 );
u16 dol_extension_id = Memory::Read_U16 (request.buffer_in + 0x1e );
const u32 dol_addr = Memory::Read_U32 (request.buffer_in + 0x18 );
const u32 max_dol_size = Memory::Read_U32 (request.buffer_in + 0x14 );
const u16 dol_extension_id = Memory::Read_U16 (request.buffer_in + 0x1e );
if (dol_extension_id == 0 )
{
path += " /default.dol" ;
}
else
{
path += StringFromFormat (" /extension%d .dol" , dol_extension_id);
path += fmt::format (" /extension{} .dol" , dol_extension_id);
}
INFO_LOG (IOS_WFS, " IOCTL_WFSI_LOAD_DOL: loading %s at address %08x (size %d)" , path.c_str (),
@@ -562,9 +553,8 @@ IPCCommandResult WFSI::IOCtl(const IOCtlRequest& request)
u32 WFSI::GetTmd (u16 group_id, u32 title_id, u64 subtitle_id, u32 address, u32* size) const
{
std::string path =
StringFromFormat (" /vol/%s/title/%s/%s/meta/%016" PRIx64 " .tmd" , m_device_name.c_str (),
GroupIdStr (group_id).c_str (), TitleIdStr (title_id).c_str (), subtitle_id);
const std::string path = fmt::format (" /vol/{}/title/{}/{}/meta/{:016x}.tmd" , m_device_name,
GroupIdStr (group_id), TitleIdStr (title_id), subtitle_id);
File::IOFile fp (WFS::NativePath (path), " rb" );
if (!fp)
{
@@ -581,10 +571,8 @@ u32 WFSI::GetTmd(u16 group_id, u32 title_id, u64 subtitle_id, u32 address, u32*
static s32 DeleteTemporaryFiles (const std::string& device_name, u64 title_id)
{
File::Delete (WFS::NativePath (
StringFromFormat (" /vol/%s/tmp/%016" PRIx64 " .ini" , device_name.c_str (), title_id)));
File::Delete (WFS::NativePath (
StringFromFormat (" /vol/%s/tmp/%016" PRIx64 " .ppcini" , device_name.c_str (), title_id)));
File::Delete (WFS::NativePath (fmt::format (" /vol/{}/tmp/{:016x}.ini" , device_name, title_id)));
File::Delete (WFS::NativePath (fmt::format (" /vol/{}/tmp/{:016x}.ppcini" , device_name, title_id)));
return IPC_SUCCESS;
}
@@ -594,8 +582,7 @@ s32 WFSI::CancelTitleImport(bool continue_install)
if (!continue_install)
{
File::DeleteDirRecursively (
WFS::NativePath (StringFromFormat (" /vol/%s/_install" , m_device_name.c_str ())));
File::DeleteDirRecursively (WFS::NativePath (fmt::format (" /vol/{}/_install" , m_device_name)));
}
DeleteTemporaryFiles (m_device_name, m_import_title_id);
@@ -609,16 +596,15 @@ s32 WFSI::CancelPatchImport(bool continue_install)
if (!continue_install)
{
File::DeleteDirRecursively (WFS::NativePath (
StringFromFormat ( " /vol/%s /title/%s/%s /_patch" , m_device_name. c_str () ,
m_current_group_id_str. c_str () , m_current_title_id_str. c_str () )));
File::DeleteDirRecursively (
WFS::NativePath ( fmt::format ( " /vol/{} /title/{}/{} /_patch" , m_device_name,
m_current_group_id_str, m_current_title_id_str)));
if (m_patch_type == PatchType::PATCH_TYPE_2)
{
// Move back _default.dol to default.dol.
const std::string content_dir =
StringFromFormat (" /vol/%s/title/%s/%s/content" , m_device_name.c_str (),
m_current_group_id_str.c_str (), m_current_title_id_str.c_str ());
const std::string content_dir = fmt::format (" /vol/{}/title/{}/{}/content" , m_device_name,
m_current_group_id_str, m_current_title_id_str);
File::Rename (WFS::NativePath (content_dir + " /_default.dol" ),
WFS::NativePath (content_dir + " /default.dol" ));
}