Merge pull request #4648 from lioncash/iofile
IOFile: Get rid of IOFile's ReleaseHandle function
This commit is contained in:
commit
119dfbb436
|
@ -947,13 +947,6 @@ bool IOFile::Close()
|
||||||
return m_good;
|
return m_good;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::FILE* IOFile::ReleaseHandle()
|
|
||||||
{
|
|
||||||
std::FILE* const ret = m_file;
|
|
||||||
m_file = nullptr;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void IOFile::SetHandle(std::FILE* file)
|
void IOFile::SetHandle(std::FILE* file)
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
|
|
|
@ -212,8 +212,6 @@ public:
|
||||||
// m_good is set to false when a read, write or other function fails
|
// m_good is set to false when a read, write or other function fails
|
||||||
bool IsGood() const { return m_good; }
|
bool IsGood() const { return m_good; }
|
||||||
explicit operator bool() const { return IsGood() && IsOpen(); }
|
explicit operator bool() const { return IsGood() && IsOpen(); }
|
||||||
std::FILE* ReleaseHandle();
|
|
||||||
|
|
||||||
std::FILE* GetHandle() { return m_file; }
|
std::FILE* GetHandle() { return m_file; }
|
||||||
void SetHandle(std::FILE* file);
|
void SetHandle(std::FILE* file);
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ bool SysConf::LoadFromFile(const std::string& filename)
|
||||||
File::IOFile f(filename, "rb");
|
File::IOFile f(filename, "rb");
|
||||||
if (f.IsOpen())
|
if (f.IsOpen())
|
||||||
{
|
{
|
||||||
if (LoadFromFileInternal(f.ReleaseHandle()))
|
if (LoadFromFileInternal(std::move(f)))
|
||||||
{
|
{
|
||||||
m_Filename = filename;
|
m_Filename = filename;
|
||||||
m_IsValid = true;
|
m_IsValid = true;
|
||||||
|
@ -90,19 +90,18 @@ bool SysConf::LoadFromFile(const std::string& filename)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SysConf::LoadFromFileInternal(FILE* fh)
|
bool SysConf::LoadFromFileInternal(File::IOFile&& file)
|
||||||
{
|
{
|
||||||
File::IOFile f(fh);
|
|
||||||
// Fill in infos
|
// Fill in infos
|
||||||
SSysConfHeader s_Header;
|
SSysConfHeader s_Header;
|
||||||
f.ReadArray(s_Header.version, 4);
|
file.ReadArray(s_Header.version, 4);
|
||||||
f.ReadArray(&s_Header.numEntries, 1);
|
file.ReadArray(&s_Header.numEntries, 1);
|
||||||
s_Header.numEntries = Common::swap16(s_Header.numEntries) + 1;
|
s_Header.numEntries = Common::swap16(s_Header.numEntries) + 1;
|
||||||
|
|
||||||
for (u16 index = 0; index < s_Header.numEntries; index++)
|
for (u16 index = 0; index < s_Header.numEntries; index++)
|
||||||
{
|
{
|
||||||
SSysConfEntry tmpEntry;
|
SSysConfEntry tmpEntry;
|
||||||
f.ReadArray(&tmpEntry.offset, 1);
|
file.ReadArray(&tmpEntry.offset, 1);
|
||||||
tmpEntry.offset = Common::swap16(tmpEntry.offset);
|
tmpEntry.offset = Common::swap16(tmpEntry.offset);
|
||||||
m_Entries.push_back(tmpEntry);
|
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)
|
for (auto i = m_Entries.begin(); i < m_Entries.end() - 1; ++i)
|
||||||
{
|
{
|
||||||
SSysConfEntry& curEntry = *i;
|
SSysConfEntry& curEntry = *i;
|
||||||
f.Seek(curEntry.offset, SEEK_SET);
|
file.Seek(curEntry.offset, SEEK_SET);
|
||||||
|
|
||||||
u8 description = 0;
|
u8 description = 0;
|
||||||
f.ReadArray(&description, 1);
|
file.ReadArray(&description, 1);
|
||||||
// Data type
|
// Data type
|
||||||
curEntry.type = (SysconfType)((description & 0xe0) >> 5);
|
curEntry.type = (SysconfType)((description & 0xe0) >> 5);
|
||||||
// Length of name in bytes - 1
|
// Length of name in bytes - 1
|
||||||
curEntry.nameLength = (description & 0x1f) + 1;
|
curEntry.nameLength = (description & 0x1f) + 1;
|
||||||
// Name
|
// Name
|
||||||
f.ReadArray(curEntry.name, curEntry.nameLength);
|
file.ReadArray(curEntry.name, curEntry.nameLength);
|
||||||
curEntry.name[curEntry.nameLength] = '\0';
|
curEntry.name[curEntry.nameLength] = '\0';
|
||||||
// Get length of data
|
// Get length of data
|
||||||
curEntry.data = nullptr;
|
curEntry.data = nullptr;
|
||||||
|
@ -128,14 +127,14 @@ bool SysConf::LoadFromFileInternal(FILE* fh)
|
||||||
switch (curEntry.type)
|
switch (curEntry.type)
|
||||||
{
|
{
|
||||||
case Type_BigArray:
|
case Type_BigArray:
|
||||||
f.ReadArray(&curEntry.dataLength, 1);
|
file.ReadArray(&curEntry.dataLength, 1);
|
||||||
curEntry.dataLength = Common::swap16(curEntry.dataLength);
|
curEntry.dataLength = Common::swap16(curEntry.dataLength);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Type_SmallArray:
|
case Type_SmallArray:
|
||||||
{
|
{
|
||||||
u8 dlength = 0;
|
u8 dlength = 0;
|
||||||
f.ReadBytes(&dlength, 1);
|
file.ReadBytes(&dlength, 1);
|
||||||
curEntry.dataLength = dlength;
|
curEntry.dataLength = dlength;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -167,11 +166,11 @@ bool SysConf::LoadFromFileInternal(FILE* fh)
|
||||||
if (curEntry.dataLength)
|
if (curEntry.dataLength)
|
||||||
{
|
{
|
||||||
curEntry.data = new u8[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
|
// Returns the size of the item in file
|
||||||
|
|
|
@ -14,6 +14,11 @@
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
#include "Common/MsgHandler.h"
|
#include "Common/MsgHandler.h"
|
||||||
|
|
||||||
|
namespace File
|
||||||
|
{
|
||||||
|
class IOFile;
|
||||||
|
}
|
||||||
|
|
||||||
// This class is meant to edit the values in a given Wii SYSCONF file
|
// This class is meant to edit the values in a given Wii SYSCONF file
|
||||||
// It currently does not add/remove/rearrange sections,
|
// It currently does not add/remove/rearrange sections,
|
||||||
// instead only modifies exiting sections' data
|
// instead only modifies exiting sections' data
|
||||||
|
@ -175,7 +180,7 @@ public:
|
||||||
void UpdateLocation();
|
void UpdateLocation();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool LoadFromFileInternal(FILE* fh);
|
bool LoadFromFileInternal(File::IOFile&& file);
|
||||||
void GenerateSysConf();
|
void GenerateSysConf();
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
|
|
|
@ -827,15 +827,12 @@ u32 GCMemcard::ImportGci(const std::string& inputFile, const std::string& output
|
||||||
if (!gci)
|
if (!gci)
|
||||||
return OPENFAIL;
|
return OPENFAIL;
|
||||||
|
|
||||||
u32 result = ImportGciInternal(gci.ReleaseHandle(), inputFile, outputFile);
|
return ImportGciInternal(std::move(gci), inputFile, outputFile);
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 GCMemcard::ImportGciInternal(FILE* gcih, const std::string& inputFile,
|
u32 GCMemcard::ImportGciInternal(File::IOFile&& gci, const std::string& inputFile,
|
||||||
const std::string& outputFile)
|
const std::string& outputFile)
|
||||||
{
|
{
|
||||||
File::IOFile gci(gcih);
|
|
||||||
unsigned int offset;
|
unsigned int offset;
|
||||||
std::string fileType;
|
std::string fileType;
|
||||||
SplitPath(inputFile, nullptr, nullptr, &fileType);
|
SplitPath(inputFile, nullptr, nullptr, &fileType);
|
||||||
|
|
|
@ -15,6 +15,11 @@
|
||||||
#include "Core/HW/EXI_DeviceIPL.h"
|
#include "Core/HW/EXI_DeviceIPL.h"
|
||||||
#include "Core/HW/Sram.h"
|
#include "Core/HW/Sram.h"
|
||||||
|
|
||||||
|
namespace File
|
||||||
|
{
|
||||||
|
class IOFile;
|
||||||
|
}
|
||||||
|
|
||||||
#define BE64(x) (Common::swap64(x))
|
#define BE64(x) (Common::swap64(x))
|
||||||
#define BE32(x) (Common::swap32(x))
|
#define BE32(x) (Common::swap32(x))
|
||||||
#define BE16(x) (Common::swap16(x))
|
#define BE16(x) (Common::swap16(x))
|
||||||
|
@ -304,7 +309,8 @@ private:
|
||||||
|
|
||||||
std::vector<GCMBlock> mc_data_blocks;
|
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();
|
void InitDirBatPointers();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue