Display improper zip structure message to non-console users

If a zip file is improperly structured, a message will be displayed when
the player loads the level list.

This will only display the last-displayed improper zip, because there
only needs to be one displayed at a time. Also because doing anything
more would most likely require heap allocation, and I don't want to do
that.
This commit is contained in:
Misa
2021-08-06 22:26:48 -07:00
committed by Ethan Lee
parent 8dc5d69ef3
commit 7699f5aaf1
7 changed files with 61 additions and 7 deletions

View File

@@ -2,6 +2,7 @@
#include <iterator>
#include <physfs.h>
#include <SDL.h>
#include <stdarg.h>
#include <stdio.h>
#include <string>
#include <tinyxml2.h>
@@ -346,6 +347,41 @@ static PHYSFS_EnumerateCallbackResult zipCheckCallback(
return PHYSFS_ENUM_OK;
}
static char levelDirError[256] = {'\0'};
static bool levelDirHasError = false;
bool FILESYSTEM_levelDirHasError(void)
{
return levelDirHasError;
}
void FILESYSTEM_clearLevelDirError(void)
{
levelDirHasError = false;
}
const char* FILESYSTEM_getLevelDirError(void)
{
return levelDirError;
}
static int setLevelDirError(const char* text, ...)
{
va_list list;
int retval;
levelDirHasError = true;
va_start(list, text);
retval = SDL_vsnprintf(levelDirError, sizeof(levelDirError), text, list);
va_end(list);
puts(levelDirError);
return retval;
}
/* For technical reasons, the level file inside a zip named LEVELNAME.zip must
* be named LEVELNAME.vvvvvv, else its custom assets won't work;
* if there are .vvvvvv files other than LEVELNAME.vvvvvv, they would be loaded
@@ -420,9 +456,8 @@ static bool checkZipStructure(const char* filename)
/* If no .vvvvvv files in zip, don't print warning. */
if (!success && zip_state.has_extension)
{
/* FIXME: How do we print this for non-terminal users? */
printf(
"%s.zip is not structured correctly! It is missing %s.vvvvvv.\n",
setLevelDirError(
"%s.zip is not structured correctly! It is missing %s.vvvvvv.",
base_name,
base_name
);
@@ -434,9 +469,8 @@ static bool checkZipStructure(const char* filename)
/* This message is redundant if the correct file already DOESN'T exist. */
if (file_exists && zip_state.other_level_files)
{
/* FIXME: How do we print this for non-terminal users? */
printf(
"%s.zip is not structured correctly! It has .vvvvvv file(s) other than %s.vvvvvv.\n",
setLevelDirError(
"%s.zip is not structured correctly! It has .vvvvvv file(s) other than %s.vvvvvv.",
base_name,
base_name
);
@@ -872,7 +906,9 @@ static PHYSFS_EnumerateCallbackResult enumerateCallback(
void FILESYSTEM_enumerateLevelDirFileNames(
void (*callback)(const char* filename)
) {
int success = PHYSFS_enumerate("levels", enumerateCallback, (void*) callback);
int success;
success = PHYSFS_enumerate("levels", enumerateCallback, (void*) callback);
if (success == 0)
{