Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag and drop support for maps, mods, savegames and demos #596

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 100 additions & 2 deletions Quake/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1231,8 +1231,8 @@ being registered.
*/
static void COM_CheckRegistered (void)
{
int h;
int i;
int h;
int i;

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

Expand Down Expand Up @@ -2271,6 +2271,104 @@ void COM_InitFilesystem (void) // johnfitz -- modified based on topaz's tutorial
COM_CheckRegistered ();
}

static qboolean switch_mod (char *mod_name)
{
if (q_strcasecmp (mod_name, GAMENAME)) // only switch for stuff outside id1
{
qboolean found = false;

for (filelist_item_t *mod = modlist; mod; mod = mod->next)
if (!q_strcasecmp (mod_name, mod->name))
found = true;

if (!found)
{
Con_Warning ("mod %s not in search path\n", mod_name);
return false;
}

const char *games = COM_GetGameNames (true);
char *pos = strstr (games, mod_name);

if (!pos || *(pos - 1) != ';' || (*(pos + strlen (mod_name)) != ';' && *(pos + strlen (mod_name)) != 0))
{
Cbuf_AddText ("game \"");
Cbuf_AddText (mod_name);
Cbuf_AddText ("\"\n");
}
}
return true;
}

/*
=================
COM_RunPath

Tries to determine what to do with a path (mods, demos, bsps or savegames), switches mod if needed
=================
*/
void COM_RunPath (char *in_path)
{
char *path = q_strdup (in_path);
char *path1 = "";
char *path2 = "";
char *path3 = path;
char *c = path;
while (*c)
{
if (*c == '\\' || *c == '/')
{
path1 = path2;
path2 = path3;
path3 = c + 1;
*c = 0;
}
++c;
}
const char *ext = COM_FileGetExtension (path3);
if (!q_strcasecmp (ext, "bsp"))
{
if (q_strcasecmp (path2, "maps") || !q_strcasecmp (path1, "") || !switch_mod (path1))
{
Con_Warning ("map not in maps path\n");
Mem_Free (path);
return;
}
Cbuf_AddText ("map \"");
Cbuf_AddText (path3);
Cbuf_AddText ("\"\n");
}
else if (!q_strcasecmp (ext, "sav"))
{
if (!q_strcasecmp (path2, "") || !switch_mod (path2))
{
Con_Warning ("savegame not in mod path\n");
Mem_Free (path);
return;
}
Cbuf_AddText ("load \"");
Cbuf_AddText (path3);
Cbuf_AddText ("\"\n");
}
else if (!q_strcasecmp (ext, "dem"))
{
if (!q_strcasecmp (path2, "") || !switch_mod (path2))
{
Con_Warning ("demo not in mod path\n");
Mem_Free (path);
return;
}
Cbuf_AddText ("playdemo \"");
Cbuf_AddText (path3);
Cbuf_AddText ("\"\n");
}
else if (Sys_FileType (in_path) == FS_ENT_DIRECTORY)
switch_mod (path3);
else
Con_Warning ("unrecognized file type %s\n", in_path);
Mem_Free (path);
}

/* The following FS_*() stdio replacements are necessary if one is
* to perform non-sequential reads on files reopened on pak files
* because we need the bookkeeping about file start/end positions.
Expand Down
2 changes: 2 additions & 0 deletions Quake/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ const char *COM_FileGetExtension (const char *in); /* doesn't return NULL */
void COM_ExtractExtension (const char *in, char *out, size_t outsize);
void COM_CreatePath (char *path);

void COM_RunPath (char *path);

char *va (const char *format, ...) FUNC_PRINTF (1, 2);
// does a varargs printf into a temp buffer

Expand Down
5 changes: 5 additions & 0 deletions Quake/in_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,11 @@ void IN_SendKeyEvents (void)
Con_DPrintf ("Ignoring SDL_CONTROLLERDEVICEREMAPPED\n");
break;

case SDL_DROPFILE:
COM_RunPath (event.drop.file);
SDL_free (event.drop.file);
break;

case SDL_QUIT:
CL_Disconnect ();
Sys_Quit ();
Expand Down