Merge pull request #4648 from lioncash/iofile

IOFile: Get rid of IOFile's ReleaseHandle function
This commit is contained in:
Matthew Parlane 2017-01-13 08:15:23 +13:00 committed by GitHub
commit 119dfbb436
6 changed files with 27 additions and 29 deletions

View File

@ -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();

View File

@ -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);

View File

@ -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

View File

@ -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();

View File

@ -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);

View File

@ -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<GCMBlock> 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: