Author: cazfi
Date: Tue Jul  5 08:50:24 2016
New Revision: 33166

URL: http://svn.gna.org/viewcvs/freeciv?rev=33166&view=rev
Log:
Prefer Windows-specific home dir detection over using $HOME.

See patch #7378

Modified:
    trunk/utility/shared.c

Modified: trunk/utility/shared.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/shared.c?rev=33166&r1=33165&r2=33166&view=diff
==============================================================================
--- trunk/utility/shared.c      (original)
+++ trunk/utility/shared.c      Tue Jul  5 08:50:24 2016
@@ -560,64 +560,65 @@
 #else  /* AMIGA */
 
   if (home_dir_user == NULL) {
-    char *env = getenv("HOME");
-
-    if (env) {
-      home_dir_user = fc_strdup(env);
-      log_verbose("HOME is %s", home_dir_user);
-    } else {
-
 #ifdef FREECIV_MSWINDOWS
 
-      /* some documentation at:
-       * 
http://justcheckingonall.wordpress.com/2008/05/16/find-shell-folders-win32/
-       * http://archives.seul.org/or/cvs/Oct-2004/msg00082.html */
-
-      LPITEMIDLIST pidl;
-      LPMALLOC pMalloc;
-
-      if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidl))) {
-
-        char *home_dir_in_local_encoding = fc_malloc(PATH_MAX);
-
-        if (SUCCEEDED(SHGetPathFromIDList(pidl, home_dir_in_local_encoding))) {
-          /* convert to internal encoding */
-          home_dir_user = 
local_to_internal_string_malloc(home_dir_in_local_encoding);
-          free(home_dir_in_local_encoding);
+    /* some documentation at:
+     * 
http://justcheckingonall.wordpress.com/2008/05/16/find-shell-folders-win32/
+     * http://archives.seul.org/or/cvs/Oct-2004/msg00082.html */
+
+    LPITEMIDLIST pidl;
+    LPMALLOC pMalloc;
+
+    if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidl))) {
+      char *home_dir_in_local_encoding = fc_malloc(PATH_MAX);
+
+      if (SUCCEEDED(SHGetPathFromIDList(pidl, home_dir_in_local_encoding))) {
+        /* convert to internal encoding */
+        home_dir_user = 
local_to_internal_string_malloc(home_dir_in_local_encoding);
+        free(home_dir_in_local_encoding);
 
 #ifdef DIR_SEPARATOR_IS_DEFAULT
-          /* replace backslashes with forward slashes */
-          {
-            char *c;
-
-            for (c = home_dir_user; *c != 0; c++) {
-              if (*c == '\\') {
-                *c = DIR_SEPARATOR_CHAR;
-              }
+        /* replace backslashes with forward slashes */
+        {
+          char *c;
+
+          for (c = home_dir_user; *c != 0; c++) {
+            if (*c == '\\') {
+              *c = DIR_SEPARATOR_CHAR;
             }
           }
+        }
 #endif /* DIR_SEPARATOR_IS_DEFAULT */
-        } else {
-          free(home_dir_in_local_encoding);
-          home_dir_user = NULL;
-          log_error("Could not find home directory "
-                    "(SHGetPathFromIDList() failed).");
-        }
-
-        SHGetMalloc(&pMalloc);
-        if (pMalloc) {
-          pMalloc->lpVtbl->Free(pMalloc, pidl);
-          pMalloc->lpVtbl->Release(pMalloc);
-        }
-
       } else {
+        free(home_dir_in_local_encoding);
+        home_dir_user = NULL;
         log_error("Could not find home directory "
-                  "(SHGetSpecialFolderLocation() failed).");
-      }
-#else  /* FREECIV_MSWINDOWS */
-      log_error("Could not find home directory (HOME is not set).");
-      home_dir_user = NULL;
+                  "(SHGetPathFromIDList() failed).");
+      }
+
+      SHGetMalloc(&pMalloc);
+      if (pMalloc) {
+        pMalloc->lpVtbl->Free(pMalloc, pidl);
+        pMalloc->lpVtbl->Release(pMalloc);
+      }
+
+    } else {
+      log_error("Could not find home directory "
+                "(SHGetSpecialFolderLocation() failed).");
+    }
+
+    if (home_dir_user == NULL)
 #endif /* FREECIV_MSWINDOWS */
+    {
+      char *env = getenv("HOME");
+
+      if (env) {
+        home_dir_user = fc_strdup(env);
+        log_verbose("HOME is %s", home_dir_user);
+      } else {
+        log_error("Could not find home directory (HOME is not set).");
+        home_dir_user = NULL;
+      }
     }
   }
 


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to