From f325fc9634350f63faa7b04893805ada8d3f8816 Mon Sep 17 00:00:00 2001
From: Lioncash <mathew1800@gmail.com>
Date: Fri, 14 Mar 2014 21:27:28 -0400
Subject: [PATCH 1/2] Clean up FileHandlerARC.cpp/.h

- Removed parentheses from the returns.
- Put the function declaration headers back on a single line.
- Make FindFileInfo's parameter a const string reference.
---
 Source/Core/DiscIO/FileHandlerARC.cpp | 54 ++++++++++++---------------
 Source/Core/DiscIO/FileHandlerARC.h   |  2 +-
 2 files changed, 24 insertions(+), 32 deletions(-)

diff --git a/Source/Core/DiscIO/FileHandlerARC.cpp b/Source/Core/DiscIO/FileHandlerARC.cpp
index ee24158053..960ecaf07d 100644
--- a/Source/Core/DiscIO/FileHandlerARC.cpp
+++ b/Source/Core/DiscIO/FileHandlerARC.cpp
@@ -69,70 +69,66 @@ CARCFile::~CARCFile()
 }
 
 
-bool
-CARCFile::IsInitialized()
+bool CARCFile::IsInitialized()
 {
-	return(m_Initialized);
+	return m_Initialized;
 }
 
 
-size_t
-CARCFile::GetFileSize(const std::string& _rFullPath)
+size_t CARCFile::GetFileSize(const std::string& _rFullPath)
 {
 	if (!m_Initialized)
 	{
-		return(0);
+		return 0;
 	}
 
 	const SFileInfo* pFileInfo = FindFileInfo(_rFullPath);
 
 	if (pFileInfo != nullptr)
 	{
-		return((size_t) pFileInfo->m_FileSize);
+		return (size_t) pFileInfo->m_FileSize;
 	}
 
-	return(0);
+	return 0;
 }
 
 
-size_t
-CARCFile::ReadFile(const std::string& _rFullPath, u8* _pBuffer, size_t _MaxBufferSize)
+size_t CARCFile::ReadFile(const std::string& _rFullPath, u8* _pBuffer, size_t _MaxBufferSize)
 {
 	if (!m_Initialized)
 	{
-		return(0);
+		return 0;
 	}
 
 	const SFileInfo* pFileInfo = FindFileInfo(_rFullPath);
 
 	if (pFileInfo == nullptr)
 	{
-		return(0);
+		return 0;
 	}
 
 	if (pFileInfo->m_FileSize > _MaxBufferSize)
 	{
-		return(0);
+		return 0;
 	}
 
 	memcpy(_pBuffer, &m_pBuffer[pFileInfo->m_Offset], (size_t)pFileInfo->m_FileSize);
-	return((size_t) pFileInfo->m_FileSize);
+	return (size_t) pFileInfo->m_FileSize;
 }
 
 
-bool
-CARCFile::ExportFile(const std::string& _rFullPath, const std::string& _rExportFilename)
+bool CARCFile::ExportFile(const std::string& _rFullPath, const std::string& _rExportFilename)
 {
 	if (!m_Initialized)
 	{
-		return(false);
+		return false;
 	}
 
 	const SFileInfo* pFileInfo = FindFileInfo(_rFullPath);
 
 	if (pFileInfo == nullptr)
 	{
-		return(false);
+		return false;
 	}
 
 	File::IOFile pFile(_rExportFilename, "wb");
@@ -141,15 +137,13 @@ CARCFile::ExportFile(const std::string& _rFullPath, const std::string& _rExportF
 }
 
 
-bool
-CARCFile::ExportAllFiles(const std::string& _rFullPath)
+bool CARCFile::ExportAllFiles(const std::string& _rFullPath)
 {
-	return(false);
+	return false;
 }
 
 
-bool
-CARCFile::ParseBuffer()
+bool CARCFile::ParseBuffer()
 {
 	// check ID
 	u32 ID = Common::swap32(*(u32*)(m_pBuffer));
@@ -186,12 +180,11 @@ CARCFile::ParseBuffer()
 		BuildFilenames(1, m_FileInfoVector.size(), nullptr, szNameTable);
 	}
 
-	return(true);
+	return true;
 }
 
 
