Refactor FG_HOME init, so we can log sooner.
Logging to file now happens earlier, so some useful early output is captured.
This commit is contained in:
parent
7cc3ffb30f
commit
9ccf159f81
6 changed files with 42 additions and 32 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -390,23 +390,26 @@ static SGPath platformDefaultDataPath()
|
|||
#else
|
||||
static SGPath platformDefaultDataPath()
|
||||
{
|
||||
SGPath config( homedir );
|
||||
SGPath config( getenv("HOME") );
|
||||
config.append( ".fgfs" );
|
||||
return config;
|
||||
}
|
||||
#endif
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
// Read in configuration (file and command line)
|
||||
bool fgInitConfig ( int argc, char **argv )
|
||||
{
|
||||
SGPath dataPath = platformDefaultDataPath();
|
||||
|
||||
const char *fg_home = getenv("FG_HOME");
|
||||
if (fg_home)
|
||||
dataPath = fg_home;
|
||||
|
||||
globals->set_fg_home(dataPath.c_str());
|
||||
|
||||
SGPath dataPath = globals->get_fg_home();
|
||||
simgear::Dir exportDir(simgear::Dir(dataPath).file("Export"));
|
||||
if (!exportDir.exists()) {
|
||||
exportDir.create(0777);
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
int fgMainInit( int argc, char **argv );
|
||||
|
||||
extern std::string homedir;
|
||||
extern std::string hostname;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue