From 411cb6116e8667b030752c11b5f7991b57c1ebe7 Mon Sep 17 00:00:00 2001
From: Rudolf Polzer <divVerent@xonotic.org>
Date: Thu, 24 Sep 2015 14:28:52 -0400
Subject: [PATCH] More changes for httpfs: if a .packs-only file exists, do not
 try to look inside a directory; add a flag -http_cache_content.

---
 filematch.c |  1 -
 fs.c        | 37 ++++++++++++++++++++++++++-----------
 sys_sdl.c   | 15 ++++++++++++---
 3 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/filematch.c b/filematch.c
index ae51599b..573b8447 100644
--- a/filematch.c
+++ b/filematch.c
@@ -219,7 +219,6 @@ void listdirectory(stringlist_t *list, const char *basepath, const char *path)
 			if (q == NULL)
 				break;
 			*q = 0;
-                        Con_Printf("Got file: %s\n", p);
 			adddirentry(list, path, p);
 			p = q + 1;
 		}
diff --git a/fs.c b/fs.c
index 550503cb..2a471a2d 100644
--- a/fs.c
+++ b/fs.c
@@ -1240,11 +1240,6 @@ static void FS_AddGameDirectory (const char *dir, qboolean iscache)
 	stringlist_t list;
 	searchpath_t *search;
 
-	if (iscache)
-		strlcpy (fs_gamedir, dir, sizeof (fs_gamedir));
-	else
-		strlcpy (fs_gamecachedir, dir, sizeof (fs_gamedir));
-
 	stringlistinit(&list);
 	listdirectory(&list, "", dir);
 	stringlistsort(&list, false);
@@ -1267,14 +1262,34 @@ static void FS_AddGameDirectory (const char *dir, qboolean iscache)
 		}
 	}
 
+	// test if we want to add the dir itself too
+	qboolean add_unpacked = true;
+	for (i = 0;i < list.numstrings;i++)
+	{
+		if (!strcasecmp(list.strings[i] + strlen(dir), ".packs-only"))
+		{
+			Con_Printf("Found %s/.packs-only file - not loading other files from there.", dir);
+			add_unpacked = false;
+		}
+	}
+
 	stringlistfreecontents(&list);
 
-	// Add the directory to the search path
-	// (unpacked files have the priority over packed files)
-	search = (searchpath_t *)Mem_Alloc(fs_mempool, sizeof(searchpath_t));
-	strlcpy (search->filename, dir, sizeof (search->filename));
-	search->next = fs_searchpaths;
-	fs_searchpaths = search;
+	if (add_unpacked)
+	{
+		// Add the directory to the search path
+		// (unpacked files have the priority over packed files)
+		search = (searchpath_t *)Mem_Alloc(fs_mempool, sizeof(searchpath_t));
+		strlcpy (search->filename, dir, sizeof (search->filename));
+		search->next = fs_searchpaths;
+		fs_searchpaths = search;
+
+		// Register the directory as a writable path.
+		if (iscache)
+			strlcpy (fs_gamedir, dir, sizeof (fs_gamedir));
+		else
+			strlcpy (fs_gamecachedir, dir, sizeof (fs_gamedir));
+	}
 }
 
 
diff --git a/sys_sdl.c b/sys_sdl.c
index 2ba791b6..34ceb246 100644
--- a/sys_sdl.c
+++ b/sys_sdl.c
@@ -205,12 +205,21 @@ void Sys_InitConsole (void)
 #include <sys/mount.h>
 static void NaCl_Init(void)
 {
+	char vabuf[1024];
+
 	mount("", "/dev", "dev", 0, "");
 	mount("", "/.config", "html5fs", 0, "type=PERSISTENT,expected_size=8388608");
 	mount("", "/.cache", "html5fs", 0, "type=TEMPORARY,expected_size=1073741824");
-	mount("", "/http", "httpfs", 0, "cache_stat=true,cache_content=false");
-	int fd = open("/dev/console0", O_WRONLY, 0644);
-	outfd = fd;
+
+	const char *http_root = "";
+	int i = COM_CheckParm("-http_root");
+	if (i && i < com_argc - 1)
+		http_root = com_argv[i + 1];
+	int cache_content = COM_CheckParm("-http_cache_content");
+
+	mount(http_root, "/http", "httpfs", 0, va(vabuf, sizeof(vabuf),
+		"cache_stat=true,cache_content=%s,allow_cross_origin_requests=true",
+		cache_content ? "true" : "false"));
 }
 #endif
 
-- 
2.39.5