-size_t
-CARCFile::BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const char* _szDirectory, const char* _szNameTable)
+size_t CARCFile::BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const char* _szDirectory, const char* _szNameTable)
 {
 	size_t CurrentIndex = _FirstIndex;
 
@@ -231,21 +224,20 @@ CARCFile::BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, cons
 		}
 	}
 
-	return(CurrentIndex);
+	return CurrentIndex;
 }
 
 
-const SFileInfo*
-CARCFile::FindFileInfo(std::string _rFullPath) const
+const SFileInfo* CARCFile::FindFileInfo(const std::string& _rFullPath) const
 {
 	for (auto& fileInfo : m_FileInfoVector)
 	{
 		if (!strcasecmp(fileInfo.m_FullPath, _rFullPath.c_str()))
 		{
-			return(&fileInfo);
+			return &fileInfo;
 		}
 	}
 
-	return(nullptr);
+	return nullptr;
 }
 } // namespace
diff --git a/Source/Core/DiscIO/FileHandlerARC.h b/Source/Core/DiscIO/FileHandlerARC.h
index 1fccd5f894..89f3810024 100644
--- a/Source/Core/DiscIO/FileHandlerARC.h
+++ b/Source/Core/DiscIO/FileHandlerARC.h
@@ -49,6 +49,6 @@ class CARCFile
 
 		size_t BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const char* _szDirectory, const char* _szNameTable);
 
-		const SFileInfo* FindFileInfo(std::string _rFullPath) const;
+		const SFileInfo* FindFileInfo(const std::string& _rFullPath) const;
 };
 } // namespace

From bd1ce18f9092f2929929513729e8abee8f60e4a5 Mon Sep 17 00:00:00 2001
From: Lioncash <mathew1800@gmail.com>
Date: Fri, 14 Mar 2014 23:38:14 -0400
Subject: [PATCH 2/2] Simplify file tree building for the filesystem view.

Technically this also simplifies on disc filename building in general.
---
 .../Core/IPC_HLE/WII_IPC_HLE_Device_DI.cpp    | 23 +++----
 Source/Core/DiscIO/DiscScrubber.cpp           |  2 +-
 Source/Core/DiscIO/FileHandlerARC.cpp         | 33 ++++------
 Source/Core/DiscIO/FileHandlerARC.h           |  2 +-
 Source/Core/DiscIO/FileMonitor.cpp            |  8 +--
 Source/Core/DiscIO/FileSystemGCWii.cpp        | 26 ++++----
 Source/Core/DiscIO/FileSystemGCWii.h          |  4 +-
 Source/Core/DiscIO/Filesystem.h               | 16 ++---
 Source/Core/DolphinWX/ISOProperties.cpp       | 62 +++++++++----------
 9 files changed, 78 insertions(+), 98 deletions(-)

diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_DI.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_DI.cpp
index 836c41b34b..4c6c219732 100644
--- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_DI.cpp
+++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_DI.cpp
@@ -201,19 +201,17 @@ u32 CWII_IPC_HLE_Device_di::ExecuteCommand(u32 _BufferIn, u32 _BufferInSize, u32
 			// Don't do anything if the log is unselected
 			if (LogManager::GetInstance()->IsEnabled(LogTypes::FILEMON))
 			{
-				const char *pFilename = nullptr;
 				if (m_pFileSystem)
-					pFilename = m_pFileSystem->GetFileName(DVDAddress);
-				if (pFilename != nullptr)
 				{
+					const std::string filename = m_pFileSystem->GetFileName(DVDAddress);
+
 					INFO_LOG(WII_IPC_DVD, "DVDLowRead: %s (0x%" PRIx64 ") - (DVDAddr: 0x%" PRIx64 ", Size: 0x%x)",
-						pFilename, m_pFileSystem->GetFileSize(pFilename), DVDAddress, Size);
-					FileMon::CheckFile(std::string(pFilename), (int)m_pFileSystem->GetFileSize(pFilename));
+						filename.c_str(), m_pFileSystem->GetFileSize(filename), DVDAddress, Size);
+					FileMon::CheckFile(filename, (int)m_pFileSystem->GetFileSize(filename));
 				}
 				else
 				{
-					INFO_LOG(WII_IPC_DVD, "DVDLowRead: file unknown - (DVDAddr: 0x%" PRIx64 ", Size: 0x%x)",
-						DVDAddress, Size);
+					ERROR_LOG(WII_IPC_DVD, "Filesystem is invalid.");
 				}
 			}
 
