aboutsummaryrefslogtreecommitdiff
path: root/games/RetroArch/savestates.patch
blob: 932783783b0679237e6fa27125b14c4f41372afa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
From 64459bda3a8add5c5e679b3fa4d1fd4cd7796233 Mon Sep 17 00:00:00 2001
From: Tatsuya79 <jeanpascalmeunier@hotmail.com>
Date: Sat, 1 Sep 2018 01:41:21 +0200
Subject: [PATCH] revert #7156

revert https://github.com/libretro/RetroArch/pull/7156
---
 tasks/task_save.c | 142 ++++++++++++++++++++--------------------------
 1 file changed, 62 insertions(+), 80 deletions(-)

diff --git a/tasks/task_save.c b/tasks/task_save.c
index fb08c229b7..1b5d93be4e 100644
--- a/tasks/task_save.c
+++ b/tasks/task_save.c
@@ -555,33 +555,6 @@ static void task_save_handler_finished(retro_task_t *task,
    free(state);
 }
 
-void* get_serialized_data(const char *path, size_t serial_size)
-{
-   retro_ctx_serialize_info_t serial_info;
-   bool ret    = false;
-   void *data  = NULL;
-
-   data = malloc(serial_size);
-
-   if (!data)
-      return NULL;
-
-   RARCH_LOG("%s: %d %s.\n",
-         msg_hash_to_str(MSG_STATE_SIZE),
-         (int)serial_size,
-         msg_hash_to_str(MSG_BYTES));
-
-   serial_info.data = data;
-   serial_info.size = serial_size;
-   ret              = core_serialize(&serial_info);
-   if ( !ret )
-   {
-      free(data) ;
-      return NULL ;
-   }
-   return data ;
-}
-
 /**
  * task_save_handler:
  * @task : the task being worked on
@@ -603,22 +576,9 @@ static void task_save_handler(retro_task_t *task)
          return;
    }
 
-   if (!state->data)
-   {
-      state->data = get_serialized_data(state->path, state->size) ;
-   }
-
    remaining       = MIN(state->size - state->written, SAVE_STATE_CHUNK);
-
-   if ( state->data )
-   {
-      written         = (int)intfstream_write(state->file,
-            (uint8_t*)state->data + state->written, remaining);
-   }
-   else
-   {
-      written = 0 ;
-   }
+   written         = (int)intfstream_write(state->file,
+         (uint8_t*)state->data + state->written, remaining);
 
    state->written += written;
 
@@ -1174,7 +1134,6 @@ error:
       free(task);
 }
 
-
 /**
  * content_save_state:
  * @path      : path of saved state that shall be written to.
@@ -1185,62 +1144,85 @@ error:
  **/
 bool content_save_state(const char *path, bool save_to_disk, bool autosave)
 {
-   //retro_ctx_serialize_info_t serial_info;
+   retro_ctx_serialize_info_t serial_info;
    retro_ctx_size_info_t info;
    bool ret    = false;
    void *data  = NULL;
 
    core_serialize_size(&info);
 
-   if (save_to_disk)
+   RARCH_LOG("%s: \"%s\".\n",
+         msg_hash_to_str(MSG_SAVING_STATE),
+         path);
+
+   if (info.size == 0)
+      return false;
+
+   data = malloc(info.size);
+
+   if (!data)
+      return false;
+
+   RARCH_LOG("%s: %d %s.\n",
+         msg_hash_to_str(MSG_STATE_SIZE),
+         (int)info.size,
+         msg_hash_to_str(MSG_BYTES));
+
+   serial_info.data = data;
+   serial_info.size = info.size;
+   ret              = core_serialize(&serial_info);
+
+   if (ret)
    {
-      if (filestream_exists(path) && !autosave)
+      if (save_to_disk)
       {
-         /* Before overwritting the savestate file, load it into a buffer
-         to allow undo_save_state() to work */
-         /* TODO/FIXME - Use msg_hash_to_str here */
-         RARCH_LOG("%s ...\n",
-               msg_hash_to_str(MSG_FILE_ALREADY_EXISTS_SAVING_TO_BACKUP_BUFFER));
+         if (filestream_exists(path) && !autosave)
+         {
+            /* Before overwritting the savestate file, load it into a buffer
+            to allow undo_save_state() to work */
+            /* TODO/FIXME - Use msg_hash_to_str here */
+            RARCH_LOG("%s ...\n",
+                  msg_hash_to_str(MSG_FILE_ALREADY_EXISTS_SAVING_TO_BACKUP_BUFFER));
 
-         task_push_load_and_save_state(path, data, info.size, true, autosave);
+            task_push_load_and_save_state(path, data, info.size, true, autosave);
+         }
+         else
+            task_push_save_state(path, data, info.size, autosave);
       }
       else
-         task_push_save_state(path, data, info.size, autosave);
-   }
-   else
-   {
-      data = get_serialized_data(path, info.size) ;
-      if ( data == NULL )
       {
-         RARCH_ERR("%s \"%s\".\n",
-               msg_hash_to_str(MSG_FAILED_TO_SAVE_STATE_TO),
-               path);
-         return false ;
-      }
-      /* save_to_disk is false, which means we are saving the state
-      in undo_load_buf to allow content_undo_load_state() to restore it */
+         /* save_to_disk is false, which means we are saving the state
+         in undo_load_buf to allow content_undo_load_state() to restore it */
 
-      /* If we were holding onto an old state already, clean it up first */
-      if (undo_load_buf.data)
-      {
-         free(undo_load_buf.data);
-         undo_load_buf.data = NULL;
-      }
+         /* If we were holding onto an old state already, clean it up first */
+         if (undo_load_buf.data)
+         {
+            free(undo_load_buf.data);
+            undo_load_buf.data = NULL;
+         }
 
-      undo_load_buf.data = malloc(info.size);
-      if (!undo_load_buf.data)
-      {
+         undo_load_buf.data = malloc(info.size);
+         if (!undo_load_buf.data)
+         {
+            free(data);
+            return false;
+         }
+
+         memcpy(undo_load_buf.data, data, info.size);
          free(data);
-         return false;
+         undo_load_buf.size = info.size;
+         strlcpy(undo_load_buf.path, path, sizeof(undo_load_buf.path));
       }
-
-      memcpy(undo_load_buf.data, data, info.size);
+   }
+   else
+   {
       free(data);
-      undo_load_buf.size = info.size;
-      strlcpy(undo_load_buf.path, path, sizeof(undo_load_buf.path));
+      RARCH_ERR("%s \"%s\".\n",
+            msg_hash_to_str(MSG_FAILED_TO_SAVE_STATE_TO),
+            path);
    }
 
-   return true;
+   return ret;
 }
 
 /**
-- 
2.18.0