|
@@ -537,6 +537,32 @@ public class Control {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * find all old auto save files (with a file-name, that does not contain the current rand)
|
|
|
+ *
|
|
|
+ * @return a list of files, that are not from the current run
|
|
|
+ */
|
|
|
+ public ArrayList<File> filterOldAutoSaveFiles() {
|
|
|
+ File[] files = new File(autosaveDir).listFiles();
|
|
|
+ ArrayList<File> oldAutoSaves = new ArrayList<>();
|
|
|
+
|
|
|
+ for (File file : files) {
|
|
|
+ if (!file.getName().contains(String.valueOf(rand)))
|
|
|
+ oldAutoSaves.add(file);
|
|
|
+ }
|
|
|
+
|
|
|
+ return oldAutoSaves;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * deletes the old autosave files
|
|
|
+ */
|
|
|
+ public void deleteObsoleteAutoSaveFiles() {
|
|
|
+ for (File file : filterOldAutoSaveFiles()) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void saveCategory() throws IOException {
|
|
|
saveController.writeCategory(categoryDir + "Category.json");
|
|
|
}
|
|
@@ -563,6 +589,14 @@ public class Control {
|
|
|
autoSaveController.increaseAutoSaveNr();
|
|
|
if (!new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
|
|
|
autoSaveController.decreaseAutoSaveNr();
|
|
|
+
|
|
|
+ // if it still does not exist, try old autosaves
|
|
|
+ if (!new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
|
|
|
+ ArrayList<File> oldAutoSaves = filterOldAutoSaveFiles();
|
|
|
+ if (oldAutoSaves.size() > 0) {
|
|
|
+ return autosaveDir + oldAutoSaves.get(oldAutoSaves.size() - 1).getName();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
return autosaveDir + rand + (autoSaveController.getAutoSaveNr());
|
|
|
}
|