2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:09:55 -06:00
|
|
|
// Refer to the license.txt file included.
|
2008-12-07 21:46:09 -07:00
|
|
|
|
2014-02-10 11:54:46 -07:00
|
|
|
#pragma once
|
2008-12-07 21:46:09 -07:00
|
|
|
|
2014-02-20 17:47:53 -07:00
|
|
|
#include <cstddef>
|
2015-08-09 05:41:41 -06:00
|
|
|
#include <map>
|
2015-08-08 11:59:33 -06:00
|
|
|
#include <memory>
|
2017-06-04 02:33:14 -06:00
|
|
|
#include <optional>
|
2014-02-20 17:47:53 -07:00
|
|
|
#include <string>
|
2008-12-07 21:46:09 -07:00
|
|
|
#include <vector>
|
|
|
|
|
2014-02-20 17:47:53 -07:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "DiscIO/Filesystem.h"
|
2008-12-07 21:46:09 -07:00
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
2017-06-06 03:49:01 -06:00
|
|
|
class Volume;
|
2015-06-13 04:51:24 -06:00
|
|
|
struct Partition;
|
2014-02-20 17:47:53 -07:00
|
|
|
|
2015-07-28 08:56:25 -06:00
|
|
|
class FileInfoGCWii : public FileInfo
|
|
|
|
{
|
|
|
|
public:
|
2015-08-08 11:59:33 -06:00
|
|
|
// None of the constructors take ownership of FST pointers
|
|
|
|
|
|
|
|
// Set everything manually
|
2015-08-02 09:39:03 -06:00
|
|
|
FileInfoGCWii(const u8* fst, u8 offset_shift, u32 index, u32 total_file_infos);
|
2015-08-08 11:59:33 -06: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 14:18:20 -06:00
|
|
|
|
2015-07-28 08:56:25 -06:00
|
|
|
~FileInfoGCWii() override;
|
|
|
|
|
2015-08-08 11:59:33 -06:00
|
|
|
std::unique_ptr<FileInfo> clone() const override;
|
|
|
|
const_iterator begin() const override;
|
|
|
|
const_iterator end() const override;
|
|
|
|
|
2015-07-30 14:18:20 -06:00
|
|
|
u64 GetOffset() const override;
|
|
|
|
u32 GetSize() const override;
|
|
|
|
bool IsDirectory() const override;
|
2015-08-08 11:59:33 -06:00
|
|
|
u32 GetTotalChildren() const override;
|
2015-07-30 14:18:20 -06:00
|
|
|
std::string GetName() const override;
|
2015-08-08 11:59:33 -06:00
|
|
|
std::string GetPath() const override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
uintptr_t GetAddress() const override;
|
|
|
|
FileInfo& operator++() override;
|
2015-07-28 08:56:25 -06:00
|
|
|
|
|
|
|
private:
|
2015-07-30 14:18:20 -06:00
|
|
|
enum class EntryProperty
|
|
|
|
{
|
2015-08-08 11:59:33 -06: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 14:18:20 -06:00
|
|
|
NAME_OFFSET = 0,
|
2015-08-08 11:59:33 -06: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 14:18:20 -06:00
|
|
|
FILE_OFFSET = 1,
|
2015-08-08 11:59:33 -06: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 14:18:20 -06:00
|
|
|
FILE_SIZE = 2
|
|
|
|
};
|
|
|
|
|
2015-08-08 11:59:33 -06: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 14:18:20 -06:00
|
|
|
u32 Get(EntryProperty entry_property) const;
|
|
|
|
|
2015-08-08 11:59:33 -06:00
|
|
|
const u8* m_fst;
|
|
|
|
u8 m_offset_shift;
|
|
|
|
u32 m_index;
|
|
|
|
u32 m_total_file_infos;
|
2015-07-28 08:56:25 -06:00
|
|
|
};
|
|
|
|
|
2017-06-06 03:49:01 -06:00
|
|
|
class FileSystemGCWii : public FileSystem
|
2008-12-07 21:46:09 -07:00
|
|
|
{
|
|
|
|
public:
|
2017-06-06 03:49:01 -06:00
|
|
|
FileSystemGCWii(const Volume* _rVolume, const Partition& partition);
|
2015-07-28 08:56:25 -06:00
|
|
|
~FileSystemGCWii() override;
|
2015-08-08 11:59:33 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
bool IsValid() const override { return m_Valid; }
|
2015-08-08 11:59:33 -06:00
|
|
|
const FileInfo& GetRoot() const override;
|
|
|
|
std::unique_ptr<FileInfo> FindFileInfo(const std::string& path) const override;
|
|
|
|
std::unique_ptr<FileInfo> FindFileInfo(u64 disc_offset) const override;
|
|
|
|
|
2015-07-30 07:06:23 -06:00
|
|
|
u64 ReadFile(const FileInfo* file_info, u8* _pBuffer, u64 _MaxBufferSize,
|
2015-07-31 05:36:28 -06:00
|
|
|
u64 _OffsetInFile) const override;
|
|
|
|
bool ExportFile(const FileInfo* file_info, const std::string& _rExportFilename) const override;
|
2016-06-24 02:43:46 -06:00
|
|
|
bool ExportApploader(const std::string& _rExportFolder) const override;
|
|
|
|
bool ExportDOL(const std::string& _rExportFolder) const override;
|
2017-06-04 02:33:14 -06:00
|
|
|
std::optional<u64> GetBootDOLOffset() const override;
|
|
|
|
std::optional<u32> GetBootDOLSize(u64 dol_offset) const override;
|
2008-12-07 21:46:09 -07:00
|
|
|
|
2009-07-02 21:26:23 -06:00
|
|
|
private:
|
2016-06-24 02:43:46 -06:00
|
|
|
bool m_Valid;
|
2015-06-13 12:50:03 -06:00
|
|
|
u32 m_offset_shift;
|
2015-07-30 14:18:20 -06:00
|
|
|
std::vector<u8> m_file_system_table;
|
2015-08-08 11:59:33 -06:00
|
|
|
FileInfoGCWii m_root;
|
2015-08-09 05:41:41 -06:00
|
|
|
// Maps the end offset of files to FST indexes
|
|
|
|
mutable std::map<u64, u32> m_offset_file_info_cache;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-08-08 11:59:33 -06:00
|
|
|
std::unique_ptr<FileInfo> FindFileInfo(const std::string& path, const FileInfo& file_info) const;
|
2008-12-07 21:46:09 -07:00
|
|
|
};
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
} // namespace
|