dolphin/Source/Core/DiscIO/FileSystemGCWii.h
JosJuice d6ee7ec32c Filesystem: Read the entire FST in one go
Instead of using lots of small scattered reads to read the FST,
only one big read is used, which is more efficient.

This also means that the FST only allocates memory once and stores all
strings close to each other - good for the CPU cache. The file info
objects use pointers to this FST memory of containing data themselves.
Keeping around the big m_FileInfoVector containing objects with only
pointers is a bit unnecessary, but that will be fixed soon.
2017-06-13 22:43:41 +02:00

79 lines
2.2 KiB
C++

// Copyright 2008 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <cstddef>
#include <optional>
#include <string>
#include <vector>
#include "Common/CommonTypes.h"
#include "DiscIO/Filesystem.h"
namespace DiscIO
{
class Volume;
struct Partition;
class FileInfoGCWii : public FileInfo
{
public:
// Does not take ownership of pointers
FileInfoGCWii(u8 offset_shift, const u8* fst_entry, const u8* name_table_start);
~FileInfoGCWii() override;
u64 GetOffset() const override;
u32 GetSize() const override;
bool IsDirectory() const override;
std::string GetName() const override;
private:
enum class EntryProperty
{
NAME_OFFSET = 0,
FILE_OFFSET = 1,
FILE_SIZE = 2
};
u32 Get(EntryProperty entry_property) const;
const u8 m_offset_shift;
const u8* const m_fst_entry;
const u8* const m_name_table_start;
};
class FileSystemGCWii : public FileSystem
{
public:
FileSystemGCWii(const Volume* _rVolume, const Partition& partition);
~FileSystemGCWii() override;
bool IsValid() const override { return m_Valid; }
const std::vector<FileInfoGCWii>& GetFileList() override;
const FileInfo* FindFileInfo(const std::string& path) override;
const FileInfo* FindFileInfo(u64 disc_offset) override;
std::string GetPath(u64 _Address) override;
std::string GetPathFromFSTOffset(size_t file_info_offset) override;
u64 ReadFile(const FileInfo* file_info, u8* _pBuffer, u64 _MaxBufferSize,
u64 _OffsetInFile) override;
bool ExportFile(const FileInfo* file_info, const std::string& _rExportFilename) override;
bool ExportApploader(const std::string& _rExportFolder) const override;
bool ExportDOL(const std::string& _rExportFolder) const override;
std::optional<u64> GetBootDOLOffset() const override;
std::optional<u32> GetBootDOLSize(u64 dol_offset) const override;
private:
bool m_Initialized;
bool m_Valid;
u32 m_offset_shift;
std::vector<FileInfoGCWii> m_FileInfoVector;
std::vector<u8> m_file_system_table;
const FileInfo* FindFileInfo(const std::string& path, size_t search_start_offset) const;
bool DetectFileSystem();
void InitFileSystem();
};
} // namespace