From 842a1e40a8a9d2a20a4686528a023517d5b151db Mon Sep 17 00:00:00 2001 From: gocha Date: Fri, 6 May 2011 14:46:10 +0900 Subject: [PATCH] win32: fix snapshot load (Unicode) --- win32/_tfwopen.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++ win32/_tfwopen.h | 32 ++++++++++++++++++++++- win32/snes9xw.vcproj | 10 ++++---- win32/wsnes9x.cpp | 1 + 4 files changed, 98 insertions(+), 6 deletions(-) diff --git a/win32/_tfwopen.cpp b/win32/_tfwopen.cpp index 6cb86a2b..537b3c7f 100644 --- a/win32/_tfwopen.cpp +++ b/win32/_tfwopen.cpp @@ -203,4 +203,65 @@ extern "C" int _twremove(const char *filename ) { return _wremove(Utf8ToWide(filename)); } +extern "C" int _twopen(const char *filename, int oflag, int pmode) { + return _wopen(Utf8ToWide(filename), oflag, pmode); +} + +extern "C" int _twaccess(const char *_Filename, int _AccessMode) { + return _waccess(Utf8ToWide(_Filename), _AccessMode); +} + +extern "C" int _twrename(const char *_OldFilename, const char *_NewFilename) { + return _wrename(Utf8ToWide(_OldFilename), Utf8ToWide(_NewFilename)); +} + +extern "C" int _twunlink(const char *_Filename) { + return _wunlink(Utf8ToWide(_Filename)); +} + +extern "C" int _twchdir(const char *_Path) { + return _wchdir(Utf8ToWide(_Path)); +} + +extern "C" int _twmkdir(const char *_Path) { + return _wmkdir(Utf8ToWide(_Path)); +} + +extern "C" int _twrmdir(const char *_Path) { + return _wrmdir(Utf8ToWide(_Path)); +} + +extern "C" void _twsplitpath(const char *_FullPath, char *_Drive, char *_Dir, char *_Filename, char *_Ext) { + wchar_t _wDrive[_MAX_PATH]; + wchar_t _wDir[_MAX_PATH]; + wchar_t _wFilename[_MAX_PATH]; + wchar_t _wExt[_MAX_PATH]; + _wsplitpath(Utf8ToWide(_FullPath), _wDrive, _wDir, _wFilename, _wExt); + strcpy(_Drive, WideToUtf8(_wDrive)); + strcpy(_Dir, WideToUtf8(_wDir)); + strcpy(_Filename, WideToUtf8(_wFilename)); + strcpy(_Ext, WideToUtf8(_wExt)); +} + +extern "C" void _twmakepath(char *_Path, const char *_Drive, const char *_Dir, const char *_Filename, const char *_Ext) { + wchar_t wResultPath[_MAX_PATH]; + wcscpy(wResultPath, L""); + _wmakepath(wResultPath, Utf8ToWide(_Drive), Utf8ToWide(_Dir), Utf8ToWide(_Filename), Utf8ToWide(_Ext)); + strcpy(_Path, WideToUtf8(wResultPath)); +} + +extern "C" char *_twcsrchr(const char *_Str, int _Ch) { + wchar_t *wStr = Utf8ToWide(_Str); + wchar_t *wResult = wcsrchr(wStr, (wchar_t) _Ch); + if (wResult != NULL) + { + wResult[0] = L'\0'; + return (char*) &_Str[strlen(WideToUtf8(wResult))]; + } + else + { + return NULL; + } +} + #endif // UNICODE diff --git a/win32/_tfwopen.h b/win32/_tfwopen.h index 23dce67d..05ca1174 100644 --- a/win32/_tfwopen.h +++ b/win32/_tfwopen.h @@ -181,6 +181,9 @@ #define _TFWOPEN_H #include +#include +#include +#include #ifdef __cplusplus extern "C" { @@ -188,6 +191,16 @@ extern "C" { FILE *_tfwopen(const char *filename, const char *mode ); int _twremove(const char *filename ); +int _twopen(const char *filename, int oflag, int pmode); +int _twaccess(const char *_Filename, int _AccessMode); +int _twrename(const char *_OldFilename, const char *_NewFilename); +int _twunlink(const char *_Filename); +int _twchdir(const char *_Path); +int _twmkdir(const char *_Path); +int _twrmdir(const char *_Path); +void _twsplitpath(const char *_FullPath, char *_Drive, char *_Dir, char *_Filename, char *_Ext); +void _twmakepath(char *_Path, const char *_Drive, const char *_Dir, const char *_Filename, const char *_Ext); +char *_twcsrchr(const char *_Str, int _Ch); #ifdef __cplusplus } @@ -256,7 +269,24 @@ public: #endif // __cplusplus #define fopen _tfwopen -#define remove _twremove +#undef remove +__inline int remove(const char *filename) { + return _twremove(filename); +} +#undef open +__inline int open(const char *filename, int oflag, int pmode) { + return _twopen(filename, oflag, pmode); +} +#define _access _twaccess +#define _rename _twrename +#define _unlink _twunlink +#define _chdir _twchdir +#define _mkdir _twmkdir +#define _rmdir _twrmdir +#define _splitpath _twsplitpath +#define _makepath _twmakepath +//#define strrchr _twcsrchr + #endif // _TFWOPEN_H #endif diff --git a/win32/snes9xw.vcproj b/win32/snes9xw.vcproj index 4b5bda35..3db6257f 100644 --- a/win32/snes9xw.vcproj +++ b/win32/snes9xw.vcproj @@ -1,7 +1,7 @@