Logging to file now happens earlier, so some useful early output is captured.
int _bootstrap_OSInit;
// Main entry point; catch any exceptions that have made it this far.
-int main ( int argc, char **argv ) {
+int main ( int argc, char **argv )
+{
#if _MSC_VER
// Don't show blocking "no disk in drive" error messages on Windows 7,
// silently return errors to application instead.
// See Microsoft MSDN #ms680621: "GUI apps should specify SEM_NOOPENFILEERRORBOX"
SetErrorMode(SEM_NOOPENFILEERRORBOX);
- // Windows has no $HOME aka %HOME%, so we have to construct the full path.
- homedir = ::getenv("APPDATA");
- homedir.append("\\flightgear.org");
-
hostname = ::getenv( "COMPUTERNAME" );
#else
// Unix(alike) systems
char _hostname[256];
gethostname(_hostname, 256);
hostname = _hostname;
-
- homedir = ::getenv( "HOME" );
-
+
signal(SIGPIPE, SIG_IGN);
#endif
#else
static SGPath platformDefaultDataPath()
{
- SGPath config( homedir );
+ SGPath config( getenv("HOME") );
config.append( ".fgfs" );
return config;
}
#endif
-// Read in configuration (file and command line)
-bool fgInitConfig ( int argc, char **argv )
+void fgInitHome()
{
SGPath dataPath = platformDefaultDataPath();
-
const char *fg_home = getenv("FG_HOME");
if (fg_home)
- dataPath = fg_home;
-
- globals->set_fg_home(dataPath.c_str());
+ dataPath = fg_home;
+ globals->set_fg_home(dataPath.c_str());
+}
+
+// Read in configuration (file and command line)
+bool fgInitConfig ( int argc, char **argv )
+{
+ SGPath dataPath = globals->get_fg_home();
simgear::Dir exportDir(simgear::Dir(dataPath).file("Export"));
if (!exportDir.exists()) {
exportDir.create(0777);
// Return the current base package version
std::string fgBasePackageVersion();
+void fgInitHome();
// Read in configuration (file and command line)
bool fgInitConfig ( int argc, char **argv );
globals->get_renderer()->addCamera(hackCam, false);
}
+
+static void logToFile()
+{
+ SGPath logPath = globals->get_fg_home();
+ logPath.append("fgfs.log");
+ if (logPath.exists()) {
+ SGPath prevLogPath = globals->get_fg_home();
+ prevLogPath.append("fgfs_0.log");
+ logPath.rename(prevLogPath);
+ // bit strange, we need to restore the correct value of logPath now
+ logPath = globals->get_fg_home();
+ logPath.append("fgfs.log");
+ }
+ sglog().logToFile(logPath, SG_ALL, SG_INFO);
+}
+
// Main top level initialization
int fgMainInit( int argc, char **argv ) {
// set default log levels
sglog().setLogLevels( SG_ALL, SG_ALERT );
+ globals = new FGGlobals;
+ fgInitHome();
+
+ // now home is initialised, we can log to a file inside it
+ logToFile();
+
string version;
#ifdef FLIGHTGEAR_VERSION
version = FLIGHTGEAR_VERSION;
// Allocate global data structures. This needs to happen before
// we parse command line options
- globals = new FGGlobals;
-
+
+
// seed the random number generator
sg_srandom_time();
SG_LOG( SG_GENERAL, SG_ALERT, "Config option parsing failed ..." );
exit(-1);
}
-
- SGPath logPath = globals->get_fg_home();
- logPath.append("fgfs.log");
- if (logPath.exists()) {
- SGPath prevLogPath = globals->get_fg_home();
- prevLogPath.append("fgfs_0.log");
- logPath.rename(prevLogPath);
- // bit strange, we need to restore the correct value of logPath now
- logPath = globals->get_fg_home();
- logPath.append("fgfs.log");
- }
- sglog().logToFile(logPath, SG_ALL, SG_INFO);
// Initialize the Window/Graphics environment.
fgOSInit(&argc, argv);
int fgMainInit( int argc, char **argv );
-extern std::string homedir;
extern std::string hostname;
#endif
// then config files
SGPath config;
+ std::string homedir(getenv("HOME"));
+
if( homedir.size() && hostname.size() ) {
// Check for ~/.fgfsrc.hostname
config.set(homedir);