FileSystem: Fixed SOME memory leaks, cleaned up code and fixed empty entry bug.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@596 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
XTra.KrazzY 2008-09-21 14:51:40 +00:00
parent de577e521f
commit 60a4630324
4 changed files with 49 additions and 33 deletions

View File

@ -35,7 +35,13 @@ CFileSystemGCWii::CFileSystemGCWii(const IVolume& _rVolume)
CFileSystemGCWii::~CFileSystemGCWii()
{}
{
while(m_FileInfoVector.size() > 0) {
SFileInfo *sfi = m_FileInfoVector.back();
m_FileInfoVector.pop_back();
delete sfi;
}
}
bool
@ -69,10 +75,10 @@ CFileSystemGCWii::GetFileName(u64 _Address)
{
for (size_t i = 0; i < m_FileInfoVector.size(); i++)
{
if ((m_FileInfoVector[i].m_Offset <= _Address) &&
((m_FileInfoVector[i].m_Offset + m_FileInfoVector[i].m_FileSize) > _Address))
if ((m_FileInfoVector[i]->m_Offset <= _Address) &&
((m_FileInfoVector[i]->m_Offset + m_FileInfoVector[i]->m_FileSize) > _Address))
{
return(m_FileInfoVector[i].m_FullPath);
return(m_FileInfoVector[i]->m_FullPath);
}
}
@ -159,15 +165,12 @@ void CFileSystemGCWii::GetStringFromOffset(u64 _Offset, char* Filename) const
m_rVolume.Read(_Offset, 255, (u8*)Filename);
}
size_t CFileSystemGCWii::GetFileList(std::vector<SFileInfo> *_rFilenames)
{
if(_rFilenames == NULL)
return m_FileInfoVector.size();
(*_rFilenames).resize(m_FileInfoVector.size());
size_t CFileSystemGCWii::GetFileList(std::vector<SFileInfo *> &_rFilenames)
{
_rFilenames.clear();
for (size_t i = 0; i < m_FileInfoVector.size(); i++)
{
(*_rFilenames)[i] = m_FileInfoVector[i];
_rFilenames.push_back(new SFileInfo(*m_FileInfoVector[i]));
}
return m_FileInfoVector.size();
}
@ -177,9 +180,9 @@ CFileSystemGCWii::FindFileInfo(const char* _rFullPath) const
{
for (size_t i = 0; i < m_FileInfoVector.size(); i++)
{
if (!strcasecmp(m_FileInfoVector[i].m_FullPath, _rFullPath))
if (!strcasecmp(m_FileInfoVector[i]->m_FullPath, _rFullPath))
{
return(&m_FileInfoVector[i]);
return(m_FileInfoVector[i]);
}
}
@ -217,15 +220,19 @@ CFileSystemGCWii::InitFileSystem()
if (Root.IsDirectory())
{
m_FileInfoVector.resize(Root.m_FileSize);
m_FileInfoVector.clear();
u64 NameTableOffset = FSTOffset;
for (size_t i = 0; i < m_FileInfoVector.size(); i++)
for (u32 i = 0; i < Root.m_FileSize; i++)
{
SFileInfo *sfi = new SFileInfo();
u64 Offset = FSTOffset + (i * 0xC);
m_FileInfoVector[i].m_NameOffset = Read32(Offset + 0x0);
m_FileInfoVector[i].m_Offset = (u64)Read32(Offset + 0x4) << m_OffsetShift;
m_FileInfoVector[i].m_FileSize = Read32(Offset + 0x8);
sfi->m_NameOffset = Read32(Offset + 0x0);
sfi->m_Offset = (u64)Read32(Offset + 0x4) << m_OffsetShift;
sfi->m_FileSize = Read32(Offset + 0x8);
m_FileInfoVector.push_back(sfi);
NameTableOffset += 0xC;
}
@ -247,36 +254,36 @@ CFileSystemGCWii::BuildFilenames(const size_t _FirstIndex, const size_t _LastInd
while (CurrentIndex < _LastIndex)
{
SFileInfo& rFileInfo = m_FileInfoVector[CurrentIndex];
u64 uOffset = _NameTableOffset + (rFileInfo.m_NameOffset & 0xFFFFFF);
SFileInfo *rFileInfo = m_FileInfoVector[CurrentIndex];
u64 uOffset = _NameTableOffset + (rFileInfo->m_NameOffset & 0xFFFFFF);
char filename[512];
GetStringFromOffset(uOffset, filename);
// check next index
if (rFileInfo.IsDirectory())
if (rFileInfo->IsDirectory())
{
// this is a directory, build up the new szDirectory
if (_szDirectory != NULL)
{
CharArrayFromFormat(rFileInfo.m_FullPath, "%s%s\\", _szDirectory, filename);
CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s\\", _szDirectory, filename);
}
else
{
CharArrayFromFormat(rFileInfo.m_FullPath, "%s\\", filename);
CharArrayFromFormat(rFileInfo->m_FullPath, "%s\\", filename);
}
CurrentIndex = BuildFilenames(CurrentIndex + 1, rFileInfo.m_FileSize, rFileInfo.m_FullPath, _NameTableOffset);
CurrentIndex = BuildFilenames(CurrentIndex + 1, rFileInfo->m_FileSize, rFileInfo->m_FullPath, _NameTableOffset);
}
else
{
// this is a filename
if (_szDirectory != NULL)
{
CharArrayFromFormat(rFileInfo.m_FullPath, "%s%s", _szDirectory, filename);
CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s", _szDirectory, filename);
}
else
{
CharArrayFromFormat(rFileInfo.m_FullPath, "%s", filename);
CharArrayFromFormat(rFileInfo->m_FullPath, "%s", filename);
}
CurrentIndex++;

View File

@ -48,8 +48,7 @@ class CFileSystemGCWii
private:
typedef std::vector<SFileInfo>CFileInfoVector;
CFileInfoVector m_FileInfoVector;
std::vector<SFileInfo *> m_FileInfoVector;
bool m_Initialized;
@ -57,7 +56,7 @@ class CFileSystemGCWii
u32 Read32(u64 _Offset) const;
virtual size_t GetFileList(std::vector<SFileInfo> *_rFilenames);
virtual size_t GetFileList(std::vector<SFileInfo *> &_rFilenames);
void GetStringFromOffset(u64 _Offset, char* Filename) const;

View File

@ -32,6 +32,15 @@ struct SFileInfo
char m_FullPath[512];
bool IsDirectory() {return((m_NameOffset& 0xFF000000) != 0 ? true : false);}
SFileInfo() : m_NameOffset(0), m_Offset(0), m_FileSize(0) {
memset(m_FullPath, 0, 512);
}
SFileInfo(const SFileInfo &rhs) : m_NameOffset(rhs.m_NameOffset),
m_Offset(rhs.m_Offset), m_FileSize(rhs.m_FileSize) {
strcpy(m_FullPath, rhs.m_FullPath);
}
};
class IFileSystem
{
@ -44,7 +53,7 @@ class IFileSystem
virtual bool IsInitialized() = 0;
virtual size_t GetFileList(std::vector<SFileInfo> *_rFilenames) = 0;
virtual size_t GetFileList(std::vector<SFileInfo *> &_rFilenames) = 0;
virtual size_t GetFileSize(const char* _rFullPath) = 0;

View File

@ -39,14 +39,15 @@ DiscIO::IFileSystem* pFileSystem = NULL;
CFilesystemViewer::CFilesystemViewer(const std::string fileName, wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& position, const wxSize& size, long style)
: wxDialog(parent, id, title, position, size, style)
{
std::vector<DiscIO::SFileInfo *> Our_Files;
OpenIso = DiscIO::CreateVolumeFromFilename(fileName);
pFileSystem = DiscIO::CreateFileSystem(*OpenIso);
std::vector<DiscIO::SFileInfo> *Our_Files = new std::vector<DiscIO::SFileInfo>[pFileSystem->GetFileList(NULL)];
pFileSystem->GetFileList(Our_Files);
CreateGUIControls();
for(u32 a = 0;a < Our_Files->size();++a)
m_Treectrl->AppendItem(RootId, wxString::FromAscii((*Our_Files)[a].m_FullPath));//printf("%d dir? %s '%s'\n", a, Our_Files[a].IsDirectory() ? "True" : "False", Our_Files[a].m_FullPath);
for(u32 a = 1; a < Our_Files.size(); ++a)
m_Treectrl->AppendItem(RootId, wxString::FromAscii(Our_Files[a]->m_FullPath));//printf("%d dir? %s '%s'\n", a, Our_Files[a].IsDirectory() ? "True" : "False", Our_Files[a].m_FullPath);
}
CFilesystemViewer::~CFilesystemViewer()