From 6f08ef9a2505bf784efdd3ca9419aa2f9bb14c4e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 11 Jan 2017 18:00:22 -0500 Subject: [PATCH] IOFile: Get rid of IOFile's ReleaseHandle function Transfer of handles should be done via std::move. --- Source/Core/Common/FileUtil.cpp | 7 ------- Source/Core/Common/FileUtil.h | 2 -- Source/Core/Common/SysConf.cpp | 25 ++++++++++++------------- Source/Core/Common/SysConf.h | 7 ++++++- Source/Core/Core/HW/GCMemcard.cpp | 7 ++----- Source/Core/Core/HW/GCMemcard.h | 8 +++++++- 6 files changed, 27 insertions(+), 29 deletions(-) diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index 4094f5edcf..59c7412072 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -947,13 +947,6 @@ bool IOFile::Close() return m_good; } -std::FILE* IOFile::ReleaseHandle() -{ - std::FILE* const ret = m_file; - m_file = nullptr; - return ret; -} - void IOFile::SetHandle(std::FILE* file) { Close(); diff --git a/Source/Core/Common/FileUtil.h b/Source/Core/Common/FileUtil.h index 755dfcd6e8..df4d6aacd6 100644 --- a/Source/Core/Common/FileUtil.h +++ b/Source/Core/Common/FileUtil.h @@ -212,8 +212,6 @@ public: // m_good is set to false when a read, write or other function fails bool IsGood() const { return m_good; } explicit operator bool() const { return IsGood() && IsOpen(); } - std::FILE* ReleaseHandle(); - std::FILE* GetHandle() { return m_file; } void SetHandle(std::FILE* file); diff --git a/Source/Core/Common/SysConf.cpp b/Source/Core/Common/SysConf.cpp index ec0bad5b9b..3b2ab36694 100644 --- a/Source/Core/Common/SysConf.cpp +++ b/Source/Core/Common/SysConf.cpp @@ -72,7 +72,7 @@ bool SysConf::LoadFromFile(const std::string& filename) File::IOFile f(filename, "rb"); if (f.IsOpen()) { - if (LoadFromFileInternal(f.ReleaseHandle())) + if (LoadFromFileInternal(std::move(f))) { m_Filename = filename; m_IsValid = true; @@ -90,19 +90,18 @@ bool SysConf::LoadFromFile(const std::string& filename) return false; } -bool SysConf::LoadFromFileInternal(FILE* fh) +bool SysConf::LoadFromFileInternal(File::IOFile&& file) { - File::IOFile f(fh); // Fill in infos SSysConfHeader s_Header; - f.ReadArray(s_Header.version, 4); - f.ReadArray(&s_Header.numEntries, 1); + file.ReadArray(s_Header.version, 4); + file.ReadArray(&s_Header.numEntries, 1); s_Header.numEntries = Common::swap16(s_Header.numEntries) + 1; for (u16 index = 0; index < s_Header.numEntries; index++) { SSysConfEntry tmpEntry; - f.ReadArray(&tmpEntry.offset, 1); + file.ReadArray(&tmpEntry.offset, 1); tmpEntry.offset = Common::swap16(tmpEntry.offset); m_Entries.push_back(tmpEntry); } @@ -111,16 +110,16 @@ bool SysConf::LoadFromFileInternal(FILE* fh) for (auto i = m_Entries.begin(); i < m_Entries.end() - 1; ++i) { SSysConfEntry& curEntry = *i; - f.Seek(curEntry.offset, SEEK_SET); + file.Seek(curEntry.offset, SEEK_SET); u8 description = 0; - f.ReadArray(&description, 1); + file.ReadArray(&description, 1); // Data type curEntry.type = (SysconfType)((description & 0xe0) >> 5); // Length of name in bytes - 1 curEntry.nameLength = (description & 0x1f) + 1; // Name - f.ReadArray(curEntry.name, curEntry.nameLength); + file.ReadArray(curEntry.name, curEntry.nameLength); curEntry.name[curEntry.nameLength] = '\0'; // Get length of data curEntry.data = nullptr; @@ -128,14 +127,14 @@ bool SysConf::LoadFromFileInternal(FILE* fh) switch (curEntry.type) { case Type_BigArray: - f.ReadArray(&curEntry.dataLength, 1); + file.ReadArray(&curEntry.dataLength, 1); curEntry.dataLength = Common::swap16(curEntry.dataLength); break; case Type_SmallArray: { u8 dlength = 0; - f.ReadBytes(&dlength, 1); + file.ReadBytes(&dlength, 1); curEntry.dataLength = dlength; break; } @@ -167,11 +166,11 @@ bool SysConf::LoadFromFileInternal(FILE* fh) if (curEntry.dataLength) { curEntry.data = new u8[curEntry.dataLength]; - f.ReadArray(curEntry.data, curEntry.dataLength); + file.ReadArray(curEntry.data, curEntry.dataLength); } } - return f.IsGood(); + return file.IsGood(); } // Returns the size of the item in file diff --git a/Source/Core/Common/SysConf.h b/Source/Core/Common/SysConf.h index 8b085051a7..97b3a98232 100644 --- a/Source/Core/Common/SysConf.h +++ b/Source/Core/Common/SysConf.h @@ -14,6 +14,11 @@ #include "Common/Logging/Log.h" #include "Common/MsgHandler.h" +namespace File +{ +class IOFile; +} + // This class is meant to edit the values in a given Wii SYSCONF file // It currently does not add/remove/rearrange sections, // instead only modifies exiting sections' data @@ -175,7 +180,7 @@ public: void UpdateLocation(); private: - bool LoadFromFileInternal(FILE* fh); + bool LoadFromFileInternal(File::IOFile&& file); void GenerateSysConf(); void Clear(); diff --git a/Source/Core/Core/HW/GCMemcard.cpp b/Source/Core/Core/HW/GCMemcard.cpp index be8ba4d249..c08b798458 100644 --- a/Source/Core/Core/HW/GCMemcard.cpp +++ b/Source/Core/Core/HW/GCMemcard.cpp @@ -827,15 +827,12 @@ u32 GCMemcard::ImportGci(const std::string& inputFile, const std::string& output if (!gci) return OPENFAIL; - u32 result = ImportGciInternal(gci.ReleaseHandle(), inputFile, outputFile); - - return result; + return ImportGciInternal(std::move(gci), inputFile, outputFile); } -u32 GCMemcard::ImportGciInternal(FILE* gcih, const std::string& inputFile, +u32 GCMemcard::ImportGciInternal(File::IOFile&& gci, const std::string& inputFile, const std::string& outputFile) { - File::IOFile gci(gcih); unsigned int offset; std::string fileType; SplitPath(inputFile, nullptr, nullptr, &fileType); diff --git a/Source/Core/Core/HW/GCMemcard.h b/Source/Core/Core/HW/GCMemcard.h index 69f6c5c85e..5a01623707 100644 --- a/Source/Core/Core/HW/GCMemcard.h +++ b/Source/Core/Core/HW/GCMemcard.h @@ -15,6 +15,11 @@ #include "Core/HW/EXI_DeviceIPL.h" #include "Core/HW/Sram.h" +namespace File +{ +class IOFile; +} + #define BE64(x) (Common::swap64(x)) #define BE32(x) (Common::swap32(x)) #define BE16(x) (Common::swap16(x)) @@ -304,7 +309,8 @@ private: std::vector mc_data_blocks; - u32 ImportGciInternal(FILE* gcih, const std::string& inputFile, const std::string& outputFile); + u32 ImportGciInternal(File::IOFile&& gci, const std::string& inputFile, + const std::string& outputFile); void InitDirBatPointers(); public: