Update Wii save import / export to use the same replace list as FileIO

add a couple of country codes I found through redump.org database

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6640 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
LPFaint99 2010-12-22 00:48:59 +00:00
parent c1c1f54c59
commit 9584b5b335
5 changed files with 75 additions and 43 deletions

View File

@ -18,6 +18,7 @@
#include "CommonPaths.h"
#include "FileUtil.h"
#include "NandPaths.h"
#include <fstream>
namespace Common
{
@ -87,4 +88,36 @@ bool CheckTitleTIK(u64 _titleID)
return false;
}
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";
}
void ReadReplacements(replace_v& replacements)
{
replacements.clear();
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));
}
};

View File

@ -25,11 +25,15 @@
namespace Common
{
typedef std::pair<char, std::string> replace_t;
typedef std::vector<replace_t> replace_v;
std::string CreateTicketFileName(u64 _titleID);
std::string CreateTitleDataPath(u64 _titleID);
std::string CreateTitleContentPath(u64 _titleID);
bool CheckTitleTMD(u64 _titleID);
bool CheckTitleTIK(u64 _titleID);
void ReadReplacements(replace_v& replacements);
}
#endif

View File

@ -22,43 +22,11 @@
#include "WII_IPC_HLE_Device_fs.h"
#include "WII_IPC_HLE_Device_FileIO.h"
#include "NandPaths.h"
#include <algorithm>
#include <fstream>
typedef std::pair<char, std::string> replace_t;
typedef std::vector<replace_t> replace_v;
static replace_v replacements;
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));
}
static Common::replace_v replacements;
// This is used by several of the FileIO and /dev/fs/ functions
std::string HLE_IPC_BuildFilename(const char* _pFilename, int _size)
@ -70,7 +38,7 @@ std::string HLE_IPC_BuildFilename(const char* _pFilename, int _size)
path_full += std::string("/title"); // this looks and feel like a hack...
// 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 (Common::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);
@ -88,7 +56,7 @@ CWII_IPC_HLE_Device_FileIO::CWII_IPC_HLE_Device_FileIO(u32 _DeviceID, const std:
, m_Mode(0)
, m_Seek(0)
{
ReadReplacements();
Common::ReadReplacements(replacements);
}
CWII_IPC_HLE_Device_FileIO::~CWII_IPC_HLE_Device_FileIO()

View File

@ -25,15 +25,18 @@ IVolume::ECountry CountrySwitch(u8 CountryCode)
// Region free - fall through to European defaults for now
case 'A':
case 'X': // Not a real region code. Used by DVDX 1.0 and
// The Homebrew Channel versions 1.0.4 and earlier.
// PAL
case 'D':
case 'D': // German
case 'X': // Used by a couple PAL games
case 'Y': // German, french
case 'L': // Japanese import to PAL regions
case 'M': // Japanese import to PAL regions
case 'S': // Spanish-speaking regions
case 'P':
case 'U': // Australia
return IVolume::COUNTRY_EUROPE;
break;

View File

@ -23,6 +23,10 @@
#include "WiiSaveCrypted.h"
#include "FileUtil.h"
#include "MathUtil.h"
#include "NandPaths.h"
#include <algorithm>
static Common::replace_v replacements;
const u8 SDKey[16] = {0xAB, 0x01, 0xB9, 0xD8, 0xE1, 0x62, 0x2B, 0x08,
0xAF, 0xBA, 0xD8, 0x4D, 0xBF, 0xC2, 0xA5, 0x5D};
@ -32,6 +36,7 @@ const u8 MD5_BLANKER[0x10] = {0x0E, 0x65, 0x37, 0x81, 0x99, 0xBE, 0x45, 0x17,
CWiiSaveCrypted::CWiiSaveCrypted(const char* FileName, u64 title)
: _saveGameTitle(title)
{
Common::ReadReplacements(replacements);
strcpy(pathData_bin, FileName);
memcpy(SD_IV, "\x21\x67\x12\xE6\xAA\x1F\x68\x9F\x95\xC5\xA2\x23\x24\xDC\x6A\x98", 0x10);
@ -286,7 +291,14 @@ void CWiiSaveCrypted::ImportWiiSaveFiles()
}
else
{
sprintf(pathRawSave, "%s%s", pathSavedir, _tmpFileHDR.name);
std::string fileName ((char*)_tmpFileHDR.name);
for (Common::replace_v::const_iterator iter = replacements.begin(); iter != replacements.end(); ++iter)
{
for (size_t j = 0; (j = fileName.find(iter->first, j)) != fileName.npos; ++j)
fileName.replace(j, 1, iter->second);
}
sprintf(pathRawSave, "%s%s", pathSavedir, fileName.c_str());
File::CreateFullPath(pathRawSave);
if (_tmpFileHDR.type == 1)
{
@ -349,13 +361,25 @@ void CWiiSaveCrypted::ExportWiiSaveFiles()
SplitPath(FilesList.at(i), NULL, &__name, &__ext);
__name += __ext;
for (Common::replace_v::const_iterator iter = replacements.begin(); iter != replacements.end(); ++iter)
{
for (size_t j = 0; (j = __name.find(iter->second, j)) != __name.npos; ++j)
{
/*std::string tmp = __name.substr(0, j) + iter->first +__name.substr(j+iter->second.length(), __name.length());
__name = tmp;*/
__name.replace(j, iter->second.length(), 1, iter->first);
}
}
if (__name.length() > 0x44)
{
PanicAlert("%s is too long for the filename, max chars is 45", __name.c_str());
b_valid = false;
return;
}
strncpy((char *)tmpFileHDR.name, __name.c_str(), 0x44);
strncpy((char *)tmpFileHDR.name, __name.c_str(), __name.length());
fpData_bin = fopen(pathData_bin, "ab");
if (fpData_bin)