2019-10-29 00:00:44 +00:00
/*
2020-01-08 00:00:57 +00:00
* * searchpaths . cpp
* *
* * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* * Copyright 2019 Christoph Oelckers
* * All rights reserved .
* *
* * Redistribution and use in source and binary forms , with or without
* * modification , are permitted provided that the following conditions
* * are met :
* *
* * 1. Redistributions of source code must retain the above copyright
* * notice , this list of conditions and the following disclaimer .
* * 2. Redistributions in binary form must reproduce the above copyright
* * notice , this list of conditions and the following disclaimer in the
* * documentation and / or other materials provided with the distribution .
* * 3. The name of the author may not be used to endorse or promote products
* * derived from this software without specific prior written permission .
* *
* * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ` ` AS IS ' ' AND ANY EXPRESS OR
* * IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED WARRANTIES
* * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED .
* * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT , INDIRECT ,
* * INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT
* * NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE ,
* * DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
* * THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
* * THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
* * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* *
* *
2019-10-29 00:00:44 +00:00
*/
2019-10-30 17:09:00 +00:00
# include "m_crc32.h"
2019-10-29 18:53:46 +00:00
# include "i_specialpaths.h"
2020-01-03 13:19:52 +00:00
# include "i_system.h"
2019-10-29 18:53:46 +00:00
# include "gameconfigfile.h"
# include "cmdlib.h"
# include "utf8.h"
2019-10-29 22:57:28 +00:00
# include "sc_man.h"
# include "resourcefile.h"
# include "printf.h"
2019-12-26 13:04:53 +00:00
# include "version.h"
2019-10-30 17:09:00 +00:00
# include "gamecontrol.h"
2019-12-27 22:22:39 +00:00
# include "m_argv.h"
2020-04-11 21:54:33 +00:00
# include "filesystem.h"
2020-04-11 21:50:43 +00:00
# include "findfile.h"
2019-10-30 17:09:00 +00:00
2019-12-11 22:41:05 +00:00
static const char * res_exts [ ] = { " .grp " , " .zip " , " .pk3 " , " .pk4 " , " .7z " , " .pk7 " } ;
2019-10-30 17:09:00 +00:00
2019-11-01 18:25:42 +00:00
int g_gameType ;
2019-10-29 00:00:44 +00:00
2019-10-29 20:06:14 +00:00
void AddSearchPath ( TArray < FString > & searchpaths , const char * path )
{
2020-01-03 16:56:22 +00:00
auto fpath = M_GetNormalizedPath ( path ) ;
2020-02-09 17:37:24 +00:00
if ( fpath . Len ( ) > 1 & & fpath . Back ( ) = = ' / ' ) fpath . Truncate ( fpath . Len ( ) - 1 ) ;
2020-01-03 16:56:22 +00:00
if ( DirExists ( fpath ) )
2019-10-29 20:06:14 +00:00
{
2020-01-03 16:56:22 +00:00
if ( searchpaths . Find ( fpath ) = = searchpaths . Size ( ) )
searchpaths . Push ( fpath ) ;
2019-10-29 20:06:14 +00:00
}
}
2019-10-29 18:53:46 +00:00
# ifndef _WIN32
2019-10-29 00:00:44 +00:00
void G_AddExternalSearchPaths ( TArray < FString > & searchpaths )
{
2020-01-08 00:00:57 +00:00
searchpaths . Append ( I_GetSteamPath ( ) ) ;
searchpaths . Append ( I_GetGogPaths ( ) ) ;
2019-10-29 00:00:44 +00:00
}
2019-10-30 17:27:52 +00:00
# else
2019-10-29 00:00:44 +00:00
//-------------------------------------------------------------------------
//
//
//
//-------------------------------------------------------------------------
2020-01-08 00:00:57 +00:00
struct RegistryPathInfo
2019-10-29 00:00:44 +00:00
{
2020-02-07 21:22:06 +00:00
const wchar_t * regPath ;
const wchar_t * regKey ;
2020-01-08 00:00:57 +00:00
const char * * subpaths ;
} ;
static const char * gameroot [ ] = { " /gameroot " , nullptr } ;
2021-04-01 01:25:57 +00:00
static const char * swaddons [ ] = { " /gameroot/addons " , " /gameroot " , nullptr } ;
2020-02-13 23:21:09 +00:00
static const char * dukeaddons [ ] = { " /gameroot " , " /gameroot/addons/dc " , " /gameroot/addons/nw " , " /gameroot/addons/vacation " , nullptr } ;
2020-01-08 00:00:57 +00:00
static const char * dn3d [ ] = { " /Duke Nukem 3D " , nullptr } ;
static const char * nam [ ] = { " /NAM " , nullptr } ;
static const char * ww2gi [ ] = { " /WW2GI " , nullptr } ;
2020-02-10 19:38:38 +00:00
static const char * bloodfs [ ] = { " " , R " (/addons/Cryptic Passage) " , nullptr } ;
2020-01-08 00:00:57 +00:00
static const char * sw [ ] = { " /Shadow Warrior " , nullptr } ;
2020-03-22 10:10:11 +00:00
static const char * redneck [ ] = { " /Redneck " , " /AGAIN " , " /HUNTIN " , nullptr } ;
2020-01-08 00:00:57 +00:00
2020-02-07 21:22:06 +00:00
# ifndef _WIN64
# define WOW64 "\\"
# else
# define WOW64 "\\Wow6432Node\\"
# endif
2020-01-08 00:00:57 +00:00
static const RegistryPathInfo paths [ ] = {
2020-02-07 21:22:06 +00:00
{ L " SOFTWARE " WOW64 " GOG.com \\ GOGDUKE3D " , L " PATH " , nullptr } ,
{ L " SOFTWARE " WOW64 " GOG.com \\ GOGREDNECKRAMPAGE " , L " PATH " , nullptr } ,
{ L " SOFTWARE " WOW64 " GOG.com \\ GOGCREDNECKRIDESAGAIN " , L " PATH " , nullptr } ,
{ L " SOFTWARE " WOW64 " GOG.com \\ GOGONEUNITONEBLOOD " , L " PATH " , nullptr } ,
{ L " SOFTWARE " WOW64 " GOG.com \\ GOGSHADOWARRIOR " , L " PATH " , nullptr } ,
{ L " SOFTWARE " WOW64 " GOG.com \\ Games \\ 1374469660 " , L " path " , bloodfs } ,
{ L " SOFTWARE " WOW64 " GOG.com \\ Games \\ 1740836875 " , L " path " , nullptr } ,
2020-11-22 11:22:47 +00:00
{ L " SOFTWARE " WOW64 " GOG.com \\ Games \\ 2132611980 " , L " path " , nullptr } , // Powerslave
2020-02-07 21:22:06 +00:00
{ L " SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Uninstall \\ Steam App 434050 " , L " InstallLocation " , nullptr } ,
2020-02-13 23:21:09 +00:00
{ L " SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Uninstall \\ Steam App 225140 " , L " InstallLocation " , dukeaddons } ,
2020-02-07 21:22:06 +00:00
{ L " SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Uninstall \\ Steam App 359850 " , L " InstallLocation " , dn3d } ,
{ L " SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Uninstall \\ Steam App 329650 " , L " InstallLocation " , nam } ,
{ L " SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Uninstall \\ Steam App 376750 " , L " InstallLocation " , ww2gi } ,
{ L " SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Uninstall \\ Steam App 299030 " , L " InstallLocation " , nullptr } , // Blood: One Unit Whole Blood (Steam)
{ L " SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Uninstall \\ Steam App 1010750 " , L " InstallLocation " , bloodfs } ,
2020-02-22 13:57:43 +00:00
{ L " SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Uninstall \\ Steam App 225160 " , L " InstallLocation " , swaddons } , // Shadow Warrior Classic Redux - Steam
2020-02-07 21:22:06 +00:00
{ L " SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Uninstall \\ Steam App 238070 " , L " InstallLocation " , gameroot } , // Shadow Warrior Classic (1997) - Steam
{ L " SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Uninstall \\ Steam App 358400 " , L " InstallLocation " , sw } ,
2020-02-22 00:02:40 +00:00
{ L " SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Uninstall \\ Steam App 565550 " , L " InstallLocation " , redneck } ,
{ L " SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Uninstall \\ Steam App 580940 " , L " InstallLocation " , redneck } ,
2020-03-22 10:10:11 +00:00
{ L " SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Uninstall \\ Steam App 580930 " , L " InstallLocation " , redneck } ,
2020-02-07 21:22:06 +00:00
#if 0
{ L " SOFTWARE \\ 3DRealms \\ Duke Nukem 3D " , nullptr , dn3d } ,
{ L " SOFTWARE \\ 3DRealms \\ Anthology " , nullptr , dn3d } ,
{ L " SOFTWARE \\ 3DRealms \\ Shadow Warrior " , nullptr , sw } ,
{ L " SOFTWARE \\ 3DRealms \\ Anthology " , nullptr , sw } ,
# endif
2020-01-08 00:00:57 +00:00
{ nullptr }
} ;
2019-10-29 00:00:44 +00:00
2020-04-23 20:58:02 +00:00
bool I_QueryPathKey ( const wchar_t * keypath , const wchar_t * valname , FString & value ) ;
2019-10-29 00:00:44 +00:00
2020-01-08 00:00:57 +00:00
void G_AddExternalSearchPaths ( TArray < FString > & searchpaths )
{
for ( auto & entry : paths )
2019-10-30 18:26:55 +00:00
{
2020-01-08 00:00:57 +00:00
// 3D Realms Anthology
2020-02-07 21:22:06 +00:00
FString buf ;
if ( I_QueryPathKey ( entry . regPath , entry . regKey , buf ) )
2020-01-08 00:00:57 +00:00
{
2020-02-07 21:22:06 +00:00
FixPathSeperator ( buf ) ;
2020-01-08 16:36:00 +00:00
if ( ! entry . subpaths ) AddSearchPath ( searchpaths , buf ) ;
2020-01-08 00:00:57 +00:00
else
{
FString path ;
for ( int i = 0 ; entry . subpaths [ i ] ; i + + )
{
path . Format ( " %s%s " , buf , entry . subpaths [ i ] ) ;
AddSearchPath ( searchpaths , path ) ;
}
}
}
2019-10-30 18:26:55 +00:00
}
2019-10-29 00:00:44 +00:00
}
# endif
//==========================================================================
//
2019-10-29 20:06:14 +00:00
//
2019-10-29 00:00:44 +00:00
//
//==========================================================================
void CollectSubdirectories ( TArray < FString > & searchpath , const char * dirmatch )
{
2020-01-03 13:19:52 +00:00
FString dirpath = MakeUTF8 ( dirmatch ) ; // convert into clean UTF-8
dirpath . Truncate ( dirpath . Len ( ) - 2 ) ; // remove the '/*'
FString AbsPath = M_GetNormalizedPath ( dirpath ) ;
if ( DirExists ( AbsPath ) )
2019-10-29 00:00:44 +00:00
{
2020-01-03 13:19:52 +00:00
findstate_t findstate ;
void * handle ;
2020-01-29 09:41:23 +00:00
if ( ( handle = I_FindFirst ( AbsPath + " /* " , & findstate ) ) ! = ( void * ) - 1 )
2019-10-29 00:00:44 +00:00
{
2020-01-03 13:19:52 +00:00
do
2019-10-29 00:00:44 +00:00
{
2020-01-03 16:34:52 +00:00
if ( I_FindAttr ( & findstate ) & FA_DIREC )
2019-10-29 00:00:44 +00:00
{
2020-01-03 16:34:52 +00:00
auto p = I_FindName ( & findstate ) ;
if ( strcmp ( p , " . " ) & & strcmp ( p , " .. " ) )
{
FStringf fullpath ( " %s/%s " , AbsPath . GetChars ( ) , p ) ;
searchpath . Push ( fullpath ) ;
}
2019-10-29 00:00:44 +00:00
}
2020-01-03 13:19:52 +00:00
} while ( I_FindNext ( handle , & findstate ) = = 0 ) ;
I_FindClose ( handle ) ;
2019-10-29 18:53:46 +00:00
}
2019-10-29 00:00:44 +00:00
}
}
//==========================================================================
//
// CollectSearchPaths
//
// collect all paths in a local array for easier management
//
//==========================================================================
TArray < FString > CollectSearchPaths ( )
{
2019-10-29 18:53:46 +00:00
TArray < FString > searchpaths ;
2019-10-29 00:00:44 +00:00
if ( GameConfig - > SetSection ( " GameSearch.Directories " ) )
{
const char * key ;
const char * value ;
while ( GameConfig - > NextInSection ( key , value ) )
{
if ( stricmp ( key , " Path " ) = = 0 )
{
2020-02-01 10:16:02 +00:00
// Checking Steam via a list entry allows easy removal if not wanted.
if ( stricmp ( value , " $STEAM " ) = = 0 )
{
G_AddExternalSearchPaths ( searchpaths ) ;
continue ;
}
2019-10-29 00:00:44 +00:00
FString nice = NicePath ( value ) ;
if ( nice . Len ( ) > 0 )
{
# ifdef _WIN32
2019-10-29 18:53:46 +00:00
if ( isalpha ( nice [ 0 ] & & nice [ 1 ] = = ' : ' & & nice [ 2 ] ! = ' / ' ) ) continue ; // ignore drive relative paths because they are meaningless.
2019-10-29 00:00:44 +00:00
# endif
// A path ending with "/*" means to add all subdirectories.
if ( nice [ nice . Len ( ) - 2 ] = = ' / ' & & nice [ nice . Len ( ) - 1 ] = = ' * ' )
{
2019-10-29 18:53:46 +00:00
CollectSubdirectories ( searchpaths , nice ) ;
2019-10-29 00:00:44 +00:00
}
else
{
2019-10-29 20:06:14 +00:00
AddSearchPath ( searchpaths , nice ) ;
2019-10-29 00:00:44 +00:00
}
}
}
}
}
// Unify and remove trailing slashes
2019-10-29 18:53:46 +00:00
for ( auto & str : searchpaths )
2019-10-29 00:00:44 +00:00
{
str . Substitute ( " \\ " , " / " ) ;
2021-05-26 14:47:36 +00:00
# ifdef _WIN32
bool isUNCpath = false ;
auto chars = str . GetChars ( ) ;
if ( chars [ 0 ] = = ' / ' & & chars [ 1 ] = = ' / ' )
isUNCpath = true ;
# endif
2019-10-29 18:53:46 +00:00
str . Substitute ( " // " , " / " ) ; // Double slashes can happen when constructing paths so just get rid of them here.
2019-10-29 00:00:44 +00:00
if ( str . Back ( ) = = ' / ' ) str . Truncate ( str . Len ( ) - 1 ) ;
2021-05-26 14:47:36 +00:00
# ifdef _WIN32
if ( isUNCpath )
str = ( FString ) " / " + str ;
# endif
2019-10-29 00:00:44 +00:00
}
2019-10-29 18:53:46 +00:00
return searchpaths ;
2019-10-29 00:00:44 +00:00
}
2019-10-29 22:57:28 +00:00
//==========================================================================
//
//
//
//==========================================================================
struct FileEntry
{
FString FileName ;
2020-01-03 16:34:52 +00:00
size_t FileLength ;
time_t FileTime ;
2019-10-29 22:57:28 +00:00
uint32_t CRCValue ;
2019-10-30 17:09:00 +00:00
uint32_t Index ;
2019-10-29 22:57:28 +00:00
} ;
TArray < FileEntry > CollectAllFilesInSearchPath ( )
{
2019-11-01 18:25:42 +00:00
uint32_t index = 0 ;
2019-10-29 22:57:28 +00:00
TArray < FileEntry > filelist ;
2019-11-01 18:25:42 +00:00
if ( userConfig . gamegrp . IsNotEmpty ( ) )
{
// If the user specified a file on the command line, insert that first, if found.
FileReader fr ;
if ( fr . OpenFile ( userConfig . gamegrp ) )
{
2020-02-04 17:12:53 +00:00
FileEntry fe = { userConfig . gamegrp , ( size_t ) fr . GetLength ( ) , 0 , 0 , index + + } ;
2019-11-01 18:25:42 +00:00
filelist . Push ( fe ) ;
}
}
2019-10-29 22:57:28 +00:00
auto paths = CollectSearchPaths ( ) ;
for ( auto & path : paths )
{
2020-01-03 16:34:52 +00:00
if ( DirExists ( path ) )
2019-10-29 22:57:28 +00:00
{
2020-01-03 16:34:52 +00:00
findstate_t findstate ;
void * handle ;
if ( ( handle = I_FindFirst ( path + " /*.* " , & findstate ) ) ! = ( void * ) - 1 )
2019-10-29 22:57:28 +00:00
{
2020-01-03 16:34:52 +00:00
do
2019-10-29 22:57:28 +00:00
{
2020-01-03 16:34:52 +00:00
if ( ! ( I_FindAttr ( & findstate ) & FA_DIREC ) )
{
auto p = I_FindName ( & findstate ) ;
filelist . Reserve ( 1 ) ;
auto & flentry = filelist . Last ( ) ;
flentry . FileName . Format ( " %s/%s " , path . GetChars ( ) , p ) ;
GetFileInfo ( flentry . FileName , & flentry . FileLength , & flentry . FileTime ) ;
flentry . Index = index + + ; // to preserve order when working on the list.
}
} while ( I_FindNext ( handle , & findstate ) = = 0 ) ;
I_FindClose ( handle ) ;
2019-10-29 22:57:28 +00:00
}
}
}
2019-10-30 17:09:00 +00:00
return filelist ;
2019-10-29 22:57:28 +00:00
}
//==========================================================================
//
//
//
//==========================================================================
2019-10-30 17:09:00 +00:00
static TArray < FileEntry > LoadCRCCache ( void )
2019-10-29 22:57:28 +00:00
{
auto cachepath = M_GetAppDataPath ( false ) + " /grpcrccache.txt " ;
FScanner sc ;
TArray < FileEntry > crclist ;
try
{
2020-04-15 11:35:16 +00:00
if ( sc . OpenFile ( cachepath ) )
2019-10-29 22:57:28 +00:00
{
2020-04-15 11:35:16 +00:00
while ( sc . GetString ( ) )
{
crclist . Reserve ( 1 ) ;
auto & flentry = crclist . Last ( ) ;
flentry . FileName = sc . String ;
sc . MustGetNumber ( ) ;
flentry . FileLength = sc . BigNumber ;
sc . MustGetNumber ( ) ;
flentry . FileTime = sc . BigNumber ;
sc . MustGetNumber ( ) ;
flentry . CRCValue = ( unsigned ) sc . BigNumber ;
}
2019-10-29 22:57:28 +00:00
}
}
2020-04-11 21:50:43 +00:00
catch ( CRecoverableError & )
2019-10-29 22:57:28 +00:00
{
// If there's a parsing error, return what we got and discard the rest.
}
return crclist ;
}
//==========================================================================
//
//
//
//==========================================================================
2019-10-30 23:41:56 +00:00
void SaveCRCs ( TArray < FileEntry > & crclist )
{
auto cachepath = M_GetAppDataPath ( true ) + " /grpcrccache.txt " ;
FileWriter * fw = FileWriter : : Open ( cachepath ) ;
if ( fw )
{
for ( auto & crc : crclist )
{
FStringf line ( " \" %s \" %llu %llu %u \n " , crc . FileName . GetChars ( ) , ( long long ) crc . FileLength , ( long long ) crc . FileTime , crc . CRCValue ) ;
fw - > Write ( line . GetChars ( ) , line . Len ( ) ) ;
}
delete fw ;
}
}
//==========================================================================
//
//
//
//==========================================================================
static TArray < GrpInfo > ParseGrpInfo ( const char * fn , FileReader & fr , TMap < FString , uint32_t > & CRCMap )
2019-10-30 17:09:00 +00:00
{
TArray < GrpInfo > groups ;
TMap < FString , int > FlagMap ;
FlagMap . Insert ( " GAMEFLAG_DUKE " , GAMEFLAG_DUKE ) ;
FlagMap . Insert ( " GAMEFLAG_NAM " , GAMEFLAG_NAM ) ;
FlagMap . Insert ( " GAMEFLAG_NAPALM " , GAMEFLAG_NAPALM ) ;
FlagMap . Insert ( " GAMEFLAG_WW2GI " , GAMEFLAG_WW2GI ) ;
FlagMap . Insert ( " GAMEFLAG_ADDON " , GAMEFLAG_ADDON ) ;
FlagMap . Insert ( " GAMEFLAG_SHAREWARE " , GAMEFLAG_SHAREWARE ) ;
FlagMap . Insert ( " GAMEFLAG_DUKEBETA " , GAMEFLAG_DUKEBETA ) ; // includes 0x20 since it's a shareware beta
FlagMap . Insert ( " GAMEFLAG_RR " , GAMEFLAG_RR ) ;
FlagMap . Insert ( " GAMEFLAG_RRRA " , GAMEFLAG_RRRA ) ;
FlagMap . Insert ( " GAMEFLAG_BLOOD " , GAMEFLAG_BLOOD ) ;
2019-11-06 18:22:14 +00:00
FlagMap . Insert ( " GAMEFLAG_SW " , GAMEFLAG_SW ) ;
2019-12-12 23:19:34 +00:00
FlagMap . Insert ( " GAMEFLAG_POWERSLAVE " , GAMEFLAG_POWERSLAVE ) ;
FlagMap . Insert ( " GAMEFLAG_EXHUMED " , GAMEFLAG_EXHUMED ) ;
2020-08-05 20:57:45 +00:00
FlagMap . Insert ( " GAMEFLAG_DUKEDC " , GAMEFLAG_DUKEDC ) ;
2021-04-25 23:24:57 +00:00
FlagMap . Insert ( " GAMEFLAG_DUKENW " , GAMEFLAG_DUKENW ) ;
FlagMap . Insert ( " GAMEFLAG_DUKEVACA " , GAMEFLAG_DUKEVACA ) ;
FlagMap . Insert ( " GAMEFLAG_BLOODCP " , GAMEFLAG_BLOODCP ) ;
FlagMap . Insert ( " GAMEFLAG_ROUTE66 " , GAMEFLAG_ROUTE66 ) ;
FlagMap . Insert ( " GAMEFLAG_SWWANTON " , GAMEFLAG_SWWANTON ) ;
FlagMap . Insert ( " GAMEFLAG_SWTWINDRAG " , GAMEFLAG_SWTWINDRAG ) ;
2019-11-06 18:22:14 +00:00
2019-10-30 17:09:00 +00:00
FScanner sc ;
auto mem = fr . Read ( ) ;
sc . OpenMem ( fn , ( const char * ) mem . Data ( ) , mem . Size ( ) ) ;
while ( sc . GetToken ( ) )
{
sc . TokenMustBe ( TK_Identifier ) ;
if ( sc . Compare ( " CRC " ) )
{
sc . MustGetToken ( ' { ' ) ;
while ( ! sc . CheckToken ( ' } ' ) )
{
sc . MustGetToken ( TK_Identifier ) ;
FString key = sc . String ;
sc . MustGetToken ( TK_IntConst ) ;
if ( sc . BigNumber < 0 | | sc . BigNumber > = UINT_MAX )
{
sc . ScriptError ( " CRC hash %s out of range " , sc . String ) ;
}
CRCMap . Insert ( key , ( uint32_t ) sc . BigNumber ) ;
}
}
2020-02-01 20:12:09 +00:00
else if ( sc . Compare ( " grpinfo " ) | | sc . Compare ( " addon " ) )
2019-10-30 17:09:00 +00:00
{
groups . Reserve ( 1 ) ;
2019-10-30 23:41:56 +00:00
auto & grp = groups . Last ( ) ;
2020-02-01 20:12:09 +00:00
grp . isAddon = sc . Compare ( " addon " ) ;
2019-10-30 17:09:00 +00:00
sc . MustGetToken ( ' { ' ) ;
while ( ! sc . CheckToken ( ' } ' ) )
{
sc . MustGetToken ( TK_Identifier ) ;
if ( sc . Compare ( " name " ) )
{
sc . MustGetToken ( TK_StringConst ) ;
grp . name = sc . String ;
}
else if ( sc . Compare ( " scriptname " ) )
{
sc . MustGetToken ( TK_StringConst ) ;
grp . scriptname = sc . String ;
}
else if ( sc . Compare ( " loaddirectory " ) )
{
2019-11-01 18:25:42 +00:00
// Only load the directory, but not the file.
grp . loaddirectory = true ;
2019-10-30 17:09:00 +00:00
}
else if ( sc . Compare ( " defname " ) )
{
sc . MustGetToken ( TK_StringConst ) ;
grp . defname = sc . String ;
}
else if ( sc . Compare ( " rtsname " ) )
{
sc . MustGetToken ( TK_StringConst ) ;
grp . rtsname = sc . String ;
}
2019-10-30 23:41:56 +00:00
else if ( sc . Compare ( " gamefilter " ) )
{
sc . MustGetToken ( TK_StringConst ) ;
grp . gamefilter = sc . String ;
}
2021-04-13 14:59:49 +00:00
else if ( sc . Compare ( " gameid " ) )
{
sc . MustGetToken ( TK_StringConst ) ;
grp . gameid = sc . String ;
}
2021-04-10 17:14:30 +00:00
else if ( sc . Compare ( " fgcolor " ) )
{
sc . MustGetToken ( TK_IntConst ) ;
grp . FgColor = sc . Number ;
}
else if ( sc . Compare ( " bkcolor " ) )
{
sc . MustGetToken ( TK_IntConst ) ;
grp . BgColor = sc . Number ;
}
2019-10-30 17:09:00 +00:00
else if ( sc . Compare ( " crc " ) )
{
sc . MustGetAnyToken ( ) ;
if ( sc . TokenType = = TK_IntConst )
{
grp . CRC = ( uint32_t ) sc . BigNumber ;
}
2019-10-30 23:41:56 +00:00
else if ( sc . TokenType = = ' - ' )
{
sc . MustGetToken ( TK_IntConst ) ;
grp . CRC = ( uint32_t ) - sc . BigNumber ;
}
2019-10-30 17:09:00 +00:00
else if ( sc . TokenType = = TK_Identifier )
{
auto ip = CRCMap . CheckKey ( sc . String ) ;
if ( ip ) grp . CRC = * ip ;
else sc . ScriptError ( " Unknown CRC value %s " , sc . String ) ;
}
else sc . TokenMustBe ( TK_IntConst ) ;
}
else if ( sc . Compare ( " dependency " ) )
{
sc . MustGetAnyToken ( ) ;
if ( sc . TokenType = = TK_IntConst )
{
grp . dependencyCRC = ( uint32_t ) sc . BigNumber ;
}
2019-10-30 23:41:56 +00:00
else if ( sc . TokenType = = ' - ' )
{
sc . MustGetToken ( TK_IntConst ) ;
grp . dependencyCRC = ( uint32_t ) - sc . BigNumber ;
}
2019-10-30 17:09:00 +00:00
else if ( sc . TokenType = = TK_Identifier )
{
auto ip = CRCMap . CheckKey ( sc . String ) ;
if ( ip ) grp . dependencyCRC = * ip ;
else sc . ScriptError ( " Unknown CRC value %s " , sc . String ) ;
}
else sc . TokenMustBe ( TK_IntConst ) ;
}
else if ( sc . Compare ( " size " ) )
{
sc . MustGetToken ( TK_IntConst ) ;
grp . size = sc . BigNumber ;
}
else if ( sc . Compare ( " flags " ) )
{
do
{
sc . MustGetAnyToken ( ) ;
if ( sc . TokenType = = TK_IntConst )
{
grp . flags | = sc . Number ;
}
else if ( sc . TokenType = = TK_Identifier )
{
auto ip = FlagMap . CheckKey ( sc . String ) ;
2019-11-02 17:03:41 +00:00
if ( ip ) grp . flags | = * ip ;
2019-10-30 17:09:00 +00:00
else sc . ScriptError ( " Unknown flag value %s " , sc . String ) ;
}
else sc . TokenMustBe ( TK_IntConst ) ;
}
while ( sc . CheckToken ( ' | ' ) ) ;
}
2019-11-01 18:25:42 +00:00
else if ( sc . Compare ( " mustcontain " ) )
2019-10-30 17:09:00 +00:00
{
do
{
sc . MustGetToken ( TK_StringConst ) ;
2019-11-01 18:25:42 +00:00
grp . mustcontain . Push ( sc . String ) ;
2019-10-30 17:09:00 +00:00
}
while ( sc . CheckToken ( ' , ' ) ) ;
}
2019-12-26 09:47:10 +00:00
else if ( sc . Compare ( " deletecontent " ) )
{
do
{
sc . MustGetToken ( TK_StringConst ) ;
grp . tobedeleted . Push ( sc . String ) ;
} while ( sc . CheckToken ( ' , ' ) ) ;
}
2019-11-01 18:25:42 +00:00
else if ( sc . Compare ( " loadgrp " ) )
{
do
{
sc . MustGetToken ( TK_StringConst ) ;
grp . loadfiles . Push ( sc . String ) ;
} while ( sc . CheckToken ( ' , ' ) ) ;
}
2019-10-30 17:09:00 +00:00
else if ( sc . Compare ( " loadart " ) )
{
do
{
sc . MustGetToken ( TK_StringConst ) ;
2019-12-11 22:41:05 +00:00
grp . loadart . Push ( sc . String ) ;
2019-10-30 17:09:00 +00:00
}
while ( sc . CheckToken ( ' , ' ) ) ;
}
2021-07-19 02:24:47 +00:00
else if ( sc . Compare ( " exclepisodes " ) )
2021-07-16 12:14:56 +00:00
{
do
{
sc . MustGetToken ( TK_StringConst ) ;
2021-07-19 02:24:47 +00:00
grp . exclepisodes . Push ( sc . String ) ;
2021-07-16 12:14:56 +00:00
}
while ( sc . CheckToken ( ' , ' ) ) ;
}
2019-10-30 17:09:00 +00:00
else sc . ScriptError ( nullptr ) ;
}
2020-09-25 08:06:06 +00:00
if ( grp . dependencyCRC = = 0 & & ( grp . flags & ( GAMEFLAG_DUKE | GAMEFLAG_NAM | GAMEFLAG_NAPALM | GAMEFLAG_WW2GI | GAMEFLAG_RRALL | GAMEFLAG_BLOOD | GAMEFLAG_SW | GAMEFLAG_PSEXHUMED ) ) = = 0 )
2020-02-16 19:18:07 +00:00
{
sc . ScriptMessage ( " Warning: GRP without game defined. Ignoring " ) ;
groups . Pop ( ) ;
}
2019-10-30 17:09:00 +00:00
}
else sc . ScriptError ( nullptr ) ;
}
return groups ;
}
//==========================================================================
//
//
//
//==========================================================================
TArray < GrpInfo > ParseAllGrpInfos ( TArray < FileEntry > & filelist )
2019-10-29 22:57:28 +00:00
{
2019-10-30 17:09:00 +00:00
TArray < GrpInfo > groups ;
2019-10-30 23:41:56 +00:00
TMap < FString , uint32_t > CRCMap ;
2019-11-02 11:59:59 +00:00
// This opens the base resource only for reading the grpinfo from it which we need before setting up the game state.
2019-10-30 17:09:00 +00:00
std : : unique_ptr < FResourceFile > engine_res ;
2021-05-22 22:58:43 +00:00
const char * baseres = BaseFileSearch ( ENGINERES_FILE , nullptr , true , GameConfig ) ;
2019-10-30 17:09:00 +00:00
engine_res . reset ( FResourceFile : : OpenResourceFile ( baseres , true , true ) ) ;
if ( engine_res )
2019-10-29 22:57:28 +00:00
{
2019-12-26 13:04:53 +00:00
auto basegrp = engine_res - > FindLump ( " engine/grpinfo.txt " ) ;
2019-10-30 17:09:00 +00:00
if ( basegrp )
{
auto fr = basegrp - > NewReader ( ) ;
if ( fr . isOpen ( ) )
{
2019-12-26 13:04:53 +00:00
groups = ParseGrpInfo ( " engine/grpinfo.txt " , fr , CRCMap ) ;
2019-10-30 17:09:00 +00:00
}
}
2019-10-29 22:57:28 +00:00
}
for ( auto & entry : filelist )
{
auto lowerstr = entry . FileName . MakeLower ( ) ;
if ( lowerstr . Len ( ) > = 8 )
{
const char * exten = lowerstr . GetChars ( ) + lowerstr . Len ( ) - 8 ;
if ( ! stricmp ( exten , " .grpinfo " ) )
{
// parse it.
FileReader fr ;
if ( fr . OpenFile ( entry . FileName ) )
{
2019-10-30 23:41:56 +00:00
auto g = ParseGrpInfo ( entry . FileName , fr , CRCMap ) ;
2019-10-30 17:09:00 +00:00
groups . Append ( g ) ;
2019-10-29 22:57:28 +00:00
}
}
}
}
2019-10-30 17:09:00 +00:00
return groups ;
2019-10-29 22:57:28 +00:00
}
2019-10-30 17:09:00 +00:00
//==========================================================================
//
//
//
//==========================================================================
void GetCRC ( FileEntry * entry , TArray < FileEntry > & CRCCache )
{
for ( auto & ce : CRCCache )
{
// File size, modification date snd name all must match exactly to pick an entry.
2019-10-30 23:41:56 +00:00
if ( entry - > FileLength = = ce . FileLength & & entry - > FileTime = = ce . FileTime & & entry - > FileName . Compare ( ce . FileName ) = = 0 )
2019-10-30 17:09:00 +00:00
{
entry - > CRCValue = ce . CRCValue ;
return ;
}
}
FileReader f ;
if ( f . OpenFile ( entry - > FileName ) )
{
TArray < uint8_t > buffer ( 65536 , 1 ) ;
uint32_t crcval = 0 ;
size_t b ;
do
{
b = f . Read ( buffer . Data ( ) , buffer . Size ( ) ) ;
2021-05-11 23:50:41 +00:00
if ( b > 0 ) crcval = AddCRC32 ( crcval , buffer . Data ( ) , unsigned ( b ) ) ;
2019-10-30 17:09:00 +00:00
}
while ( b = = buffer . Size ( ) ) ;
entry - > CRCValue = crcval ;
CRCCache . Push ( * entry ) ;
}
}
2019-10-29 22:57:28 +00:00
2019-10-30 17:09:00 +00:00
GrpInfo * IdentifyGroup ( FileEntry * entry , TArray < GrpInfo * > & groups )
2019-10-29 22:57:28 +00:00
{
2019-10-30 17:09:00 +00:00
for ( auto g : groups )
{
if ( entry - > FileLength = = g - > size & & entry - > CRCValue = = g - > CRC )
return g ;
}
return nullptr ;
}
//==========================================================================
//
//
//
//==========================================================================
2020-02-01 20:12:09 +00:00
static bool CheckAddon ( GrpInfo * addon , GrpInfo * main , const char * filename )
{
if ( addon - > dependencyCRC ! = main - > CRC ) return false ;
FString path = ExtractFilePath ( filename ) ;
if ( path . Len ( ) > 0 & & path . Back ( ) ! = ' / ' ) path + = ' / ' ;
for ( auto & fn : addon - > mustcontain )
{
FString check = path + fn ;
2020-03-01 06:40:13 +00:00
if ( FileExists ( check ) ) continue ;
# if !defined _WIN32
2020-03-01 09:17:26 +00:00
check = path + fn . MakeLower ( ) ;
2020-03-01 06:40:13 +00:00
if ( FileExists ( check ) ) continue ;
2020-03-01 09:17:26 +00:00
check = path + fn . MakeUpper ( ) ;
2020-03-01 06:40:13 +00:00
if ( FileExists ( check ) ) continue ;
# endif
return false ;
2020-02-01 20:12:09 +00:00
}
return true ;
}
//==========================================================================
//
//
//
//==========================================================================
2019-10-30 17:09:00 +00:00
TArray < GrpEntry > GrpScan ( )
{
TArray < GrpEntry > foundGames ;
2019-10-30 23:41:56 +00:00
TArray < FileEntry * > sortedFileList ;
TArray < GrpInfo * > sortedGroupList ;
2019-12-11 22:41:05 +00:00
TArray < GrpInfo * > contentGroupList ;
2020-02-01 20:12:09 +00:00
TArray < GrpInfo * > addonList ;
2019-10-30 23:41:56 +00:00
2019-10-30 17:09:00 +00:00
auto allFiles = CollectAllFilesInSearchPath ( ) ;
auto allGroups = ParseAllGrpInfos ( allFiles ) ;
2019-10-30 23:41:56 +00:00
2019-10-30 17:09:00 +00:00
auto cachedCRCs = LoadCRCCache ( ) ;
2019-10-30 23:41:56 +00:00
auto numCRCs = cachedCRCs . Size ( ) ;
2021-03-12 22:45:03 +00:00
for ( unsigned i = 0 ; i < allGroups . Size ( ) ; i + + )
allGroups [ i ] . index = i ;
2019-10-30 17:09:00 +00:00
// Remove all unnecessary content from the file list. Since this contains all data from the search path's directories it can be quite large.
// Sort both lists by file size so that we only need to pass over each list once to weed out all unrelated content. Go backward to avoid too much item movement
// (most will be deleted anyway.)
2019-12-11 22:41:05 +00:00
2019-10-30 23:41:56 +00:00
for ( auto & f : allFiles ) sortedFileList . Push ( & f ) ;
2019-12-11 22:41:05 +00:00
for ( auto & g : allGroups )
{
2020-02-01 20:12:09 +00:00
if ( g . isAddon )
addonList . Push ( & g ) ;
else if ( g . CRC = = 0 & & g . mustcontain . Size ( ) > 0 )
2019-12-11 22:41:05 +00:00
contentGroupList . Push ( & g ) ;
else
sortedGroupList . Push ( & g ) ;
}
// As a first pass we need to look for all known game resources which only are identified by a content list
if ( contentGroupList . Size ( ) )
{
for ( auto fe : sortedFileList )
{
FString fn = fe - > FileName . MakeLower ( ) ;
for ( auto ext : res_exts )
{
if ( strcmp ( ext , fn . GetChars ( ) + fn . Len ( ) - 4 ) = = 0 )
{
auto resf = FResourceFile : : OpenResourceFile ( fe - > FileName , true , true ) ;
if ( resf )
{
for ( auto grp : contentGroupList )
{
bool ok = true ;
for ( auto & lump : grp - > mustcontain )
{
if ( ! resf - > FindLump ( lump ) )
{
ok = false ;
break ;
}
}
if ( ok )
{
// got a match
foundGames . Reserve ( 1 ) ;
auto & fg = foundGames . Last ( ) ;
fg . FileInfo = * grp ;
fg . FileName = fe - > FileName ;
break ;
}
}
2019-12-24 15:30:33 +00:00
delete resf ;
2019-12-11 22:41:05 +00:00
}
}
}
}
}
2019-10-30 23:41:56 +00:00
2019-10-30 17:09:00 +00:00
std : : sort ( sortedFileList . begin ( ) , sortedFileList . end ( ) , [ ] ( FileEntry * lhs , FileEntry * rhs ) { return lhs - > FileLength < rhs - > FileLength ; } ) ;
std : : sort ( sortedGroupList . begin ( ) , sortedGroupList . end ( ) , [ ] ( GrpInfo * lhs , GrpInfo * rhs ) { return lhs - > size < rhs - > size ; } ) ;
2019-10-30 23:41:56 +00:00
int findex = sortedFileList . Size ( ) - 1 ;
int gindex = sortedGroupList . Size ( ) - 1 ;
2019-10-30 17:09:00 +00:00
2019-12-11 22:41:05 +00:00
2021-05-23 06:13:52 +00:00
while ( findex > = 0 & & gindex > = 0 )
2019-10-30 17:09:00 +00:00
{
if ( sortedFileList [ findex ] - > FileLength > sortedGroupList [ gindex ] - > size )
{
// File is larger than the largest known group so it cannot be a candidate.
sortedFileList . Delete ( findex - - ) ;
}
else if ( sortedFileList [ findex ] - > FileLength < sortedGroupList [ gindex ] - > size )
{
// The largest available file is smaller than this group so we cannot possibly have it.
sortedGroupList . Delete ( gindex - - ) ;
}
else
{
2019-10-30 23:41:56 +00:00
findex - - ;
gindex - - ;
2019-10-30 17:09:00 +00:00
// We found a matching file. Skip over all other entries of the same size so we can analyze those later as well
2021-05-23 06:13:52 +00:00
while ( findex > = 0 & & sortedFileList [ findex ] - > FileLength = = sortedFileList [ findex + 1 ] - > FileLength ) findex - - ;
while ( gindex > = 0 & & sortedGroupList [ gindex ] - > size = = sortedGroupList [ gindex + 1 ] - > size ) gindex - - ;
2019-10-30 17:09:00 +00:00
}
}
2019-10-30 23:41:56 +00:00
sortedFileList . Delete ( 0 , findex + 1 ) ;
sortedGroupList . Delete ( 0 , gindex + 1 ) ;
2019-10-30 17:09:00 +00:00
if ( sortedGroupList . Size ( ) = = 0 | | sortedFileList . Size ( ) = = 0 )
2019-10-30 23:41:56 +00:00
return foundGames ;
2019-10-30 17:09:00 +00:00
for ( auto entry : sortedFileList )
{
GetCRC ( entry , cachedCRCs ) ;
auto grp = IdentifyGroup ( entry , sortedGroupList ) ;
if ( grp )
{
foundGames . Reserve ( 1 ) ;
2019-10-30 23:41:56 +00:00
auto & fg = foundGames . Last ( ) ;
2019-10-30 17:09:00 +00:00
fg . FileInfo = * grp ;
fg . FileName = entry - > FileName ;
2020-02-01 20:12:09 +00:00
for ( auto addon : addonList )
{
if ( CheckAddon ( addon , grp , entry - > FileName ) )
{
foundGames . Reserve ( 1 ) ;
auto & fga = foundGames . Last ( ) ;
fga . FileInfo = * addon ;
}
}
2019-10-30 17:09:00 +00:00
}
}
2019-10-30 23:41:56 +00:00
// We must check for all addons if their dependency is present.
for ( int i = foundGames . Size ( ) - 1 ; i > = 0 ; i - - )
2019-10-30 17:09:00 +00:00
{
auto crc = foundGames [ i ] . FileInfo . dependencyCRC ;
if ( crc ! = 0 )
{
bool found = false ;
2019-10-30 23:41:56 +00:00
for ( auto & fg : foundGames )
2019-10-30 17:09:00 +00:00
{
if ( fg . FileInfo . CRC = = crc )
{
found = true ;
break ;
}
}
if ( ! found ) foundGames . Delete ( i ) ; // Dependent add-on without dependency cannot be played.
}
}
2019-10-30 23:41:56 +00:00
// return everything to its proper order (using qsort because sorting an array of complex structs with std::sort is a messy affair.)
qsort ( foundGames . Data ( ) , foundGames . Size ( ) , sizeof ( foundGames [ 0 ] ) , [ ] ( const void * a , const void * b ) - > int
{
auto A = ( const GrpEntry * ) a ;
auto B = ( const GrpEntry * ) b ;
2021-03-12 22:45:03 +00:00
return ( int ) A - > FileInfo . index - ( int ) B - > FileInfo . index ;
2019-10-30 23:41:56 +00:00
} ) ;
// Finally, scan the list for duplicstes. Only the first occurence should count.
for ( unsigned i = 0 ; i < foundGames . Size ( ) ; i + + )
{
2019-12-06 22:20:18 +00:00
for ( unsigned j = foundGames . Size ( ) - 1 ; j > i ; j - - )
2019-10-30 23:41:56 +00:00
{
2020-10-19 09:46:22 +00:00
if ( foundGames [ i ] . FileInfo . CRC = = foundGames [ j ] . FileInfo . CRC & & ( foundGames [ j ] . FileInfo . CRC ! = 0 | | foundGames [ i ] . FileInfo . name = = foundGames [ j ] . FileInfo . name ) )
2019-10-30 23:41:56 +00:00
foundGames . Delete ( j ) ;
}
}
// new CRCs got added so save the list.
if ( cachedCRCs . Size ( ) > numCRCs )
{
SaveCRCs ( cachedCRCs ) ;
}
2019-10-30 17:09:00 +00:00
return foundGames ;
2019-10-29 22:57:28 +00:00
}
2019-11-01 18:25:42 +00:00
//==========================================================================
//
// Fallback in case nothing got defined.
// Also used by 'includedefault' which forces this to be statically defined
// (and which shouldn't be used to begin with because there are no default DEFs!)
//
//==========================================================================
const char * G_DefaultDefFile ( void )
{
2021-01-02 03:46:58 +00:00
if ( isBlood ( ) )
2019-11-01 18:25:42 +00:00
return " blood.def " ;
if ( g_gameType & GAMEFLAG_DUKE )
return " duke3d.def " ;
if ( g_gameType & GAMEFLAG_RRRA )
return " rrra.def " ;
if ( g_gameType & GAMEFLAG_RR )
return " rr.def " ;
2021-07-11 02:42:33 +00:00
if ( isWW2GI ( ) )
2019-11-01 18:25:42 +00:00
return " ww2gi.def " ;
2021-07-11 02:39:54 +00:00
if ( isSWALL ( ) )
2019-11-01 18:25:42 +00:00
return " sw.def " ;
2019-11-24 09:03:19 +00:00
if ( g_gameType & GAMEFLAG_PSEXHUMED )
return " exhumed.def " ;
2019-11-01 18:25:42 +00:00
if ( g_gameType & GAMEFLAG_NAM )
return fileSystem . FindFile ( " nam.def " ) ? " nam.def " : " napalm.def " ;
if ( g_gameType & GAMEFLAG_NAPALM )
return fileSystem . FindFile ( " napalm.def " ) ? " napalm.def " : " nam.def " ;
return " duke3d.def " ;
}
const char * G_DefFile ( void )
{
return userConfig . DefaultDef . IsNotEmpty ( ) ? userConfig . DefaultDef . GetChars ( ) : G_DefaultDefFile ( ) ;
}
2019-11-01 21:17:15 +00:00
#if 0
// Should this be added to the game data collector?
bool AddINIFile ( const char * pzFile , bool bForce = false )
{
char * pzFN ;
static INICHAIN * pINIIter = NULL ;
if ( ! bForce )
{
if ( findfrompath ( pzFile , & pzFN ) ) return false ; // failed to resolve the filename
2019-11-08 01:02:54 +00:00
if ( ! FileExists ( pzFN ) )
2019-11-01 21:17:15 +00:00
{
2021-03-24 20:13:36 +00:00
M_Free ( pzFN ) ;
2019-11-01 21:17:15 +00:00
return false ;
} // failed to stat the file
2021-03-24 20:13:36 +00:00
M_Free ( pzFN ) ;
2019-11-01 21:17:15 +00:00
IniFile * pTempIni = new IniFile ( pzFile ) ;
if ( ! pTempIni - > FindSection ( " Episode1 " ) )
{
delete pTempIni ;
return false ;
}
delete pTempIni ;
}
if ( ! pINIChain )
pINIIter = pINIChain = new INICHAIN ;
else
pINIIter = pINIIter - > pNext = new INICHAIN ;
pINIIter - > pNext = NULL ;
pINIIter - > pDescription = NULL ;
2020-09-08 16:48:18 +00:00
strncpy ( pINIIter - > zName , pzFile , BMAX_PATH ) ;
2020-08-30 21:34:40 +00:00
for ( int i = 0 ; i < countof ( gINIDescription ) ; i + + )
2019-11-01 21:17:15 +00:00
{
2020-09-04 19:24:48 +00:00
if ( ! strnicmp ( pINIIter - > zName , gINIDescription [ i ] . pzFilename , BMAX_PATH ) )
2019-11-01 21:17:15 +00:00
{
pINIIter - > pDescription = & gINIDescription [ i ] ;
break ;
}
}
return true ;
}
void ScanINIFiles ( void )
{
nINICount = 0 ;
BUILDVFS_FIND_REC * pINIList = klistpath ( " / " , " *.ini " , BUILDVFS_FIND_FILE ) ;
pINIChain = NULL ;
if ( bINIOverride | | ! pINIList )
{
AddINIFile ( BloodIniFile , true ) ;
}
for ( auto pIter = pINIList ; pIter ; pIter = pIter - > next )
{
AddINIFile ( pIter - > name ) ;
}
klistfree ( pINIList ) ;
pINISelected = pINIChain ;
for ( auto pIter = pINIChain ; pIter ; pIter = pIter - > pNext )
{
2020-09-04 19:24:48 +00:00
if ( ! strnicmp ( BloodIniFile , pIter - > zName , BMAX_PATH ) )
2019-11-01 21:17:15 +00:00
{
pINISelected = pIter ;
break ;
}
}
2019-11-08 01:02:54 +00:00
# endif