Author: cazfi
Date: Tue Jul  5 08:50:32 2016
New Revision: 33167

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

See patch #7378

Modified:
    branches/S2_6/utility/shared.c

Modified: branches/S2_6/utility/shared.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/utility/shared.c?rev=33167&r1=33166&r2=33167&view=diff
==============================================================================
--- branches/S2_6/utility/shared.c      (original)
+++ branches/S2_6/utility/shared.c      Tue Jul  5 08:50:32 2016
@@ -631,63 +631,65 @@
 #else  /* AMIGA */
 
   if (home_dir == NULL) {
-    char *env = getenv("HOME");
-
-    if (env) {
-      home_dir = fc_strdup(env);
-      log_verbose("HOME is %s", home_dir);
-    } 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 = 
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 = 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; *c != 0; c++) {
-              if (*c == '\\') {
-                *c = DIR_SEPARATOR_CHAR;
-              }
+        /* replace backslashes with forward slashes */
+        {
+          char *c;
+
+          for (c = home_dir; *c != 0; c++) {
+            if (*c == '\\') {
+              *c = DIR_SEPARATOR_CHAR;
             }
           }
+        }
 #endif /* DIR_SEPARATOR_IS_DEFAULT */
-        } else {
-          free(home_dir_in_local_encoding);
-          home_dir = 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 = 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 = 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 == NULL)
 #endif /* FREECIV_MSWINDOWS */
+    {
+      char *env = getenv("HOME");
+
+      if (env) {
+        home_dir = fc_strdup(env);
+        log_verbose("HOME is %s", home_dir);
+      } else {
+        log_error("Could not find home directory (HOME is not set).");
+        home_dir = NULL;
+      }
     }
   }
 


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

Reply via email to