From ce54c1e571a7f79c173dd8f949003255ba95670a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 3 Jun 2014 01:08:54 -0400 Subject: Kill off replaceable usages of s[n]printf. --- Source/Core/DiscIO/NANDContentLoader.cpp | 62 ++++++++++++-------------------- 1 file changed, 23 insertions(+), 39 deletions(-) (limited to 'Source/Core/DiscIO/NANDContentLoader.cpp') 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; } -- cgit v1.2.3