Просмотр исходного кода

Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().

Ryan C. Gordon 14 лет назад
Родитель
Сommit
43367c0c29
2 измененных файлов с 24 добавлено и 8 удалено
  1. 1 3
      src/physfs.c
  2. 23 5
      src/platform_windows.c

+ 1 - 3
src/physfs.c

@@ -1380,8 +1380,8 @@ void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback callback, void *data)
 const char *PHYSFS_getPrefDir(const char *org, const char *app)
 {
     const char dirsep = __PHYSFS_platformDirSeparator;
-    char *ptr = NULL;
     PHYSFS_Stat statbuf;
+    char *ptr = NULL;
     int exists = 0;
 
     BAIL_IF_MACRO(!initialized, PHYSFS_ERR_NOT_INITIALIZED, 0);
@@ -1394,7 +1394,6 @@ const char *PHYSFS_getPrefDir(const char *org, const char *app)
     prefDir = __PHYSFS_platformCalcPrefDir(org, app);
     BAIL_IF_MACRO(!prefDir, ERRPASS, NULL);
 
-    #if !PHYSFS_PLATFORM_WINDOWS  /* Windows guarantees the dir exists here. */
     if (__PHYSFS_platformStat(prefDir, &exists, &statbuf))
         return prefDir;
 
@@ -1410,7 +1409,6 @@ const char *PHYSFS_getPrefDir(const char *org, const char *app)
         allocator.Free(prefDir);
         prefDir = NULL;
     } /* if */
-    #endif
 
     return prefDir;
 } /* PHYSFS_getPrefDir */

+ 23 - 5
src/platform_windows.c

@@ -443,17 +443,35 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0)
 
 char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app)
 {
-    // Vista and later has a new API for this, but SHGetFolderPath works there,
-    //  and apparently just wraps the new API. This is the new way to do it:
-    // SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_CREATE,
-    //                      NULL, &wszPath);
+    /*
+     * Vista and later has a new API for this, but SHGetFolderPath works there,
+     *  and apparently just wraps the new API. This is the new way to do it:
+     *
+     *     SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_CREATE,
+     *                          NULL, &wszPath);
+     */
 
     WCHAR path[MAX_PATH];
+    char *utf8 = NULL;
+    size_t len = 0;
+    char *retval = NULL;
+
     if (!SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
                                    NULL, 0, path)))
         BAIL_MACRO(PHYSFS_ERR_OS_ERROR, NULL);
 
-    return unicodeToUtf8Heap(path);
+    utf8 = unicodeToUtf8Heap(path);
+    BAIL_IF_MACRO(!utf8, ERRPASS, NULL);
+    len = strlen(utf8) + strlen(org) + strlen(app) + 3;
+    retval = allocator.Malloc(len);
+    if (!retval)
+    {
+        allocator.Free(utf8);
+        BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL);
+    } /* if */
+
+    sprintf(retval, "%s\\%s\\%s", utf8, org, app);
+    return retval;
 } /* __PHYSFS_platformCalcPrefDir */