Files
dolphin/Source/Core/DiscIO/FileSystemGCWii.h
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

109 lines
3.3 KiB
C++
Raw Normal View History

// Copyright 2008 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2008-12-08 04:46:09 +00:00
#pragma once
2008-12-08 04:46:09 +00:00
#include <cstddef>
#include <map>
2015-08-08 19:59:33 +02:00
#include <memory>
#include <optional>
#include <string>
#include <string_view>
2008-07-12 17:40:22 +00:00
#include <vector>
2008-12-08 04:46:09 +00:00
#include "Common/CommonTypes.h"
2014-02-17 05:18:15 -05:00
#include "DiscIO/Filesystem.h"
2008-12-08 04:46:09 +00:00
2008-07-12 17:40:22 +00:00
namespace DiscIO
{
class VolumeDisc;
struct Partition;
class FileInfoGCWii : public FileInfo
{
public:
2015-08-08 19:59:33 +02:00
// None of the constructors take ownership of FST pointers
// Set everything manually
FileInfoGCWii(const u8* fst, u8 offset_shift, u32 index, u32 total_file_infos);
2015-08-08 19:59:33 +02:00
// For the root object only
FileInfoGCWii(const u8* fst, u8 offset_shift);
// Copy another object
FileInfoGCWii(const FileInfoGCWii& file_info) = default;
// Copy data that is common to the whole file system
FileInfoGCWii(const FileInfoGCWii& file_info, u32 index);
2015-07-30 22:18:20 +02:00
~FileInfoGCWii() override;
2015-08-08 19:59:33 +02:00
std::unique_ptr<FileInfo> clone() const override;
const_iterator begin() const override;
const_iterator end() const override;
2015-07-30 22:18:20 +02:00
u64 GetOffset() const override;
u32 GetSize() const override;
2020-12-03 20:59:45 +01:00
bool IsRoot() const override;
2015-07-30 22:18:20 +02:00
bool IsDirectory() const override;
2015-08-08 19:59:33 +02:00
u32 GetTotalChildren() const override;
2015-07-30 22:18:20 +02:00
std::string GetName() const override;
bool NameCaseInsensitiveEquals(std::string_view other) const override;
2015-08-08 19:59:33 +02:00
std::string GetPath() const override;
bool IsValid(u64 fst_size, const FileInfoGCWii& parent_directory) const;
2015-08-08 19:59:33 +02:00
protected:
uintptr_t GetAddress() const override;
FileInfo& operator++() override;
private:
2015-07-30 22:18:20 +02:00
enum class EntryProperty
{
2015-08-08 19:59:33 +02:00
// NAME_OFFSET's lower 3 bytes are the name's offset within the name table.
// NAME_OFFSET's upper 1 byte is 1 for directories and 0 for files.
2015-07-30 22:18:20 +02:00
NAME_OFFSET = 0,
2015-08-08 19:59:33 +02:00
// For files, FILE_OFFSET is the file offset in the partition,
// and for directories, it's the FST index of the parent directory.
// The root directory has its parent directory index set to 0.
2015-07-30 22:18:20 +02:00
FILE_OFFSET = 1,
2015-08-08 19:59:33 +02:00
// For files, FILE_SIZE is the file size, and for directories,
// it's the FST index of the next entry that isn't in the directory.
2015-07-30 22:18:20 +02:00
FILE_SIZE = 2
};
2015-08-08 19:59:33 +02:00
// For files, returns the index of the next item. For directories,
// returns the index of the next item that isn't inside it.
u32 GetNextIndex() const;
// Returns one of the three properties of this FST entry.
// Read the comments in EntryProperty for details.
2015-07-30 22:18:20 +02:00
u32 Get(EntryProperty entry_property) const;
// Returns the name offset, excluding the directory identification byte
u64 GetNameOffset() const;
2015-07-30 22:18:20 +02:00
2015-08-08 19:59:33 +02:00
const u8* m_fst;
u8 m_offset_shift;
u32 m_index;
u32 m_total_file_infos;
};
class FileSystemGCWii : public FileSystem
2008-07-12 17:40:22 +00:00
{
public:
FileSystemGCWii(const VolumeDisc* volume, const Partition& partition);
~FileSystemGCWii() override;
2015-08-08 19:59:33 +02:00
2015-08-09 20:53:38 +02:00
bool IsValid() const override { return m_valid; }
2015-08-08 19:59:33 +02:00
const FileInfo& GetRoot() const override;
std::unique_ptr<FileInfo> FindFileInfo(std::string_view path) const override;
2015-08-08 19:59:33 +02:00
std::unique_ptr<FileInfo> FindFileInfo(u64 disc_offset) const override;
2009-07-03 03:26:23 +00:00
private:
2015-08-09 20:53:38 +02:00
bool m_valid;
2015-07-30 22:18:20 +02:00
std::vector<u8> m_file_system_table;
2015-08-08 19:59:33 +02:00
FileInfoGCWii m_root;
// Maps the end offset of files to FST indexes
mutable std::map<u64, u32> m_offset_file_info_cache;
std::unique_ptr<FileInfo> FindFileInfo(std::string_view path, const FileInfo& file_info) const;
2008-07-12 17:40:22 +00:00
};
2008-12-08 04:46:09 +00:00
2019-05-05 23:48:12 +00:00
} // namespace DiscIO