Check for possible corrupt save files and prevent loading.
This commit is contained in:
parent
3a99531a04
commit
224952a962
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: Blob Wars : Attrition\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2018-04-24 19:04:13+0100\n"
|
||||
"POT-Creation-Date: 2018-04-29 07:46:49+0100\n"
|
||||
"PO-Revision-Date: ???\n"
|
||||
"Last-Translator: ???\n"
|
||||
"Language-Team: ???\n"
|
||||
|
@ -265,6 +265,12 @@ msgstr ""
|
|||
msgid "Cells: %d / %d"
|
||||
msgstr ""
|
||||
|
||||
msgid "! Corrupt data"
|
||||
msgstr ""
|
||||
|
||||
msgid "- empty -"
|
||||
msgstr ""
|
||||
|
||||
msgid "This is an information point. Bob can stand by them for a few moments to see what they have to say. There are many scattered throughout this tutorial map, to help you learn how to play. They will also appear from time to time during the actual game. Stand by them for a short time, to get more information. If you get lost, tap the radar icon in the top left, to view a map of the local area."
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -429,5 +429,7 @@ enum
|
|||
ST_HUB_KEYS,
|
||||
ST_HUB_HEARTS,
|
||||
ST_HUB_CELLS,
|
||||
ST_CORRUPT_SAVE,
|
||||
ST_EMPTY_SAVE,
|
||||
ST_MAX
|
||||
};
|
||||
|
|
|
@ -296,6 +296,8 @@ void loadGame(int slot)
|
|||
|
||||
root = cJSON_Parse(text);
|
||||
|
||||
if (root)
|
||||
{
|
||||
game.cells = cJSON_GetObjectItem(root, "cells")->valueint;
|
||||
game.hearts = cJSON_GetObjectItem(root, "hearts")->valueint;
|
||||
|
||||
|
@ -338,6 +340,11 @@ void loadGame(int slot)
|
|||
}
|
||||
|
||||
cJSON_Delete(root);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Corrupt save file\n");
|
||||
}
|
||||
|
||||
free(text);
|
||||
}
|
||||
|
@ -482,6 +489,8 @@ char *getSaveWidgetLabel(char *filename)
|
|||
|
||||
root = cJSON_Parse(text);
|
||||
|
||||
if (root)
|
||||
{
|
||||
statsJSON = cJSON_GetObjectItem(root, "stats");
|
||||
|
||||
memset(stats, 0, sizeof(int) * STAT_MAX);
|
||||
|
@ -498,12 +507,13 @@ char *getSaveWidgetLabel(char *filename)
|
|||
|
||||
cJSON_Delete(root);
|
||||
|
||||
free(text);
|
||||
|
||||
gameDone = stats[STAT_MIAS_RESCUED] + stats[STAT_TARGETS_DEFEATED] + stats[STAT_KEYS_FOUND] + stats[STAT_HEARTS_FOUND] + stats[STAT_CELLS_FOUND];
|
||||
gameTotal = game.totalMIAs + game.totalTargets + game.totalKeys + game.totalHearts + game.totalCells;
|
||||
|
||||
sprintf(label, "%d%%%% - %s", getPercent(gameDone, gameTotal), timeToString(stats[STAT_TIME_PLAYED], 1));
|
||||
}
|
||||
|
||||
free(text);
|
||||
|
||||
return label;
|
||||
}
|
||||
|
|
|
@ -208,10 +208,16 @@ static void populateSaveSlotWidgets(void)
|
|||
{
|
||||
strcpy(save[i]->label, getSaveWidgetLabel(filename));
|
||||
save[i]->value[0] = 1;
|
||||
|
||||
if (strlen(save[i]->label) == 0)
|
||||
{
|
||||
STRNCPY(save[i]->label, app.strings[ST_CORRUPT_SAVE], MAX_NAME_LENGTH);
|
||||
save[i]->value[0] = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(save[i]->label, "(empty)");
|
||||
STRNCPY(save[i]->label, app.strings[ST_EMPTY_SAVE], MAX_NAME_LENGTH);
|
||||
save[i]->value[0] = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -93,4 +93,7 @@ void initStrings(void)
|
|||
app.strings[ST_HUB_KEYS] = _("Keys: %d / %d");
|
||||
app.strings[ST_HUB_HEARTS] = _("Hearts: %d / %d");
|
||||
app.strings[ST_HUB_CELLS] = _("Cells: %d / %d");
|
||||
|
||||
app.strings[ST_CORRUPT_SAVE] = _("! Corrupt data");
|
||||
app.strings[ST_EMPTY_SAVE] = _("- empty -");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue