forked from len0rd/rockbox
Delete the save file immediately after loading it to avoid false tries at the end (part of FS#10138 by Teruaki Kawashima, minor modification by me)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21497 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
8acc86c036
commit
1f64522a43
1 changed files with 13 additions and 12 deletions
|
@ -1352,10 +1352,13 @@ int save_game( void )
|
||||||
|
|
||||||
int load_game( void )
|
int load_game( void )
|
||||||
{
|
{
|
||||||
|
int checksum, retval;
|
||||||
|
|
||||||
int fd = open_save_file( O_RDONLY );
|
int fd = open_save_file( O_RDONLY );
|
||||||
int checksum;
|
|
||||||
if( fd < 0 )
|
if( fd < 0 )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
retval = 0; /* Assume good case */
|
||||||
if( ( rb->lseek( fd, -sizeof( int ), SEEK_END ) == -((ssize_t)sizeof( int ))-1 )
|
if( ( rb->lseek( fd, -sizeof( int ), SEEK_END ) == -((ssize_t)sizeof( int ))-1 )
|
||||||
|| ( rb->read( fd, &checksum, sizeof( int ) ) < ((ssize_t)sizeof( int )) )
|
|| ( rb->read( fd, &checksum, sizeof( int ) ) < ((ssize_t)sizeof( int )) )
|
||||||
|| ( rb->lseek( fd, 0, SEEK_SET ) == -1 )
|
|| ( rb->lseek( fd, 0, SEEK_SET ) == -1 )
|
||||||
|
@ -1370,19 +1373,18 @@ int load_game( void )
|
||||||
|| save_read( fd, cols, COL_NUM * sizeof( int ), &checksum )
|
|| save_read( fd, cols, COL_NUM * sizeof( int ), &checksum )
|
||||||
|| save_read( fd, stacks, SUITS * sizeof( int ), &checksum ) )
|
|| save_read( fd, stacks, SUITS * sizeof( int ), &checksum ) )
|
||||||
{
|
{
|
||||||
rb->close( fd );
|
|
||||||
rb->splash( 2*HZ, "Error while loading saved game. Aborting." );
|
rb->splash( 2*HZ, "Error while loading saved game. Aborting." );
|
||||||
delete_save_file();
|
retval = -2;
|
||||||
return -2;
|
|
||||||
}
|
}
|
||||||
rb->close( fd );
|
else if( checksum != 42 )
|
||||||
if( checksum != 42 )
|
|
||||||
{
|
{
|
||||||
rb->splash( 2*HZ, "Save file was corrupted. Aborting." );
|
rb->splash( 2*HZ, "Save file was corrupted. Aborting." );
|
||||||
delete_save_file();
|
retval = -3;
|
||||||
return -3;
|
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
rb->close( fd );
|
||||||
|
delete_save_file();
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1931,9 +1933,8 @@ enum plugin_status plugin_start(const void* parameter )
|
||||||
* winning instead of quiting) */
|
* winning instead of quiting) */
|
||||||
while( ( result = solitaire( result ) ) == SOLITAIRE_WIN );
|
while( ( result = solitaire( result ) ) == SOLITAIRE_WIN );
|
||||||
|
|
||||||
if( result == SOLITAIRE_QUIT )
|
if( result != SOLITAIRE_QUIT )
|
||||||
delete_save_file();
|
/* result == SOLITAIRE_USB || result == SOLITAIRE_SAVE_AND_QUIT */
|
||||||
else /* result == SOLITAIRE_USB || result == SOLITAIRE_SAVE_AND_QUIT */
|
|
||||||
save_game();
|
save_game();
|
||||||
|
|
||||||
if (rb->memcmp(&sol, &sol_disk, sizeof(sol))) /* save settings if changed */
|
if (rb->memcmp(&sol, &sol_disk, sizeof(sol))) /* save settings if changed */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue