simplify lump filters handling, convert slashes for zip paths

This commit is contained in:
Roman Fomin 2024-05-26 00:30:49 +07:00
parent 49113c9d85
commit 97631fe0b9
2 changed files with 72 additions and 37 deletions

View File

@ -113,16 +113,12 @@ static struct
GameMode_t mode; GameMode_t mode;
GameMission_t mission; GameMission_t mission;
} filters[] = { } filters[] = {
{"filter/doom", indetermined, none }, {"doom.id.doom1", shareware, doom },
{"filter/doom.id", indetermined, doom }, {"doom.id.doom1.registered", registered, doom },
{"filter/doom.id.doom1", indetermined, doom }, {"doom.id.doom1.ultimate", retail, doom },
{"filter/doom.id.doom1.registered", registered, doom }, {"doom.id.doom2.commercial", commercial, doom2 },
{"filter/doom.id.doom1.ultimate", retail, doom }, {"doom.id.doom2.plutonia", commercial, pack_plut},
{"filter/doom.id", indetermined, doom2 }, {"doom.id.doom2.tnt", commercial, pack_tnt },
{"filter/doom.id.doom2", indetermined, doom2 },
{"filter/doom.id.doom2.commercial", commercial, doom2 },
{"filter/doom.id.doom2.plutonia", commercial, pack_plut},
{"filter/doom.id.doom2.tnt", commercial, pack_tnt },
}; };
w_module_t *modules[] = w_module_t *modules[] =
@ -131,15 +127,35 @@ w_module_t *modules[] =
&w_file_module, &w_file_module,
}; };
static void AddDirs(w_module_t *module, w_handle_t handle, const char *base)
{
module->AddDir(handle, base, NULL, NULL);
for (int i = 0; i < arrlen(subdirs); ++i)
{
if (base[0] == '.')
{
module->AddDir(handle, subdirs[i].dir, subdirs[i].start_marker,
subdirs[i].end_marker);
}
else
{
char *s = M_StringJoin(base, DIR_SEPARATOR_S, subdirs[i].dir, NULL);
module->AddDir(handle, s, subdirs[i].start_marker,
subdirs[i].end_marker);
free(s);
}
}
}
boolean W_AddPath(const char *path) boolean W_AddPath(const char *path)
{ {
w_handle_t handle = {0}; w_handle_t handle = {0};
w_type_t result = W_NONE;
w_module_t *active_module = NULL; w_module_t *active_module = NULL;
for (int i = 0; i < arrlen(modules); ++i) for (int i = 0; i < arrlen(modules); ++i)
{ {
result = modules[i]->Open(path, &handle); w_type_t result = modules[i]->Open(path, &handle);
if (result == W_FILE) if (result == W_FILE)
{ {
@ -152,44 +168,44 @@ boolean W_AddPath(const char *path)
} }
} }
if (result == W_NONE || !active_module) if (!active_module)
{ {
return false; return false;
} }
active_module->AddDir(handle, ".", NULL, NULL); AddDirs(active_module, handle, ".");
for (int i = 0; i < arrlen(subdirs); ++i) char *dir = NULL;
{
active_module->AddDir(handle, subdirs[i].dir, subdirs[i].start_marker,
subdirs[i].end_marker);
}
for (int i = 0; i < arrlen(filters); ++i) for (int i = 0; i < arrlen(filters); ++i)
{ {
if (filters[i].mode != indetermined && filters[i].mode != gamemode) if (filters[i].mode == gamemode && filters[i].mission == gamemission)
{ {
continue; dir = M_StringJoin("filter", DIR_SEPARATOR_S, filters[i].dir, NULL);
} break;
if (filters[i].mission != none && filters[i].mission != gamemission
&& !(gamemission > doom2 && filters[i].mission == doom2))
{
continue;
}
for (int j = 0; j < arrlen(subdirs); ++j)
{
char *s = M_StringJoin(filters[i].dir, "/", subdirs[j].dir, NULL);
active_module->AddDir(handle, s, subdirs[j].start_marker,
subdirs[j].end_marker);
free(s);
} }
} }
if (!dir)
{
return true; return true;
} }
for (char *p = dir; *p; ++p)
{
if (*p == '.')
{
*p = '\0';
AddDirs(active_module, handle, dir);
*p = '.';
}
}
AddDirs(active_module, handle, dir);
free(dir);
return true;
}
// jff 1/23/98 Create routines to reorder the master directory // jff 1/23/98 Create routines to reorder the master directory
// putting all flats into one marked block, and all sprites into another. // putting all flats into one marked block, and all sprites into another.

View File

@ -21,6 +21,21 @@
#include "miniz.h" #include "miniz.h"
static char *ConvertSlashes(const char *path)
{
char *result = M_StringDuplicate(path);
for (char *p = result; *p; ++p)
{
if (*p == '\\')
{
*p = '/';
}
}
return result;
}
static void AddWadInMem(mz_zip_archive *zip, const char *name, int index, static void AddWadInMem(mz_zip_archive *zip, const char *name, int index,
size_t data_size) size_t data_size)
{ {
@ -95,6 +110,8 @@ static void W_ZIP_AddDir(w_handle_t handle, const char *path,
{ {
mz_zip_archive *zip = handle.p1.zip; mz_zip_archive *zip = handle.p1.zip;
char *local_path = ConvertSlashes(path);
int startlump = numlumps; int startlump = numlumps;
for (int i = 0; i < mz_zip_reader_get_num_files(zip); ++i) for (int i = 0; i < mz_zip_reader_get_num_files(zip); ++i)
@ -108,7 +125,7 @@ static void W_ZIP_AddDir(w_handle_t handle, const char *path,
} }
char *name = M_DirName(stat.m_filename); char *name = M_DirName(stat.m_filename);
int result = strcasecmp(name, path); int result = strcasecmp(name, local_path);
free(name); free(name);
if (result) if (result)
{ {
@ -148,6 +165,8 @@ static void W_ZIP_AddDir(w_handle_t handle, const char *path,
{ {
W_AddMarker(end_marker); W_AddMarker(end_marker);
} }
free(local_path);
} }
static mz_zip_archive **zips = NULL; static mz_zip_archive **zips = NULL;