* support multiple Extra Resource Paths

This commit is contained in:
Garux 2023-08-22 15:40:09 +06:00
parent c9d8265958
commit 158b724dba
4 changed files with 47 additions and 45 deletions

View File

@ -258,10 +258,10 @@ public:
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();
}

View File

@ -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<CopiedString, const char*, setEnginePath> EnginePathImp
// Extra Resource Path
CopiedString g_strExtraResourcePath;
std::array<CopiedString, 5> g_strExtraResourcePaths;
const char* ExtraResourcePath_get(){
return g_strExtraResourcePath.c_str();
const std::array<CopiedString, 5>& 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() )

View File

@ -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<CopiedString, 5>& ExtraResourcePaths_get();
extern CopiedString g_strAppPath;
const char* AppPath_get();

View File

@ -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<CopiedString> 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 );
};
for( const auto& path : ExtraResourcePaths_get() )
paths_push( path.c_str() );
StringOutputStream str( 256 );
// if we have a mod dir
if ( !path_equal( gamename, basegame ) ) {
// ~/.<gameprefix>/<fs_game>
if ( !path_equal( globalRoot, userRoot ) ) {
GlobalFileSystem().initDirectory( str( userRoot, gamename, '/' ) ); // userGamePath
}
// <fs_basepath>/<fs_game>
{
GlobalFileSystem().initDirectory( str( globalRoot, gamename, '/' ) ); // globalGamePath
}
}
// ~/.<gameprefix>/<fs_game>
paths_push( str( userRoot, gamename, '/' ) ); // userGamePath
// <fs_basepath>/<fs_game>
paths_push( str( globalRoot, gamename, '/' ) ); // globalGamePath
// ~/.<gameprefix>/<fs_main>
if ( !path_equal( globalRoot, userRoot ) ) {
GlobalFileSystem().initDirectory( str( userRoot, basegame, '/' ) ); // userBasePath
}
paths_push( str( userRoot, basegame, '/' ) ); // userBasePath
// <fs_basepath>/<fs_main>
{
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" ) );
}