#include "fg_os.hxx"
+#ifdef _MSC_VER
+char homepath[256] = "";
+char * homedir = homepath;
+char *hostname = ::getenv( "COMPUTERNAME" );
+#else
char *homedir = ::getenv( "HOME" );
char *hostname = ::getenv( "HOSTNAME" );
+#endif
bool free_hostname = false;
// foreward declaration.
// Main entry point; catch any exceptions that have made it this far.
int main ( int argc, char **argv ) {
+#if _MSC_VER
+ // Windows has no $HOME aka %HOME%, so we have to construct the full path.
+ // make sure it fits into the buffer. Max. path length is 255, but who knows
+ // what's in these environment variables?
+ homepath[sizeof(homepath)-1] = 0;
+ strncpy( homepath, ::getenv("APPDATA"), sizeof(homepath)-1 );
+ strncat( homepath, "\\flightgear.org", sizeof(homepath)-strlen(homepath)-1 );
+#endif
#ifdef PTW32_STATIC_LIB
// Initialise static pthread win32 lib
if (hostname == NULL)
{
char _hostname[256];
- gethostname(_hostname, 256);
- hostname = strdup(_hostname);
- free_hostname = true;
+ if( gethostname(_hostname, 256) >= 0 ) {
+ hostname = strdup(_hostname);
+ free_hostname = true;
+ }
}
SG_LOG(SG_GENERAL, SG_INFO, "Scanning command line for: " << option );
static string fgScanForOption( const string& option ) {
string arg("");
-#if defined( unix ) || defined( __CYGWIN__ )
+#if defined( unix ) || defined( __CYGWIN__ ) || defined(_MSC_VER)
// Next check home directory for .fgfsrc.hostname file
if ( arg.empty() ) {
- if ( homedir != NULL ) {
+ if ( homedir != NULL && hostname != NULL && strlen(hostname) > 0) {
SGPath config( homedir );
config.append( ".fgfsrc" );
config.concat( "." );
config.append( "system.fgfsrc" );
fgParseOptions(config.str());
-#if defined( unix ) || defined( __CYGWIN__ )
- config.concat( "." );
- config.concat( hostname );
- fgParseOptions(config.str());
+#if defined( unix ) || defined( __CYGWIN__ ) || defined(_MSC_VER)
+ if( hostname != NULL && strlen(hostname) > 0 ) {
+ config.concat( "." );
+ config.concat( hostname );
+ fgParseOptions(config.str());
+ }
#endif
// Check for ~/.fgfsrc
fgParseOptions(config.str());
}
-#if defined( unix ) || defined( __CYGWIN__ )
- // Check for ~/.fgfsrc.hostname
- config.concat( "." );
- config.concat( hostname );
- fgParseOptions(config.str());
+#if defined( unix ) || defined( __CYGWIN__ ) || defined(_MSC_VER)
+ if( hostname != NULL && strlen(hostname) > 0 ) {
+ // Check for ~/.fgfsrc.hostname
+ config.concat( "." );
+ config.concat( hostname );
+ fgParseOptions(config.str());
+ }
#endif
// Parse remaining command line options
SGPropertyNode root;
try {
readProperties(path.str(), &root);
- } catch (sg_exception& e) {
+ } catch (sg_exception& ) {
return false;
}