@@ -338,18 +336,17 @@ u32 CWII_IPC_HLE_Device_di::ExecuteCommand(u32 _BufferIn, u32 _BufferInSize, u32
 	case DVDLowSeek:
 		{
 			u64 DVDAddress = Memory::Read_U32(_BufferIn + 0x4) << 2;
-			const char *pFilename = nullptr;
+
 			if (m_pFileSystem)
-				pFilename = m_pFileSystem->GetFileName(DVDAddress);
-			if (pFilename != nullptr)
 			{
+				const std::string filename = m_pFileSystem->GetFileName(DVDAddress);
+
 				INFO_LOG(WII_IPC_DVD, "DVDLowSeek: %s (0x%" PRIx64 ") - (DVDAddr: 0x%" PRIx64 ")",
-					pFilename, m_pFileSystem->GetFileSize(pFilename), DVDAddress);
+					filename.c_str(), m_pFileSystem->GetFileSize(filename), DVDAddress);
 			}
 			else
 			{
-				INFO_LOG(WII_IPC_DVD, "DVDLowSeek: file unknown - (DVDAddr: 0x%" PRIx64 ")",
-					DVDAddress);
+				ERROR_LOG(WII_IPC_DVD, "Filesystem is invalid.");
 			}
 		}
 		break;
diff --git a/Source/Core/DiscIO/DiscScrubber.cpp b/Source/Core/DiscIO/DiscScrubber.cpp
index b48967d31b..69d98ff046 100644
--- a/Source/Core/DiscIO/DiscScrubber.cpp
+++ b/Source/Core/DiscIO/DiscScrubber.cpp
@@ -317,7 +317,7 @@ bool ParsePartitionData(SPartition& _rPartition)
 		// Go through the filesystem and mark entries as used
 		for (size_t currentFile = 0; currentFile < numFiles; currentFile++)
 		{
-			DEBUG_LOG(DISCIO, "%s", currentFile ? (*Files.at(currentFile)).m_FullPath : "/");
+			DEBUG_LOG(DISCIO, "%s", currentFile ? (*Files.at(currentFile)).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
diff --git a/Source/Core/DiscIO/FileHandlerARC.cpp b/Source/Core/DiscIO/FileHandlerARC.cpp
index 960ecaf07d..6215b0a100 100644
--- a/Source/Core/DiscIO/FileHandlerARC.cpp
+++ b/Source/Core/DiscIO/FileHandlerARC.cpp
@@ -9,6 +9,7 @@
 
 #include "Common/Common.h"
 #include "Common/FileUtil.h"
+#include "Common/StringUtil.h"
 #include "DiscIO/Blob.h"
 #include "DiscIO/FileHandlerARC.h"
 #include "DiscIO/Filesystem.h"
@@ -86,7 +87,7 @@ size_t CARCFile::GetFileSize(const std::string& _rFullPath)
 
 	if (pFileInfo != nullptr)
 	{
-		return (size_t) pFileInfo->m_FileSize;
+		return (size_t)pFileInfo->m_FileSize;
 	}
 
 	return 0;
@@ -177,14 +178,14 @@ bool CARCFile::ParseBuffer()
 			szNameTable += 0xC;
 		}
 
-		BuildFilenames(1, m_FileInfoVector.size(), nullptr, szNameTable);
+		BuildFilenames(1, m_FileInfoVector.size(), "", szNameTable);
 	}
 
 	return true;
 }
 
 
