@@ -555,6 +555,33 @@ static void task_save_handler_finished(retro_task_t *task,
555
555
free (state );
556
556
}
557
557
558
+ void * get_serialized_data (const char * path , size_t serial_size )
559
+ {
560
+ retro_ctx_serialize_info_t serial_info ;
561
+ bool ret = false;
562
+ void * data = NULL ;
563
+
564
+ data = malloc (serial_size );
565
+
566
+ if (!data )
567
+ return NULL ;
568
+
569
+ RARCH_LOG ("%s: %d %s.\n" ,
570
+ msg_hash_to_str (MSG_STATE_SIZE ),
571
+ (int )serial_size ,
572
+ msg_hash_to_str (MSG_BYTES ));
573
+
574
+ serial_info .data = data ;
575
+ serial_info .size = serial_size ;
576
+ ret = core_serialize (& serial_info );
577
+ if ( !ret )
578
+ {
579
+ free (data ) ;
580
+ return NULL ;
581
+ }
582
+ return data ;
583
+ }
584
+
558
585
/**
559
586
* task_save_handler:
560
587
* @task : the task being worked on
@@ -576,9 +603,22 @@ static void task_save_handler(retro_task_t *task)
576
603
return ;
577
604
}
578
605
606
+ if (!state -> data )
607
+ {
608
+ state -> data = get_serialized_data (state -> path , state -> size ) ;
609
+ }
610
+
579
611
remaining = MIN (state -> size - state -> written , SAVE_STATE_CHUNK );
580
- written = (int )intfstream_write (state -> file ,
581
- (uint8_t * )state -> data + state -> written , remaining );
612
+
613
+ if ( state -> data )
614
+ {
615
+ written = (int )intfstream_write (state -> file ,
616
+ (uint8_t * )state -> data + state -> written , remaining );
617
+ }
618
+ else
619
+ {
620
+ written = 0 ;
621
+ }
582
622
583
623
state -> written += written ;
584
624
@@ -1134,6 +1174,7 @@ static void task_push_load_and_save_state(const char *path, void *data,
1134
1174
free (task );
1135
1175
}
1136
1176
1177
+
1137
1178
/**
1138
1179
* content_save_state:
1139
1180
* @path : path of saved state that shall be written to.
@@ -1144,85 +1185,62 @@ static void task_push_load_and_save_state(const char *path, void *data,
1144
1185
**/
1145
1186
bool content_save_state (const char * path , bool save_to_disk , bool autosave )
1146
1187
{
1147
- retro_ctx_serialize_info_t serial_info ;
1188
+ // retro_ctx_serialize_info_t serial_info;
1148
1189
retro_ctx_size_info_t info ;
1149
1190
bool ret = false;
1150
1191
void * data = NULL ;
1151
1192
1152
1193
core_serialize_size (& info );
1153
1194
1154
- RARCH_LOG ("%s: \"%s\".\n" ,
1155
- msg_hash_to_str (MSG_SAVING_STATE ),
1156
- path );
1157
-
1158
- if (info .size == 0 )
1159
- return false;
1160
-
1161
- data = malloc (info .size );
1162
-
1163
- if (!data )
1164
- return false;
1165
-
1166
- RARCH_LOG ("%s: %d %s.\n" ,
1167
- msg_hash_to_str (MSG_STATE_SIZE ),
1168
- (int )info .size ,
1169
- msg_hash_to_str (MSG_BYTES ));
1170
-
1171
- serial_info .data = data ;
1172
- serial_info .size = info .size ;
1173
- ret = core_serialize (& serial_info );
1174
-
1175
- if (ret )
1195
+ if (save_to_disk )
1176
1196
{
1177
- if (save_to_disk )
1197
+ if (filestream_exists ( path ) && ! autosave )
1178
1198
{
1179
- if (filestream_exists (path ) && !autosave )
1180
- {
1181
- /* Before overwritting the savestate file, load it into a buffer
1182
- to allow undo_save_state() to work */
1183
- /* TODO/FIXME - Use msg_hash_to_str here */
1184
- RARCH_LOG ("%s ...\n" ,
1185
- msg_hash_to_str (MSG_FILE_ALREADY_EXISTS_SAVING_TO_BACKUP_BUFFER ));
1199
+ /* Before overwritting the savestate file, load it into a buffer
1200
+ to allow undo_save_state() to work */
1201
+ /* TODO/FIXME - Use msg_hash_to_str here */
1202
+ RARCH_LOG ("%s ...\n" ,
1203
+ msg_hash_to_str (MSG_FILE_ALREADY_EXISTS_SAVING_TO_BACKUP_BUFFER ));
1186
1204
1187
- task_push_load_and_save_state (path , data , info .size , true, autosave );
1188
- }
1189
- else
1190
- task_push_save_state (path , data , info .size , autosave );
1205
+ task_push_load_and_save_state (path , data , info .size , true, autosave );
1191
1206
}
1192
1207
else
1208
+ task_push_save_state (path , data , info .size , autosave );
1209
+ }
1210
+ else
1211
+ {
1212
+ data = get_serialized_data (path , info .size ) ;
1213
+ if ( data == NULL )
1193
1214
{
1194
- /* save_to_disk is false, which means we are saving the state
1195
- in undo_load_buf to allow content_undo_load_state() to restore it */
1196
-
1197
- /* If we were holding onto an old state already, clean it up first */
1198
- if (undo_load_buf .data )
1199
- {
1200
- free (undo_load_buf .data );
1201
- undo_load_buf .data = NULL ;
1202
- }
1215
+ RARCH_ERR ("%s \"%s\".\n" ,
1216
+ msg_hash_to_str (MSG_FAILED_TO_SAVE_STATE_TO ),
1217
+ path );
1218
+ return false ;
1219
+ }
1220
+ /* save_to_disk is false, which means we are saving the state
1221
+ in undo_load_buf to allow content_undo_load_state() to restore it */
1203
1222
1204
- undo_load_buf . data = malloc ( info . size );
1205
- if (! undo_load_buf .data )
1206
- {
1207
- free (data );
1208
- return false ;
1209
- }
1223
+ /* If we were holding onto an old state already, clean it up first */
1224
+ if (undo_load_buf .data )
1225
+ {
1226
+ free (undo_load_buf . data );
1227
+ undo_load_buf . data = NULL ;
1228
+ }
1210
1229
1211
- memcpy (undo_load_buf .data , data , info .size );
1230
+ undo_load_buf .data = malloc (info .size );
1231
+ if (!undo_load_buf .data )
1232
+ {
1212
1233
free (data );
1213
- undo_load_buf .size = info .size ;
1214
- strlcpy (undo_load_buf .path , path , sizeof (undo_load_buf .path ));
1234
+ return false;
1215
1235
}
1216
- }
1217
- else
1218
- {
1236
+
1237
+ memcpy (undo_load_buf .data , data , info .size );
1219
1238
free (data );
1220
- RARCH_ERR ("%s \"%s\".\n" ,
1221
- msg_hash_to_str (MSG_FAILED_TO_SAVE_STATE_TO ),
1222
- path );
1239
+ undo_load_buf .size = info .size ;
1240
+ strlcpy (undo_load_buf .path , path , sizeof (undo_load_buf .path ));
1223
1241
}
1224
1242
1225
- return ret ;
1243
+ return true ;
1226
1244
}
1227
1245
1228
1246
/**
0 commit comments