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:
parent
a9ca9cfd9b
commit
3528629d9a
|
@ -23,32 +23,64 @@
|
||||||
#include "WII_IPC_HLE_Device_fs.h"
|
#include "WII_IPC_HLE_Device_fs.h"
|
||||||
#include "WII_IPC_HLE_Device_FileIO.h"
|
#include "WII_IPC_HLE_Device_FileIO.h"
|
||||||
#include <algorithm>
|
#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
|
// This is used by several of the FileIO and /dev/fs/ functions
|
||||||
std::string HLE_IPC_BuildFilename(const char* _pFilename, int _size)
|
std::string HLE_IPC_BuildFilename(const char* _pFilename, int _size)
|
||||||
{
|
{
|
||||||
char Buffer[128];
|
std::string path_full = std::string(File::GetUserPath(D_WIIROOT_IDX));
|
||||||
memcpy(Buffer, _pFilename, _size);
|
std::string path_wii(_pFilename, _size);
|
||||||
|
|
||||||
std::string Filename = std::string(File::GetUserPath(D_WIIROOT_IDX));
|
if (path_wii[1] == '0')
|
||||||
if (Buffer[1] == '0')
|
path_full += std::string("/title"); // this looks and feel like a hack...
|
||||||
Filename += std::string("/title"); // this looks and feel like a hack...
|
|
||||||
|
|
||||||
// Replaces chars that NTFS can't support with '-'. TODO '/', '\' ?
|
// Replaces chars that FAT32 can't support with strings defined in /sys/replace
|
||||||
std::replace(Buffer, Buffer + _size, '"', '-');
|
for (replace_v::const_iterator i = replacements.begin(); i != replacements.end(); ++i)
|
||||||
std::replace(Buffer, Buffer + _size, '*', '-');
|
{
|
||||||
std::replace(Buffer, Buffer + _size, ':', '-');
|
for (size_t j = 0; (j = path_wii.find(i->first, j)) != path_wii.npos; ++j)
|
||||||
std::replace(Buffer, Buffer + _size, '<', '-');
|
path_wii.replace(j, 1, i->second);
|
||||||
std::replace(Buffer, Buffer + _size, '>', '-');
|
}
|
||||||
std::replace(Buffer, Buffer + _size, '?', '-');
|
|
||||||
std::replace(Buffer, Buffer + _size, '|', '-');
|
|
||||||
|
|
||||||
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)
|
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
|
: IWII_IPC_HLE_Device(_DeviceID, _rDeviceName, false) // not a real hardware
|
||||||
, m_pFileHandle(NULL)
|
, 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_Mode(0)
|
||||||
, m_Seek(0)
|
, m_Seek(0)
|
||||||
{
|
{
|
||||||
|
ReadReplacements();
|
||||||
}
|
}
|
||||||
|
|
||||||
CWII_IPC_HLE_Device_FileIO::~CWII_IPC_HLE_Device_FileIO()
|
CWII_IPC_HLE_Device_FileIO::~CWII_IPC_HLE_Device_FileIO()
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
#include "WII_IPC_HLE_Device.h"
|
#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
|
class CWII_IPC_HLE_Device_FileIO : public IWII_IPC_HLE_Device
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "CommonPaths.h"
|
#include "CommonPaths.h"
|
||||||
|
|
||||||
#include "WII_IPC_HLE_Device_fs.h"
|
#include "WII_IPC_HLE_Device_fs.h"
|
||||||
|
#include "WII_IPC_HLE_Device_FileIO.h"
|
||||||
|
|
||||||
#include "StringUtil.h"
|
#include "StringUtil.h"
|
||||||
#include "FileSearch.h"
|
#include "FileSearch.h"
|
||||||
|
@ -26,8 +27,6 @@
|
||||||
|
|
||||||
#include "../VolumeHandler.h"
|
#include "../VolumeHandler.h"
|
||||||
|
|
||||||
extern std::string HLE_IPC_BuildFilename(const char* _pFilename, int _size);
|
|
||||||
|
|
||||||
#define MAX_NAME (12)
|
#define MAX_NAME (12)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue