From 16e9a106940bacd4f6f185d96ab6ee63c62bcfdf Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Mon, 22 Jun 2020 15:14:57 +0000 Subject: [PATCH] Consolidate FS_Init and associated code This is a minor cleanup to make refactoring Host_Init slightly easier later. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12715 d7cf8633-e32d-0410-b094-e92efae38249 --- fs.c | 137 ++++++++++++++++++++++++++++++++------------------------- host.c | 11 +---- 2 files changed, 78 insertions(+), 70 deletions(-) diff --git a/fs.c b/fs.c index 4c5d5031..34ed6525 100644 --- a/fs.c +++ b/fs.c @@ -1790,51 +1790,6 @@ static void COM_InsertFlags(const char *buf) { sys.argc = i; } -/* -================ -FS_Init_SelfPack -================ -*/ -void FS_Init_SelfPack (void) -{ - char *buf; - - PK3_OpenLibrary (); - fs_mempool = Mem_AllocPool("file management", 0, NULL); - - // Load darkplaces.opt from the FS. - if (!COM_CheckParm("-noopt")) - { - buf = (char *) FS_SysLoadFile("darkplaces.opt", tempmempool, true, NULL); - if(buf) - { - COM_InsertFlags(buf); - Mem_Free(buf); - } - } - -#ifndef USE_RWOPS - // Provide the SelfPack. - if (!COM_CheckParm("-noselfpack") && sys.selffd >= 0) - { - fs_selfpack = FS_LoadPackPK3FromFD(sys.argv[0], sys.selffd, true); - if(fs_selfpack) - { - FS_AddSelfPack(); - if (!COM_CheckParm("-noopt")) - { - buf = (char *) FS_LoadFile("darkplaces.opt", tempmempool, true, NULL); - if(buf) - { - COM_InsertFlags(buf); - Mem_Free(buf); - } - } - } - } -#endif -} - static int FS_ChooseUserDir(userdirmode_t userdirmode, char *userdir, size_t userdirsize) { #if defined(__IPHONEOS__) @@ -2006,12 +1961,21 @@ static int FS_ChooseUserDir(userdirmode_t userdirmode, char *userdir, size_t use #endif } -/* -================ -FS_Init -================ -*/ -void FS_Init (void) +void FS_Init_Commands(void) +{ + Cvar_RegisterVariable (&scr_screenshot_name); + Cvar_RegisterVariable (&fs_empty_files_in_pack_mark_deletions); + Cvar_RegisterVariable (&cvar_fs_gamedir); + + Cmd_AddCommand(CMD_SHARED, "gamedir", FS_GameDir_f, "changes active gamedir list (can take multiple arguments), not including base directory (example usage: gamedir ctf)"); + Cmd_AddCommand(CMD_SHARED, "fs_rescan", FS_Rescan_f, "rescans filesystem for new pack archives and any other changes"); + Cmd_AddCommand(CMD_SHARED, "path", FS_Path_f, "print searchpath (game directories and archives)"); + Cmd_AddCommand(CMD_SHARED, "dir", FS_Dir_f, "list files in searchpath matching an * filename pattern, one per line"); + Cmd_AddCommand(CMD_SHARED, "ls", FS_Ls_f, "list files in searchpath matching an * filename pattern, multiple per line"); + Cmd_AddCommand(CMD_SHARED, "which", FS_Which_f, "accepts a file name as argument and reports where the file is taken from"); +} + +static void FS_Init_Dir (void) { const char *p; int i; @@ -2174,18 +2138,69 @@ void FS_Init (void) fs_mutex = Thread_CreateMutex(); } -void FS_Init_Commands(void) +/* +================ +FS_Init_SelfPack +================ +*/ +void FS_Init_SelfPack (void) { - Cvar_RegisterVariable (&scr_screenshot_name); - Cvar_RegisterVariable (&fs_empty_files_in_pack_mark_deletions); - Cvar_RegisterVariable (&cvar_fs_gamedir); + char *buf; - Cmd_AddCommand(CMD_SHARED, "gamedir", FS_GameDir_f, "changes active gamedir list (can take multiple arguments), not including base directory (example usage: gamedir ctf)"); - Cmd_AddCommand(CMD_SHARED, "fs_rescan", FS_Rescan_f, "rescans filesystem for new pack archives and any other changes"); - Cmd_AddCommand(CMD_SHARED, "path", FS_Path_f, "print searchpath (game directories and archives)"); - Cmd_AddCommand(CMD_SHARED, "dir", FS_Dir_f, "list files in searchpath matching an * filename pattern, one per line"); - Cmd_AddCommand(CMD_SHARED, "ls", FS_Ls_f, "list files in searchpath matching an * filename pattern, multiple per line"); - Cmd_AddCommand(CMD_SHARED, "which", FS_Which_f, "accepts a file name as argument and reports where the file is taken from"); + // Load darkplaces.opt from the FS. + if (!COM_CheckParm("-noopt")) + { + buf = (char *) FS_SysLoadFile("darkplaces.opt", tempmempool, true, NULL); + if(buf) + { + COM_InsertFlags(buf); + Mem_Free(buf); + } + } + +#ifndef USE_RWOPS + // Provide the SelfPack. + if (!COM_CheckParm("-noselfpack") && sys.selffd >= 0) + { + fs_selfpack = FS_LoadPackPK3FromFD(sys.argv[0], sys.selffd, true); + if(fs_selfpack) + { + FS_AddSelfPack(); + if (!COM_CheckParm("-noopt")) + { + buf = (char *) FS_LoadFile("darkplaces.opt", tempmempool, true, NULL); + if(buf) + { + COM_InsertFlags(buf); + Mem_Free(buf); + } + } + } + } +#endif +} + +/* +================ +FS_Init +================ +*/ + +void FS_Init(void) +{ + fs_mempool = Mem_AllocPool("file management", 0, NULL); + + FS_Init_Commands(); + + PK3_OpenLibrary (); + + // initialize the self-pack (must be before COM_InitGameType as it may add command line options) + FS_Init_SelfPack(); + + // detect gamemode from commandline options or executable name + COM_InitGameType(); + + FS_Init_Dir(); } /* diff --git a/host.c b/host.c index 85096e39..301ea8ea 100644 --- a/host.c +++ b/host.c @@ -1224,16 +1224,12 @@ static void Host_Init (void) Curl_Init_Commands(); Sys_Init_Commands(); COM_Init_Commands(); - FS_Init_Commands(); // initialize console window (only used by sys_win.c) Sys_InitConsole(); - // initialize the self-pack (must be before COM_InitGameType as it may add command line options) - FS_Init_SelfPack(); - - // detect gamemode from commandline options or executable name - COM_InitGameType(); + // initialize filesystem (including fs_basedir, fs_gamedir, -game, scr_screenshot_name) + FS_Init(); // construct a version string for the corner of the console os = DP_OS_NAME; @@ -1246,9 +1242,6 @@ static void Host_Init (void) // initialize ixtable Mathlib_Init(); - // initialize filesystem (including fs_basedir, fs_gamedir, -game, scr_screenshot_name) - FS_Init(); - // register the cvars for session locking Host_InitSession(); -- 2.39.2