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)
set(EVENT_INPUT_DEFAULT 1)
find_library(CORESERVICES_LIBRARY CoreServices)
list(APPEND PLATFORM_LIBS ${CORESERVICES_LIBRARY})
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
# disabled while DBus / HAL / udev issues are decided
#set(EVENT_INPUT_DEFAULT 1)

View file

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

View file

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

View file

@ -451,6 +451,43 @@ private:
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)
bool fgInitConfig ( int argc, char **argv ) {
@ -467,42 +504,34 @@ bool fgInitConfig ( int argc, char **argv ) {
}
SGPropertyNode autosave;
#ifdef _WIN32
char *envp = ::getenv( "APPDATA" );
if (envp != NULL ) {
SGPath config( envp );
config.append( "flightgear.org" );
#else
if ( homedir != NULL ) {
SGPath config( homedir );
config.append( ".fgfs" );
#endif
const char *fg_home = getenv("FG_HOME");
if (fg_home)
config = fg_home;
SGPath dataPath = platformDefaultDataPath();
const char *fg_home = getenv("FG_HOME");
if (fg_home)
dataPath = fg_home;
simgear::Dir exportDir(simgear::Dir(dataPath).file("Export"));
if (!exportDir.exists()) {
exportDir.create(0777);
}
SGPath home_export(config.str());
home_export.append("Export/dummy");
home_export.create_dir(0777);
// Set /sim/fg-home and don't allow malign code to override it until
// Nasal security is set up. Use FG_HOME if necessary.
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
// Nasal security is set up. Use FG_HOME if necessary.
SGPropertyNode *home = fgGetNode("/sim", true);
home->removeChild("fg-home", 0, false);
home = home->getChild("fg-home", 0, true);
home->setStringValue(config.c_str());
home->setAttribute(SGPropertyNode::WRITE, false);
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() << ")");
}
}
SGPath autosaveFile = simgear::Dir(dataPath).file("autosave.xml");
if (autosaveFile.exists()) {
SG_LOG(SG_INPUT, SG_INFO, "Reading user settings from " << autosaveFile.str());
try {
readProperties(autosaveFile.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.