]> git.mxchange.org Git - flightgear.git/commitdiff
Abstraction for the user's desktop location.
authorJames Turner <zakalawe@mac.com>
Sat, 4 May 2013 09:58:22 +0000 (10:58 +0100)
committerJames Turner <zakalawe@mac.com>
Sun, 9 Jun 2013 22:00:09 +0000 (23:00 +0100)
src/GUI/gui_funcs.cxx
src/Main/fg_init.cxx
src/Main/fg_init.hxx

index a68ce578a7e595ba11c34afc4c9989e0db95df80..1f78d45046767d62a56c0e25ecced56f8ed3f9e0 100644 (file)
@@ -52,6 +52,7 @@
 #include <Cockpit/panel.hxx>
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
+#include <Main/fg_init.hxx> // for platformDesktopPath
 #include <Main/fg_os.hxx>
 #include <Viewer/renderer.hxx>
 #include <Viewer/viewmgr.hxx>
@@ -480,7 +481,7 @@ namespace
 
             string dir = fgGetString("/sim/paths/screenshot-dir");
             if (dir.empty())
-                dir = fgGetString("/sim/fg-current");
+              dir = platformDesktopPath().str();
 
             _path.set(dir + '/');
             if (_path.create_dir( 0755 )) {
index 486fbdd407307a2c6bf0997e878b101b1c0c5fdf..ec76fe987127135fdfb21145755eddc38db0b63f 100644 (file)
@@ -366,6 +366,34 @@ static SGPath platformDefaultDataPath()
   config.append( "flightgear.org" );
   return config;
 }
+
+SGPath platformDesktopPath()
+{  
+    /*
+  typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPWSTR, int, BOOL);
+  static GetSpecialFolderPath SHGetSpecialFolderPath = NULL;
+
+  // lazy open+resolve of shell32
+  if (!SHGetSpecialFolderPath) {
+    HINSTANCE shellDll = ::LoadLibrary("shell32");
+    SHGetSpecialFolderPath = (GetSpecialFolderPath) GetProcAddress(shellDll, "SHGetSpecialFolderPathA");
+  }
+  
+  if (!SHGetSpecialFolderPath)
+    return SGPath();
+  
+  char path[PATH_MAX];
+  if (SHGetSpecialFolderPath(0, path, CSIDL_DESKTOPDIRECTORY, false)) {
+    return SGPath(path);
+  }
+  
+  // failed, bad
+  return SGPath();
+    */
+    
+    return SGPath(fgGetString("/sim/fg-current"));
+}
+
 #elif __APPLE__
 
 #include <CoreServices/CoreServices.h>
@@ -388,6 +416,23 @@ static SGPath platformDefaultDataPath()
   appData.append("FlightGear");
   return appData;
 }
+
+SGPath platformDesktopPath()
+{
+  FSRef ref;
+  OSErr err = FSFindFolder(kUserDomain, kDesktopFolderType, false, &ref);
+  if (err) {
+    return SGPath();
+  }
+  
+  unsigned char path[1024];
+  if (FSRefMakePath(&ref, path, 1024) != noErr) {
+    return SGPath();
+  }
+  
+  return SGPath((const char*) path);
+}
+
 #else
 static SGPath platformDefaultDataPath()
 {
@@ -395,6 +440,13 @@ static SGPath platformDefaultDataPath()
   config.append( ".fgfs" );
   return config;
 }
+
+SGPath platformDesktopPath()
+{
+  SGPath config( getenv("HOME") );
+  config.append( "Desktop" );
+  return config;
+}
 #endif
 
 void fgInitHome()
index b6f7ce2b1dbb763768d1964d5d8e1f5c7fa92471..6341f43520c2e23da627810b5deb816733f73b3d 100644 (file)
 #define _FG_INIT_HXX
 
 #include <string>
+#include <simgear/misc/sg_path.hxx>
 
 // forward decls
 class SGPropertyNode;
-class SGPath;
 
 // Return the current base package version
 std::string fgBasePackageVersion();
@@ -46,6 +46,8 @@ void fgOutputSettings();
 // Initialize the localization
 SGPropertyNode *fgInitLocale(const char *language);
 
+/// retrieve the user's desktop directory path
+SGPath platformDesktopPath();
 
 // Init navaids and waypoints
 bool fgInitNav ();