Skip to content

Commit 2baa808

Browse files
committed
Drag and drop support for maps, mods, savegames and demos
1 parent 352ec9f commit 2baa808

File tree

3 files changed

+107
-2
lines changed

3 files changed

+107
-2
lines changed

Quake/common.c

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,8 +1231,8 @@ being registered.
12311231
*/
12321232
static void COM_CheckRegistered (void)
12331233
{
1234-
int h;
1235-
int i;
1234+
int h;
1235+
int i;
12361236

12371237
COM_OpenFile ("gfx/pop.lmp", &h, NULL);
12381238

@@ -2271,6 +2271,104 @@ void COM_InitFilesystem (void) // johnfitz -- modified based on topaz's tutorial
22712271
COM_CheckRegistered ();
22722272
}
22732273

2274+
static qboolean switch_mod (char *mod_name)
2275+
{
2276+
if (q_strcasecmp (mod_name, GAMENAME)) // only switch for stuff outside id1
2277+
{
2278+
qboolean found = false;
2279+
2280+
for (filelist_item_t *mod = modlist; mod; mod = mod->next)
2281+
if (!q_strcasecmp (mod_name, mod->name))
2282+
found = true;
2283+
2284+
if (!found)
2285+
{
2286+
Con_Warning ("mod %s not in search path\n", mod_name);
2287+
return false;
2288+
}
2289+
2290+
const char *games = COM_GetGameNames (true);
2291+
char *pos = strstr (games, mod_name);
2292+
2293+
if (!pos || *(pos - 1) != ';' || (*(pos + strlen (mod_name)) != ';' && *(pos + strlen (mod_name)) != 0))
2294+
{
2295+
Cbuf_AddText ("game \"");
2296+
Cbuf_AddText (mod_name);
2297+
Cbuf_AddText ("\"\n");
2298+
}
2299+
}
2300+
return true;
2301+
}
2302+
2303+
/*
2304+
=================
2305+
COM_RunPath
2306+
2307+
Tries to determine what to do with a path (mods, demos, bsps or savegames), switches mod if needed
2308+
=================
2309+
*/
2310+
void COM_RunPath (char *in_path)
2311+
{
2312+
char *path = q_strdup (in_path);
2313+
char *path1 = "";
2314+
char *path2 = "";
2315+
char *path3 = path;
2316+
char *c = path;
2317+
while (*c)
2318+
{
2319+
if (*c == '\\' || *c == '/')
2320+
{
2321+
path1 = path2;
2322+
path2 = path3;
2323+
path3 = c + 1;
2324+
*c = 0;
2325+
}
2326+
++c;
2327+
}
2328+
const char *ext = COM_FileGetExtension (path3);
2329+
if (!q_strcasecmp (ext, "bsp"))
2330+
{
2331+
if (q_strcasecmp (path2, "maps") || !q_strcasecmp (path1, "") || !switch_mod (path1))
2332+
{
2333+
Con_Warning ("map not in maps path\n");
2334+
Mem_Free (path);
2335+
return;
2336+
}
2337+
Cbuf_AddText ("map \"");
2338+
Cbuf_AddText (path3);
2339+
Cbuf_AddText ("\"\n");
2340+
}
2341+
else if (!q_strcasecmp (ext, "sav"))
2342+
{
2343+
if (!q_strcasecmp (path2, "") || !switch_mod (path2))
2344+
{
2345+
Con_Warning ("savegame not in mod path\n");
2346+
Mem_Free (path);
2347+
return;
2348+
}
2349+
Cbuf_AddText ("load \"");
2350+
Cbuf_AddText (path3);
2351+
Cbuf_AddText ("\"\n");
2352+
}
2353+
else if (!q_strcasecmp (ext, "dem"))
2354+
{
2355+
if (!q_strcasecmp (path2, "") || !switch_mod (path2))
2356+
{
2357+
Con_Warning ("demo not in mod path\n");
2358+
Mem_Free (path);
2359+
return;
2360+
}
2361+
Cbuf_AddText ("playdemo \"");
2362+
Cbuf_AddText (path3);
2363+
Cbuf_AddText ("\"\n");
2364+
}
2365+
else if (Sys_FileType (in_path) == FS_ENT_DIRECTORY)
2366+
switch_mod (path3);
2367+
else
2368+
Con_Warning ("unrecognized file type %s\n", in_path);
2369+
Mem_Free (path);
2370+
}
2371+
22742372
/* The following FS_*() stdio replacements are necessary if one is
22752373
* to perform non-sequential reads on files reopened on pak files
22762374
* because we need the bookkeeping about file start/end positions.

Quake/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ const char *COM_FileGetExtension (const char *in); /* doesn't return NULL */
227227
void COM_ExtractExtension (const char *in, char *out, size_t outsize);
228228
void COM_CreatePath (char *path);
229229

230+
void COM_RunPath (char *path);
231+
230232
char *va (const char *format, ...) FUNC_PRINTF (1, 2);
231233
// does a varargs printf into a temp buffer
232234

Quake/in_sdl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,11 @@ void IN_SendKeyEvents (void)
10011001
Con_DPrintf ("Ignoring SDL_CONTROLLERDEVICEREMAPPED\n");
10021002
break;
10031003

1004+
case SDL_DROPFILE:
1005+
COM_RunPath (event.drop.file);
1006+
SDL_free (event.drop.file);
1007+
break;
1008+
10041009
case SDL_QUIT:
10051010
CL_Disconnect ();
10061011
Sys_Quit ();

0 commit comments

Comments
 (0)