11package com .dazednconfused .catalauncher .backup ;
22
3- import static com .dazednconfused .catalauncher .helper .Constants .CUSTOM_SAVE_PATH ;
4- import static com .dazednconfused .catalauncher .helper .Constants .CUSTOM_TRASHED_SAVE_PATH ;
5- import static com .dazednconfused .catalauncher .helper .Constants .LAUNCHER_ROOT_FOLDER ;
6- import static com .dazednconfused .catalauncher .helper .Constants .SAVE_BACKUP_PATH ;
7-
3+ import com .dazednconfused .catalauncher .helper .Paths ;
4+ import com .dazednconfused .catalauncher .helper .Zipper ;
85import com .dazednconfused .catalauncher .helper .result .Result ;
96
107import io .vavr .control .Try ;
@@ -29,8 +26,8 @@ public class SaveManager {
2926 private static final Logger LOGGER = LoggerFactory .getLogger (SaveManager .class );
3027
3128 /**
32- * Returns the current {@link com.dazednconfused.catalauncher.helper.Constants#CUSTOM_SAVE_PATH } compression job, wrapped
33- * inside a {@link Thread} and ready to be executed.
29+ * Returns the current {@link Paths#getCustomSavePath() } compression job, wrapped inside a {@link Thread} and ready to
30+ * be executed.
3431 * */
3532 public static Optional <Thread > backupCurrentSaves (Consumer <Integer > onPercentDoneCallback ) {
3633 LOGGER .info ("Backup-ing all saves..." );
@@ -40,7 +37,7 @@ public static Optional<Thread> backupCurrentSaves(Consumer<Integer> onPercentDon
4037 return Optional .empty ();
4138 }
4239
43- File savesFolder = new File (CUSTOM_SAVE_PATH );
40+ File savesFolder = new File (Paths . getCustomSavePath () );
4441 return Optional .of (compressFolderAsJob (
4542 savesFolder ,
4643 getSaveBackupFolder ().getAbsolutePath () + "/" + generateNameBasedOnCurrentTimestamp () + ".zip" ,
@@ -54,19 +51,19 @@ public static Optional<Thread> backupCurrentSaves(Consumer<Integer> onPercentDon
5451 public static Optional <Thread > restoreBackup (File backup2beRestored , Consumer <Integer > onPercentDoneCallback ) {
5552 LOGGER .info ("Restoring backup [{}]..." , backup2beRestored );
5653
57- File trashedSaves = new File (CUSTOM_TRASHED_SAVE_PATH );
54+ File trashedSaves = new File (Paths . getCustomTrashedSavePath () );
5855
5956 if (!trashedSaves .exists ()) {
6057 LOGGER .debug ("Trashed saves' folder [{}] doesn't exist. Generating..." , trashedSaves );
6158 Try .of (trashedSaves ::mkdirs ).onFailure (t -> LOGGER .error ("There was an error while creating trashed saves' folder [{}]" , trashedSaves , t ));
6259 }
6360
64- File trashedSavePath = new File (CUSTOM_TRASHED_SAVE_PATH + generateNameBasedOnCurrentTimestamp ());
61+ File trashedSavePath = new File (Paths . getCustomTrashedSavePath () + generateNameBasedOnCurrentTimestamp ());
6562
6663 if (!saveFilesExist ()) {
6764 LOGGER .info ("No current saves found. Nothing to move to trash folder." );
6865 } else {
69- File currentSave = new File (CUSTOM_SAVE_PATH );
66+ File currentSave = new File (Paths . getCustomSavePath () );
7067
7168 Try .of (() -> Files .move (
7269 currentSave .toPath (),
@@ -76,7 +73,7 @@ public static Optional<Thread> restoreBackup(File backup2beRestored, Consumer<In
7673
7774 return Optional .of (decompressFolderAsJob (
7875 backup2beRestored ,
79- LAUNCHER_ROOT_FOLDER , // we don't decompress into CUSTOM_SAVE_PATH because we end up with ./saves/saves/<actual world saves>
76+ Paths . getLauncherRootFolder () , // we don't decompress into CUSTOM_SAVE_PATH because we end up with ./saves/saves/<actual world saves>
8077 onPercentDoneCallback
8178 ));
8279 }
@@ -105,7 +102,7 @@ public static Result<Throwable, File> renameBackup(File toBeRenamed, String newN
105102 }
106103
107104 /**
108- * Returns all save backups currently found in {@link com.dazednconfused.catalauncher.helper.Constants#SAVE_BACKUP_PATH }.
105+ * Returns all save backups currently found in {@link Paths#getSaveBackupPath() }.
109106 * */
110107 public static List <File > listAllBackups () {
111108 LOGGER .debug ("Listing all backups..." );
@@ -115,11 +112,11 @@ public static List<File> listAllBackups() {
115112 }
116113
117114 /**
118- * If save files exist in {@link com.dazednconfused.catalauncher.helper.Constants#CUSTOM_SAVE_PATH }, returns the last
119- * modified valid save file. Save file is valid if it has a .sav file in it.
115+ * If save files exist in {@link Paths#getCustomSavePath() }, returns the last modified valid save file. Save file is valid
116+ * if it has a .sav file in it.
120117 * */
121118 public static Optional <File > getLastModifiedValidSave () {
122- File savesFolder = new File (CUSTOM_SAVE_PATH );
119+ File savesFolder = new File (Paths . getCustomSavePath () );
123120 if (!saveFilesExist ()) {
124121 return Optional .empty ();
125122 }
@@ -137,18 +134,17 @@ public static Optional<File> getLastModifiedValidSave() {
137134
138135 }
139136 /**
140- * Determines whether save files exist in {@link com.dazednconfused.catalauncher.helper.Constants#CUSTOM_SAVE_PATH }.
137+ * Determines whether save files exist in {@link Paths#getCustomSavePath() }.
141138 * */
142139
143140 public static boolean saveFilesExist () {
144- File savesFolder = new File (CUSTOM_SAVE_PATH );
141+ File savesFolder = new File (Paths . getCustomSavePath () );
145142 return savesFolder .exists () && Arrays .stream (Objects .requireNonNull (savesFolder .listFiles ())).anyMatch (file -> !file .getName ().equals (".DS_Store" ));
146143 }
147144
148145 /**
149- * Gets the latest save {@link File} from {@link com.dazednconfused.catalauncher.helper.Constants#CUSTOM_SAVE_PATH}, wrapped
150- * inside an {@link Optional}. {@link Optional#empty()} if given path doesn't exist or doesn't have any folders that could
151- * be assumed to be individual save files.
146+ * Gets the latest save {@link File} from {@link Paths#getCustomSavePath()}, wrapped inside an {@link Optional}. {@link Optional#empty()}
147+ * if given path doesn't exist or doesn't have any folders that could be assumed to be individual save files.
152148 * */
153149 public static Optional <File > getLatestSave () {
154150
@@ -160,10 +156,10 @@ public static Optional<File> getLatestSave() {
160156 }
161157
162158 /**
163- * Retrieves the {@link com.dazednconfused.catalauncher.helper.Constants#SAVE_BACKUP_PATH } as a {@link File}.
159+ * Retrieves the {@link Paths#getSaveBackupPath() } as a {@link File}.
164160 * */
165161 private static File getSaveBackupFolder () {
166- File backupPath = new File (SAVE_BACKUP_PATH );
162+ File backupPath = new File (Paths . getSaveBackupPath () );
167163 if (!backupPath .exists ()) {
168164 LOGGER .debug ("Save backup destination folder [{}] not found. Creating..." , backupPath );
169165 Try .of (backupPath ::mkdirs ).onFailure (t -> LOGGER .error ("Could not create backup destination folder [{}]" , backupPath , t ));
@@ -176,14 +172,14 @@ private static File getSaveBackupFolder() {
176172 * Returns the requested compression job wrapped inside a {@link Thread} and ready to be executed.
177173 * */
178174 private static Thread compressFolderAsJob (File sourceDir , String outputFile , Consumer <Integer > onPercentDoneCallback ) {
179- return new Thread (() -> Zipper .compressAndCallback (sourceDir , outputFile , onPercentDoneCallback , 100 ));
175+ return new Thread (() -> Zipper .compressAndCallback (sourceDir , Path . of ( outputFile ) , onPercentDoneCallback , 100 ));
180176 }
181177
182178 /**
183179 * Returns the requested decompression job wrapped inside a {@link Thread} and ready to be executed.
184180 * */
185181 private static Thread decompressFolderAsJob (File sourceFile , String destinationPath , Consumer <Integer > onPercentDoneCallback ) {
186- return new Thread (() -> Zipper .decompressAndCallback (sourceFile , destinationPath , onPercentDoneCallback , 100 ));
182+ return new Thread (() -> Zipper .decompressAndCallback (sourceFile , Path . of ( destinationPath ) , onPercentDoneCallback , 100 ));
187183 }
188184
189185 /**
0 commit comments