Skip to content

Commit

Permalink
Various fixes for ISOProperties's filesystem viewer, bugfix for empty…
Browse files Browse the repository at this point in the history
… folders not being empty thanks to j4ck.fr0st (issue 702), also added icons and fixed dumping all files from a wii game.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4266 8ced0084-cf51-0410-be5f-012b33b47a6e
  • Loading branch information
sl1nk3 committed Sep 13, 2009
1 parent c743140 commit e76d2a1
Show file tree
Hide file tree
Showing 8 changed files with 604 additions and 158 deletions.
131 changes: 61 additions & 70 deletions Source/Core/DiscIO/Src/FileSystemGCWii.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ u64 CFileSystemGCWii::GetFileSize(const char* _rFullPath) const

const SFileInfo* pFileInfo = FindFileInfo(_rFullPath);

if (pFileInfo != NULL)
if (pFileInfo != NULL && !pFileInfo->IsDirectory())
return pFileInfo->m_FileSize;

return 0;
Expand All @@ -68,7 +68,7 @@ const char* CFileSystemGCWii::GetFileName(u64 _Address) const
}
}

return NULL;
return 0;
}

u64 CFileSystemGCWii::ReadFile(const char* _rFullPath, u8* _pBuffer, size_t _MaxBufferSize) const
Expand Down Expand Up @@ -115,82 +115,73 @@ bool CFileSystemGCWii::ExportFile(const char* _rFullPath, const char* _rExportFi
delete[] buffer;
return false;
}
bool CFileSystemGCWii::ExportDir(const char* _rFullPath, const char* _rExportFolder) const

void CFileSystemGCWii::ExportApploader(const char* _rExportFolder) const
{
std::vector<const SFileInfo *> fst;
GetFileList(fst);
char exportName[512];
//look for the dir we are going to extract
u32 index[2];
if (!_rFullPath)

// Extract Apploader
// ------------------
// Apploader code size
u32 AppSize = Read32(0x2440 + 0x14) << m_OffsetShift;
AppSize += Read32(0x2440 + 0x18) << m_OffsetShift; // + apptrailer size
AppSize += 0x20; // + the header = Apploader size! :')
DEBUG_LOG(DISCIO,"AppSize -> %x",AppSize);

char* buffer = new char[AppSize];
m_rVolume->Read(0x2440, AppSize, (u8*)buffer);
sprintf(exportName, "%s/apploader.ldr", _rExportFolder);
FILE* AppFile = fopen(exportName,"w");
if (!AppFile)
{
//extract all
index[0] = 0;
index[1] = fst.size();
PanicAlert("Failed to create %s! canceling further extraction",exportName);
return;
}
else
fwrite(buffer, 1, AppSize, AppFile);
fclose(AppFile);
//delete[] buffer; buffer = 0;

/* TODO : This part crashes with Wii games :/
// Extract dol(bootfile)
// ---------------------
u32 DolOffset = Read32(0x420) << m_OffsetShift;
u32 DolSize = 0, offset = 0, size = 0, max = 0;
// note DacoTaco : thank you shuffle and discscrubber :P . find it kinda of pointless to include
// the discscrubber just for the GetDolSize function so its copy pasta time ...
// TODO: fix boot.dol size. or gc-tool is again silly with size or we are wrong (more likely :/)
// Iterate through the 7 code segments
for (u8 i = 0; i < 7; i++)
{
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);
m_rVolume->Read(DolOffset + 0x00 + i * 4, 4, (u8*)&offset);
m_rVolume->Read(DolOffset + 0x90 + i * 4, 4, (u8*)&size);
if (offset + size > DolSize)
DolSize = offset + size;
}
//extraction
for (int i = index[0]; i < index[1];i++)
// Iterate through the 11 data segments
for (u8 i = 0; i < 11; i++)
{
if (fst[i]->IsDirectory())
{
sprintf(exportName, "%s/%s/", _rExportFolder, fst[i]->m_FullPath);
DEBUG_LOG(DISCIO, "%s", exportName);

if (!File::Exists(exportName))
{

if (!File::CreateFullPath(exportName))
{
ERROR_LOG(DISCIO, "Could not create the path %s", exportName);
return false;
}
}
else
{
if (!File::IsDirectory(exportName))
{
ERROR_LOG(DISCIO, "%s already exists and is not a directory", exportName);
return false;
}
DEBUG_LOG(DISCIO, "folder %s already exists", exportName);

}
}
else
{
sprintf(exportName, "%s/%s", _rExportFolder, fst[i]->m_FullPath);
DEBUG_LOG(DISCIO, "%s", exportName);
if (!File::Exists(exportName))
{
if (!ExportFile(fst[i]->m_FullPath, exportName))
ERROR_LOG(DISCIO, "Could not export %s", exportName);
}
else
{
DEBUG_LOG(DISCIO, "%s already exists", exportName);
}
}
m_rVolume->Read(DolOffset + 0x1c + i * 4, 4, (u8*)&offset);
m_rVolume->Read(DolOffset + 0xac + i * 4, 4, (u8*)&size);
if (offset + size > DolSize)
DolSize = offset + size;
}
return false;
// Add header to size
DolSize += 0x40;
buffer = new char[DolSize];
m_rVolume->Read(DolOffset, DolSize, (u8*)&buffer);
sprintf(exportName, "%s/boot.dol", _rExportFolder);
FILE* DolFile = fopen(exportName, "w");
if (!DolFile)
{
PanicAlert("Failed to create %s! canceling further extraction",exportName);
return;
}
fwrite(buffer, 1, DolSize, DolFile);
fclose(DolFile);
delete[] buffer;
*/
}

u32 CFileSystemGCWii::Read32(u64 _Offset) const
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DiscIO/Src/FileSystemGCWii.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ class CFileSystemGCWii : public IFileSystem
virtual ~CFileSystemGCWii();
virtual bool IsInitialized() const;
virtual u64 GetFileSize(const char* _rFullPath) const;
virtual size_t GetFileList(std::vector<const SFileInfo *> &_rFilenames) const;
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 ExportDir(const char* _rFullPath, const char* _rExportFilename) const;
virtual void ExportApploader(const char* _rExportFolder) const;

private:

bool m_Initialized;
u32 m_OffsetShift; // WII offsets are all shifted
std::vector <SFileInfo> m_FileInfoVector;
u32 Read32(u64 _Offset) const;
virtual size_t GetFileList(std::vector<const SFileInfo *> &_rFilenames) const;
void GetStringFromOffset(u64 _Offset, char* Filename) const;
const SFileInfo* FindFileInfo(const char* _rFullPath) const;
bool InitFileSystem();
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DiscIO/Src/Filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class IFileSystem
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 ExportDir(const char* _rFullPath, const char* _rExportFilename) const = 0;
virtual void ExportApploader(const char* _rExportFolder) const = 0;
virtual const char* GetFileName(u64 _Address) const = 0;

virtual const IVolume *GetVolume() const { return m_rVolume; }
Expand Down
Loading

0 comments on commit e76d2a1

Please sign in to comment.