mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-29 17:19:44 -06:00
IOFile: Get rid of IOFile's ReleaseHandle function
Transfer of handles should be done via std::move.
This commit is contained in:
@ -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();
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
||||
|
Reference in New Issue
Block a user