-size_t CARCFile::BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const char* _szDirectory, const char* _szNameTable)
+size_t CARCFile::BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const std::string& _szDirectory, const char* _szNameTable)
 {
 	size_t CurrentIndex = _FirstIndex;
 
@@ -196,29 +197,19 @@ size_t CARCFile::BuildFilenames(const size_t _FirstIndex, const size_t _LastInde
 		// check next index
 		if (rFileInfo.IsDirectory())
 		{
-			// this is a directory, build up the new szDirectory
-			if (_szDirectory != nullptr)
-			{
-				sprintf(rFileInfo.m_FullPath, "%s%s/", _szDirectory, &_szNameTable[uOffset]);
-			}
+			if (_szDirectory.empty())
+				rFileInfo.m_FullPath += StringFromFormat("%s/", &_szNameTable[uOffset]);
 			else
-			{
-				sprintf(rFileInfo.m_FullPath, "%s/", &_szNameTable[uOffset]);
-			}
+				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
+		else // This is a filename
 		{
-			// this is a filename
-			if (_szDirectory != nullptr)
-			{
-				sprintf(rFileInfo.m_FullPath, "%s%s", _szDirectory, &_szNameTable[uOffset]);
-			}
+			if (_szDirectory.empty())
+				rFileInfo.m_FullPath += StringFromFormat("%s", &_szNameTable[uOffset]);
 			else
-			{
-				sprintf(rFileInfo.m_FullPath, "%s", &_szNameTable[uOffset]);
-			}
+				rFileInfo.m_FullPath += StringFromFormat("%s%s", _szDirectory.c_str(), &_szNameTable[uOffset]);
 
 			CurrentIndex++;
 		}
@@ -232,7 +223,7 @@ const SFileInfo* CARCFile::FindFileInfo(const std::string& _rFullPath) const
 {
 	for (auto& fileInfo : m_FileInfoVector)
 	{
-		if (!strcasecmp(fileInfo.m_FullPath, _rFullPath.c_str()))
+		if (!strcasecmp(fileInfo.m_FullPath.c_str(), _rFullPath.c_str()))
 		{
 			return &fileInfo;
 		}
diff --git a/Source/Core/DiscIO/FileHandlerARC.h b/Source/Core/DiscIO/FileHandlerARC.h
index 89f3810024..327d81c4b9 100644
--- a/Source/Core/DiscIO/FileHandlerARC.h
+++ b/Source/Core/DiscIO/FileHandlerARC.h
@@ -47,7 +47,7 @@ class CARCFile
 
 		bool ParseBuffer();
 
-		size_t BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const char* _szDirectory, const char* _szNameTable);
+		size_t BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const std::string& _szDirectory, const char* _szNameTable);
 
 		const SFileInfo* FindFileInfo(const std::string& _rFullPath) const;
 };
diff --git a/Source/Core/DiscIO/FileMonitor.cpp b/Source/Core/DiscIO/FileMonitor.cpp
index 34790ff408..d99bd14cd8 100644
--- a/Source/Core/DiscIO/FileMonitor.cpp
+++ b/Source/Core/DiscIO/FileMonitor.cpp
@@ -142,13 +142,9 @@ void FindFilename(u64 offset)
 		return;
 	}
 
-	const char *fname = pFileSystem->GetFileName(offset);
+	const std::string filename = pFileSystem->GetFileName(offset);
 
-	// There's something wrong with the paths
-	if (!fname || (strlen(fname) == 512))
-		return;
-
-	CheckFile(fname, pFileSystem->GetFileSize(fname));
+	CheckFile(filename, pFileSystem->GetFileSize(filename));
 }
 
 void Close()
diff --git a/Source/Core/DiscIO/FileSystemGCWii.cpp b/Source/Core/DiscIO/FileSystemGCWii.cpp
index 1ecf71d4b5..f9f88e8d02 100644
--- a/Source/Core/DiscIO/FileSystemGCWii.cpp
+++ b/Source/Core/DiscIO/FileSystemGCWii.cpp
@@ -46,7 +46,7 @@ u64 CFileSystemGCWii::GetFileSize(const std::string& _rFullPath)
 	return 0;
 }
 
-const char* CFileSystemGCWii::GetFileName(u64 _Address)
+const std::string CFileSystemGCWii::GetFileName(u64 _Address)
 {
 	if (!m_Initialized)
 		InitFileSystem();
@@ -239,7 +239,7 @@ const SFileInfo* CFileSystemGCWii::FindFileInfo(const std::string& _rFullPath)
 
 	for (auto& fileInfo : m_FileInfoVector)
 	{
-		if (!strcasecmp(fileInfo.m_FullPath, _rFullPath.c_str()))
+		if (!strcasecmp(fileInfo.m_FullPath.c_str(), _rFullPath.c_str()))
 			return &fileInfo;
 	}
 
@@ -297,13 +297,11 @@ void CFileSystemGCWii::InitFileSystem()
 			NameTableOffset += 0xC;
 		}
 
-		BuildFilenames(1, m_FileInfoVector.size(), nullptr, NameTableOffset);
+		BuildFilenames(1, m_FileInfoVector.size(), "", NameTableOffset);
 	}
 }
 
