From 6d158e886ca230c8a3cea8197229129a8b0660da Mon Sep 17 00:00:00 2001 From: James Turner Date: Sat, 4 May 2013 10:58:22 +0100 Subject: [PATCH] Abstraction for the user's desktop location. --- src/GUI/gui_funcs.cxx | 3 ++- src/Main/fg_init.cxx | 52 +++++++++++++++++++++++++++++++++++++++++++ src/Main/fg_init.hxx | 4 +++- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/GUI/gui_funcs.cxx b/src/GUI/gui_funcs.cxx index a68ce578a..1f78d4504 100644 --- a/src/GUI/gui_funcs.cxx +++ b/src/GUI/gui_funcs.cxx @@ -52,6 +52,7 @@ #include #include
#include
+#include
// for platformDesktopPath #include
#include #include @@ -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 )) { diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 486fbdd40..ec76fe987 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -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 @@ -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() diff --git a/src/Main/fg_init.hxx b/src/Main/fg_init.hxx index b6f7ce2b1..6341f4352 100644 --- a/src/Main/fg_init.hxx +++ b/src/Main/fg_init.hxx @@ -26,10 +26,10 @@ #define _FG_INIT_HXX #include +#include // 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 (); -- 2.39.5