diff --git a/radiant/build.cpp b/radiant/build.cpp index e944cd9f..fc9bf717 100644 --- a/radiant/build.cpp +++ b/radiant/build.cpp @@ -258,10 +258,10 @@ class ToolXMLConstructor final : public XMLElementParser void flush(){ if ( !m_buffer.empty() ) { m_tool.push_back( new VariableString( m_buffer.c_str() ) ); - // q3map2 ExtraResoucePath hack + // q3map2 ExtraResourcePaths hack if( strstr( m_buffer.c_str(), "[RadiantPath]q3map2.[ExecutableType]" ) != nullptr // is q3map2 - && strstr( m_buffer.c_str(), "[ExtraResoucePath]" ) == nullptr ){ // has no extra path right away (could have been added by this before) - m_tool.push_back( new VariableString( "[ExtraResoucePath]" ) ); + && strstr( m_buffer.c_str(), "[ExtraResourcePaths]" ) == nullptr ){ // has no extra path right away (could have been added by this before) + m_tool.push_back( new VariableString( "[ExtraResourcePaths]" ) ); } m_buffer.clear(); } diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index c3abf333..f548d567 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -321,11 +321,11 @@ void EnginePath_Unrealise(){ static CopiedString g_installedDevFilesPath; // track last engine path, where dev files installation occured, to prompt again when changed -static void installDevFiles( const CopiedString& enginePath ){ - if( !path_equal( enginePath.c_str(), g_installedDevFilesPath.c_str() ) ){ +static void installDevFiles(){ + if( !path_equal( g_strEnginePath.c_str(), g_installedDevFilesPath.c_str() ) ){ ASSERT_MESSAGE( g_enginepath_unrealised != 0, "installDevFiles: engine path realised" ); - DoInstallDevFilesDlg( enginePath.c_str() ); - g_installedDevFilesPath = enginePath; + DoInstallDevFilesDlg( g_strEnginePath.c_str() ); + g_installedDevFilesPath = g_strEnginePath; } } @@ -352,7 +352,7 @@ void setEnginePath( CopiedString& self, const char* value ){ self = buffer.c_str(); - installDevFiles( self ); + installDevFiles(); EnginePath_Realise(); } @@ -362,10 +362,10 @@ typedef ReferenceCaller1 EnginePathImp // Extra Resource Path -CopiedString g_strExtraResourcePath; +std::array g_strExtraResourcePaths; -const char* ExtraResourcePath_get(){ - return g_strExtraResourcePath.c_str(); +const std::array& ExtraResourcePaths_get(){ + return g_strExtraResourcePaths; } @@ -421,10 +421,11 @@ void Paths_constructPreferences( PreferencesPage& page ){ void Paths_constructPage( PreferenceGroup& group ){ PreferencesPage page( group.createPage( "Paths", "Path Settings" ) ); Paths_constructPreferences( page ); - page.appendPathEntry( "Extra Resource Path", true, - StringImportCallback( EnginePathImportCaller( g_strExtraResourcePath ) ), - StringExportCallback( StringExportCaller( g_strExtraResourcePath ) ) - ); + for( auto& extraPath : g_strExtraResourcePaths ) + page.appendPathEntry( "Extra Resource Path", true, + StringImportCallback( EnginePathImportCaller( extraPath ) ), + StringExportCallback( StringExportCaller( extraPath ) ) + ); } void Paths_registerPreferencesPage(){ @@ -486,7 +487,7 @@ void EnginePath_verify(){ g_PathsDialog.DoModal(); g_PathsDialog.Destroy(); } - installDevFiles( g_strEnginePath ); // try this anytime, as engine path may be set via command line or -gamedetect + installDevFiles(); // try this anytime, as engine path may be set via command line or -gamedetect } namespace @@ -2096,7 +2097,10 @@ void MainFrame_Construct(){ GlobalPreferenceSystem().registerPreference( "OpenGLFont", CopiedStringImportStringCaller( g_OpenGLFont ), CopiedStringExportStringCaller( g_OpenGLFont ) ); GlobalPreferenceSystem().registerPreference( "OpenGLFontSize", IntImportStringCaller( g_OpenGLFontSize ), IntExportStringCaller( g_OpenGLFontSize ) ); - GlobalPreferenceSystem().registerPreference( "ExtraResoucePath", CopiedStringImportStringCaller( g_strExtraResourcePath ), CopiedStringExportStringCaller( g_strExtraResourcePath ) ); + for( size_t i = 0; i < g_strExtraResourcePaths.size(); ++i ) + GlobalPreferenceSystem().registerPreference( StringOutputStream( 32 )( "ExtraResourcePath", i ), + CopiedStringImportStringCaller( g_strExtraResourcePaths[i] ), CopiedStringExportStringCaller( g_strExtraResourcePaths[i] ) ); + GlobalPreferenceSystem().registerPreference( "EnginePath", CopiedStringImportStringCaller( g_strEnginePath ), CopiedStringExportStringCaller( g_strEnginePath ) ); GlobalPreferenceSystem().registerPreference( "InstalledDevFilesPath", CopiedStringImportStringCaller( g_installedDevFilesPath ), CopiedStringExportStringCaller( g_installedDevFilesPath ) ); if ( g_strEnginePath.empty() ) diff --git a/radiant/mainframe.h b/radiant/mainframe.h index ce835e26..8a3f5d95 100644 --- a/radiant/mainframe.h +++ b/radiant/mainframe.h @@ -180,8 +180,7 @@ void Radiant_detachGameToolsPathObserver( ModuleObserver& observer ); void EnginePath_verify(); const char* EnginePath_get(); -extern CopiedString g_strExtraResourcePath; -const char* ExtraResourcePath_get(); +const std::array& ExtraResourcePaths_get(); extern CopiedString g_strAppPath; const char* AppPath_get(); diff --git a/radiant/qe3.cpp b/radiant/qe3.cpp index 8df67a1c..e742e625 100644 --- a/radiant/qe3.cpp +++ b/radiant/qe3.cpp @@ -86,33 +86,29 @@ void QE_InitVFS(){ const char* userRoot = g_qeglobals.m_userEnginePath.c_str(); const char* globalRoot = EnginePath_get(); - const char* extrapath = ExtraResourcePath_get(); - if( !string_empty( extrapath ) ) - GlobalFileSystem().initDirectory( extrapath ); + std::vector paths; + const auto paths_push = [&paths]( const char* newPath ){ // collects unique paths + if( !string_empty( newPath ) + && std::none_of( paths.cbegin(), paths.cend(), [newPath]( const CopiedString& path ){ return path_equal( path.c_str(), newPath ); } ) ) + paths.emplace_back( newPath ); + }; - StringOutputStream str( 256 ); - // if we have a mod dir - if ( !path_equal( gamename, basegame ) ) { - // ~/./ - if ( !path_equal( globalRoot, userRoot ) ) { - GlobalFileSystem().initDirectory( str( userRoot, gamename, '/' ) ); // userGamePath - } - // / - { - GlobalFileSystem().initDirectory( str( globalRoot, gamename, '/' ) ); // globalGamePath - } - } + for( const auto& path : ExtraResourcePaths_get() ) + paths_push( path.c_str() ); + StringOutputStream str( 256 ); + // ~/./ + paths_push( str( userRoot, gamename, '/' ) ); // userGamePath + // / + paths_push( str( globalRoot, gamename, '/' ) ); // globalGamePath // ~/./ - if ( !path_equal( globalRoot, userRoot ) ) { - GlobalFileSystem().initDirectory( str( userRoot, basegame, '/' ) ); // userBasePath - } - + paths_push( str( userRoot, basegame, '/' ) ); // userBasePath // / - { - GlobalFileSystem().initDirectory( str( globalRoot, basegame, '/' ) ); // globalBasePath - } + paths_push( str( globalRoot, basegame, '/' ) ); // globalBasePath + + for( const auto& path : paths ) + GlobalFileSystem().initDirectory( path.c_str() ); } @@ -163,17 +159,20 @@ bool ConfirmModified( const char* title ){ } void bsp_init(){ + StringOutputStream stream( 256 ); + build_set_variable( "RadiantPath", AppPath_get() ); build_set_variable( "ExecutableType", RADIANT_EXECUTABLE ); build_set_variable( "EnginePath", EnginePath_get() ); build_set_variable( "UserEnginePath", g_qeglobals.m_userEnginePath.c_str() ); - build_set_variable( "ExtraResoucePath", string_empty( ExtraResourcePath_get() )? "" - : StringOutputStream()( " -fs_pakpath ", makeQuoted( ExtraResourcePath_get() ) ) ); + for( const auto& path : ExtraResourcePaths_get() ) + if( !string_empty( path.c_str() ) ) + stream << " -fs_pakpath " << makeQuoted( path ); + build_set_variable( "ExtraResourcePaths", stream ); build_set_variable( "MonitorAddress", ( g_WatchBSP_Enabled ) ? RADIANT_MONITOR_ADDRESS : "" ); build_set_variable( "GameName", gamename_get() ); const char* mapname = Map_Name( g_map ); - StringOutputStream stream( 256 ); { build_set_variable( "BspFile", stream( PathExtensionless( mapname ), ".bsp" ) ); }