-// Changed this stuff from C++ string to C strings for speed in debug mode. Doesn't matter in release, but
-// std::string is SLOW in debug mode.
-size_t CFileSystemGCWii::BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const char* _szDirectory, u64 _NameTableOffset)
+size_t CFileSystemGCWii::BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const std::string& _szDirectory, u64 _NameTableOffset)
 {
 	size_t CurrentIndex = _FirstIndex;
 
@@ -316,21 +314,19 @@ size_t CFileSystemGCWii::BuildFilenames(const size_t _FirstIndex, const size_t _
 		// check next index
 		if (rFileInfo->IsDirectory())
 		{
-			// this is a directory, build up the new szDirectory
-			if (_szDirectory != nullptr)
-				CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s/", _szDirectory, filename.c_str());
+			if (_szDirectory.empty())
+				rFileInfo->m_FullPath += StringFromFormat("%s/", filename.c_str());
 			else
-				CharArrayFromFormat(rFileInfo->m_FullPath, "%s/", filename.c_str());
+				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
+		else // This is a filename
 		{
-			// this is a filename
-			if (_szDirectory != nullptr)
-				CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s", _szDirectory, filename.c_str());
+			if (_szDirectory.empty())
+				rFileInfo->m_FullPath += filename;
 			else
-				CharArrayFromFormat(rFileInfo->m_FullPath, "%s", filename.c_str());
+				rFileInfo->m_FullPath += StringFromFormat("%s%s", _szDirectory.c_str(), filename.c_str());
 
 			CurrentIndex++;
 		}
diff --git a/Source/Core/DiscIO/FileSystemGCWii.h b/Source/Core/DiscIO/FileSystemGCWii.h
index 4ce1e09cbf..a807358b32 100644
--- a/Source/Core/DiscIO/FileSystemGCWii.h
+++ b/Source/Core/DiscIO/FileSystemGCWii.h
@@ -24,7 +24,7 @@ public:
 	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 char* GetFileName(u64 _Address) override;
+	virtual const std::string GetFileName(u64 _Address) override;
 	virtual u64 ReadFile(const std::string& _rFullPath, u8* _pBuffer, size_t _MaxBufferSize) override;
 	virtual bool ExportFile(const std::string& _rFullPath, const std::string&_rExportFilename) override;
 	virtual bool ExportApploader(const std::string& _rExportFolder) const override;
@@ -43,7 +43,7 @@ private:
 	const SFileInfo* FindFileInfo(const std::string& _rFullPath);
 	bool DetectFileSystem();
 	void InitFileSystem();
-	size_t BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const char* _szDirectory, u64 _NameTableOffset);
+	size_t BuildFilenames(const size_t _FirstIndex, const size_t _LastIndex, const std::string& _szDirectory, u64 _NameTableOffset);
 };
 
 } // namespace
diff --git a/Source/Core/DiscIO/Filesystem.h b/Source/Core/DiscIO/Filesystem.h
index 44fa88391b..9145609267 100644
--- a/Source/Core/DiscIO/Filesystem.h
+++ b/Source/Core/DiscIO/Filesystem.h
@@ -22,17 +22,17 @@ struct SFileInfo
 	u64 m_NameOffset;
 	u64 m_Offset;
 	u64 m_FileSize;
-	char m_FullPath[512];
+	std::string m_FullPath;
 
-	bool IsDirectory() const { return (m_NameOffset & 0xFF000000) != 0 ? true : false; }
+	bool IsDirectory() const { return (m_NameOffset & 0xFF000000) != 0; }
 
