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 checksum, retval;
|
||||
|
||||
int fd = open_save_file( O_RDONLY );
|
||||
int checksum;
|
||||
if( fd < 0 )
|
||||
return -1;
|
||||
|
||||
retval = 0; /* Assume good case */
|
||||
if( ( rb->lseek( fd, -sizeof( int ), SEEK_END ) == -((ssize_t)sizeof( int ))-1 )
|
||||
|| ( rb->read( fd, &checksum, sizeof( int ) ) < ((ssize_t)sizeof( int )) )
|
||||
|| ( 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, stacks, SUITS * sizeof( int ), &checksum ) )
|
||||
{
|
||||
rb->close( fd );
|
||||
rb->splash( 2*HZ, "Error while loading saved game. Aborting." );
|
||||
delete_save_file();
|
||||
return -2;
|
||||
retval = -2;
|
||||
}
|
||||
rb->close( fd );
|
||||
if( checksum != 42 )
|
||||
else if( checksum != 42 )
|
||||
{
|
||||
rb->splash( 2*HZ, "Save file was corrupted. Aborting." );
|
||||
delete_save_file();
|
||||
return -3;
|
||||
retval = -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) */
|
||||
while( ( result = solitaire( result ) ) == SOLITAIRE_WIN );
|
||||
|
||||
if( result == SOLITAIRE_QUIT )
|
||||
delete_save_file();
|
||||
else /* result == SOLITAIRE_USB || result == SOLITAIRE_SAVE_AND_QUIT */
|
||||
if( result != SOLITAIRE_QUIT )
|
||||
/* result == SOLITAIRE_USB || result == SOLITAIRE_SAVE_AND_QUIT */
|
||||
save_game();
|
||||
|
||||
if (rb->memcmp(&sol, &sol_disk, sizeof(sol))) /* save settings if changed */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue