summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO/NANDContentLoader.cpp
diff options
context:
space:
mode:
authorPierre Bourdon <delroth@gmail.com>2014-06-19 01:59:02 +0200
committerPierre Bourdon <delroth@gmail.com>2014-06-19 01:59:02 +0200
commit591a27e32894f9454ebbdae040f61e60fa1ebf87 (patch)
treea8a50407af01bd5da5b9ba122e02a756ac73119d /Source/Core/DiscIO/NANDContentLoader.cpp
parentdccd9ead7dd23bf3b463a8e4043bdc63de6a7a9f (diff)
parentce54c1e571a7f79c173dd8f949003255ba95670a (diff)
Merge pull request #456 from lioncash/adios-sprintf
Kill off replaceable usages of s[n]printf.
Diffstat (limited to 'Source/Core/DiscIO/NANDContentLoader.cpp')
-rw-r--r--Source/Core/DiscIO/NANDContentLoader.cpp62
1 files changed, 23 insertions, 39 deletions
diff --git a/Source/Core/DiscIO/NANDContentLoader.cpp b/Source/Core/DiscIO/NANDContentLoader.cpp
index 6915e325d8..fec20cd4b5 100644
--- a/Source/Core/DiscIO/NANDContentLoader.cpp
+++ b/Source/Core/DiscIO/NANDContentLoader.cpp
@@ -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;
}