mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-10 14:39:01 +01:00
Filesystem: Return file list reference instead of modifying argument
This commit is contained in:
parent
79dff19aa0
commit
d43a920924
@ -274,9 +274,6 @@ bool ParsePartitionData(SPartition& _rPartition)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::vector<const SFileInfo *> Files;
|
|
||||||
size_t numFiles = filesystem->GetFileList(Files);
|
|
||||||
|
|
||||||
// Mark things as used which are not in the filesystem
|
// Mark things as used which are not in the filesystem
|
||||||
// Header, Header Information, Apploader
|
// Header, Header Information, Apploader
|
||||||
ReadFromVolume(0x2440 + 0x14, 4, _rPartition.Header.ApploaderSize, true);
|
ReadFromVolume(0x2440 + 0x14, 4, _rPartition.Header.ApploaderSize, true);
|
||||||
@ -305,18 +302,14 @@ bool ParsePartitionData(SPartition& _rPartition)
|
|||||||
, _rPartition.Header.FSTSize);
|
, _rPartition.Header.FSTSize);
|
||||||
|
|
||||||
// Go through the filesystem and mark entries as used
|
// Go through the filesystem and mark entries as used
|
||||||
for (size_t currentFile = 0; currentFile < numFiles; currentFile++)
|
for (SFileInfo file : filesystem->GetFileList())
|
||||||
{
|
{
|
||||||
DEBUG_LOG(DISCIO, "%s", currentFile ? (*Files.at(currentFile)).m_FullPath.c_str() : "/");
|
DEBUG_LOG(DISCIO, file.m_FullPath.empty() ? "/" : file.m_FullPath.c_str());
|
||||||
// Just 1byte for directory? - it will end up reserving a cluster this way
|
// Just 1byte for directory? - it will end up reserving a cluster this way
|
||||||
if ((*Files.at(currentFile)).m_NameOffset & 0x1000000)
|
if (file.m_NameOffset & 0x1000000)
|
||||||
MarkAsUsedE(_rPartition.Offset
|
MarkAsUsedE(_rPartition.Offset + _rPartition.Header.DataOffset, file.m_Offset, 1);
|
||||||
+ _rPartition.Header.DataOffset
|
|
||||||
, (*Files.at(currentFile)).m_Offset, 1);
|
|
||||||
else
|
else
|
||||||
MarkAsUsedE(_rPartition.Offset
|
MarkAsUsedE(_rPartition.Offset + _rPartition.Header.DataOffset, file.m_Offset, file.m_FileSize);
|
||||||
+ _rPartition.Header.DataOffset
|
|
||||||
, (*Files.at(currentFile)).m_Offset, (*Files.at(currentFile)).m_FileSize);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ namespace FileMon
|
|||||||
|
|
||||||
static DiscIO::IVolume *OpenISO = nullptr;
|
static DiscIO::IVolume *OpenISO = nullptr;
|
||||||
static DiscIO::IFileSystem *pFileSystem = nullptr;
|
static DiscIO::IFileSystem *pFileSystem = nullptr;
|
||||||
static std::vector<const DiscIO::SFileInfo *> DiscFiles;
|
|
||||||
static std::string ISOFile = "", CurrentFile = "";
|
static std::string ISOFile = "", CurrentFile = "";
|
||||||
static bool FileAccess = true;
|
static bool FileAccess = true;
|
||||||
|
|
||||||
@ -73,8 +72,6 @@ void ReadFileSystem(const std::string& filename)
|
|||||||
pFileSystem = nullptr;
|
pFileSystem = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DiscFiles' pointers are no longer valid after pFileSystem is cleared
|
|
||||||
DiscFiles.clear();
|
|
||||||
OpenISO = DiscIO::CreateVolumeFromFilename(filename);
|
OpenISO = DiscIO::CreateVolumeFromFilename(filename);
|
||||||
if (!OpenISO)
|
if (!OpenISO)
|
||||||
return;
|
return;
|
||||||
@ -85,8 +82,6 @@ void ReadFileSystem(const std::string& filename)
|
|||||||
|
|
||||||
if (!pFileSystem)
|
if (!pFileSystem)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pFileSystem->GetFileList(DiscFiles);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FileAccess = true;
|
FileAccess = true;
|
||||||
@ -166,9 +161,6 @@ void Close()
|
|||||||
pFileSystem = nullptr;
|
pFileSystem = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DiscFiles' pointers are no longer valid after pFileSystem is cleared
|
|
||||||
DiscFiles.clear();
|
|
||||||
|
|
||||||
ISOFile = "";
|
ISOFile = "";
|
||||||
CurrentFile = "";
|
CurrentFile = "";
|
||||||
FileAccess = true;
|
FileAccess = true;
|
||||||
|
@ -215,18 +215,12 @@ std::string CFileSystemGCWii::GetStringFromOffset(u64 _Offset) const
|
|||||||
return SHIFTJISToUTF8(data);
|
return SHIFTJISToUTF8(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t CFileSystemGCWii::GetFileList(std::vector<const SFileInfo *> &_rFilenames)
|
const std::vector<SFileInfo>& CFileSystemGCWii::GetFileList()
|
||||||
{
|
{
|
||||||
if (!m_Initialized)
|
if (!m_Initialized)
|
||||||
InitFileSystem();
|
InitFileSystem();
|
||||||
|
|
||||||
if (_rFilenames.size())
|
return m_FileInfoVector;
|
||||||
PanicAlert("GetFileList : input list has contents?");
|
|
||||||
_rFilenames.clear();
|
|
||||||
_rFilenames.reserve(m_FileInfoVector.size());
|
|
||||||
for (auto& fileInfo : m_FileInfoVector)
|
|
||||||
_rFilenames.push_back(&fileInfo);
|
|
||||||
return m_FileInfoVector.size();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const SFileInfo* CFileSystemGCWii::FindFileInfo(const std::string& _rFullPath)
|
const SFileInfo* CFileSystemGCWii::FindFileInfo(const std::string& _rFullPath)
|
||||||
|
@ -23,7 +23,7 @@ public:
|
|||||||
virtual ~CFileSystemGCWii();
|
virtual ~CFileSystemGCWii();
|
||||||
virtual bool IsValid() const override { return m_Valid; }
|
virtual bool IsValid() const override { return m_Valid; }
|
||||||
virtual u64 GetFileSize(const std::string& _rFullPath) override;
|
virtual u64 GetFileSize(const std::string& _rFullPath) override;
|
||||||
virtual size_t GetFileList(std::vector<const SFileInfo *> &_rFilenames) override;
|
virtual const std::vector<SFileInfo>& GetFileList() override;
|
||||||
virtual const std::string GetFileName(u64 _Address) override;
|
virtual const std::string GetFileName(u64 _Address) override;
|
||||||
virtual u64 ReadFile(const std::string& _rFullPath, u8* _pBuffer, size_t _MaxBufferSize) override;
|
virtual u64 ReadFile(const std::string& _rFullPath, u8* _pBuffer, size_t _MaxBufferSize) override;
|
||||||
virtual bool ExportFile(const std::string& _rFullPath, const std::string&_rExportFilename) override;
|
virtual bool ExportFile(const std::string& _rFullPath, const std::string&_rExportFilename) override;
|
||||||
|
@ -43,7 +43,7 @@ public:
|
|||||||
|
|
||||||
virtual ~IFileSystem();
|
virtual ~IFileSystem();
|
||||||
virtual bool IsValid() const = 0;
|
virtual bool IsValid() const = 0;
|
||||||
virtual size_t GetFileList(std::vector<const SFileInfo *> &_rFilenames) = 0;
|
virtual const std::vector<SFileInfo>& GetFileList() = 0;
|
||||||
virtual u64 GetFileSize(const std::string& _rFullPath) = 0;
|
virtual u64 GetFileSize(const std::string& _rFullPath) = 0;
|
||||||
virtual u64 ReadFile(const std::string& _rFullPath, u8* _pBuffer, size_t _MaxBufferSize) = 0;
|
virtual u64 ReadFile(const std::string& _rFullPath, u8* _pBuffer, size_t _MaxBufferSize) = 0;
|
||||||
virtual bool ExportFile(const std::string& _rFullPath, const std::string& _rExportFilename) = 0;
|
virtual bool ExportFile(const std::string& _rFullPath, const std::string& _rExportFilename) = 0;
|
||||||
|
@ -251,11 +251,10 @@ CISOProperties::CISOProperties(const std::string fileName, wxWindow* parent, wxW
|
|||||||
{
|
{
|
||||||
if ((partition.FileSystem = DiscIO::CreateFileSystem(partition.Partition)) != nullptr)
|
if ((partition.FileSystem = DiscIO::CreateFileSystem(partition.Partition)) != nullptr)
|
||||||
{
|
{
|
||||||
partition.FileSystem->GetFileList(partition.Files);
|
|
||||||
wxTreeItemId PartitionRoot =
|
wxTreeItemId PartitionRoot =
|
||||||
m_Treectrl->AppendItem(RootId, wxString::Format(_("Partition %i"), partition_count), 0, 0);
|
m_Treectrl->AppendItem(RootId, wxString::Format(_("Partition %i"), partition_count), 0, 0);
|
||||||
m_Treectrl->SetItemData(PartitionRoot, new WiiPartition(partition));
|
m_Treectrl->SetItemData(PartitionRoot, new WiiPartition(partition));
|
||||||
CreateDirectoryTree(PartitionRoot, partition.Files);
|
CreateDirectoryTree(PartitionRoot, partition.FileSystem->GetFileList());
|
||||||
if (partition_count == 1)
|
if (partition_count == 1)
|
||||||
m_Treectrl->Expand(PartitionRoot);
|
m_Treectrl->Expand(PartitionRoot);
|
||||||
partition_count++;
|
partition_count++;
|
||||||
@ -270,12 +269,9 @@ CISOProperties::CISOProperties(const std::string fileName, wxWindow* parent, wxW
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GCFiles.clear();
|
|
||||||
pFileSystem = DiscIO::CreateFileSystem(OpenISO);
|
pFileSystem = DiscIO::CreateFileSystem(OpenISO);
|
||||||
if (pFileSystem)
|
if (pFileSystem)
|
||||||
pFileSystem->GetFileList(GCFiles);
|
CreateDirectoryTree(RootId, pFileSystem->GetFileList());
|
||||||
if (!GCFiles.empty())
|
|
||||||
CreateDirectoryTree(RootId, GCFiles);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Treectrl->Expand(RootId);
|
m_Treectrl->Expand(RootId);
|
||||||
@ -286,22 +282,20 @@ CISOProperties::~CISOProperties()
|
|||||||
{
|
{
|
||||||
if (!OpenISO->IsWiiDisc() && !OpenISO->IsWadFile() && pFileSystem)
|
if (!OpenISO->IsWiiDisc() && !OpenISO->IsWadFile() && pFileSystem)
|
||||||
delete pFileSystem;
|
delete pFileSystem;
|
||||||
// vector's items are no longer valid after deleting filesystem
|
|
||||||
GCFiles.clear();
|
|
||||||
delete OpenGameListItem;
|
delete OpenGameListItem;
|
||||||
delete OpenISO;
|
delete OpenISO;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t CISOProperties::CreateDirectoryTree(wxTreeItemId& parent, std::vector<const DiscIO::SFileInfo*> fileInfos)
|
size_t CISOProperties::CreateDirectoryTree(wxTreeItemId& parent, const std::vector<DiscIO::SFileInfo>& fileInfos)
|
||||||
{
|
{
|
||||||
if (fileInfos.empty())
|
if (fileInfos.empty())
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
return CreateDirectoryTree(parent, fileInfos, 1, fileInfos.at(0)->m_FileSize);
|
return CreateDirectoryTree(parent, fileInfos, 1, fileInfos.at(0).m_FileSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t CISOProperties::CreateDirectoryTree(wxTreeItemId& parent,
|
size_t CISOProperties::CreateDirectoryTree(wxTreeItemId& parent,
|
||||||
std::vector<const DiscIO::SFileInfo*> fileInfos,
|
const std::vector<DiscIO::SFileInfo>& fileInfos,
|
||||||
const size_t _FirstIndex,
|
const size_t _FirstIndex,
|
||||||
const size_t _LastIndex)
|
const size_t _LastIndex)
|
||||||
{
|
{
|
||||||
@ -309,8 +303,8 @@ size_t CISOProperties::CreateDirectoryTree(wxTreeItemId& parent,
|
|||||||
|
|
||||||
while (CurrentIndex < _LastIndex)
|
while (CurrentIndex < _LastIndex)
|
||||||
{
|
{
|
||||||
const DiscIO::SFileInfo* rFileInfo = fileInfos[CurrentIndex];
|
const DiscIO::SFileInfo rFileInfo = fileInfos[CurrentIndex];
|
||||||
std::string filePath = rFileInfo->m_FullPath;
|
std::string filePath = rFileInfo.m_FullPath;
|
||||||
|
|
||||||
// Trim the trailing '/' if it exists.
|
// Trim the trailing '/' if it exists.
|
||||||
if (filePath[filePath.length() - 1] == DIR_SEP_CHR)
|
if (filePath[filePath.length() - 1] == DIR_SEP_CHR)
|
||||||
@ -327,10 +321,10 @@ size_t CISOProperties::CreateDirectoryTree(wxTreeItemId& parent,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check next index
|
// check next index
|
||||||
if (rFileInfo->IsDirectory())
|
if (rFileInfo.IsDirectory())
|
||||||
{
|
{
|
||||||
wxTreeItemId item = m_Treectrl->AppendItem(parent, StrToWxStr(filePath), 1, 1);
|
wxTreeItemId item = m_Treectrl->AppendItem(parent, StrToWxStr(filePath), 1, 1);
|
||||||
CurrentIndex = CreateDirectoryTree(item, fileInfos, CurrentIndex + 1, (size_t)rFileInfo->m_FileSize);
|
CurrentIndex = CreateDirectoryTree(item, fileInfos, CurrentIndex + 1, (size_t)rFileInfo.m_FileSize);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -779,8 +773,7 @@ void CISOProperties::ExportDir(const std::string& _rFullPath, const std::string&
|
|||||||
{
|
{
|
||||||
DiscIO::IFileSystem* const fs = OpenISO->IsWiiDisc() ? partition->FileSystem : pFileSystem;
|
DiscIO::IFileSystem* const fs = OpenISO->IsWiiDisc() ? partition->FileSystem : pFileSystem;
|
||||||
|
|
||||||
std::vector<const DiscIO::SFileInfo*> fst;
|
const std::vector<DiscIO::SFileInfo>& fst = fs->GetFileList();
|
||||||
fs->GetFileList(fst);
|
|
||||||
|
|
||||||
u32 index = 0;
|
u32 index = 0;
|
||||||
u32 size = 0;
|
u32 size = 0;
|
||||||
@ -800,10 +793,10 @@ void CISOProperties::ExportDir(const std::string& _rFullPath, const std::string&
|
|||||||
// Look for the dir we are going to extract
|
// Look for the dir we are going to extract
|
||||||
for (index = 0; index != fst.size(); ++index)
|
for (index = 0; index != fst.size(); ++index)
|
||||||
{
|
{
|
||||||
if (fst[index]->m_FullPath == _rFullPath)
|
if (fst[index].m_FullPath == _rFullPath)
|
||||||
{
|
{
|
||||||
DEBUG_LOG(DISCIO, "Found the directory at %u", index);
|
DEBUG_LOG(DISCIO, "Found the directory at %u", index);
|
||||||
size = (u32)fst[index]->m_FileSize;
|
size = (u32)fst[index].m_FileSize;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -828,14 +821,14 @@ void CISOProperties::ExportDir(const std::string& _rFullPath, const std::string&
|
|||||||
dialog.SetTitle(wxString::Format("%s : %d%%", dialogTitle.c_str(),
|
dialog.SetTitle(wxString::Format("%s : %d%%", dialogTitle.c_str(),
|
||||||
(u32)(((float)(i - index) / (float)(size - index)) * 100)));
|
(u32)(((float)(i - index) / (float)(size - index)) * 100)));
|
||||||
|
|
||||||
dialog.Update(i, wxString::Format(_("Extracting %s"), StrToWxStr(fst[i]->m_FullPath)));
|
dialog.Update(i, wxString::Format(_("Extracting %s"), StrToWxStr(fst[i].m_FullPath)));
|
||||||
|
|
||||||
if (dialog.WasCancelled())
|
if (dialog.WasCancelled())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (fst[i]->IsDirectory())
|
if (fst[i].IsDirectory())
|
||||||
{
|
{
|
||||||
const std::string exportName = StringFromFormat("%s/%s/", _rExportFolder.c_str(), fst[i]->m_FullPath.c_str());
|
const std::string exportName = StringFromFormat("%s/%s/", _rExportFolder.c_str(), fst[i].m_FullPath.c_str());
|
||||||
DEBUG_LOG(DISCIO, "%s", exportName.c_str());
|
DEBUG_LOG(DISCIO, "%s", exportName.c_str());
|
||||||
|
|
||||||
if (!File::Exists(exportName) && !File::CreateFullPath(exportName))
|
if (!File::Exists(exportName) && !File::CreateFullPath(exportName))
|
||||||
@ -852,10 +845,10 @@ void CISOProperties::ExportDir(const std::string& _rFullPath, const std::string&
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const std::string exportName = StringFromFormat("%s/%s", _rExportFolder.c_str(), fst[i]->m_FullPath.c_str());
|
const std::string exportName = StringFromFormat("%s/%s", _rExportFolder.c_str(), fst[i].m_FullPath.c_str());
|
||||||
DEBUG_LOG(DISCIO, "%s", exportName.c_str());
|
DEBUG_LOG(DISCIO, "%s", exportName.c_str());
|
||||||
|
|
||||||
if (!File::Exists(exportName) && !fs->ExportFile(fst[i]->m_FullPath, exportName))
|
if (!File::Exists(exportName) && !fs->ExportFile(fst[i].m_FullPath, exportName))
|
||||||
{
|
{
|
||||||
ERROR_LOG(DISCIO, "Could not export %s", exportName.c_str());
|
ERROR_LOG(DISCIO, "Could not export %s", exportName.c_str());
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,6 @@ class WiiPartition final : public wxTreeItemData
|
|||||||
public:
|
public:
|
||||||
DiscIO::IVolume *Partition;
|
DiscIO::IVolume *Partition;
|
||||||
DiscIO::IFileSystem *FileSystem;
|
DiscIO::IFileSystem *FileSystem;
|
||||||
std::vector<const DiscIO::SFileInfo *> Files;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PHackData
|
struct PHackData
|
||||||
@ -218,13 +217,12 @@ private:
|
|||||||
|
|
||||||
GameListItem* OpenGameListItem;
|
GameListItem* OpenGameListItem;
|
||||||
|
|
||||||
std::vector<const DiscIO::SFileInfo*> GCFiles;
|
|
||||||
typedef std::vector<const DiscIO::SFileInfo*>::iterator fileIter;
|
typedef std::vector<const DiscIO::SFileInfo*>::iterator fileIter;
|
||||||
|
|
||||||
size_t CreateDirectoryTree(wxTreeItemId& parent,
|
size_t CreateDirectoryTree(wxTreeItemId& parent,
|
||||||
std::vector<const DiscIO::SFileInfo*> fileInfos);
|
const std::vector<DiscIO::SFileInfo>& fileInfos);
|
||||||
size_t CreateDirectoryTree(wxTreeItemId& parent,
|
size_t CreateDirectoryTree(wxTreeItemId& parent,
|
||||||
std::vector<const DiscIO::SFileInfo*> fileInfos,
|
const std::vector<DiscIO::SFileInfo>& fileInfos,
|
||||||
const size_t _FirstIndex,
|
const size_t _FirstIndex,
|
||||||
const size_t _LastIndex);
|
const size_t _LastIndex);
|
||||||
void ExportDir(const std::string& _rFullPath, const std::string& _rExportFilename,
|
void ExportDir(const std::string& _rFullPath, const std::string& _rExportFilename,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user