summaryrefslogtreecommitdiff
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
parent8acc86c036430707ec36d1bfc4366ff8e45da5c6 (diff)
downloadrockbox-1f64522a43dbab91fb8273ed5a9ffbcdc907438f.tar.gz
rockbox-1f64522a43dbab91fb8273ed5a9ffbcdc907438f.zip
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
-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 80ef1af60d..69216cecba 100644
--- a/apps/plugins/solitaire.c
+++ b/apps/plugins/solitaire.c
@@ -1352,10 +1352,13 @@ int save_game( void )
1352 1352
1353int load_game( void ) 1353int load_game( void )
1354{ 1354{
1355 int checksum, retval;
1356
1355 int fd = open_save_file( O_RDONLY ); 1357 int fd = open_save_file( O_RDONLY );
1356 int checksum;
1357 if( fd < 0 ) 1358 if( fd < 0 )
1358 return -1; 1359 return -1;
1360
1361 retval = 0; /* Assume good case */
1359 if( ( rb->lseek( fd, -sizeof( int ), SEEK_END ) == -((ssize_t)sizeof( int ))-1 ) 1362 if( ( rb->lseek( fd, -sizeof( int ), SEEK_END ) == -((ssize_t)sizeof( int ))-1 )
1360 || ( rb->read( fd, &checksum, sizeof( int ) ) < ((ssize_t)sizeof( int )) ) 1363 || ( rb->read( fd, &checksum, sizeof( int ) ) < ((ssize_t)sizeof( int )) )
1361 || ( rb->lseek( fd, 0, SEEK_SET ) == -1 ) 1364 || ( rb->lseek( fd, 0, SEEK_SET ) == -1 )
@@ -1370,19 +1373,18 @@ int load_game( void )
1370 || save_read( fd, cols, COL_NUM * sizeof( int ), &checksum ) 1373 || save_read( fd, cols, COL_NUM * sizeof( int ), &checksum )
1371 || save_read( fd, stacks, SUITS * sizeof( int ), &checksum ) ) 1374 || save_read( fd, stacks, SUITS * sizeof( int ), &checksum ) )
1372 { 1375 {
1373 rb->close( fd );
1374 rb->splash( 2*HZ, "Error while loading saved game. Aborting." ); 1376 rb->splash( 2*HZ, "Error while loading saved game. Aborting." );
1375 delete_save_file(); 1377 retval = -2;
1376 return -2;
1377 } 1378 }
1378 rb->close( fd ); 1379 else if( checksum != 42 )
1379 if( checksum != 42 )
1380 { 1380 {
1381 rb->splash( 2*HZ, "Save file was corrupted. Aborting." ); 1381 rb->splash( 2*HZ, "Save file was corrupted. Aborting." );
1382 delete_save_file(); 1382 retval = -3;
1383 return -3;
1384 } 1383 }
1385 return 0; 1384
1385 rb->close( fd );
1386 delete_save_file();
1387 return retval;
1386} 1388}
1387 1389
1388/** 1390/**
@@ -1931,9 +1933,8 @@ enum plugin_status plugin_start(const void* parameter )
1931 * winning instead of quiting) */ 1933 * winning instead of quiting) */
1932 while( ( result = solitaire( result ) ) == SOLITAIRE_WIN ); 1934 while( ( result = solitaire( result ) ) == SOLITAIRE_WIN );
1933 1935
1934 if( result == SOLITAIRE_QUIT ) 1936 if( result != SOLITAIRE_QUIT )
1935 delete_save_file(); 1937 /* result == SOLITAIRE_USB || result == SOLITAIRE_SAVE_AND_QUIT */
1936 else /* result == SOLITAIRE_USB || result == SOLITAIRE_SAVE_AND_QUIT */
1937 save_game(); 1938 save_game();
1938 1939
1939 if (rb->memcmp(&sol, &sol_disk, sizeof(sol))) /* save settings if changed */ 1940 if (rb->memcmp(&sol, &sol_disk, sizeof(sol))) /* save settings if changed */