summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorAlexander Levin <al.le@rockbox.org>2009-06-24 21:14:28 +0000
committerAlexander Levin <al.le@rockbox.org>2009-06-24 21:14:28 +0000
commit1f64522a43dbab91fb8273ed5a9ffbcdc907438f (patch)
tree38188dce3ddc497b14caa96b58924f697b9bdd17 /apps
parent8acc86c036430707ec36d1bfc4366ff8e45da5c6 (diff)
downloadrockbox-1f64522a43dbab91fb8273ed5a9ffbcdc907438f.zip
rockbox-1f64522a43dbab91fb8273ed5a9ffbcdc907438f.tar.gz
rockbox-1f64522a43dbab91fb8273ed5a9ffbcdc907438f.tar.bz2
rockbox-1f64522a43dbab91fb8273ed5a9ffbcdc907438f.tar.xz
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
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/solitaire.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/apps/plugins/solitaire.c b/apps/plugins/solitaire.c
index 80ef1af..69216ce 100644
--- a/apps/plugins/solitaire.c
+++ b/apps/plugins/solitaire.c
@@ -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 */