fix chinese filenames in savestates and dct files (fixes #343)
This commit is contained in:
parent
fc3d81e73a
commit
209dfca35f
|
@ -804,52 +804,49 @@ BOOL CHEATS::save()
|
||||||
{
|
{
|
||||||
const char *types[] = {"DS", "AR", "CB"};
|
const char *types[] = {"DS", "AR", "CB"};
|
||||||
std::string cheatLineStr = "";
|
std::string cheatLineStr = "";
|
||||||
FILE *flist = fopen((char *)filename, "w");
|
|
||||||
|
|
||||||
if (flist)
|
EMUFILE_FILE flist((char *)filename, "w");
|
||||||
|
if(flist.fail())
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
flist.fprintf("; DeSmuME cheats file. VERSION %i.%03i\n", CHEAT_VERSION_MAJOR, CHEAT_VERSION_MINOR);
|
||||||
|
flist.fprintf("Name=%s\n", gameInfo.ROMname);
|
||||||
|
flist.fprintf("Serial=%s\n", gameInfo.ROMserial);
|
||||||
|
flist.fprintf("\n; cheats list\n");
|
||||||
|
for (size_t i = 0; i < list.size(); i++)
|
||||||
{
|
{
|
||||||
fprintf(flist, "; DeSmuME cheats file. VERSION %i.%03i\n", CHEAT_VERSION_MAJOR, CHEAT_VERSION_MINOR);
|
if (list[i].num == 0) continue;
|
||||||
fprintf(flist, "Name=%s\n", gameInfo.ROMname);
|
|
||||||
fprintf(flist, "Serial=%s\n", gameInfo.ROMserial);
|
char buf1[8] = {0};
|
||||||
fputs("\n; cheats list\n", flist);
|
sprintf(buf1, "%s %c ", types[list[i].type], list[i].enabled?'1':'0');
|
||||||
for (size_t i = 0; i < list.size(); i++)
|
cheatLineStr = buf1;
|
||||||
|
|
||||||
|
for (int t = 0; t < list[i].num; t++)
|
||||||
{
|
{
|
||||||
if (list[i].num == 0) continue;
|
char buf2[10] = { 0 };
|
||||||
|
|
||||||
char buf1[8] = {0};
|
u32 adr = list[i].code[t][0];
|
||||||
sprintf(buf1, "%s %c ", types[list[i].type], list[i].enabled?'1':'0');
|
if (list[i].type == 0)
|
||||||
cheatLineStr = buf1;
|
|
||||||
|
|
||||||
for (int t = 0; t < list[i].num; t++)
|
|
||||||
{
|
{
|
||||||
char buf2[10] = { 0 };
|
//size of the cheat is written out as adr highest nybble
|
||||||
|
adr &= 0x0FFFFFFF;
|
||||||
u32 adr = list[i].code[t][0];
|
adr |= (list[i].size << 28);
|
||||||
if (list[i].type == 0)
|
|
||||||
{
|
|
||||||
//size of the cheat is written out as adr highest nybble
|
|
||||||
adr &= 0x0FFFFFFF;
|
|
||||||
adr |= (list[i].size << 28);
|
|
||||||
}
|
|
||||||
sprintf(buf2, "%08X", adr);
|
|
||||||
cheatLineStr += buf2;
|
|
||||||
|
|
||||||
sprintf(buf2, "%08X", list[i].code[t][1]);
|
|
||||||
cheatLineStr += buf2;
|
|
||||||
if (t < (list[i].num - 1))
|
|
||||||
cheatLineStr += ",";
|
|
||||||
}
|
}
|
||||||
|
sprintf(buf2, "%08X", adr);
|
||||||
cheatLineStr += " ;";
|
cheatLineStr += buf2;
|
||||||
cheatLineStr += trim(list[i].description);
|
|
||||||
fprintf(flist, "%s\n", cheatLineStr.c_str());
|
sprintf(buf2, "%08X", list[i].code[t][1]);
|
||||||
|
cheatLineStr += buf2;
|
||||||
|
if (t < (list[i].num - 1))
|
||||||
|
cheatLineStr += ",";
|
||||||
}
|
}
|
||||||
fputs("\n", flist);
|
|
||||||
fclose(flist);
|
cheatLineStr += " ;";
|
||||||
return TRUE;
|
cheatLineStr += trim(list[i].description);
|
||||||
|
flist.fprintf("%s\n", cheatLineStr.c_str());
|
||||||
}
|
}
|
||||||
|
flist.fprintf("\n");
|
||||||
return FALSE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *CHEATS::clearCode(char *s)
|
char *CHEATS::clearCode(char *s)
|
||||||
|
@ -873,11 +870,9 @@ char *CHEATS::clearCode(char *s)
|
||||||
|
|
||||||
BOOL CHEATS::load()
|
BOOL CHEATS::load()
|
||||||
{
|
{
|
||||||
FILE *flist = fopen((char *)filename, "r");
|
EMUFILE_FILE flist((char *)filename, "r");
|
||||||
if (flist == NULL)
|
if(flist.fail())
|
||||||
{
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
|
|
||||||
size_t readSize = (MAX_XX_CODE * 17) + sizeof(list[0].description) + 7;
|
size_t readSize = (MAX_XX_CODE * 17) + sizeof(list[0].description) + 7;
|
||||||
if (readSize < CHEAT_FILE_MIN_FGETS_BUFFER)
|
if (readSize < CHEAT_FILE_MIN_FGETS_BUFFER)
|
||||||
|
@ -886,11 +881,6 @@ BOOL CHEATS::load()
|
||||||
}
|
}
|
||||||
|
|
||||||
char *buf = (char *)malloc(readSize);
|
char *buf = (char *)malloc(readSize);
|
||||||
if (buf == NULL)
|
|
||||||
{
|
|
||||||
fclose(flist);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
readSize *= sizeof(*buf);
|
readSize *= sizeof(*buf);
|
||||||
|
|
||||||
|
@ -901,12 +891,12 @@ BOOL CHEATS::load()
|
||||||
INFO("Load cheats: %s\n", filename);
|
INFO("Load cheats: %s\n", filename);
|
||||||
clear();
|
clear();
|
||||||
last = 0; line = 0;
|
last = 0; line = 0;
|
||||||
while (!feof(flist))
|
while (!flist.eof())
|
||||||
{
|
{
|
||||||
CHEATS_LIST tmp_cht;
|
CHEATS_LIST tmp_cht;
|
||||||
line++; // only for debug
|
line++; // only for debug
|
||||||
memset(buf, 0, readSize);
|
memset(buf, 0, readSize);
|
||||||
if (fgets(buf, readSize, flist) == NULL) {
|
if (flist.fgets(buf, readSize) == NULL) {
|
||||||
//INFO("Cheats: Failed to read from flist at line %i\n", line);
|
//INFO("Cheats: Failed to read from flist at line %i\n", line);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -980,7 +970,6 @@ BOOL CHEATS::load()
|
||||||
free(buf);
|
free(buf);
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
|
|
||||||
fclose(flist);
|
|
||||||
INFO("Added %i cheat codes\n", list.size());
|
INFO("Added %i cheat codes\n", list.size());
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
|
@ -83,6 +83,8 @@ public:
|
||||||
virtual int fgetc() = 0;
|
virtual int fgetc() = 0;
|
||||||
virtual int fputc(int c) = 0;
|
virtual int fputc(int c) = 0;
|
||||||
|
|
||||||
|
virtual char* fgets(char* str, int num) = 0;
|
||||||
|
|
||||||
virtual size_t _fread(const void *ptr, size_t bytes) = 0;
|
virtual size_t _fread(const void *ptr, size_t bytes) = 0;
|
||||||
virtual size_t fwrite(const void *ptr, size_t bytes) = 0;
|
virtual size_t fwrite(const void *ptr, size_t bytes) = 0;
|
||||||
|
|
||||||
|
@ -234,6 +236,11 @@ public:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual char* fgets(char* str, int num)
|
||||||
|
{
|
||||||
|
throw "Not tested: emufile memory fgets";
|
||||||
|
}
|
||||||
|
|
||||||
virtual size_t _fread(const void *ptr, size_t bytes);
|
virtual size_t _fread(const void *ptr, size_t bytes);
|
||||||
virtual size_t fwrite(const void *ptr, size_t bytes){
|
virtual size_t fwrite(const void *ptr, size_t bytes){
|
||||||
reserve(pos+(s32)bytes);
|
reserve(pos+(s32)bytes);
|
||||||
|
@ -335,6 +342,10 @@ public:
|
||||||
return ::fputc(c, fp);
|
return ::fputc(c, fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual char* fgets(char* str, int num) {
|
||||||
|
return ::fgets(str, num, fp);
|
||||||
|
}
|
||||||
|
|
||||||
virtual size_t _fread(const void *ptr, size_t bytes);
|
virtual size_t _fread(const void *ptr, size_t bytes);
|
||||||
virtual size_t fwrite(const void *ptr, size_t bytes);
|
virtual size_t fwrite(const void *ptr, size_t bytes);
|
||||||
|
|
||||||
|
|
|
@ -1044,13 +1044,12 @@ bool savestate_save (const char *file_name)
|
||||||
if (!savestate_save(ms))
|
if (!savestate_save(ms))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
FILE* file = fopen(file_name,"wb");
|
EMUFILE_FILE file(file_name, "wb");
|
||||||
if(file)
|
if(file.fail())
|
||||||
{
|
return false;
|
||||||
elems_written = fwrite(ms.buf(),1,ms.size(),file);
|
|
||||||
fclose(file);
|
file.fwrite(ms.buf(), ms.size());
|
||||||
return (elems_written == ms.size());
|
return true;
|
||||||
} else return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wifi_savestate(EMUFILE &os)
|
static void wifi_savestate(EMUFILE &os)
|
||||||
|
|
Loading…
Reference in New Issue