X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=fs.c;h=2d53dbddc43cc9c735bd91e15913c73d459763d1;hb=1be7bcf4e96658898dd5e4b413819e660b4c7063;hp=39a5aecadd1a68ed823dba01022c27540505f162;hpb=701925453d9a40b422e3f29fd13e30fe59a9b572;p=xonotic%2Fdarkplaces.git diff --git a/fs.c b/fs.c index 39a5aeca..2d53dbdd 100644 --- a/fs.c +++ b/fs.c @@ -702,9 +702,7 @@ void FS_Path_f (void) for (s=fs_searchpaths ; s ; s=s->next) { if (s->pack) - { Con_Printf("%s (%i files)\n", s->pack->filename, s->pack->numfiles); - } else Con_Printf("%s\n", s->filename); } @@ -799,7 +797,7 @@ void FS_AddGameDirectory (const char *dir) { if (matchpattern(current->text, "*.pak", true)) { - dpsnprintf (pakfile, sizeof (pakfile), "%s/%s", dir, current->text); + dpsnprintf (pakfile, sizeof (pakfile), "%s%s", dir, current->text); pak = FS_LoadPackPAK (pakfile); if (pak) { @@ -818,7 +816,7 @@ void FS_AddGameDirectory (const char *dir) { if (matchpattern(current->text, "*.pk3", true)) { - dpsnprintf (pakfile, sizeof (pakfile), "%s/%s", dir, current->text); + dpsnprintf (pakfile, sizeof (pakfile), "%s%s", dir, current->text); pak = FS_LoadPackPK3 (pakfile); if (pak) { @@ -853,16 +851,14 @@ void FS_AddGameHierarchy (const char *dir) const char *homedir; #endif - strlcpy (com_modname, dir, sizeof (com_modname)); - // Add the common game directory - FS_AddGameDirectory (va("%s/%s", fs_basedir, dir)); + FS_AddGameDirectory (va("%s/%s/", fs_basedir, dir)); #ifndef WIN32 // Add the personal game directory homedir = getenv ("HOME"); if (homedir != NULL && homedir[0] != '\0') - FS_AddGameDirectory (va("%s/.%s/%s", homedir, gameuserdirname, dir)); + FS_AddGameDirectory (va("%s/.%s/%s/", homedir, gameuserdirname, dir)); #endif } @@ -904,14 +900,22 @@ void FS_Init (void) fs_mempool = Mem_AllocPool("file management", 0, NULL); - Cvar_RegisterVariable (&scr_screenshot_name); - - Cmd_AddCommand ("path", FS_Path_f); - Cmd_AddCommand ("dir", FS_Dir_f); - Cmd_AddCommand ("ls", FS_Ls_f); - strcpy(fs_basedir, "."); - strcpy(fs_gamedir, "."); + strcpy(fs_gamedir, ""); + +#ifdef MACOSX + // FIXME: is there a better way to find the directory outside the .app? + if (strstr(com_argv[0], ".app/")) + { + char *split; + char temp[4096]; + split = strstr(com_argv[0], ".app/"); + while (split > com_argv[0] && *split != '/') + split--; + strlcpy(fs_basedir, com_argv[0], sizeof(fs_basedir)); + fs_basedir[split - com_argv[0]] = 0; + } +#endif PK3_OpenLibrary (); @@ -963,7 +967,6 @@ void FS_Init (void) // add the game-specific paths // gamedirname1 (typically id1) FS_AddGameHierarchy (gamedirname1); - Cvar_SetQuick (&scr_screenshot_name, gamescreenshotname); // add the game-specific path, if any if (gamedirname2) @@ -972,6 +975,9 @@ void FS_Init (void) FS_AddGameHierarchy (gamedirname2); } + // set the com_modname (reported in server info) + strlcpy(com_modname, gamedirname1, sizeof(com_modname)); + // -game // Adds basedir/gamedir as an override game // LordHavoc: now supports multiple -game directories @@ -984,7 +990,8 @@ void FS_Init (void) i++; fs_modified = true; FS_AddGameHierarchy (com_argv[i]); - Cvar_SetQuick (&scr_screenshot_name, com_modname); + // update the com_modname + strlcpy (com_modname, com_argv[i], sizeof (com_modname)); } } @@ -993,6 +1000,22 @@ void FS_Init (void) unlink (va("%s/qconsole.log", fs_gamedir)); } +void FS_Init_Commands(void) +{ + Cvar_RegisterVariable (&scr_screenshot_name); + + Cmd_AddCommand ("path", FS_Path_f); + Cmd_AddCommand ("dir", FS_Dir_f); + Cmd_AddCommand ("ls", FS_Ls_f); + + // set the default screenshot name to either the mod name or the + // gamemode screenshot name + if (fs_modified) + Cvar_SetQuick (&scr_screenshot_name, com_modname); + else + Cvar_SetQuick (&scr_screenshot_name, gamescreenshotname); +} + /* ================ FS_Shutdown @@ -1264,7 +1287,7 @@ static searchpath_t *FS_FindFile (const char *name, int* index, qboolean quiet) else { char netpath[MAX_OSPATH]; - dpsnprintf(netpath, sizeof(netpath), "%s/%s", search->filename, name); + dpsnprintf(netpath, sizeof(netpath), "%s%s", search->filename, name); if (FS_SysFileExists (netpath)) { if (!quiet) @@ -1313,7 +1336,7 @@ qfile_t *FS_OpenReadFile (const char *filename, qboolean quiet, qboolean nonbloc if (pack_ind < 0) { char path [MAX_OSPATH]; - dpsnprintf (path, sizeof (path), "%s/%s", search->filename, filename); + dpsnprintf (path, sizeof (path), "%s%s", search->filename, filename); return FS_SysOpen (path, "rb", nonblocking); } @@ -1353,7 +1376,7 @@ qfile_t* FS_Open (const char* filepath, const char* mode, qboolean quiet, qboole char real_path [MAX_OSPATH]; // Open the file on disk directly - dpsnprintf (real_path, sizeof (real_path), "%s/%s", fs_gamedir, filepath); + dpsnprintf (real_path, sizeof (real_path), "%s%s", fs_gamedir, filepath); // Create directories up to the file FS_CreatePath (real_path); @@ -1995,10 +2018,14 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet) char netpath[MAX_OSPATH]; char temp[MAX_OSPATH]; - while(!strncmp(pattern, "./", 2)) - pattern += 2; - while(!strncmp(pattern, ".\\", 2)) - pattern += 2; + for (i = 0;pattern[i] == '.' || pattern[i] == ':' || pattern[i] == '/' || pattern[i] == '\\';i++) + ; + + if (i > 0) + { + Con_Printf("Don't use punctuation at the beginning of a search pattern!\n"); + return NULL; + } search = NULL; liststart = NULL; @@ -2007,14 +2034,9 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet) slash = strrchr(pattern, '/'); backslash = strrchr(pattern, '\\'); colon = strrchr(pattern, ':'); - separator = pattern; - if (separator < slash) - separator = slash; - if (separator < backslash) - separator = backslash; - if (separator < colon) - separator = colon; - basepathlength = separator - pattern; + separator = max(slash, backslash); + separator = max(separator, colon); + basepathlength = separator ? (separator + 1 - pattern) : 0; basepath = Mem_Alloc (tempmempool, basepathlength + 1); if (basepathlength) memcpy(basepath, pattern, basepathlength); @@ -2066,12 +2088,12 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet) else { // get a directory listing and look at each name - dpsnprintf(netpath, sizeof (netpath), "%s/%s", searchpath->filename, basepath); + dpsnprintf(netpath, sizeof (netpath), "%s%s", searchpath->filename, basepath); if ((dir = listdirectory(netpath))) { for (dirfile = dir;dirfile;dirfile = dirfile->next) { - dpsnprintf(temp, sizeof(temp), "%s/%s", basepath, dirfile->text); + dpsnprintf(temp, sizeof(temp), "%s%s", basepath, dirfile->text); if (matchpattern(temp, (char *)pattern, true)) { for (listtemp = liststart;listtemp;listtemp = listtemp->next)