}
#endif
+
+/* This code seems to have originally been written with the assumption that
+ * read(..., n) returns n on success. This is not the case (refer to
+ * <https://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html>).
+ * Ditto for write.
+ */
+
+/*
+====================
+ReadAll
+
+Read exactly length bytes from fd into buf. If end of file is reached,
+the number of bytes read is returned. If an error occurred, that error
+is returned. Note that if an error is returned, any previously read
+data is lost.
+====================
+*/
+static fs_offset_t ReadAll(const filedesc_t fd, void *const buf, const size_t length)
+{
+ char *const p = (char *)buf;
+ size_t cursor = 0;
+ do
+ {
+ const fs_offset_t result = FILEDESC_READ(fd, p + cursor, length - cursor);
+ if (result < 0) // Error
+ return result;
+ if (result == 0) // EOF
+ break;
+ cursor += result;
+ } while (cursor < length);
+ return cursor;
+}
+
+/*
+====================
+WriteAll
+
+Write exactly length bytes to fd from buf.
+If an error occurred, that error is returned.
+====================
+*/
+static fs_offset_t WriteAll(const filedesc_t fd, const void *const buf, const size_t length)
+{
+ const char *const p = (const char *)buf;
+ size_t cursor = 0;
+ do
+ {
+ const fs_offset_t result = FILEDESC_WRITE(fd, p + cursor, length - cursor);
+ if (result < 0) // Error
+ return result;
+ cursor += result;
+ } while (cursor < length);
+ return cursor;
+}
+
+#undef FILEDESC_READ
+#define FILEDESC_READ ReadAll
+#undef FILEDESC_WRITE
+#define FILEDESC_WRITE WriteAll
+
/** \page fs File System
All of Quake's data access is through a hierchal file system, but the contents
cvar_t scr_screenshot_name = {CF_CLIENT | CF_PERSISTENT, "scr_screenshot_name","dp", "prefix name for saved screenshots (changes based on -game commandline, as well as which game mode is running; the date is encoded using strftime escapes)"};
cvar_t fs_empty_files_in_pack_mark_deletions = {CF_CLIENT | CF_SERVER, "fs_empty_files_in_pack_mark_deletions", "0", "if enabled, empty files in a pak/pk3 count as not existing but cancel the search in further packs, effectively allowing patch pak/pk3 files to 'delete' files"};
+cvar_t fs_unload_dlcache = {CF_CLIENT, "fs_unload_dlcache", "1", "if enabled, unload dlcache's loaded pak/pk3 files when changing server and/or map WARNING: disabling unloading can cause servers to override assets of other servers, \"memory leaking\" by dlcache assets never unloading and many more issues"};
cvar_t cvar_fs_gamedir = {CF_CLIENT | CF_SERVER | CF_READONLY | CF_PERSISTENT, "fs_gamedir", "", "the list of currently selected gamedirs (use the 'gamedir' command to change this)"};
#endif
#ifdef WIN32
-static HRESULT (WINAPI *qSHGetFolderPath) (HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath);
+static HRESULT (WINAPI *qSHGetFolderPath) (HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath);
static dllfunction_t shfolderfuncs[] =
{
{"SHGetFolderPathW", (void **) &qSHGetFolderPath},
};
static dllhandle_t shfolder_dll = NULL;
-const GUID qFOLDERID_SavedGames = {0x4C5C32FF, 0xBB9D, 0x43b0, {0xB5, 0xB4, 0x2D, 0x72, 0xE5, 0x4E, 0xAA, 0xA4}};
+const GUID qFOLDERID_SavedGames = {0x4C5C32FF, 0xBB9D, 0x43b0, {0xB5, 0xB4, 0x2D, 0x72, 0xE5, 0x4E, 0xAA, 0xA4}};
#define qREFKNOWNFOLDERID const GUID *
#define qKF_FLAG_CREATE 0x8000
#define qKF_FLAG_NO_ALIAS 0x1000
{
searchpath_t *search = fs_searchpaths, *searchprev = fs_searchpaths, *searchnext;
+ if (!fs_unload_dlcache.integer)
+ return;
+
while (search)
{
searchnext = search->next;
// add back the selfpack as new first item
FS_AddSelfPack();
- // set the default screenshot name to either the mod name or the
- // gamemode screenshot name
- if (strcmp(com_modname, gamedirname1))
- Cvar_SetQuick (&scr_screenshot_name, com_modname);
- else
- Cvar_SetQuick (&scr_screenshot_name, gamescreenshotname);
-
+ if (cls.state != ca_dedicated)
+ {
+ // set the default screenshot name to either the mod name or the
+ // gamemode screenshot name
+ if (strcmp(com_modname, gamedirname1))
+ Cvar_SetQuick (&scr_screenshot_name, com_modname);
+ else
+ Cvar_SetQuick (&scr_screenshot_name, gamescreenshotname);
+ }
+
if((i = Sys_CheckParm("-modname")) && i < sys.argc - 1)
strlcpy(com_modname, sys.argv[i+1], sizeof(com_modname));
ret = FS_SysCheckGameDir(va(vabuf, sizeof(vabuf), "%s%s/", fs_basedir, gamedir), buf, sizeof(buf));
if(ret)
return ret;
-
+
return fs_checkgamedir_missing;
}
continue;
if(!*info)
continue;
- stringlistappend(&list2, list.strings[i]);
+ stringlistappend(&list2, list.strings[i]);
}
stringlistfreecontents(&list);
#if _MSC_VER >= 1400
size_t homedirwlen;
#endif
- TCHAR mydocsdir[MAX_PATH + 1];
+ wchar_t mydocsdirw[WSTRBUF];
+ char mydocsdir[WSTRBUF];
wchar_t *savedgamesdirw;
char savedgamesdir[WSTRBUF] = {0};
int fd;
if (!shfolder_dll)
Sys_LoadDependency(shfolderdllnames, &shfolder_dll, shfolderfuncs);
mydocsdir[0] = 0;
- if (qSHGetFolderPath && qSHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, mydocsdir) == S_OK)
+ if (qSHGetFolderPath && qSHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, mydocsdirw) == S_OK)
{
+ narrow(mydocsdirw, mydocsdir);
dpsnprintf(userdir, userdirsize, "%s/My Games/%s/", mydocsdir, gameuserdirname);
break;
}
{
Cvar_RegisterVariable (&scr_screenshot_name);
Cvar_RegisterVariable (&fs_empty_files_in_pack_mark_deletions);
+ Cvar_RegisterVariable (&fs_unload_dlcache);
Cvar_RegisterVariable (&cvar_fs_gamedir);
Cmd_AddCommand(CF_SHARED, "gamedir", FS_GameDir_f, "changes active gamedir list (can take multiple arguments), not including base directory (example usage: gamedir ctf)");
====================
FS_SanitizePath
-Sanitize path (replace non-portable characters
+Sanitize path (replace non-portable characters
with portable ones in-place, etc)
====================
*/
if(count < 0)
return NULL;
linkbuf[count] = 0;
-
+
// Now combine the paths...
mergeslash = strrchr(filename, '/');
mergestart = linkbuf;
{
Con_Printf("usage:\n%s <file>\n", Cmd_Argv(cmd, 0));
return;
- }
+ }
filename = Cmd_Argv(cmd, 1);
sp = FS_FindFile(filename, &index, true);
if (!sp) {
Mem_Free(tmp);
return NULL;
}
-
+
if(qz_deflateEnd(&strm) != Z_OK)
{
Con_Printf("FS_Deflate: deflateEnd failed\n");
memcpy(out, tmp, strm.total_out);
Mem_Free(tmp);
-
+
return out;
}
case Z_STREAM_END:
case Z_OK:
break;
-
+
case Z_STREAM_ERROR:
Con_Print("FS_Inflate: stream error!\n");
break;
default:
Con_Print("FS_Inflate: unknown error!\n");
break;
-
+
}
if(ret != Z_OK && ret != Z_STREAM_END)
{
Mem_Free(outbuf.data);
*inflated_size = (size_t)outbuf.cursize;
-
+
return out;
}