mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-12-30 21:10:58 +01:00
deba9ce256
New dolphin-tool command: "header" -b / --block_size -c / --compression -l / --compression_level Informative RVZ/WIA header2 value "compression_level" is now a s32 instead of a u32, because negative compression is a thing. Speaking of, it is now possible to use negative compression levels in dolphin-tool's convert command (not the GUI, though).
90 lines
2.2 KiB
C++
90 lines
2.2 KiB
C++
// Copyright 2008 Dolphin Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "Common/CommonTypes.h"
|
|
#include "Common/IOFile.h"
|
|
#include "DiscIO/Blob.h"
|
|
|
|
namespace DiscIO
|
|
{
|
|
static constexpr u32 WBFS_MAGIC = 0x53464257; // "WBFS" (byteswapped to little endian)
|
|
|
|
class WbfsFileReader : public BlobReader
|
|
{
|
|
public:
|
|
~WbfsFileReader();
|
|
|
|
static std::unique_ptr<WbfsFileReader> Create(File::IOFile file, const std::string& path);
|
|
|
|
BlobType GetBlobType() const override { return BlobType::WBFS; }
|
|
|
|
u64 GetRawSize() const override { return m_size; }
|
|
// The WBFS format does not save the original file size.
|
|
// This function returns a constant upper bound
|
|
// (the size of a double-layer Wii disc).
|
|
u64 GetDataSize() const override;
|
|
bool IsDataSizeAccurate() const override { return false; }
|
|
|
|
u64 GetBlockSize() const override { return m_wbfs_sector_size; }
|
|
bool HasFastRandomAccessInBlock() const override { return true; }
|
|
std::string GetCompressionMethod() const override { return {}; }
|
|
std::optional<int> GetCompressionLevel() const override { return std::nullopt; }
|
|
|
|
bool Read(u64 offset, u64 nbytes, u8* out_ptr) override;
|
|
|
|
private:
|
|
WbfsFileReader(File::IOFile file, const std::string& path);
|
|
|
|
void OpenAdditionalFiles(const std::string& path);
|
|
bool AddFileToList(File::IOFile file);
|
|
bool ReadHeader();
|
|
|
|
File::IOFile& SeekToCluster(u64 offset, u64* available);
|
|
bool IsGood() { return m_good; }
|
|
struct FileEntry
|
|
{
|
|
FileEntry(File::IOFile file_, u64 base_address_, u64 size_)
|
|
: file(std::move(file_)), base_address(base_address_), size(size_)
|
|
{
|
|
}
|
|
|
|
File::IOFile file;
|
|
u64 base_address;
|
|
u64 size;
|
|
};
|
|
|
|
std::vector<FileEntry> m_files;
|
|
|
|
u64 m_size;
|
|
|
|
u64 m_hd_sector_size;
|
|
u64 m_wbfs_sector_size;
|
|
u64 m_wbfs_sector_count;
|
|
u64 m_disc_info_size;
|
|
|
|
#pragma pack(1)
|
|
struct WbfsHeader
|
|
{
|
|
u32 magic;
|
|
u32 hd_sector_count;
|
|
u8 hd_sector_shift;
|
|
u8 wbfs_sector_shift;
|
|
u8 padding[2];
|
|
u8 disc_table[500];
|
|
} m_header;
|
|
#pragma pack()
|
|
|
|
std::vector<u16> m_wlba_table;
|
|
u64 m_blocks_per_disc;
|
|
|
|
bool m_good;
|
|
};
|
|
|
|
} // namespace DiscIO
|