Use the /sys/replace file for defining char to replace and their corresponding replacement strings.

Method suggested by pune for compatibility across filesystems and nand tools.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6557 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Shawn Hoffman 2010-12-11 20:51:48 +00:00
parent a9ca9cfd9b
commit 3528629d9a
3 changed files with 52 additions and 18 deletions

View File

@ -23,32 +23,64 @@
#include "WII_IPC_HLE_Device_fs.h"
#include "WII_IPC_HLE_Device_FileIO.h"
#include <algorithm>
#include <fstream>
typedef std::pair<char, std::string> replace_t;
typedef std::vector<replace_t> replace_v;
static replace_v replacements;
#pragma optimize("",off)
static void CreateReplacementFile(std::string &filename)
{
std::ofstream replace(filename.c_str());
replace <<"\" __22__\n";
replace << "* __2a__\n";
//replace << "/ __2f__\n";
replace << ": __3a__\n";
replace << "< __3c__\n";
replace << "> __3e__\n";
replace << "? __3f__\n";
//replace <<"\\ __5c__\n";
replace << "| __7c__\n";
}
static void ReadReplacements()
{
const std::string replace_fname = "/sys/replace";
std::string filename(File::GetUserPath(D_WIIROOT_IDX));
filename += replace_fname;
if (!File::Exists(filename.c_str()))
CreateReplacementFile(filename);
std::ifstream f(filename.c_str());
char letter;
std::string replacement;
while (f >> letter >> replacement && replacement.size())
replacements.push_back(std::make_pair(letter, replacement));
}
// This is used by several of the FileIO and /dev/fs/ functions
std::string HLE_IPC_BuildFilename(const char* _pFilename, int _size)
{
char Buffer[128];
memcpy(Buffer, _pFilename, _size);
std::string path_full = std::string(File::GetUserPath(D_WIIROOT_IDX));
std::string path_wii(_pFilename, _size);
std::string Filename = std::string(File::GetUserPath(D_WIIROOT_IDX));
if (Buffer[1] == '0')
Filename += std::string("/title"); // this looks and feel like a hack...
if (path_wii[1] == '0')
path_full += std::string("/title"); // this looks and feel like a hack...
// Replaces chars that NTFS can't support with '-'. TODO '/', '\' ?
std::replace(Buffer, Buffer + _size, '"', '-');
std::replace(Buffer, Buffer + _size, '*', '-');
std::replace(Buffer, Buffer + _size, ':', '-');
std::replace(Buffer, Buffer + _size, '<', '-');
std::replace(Buffer, Buffer + _size, '>', '-');
std::replace(Buffer, Buffer + _size, '?', '-');
std::replace(Buffer, Buffer + _size, '|', '-');
// Replaces chars that FAT32 can't support with strings defined in /sys/replace
for (replace_v::const_iterator i = replacements.begin(); i != replacements.end(); ++i)
{
for (size_t j = 0; (j = path_wii.find(i->first, j)) != path_wii.npos; ++j)
path_wii.replace(j, 1, i->second);
}
Filename += Buffer;
path_full += path_wii;
return Filename;
return path_full;
}
#pragma optimize("",on)
CWII_IPC_HLE_Device_FileIO::CWII_IPC_HLE_Device_FileIO(u32 _DeviceID, const std::string& _rDeviceName)
: IWII_IPC_HLE_Device(_DeviceID, _rDeviceName, false) // not a real hardware
, m_pFileHandle(NULL)
@ -56,6 +88,7 @@ CWII_IPC_HLE_Device_FileIO::CWII_IPC_HLE_Device_FileIO(u32 _DeviceID, const std:
, m_Mode(0)
, m_Seek(0)
{
ReadReplacements();
}
CWII_IPC_HLE_Device_FileIO::~CWII_IPC_HLE_Device_FileIO()

View File

@ -20,6 +20,8 @@
#include "WII_IPC_HLE_Device.h"
std::string HLE_IPC_BuildFilename(const char* _pFilename, int _size);
class CWII_IPC_HLE_Device_FileIO : public IWII_IPC_HLE_Device
{
public:

View File

@ -19,6 +19,7 @@
#include "CommonPaths.h"
#include "WII_IPC_HLE_Device_fs.h"
#include "WII_IPC_HLE_Device_FileIO.h"
#include "StringUtil.h"
#include "FileSearch.h"
@ -26,8 +27,6 @@
#include "../VolumeHandler.h"
extern std::string HLE_IPC_BuildFilename(const char* _pFilename, int _size);
#define MAX_NAME (12)