Kill off replaceable usages of s[n]printf.

This commit is contained in:
Lioncash
2014-06-03 01:08:54 -04:00
parent dccd9ead7d
commit ce54c1e571
29 changed files with 216 additions and 243 deletions

View File

@ -24,15 +24,12 @@ CBannerLoaderWii::CBannerLoaderWii(DiscIO::IVolume *pVolume)
: m_pBannerFile(nullptr)
, m_IsValid(false)
{
char Filename[260];
u64 TitleID;
pVolume->GetTitleID((u8*)&TitleID);
TitleID = Common::swap64(TitleID);
sprintf(Filename, "%stitle/%08x/%08x/data/banner.bin",
File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(TitleID>>32), (u32)TitleID);
std::string Filename = StringFromFormat("%stitle/%08x/%08x/data/banner.bin",
File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(TitleID>>32), (u32)TitleID);
if (!File::Exists(Filename))
{
@ -40,26 +37,26 @@ CBannerLoaderWii::CBannerLoaderWii(DiscIO::IVolume *pVolume)
// from the savefiles is very different from the banner.bin
// inside opening.bnr
#if 0
char bnrFilename[260], titleFolder[260];
// Creating title folder
sprintf(titleFolder, "%stitle/%08x/%08x/data/",
std::string titleFolder = StringFromFormat("%stitle/%08x/%08x/data/",
File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(TitleID>>32), (u32)TitleID);
if (!File::Exists(titleFolder))
File::CreateFullPath(titleFolder);
// Extracting banner.bin from opening.bnr
sprintf(bnrFilename, "%stitle/%08x/%08x/data/opening.bnr",
std::string bnrFilename = StringFromFormat("%stitle/%08x/%08x/data/opening.bnr",
File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(TitleID>>32), (u32)TitleID);
if (!_rFileSystem.ExportFile("opening.bnr", bnrFilename)) {
if (!_rFileSystem.ExportFile("opening.bnr", bnrFilename))
{
m_IsValid = false;
return;
}
CARCFile bnrArc (bnrFilename, 0x600);
if (!bnrArc.ExportFile("meta/banner.bin", Filename)) {
if (!bnrArc.ExportFile("meta/banner.bin", Filename))
{
m_IsValid = false;
return;
}

View File

@ -66,7 +66,7 @@ public:
// Factory function - examines the path to choose the right type of IBlobReader, and returns one.
IBlobReader* CreateBlobReader(const std::string& filename);
typedef void (*CompressCB)(const char *text, float percent, void* arg);
typedef void (*CompressCB)(const std::string& text, float percent, void* arg);
bool CompressFileToBlob(const std::string& infile, const std::string& outfile, u32 sub_type = 0, int sector_size = 16384,
CompressCB callback = nullptr, void *arg = nullptr);

View File

@ -17,6 +17,7 @@
#include "Common/Common.h"
#include "Common/FileUtil.h"
#include "Common/Hash.h"
#include "Common/StringUtil.h"
#include "DiscIO/Blob.h"
#include "DiscIO/CompressedBlob.h"
#include "DiscIO/DiscScrubber.h"
@ -203,8 +204,8 @@ bool CompressFileToBlob(const std::string& infile, const std::string& outfile, u
int ratio = 0;
if (inpos != 0)
ratio = (int)(100 * position / inpos);
char temp[512];
sprintf(temp, "%i of %i blocks. Compression ratio %i%%", i, header.num_blocks, ratio);
std::string temp = StringFromFormat("%i of %i blocks. Compression ratio %i%%", i, header.num_blocks, ratio);
callback(temp, (float)i / (float)header.num_blocks, arg);
}

View File

@ -38,7 +38,7 @@ void CSharedContent::UpdateLocation()
{
m_Elements.clear();
lastID = 0;
sprintf(contentMap, "%sshared1/content.map", File::GetUserPath(D_WIIUSER_IDX).c_str());
contentMap = StringFromFormat("%sshared1/content.map", File::GetUserPath(D_WIIUSER_IDX).c_str());
File::IOFile pFile(contentMap, "rb");
SElement Element;
@ -58,11 +58,9 @@ std::string CSharedContent::GetFilenameFromSHA1(const u8* _pHash)
{
if (memcmp(_pHash, Element.SHA1Hash, 20) == 0)
{
char szFilename[1024];
sprintf(szFilename, "%sshared1/%c%c%c%c%c%c%c%c.app", File::GetUserPath(D_WIIUSER_IDX).c_str(),
Element.FileName[0], Element.FileName[1], Element.FileName[2], Element.FileName[3],
Element.FileName[4], Element.FileName[5], Element.FileName[6], Element.FileName[7]);
return szFilename;
return StringFromFormat("%sshared1/%c%c%c%c%c%c%c%c.app", File::GetUserPath(D_WIIUSER_IDX).c_str(),
Element.FileName[0], Element.FileName[1], Element.FileName[2], Element.FileName[3],
Element.FileName[4], Element.FileName[5], Element.FileName[6], Element.FileName[7]);
}
}
return "unk";
@ -70,13 +68,13 @@ std::string CSharedContent::GetFilenameFromSHA1(const u8* _pHash)
std::string CSharedContent::AddSharedContent(const u8* _pHash)
{
std::string szFilename = GetFilenameFromSHA1(_pHash);
if (strcasecmp(szFilename.c_str(), "unk") == 0)
std::string filename = GetFilenameFromSHA1(_pHash);
if (strcasecmp(filename.c_str(), "unk") == 0)
{
char tempFilename[1024], c_ID[9];
std::string id = StringFromFormat("%08x", lastID);
SElement Element;
sprintf(c_ID, "%08x", lastID);
memcpy(Element.FileName, c_ID, 8);
memcpy(Element.FileName, id.c_str(), 8);
memcpy(Element.SHA1Hash, _pHash, 20);
m_Elements.push_back(Element);
@ -85,11 +83,11 @@ std::string CSharedContent::AddSharedContent(const u8* _pHash)
File::IOFile pFile(contentMap, "ab");
pFile.WriteArray(&Element, 1);
sprintf(tempFilename, "%sshared1/%s.app", File::GetUserPath(D_WIIUSER_IDX).c_str(), c_ID);
szFilename = tempFilename;
filename = StringFromFormat("%sshared1/%s.app", File::GetUserPath(D_WIIUSER_IDX).c_str(), id.c_str());
lastID++;
}
return szFilename;
return filename;
}
@ -97,9 +95,7 @@ std::string CSharedContent::AddSharedContent(const u8* _pHash)
class CNANDContentLoader : public INANDContentLoader
{
public:
CNANDContentLoader(const std::string& _rName);
virtual ~CNANDContentLoader();
bool IsValid() const override { return m_Valid; }
@ -122,7 +118,6 @@ public:
u8 GetCountryChar() const override {return m_Country; }
private:
bool m_Valid;
bool m_isWAD;
std::string m_Path;
@ -148,8 +143,6 @@ private:
};
CNANDContentLoader::CNANDContentLoader(const std::string& _rName)
: m_Valid(false)
, m_isWAD(false)
@ -222,8 +215,7 @@ bool CNANDContentLoader::Initialize(const std::string& _rName)
File::IOFile pTMDFile(TMDFileName, "rb");
if (!pTMDFile)
{
WARN_LOG(DISCIO, "CreateFromDirectory: error opening %s",
TMDFileName.c_str());
WARN_LOG(DISCIO, "CreateFromDirectory: error opening %s", TMDFileName.c_str());
return false;
}
u32 pTMDSize = (u32)File::GetSize(TMDFileName);
@ -374,10 +366,9 @@ void CNANDContentLoader::RemoveTitle() const
{
if (!(m_Content[i].m_Type & 0x8000)) // skip shared apps
{
char szFilename[1024];
sprintf(szFilename, "%s%08x.app", Common::GetTitleContentPath(m_TitleID).c_str(), m_Content[i].m_ContentID);
INFO_LOG(DISCIO, "Delete %s", szFilename);
File::Delete(szFilename);
std::string filename = StringFromFormat("%s%08x.app", Common::GetTitleContentPath(m_TitleID).c_str(), m_Content[i].m_ContentID);
INFO_LOG(DISCIO, "Delete %s", filename.c_str());
File::Delete(filename);
}
}
}
@ -392,7 +383,7 @@ void cUIDsys::UpdateLocation()
{
m_Elements.clear();
lastUID = 0x00001000;
sprintf(uidSys, "%ssys/uid.sys", File::GetUserPath(D_WIIUSER_IDX).c_str());
uidSys = StringFromFormat("%ssys/uid.sys", File::GetUserPath(D_WIIUSER_IDX).c_str());
File::IOFile pFile(uidSys, "rb");
SElement Element;
@ -411,7 +402,7 @@ void cUIDsys::UpdateLocation()
File::CreateFullPath(uidSys);
pFile.Open(uidSys, "wb");
if (!pFile.WriteArray(&Element, 1))
ERROR_LOG(DISCIO, "Failed to write to %s", uidSys);
ERROR_LOG(DISCIO, "Failed to write to %s", uidSys.c_str());
}
}
@ -491,15 +482,14 @@ u64 CNANDContentManager::Install_WiiWAD(std::string &fileName)
pTMDFile.WriteBytes(Content.m_Header, INANDContentLoader::CONTENT_HEADER_SIZE);
char APPFileName[1024];
std::string APPFileName;
if (Content.m_Type & 0x8000) //shared
{
sprintf(APPFileName, "%s",
CSharedContent::AccessInstance().AddSharedContent(Content.m_SHA1Hash).c_str());
APPFileName = CSharedContent::AccessInstance().AddSharedContent(Content.m_SHA1Hash);
}
else
{
sprintf(APPFileName, "%s%08x.app", ContentPath.c_str(), Content.m_ContentID);
APPFileName = StringFromFormat("%s%08x.app", ContentPath.c_str(), Content.m_ContentID);
}
if (!File::Exists(APPFileName))
@ -508,7 +498,7 @@ u64 CNANDContentManager::Install_WiiWAD(std::string &fileName)
File::IOFile pAPPFile(APPFileName, "wb");
if (!pAPPFile)
{
PanicAlertT("WAD installation failed: error creating %s", APPFileName);
PanicAlertT("WAD installation failed: error creating %s", APPFileName.c_str());
return 0;
}
@ -516,15 +506,10 @@ u64 CNANDContentManager::Install_WiiWAD(std::string &fileName)
}
else
{
INFO_LOG(DISCIO, "Content %s already exists.", APPFileName);
INFO_LOG(DISCIO, "Content %s already exists.", APPFileName.c_str());
}
}
pTMDFile.Close();
//Extract and copy WAD's ticket to ticket directory
if (!Add_Ticket(TitleID, ContentLoader.GetTIK(), ContentLoader.GetTIKSize()))
{
@ -534,7 +519,6 @@ u64 CNANDContentManager::Install_WiiWAD(std::string &fileName)
cUIDsys::AccessInstance().AddTitle(TitleID);
return TitleID;
}

View File

@ -68,30 +68,26 @@ public:
class CNANDContentManager
{
public:
static CNANDContentManager& Access() { return m_Instance; }
u64 Install_WiiWAD(std::string &fileName);
const INANDContentLoader& GetNANDLoader(const std::string& _rName, bool forceReload = false);
const INANDContentLoader& GetNANDLoader(u64 _titleId, bool forceReload = false);
bool RemoveTitle(u64 _titleID);
private:
CNANDContentManager() {};
~CNANDContentManager();
static CNANDContentManager m_Instance;
typedef std::map<std::string, INANDContentLoader*> CNANDContentMap;
CNANDContentMap m_Map;
};
class CSharedContent
{
public:
static CSharedContent& AccessInstance() { return m_Instance; }
std::string GetFilenameFromSHA1(const u8* _pHash);
@ -99,10 +95,7 @@ public:
void UpdateLocation();
private:
CSharedContent();
virtual ~CSharedContent();
#pragma pack(push,1)
@ -114,7 +107,7 @@ private:
#pragma pack(pop)
u32 lastID;
char contentMap[1024];
std::string contentMap;
std::vector<SElement> m_Elements;
static CSharedContent m_Instance;
};
@ -122,18 +115,15 @@ private:
class cUIDsys
{
public:
static cUIDsys& AccessInstance() { return m_Instance; }
u32 GetUIDFromTitle(u64 _Title);
void AddTitle(u64 _Title);
void GetTitleIDs(std::vector<u64>& _TitleIDs, bool _owned = false);
void UpdateLocation();
private:
cUIDsys();
virtual ~cUIDsys();
#pragma pack(push,1)
@ -143,8 +133,9 @@ private:
u8 UID[4];
};
#pragma pack(pop)
u32 lastUID;
char uidSys[1024];
std::string uidSys;
std::vector<SElement> m_Elements;
static cUIDsys m_Instance;
};