]> git.mxchange.org Git - flightgear.git/commitdiff
Under Windows, set fg-home to My Documents, or whatever localized name this folder...
authorfredb <fredb>
Sat, 1 Apr 2006 11:07:45 +0000 (11:07 +0000)
committerfredb <fredb>
Sat, 1 Apr 2006 11:07:45 +0000 (11:07 +0000)
src/Main/fg_init.cxx

index 4985fb3e64b378bf111374681878744f95e143be..41886f23822c86fc9b8c1abde05a9e416952e912 100644 (file)
@@ -594,16 +594,36 @@ bool fgInitConfig ( int argc, char **argv ) {
     }
 
 #ifdef _MSC_VER
-    char *envp = ::getenv( "APPDATA" );
+    // Best solution is to set fg-home to My Documents but it requires reading the Windows registry
+    bool fg_home_set = false;
+    HKEY hKey;
+    LONG rc = RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", 0, KEY_QUERY_VALUE, &hKey );
+    if ( rc == ERROR_SUCCESS ) {
+        DWORD vt,bs;
+        rc = RegQueryValueEx( hKey, "Personal", NULL, &vt, NULL, &bs );
+        if ( rc == ERROR_SUCCESS ) {
+            unsigned char *buff = new unsigned char[ bs ];
+            rc = RegQueryValueEx( hKey, "Personal", NULL, &vt, buff, &bs );
+            fgSetString("/sim/fg-home", (char *)buff);
+            fg_home_set = true;
+            delete [] buff;
+        }
+        RegCloseKey( hKey );
+    }
+    char *envp = ::getenv( "APPDATA" ); // APPDATA is for applications and is hidden
     if (envp != NULL ) {
         SGPath config( envp );
         config.append( "flightgear.org" );
+        if ( !fg_home_set ) {
+            fgSetString("/sim/fg-home", config.c_str());
+            fg_home_set = true;
+        }
 #else
     if ( homedir != NULL ) {
         SGPath config( homedir );
         config.append( ".fgfs" );
-#endif
         fgSetString("/sim/fg-home", config.c_str());
+#endif
         config.append( "autosave.xml" );
         SG_LOG(SG_INPUT, SG_INFO, "Reading user settings from autosave.xml");
         try {