Fix broken replay files from computer crashes
Thanks amdgpu.
This commit is contained in:
parent
8707b5281b
commit
bd72b7bf3a
|
@ -0,0 +1,3 @@
|
|||
Compile_Command = "make -f " + Project_Root + "Makefile";
|
||||
Run_Command = Project_Root + "minilauncher4slippi";
|
||||
Cleanup_Command = "";
|
23
replay.c
23
replay.c
|
@ -94,7 +94,7 @@ ubjson_search(unsigned char* buf, long length, char const* key, long* offset)
|
|||
static int
|
||||
parse_replay(struct replay* rpy)
|
||||
{
|
||||
unsigned char buf[1024] = {0};
|
||||
unsigned char buf[4096] = {0};
|
||||
char* filename;
|
||||
asprintf(&filename, "%s%s", replays_dir, rpy->filename);
|
||||
FILE* SLP = fopen(filename, "r");
|
||||
|
@ -105,13 +105,15 @@ parse_replay(struct replay* rpy)
|
|||
}
|
||||
// We used stat at some point, but a filename comparison is easier to write
|
||||
//assert(stat(filename, &(rpy->attr)) == 0);
|
||||
|
||||
long data_skip;
|
||||
|
||||
long filesize = fsize(SLP);
|
||||
|
||||
// Skip begin header and raw data
|
||||
fseek(SLP, 11, SEEK_CUR);
|
||||
fread(buf, 1, 4, SLP);
|
||||
fseek(SLP, dec_uint_be(buf, 4), SEEK_CUR);
|
||||
fseek(SLP, (data_skip = dec_uint_be(buf, 4)), SEEK_CUR);
|
||||
fseek(SLP, -6, SEEK_CUR);
|
||||
fread(buf, 1, 1, SLP);
|
||||
fseek(SLP, 5, SEEK_CUR);
|
||||
|
@ -119,6 +121,13 @@ parse_replay(struct replay* rpy)
|
|||
|
||||
// debug
|
||||
long length = filesize - ftell(SLP);
|
||||
// Sometimes, your computer will crash (this happened to me :^) and the file
|
||||
// will of course, just be corrupted or F-ed up
|
||||
if (length > 4096)
|
||||
{
|
||||
goto abort;
|
||||
}
|
||||
|
||||
fread(buf, 1, length, SLP);
|
||||
long off;
|
||||
char* bufx = buf;
|
||||
|
@ -138,9 +147,15 @@ parse_replay(struct replay* rpy)
|
|||
rpy->p2code = p2code;
|
||||
|
||||
//printf("Reading %s\n", filename);
|
||||
abort:
|
||||
fclose(SLP);
|
||||
return 0;
|
||||
abort:
|
||||
rpy->p1 = NULL;
|
||||
rpy->p1code = NULL;
|
||||
rpy->p2 = NULL;
|
||||
rpy->p2code = NULL;
|
||||
fclose(SLP);
|
||||
return 3;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -368,7 +383,7 @@ tab_replays_setup(Evas_Object* parent)
|
|||
i, // Item data
|
||||
NULL, // Parent item for trees, NULL if none
|
||||
ELM_GENLIST_ITEM_TREE, // Item type; this is the common one
|
||||
NULL, // Callback on selection of the item
|
||||
_item_select_cb, // Callback on selection of the item
|
||||
(long)i // Data for that callback function
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue