MCPcopy Create free account
hub / github.com/clementgallet/libTAS / renameSaveFile

Function renameSaveFile

src/library/fileio/SaveFileList.cpp:237–279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

235}
236
237int renameSaveFile(const char *oldfile, const char *newfile)
238{
239 std::lock_guard<std::mutex> lock(getSaveFileListMutex());
240
241 char* canonnewfile = SaveFile::canonicalizeFile(newfile);
242 if (!canonnewfile)
243 return -1;
244 std::string newfilestr(canonnewfile);
245 free(canonnewfile);
246
247 /* Remove the newfile if present */
248 auto& savefiles = getSaveFileList();
249 savefiles.remove_if([newfile](const std::unique_ptr<SaveFile>& s) { return (s->isSameFile(newfile));});
250
251 for (const auto& savefile : savefiles) {
252 if (savefile->isSameFile(oldfile)) {
253 savefile->filename = newfilestr;
254
255 /* Create a savefile for the old path with `removed` flag, so that
256 * future attempts at reading it will return a missing file, instead
257 * of using the original file. */
258 savefiles.emplace_front(new SaveFile(oldfile));
259 savefiles.front()->remove();
260 return 0;
261 }
262 }
263
264 /* If the file is not registered, create a savefile */
265 if (isSaveFile(newfile)) {
266 savefiles.emplace_front(new SaveFile(oldfile));
267 savefiles.front()->open("rb");
268 savefiles.front()->filename = newfilestr;
269
270 /* Create a dummy entry to mark the old file as removed */
271 savefiles.emplace_front(new SaveFile(oldfile));
272 savefiles.front()->remove();
273
274 GlobalNative gn;
275 return access(oldfile, W_OK);
276 }
277
278 return 1;
279}
280
281const SaveFile* getSaveFile(const char *file)
282{

Callers 1

renameFunction · 0.85

Calls 6

isSaveFileFunction · 0.85
accessFunction · 0.85
isSameFileMethod · 0.80
frontMethod · 0.80
removeMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected