]> git.mxchange.org Git - flightgear.git/commitdiff
Refactor FG_HOME init, so we can log sooner.
authorJames Turner <zakalawe@mac.com>
Fri, 8 Feb 2013 11:43:51 +0000 (11:43 +0000)
committerJames Turner <zakalawe@mac.com>
Fri, 8 Feb 2013 12:57:17 +0000 (12:57 +0000)
Logging to file now happens earlier, so some useful early output is captured.

src/Main/bootstrap.cxx
src/Main/fg_init.cxx
src/Main/fg_init.hxx
src/Main/main.cxx
src/Main/main.hxx
src/Main/options.cxx

index 4eff67b5b551b7005927a0879b8d95d0c835b570..a4425c76ab0ed76d08d561e47d18ffd9d855db2d 100644 (file)
@@ -163,26 +163,21 @@ static void fg_terminate() {
 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
 
index 755484f34ead3f5172394ca281f9b087e9fb3575..5e91d5ec94d036be92ec91389227304eb64919d7 100644 (file)
@@ -390,23 +390,26 @@ static SGPath platformDefaultDataPath()
 #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);
index f5215bb723691eaeafbd4821fe62e80ed8d3a724..f79a6f5313fc5f69872a2a477ef9e1d4912580e4 100644 (file)
@@ -34,6 +34,7 @@ class SGPath;
 // Return the current base package version
 std::string fgBasePackageVersion();
 
+void fgInitHome();
 
 // Read in configuration (file and command line)
 bool fgInitConfig ( int argc, char **argv );
index e1b98d3c3febe0a591b285b2c1da5bbf5f1a4821..1f885e7c26fb21517dc9beb050c6ecc1d55b6485 100644 (file)
@@ -273,12 +273,34 @@ static void ATIScreenSizeHack()
     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;
@@ -292,8 +314,8 @@ int fgMainInit( int argc, char **argv ) {
     // 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();
 
@@ -313,18 +335,6 @@ int fgMainInit( int argc, char **argv ) {
       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);
index 145feacf1da0f3f8d1adde10998faf4b9fb09e10..7cea8baaf4fe9d62f202e08cb0e693562c409755 100644 (file)
@@ -23,7 +23,6 @@
 
 int fgMainInit( int argc, char **argv );
 
-extern std::string homedir;
 extern std::string hostname;
 
 #endif
index 7187431449b6eba72436cdd9839d8d66c52e005f..365eb415893cc67e8879e7e09d308a88d5ea5fbe 100644 (file)
@@ -1745,6 +1745,8 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath)
 // then config files
   SGPath config;
   
+  std::string homedir(getenv("HOME"));
+    
   if( homedir.size() && hostname.size() ) {
     // Check for ~/.fgfsrc.hostname
     config.set(homedir);