void gamedetect(){
// if we're inside a Nexuiz install
// default to nexuiz.game (unless the user used an option to inhibit this)
- bool nogamedetect = false;
+ //bool nogamedetect = false;
+ bool nogamedetect = true;
int i;
for ( i = 1; i < g_argc - 1; ++i )
{
namespace
{
+ // executable file path
+ CopiedString app_filepath;
+ // directory paths
CopiedString home_path;
CopiedString app_path;
CopiedString lib_path;
CopiedString data_path;
}
+const char* environment_get_app_filepath(){
+ return app_filepath.c_str();
+}
+
const char* environment_get_home_path(){
return home_path.c_str();
}
return app_path.c_str();
}
-
const char *environment_get_lib_path()
{
return lib_path.c_str();
#endif
;
-/// brief Returns the filename of the executable belonging to the current process, or 0 if not found.
+/// brief Returns the filename of the executable belonging to the current process, or empty string if not found.
char const* getexename( char *buf ){
/* Now read the symbolic link */
- int ret = readlink( LINK_NAME, buf, PATH_MAX );
+ const int ret = readlink( LINK_NAME, buf, PATH_MAX );
if ( ret == -1 ) {
globalOutputStream() << "getexename: falling back to argv[0]: " << makeQuoted( g_argv[0] );
- const char* path = realpath( g_argv[0], buf );
- if ( path == 0 ) {
+ if( realpath( g_argv[0], buf ) == 0 ) {
/* In case of an error, leave the handling up to the caller */
- return "";
+ *buf = '\0';
}
}
+ else {
+ /* Ensure proper NUL termination */
+ buf[ret] = 0;
+ }
- /* Ensure proper NUL termination */
- buf[ret] = 0;
+ return buf;
+}
+char const* getexepath( char *buf ) {
/* delete the program name */
*( strrchr( buf, '/' ) ) = '\0';
{
char real[PATH_MAX];
- app_path = getexename( real );
- ASSERT_MESSAGE( !string_empty( app_path.c_str() ), "failed to deduce app path" );
+ app_filepath = getexename( real );
+ ASSERT_MESSAGE( !string_empty( app_filepath.c_str() ), "failed to deduce app path" );
+
+ strncpy( real, app_filepath.c_str(), strlen( app_filepath.c_str() ) );
+ app_path = getexepath( real );
}
{
+#if defined(RADIANT_FHS_INSTALL)
StringOutputStream buffer;
- buffer << app_path.c_str() << "../lib/" << RADIANT_BASENAME << "/";
- if ( file_is_directory( buffer.c_str() ) ) {
- lib_path = buffer.c_str();
- }
- else {
- lib_path = app_path.c_str();
- }
+ #if defined(RADIANT_ADDONS_DIR)
+ buffer << RADIANT_ADDONS_DIR << "/";
+ #else
+ buffer << app_path.c_str() << "../lib/";
+ buffer << RADIANT_LIB_ARCH << "/";
+ buffer << RADIANT_BASENAME << "/";
+ #endif
+ lib_path = buffer.c_str();
+#else
+ lib_path = app_path.c_str();
+#endif
}
{
+#if defined(RADIANT_FHS_INSTALL)
StringOutputStream buffer;
- buffer << app_path.c_str() << "../share/" << RADIANT_BASENAME << "/";
- if ( file_is_directory( buffer.c_str() ) ) {
- data_path = buffer.c_str();
- }
- else {
- data_path = app_path.c_str();
- }
+ #if defined(RADIANT_DATA_DIR)
+ buffer << RADIANT_DATA_DIR << "/";
+ #else
+ buffer << app_path.c_str() << "../share/";
+ buffer << RADIANT_BASENAME << "/";
+ #endif
+ data_path = buffer.c_str();
+#else
+ data_path = app_path.c_str();
+#endif
}
if ( !portable_app_setup() ) {
- // this is used on both Linux and macOS
- // but a macOS specific code may be written instead
StringOutputStream home( 256 );
- home << DirectoryCleaned(g_get_user_config_dir()) << "/" << RADIANT_BASENAME << "/";
- // first create ~/.config
- // since it may be missing on brand new home directory
- Q_mkdir( g_get_user_config_dir() );
- // then create ~/.config/netradiant
+#if GDEF_OS_MACOS
+ /* This is used on macOS, this will produce
+ ~/Library/Application Support/NetRadiant folder. */
+ home << DirectoryCleaned( g_get_home_dir() );
+ Q_mkdir( home.c_str() );
+ home << "Library/";
+ Q_mkdir( home.c_str() );
+ home << "Application Support/";
+ Q_mkdir( home.c_str() );
+ home << RADIANT_NAME << "/";
+#else // if GDEF_OS_XDG
+ /* This is used on both Linux and FreeBSD,
+ this will produce ~/.config/netradiant folder
+ when environment has default settings, the
+ XDG_CONFIG_HOME variable modifies it. */
+ home << DirectoryCleaned( g_get_user_config_dir() );
+ Q_mkdir( home.c_str() );
+ home << RADIANT_BASENAME << "/";
+#endif // ! GDEF_OS_MACOS
Q_mkdir( home.c_str() );
home_path = home.c_str();
}
+
gamedetect();
}
#include <windows.h>
+char* openCmdMap;
+
+void cmdMap(){
+ openCmdMap = NULL;
+ for ( int i = 1; i < g_argc; ++i )
+ {
+ if ( !stricmp( g_argv[i] + strlen(g_argv[i]) - 4, ".map" ) ){
+ openCmdMap = g_argv[i];
+ }
+ }
+}
+
void environment_init( int argc, char const* argv[] ){
args_init( argc, argv );
{
// get path to the editor
char filename[MAX_PATH + 1];
+ StringOutputStream app_filepath_stream( 256 );
+ StringOutputStream app_path_stream( 256 );
+
GetModuleFileName( 0, filename, MAX_PATH );
+
+ app_filepath_stream << PathCleaned( filename );
+ app_filepath = app_filepath_stream.c_str();
+
char* last_separator = strrchr( filename, '\\' );
if ( last_separator != 0 ) {
*( last_separator + 1 ) = '\0';
{
filename[0] = '\0';
}
- StringOutputStream app( 256 );
- app << PathCleaned( filename );
- app_path = app.c_str();
+
+ app_path_stream << PathCleaned( filename );
+ app_path = app_path_stream.c_str();
lib_path = app_path;
data_path = app_path;
if ( !portable_app_setup() ) {
char *appdata = getenv( "APPDATA" );
+
StringOutputStream home( 256 );
home << PathCleaned( appdata );
- home << "/NetRadiantSettings/";
+ home << "/";
+ home << RADIANT_NAME;
+ home << "/";
+
Q_mkdir( home.c_str() );
home_path = home.c_str();
}
gamedetect();
+ cmdMap();
}
#else