Commit 9c200ea0b561c6ac9b63d09709c5878fd6411af6

Authored by dg
1 parent 14ce2042

Fix loading saves on windows when the user has unicode in his windows username

git-svn-id: http://svn.net-core.org/repos/t-engine4@2641 51575b47-30f0-44d4-a5cc-537603b46e54
Showing 1 changed file with 35 additions and 1 deletions
... ... @@ -123,6 +123,7 @@ static HANDLE (WINAPI *pFindFirstFileW)(LPCWSTR, LPWIN32_FIND_DATAW);
123 123 static BOOL (WINAPI *pFindNextFileW)(HANDLE, LPWIN32_FIND_DATAW);
124 124 static DWORD (WINAPI *pGetCurrentDirectoryW)(DWORD, LPWSTR);
125 125 static BOOL (WINAPI *pDeleteFileW)(LPCWSTR);
  126 +static BOOL (WINAPI *pMoveFileW)(LPCWSTR,LPCWSTR);
126 127 static BOOL (WINAPI *pRemoveDirectoryW)(LPCWSTR);
127 128 static BOOL (WINAPI *pCreateDirectoryW)(LPCWSTR, LPSECURITY_ATTRIBUTES);
128 129 static BOOL (WINAPI *pGetFileAttributesExA)
... ... @@ -216,6 +217,25 @@ static BOOL WINAPI fallbackRemoveDirectoryW(LPCWSTR dname)
216 217 return(retval);
217 218 } /* fallbackRemoveDirectoryW */
218 219
  220 +static BOOL WINAPI fallbackMoveFileW(LPCWSTR fname1, LPCWSTR fname2)
  221 +{
  222 + BOOL retval = 0;
  223 +
  224 + const int buflen1 = (int) (wStrLen(fname1) + 1);
  225 + char *cpstr1 = (char *) __PHYSFS_smallAlloc(buflen1);
  226 + WideCharToMultiByte(CP_ACP, 0, fname1, buflen1, cpstr1, buflen1, NULL, NULL);
  227 +
  228 + const int buflen2 = (int) (wStrLen(fname2) + 1);
  229 + char *cpstr2 = (char *) __PHYSFS_smallAlloc(buflen2);
  230 + WideCharToMultiByte(CP_ACP, 0, fname2, buflen2, cpstr2, buflen2, NULL, NULL);
  231 +
  232 + retval = MoveFile(cpstr1, cpstr2);
  233 +
  234 + __PHYSFS_smallFree(cpstr1);
  235 + __PHYSFS_smallFree(cpstr2);
  236 + return(retval);
  237 +} /* fallbackRemoveDirectoryW */
  238 +
219 239 static BOOL WINAPI fallbackCreateDirectoryW(LPCWSTR dname,
220 240 LPSECURITY_ATTRIBUTES attr)
221 241 {
... ... @@ -313,6 +333,7 @@ static int findApiSymbols(void)
313 333 LOOKUP(RemoveDirectoryW, osHasUnicode);
314 334 LOOKUP(CreateFileW, osHasUnicode);
315 335 LOOKUP(DeleteFileW, osHasUnicode);
  336 + LOOKUP(MoveFileW, osHasUnicode);
316 337 } /* if */
317 338
318 339 #undef LOOKUP_NOFALLBACK
... ... @@ -982,7 +1003,20 @@ int __PHYSFS_platformDeinit(void)
982 1003
983 1004 int __PHYSFS_platformRename(const char *filename1, const char *filename2)
984 1005 {
985   - return MoveFile(filename1, filename2);
  1006 + WCHAR *wfname1, *wfname2;
  1007 +
  1008 + UTF8_TO_UNICODE_STACK_MACRO(wfname1, filename1);
  1009 + BAIL_IF_MACRO(wfname1 == NULL, ERR_OUT_OF_MEMORY, NULL);
  1010 +
  1011 + UTF8_TO_UNICODE_STACK_MACRO(wfname2, filename2);
  1012 + BAIL_IF_MACRO(wfname2 == NULL, ERR_OUT_OF_MEMORY, NULL);
  1013 +
  1014 + BOOL ret = pMoveFileW(wfname1, wfname2);
  1015 +
  1016 + __PHYSFS_smallFree(wfname1);
  1017 + __PHYSFS_smallFree(wfname2);
  1018 +
  1019 + return ret;
986 1020 } /* __PHYSFS_platformRename */
987 1021
988 1022 static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly)
... ...