mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-09 23:59:27 +01:00
Merge pull request #2338 from JosJuice/getfilelist-return
Filesystem: Return file list reference instead of modifying argument
This commit is contained in:
commit
2ae6fb9240
@ -274,9 +274,6 @@ bool ParsePartitionData(SPartition& _rPartition)
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<const SFileInfo *> Files;
|
||||
size_t numFiles = filesystem->GetFileList(Files);
|
||||
|
||||
// Mark things as used which are not in the filesystem
|
||||
// Header, Header Information, Apploader
|
||||
ReadFromVolume(0x2440 + 0x14, 4, _rPartition.Header.ApploaderSize, true);
|
||||
@ -305,18 +302,14 @@ bool ParsePartitionData(SPartition& _rPartition)
|
||||
, _rPartition.Header.FSTSize);
|
||||
|
||||
// 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
|
||||
if ((*Files.at(currentFile)).m_NameOffset & 0x1000000)
|
||||
MarkAsUsedE(_rPartition.Offset
|
||||
+ _rPartition.Header.DataOffset
|
||||
, (*Files.at(currentFile)).m_Offset, 1);
|
||||
if (file.m_NameOffset & 0x1000000)
|
||||
MarkAsUsedE(_rPartition.Offset + _rPartition.Header.DataOffset, file.m_Offset, 1);
|
||||
else
|
||||
MarkAsUsedE(_rPartition.Offset
|
||||
+ _rPartition.Header.DataOffset
|
||||
, (*Files.at(currentFile)).m_Offset, (*Files.at(currentFile)).m_FileSize);
|
||||
MarkAsUsedE(_rPartition.Offset + _rPartition.Header.DataOffset, file.m_Offset, file.m_FileSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,6 @@ namespace FileMon
|
||||
|
||||
static DiscIO::IVolume *OpenISO = nullptr;
|
||||
static DiscIO::IFileSystem *pFileSystem = nullptr;
|
||||
static std::vector<const DiscIO::SFileInfo *> DiscFiles;
|
||||
static std::string ISOFile = "", CurrentFile = "";
|
||||
static bool FileAccess = true;
|
||||
|
||||
@ -73,8 +72,6 @@ void ReadFileSystem(const std::string& filename)
|
||||
pFileSystem = nullptr;
|
||||
}
|
||||
|
||||
// DiscFiles' pointers are no longer valid after pFileSystem is cleared
|
||||
DiscFiles.clear();
|
||||
OpenISO = DiscIO::CreateVolumeFromFilename(filename);
|
||||
if (!OpenISO)
|
||||
return;
|
||||
@ -85,8 +82,6 @@ void ReadFileSystem(const std::string& filename)
|
||||
|
||||
if (!pFileSystem)
|
||||
return;
|
||||
|
||||
pFileSystem->GetFileList(DiscFiles);
|
||||
}
|
||||
|
||||
FileAccess = true;
|
||||
@ -166,9 +161,6 @@ void Close()
|
||||
pFileSystem = nullptr;
|
||||
}
|
||||
|
||||
// DiscFiles' pointers are no longer valid after pFileSystem is cleared
|
||||
DiscFiles.clear();
|
||||
|
||||
ISOFile = "";
|
||||
CurrentFile = "";
|
||||
FileAccess = true;
|
||||
|
@ -210,18 +210,12 @@ std::string CFileSystemGCWii::GetStringFromOffset(u64 _Offset) const
|
||||
return SHIFTJISToUTF8(data);
|
||||
}
|
||||
|
||||
size_t CFileSystemGCWii::GetFileList(std::vector<const SFileInfo *> &_rFilenames)
|
||||
const std::vector<SFileInfo>& CFileSystemGCWii::GetFileList()
|
||||
{
|
||||
if (!m_Initialized)
|
||||
InitFileSystem();
|
||||
|
||||
if (_rFilenames.size())
|
||||
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();
|
||||
return m_FileInfoVector;
|
||||
}
|
||||
|
||||
const SFileInfo* CFileSystemGCWii::FindFileInfo(const std::string& _rFullPath)
|
||||
|
@ -23,7 +23,7 @@ public:
|
||||
virtual ~CFileSystemGCWii();
|
||||
virtual bool IsValid() const override { return m_Valid; }
|
||||
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 u64 ReadFile(const std::string& _rFullPath, u8* _pBuffer, u64 _MaxBufferSize, u64 _OffsetInFile) override;
|
||||
virtual bool ExportFile(const std::string& _rFullPath, const std::string&_rExportFilename) override;
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
|
||||
virtual ~IFileSystem();
|
||||
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 ReadFile(const std::string& _rFullPath, u8* _pBuffer, u64 _MaxBufferSize, u64 _OffsetInFile = 0) = 0;
|
||||
virtual bool ExportFile(const std::string& _rFullPath, const std::string& _rExportFilename) = 0;
|
||||
|
@ -210,11 +210,10 @@ CISOProperties::CISOProperties(const std::string fileName, wxWindow* parent, wxW
|
||||
{
|
||||
if ((partition.FileSystem = DiscIO::CreateFileSystem(partition.Partition)) != nullptr)
|
||||
{
|
||||
partition.FileSystem->GetFileList(partition.Files);
|
||||
wxTreeItemId PartitionRoot =
|
||||
m_Treectrl->AppendItem(RootId, wxString::Format(_("Partition %i"), partition_count), 0, 0);
|
||||
m_Treectrl->SetItemData(PartitionRoot, new WiiPartition(partition));
|
||||
CreateDirectoryTree(PartitionRoot, partition.Files);
|
||||
CreateDirectoryTree(PartitionRoot, partition.FileSystem->GetFileList());
|
||||
if (partition_count == 1)
|
||||
m_Treectrl->Expand(PartitionRoot);
|
||||
partition_count++;
|
||||
@ -229,12 +228,9 @@ CISOProperties::CISOProperties(const std::string fileName, wxWindow* parent, wxW
|
||||
}
|
||||
else
|
||||
{
|
||||
GCFiles.clear();
|
||||
pFileSystem = DiscIO::CreateFileSystem(OpenISO);
|
||||
if (pFileSystem)
|
||||
pFileSystem->GetFileList(GCFiles);
|
||||
if (!GCFiles.empty())
|
||||
CreateDirectoryTree(RootId, GCFiles);
|
||||
CreateDirectoryTree(RootId, pFileSystem->GetFileList());
|
||||
}
|
||||
|
||||
m_Treectrl->Expand(RootId);
|
||||
@ -245,22 +241,20 @@ CISOProperties::~CISOProperties()
|
||||
{
|
||||
if (!OpenISO->IsWiiDisc() && !OpenISO->IsWadFile() && pFileSystem)
|
||||
delete pFileSystem;
|
||||
// vector's items are no longer valid after deleting filesystem
|
||||
GCFiles.clear();
|
||||
delete OpenGameListItem;
|
||||
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())
|
||||
return 0;
|
||||
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,
|
||||
std::vector<const DiscIO::SFileInfo*> fileInfos,
|
||||
const std::vector<DiscIO::SFileInfo>& fileInfos,
|
||||
const size_t _FirstIndex,
|
||||
const size_t _LastIndex)
|
||||
{
|
||||
@ -268,8 +262,8 @@ size_t CISOProperties::CreateDirectoryTree(wxTreeItemId& parent,
|
||||
|
||||
while (CurrentIndex < _LastIndex)
|
||||
{
|
||||
const DiscIO::SFileInfo* rFileInfo = fileInfos[CurrentIndex];
|
||||
std::string filePath = rFileInfo->m_FullPath;
|
||||
const DiscIO::SFileInfo rFileInfo = fileInfos[CurrentIndex];
|
||||
std::string filePath = rFileInfo.m_FullPath;
|
||||
|
||||
// Trim the trailing '/' if it exists.
|
||||
if (filePath[filePath.length() - 1] == DIR_SEP_CHR)
|
||||
@ -286,10 +280,10 @@ size_t CISOProperties::CreateDirectoryTree(wxTreeItemId& parent,
|
||||
}
|
||||
|
||||
// check next index
|
||||
if (rFileInfo->IsDirectory())
|
||||
if (rFileInfo.IsDirectory())
|
||||
{
|
||||
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
|
||||
{
|
||||
@ -772,8 +766,7 @@ void CISOProperties::ExportDir(const std::string& _rFullPath, const std::string&
|
||||
{
|
||||
DiscIO::IFileSystem* const fs = OpenISO->IsWiiDisc() ? partition->FileSystem : pFileSystem;
|
||||
|
||||
std::vector<const DiscIO::SFileInfo*> fst;
|
||||
fs->GetFileList(fst);
|
||||
const std::vector<DiscIO::SFileInfo>& fst = fs->GetFileList();
|
||||
|
||||
u32 index = 0;
|
||||
u32 size = 0;
|
||||
@ -793,10 +786,10 @@ void CISOProperties::ExportDir(const std::string& _rFullPath, const std::string&
|
||||
// Look for the dir we are going to extract
|
||||
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);
|
||||
size = (u32)fst[index]->m_FileSize;
|
||||
size = (u32)fst[index].m_FileSize;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -821,14 +814,14 @@ void CISOProperties::ExportDir(const std::string& _rFullPath, const std::string&
|
||||
dialog.SetTitle(wxString::Format("%s : %d%%", dialogTitle.c_str(),
|
||||
(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())
|
||||
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());
|
||||
|
||||
if (!File::Exists(exportName) && !File::CreateFullPath(exportName))
|
||||
@ -845,10 +838,10 @@ void CISOProperties::ExportDir(const std::string& _rFullPath, const std::string&
|
||||
}
|
||||
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());
|
||||
|
||||
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());
|
||||
}
|
||||
|
@ -38,7 +38,6 @@ class WiiPartition final : public wxTreeItemData
|
||||
public:
|
||||
DiscIO::IVolume *Partition;
|
||||
DiscIO::IFileSystem *FileSystem;
|
||||
std::vector<const DiscIO::SFileInfo *> Files;
|
||||
};
|
||||
|
||||
struct PHackData
|
||||
@ -211,13 +210,12 @@ private:
|
||||
|
||||
GameListItem* OpenGameListItem;
|
||||
|
||||
std::vector<const DiscIO::SFileInfo*> GCFiles;
|
||||
typedef std::vector<const DiscIO::SFileInfo*>::iterator fileIter;
|
||||
|
||||
size_t CreateDirectoryTree(wxTreeItemId& parent,
|
||||
std::vector<const DiscIO::SFileInfo*> fileInfos);
|
||||
const std::vector<DiscIO::SFileInfo>& fileInfos);
|
||||
size_t CreateDirectoryTree(wxTreeItemId& parent,
|
||||
std::vector<const DiscIO::SFileInfo*> fileInfos,
|
||||
const std::vector<DiscIO::SFileInfo>& fileInfos,
|
||||
const size_t _FirstIndex,
|
||||
const size_t _LastIndex);
|
||||
void ExportDir(const std::string& _rFullPath, const std::string& _rExportFilename,
|
||||
|
Loading…
x
Reference in New Issue
Block a user