-	SFileInfo() : m_NameOffset(0), m_Offset(0), m_FileSize(0) {
-		memset(m_FullPath, 0, sizeof(m_FullPath));
+	SFileInfo() : m_NameOffset(0), m_Offset(0), m_FileSize(0)
+	{
 	}
 
-	SFileInfo(const SFileInfo &rhs) : m_NameOffset(rhs.m_NameOffset),
-		m_Offset(rhs.m_Offset), m_FileSize(rhs.m_FileSize) {
-		memcpy(m_FullPath, rhs.m_FullPath, strlen(rhs.m_FullPath) + 1);
+	SFileInfo(const SFileInfo& rhs) : m_NameOffset(rhs.m_NameOffset),
+	    m_Offset(rhs.m_Offset), m_FileSize(rhs.m_FileSize), m_FullPath(rhs.m_FullPath)
+	{
 	}
 };
 
@@ -49,7 +49,7 @@ public:
 	virtual bool ExportFile(const std::string& _rFullPath, const std::string& _rExportFilename) = 0;
 	virtual bool ExportApploader(const std::string& _rExportFolder) const = 0;
 	virtual bool ExportDOL(const std::string& _rExportFolder) const = 0;
-	virtual const char* GetFileName(u64 _Address) = 0;
+	virtual const std::string GetFileName(u64 _Address) = 0;
 	virtual bool GetBootDOL(u8* &buffer, u32 DolSize) const = 0;
 	virtual u32 GetBootDOLSize() const = 0;
 
diff --git a/Source/Core/DolphinWX/ISOProperties.cpp b/Source/Core/DolphinWX/ISOProperties.cpp
index 3be4a27cbd..ac1d1e5435 100644
--- a/Source/Core/DolphinWX/ISOProperties.cpp
+++ b/Source/Core/DolphinWX/ISOProperties.cpp
@@ -320,30 +320,32 @@ size_t CISOProperties::CreateDirectoryTree(wxTreeItemId& parent,
 
 	while (CurrentIndex < _LastIndex)
 	{
-		const DiscIO::SFileInfo *rFileInfo = fileInfos[CurrentIndex];
-		char *name = (char*)rFileInfo->m_FullPath;
+		const DiscIO::SFileInfo* rFileInfo = fileInfos[CurrentIndex];
+		std::string filePath = rFileInfo->m_FullPath;
 
-		if (rFileInfo->IsDirectory())
+		// Trim the trailing '/' if it exists.
+		if (filePath[filePath.length() - 1] == DIR_SEP_CHR)
 		{
-			name[strlen(name) - 1] = '\0';
+			filePath.pop_back();
 		}
 
-		char *itemName = strrchr(name, DIR_SEP_CHR);
-
-		if (!itemName)
-			itemName = name;
-		else
-			itemName++;
+		// Cut off the path up to the actual filename or folder.
+		// Say we have "/music/stream/stream1.strm", the result will be "stream1.strm".
+		size_t dirSepIndex = filePath.find_last_of(DIR_SEP_CHR);
+		if (dirSepIndex != std::string::npos)
+		{
+			filePath = filePath.substr(dirSepIndex + 1);
+		}
 
 		// check next index
 		if (rFileInfo->IsDirectory())
 		{
-			wxTreeItemId item = m_Treectrl->AppendItem(parent, StrToWxStr(itemName), 1, 1);
+			wxTreeItemId item = m_Treectrl->AppendItem(parent, StrToWxStr(filePath), 1, 1);
 			CurrentIndex = CreateDirectoryTree(item, fileInfos, CurrentIndex + 1, (size_t)rFileInfo->m_FileSize);
 		}
 		else
 		{
-			m_Treectrl->AppendItem(parent, StrToWxStr(itemName), 2, 2);
+			m_Treectrl->AppendItem(parent, StrToWxStr(filePath), 2, 2);
 			CurrentIndex++;
 		}
 	}
@@ -734,7 +736,7 @@ void CISOProperties::OnExtractFile(wxCommandEvent& WXUNUSED (event))
 	if (DiscIO::IsVolumeWiiDisc(OpenISO))
 	{
 		int partitionNum = wxAtoi(File.Mid(File.find_first_of("/") - 1, 1));
-		File.Remove(0, File.find_first_of("/") +1); // Remove "Partition x/"
+		File.Remove(0, File.find_first_of("/") + 1); // Remove "Partition x/"
 		WiiDisc.at(partitionNum).FileSystem->ExportFile(WxStrToStr(File), WxStrToStr(Path));
 	}
 	else
@@ -745,7 +747,7 @@ void CISOProperties::OnExtractFile(wxCommandEvent& WXUNUSED (event))
 
 void CISOProperties::ExportDir(const char* _rFullPath, const char* _rExportFolder, const int partitionNum)
 {
-	char exportName[512];
+	std::string exportName;
 	u32 index[2] = {0, 0};
 	std::vector<const DiscIO::SFileInfo *> fst;
 	DiscIO::IFileSystem *FS = nullptr;
@@ -774,7 +776,7 @@ void CISOProperties::ExportDir(const char* _rFullPath, const char* _rExportFolde
 	{
 		for (index[0] = 0; index[0] < fst.size(); index[0]++)
 		{
-			if (!strcmp(fst.at(index[0])->m_FullPath, _rFullPath))
+			if (fst.at(index[0])->m_FullPath == _rFullPath)
 			{
 				DEBUG_LOG(DISCIO, "Found the directory at %u", index[0]);
 				index[1] = (u32)fst.at(index[0])->m_FileSize;
@@ -802,41 +804,40 @@ void CISOProperties::ExportDir(const char* _rFullPath, const char* _rExportFolde
 		dialog.SetTitle(wxString::Format(wxT("%s : %d%%"), dialogTitle.c_str(),
 			(u32)(((float)(i - index[0]) / (float)(index[1] - index[0])) * 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())
 		{
-			snprintf(exportName, sizeof(exportName), "%s/%s/", _rExportFolder, fst[i]->m_FullPath);
-			DEBUG_LOG(DISCIO, "%s", exportName);
+			exportName = StringFromFormat("%s/%s/", _rExportFolder, fst[i]->m_FullPath.c_str());
+			DEBUG_LOG(DISCIO, "%s", exportName.c_str());
 
 			if (!File::Exists(exportName) && !File::CreateFullPath(exportName))
 			{
-				ERROR_LOG(DISCIO, "Could not create the path %s", exportName);
+				ERROR_LOG(DISCIO, "Could not create the path %s", exportName.c_str());
 			}
 			else
 			{
 				if (!File::IsDirectory(exportName))
-					ERROR_LOG(DISCIO, "%s already exists and is not a directory", exportName);
+					ERROR_LOG(DISCIO, "%s already exists and is not a directory", exportName.c_str());
 
-				DEBUG_LOG(DISCIO, "Folder %s already exists", exportName);
+				DEBUG_LOG(DISCIO, "Folder %s already exists", exportName.c_str());
 			}
 		}
 		else
 		{
-			snprintf(exportName, sizeof(exportName), "%s/%s", _rExportFolder, fst[i]->m_FullPath);
-			DEBUG_LOG(DISCIO, "%s", exportName);
+			exportName = StringFromFormat("%s/%s", _rExportFolder, fst[i]->m_FullPath.c_str());
+			DEBUG_LOG(DISCIO, "%s", exportName.c_str());
 
 			if (!File::Exists(exportName) && !FS->ExportFile(fst[i]->m_FullPath, exportName))
 			{
-				ERROR_LOG(DISCIO, "Could not export %s", exportName);
+				ERROR_LOG(DISCIO, "Could not export %s", exportName.c_str());
 			}
 			else
 			{
-				DEBUG_LOG(DISCIO, "%s already exists", exportName);
+				DEBUG_LOG(DISCIO, "%s already exists", exportName.c_str());
 			}
 		}
 	}
@@ -863,8 +864,7 @@ void CISOProperties::OnExtractDir(wxCommandEvent& event)
 
 	while (m_Treectrl->GetItemParent(m_Treectrl->GetSelection()) != m_Treectrl->GetRootItem())
 	{
-		wxString temp;
-		temp = m_Treectrl->GetItemText(m_Treectrl->GetItemParent(m_Treectrl->GetSelection()));
+		wxString 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()));
@@ -873,7 +873,7 @@ void CISOProperties::OnExtractDir(wxCommandEvent& event)
 	if (DiscIO::IsVolumeWiiDisc(OpenISO))
 	{
 		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);
 	}
 	else
@@ -893,7 +893,7 @@ void CISOProperties::OnExtractDataFromHeader(wxCommandEvent& event)
 	if (DiscIO::IsVolumeWiiDisc(OpenISO))
 	{
 		wxString Directory = m_Treectrl->GetItemText(m_Treectrl->GetSelection());
-		std::size_t partitionNum = (std::size_t)wxAtoi(Directory.Mid(Directory.find_first_of("0123456789"), 2));
+		int partitionNum = wxAtoi(Directory.Mid(Directory.find_first_of("0123456789"), 2));
 
 		if (WiiDisc.size() > partitionNum)
 		{
@@ -902,7 +902,7 @@ void CISOProperties::OnExtractDataFromHeader(wxCommandEvent& event)
 		}
 		else
 		{
-			PanicAlertT("Partition doesn't exist: %u", (unsigned) partitionNum);
+			PanicAlertT("Partition doesn't exist: %d", partitionNum);
 			return;
 		}
 	}