Fix ISO Directory extraction.

This commit is contained in:
Jordan Woyak 2014-06-29 14:22:06 -05:00
parent 91da031220
commit 3805c4967f
4 changed files with 52 additions and 71 deletions

View File

@ -192,26 +192,19 @@ size_t CARCFile::BuildFilenames(const size_t _FirstIndex, const size_t _LastInde
while (CurrentIndex < _LastIndex) while (CurrentIndex < _LastIndex)
{ {
SFileInfo& rFileInfo = m_FileInfoVector[CurrentIndex]; SFileInfo& rFileInfo = m_FileInfoVector[CurrentIndex];
int uOffset = rFileInfo.m_NameOffset & 0xFFFFFF; int const uOffset = rFileInfo.m_NameOffset & 0xFFFFFF;
rFileInfo.m_FullPath = _szDirectory + &_szNameTable[uOffset];
// check next index // check next index
if (rFileInfo.IsDirectory()) if (rFileInfo.IsDirectory())
{ {
if (_szDirectory.empty()) rFileInfo.m_FullPath += '/';
rFileInfo.m_FullPath += StringFromFormat("%s/", &_szNameTable[uOffset]); CurrentIndex = BuildFilenames(CurrentIndex + 1, (size_t)rFileInfo.m_FileSize, rFileInfo.m_FullPath, _szNameTable);
else
rFileInfo.m_FullPath += StringFromFormat("%s%s/", _szDirectory.c_str(), &_szNameTable[uOffset]);
CurrentIndex = BuildFilenames(CurrentIndex + 1, (size_t) rFileInfo.m_FileSize, rFileInfo.m_FullPath, _szNameTable);
} }
else // This is a filename else
{ {
if (_szDirectory.empty()) ++CurrentIndex;
rFileInfo.m_FullPath += StringFromFormat("%s", &_szNameTable[uOffset]);
else
rFileInfo.m_FullPath += StringFromFormat("%s%s", _szDirectory.c_str(), &_szNameTable[uOffset]);
CurrentIndex++;
} }
} }

View File

@ -307,28 +307,20 @@ size_t CFileSystemGCWii::BuildFilenames(const size_t _FirstIndex, const size_t _
while (CurrentIndex < _LastIndex) while (CurrentIndex < _LastIndex)
{ {
SFileInfo *rFileInfo = &m_FileInfoVector[CurrentIndex]; SFileInfo& rFileInfo = m_FileInfoVector[CurrentIndex];
u64 uOffset = _NameTableOffset + (rFileInfo->m_NameOffset & 0xFFFFFF); u64 const uOffset = _NameTableOffset + (rFileInfo.m_NameOffset & 0xFFFFFF);
std::string filename = GetStringFromOffset(uOffset);
rFileInfo.m_FullPath = _szDirectory + GetStringFromOffset(uOffset);
// check next index // check next index
if (rFileInfo->IsDirectory()) if (rFileInfo.IsDirectory())
{ {
if (_szDirectory.empty()) rFileInfo.m_FullPath += '/';
rFileInfo->m_FullPath += StringFromFormat("%s/", filename.c_str()); CurrentIndex = BuildFilenames(CurrentIndex + 1, (size_t) rFileInfo.m_FileSize, rFileInfo.m_FullPath, _NameTableOffset);
else
rFileInfo->m_FullPath += StringFromFormat("%s%s/", _szDirectory.c_str(), filename.c_str());
CurrentIndex = BuildFilenames(CurrentIndex + 1, (size_t) rFileInfo->m_FileSize, rFileInfo->m_FullPath, _NameTableOffset);
} }
else // This is a filename else
{ {
if (_szDirectory.empty()) ++CurrentIndex;
rFileInfo->m_FullPath += filename;
else
rFileInfo->m_FullPath += StringFromFormat("%s%s", _szDirectory.c_str(), filename.c_str());
CurrentIndex++;
} }
} }

View File

@ -762,53 +762,47 @@ void CISOProperties::OnExtractFile(wxCommandEvent& WXUNUSED (event))
} }
} }
void CISOProperties::ExportDir(const char* _rFullPath, const char* _rExportFolder, const int partitionNum) void CISOProperties::ExportDir(const std::string& _rFullPath, const std::string& _rExportFolder, const int partitionNum)
{ {
std::string exportName; DiscIO::IFileSystem* const fs = DiscIO::IsVolumeWiiDisc(OpenISO) ? WiiDisc[partitionNum].FileSystem : pFileSystem;
u32 index[2] = {0, 0};
std::vector<const DiscIO::SFileInfo *> fst;
DiscIO::IFileSystem *FS = nullptr;
if (DiscIO::IsVolumeWiiDisc(OpenISO)) std::vector<const DiscIO::SFileInfo*> fst;
fs->GetFileList(fst);
u32 index = 0;
u32 size = 0;
// Extract all
if (_rFullPath.empty())
{ {
FS = WiiDisc.at(partitionNum).FileSystem; index = 0;
size = (u32)fst.size();
fs->ExportApploader(_rExportFolder);
if (!DiscIO::IsVolumeWiiDisc(OpenISO))
fs->ExportDOL(_rExportFolder);
} }
else else
{ {
FS = pFileSystem; // Look for the dir we are going to extract
} for (index = 0; index != fst.size(); ++index)
FS->GetFileList(fst);
if (!_rFullPath) // Extract all
{
index[0] = 0;
index[1] = (u32)fst.size();
FS->ExportApploader(_rExportFolder);
if (!DiscIO::IsVolumeWiiDisc(OpenISO))
FS->ExportDOL(_rExportFolder);
}
else // Look for the dir we are going to extract
{
for (index[0] = 0; index[0] < fst.size(); index[0]++)
{ {
if (fst.at(index[0])->m_FullPath == _rFullPath) if (fst[index]->m_FullPath == _rFullPath)
{ {
DEBUG_LOG(DISCIO, "Found the directory at %u", index[0]); DEBUG_LOG(DISCIO, "Found the directory at %u", index);
index[1] = (u32)fst.at(index[0])->m_FileSize; size = (u32)fst[index]->m_FileSize;
break; break;
} }
} }
DEBUG_LOG(DISCIO,"Directory found from %u to %u\nextracting to:\n%s",index[0],index[1],_rExportFolder); DEBUG_LOG(DISCIO,"Directory found from %u to %u\nextracting to:\n%s", index , size, _rExportFolder.c_str());
} }
wxString dialogTitle = index[0] ? _("Extracting Directory") : _("Extracting All Files"); wxString dialogTitle = (index != 0) ? _("Extracting Directory") : _("Extracting All Files");
wxProgressDialog dialog( wxProgressDialog dialog(
dialogTitle, dialogTitle,
_("Extracting..."), _("Extracting..."),
index[1] - 1, size - 1,
this, this,
wxPD_APP_MODAL | wxPD_AUTO_HIDE | wxPD_CAN_ABORT | wxPD_APP_MODAL | wxPD_AUTO_HIDE | wxPD_CAN_ABORT |
wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME | wxPD_REMAINING_TIME | wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME | wxPD_REMAINING_TIME |
@ -816,10 +810,10 @@ void CISOProperties::ExportDir(const char* _rFullPath, const char* _rExportFolde
); );
// Extraction // Extraction
for (u32 i = index[0]; i < index[1]; i++) for (u32 i = index; i < size; i++)
{ {
dialog.SetTitle(wxString::Format("%s : %d%%", dialogTitle.c_str(), dialog.SetTitle(wxString::Format("%s : %d%%", dialogTitle.c_str(),
(u32)(((float)(i - index[0]) / (float)(index[1] - index[0])) * 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)));
@ -828,7 +822,7 @@ void CISOProperties::ExportDir(const char* _rFullPath, const char* _rExportFolde
if (fst[i]->IsDirectory()) if (fst[i]->IsDirectory())
{ {
exportName = StringFromFormat("%s/%s/", _rExportFolder, 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))
@ -845,10 +839,10 @@ void CISOProperties::ExportDir(const char* _rFullPath, const char* _rExportFolde
} }
else else
{ {
exportName = StringFromFormat("%s/%s", _rExportFolder, 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());
} }
@ -872,9 +866,9 @@ void CISOProperties::OnExtractDir(wxCommandEvent& event)
{ {
if (DiscIO::IsVolumeWiiDisc(OpenISO)) if (DiscIO::IsVolumeWiiDisc(OpenISO))
for (u32 i = 0; i < WiiDisc.size(); i++) for (u32 i = 0; i < WiiDisc.size(); i++)
ExportDir(nullptr, WxStrToStr(Path).c_str(), i); ExportDir("", WxStrToStr(Path).c_str(), i);
else else
ExportDir(nullptr, WxStrToStr(Path).c_str()); ExportDir("", WxStrToStr(Path).c_str());
return; return;
} }
@ -887,15 +881,17 @@ void CISOProperties::OnExtractDir(wxCommandEvent& event)
m_Treectrl->SelectItem(m_Treectrl->GetItemParent(m_Treectrl->GetSelection())); m_Treectrl->SelectItem(m_Treectrl->GetItemParent(m_Treectrl->GetSelection()));
} }
Directory += DIR_SEP_CHR;
if (DiscIO::IsVolumeWiiDisc(OpenISO)) if (DiscIO::IsVolumeWiiDisc(OpenISO))
{ {
int partitionNum = wxAtoi(Directory.Mid(Directory.find_first_of("/") - 1, 1)); int partitionNum = wxAtoi(Directory.Mid(Directory.find_first_of("/") - 1, 1));
Directory.Remove(0, Directory.find_first_of("/") + 1); // Remove "Partition x/" Directory.Remove(0, Directory.find_first_of("/") + 1); // Remove "Partition x/"
ExportDir(WxStrToStr(Directory).c_str(), WxStrToStr(Path).c_str(), partitionNum); ExportDir(WxStrToStr(Directory), WxStrToStr(Path), partitionNum);
} }
else else
{ {
ExportDir(WxStrToStr(Directory).c_str(), WxStrToStr(Path).c_str()); ExportDir(WxStrToStr(Directory), WxStrToStr(Path));
} }
} }

View File

@ -205,7 +205,7 @@ private:
std::vector<const DiscIO::SFileInfo*> fileInfos, std::vector<const DiscIO::SFileInfo*> fileInfos,
const size_t _FirstIndex, const size_t _FirstIndex,
const size_t _LastIndex); const size_t _LastIndex);
void ExportDir(const char* _rFullPath, const char* _rExportFilename, void ExportDir(const std::string& _rFullPath, const std::string& _rExportFilename,
const int partitionNum = 0); const int partitionNum = 0);
IniFile GameIniDefault; IniFile GameIniDefault;