1
0
Fork 0

Refactor fg-home computation, use Library/Application Support on Mac.

This commit is contained in:
James Turner 2011-10-16 19:55:04 +01:00
parent 0431822e2a
commit 6adb42078e
4 changed files with 79 additions and 54 deletions

View file

@ -51,6 +51,10 @@ endif()
IF(APPLE) IF(APPLE)
set(EVENT_INPUT_DEFAULT 1) set(EVENT_INPUT_DEFAULT 1)
find_library(CORESERVICES_LIBRARY CoreServices)
list(APPEND PLATFORM_LIBS ${CORESERVICES_LIBRARY})
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux") elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
# disabled while DBus / HAL / udev issues are decided # disabled while DBus / HAL / udev issues are decided
#set(EVENT_INPUT_DEFAULT 1) #set(EVENT_INPUT_DEFAULT 1)

View file

@ -80,6 +80,7 @@ target_link_libraries(fgfs
${LIBSVN_LIBRARIES} ${LIBSVN_LIBRARIES}
${HLA_LIBRARIES} ${HLA_LIBRARIES}
${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES}
${PLATFORM_LIBS}
) )
install(TARGETS fgfs RUNTIME DESTINATION bin) install(TARGETS fgfs RUNTIME DESTINATION bin)

View file

@ -191,27 +191,18 @@ do_exit (const SGPropertyNode * arg)
fgSetBool("/sim/signals/exit", true); fgSetBool("/sim/signals/exit", true);
if (fgGetBool("/sim/startup/save-on-exit")) { if (fgGetBool("/sim/startup/save-on-exit")) {
#ifdef _WIN32 SGPath autosaveFile(fgGetString("/sim/fg-home"));
char* envp = ::getenv( "APPDATA" ); autosaveFile.append( "autosave.xml" );
if ( envp != NULL ) { autosaveFile.create_dir( 0700 );
SGPath config( envp ); SG_LOG(SG_IO, SG_INFO, "Saving user settings to " << autosaveFile.str());
config.append( "flightgear.org" ); try {
#else writeProperties(autosaveFile.str(), globals->get_props(), false, SGPropertyNode::USERARCHIVE);
if ( homedir != NULL ) { } catch (const sg_exception &e) {
SGPath config( homedir ); guiErrorMessage("Error writing autosave.xml: ", e);
config.append( ".fgfs" ); }
#endif
config.append( "autosave.xml" ); SG_LOG(SG_INPUT, SG_DEBUG, "Finished Saving user settings");
config.create_dir( 0700 );
SG_LOG(SG_IO, SG_INFO, "Saving user settings to " << config.str());
try {
writeProperties(config.str(), globals->get_props(), false, SGPropertyNode::USERARCHIVE);
} catch (const sg_exception &e) {
guiErrorMessage("Error writing autosave.xml: ", e);
}
SG_LOG(SG_INPUT, SG_DEBUG, "Finished Saving user settings");
}
} }
fgOSExit(arg->getIntValue("status", 0)); fgOSExit(arg->getIntValue("status", 0));

View file

@ -451,6 +451,43 @@ private:
SGPropertyNode* _cache; SGPropertyNode* _cache;
}; };
#ifdef _WIN32
static SGPath platformDefaultDataPath()
{
char *envp = ::getenv( "APPDATA" );
SGPath config( envp );
config.append( "flightgear.org" );
}
#elif __APPLE__
#include <CoreServices/CoreServices.h>
static SGPath platformDefaultDataPath()
{
FSRef ref;
OSErr err = FSFindFolder(kUserDomain, kApplicationSupportFolderType, false, &ref);
if (err) {
return SGPath();
}
unsigned char path[1024];
if (FSRefMakePath(&ref, path, 1024) != noErr) {
return SGPath();
}
SGPath appData;
appData.set((const char*) path);
appData.append("flightgear.org");
return appData;
}
#else
static SGPath platformDefaultDataPath()
{
SGPath config( homedir );
config.append( ".fgfs" );
}
#endif
// Read in configuration (file and command line) // Read in configuration (file and command line)
bool fgInitConfig ( int argc, char **argv ) { bool fgInitConfig ( int argc, char **argv ) {
@ -467,42 +504,34 @@ bool fgInitConfig ( int argc, char **argv ) {
} }
SGPropertyNode autosave; SGPropertyNode autosave;
#ifdef _WIN32 SGPath dataPath = platformDefaultDataPath();
char *envp = ::getenv( "APPDATA" );
if (envp != NULL ) { const char *fg_home = getenv("FG_HOME");
SGPath config( envp ); if (fg_home)
config.append( "flightgear.org" ); dataPath = fg_home;
#else
if ( homedir != NULL ) { simgear::Dir exportDir(simgear::Dir(dataPath).file("Export"));
SGPath config( homedir ); if (!exportDir.exists()) {
config.append( ".fgfs" ); exportDir.create(0777);
#endif }
const char *fg_home = getenv("FG_HOME");
if (fg_home)
config = fg_home;
SGPath home_export(config.str()); // Set /sim/fg-home and don't allow malign code to override it until
home_export.append("Export/dummy"); // Nasal security is set up. Use FG_HOME if necessary.
home_export.create_dir(0777); SGPropertyNode *home = fgGetNode("/sim", true);
home->removeChild("fg-home", 0, false);
home = home->getChild("fg-home", 0, true);
home->setStringValue(dataPath.c_str());
home->setAttribute(SGPropertyNode::WRITE, false);
// Set /sim/fg-home and don't allow malign code to override it until SGPath autosaveFile = simgear::Dir(dataPath).file("autosave.xml");
// Nasal security is set up. Use FG_HOME if necessary. if (autosaveFile.exists()) {
SGPropertyNode *home = fgGetNode("/sim", true); SG_LOG(SG_INPUT, SG_INFO, "Reading user settings from " << autosaveFile.str());
home->removeChild("fg-home", 0, false); try {
home = home->getChild("fg-home", 0, true); readProperties(autosaveFile.str(), &autosave, SGPropertyNode::USERARCHIVE);
home->setStringValue(config.c_str()); } catch (sg_exception& e) {
home->setAttribute(SGPropertyNode::WRITE, false); SG_LOG(SG_INPUT, SG_WARN, "failed to read user settings:" << e.getMessage()
<< "(from " << e.getOrigin() << ")");
config.append( "autosave.xml" ); }
if (config.exists()) {
SG_LOG(SG_INPUT, SG_INFO, "Reading user settings from " << config.str());
try {
readProperties(config.str(), &autosave, SGPropertyNode::USERARCHIVE);
} catch (sg_exception& e) {
SG_LOG(SG_INPUT, SG_WARN, "failed to read user settings:" << e.getMessage()
<< "(from " << e.getOrigin() << ")");
}
}
} }
// Scan user config files and command line for a specified aircraft. // Scan user config files and command line for a specified aircraft.