From be702ce75064577c744524902c6c6db1ba7a67b2 Mon Sep 17 00:00:00 2001 From: LPFaint99 Date: Sun, 13 Sep 2009 09:03:38 +0000 Subject: [PATCH] patch by Daco for extracting directory contents from a gcm (which also allows dumping an entire partion other than 0 from a wii disc) plus a small fix for File::GetSize log git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4258 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/FileUtil.cpp | 2 +- Source/Core/DiscIO/Src/FileSystemGCWii.cpp | 40 +++++++++++++++++---- Source/Core/DiscIO/Src/FileSystemGCWii.h | 2 +- Source/Core/DiscIO/Src/Filesystem.h | 2 +- Source/Core/DolphinWX/Src/ISOProperties.cpp | 32 +++++++++++++++-- 5 files changed, 66 insertions(+), 12 deletions(-) diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index 99c74c26ad..41d68200a5 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -332,7 +332,7 @@ u64 GetSize(const char *filename) // on windows it's actually _stat64 defined in commonFuncs struct stat64 buf; if (stat64(filename, &buf) == 0) { - DEBUG_LOG(COMMON, "GetSize: %s: %d", filename, buf.st_size); + DEBUG_LOG(COMMON, "GetSize: %s: %ld", filename, buf.st_size); return buf.st_size; } diff --git a/Source/Core/DiscIO/Src/FileSystemGCWii.cpp b/Source/Core/DiscIO/Src/FileSystemGCWii.cpp index 83f65a25c9..04885c6904 100644 --- a/Source/Core/DiscIO/Src/FileSystemGCWii.cpp +++ b/Source/Core/DiscIO/Src/FileSystemGCWii.cpp @@ -115,18 +115,44 @@ bool CFileSystemGCWii::ExportFile(const char* _rFullPath, const char* _rExportFi delete[] buffer; return false; } - -bool CFileSystemGCWii::ExportAllFiles(const char* _rFullPath) const +bool CFileSystemGCWii::ExportDir(const char* _rFullPath, const char* _rExportFolder) const { std::vector fst; - char exportName[512]; GetFileList(fst); - - for (u64 i = 1; i < fst.size(); i++) + char exportName[512]; + //look for the dir we are going to extract + u32 index[2]; + if (!_rFullPath) + { + //extract all + index[0] = 0; + index[1] = fst.size(); + } + else + { + for(index[0] = 0; index[0] < fst.size();index[0]++) + { + // Note By DacoTaco : i wonder why it doesn't work with just the _rFullPath + if (fst.at(index[0])->m_FullPath == FindFileInfo(_rFullPath)->m_FullPath ) + { + DEBUG_LOG(DISCIO,"Found the Dir at %u",index[0]); + break; + } + } + //now to get the index of last file + index[1] = index[0]; + while(index[1] < fst.at(index[0])->m_FileSize) + { + index[1]++; + } + DEBUG_LOG(DISCIO,"Dir found from %u to %u\nextracting to:\n%s",index[0],index[1],_rExportFolder); + } + //extraction + for (int i = index[0]; i < index[1];i++) { if (fst[i]->IsDirectory()) { - sprintf(exportName, "%s/%s/", _rFullPath, fst[i]->m_FullPath); + sprintf(exportName, "%s/%s/", _rExportFolder, fst[i]->m_FullPath); DEBUG_LOG(DISCIO, "%s", exportName); if (!File::Exists(exportName)) @@ -151,7 +177,7 @@ bool CFileSystemGCWii::ExportAllFiles(const char* _rFullPath) const } else { - sprintf(exportName, "%s/%s", _rFullPath, fst[i]->m_FullPath); + sprintf(exportName, "%s/%s", _rExportFolder, fst[i]->m_FullPath); DEBUG_LOG(DISCIO, "%s", exportName); if (!File::Exists(exportName)) { diff --git a/Source/Core/DiscIO/Src/FileSystemGCWii.h b/Source/Core/DiscIO/Src/FileSystemGCWii.h index 479e1f8fee..5c08f52855 100644 --- a/Source/Core/DiscIO/Src/FileSystemGCWii.h +++ b/Source/Core/DiscIO/Src/FileSystemGCWii.h @@ -35,7 +35,7 @@ public: virtual const char* GetFileName(u64 _Address) const; virtual u64 ReadFile(const char* _rFullPath, u8* _pBuffer, size_t _MaxBufferSize) const; virtual bool ExportFile(const char* _rFullPath, const char* _rExportFilename) const; - virtual bool ExportAllFiles(const char* _rFullPath) const; + virtual bool ExportDir(const char* _rFullPath, const char* _rExportFilename) const; private: diff --git a/Source/Core/DiscIO/Src/Filesystem.h b/Source/Core/DiscIO/Src/Filesystem.h index 86e2fb0f3d..3c1e68063f 100644 --- a/Source/Core/DiscIO/Src/Filesystem.h +++ b/Source/Core/DiscIO/Src/Filesystem.h @@ -54,7 +54,7 @@ public: virtual u64 GetFileSize(const char* _rFullPath) const = 0; virtual u64 ReadFile(const char* _rFullPath, u8* _pBuffer, size_t _MaxBufferSize) const = 0; virtual bool ExportFile(const char* _rFullPath, const char* _rExportFilename) const = 0; - virtual bool ExportAllFiles(const char* _rFullPath) const = 0; + virtual bool ExportDir(const char* _rFullPath, const char* _rExportFilename) const = 0; virtual const char* GetFileName(u64 _Address) const = 0; virtual const IVolume *GetVolume() const { return m_rVolume; } diff --git a/Source/Core/DolphinWX/Src/ISOProperties.cpp b/Source/Core/DolphinWX/Src/ISOProperties.cpp index c74e9f14c7..dc1daacea0 100644 --- a/Source/Core/DolphinWX/Src/ISOProperties.cpp +++ b/Source/Core/DolphinWX/Src/ISOProperties.cpp @@ -563,7 +563,7 @@ void CISOProperties::OnRightClickOnTree(wxTreeEvent& event) wxMenu popupMenu; if (m_Treectrl->ItemHasChildren(m_Treectrl->GetSelection())) - ;//popupMenu.Append(IDM_EXTRACTDIR, _("Extract Directory...")); + popupMenu.Append(IDM_EXTRACTDIR, _("Extract Directory...!experimental!")); else popupMenu.Append(IDM_EXTRACTFILE, _("Extract File...")); @@ -617,6 +617,34 @@ void CISOProperties::OnExtractFile(wxCommandEvent& WXUNUSED (event)) void CISOProperties::OnExtractDir(wxCommandEvent& WXUNUSED (event)) { + if(!AskYesNo("%s", "Warning! this process does not yet have a progress bar.\nDolphin might appear unresponsive(depends on how big the folder is) until the extraction is complete\nContinue?")) + return; + wxString Path; + wxString Directory; + + Directory = m_Treectrl->GetItemText(m_Treectrl->GetSelection()); + Path = wxDirSelector(wxT("Choose the folder where to extract to")); + + if (!Path || !Directory) + return; + + while (m_Treectrl->GetItemParent(m_Treectrl->GetSelection()) != m_Treectrl->GetRootItem()) + { + wxString temp; + temp = m_Treectrl->GetItemText(m_Treectrl->GetItemParent(m_Treectrl->GetSelection())); + Directory = temp + wxT(DIR_SEP_CHR) + Directory; + + m_Treectrl->SelectItem(m_Treectrl->GetItemParent(m_Treectrl->GetSelection())); + } + + if (DiscIO::IsVolumeWiiDisc(OpenISO)) + { + int partitionNum = wxAtoi(Directory.SubString(10, 11)); + Directory.Remove(0, 12); // Remove "Partition x/" + WiiDisc.at(partitionNum).FileSystem->ExportDir(Directory.mb_str(), Path.mb_str()); + } + else + pFileSystem->ExportDir(Directory.mb_str(), Path.mb_str()); } void CISOProperties::OnExtractAll(wxCommandEvent& WXUNUSED (event)) @@ -631,7 +659,7 @@ void CISOProperties::OnExtractAll(wxCommandEvent& WXUNUSED (event)) if (dialog.ShowModal() == wxID_OK) { std::string sPath(dialog.GetPath().mb_str()); - pFileSystem->ExportAllFiles(sPath.c_str()); + pFileSystem->ExportDir(NULL,sPath.c_str()); } }