@@ -313,6 +313,7 @@ public void reload() {
313313 savestateList .clear ();
314314 Thread t = new Thread (new Runnable () {
315315
316+ @ SuppressWarnings ("deprecation" )
316317 @ Override
317318 public void run () {
318319 Stream <Path > stream = null ;
@@ -343,7 +344,30 @@ public void run() {
343344 * Read the index from the folder if the savestate file
344345 * doesn't exist
345346 */
346- if (!Files .exists (savestateDat )) {
347+ if (Files .exists (savestateDat )) {
348+ savestate = new Savestate (savestateDat , path );
349+ savestate .load ();
350+ } else if (Files .exists (path .resolve ("tasmod/savestateData.txt" ))) { // Legacy format
351+
352+ Path tasmodDir = path .resolve ("tasmod" );
353+ Path tasDir = tasmodDir .getParent ().resolve (savestateDataDir );
354+ copyFolder (tasmodDir , tasDir );
355+ deleteFolder (tasmodDir );
356+
357+ Path legacyPath = tasDir .resolve ("savestateData.txt" );
358+ com .minecrafttas .tasmod .savestates .files .SavestateDataFile dataFile = new com .minecrafttas .tasmod .savestates .files .SavestateDataFile (legacyPath );
359+ dataFile .load ();
360+ int index = Integer .parseInt (dataFile .get (com .minecrafttas .tasmod .savestates .files .SavestateDataFile .DataValues .INDEX ));
361+
362+ try {
363+ Files .delete (legacyPath );
364+ } catch (IOException e ) {
365+ e .printStackTrace ();
366+ }
367+
368+ savestate = new Savestate (savestateDat , index , "Savestate #" + index , null , path );
369+ savestate .save ();
370+ } else {
347371 String filename = path .getFileName ().toString ();
348372 Matcher matcher = backupIndexPattern .matcher (filename );
349373 int backupIndex = -1 ;
@@ -354,9 +378,6 @@ public void run() {
354378 logger .warn ("Savestate {} does not contain a valid savestate.json, skipping" , backupIndex );
355379 Throwable error = new SavestateException ("Savestate.json data file not found in " + savestateBaseDirectory .relativize (savestateDat ));
356380 savestate = new FailedSavestate (path , backupIndex , null , null , error );
357- } else {
358- savestate = new Savestate (savestateDat , path );
359- savestate .load ();
360381 }
361382 savestateList .put (savestate .getIndex (), savestate .clone ());
362383 });
0 commit comments