1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 17:49:43 +01:00

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)
{

View file

@ -40,6 +40,10 @@ bool FILESYSTEM_loadTiXml2Document(const char *name, tinyxml2::XMLDocument& doc)
void FILESYSTEM_enumerateLevelDirFileNames(void (*callback)(const char* filename));
bool FILESYSTEM_levelDirHasError(void);
void FILESYSTEM_clearLevelDirError(void);
const char* FILESYSTEM_getLevelDirError(void);
bool FILESYSTEM_openDirectoryEnabled(void);
bool FILESYSTEM_openDirectory(const char *dname);

View file

@ -6478,7 +6478,9 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ )
menuyoff = 10;
break;
case Menu::errorloadinglevel:
case Menu::warninglevellist:
option("ok");
menuyoff = 50;
break;
}

View file

@ -36,6 +36,7 @@ namespace Menu
errornostart,
errorsavingsettings,
errorloadinglevel,
warninglevellist,
graphicoptions,
ed_settings,
ed_desc,

View file

@ -492,6 +492,10 @@ static void menuactionpress(void)
ed.getDirectoryData();
game.loadcustomlevelstats(); //Should only load a file if it's needed
game.createmenu(Menu::levellist);
if (FILESYSTEM_levelDirHasError())
{
game.createmenu(Menu::warninglevellist);
}
map.nexttowercolour();
break;
#if !defined(NO_EDITOR)
@ -1728,6 +1732,7 @@ static void menuactionpress(void)
map.nexttowercolour();
break;
case Menu::errorloadinglevel:
case Menu::warninglevellist:
music.playef(11);
game.returnmenu();
map.nexttowercolour();

View file

@ -1391,6 +1391,10 @@ static void menurender(void)
graphics.bigprint(-1, 45, "ERROR", tr, tg, tb, true);
graphics.PrintWrap(-1, 65, graphics.error, tr, tg, tb, true, 10, 304);
break;
case Menu::warninglevellist:
graphics.bigprint(-1, 45, "WARNING", tr, tg, tb, true);
graphics.PrintWrap(-1, 65, FILESYSTEM_getLevelDirError(), tr, tg, tb, true, 10, 304);
break;
default:
break;
}

View file

@ -229,6 +229,8 @@ void editorclass::getDirectoryData(void)
ListOfMetaData.clear();
FILESYSTEM_clearLevelDirError();
loadZips();
FILESYSTEM_enumerateLevelDirFileNames(levelMetaDataCallback);