From 36cfcb530f6810afca93e75c47f767a453a99361 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sat, 29 Jan 2022 05:58:31 +0100 Subject: [PATCH] IOFile: Make origin parameter to Seek() an enum class. --- Source/Core/AudioCommon/WaveFile.cpp | 5 ++-- Source/Core/Common/IOFile.cpp | 20 +++++++++++-- Source/Core/Common/IOFile.h | 9 +++++- Source/Core/Common/LinearDiskCache.h | 2 +- Source/Core/Core/Boot/Boot.cpp | 2 +- Source/Core/Core/FifoPlayer/FifoDataFile.cpp | 28 +++++++++---------- Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp | 2 +- Source/Core/Core/HW/GCMemcard/GCIFile.cpp | 2 +- Source/Core/Core/HW/GCMemcard/GCMemcard.cpp | 4 +-- Source/Core/Core/HW/WiiSave.cpp | 23 ++++++++------- Source/Core/Core/IOS/FS/HostBackend/File.cpp | 4 +-- Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp | 8 +++--- Source/Core/Core/IOS/WFS/WFSSRV.cpp | 8 +++--- Source/Core/Core/Movie.cpp | 2 +- Source/Core/DiscIO/CISOBlob.cpp | 10 +++++-- Source/Core/DiscIO/CompressedBlob.cpp | 14 +++++----- Source/Core/DiscIO/DirectoryBlob.cpp | 2 +- Source/Core/DiscIO/DriveBlob.cpp | 2 +- Source/Core/DiscIO/FileBlob.cpp | 2 +- Source/Core/DiscIO/NANDImporter.cpp | 4 ++- Source/Core/DiscIO/TGCBlob.cpp | 15 +++++++--- Source/Core/DiscIO/WIABlob.cpp | 12 ++++---- Source/Core/DiscIO/WbfsBlob.cpp | 8 +++--- Source/Core/DiscIO/WiiSaveBanner.cpp | 2 +- .../VideoCommon/HiresTextures_DDSLoader.cpp | 2 +- Source/Core/VideoCommon/ShaderCache.cpp | 2 +- 26 files changed, 116 insertions(+), 78 deletions(-) diff --git a/Source/Core/AudioCommon/WaveFile.cpp b/Source/Core/AudioCommon/WaveFile.cpp index a7dd489db3..edc870bef7 100644 --- a/Source/Core/AudioCommon/WaveFile.cpp +++ b/Source/Core/AudioCommon/WaveFile.cpp @@ -95,11 +95,10 @@ bool WaveFileWriter::Start(const std::string& filename, unsigned int HLESampleRa void WaveFileWriter::Stop() { - // u32 file_size = (u32)ftello(file); - file.Seek(4, SEEK_SET); + file.Seek(4, File::SeekOrigin::Begin); Write(audio_size + 36); - file.Seek(40, SEEK_SET); + file.Seek(40, File::SeekOrigin::Begin); Write(audio_size); file.Close(); diff --git a/Source/Core/Common/IOFile.cpp b/Source/Core/Common/IOFile.cpp index 1378906357..e0f16582be 100644 --- a/Source/Core/Common/IOFile.cpp +++ b/Source/Core/Common/IOFile.cpp @@ -106,9 +106,25 @@ u64 IOFile::GetSize() const return 0; } -bool IOFile::Seek(s64 off, int origin) +bool IOFile::Seek(s64 offset, SeekOrigin origin) { - if (!IsOpen() || 0 != fseeko(m_file, off, origin)) + int fseek_origin; + switch (origin) + { + case SeekOrigin::Begin: + fseek_origin = SEEK_SET; + break; + case SeekOrigin::Current: + fseek_origin = SEEK_CUR; + break; + case SeekOrigin::End: + fseek_origin = SEEK_END; + break; + default: + return false; + } + + if (!IsOpen() || 0 != fseeko(m_file, offset, fseek_origin)) m_good = false; return m_good; diff --git a/Source/Core/Common/IOFile.h b/Source/Core/Common/IOFile.h index 873c4c2af5..21c2ff6fcf 100644 --- a/Source/Core/Common/IOFile.h +++ b/Source/Core/Common/IOFile.h @@ -13,6 +13,13 @@ namespace File { +enum class SeekOrigin +{ + Begin, + Current, + End, +}; + // simple wrapper for cstdlib file functions to // hopefully will make error checking easier // and make forgetting an fclose() harder @@ -89,7 +96,7 @@ public: std::FILE* GetHandle() { return m_file; } void SetHandle(std::FILE* file); - bool Seek(s64 off, int origin); + bool Seek(s64 offset, SeekOrigin origin); u64 Tell() const; u64 GetSize() const; bool Resize(u64 size); diff --git a/Source/Core/Common/LinearDiskCache.h b/Source/Core/Common/LinearDiskCache.h index 78982109b9..541accf8d3 100644 --- a/Source/Core/Common/LinearDiskCache.h +++ b/Source/Core/Common/LinearDiskCache.h @@ -101,7 +101,7 @@ public: m_num_entries++; } m_file.Clear(); - m_file.Seek(last_valid_value_start, SEEK_SET); + m_file.Seek(last_valid_value_start, File::SeekOrigin::Begin); return m_num_entries; } diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index 47e3674397..30691c730f 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -650,7 +650,7 @@ BootExecutableReader::BootExecutableReader(const std::string& file_name) BootExecutableReader::BootExecutableReader(File::IOFile file) { - file.Seek(0, SEEK_SET); + file.Seek(0, File::SeekOrigin::Begin); m_bytes.resize(file.GetSize()); file.ReadBytes(m_bytes.data(), m_bytes.size()); } diff --git a/Source/Core/Core/FifoPlayer/FifoDataFile.cpp b/Source/Core/Core/FifoPlayer/FifoDataFile.cpp index 16f4c2ba64..7bfdff7833 100644 --- a/Source/Core/Core/FifoPlayer/FifoDataFile.cpp +++ b/Source/Core/Core/FifoPlayer/FifoDataFile.cpp @@ -167,7 +167,7 @@ bool FifoDataFile::Save(const std::string& filename) header.mem1_size = Memory::GetRamSizeReal(); header.mem2_size = Memory::GetExRamSizeReal(); - file.Seek(0, SEEK_SET); + file.Seek(0, File::SeekOrigin::Begin); file.WriteBytes(&header, sizeof(FileHeader)); // Write frames list @@ -176,7 +176,7 @@ bool FifoDataFile::Save(const std::string& filename) const FifoFrameInfo& srcFrame = m_Frames[i]; // Write FIFO data - file.Seek(0, SEEK_END); + file.Seek(0, File::SeekOrigin::End); u64 dataOffset = file.Tell(); file.WriteBytes(srcFrame.fifoData.data(), srcFrame.fifoData.size()); @@ -192,7 +192,7 @@ bool FifoDataFile::Save(const std::string& filename) // Write frame info u64 frameOffset = frameListOffset + (i * sizeof(FileFrameInfo)); - file.Seek(frameOffset, SEEK_SET); + file.Seek(frameOffset, File::SeekOrigin::Begin); file.WriteBytes(&dstFrame, sizeof(FileFrameInfo)); } @@ -284,19 +284,19 @@ std::unique_ptr FifoDataFile::Load(const std::string& filename, bo } u32 size = std::min(BP_MEM_SIZE, header.bpMemSize); - file.Seek(header.bpMemOffset, SEEK_SET); + file.Seek(header.bpMemOffset, File::SeekOrigin::Begin); file.ReadArray(&dataFile->m_BPMem); size = std::min(CP_MEM_SIZE, header.cpMemSize); - file.Seek(header.cpMemOffset, SEEK_SET); + file.Seek(header.cpMemOffset, File::SeekOrigin::Begin); file.ReadArray(&dataFile->m_CPMem); size = std::min(XF_MEM_SIZE, header.xfMemSize); - file.Seek(header.xfMemOffset, SEEK_SET); + file.Seek(header.xfMemOffset, File::SeekOrigin::Begin); file.ReadArray(&dataFile->m_XFMem); size = std::min(XF_REGS_SIZE, header.xfRegsSize); - file.Seek(header.xfRegsOffset, SEEK_SET); + file.Seek(header.xfRegsOffset, File::SeekOrigin::Begin); file.ReadArray(&dataFile->m_XFRegs); // Texture memory saving was added in version 4. @@ -304,7 +304,7 @@ std::unique_ptr FifoDataFile::Load(const std::string& filename, bo if (dataFile->m_Version >= 4) { size = std::min(TEX_MEM_SIZE, header.texMemSize); - file.Seek(header.texMemOffset, SEEK_SET); + file.Seek(header.texMemOffset, File::SeekOrigin::Begin); file.ReadArray(&dataFile->m_TexMem); } @@ -319,7 +319,7 @@ std::unique_ptr FifoDataFile::Load(const std::string& filename, bo for (u32 i = 0; i < header.frameCount; ++i) { u64 frameOffset = header.frameListOffset + (i * sizeof(FileFrameInfo)); - file.Seek(frameOffset, SEEK_SET); + file.Seek(frameOffset, File::SeekOrigin::Begin); FileFrameInfo srcFrame; if (!file.ReadBytes(&srcFrame, sizeof(FileFrameInfo))) return panic_failed_to_read(); @@ -329,7 +329,7 @@ std::unique_ptr FifoDataFile::Load(const std::string& filename, bo dstFrame.fifoStart = srcFrame.fifoStart; dstFrame.fifoEnd = srcFrame.fifoEnd; - file.Seek(srcFrame.fifoDataOffset, SEEK_SET); + file.Seek(srcFrame.fifoDataOffset, File::SeekOrigin::Begin); file.ReadBytes(dstFrame.fifoData.data(), srcFrame.fifoDataSize); ReadMemoryUpdates(srcFrame.memoryUpdatesOffset, srcFrame.numMemoryUpdates, @@ -375,7 +375,7 @@ u64 FifoDataFile::WriteMemoryUpdates(const std::vector& memUpdates const MemoryUpdate& srcUpdate = memUpdates[i]; // Write memory - file.Seek(0, SEEK_END); + file.Seek(0, File::SeekOrigin::End); u64 dataOffset = file.Tell(); file.WriteBytes(srcUpdate.data.data(), srcUpdate.data.size()); @@ -387,7 +387,7 @@ u64 FifoDataFile::WriteMemoryUpdates(const std::vector& memUpdates dstUpdate.type = srcUpdate.type; u64 updateOffset = updateListOffset + (i * sizeof(FileMemoryUpdate)); - file.Seek(updateOffset, SEEK_SET); + file.Seek(updateOffset, File::SeekOrigin::Begin); file.WriteBytes(&dstUpdate, sizeof(FileMemoryUpdate)); } @@ -402,7 +402,7 @@ void FifoDataFile::ReadMemoryUpdates(u64 fileOffset, u32 numUpdates, for (u32 i = 0; i < numUpdates; ++i) { u64 updateOffset = fileOffset + (i * sizeof(FileMemoryUpdate)); - file.Seek(updateOffset, SEEK_SET); + file.Seek(updateOffset, File::SeekOrigin::Begin); FileMemoryUpdate srcUpdate; file.ReadBytes(&srcUpdate, sizeof(FileMemoryUpdate)); @@ -412,7 +412,7 @@ void FifoDataFile::ReadMemoryUpdates(u64 fileOffset, u32 numUpdates, dstUpdate.data.resize(srcUpdate.dataSize); dstUpdate.type = static_cast(srcUpdate.type); - file.Seek(srcUpdate.dataOffset, SEEK_SET); + file.Seek(srcUpdate.dataOffset, File::SeekOrigin::Begin); file.ReadBytes(dstUpdate.data.data(), srcUpdate.dataSize); } } diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp index e55f880869..6f4d7ad2c2 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp +++ b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp @@ -236,7 +236,7 @@ void CEXIIPL::LoadFontFile(const std::string& filename, u32 offset) INFO_LOG_FMT(BOOT, "Found IPL dump, loading {} font from {}", (offset == 0x1aff00) ? "Shift JIS" : "Windows-1252", ipl_rom_path); - stream.Seek(offset, 0); + stream.Seek(offset, File::SeekOrigin::Begin); stream.ReadBytes(&m_rom[offset], fontsize); m_fonts_loaded = true; diff --git a/Source/Core/Core/HW/GCMemcard/GCIFile.cpp b/Source/Core/Core/HW/GCMemcard/GCIFile.cpp index 886448709a..6bbb70e590 100644 --- a/Source/Core/Core/HW/GCMemcard/GCIFile.cpp +++ b/Source/Core/Core/HW/GCMemcard/GCIFile.cpp @@ -55,7 +55,7 @@ bool GCIFile::LoadSaveBlocks() } m_save_data.resize(num_blocks); - save_file.Seek(DENTRY_SIZE, SEEK_SET); + save_file.Seek(DENTRY_SIZE, File::SeekOrigin::Begin); if (!save_file.ReadBytes(m_save_data.data(), size)) { ERROR_LOG_FMT(EXPANSIONINTERFACE, "Failed to read data from GCI file {}", m_filename); diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp b/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp index 8a8c65a8d9..e6b6383de5 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp +++ b/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp @@ -112,7 +112,7 @@ std::pair> GCMemcard::Open(std::str // read the entire card into memory GCMemcard card; - file.Seek(0, SEEK_SET); + file.Seek(0, File::SeekOrigin::Begin); if (!file.ReadBytes(&card.m_header_block, BLOCK_SIZE) || !file.ReadBytes(&card.m_directory_blocks[0], BLOCK_SIZE) || !file.ReadBytes(&card.m_directory_blocks[1], BLOCK_SIZE) || @@ -310,7 +310,7 @@ bool GCMemcard::IsShiftJIS() const bool GCMemcard::Save() { File::IOFile mcdFile(m_filename, "wb"); - mcdFile.Seek(0, SEEK_SET); + mcdFile.Seek(0, File::SeekOrigin::Begin); mcdFile.WriteBytes(&m_header_block, BLOCK_SIZE); mcdFile.WriteBytes(&m_directory_blocks[0], BLOCK_SIZE); diff --git a/Source/Core/Core/HW/WiiSave.cpp b/Source/Core/Core/HW/WiiSave.cpp index 52ce17112e..62bbf9e7e0 100644 --- a/Source/Core/Core/HW/WiiSave.cpp +++ b/Source/Core/Core/HW/WiiSave.cpp @@ -278,7 +278,7 @@ public: std::optional
ReadHeader() override { Header header; - if (!m_file.Seek(0, SEEK_SET) || !m_file.ReadArray(&header, 1)) + if (!m_file.Seek(0, File::SeekOrigin::Begin) || !m_file.ReadArray(&header, 1)) return {}; std::array iv = s_sd_initial_iv; @@ -310,7 +310,7 @@ public: std::optional ReadBkHeader() override { BkHeader bk_header; - m_file.Seek(sizeof(Header), SEEK_SET); + m_file.Seek(sizeof(Header), File::SeekOrigin::Begin); if (!m_file.ReadArray(&bk_header, 1)) return {}; if (bk_header.size != BK_LISTED_SZ || bk_header.magic != BK_HDR_MAGIC) @@ -323,7 +323,7 @@ public: std::optional> ReadFiles() override { const std::optional bk_header = ReadBkHeader(); - if (!bk_header || !m_file.Seek(sizeof(Header) + sizeof(BkHeader), SEEK_SET)) + if (!bk_header || !m_file.Seek(sizeof(Header) + sizeof(BkHeader), File::SeekOrigin::Begin)) return {}; std::vector files; @@ -352,15 +352,18 @@ public: save_file.data = [this, size, rounded_size, iv, pos]() mutable -> std::optional> { std::vector file_data(rounded_size); - if (!m_file.Seek(pos, SEEK_SET) || !m_file.ReadBytes(file_data.data(), rounded_size)) + if (!m_file.Seek(pos, File::SeekOrigin::Begin) || + !m_file.ReadBytes(file_data.data(), rounded_size)) + { return {}; + } m_iosc.Decrypt(IOS::HLE::IOSC::HANDLE_SD_KEY, iv.data(), file_data.data(), rounded_size, file_data.data(), IOS::PID_ES); file_data.resize(size); return file_data; }; - m_file.Seek(pos + rounded_size, SEEK_SET); + m_file.Seek(pos + rounded_size, File::SeekOrigin::Begin); } files.emplace_back(std::move(save_file)); } @@ -373,17 +376,17 @@ public: std::array iv = s_sd_initial_iv; m_iosc.Encrypt(IOS::HLE::IOSC::HANDLE_SD_KEY, iv.data(), reinterpret_cast(&header), sizeof(Header), reinterpret_cast(&encrypted_header), IOS::PID_ES); - return m_file.Seek(0, SEEK_SET) && m_file.WriteArray(&encrypted_header, 1); + return m_file.Seek(0, File::SeekOrigin::Begin) && m_file.WriteArray(&encrypted_header, 1); } bool WriteBkHeader(const BkHeader& bk_header) override { - return m_file.Seek(sizeof(Header), SEEK_SET) && m_file.WriteArray(&bk_header, 1); + return m_file.Seek(sizeof(Header), File::SeekOrigin::Begin) && m_file.WriteArray(&bk_header, 1); } bool WriteFiles(const std::vector& files) override { - if (!m_file.Seek(sizeof(Header) + sizeof(BkHeader), SEEK_SET)) + if (!m_file.Seek(sizeof(Header) + sizeof(BkHeader), File::SeekOrigin::Begin)) return false; for (const SaveFile& save_file : files) @@ -440,7 +443,7 @@ private: { const u32 data_size = bk_header->size_of_files + sizeof(BkHeader); auto data = std::make_unique(data_size); - m_file.Seek(sizeof(Header), SEEK_SET); + m_file.Seek(sizeof(Header), File::SeekOrigin::Begin); if (!m_file.ReadBytes(data.get(), data_size)) return false; mbedtls_sha1_ret(data.get(), data_size, data_sha1.data()); @@ -453,7 +456,7 @@ private: data_sha1.data(), static_cast(data_sha1.size())); // Write signatures. - if (!m_file.Seek(0, SEEK_END)) + if (!m_file.Seek(0, File::SeekOrigin::End)) return false; const u32 SIGNATURE_END_MAGIC = Common::swap32(0x2f536969); const IOS::CertECC device_certificate = m_iosc.GetDeviceCertificate(); diff --git a/Source/Core/Core/IOS/FS/HostBackend/File.cpp b/Source/Core/Core/IOS/FS/HostBackend/File.cpp index 1e4ea5e725..9f58c2fffa 100644 --- a/Source/Core/Core/IOS/FS/HostBackend/File.cpp +++ b/Source/Core/Core/IOS/FS/HostBackend/File.cpp @@ -127,7 +127,7 @@ Result HostFileSystem::ReadBytesFromFile(Fd fd, u8* ptr, u32 count) count = file_size - handle->file_offset; // File might be opened twice, need to seek before we read - handle->host_file->Seek(handle->file_offset, SEEK_SET); + handle->host_file->Seek(handle->file_offset, File::SeekOrigin::Begin); const u32 actually_read = static_cast(fread(ptr, 1, count, handle->host_file->GetHandle())); if (actually_read != count && ferror(handle->host_file->GetHandle())) @@ -149,7 +149,7 @@ Result HostFileSystem::WriteBytesToFile(Fd fd, const u8* ptr, u32 count) return ResultCode::AccessDenied; // File might be opened twice, need to seek before we read - handle->host_file->Seek(handle->file_offset, SEEK_SET); + handle->host_file->Seek(handle->file_offset, File::SeekOrigin::Begin); if (!handle->host_file->WriteBytes(ptr, count)) return ResultCode::AccessDenied; diff --git a/Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp b/Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp index c6dcab44e5..4ea206e6ce 100644 --- a/Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp +++ b/Source/Core/Core/IOS/SDIO/SDIOSlot0.cpp @@ -251,8 +251,8 @@ s32 SDIOSlot0Device::ExecuteCommand(const Request& request, u32 buffer_in, u32 b const u32 size = req.bsize * req.blocks; const u64 address = GetAddressFromRequest(req.arg); - if (!m_card.Seek(address, SEEK_SET)) - ERROR_LOG_FMT(IOS_SD, "Seek failed WTF"); + if (!m_card.Seek(address, File::SeekOrigin::Begin)) + ERROR_LOG_FMT(IOS_SD, "Seek failed"); if (m_card.ReadBytes(Memory::GetPointer(req.addr), size)) { @@ -281,8 +281,8 @@ s32 SDIOSlot0Device::ExecuteCommand(const Request& request, u32 buffer_in, u32 b const u32 size = req.bsize * req.blocks; const u64 address = GetAddressFromRequest(req.arg); - if (!m_card.Seek(address, SEEK_SET)) - ERROR_LOG_FMT(IOS_SD, "fseeko failed WTF"); + if (!m_card.Seek(address, File::SeekOrigin::Begin)) + ERROR_LOG_FMT(IOS_SD, "Seek failed"); if (!m_card.WriteBytes(Memory::GetPointer(req.addr), size)) { diff --git a/Source/Core/Core/IOS/WFS/WFSSRV.cpp b/Source/Core/Core/IOS/WFS/WFSSRV.cpp index 0c19df11b6..26f394d186 100644 --- a/Source/Core/Core/IOS/WFS/WFSSRV.cpp +++ b/Source/Core/Core/IOS/WFS/WFSSRV.cpp @@ -290,14 +290,14 @@ std::optional WFSSRVDevice::IOCtl(const IOCtlRequest& request) const u64 previous_position = fd_obj->file.Tell(); if (absolute) { - fd_obj->file.Seek(position, SEEK_SET); + fd_obj->file.Seek(position, File::SeekOrigin::Begin); } size_t read_bytes; fd_obj->file.ReadArray(Memory::GetPointer(addr), size, &read_bytes); // TODO(wfs): Handle read errors. if (absolute) { - fd_obj->file.Seek(previous_position, SEEK_SET); + fd_obj->file.Seek(previous_position, File::SeekOrigin::Begin); } else { @@ -331,13 +331,13 @@ std::optional WFSSRVDevice::IOCtl(const IOCtlRequest& request) const u64 previous_position = fd_obj->file.Tell(); if (absolute) { - fd_obj->file.Seek(position, SEEK_SET); + fd_obj->file.Seek(position, File::SeekOrigin::Begin); } fd_obj->file.WriteArray(Memory::GetPointer(addr), size); // TODO(wfs): Handle write errors. if (absolute) { - fd_obj->file.Seek(previous_position, SEEK_SET); + fd_obj->file.Seek(previous_position, File::SeekOrigin::Begin); } else { diff --git a/Source/Core/Core/Movie.cpp b/Source/Core/Core/Movie.cpp index 9b1c83ff89..25b8f54018 100644 --- a/Source/Core/Core/Movie.cpp +++ b/Source/Core/Core/Movie.cpp @@ -1021,7 +1021,7 @@ void LoadInput(const std::string& movie_path) { s_rerecords++; tmpHeader.numRerecords = s_rerecords; - t_record.Seek(0, SEEK_SET); + t_record.Seek(0, File::SeekOrigin::Begin); t_record.WriteArray(&tmpHeader, 1); } diff --git a/Source/Core/DiscIO/CISOBlob.cpp b/Source/Core/DiscIO/CISOBlob.cpp index 36c6850abc..f8144eec33 100644 --- a/Source/Core/DiscIO/CISOBlob.cpp +++ b/Source/Core/DiscIO/CISOBlob.cpp @@ -18,7 +18,7 @@ CISOFileReader::CISOFileReader(File::IOFile file) : m_file(std::move(file)) m_size = m_file.GetSize(); CISOHeader header; - m_file.Seek(0, SEEK_SET); + m_file.Seek(0, File::SeekOrigin::Begin); m_file.ReadArray(&header, 1); m_block_size = header.block_size; @@ -31,8 +31,11 @@ CISOFileReader::CISOFileReader(File::IOFile file) : m_file(std::move(file)) std::unique_ptr CISOFileReader::Create(File::IOFile file) { CISOHeader header; - if (file.Seek(0, SEEK_SET) && file.ReadArray(&header, 1) && header.magic == CISO_MAGIC) + if (file.Seek(0, File::SeekOrigin::Begin) && file.ReadArray(&header, 1) && + header.magic == CISO_MAGIC) + { return std::unique_ptr(new CISOFileReader(std::move(file))); + } return nullptr; } @@ -63,7 +66,8 @@ bool CISOFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr) // calculate the base address u64 const file_off = CISO_HEADER_SIZE + m_ciso_map[block] * (u64)m_block_size + data_offset; - if (!(m_file.Seek(file_off, SEEK_SET) && m_file.ReadArray(out_ptr, bytes_to_read))) + if (!(m_file.Seek(file_off, File::SeekOrigin::Begin) && + m_file.ReadArray(out_ptr, bytes_to_read))) { m_file.Clear(); return false; diff --git a/Source/Core/DiscIO/CompressedBlob.cpp b/Source/Core/DiscIO/CompressedBlob.cpp index 8f491a41c6..f537d8b583 100644 --- a/Source/Core/DiscIO/CompressedBlob.cpp +++ b/Source/Core/DiscIO/CompressedBlob.cpp @@ -38,7 +38,7 @@ CompressedBlobReader::CompressedBlobReader(File::IOFile file, const std::string& : m_file(std::move(file)), m_file_name(filename) { m_file_size = m_file.GetSize(); - m_file.Seek(0, SEEK_SET); + m_file.Seek(0, File::SeekOrigin::Begin); m_file.ReadArray(&m_header, 1); SetSectorSize(m_header.block_size); @@ -104,7 +104,7 @@ bool CompressedBlobReader::GetBlock(u64 block_num, u8* out_ptr) // clear unused part of zlib buffer. maybe this can be deleted when it works fully. memset(&m_zlib_buffer[comp_block_size], 0, m_zlib_buffer.size() - comp_block_size); - m_file.Seek(offset, SEEK_SET); + m_file.Seek(offset, File::SeekOrigin::Begin); if (!m_file.ReadBytes(m_zlib_buffer.data(), comp_block_size)) { ERROR_LOG_FMT(DISCIO, "The disc image \"{}\" is truncated, some of the data is missing.", @@ -301,9 +301,9 @@ bool ConvertToGCZ(BlobReader* infile, const std::string& infile_path, std::vector hashes(header.num_blocks); // seek past the header (we will write it at the end) - outfile.Seek(sizeof(CompressedBlobHeader), SEEK_CUR); + outfile.Seek(sizeof(CompressedBlobHeader), File::SeekOrigin::Current); // seek past the offset and hash tables (we will write them at the end) - outfile.Seek((sizeof(u64) + sizeof(u32)) * header.num_blocks, SEEK_CUR); + outfile.Seek((sizeof(u64) + sizeof(u32)) * header.num_blocks, File::SeekOrigin::Current); // Now we are ready to write compressed data! u64 inpos = 0; @@ -361,7 +361,7 @@ bool ConvertToGCZ(BlobReader* infile, const std::string& infile_path, else { // Okay, go back and fill in headers - outfile.Seek(0, SEEK_SET); + outfile.Seek(0, File::SeekOrigin::Begin); outfile.WriteArray(&header, 1); outfile.WriteArray(offsets.data(), header.num_blocks); outfile.WriteArray(hashes.data(), header.num_blocks); @@ -385,11 +385,11 @@ bool ConvertToGCZ(BlobReader* infile, const std::string& infile_path, bool IsGCZBlob(File::IOFile& file) { const u64 position = file.Tell(); - if (!file.Seek(0, SEEK_SET)) + if (!file.Seek(0, File::SeekOrigin::Begin)) return false; CompressedBlobHeader header; bool is_gcz = file.ReadArray(&header, 1) && header.magic_cookie == GCZ_MAGIC; - file.Seek(position, SEEK_SET); + file.Seek(position, File::SeekOrigin::Begin); return is_gcz; } diff --git a/Source/Core/DiscIO/DirectoryBlob.cpp b/Source/Core/DiscIO/DirectoryBlob.cpp index cc0222b014..86de55595a 100644 --- a/Source/Core/DiscIO/DirectoryBlob.cpp +++ b/Source/Core/DiscIO/DirectoryBlob.cpp @@ -98,7 +98,7 @@ bool DiscContent::Read(u64* offset, u64* length, u8** buffer) const { const auto& content = std::get(m_content_source); File::IOFile file(content.m_filename, "rb"); - if (!file.Seek(content.m_offset + offset_in_content, SEEK_SET) || + if (!file.Seek(content.m_offset + offset_in_content, File::SeekOrigin::Begin) || !file.ReadBytes(*buffer, bytes_to_read)) { return false; diff --git a/Source/Core/DiscIO/DriveBlob.cpp b/Source/Core/DiscIO/DriveBlob.cpp index 3755317e3a..000915692c 100644 --- a/Source/Core/DiscIO/DriveBlob.cpp +++ b/Source/Core/DiscIO/DriveBlob.cpp @@ -150,7 +150,7 @@ bool DriveReader::ReadMultipleAlignedBlocks(u64 block_num, u64 num_blocks, u8* o } return bytes_read == GetSectorSize() * num_blocks; #else - m_file.Seek(GetSectorSize() * block_num, SEEK_SET); + m_file.Seek(GetSectorSize() * block_num, File::SeekOrigin::Begin); if (m_file.ReadBytes(out_ptr, num_blocks * GetSectorSize())) return true; m_file.Clear(); diff --git a/Source/Core/DiscIO/FileBlob.cpp b/Source/Core/DiscIO/FileBlob.cpp index 17c855fbfe..8a9cfafcdc 100644 --- a/Source/Core/DiscIO/FileBlob.cpp +++ b/Source/Core/DiscIO/FileBlob.cpp @@ -30,7 +30,7 @@ std::unique_ptr PlainFileReader::Create(File::IOFile file) bool PlainFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr) { - if (m_file.Seek(offset, SEEK_SET) && m_file.ReadBytes(out_ptr, nbytes)) + if (m_file.Seek(offset, File::SeekOrigin::Begin) && m_file.ReadBytes(out_ptr, nbytes)) { return true; } diff --git a/Source/Core/DiscIO/NANDImporter.cpp b/Source/Core/DiscIO/NANDImporter.cpp index ea72c3e6c4..ccd1525b62 100644 --- a/Source/Core/DiscIO/NANDImporter.cpp +++ b/Source/Core/DiscIO/NANDImporter.cpp @@ -71,7 +71,9 @@ bool NANDImporter::ReadNANDBin(const std::string& path_to_bin, m_update_callback(); file.ReadBytes(&m_nand[i * NAND_BLOCK_SIZE], NAND_BLOCK_SIZE); - file.Seek(NAND_ECC_BLOCK_SIZE, SEEK_CUR); // We don't care about the ECC blocks + + // We don't care about the ECC blocks + file.Seek(NAND_ECC_BLOCK_SIZE, File::SeekOrigin::Current); } m_nand_keys.resize(NAND_KEYS_SIZE); diff --git a/Source/Core/DiscIO/TGCBlob.cpp b/Source/Core/DiscIO/TGCBlob.cpp index b6402a44bc..b0571726fa 100644 --- a/Source/Core/DiscIO/TGCBlob.cpp +++ b/Source/Core/DiscIO/TGCBlob.cpp @@ -48,15 +48,18 @@ namespace DiscIO std::unique_ptr TGCFileReader::Create(File::IOFile file) { TGCHeader header; - if (file.Seek(0, SEEK_SET) && file.ReadArray(&header, 1) && header.magic == TGC_MAGIC) + if (file.Seek(0, File::SeekOrigin::Begin) && file.ReadArray(&header, 1) && + header.magic == TGC_MAGIC) + { return std::unique_ptr(new TGCFileReader(std::move(file))); + } return nullptr; } TGCFileReader::TGCFileReader(File::IOFile file) : m_file(std::move(file)) { - m_file.Seek(0, SEEK_SET); + m_file.Seek(0, File::SeekOrigin::Begin); m_file.ReadArray(&m_header, 1); m_size = m_file.GetSize(); @@ -64,8 +67,11 @@ TGCFileReader::TGCFileReader(File::IOFile file) : m_file(std::move(file)) const u32 fst_offset = Common::swap32(m_header.fst_real_offset); const u32 fst_size = Common::swap32(m_header.fst_size); m_fst.resize(fst_size); - if (!m_file.Seek(fst_offset, SEEK_SET) || !m_file.ReadBytes(m_fst.data(), m_fst.size())) + if (!m_file.Seek(fst_offset, File::SeekOrigin::Begin) || + !m_file.ReadBytes(m_fst.data(), m_fst.size())) + { m_fst.clear(); + } constexpr size_t FST_ENTRY_SIZE = 12; if (m_fst.size() < FST_ENTRY_SIZE) @@ -101,7 +107,8 @@ bool TGCFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr) { const u32 tgc_header_size = Common::swap32(m_header.tgc_header_size); - if (m_file.Seek(offset + tgc_header_size, SEEK_SET) && m_file.ReadBytes(out_ptr, nbytes)) + if (m_file.Seek(offset + tgc_header_size, File::SeekOrigin::Begin) && + m_file.ReadBytes(out_ptr, nbytes)) { const u32 replacement_dol_offset = SubtractBE32(m_header.dol_real_offset, tgc_header_size); const u32 replacement_fst_offset = SubtractBE32(m_header.fst_real_offset, tgc_header_size); diff --git a/Source/Core/DiscIO/WIABlob.cpp b/Source/Core/DiscIO/WIABlob.cpp index 85e5508f7f..fa83e73043 100644 --- a/Source/Core/DiscIO/WIABlob.cpp +++ b/Source/Core/DiscIO/WIABlob.cpp @@ -87,7 +87,7 @@ WIARVZFileReader::~WIARVZFileReader() = default; template bool WIARVZFileReader::Initialize(const std::string& path) { - if (!m_file.Seek(0, SEEK_SET) || !m_file.ReadArray(&m_header_1, 1)) + if (!m_file.Seek(0, File::SeekOrigin::Begin) || !m_file.ReadArray(&m_header_1, 1)) return false; if ((!RVZ && m_header_1.magic != WIA_MAGIC) || (RVZ && m_header_1.magic != RVZ_MAGIC)) @@ -160,7 +160,7 @@ bool WIARVZFileReader::Initialize(const std::string& path) const size_t number_of_partition_entries = Common::swap32(m_header_2.number_of_partition_entries); const size_t partition_entry_size = Common::swap32(m_header_2.partition_entry_size); std::vector partition_entries(partition_entry_size * number_of_partition_entries); - if (!m_file.Seek(Common::swap64(m_header_2.partition_entries_offset), SEEK_SET)) + if (!m_file.Seek(Common::swap64(m_header_2.partition_entries_offset), File::SeekOrigin::Begin)) return false; if (!m_file.ReadBytes(partition_entries.data(), partition_entries.size())) return false; @@ -686,7 +686,7 @@ bool WIARVZFileReader::Chunk::Read(u64 offset, u64 size, u8* out_ptr) return false; } - if (!m_file->Seek(m_offset_in_file, SEEK_SET)) + if (!m_file->Seek(m_offset_in_file, File::SeekOrigin::Begin)) return false; if (!m_file->ReadBytes(m_in.data.data() + m_in.bytes_written, bytes_to_read)) return false; @@ -1716,7 +1716,7 @@ bool WIARVZFileReader::WriteHeader(File::IOFile* file, const u8* data, size { WARN_LOG_FMT(DISCIO, "Headers did not fit in the allocated space. Writing to end of file instead"); - if (!file->Seek(0, SEEK_END)) + if (!file->Seek(0, File::SeekOrigin::End)) return false; *bytes_written = file->Tell(); } @@ -1949,7 +1949,7 @@ WIARVZFileReader::Convert(BlobReader* infile, const VolumeDisc* infile_volu return ConversionResultCode::InternalError; bytes_written = sizeof(WIAHeader1) + sizeof(WIAHeader2); - if (!outfile->Seek(sizeof(WIAHeader1) + sizeof(WIAHeader2), SEEK_SET)) + if (!outfile->Seek(sizeof(WIAHeader1) + sizeof(WIAHeader2), File::SeekOrigin::Begin)) return ConversionResultCode::WriteFailed; u64 partition_entries_offset; @@ -2018,7 +2018,7 @@ WIARVZFileReader::Convert(BlobReader* infile, const VolumeDisc* infile_volu mbedtls_sha1_ret(reinterpret_cast(&header_1), offsetof(WIAHeader1, header_1_hash), header_1.header_1_hash.data()); - if (!outfile->Seek(0, SEEK_SET)) + if (!outfile->Seek(0, File::SeekOrigin::Begin)) return ConversionResultCode::WriteFailed; if (!outfile->WriteArray(&header_1, 1)) diff --git a/Source/Core/DiscIO/WbfsBlob.cpp b/Source/Core/DiscIO/WbfsBlob.cpp index b02de124ee..74351ccb39 100644 --- a/Source/Core/DiscIO/WbfsBlob.cpp +++ b/Source/Core/DiscIO/WbfsBlob.cpp @@ -37,7 +37,7 @@ WbfsFileReader::WbfsFileReader(File::IOFile file, const std::string& path) // Grab disc info (assume slot 0, checked in ReadHeader()) m_wlba_table.resize(m_blocks_per_disc); m_files[0].file.Seek(m_hd_sector_size + WII_DISC_HEADER_SIZE /*+ i * m_disc_info_size*/, - SEEK_SET); + File::SeekOrigin::Begin); m_files[0].file.ReadBytes(m_wlba_table.data(), m_blocks_per_disc * sizeof(u16)); for (size_t i = 0; i < m_blocks_per_disc; i++) m_wlba_table[i] = Common::swap16(m_wlba_table[i]); @@ -86,7 +86,7 @@ bool WbfsFileReader::AddFileToList(File::IOFile file) bool WbfsFileReader::ReadHeader() { // Read hd size info - m_files[0].file.Seek(0, SEEK_SET); + m_files[0].file.Seek(0, File::SeekOrigin::Begin); m_files[0].file.ReadBytes(&m_header, sizeof(WbfsHeader)); if (m_header.magic != WBFS_MAGIC) return false; @@ -152,7 +152,7 @@ File::IOFile& WbfsFileReader::SeekToCluster(u64 offset, u64* available) { if (final_address < (file_entry.base_address + file_entry.size)) { - file_entry.file.Seek(final_address - file_entry.base_address, SEEK_SET); + file_entry.file.Seek(final_address - file_entry.base_address, File::SeekOrigin::Begin); if (available) { u64 till_end_of_file = file_entry.size - (final_address - file_entry.base_address); @@ -168,7 +168,7 @@ File::IOFile& WbfsFileReader::SeekToCluster(u64 offset, u64* available) ERROR_LOG_FMT(DISCIO, "Read beyond end of disc"); if (available) *available = 0; - m_files[0].file.Seek(0, SEEK_SET); + m_files[0].file.Seek(0, File::SeekOrigin::Begin); return m_files[0].file; } diff --git a/Source/Core/DiscIO/WiiSaveBanner.cpp b/Source/Core/DiscIO/WiiSaveBanner.cpp index 484bb92869..7c2bdbca5b 100644 --- a/Source/Core/DiscIO/WiiSaveBanner.cpp +++ b/Source/Core/DiscIO/WiiSaveBanner.cpp @@ -60,7 +60,7 @@ std::vector WiiSaveBanner::GetBanner(u32* width, u32* height) const *height = 0; File::IOFile file(m_path, "rb"); - if (!file.Seek(sizeof(Header), SEEK_SET)) + if (!file.Seek(sizeof(Header), File::SeekOrigin::Begin)) return std::vector(); std::vector banner_data(BANNER_WIDTH * BANNER_HEIGHT); diff --git a/Source/Core/VideoCommon/HiresTextures_DDSLoader.cpp b/Source/Core/VideoCommon/HiresTextures_DDSLoader.cpp index e5b4c0a3e9..f3b2daf5eb 100644 --- a/Source/Core/VideoCommon/HiresTextures_DDSLoader.cpp +++ b/Source/Core/VideoCommon/HiresTextures_DDSLoader.cpp @@ -447,7 +447,7 @@ bool HiresTexture::LoadDDSTexture(HiresTexture* tex, const std::string& filename // Read first mip level, as it may have a custom pitch. Level first_level; - if (!file.Seek(info.first_mip_offset, SEEK_SET) || + if (!file.Seek(info.first_mip_offset, File::SeekOrigin::Begin) || !ReadMipLevel(&first_level, file, filename, 0, info, info.width, info.height, info.first_mip_row_length, info.first_mip_size)) { diff --git a/Source/Core/VideoCommon/ShaderCache.cpp b/Source/Core/VideoCommon/ShaderCache.cpp index eada4c970b..984793d9d8 100644 --- a/Source/Core/VideoCommon/ShaderCache.cpp +++ b/Source/Core/VideoCommon/ShaderCache.cpp @@ -772,7 +772,7 @@ void ShaderCache::LoadPipelineUIDCache() // We open the file for reading and writing, so we must seek to the end before writing. if (uid_file_valid) - uid_file_valid = m_gx_pipeline_uid_cache_file.Seek(expected_size, SEEK_SET); + uid_file_valid = m_gx_pipeline_uid_cache_file.Seek(expected_size, File::SeekOrigin::Begin); } // If the file is invalid, close it. We re-open and truncate it below.