]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - fs.c
allow extra args for messagemode and messagemode2 to prefill a message prefix
[xonotic/darkplaces.git] / fs.c
diff --git a/fs.c b/fs.c
index b5ffaf2acb31762f2ad6e4e04bcd10e5df817c15..d810ff541f1b6e497dc6489150dd1f38415d4c57 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -1206,7 +1206,7 @@ void FS_AddGameDirectory (const char *dir)
 
        stringlistinit(&list);
        listdirectory(&list, "", dir);
-       stringlistsort(&list);
+       stringlistsort(&list, false);
 
        // add any PAK package in the directory
        for (i = 0;i < list.numstrings;i++)
@@ -1364,11 +1364,14 @@ void FS_Rescan (void)
        // gamedirname1 (typically id1)
        FS_AddGameHierarchy (gamedirname1);
        // update the com_modname (used for server info)
-       strlcpy(com_modname, gamedirname1, sizeof(com_modname));
+       if (gamedirname2 && gamedirname2[0])
+               strlcpy(com_modname, gamedirname2, sizeof(com_modname));
+       else
+               strlcpy(com_modname, gamedirname1, sizeof(com_modname));
 
        // add the game-specific path, if any
        // (only used for mission packs and the like, which should set fs_modified)
-       if (gamedirname2)
+       if (gamedirname2 && gamedirname2[0])
        {
                fs_modified = true;
                FS_AddGameHierarchy (gamedirname2);
@@ -1644,7 +1647,7 @@ static void FS_ListGameDirs(void)
        stringlistinit(&list);
        listdirectory(&list, va("%s/", fs_basedir), "");
        listdirectory(&list, va("%s/", fs_userdir), "");
-       stringlistsort(&list);
+       stringlistsort(&list, false);
 
        stringlistinit(&list2);
        for(i = 0; i < list.numstrings; ++i)
@@ -1872,6 +1875,12 @@ int FS_ChooseUserDir(userdirmode_t userdirmode, char *userdir, size_t userdirsiz
        }
 #endif
 
+
+#ifdef WIN32
+       // historical behavior...
+       if (userdirmode == USERDIRMODE_NOHOME && strcmp(gamedirname1, "id1"))
+               return 0; // don't bother checking if the basedir folder is writable, it's annoying...  unless it is Quake on Windows where NOHOME is the default preferred and we have to check for an error case
+#endif
        // see if we can write to this path (note: won't create path)
 #if _MSC_VER >= 1400
        _sopen_s(&fd, va("%s%s/config.cfg", userdir, gamedirname1), O_WRONLY | O_CREAT, _SH_DENYNO, _S_IREAD | _S_IWRITE); // note: no O_TRUNC here!
@@ -1918,8 +1927,7 @@ void FS_Init (void)
 #ifdef DP_FS_BASEDIR
                strlcpy(fs_basedir, DP_FS_BASEDIR, sizeof(fs_basedir));
 #elif defined(MACOSX)
-               // FIXME: is there a better way to find the directory outside the .app?
-               // FIXME: check if game data is inside .app bundle
+               // FIXME: is there a better way to find the directory outside the .app, without using Objective-C?
                if (strstr(com_argv[0], ".app/"))
                {
                        char *split;
@@ -1927,9 +1935,23 @@ void FS_Init (void)
                        split = strstr(fs_basedir, ".app/");
                        if (split)
                        {
-                               while (split > fs_basedir && *split != '/')
-                                       split--;
-                               *split = 0;
+                               struct stat statresult;
+                               // truncate to just after the .app/
+                               split[5] = 0;
+                               // see if gamedir exists in Resources
+                               if (stat(va("%s/Contents/Resources/%s", fs_basedir, gamedirname1), &statresult) == 0)
+                               {
+                                       // found gamedir inside Resources, use it
+                                       strlcat(fs_basedir, "Contents/Resources/", sizeof(fs_basedir));
+                               }
+                               else
+                               {
+                                       // no gamedir found in Resources, gamedir is probably
+                                       // outside the .app, remove .app part of path
+                                       while (split > fs_basedir && *split != '/')
+                                               split--;
+                                       *split = 0;
+                               }
                        }
                }
 #endif
@@ -3490,7 +3512,7 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet)
 
        if (resultlist.numstrings)
        {
-               stringlistsort(&resultlist);
+               stringlistsort(&resultlist, true);
                numfiles = resultlist.numstrings;
                numchars = 0;
                for (resultlistindex = 0;resultlistindex < resultlist.numstrings;resultlistindex++)
@@ -3594,7 +3616,7 @@ int FS_ListDirectory(const char *pattern, int oneperline)
 static void FS_ListDirectoryCmd (const char* cmdname, int oneperline)
 {
        const char *pattern;
-       if (Cmd_Argc() > 3)
+       if (Cmd_Argc() >= 3)
        {
                Con_Printf("usage:\n%s [path/pattern]\n", cmdname);
                return;