@@ -22,6 +22,7 @@ import com.unciv.models.metadata.GameSettings
22
22
import com.unciv.models.metadata.doMigrations
23
23
import com.unciv.models.metadata.isMigrationNecessary
24
24
import com.unciv.models.ruleset.RulesetCache
25
+ import com.unciv.ui.screens.modmanager.ModUIData
25
26
import com.unciv.ui.screens.savescreens.Gzip
26
27
import com.unciv.utils.Concurrency
27
28
import com.unciv.utils.Log
@@ -34,6 +35,7 @@ private const val SAVE_FILES_FOLDER = "SaveFiles"
34
35
private const val MULTIPLAYER_FILES_FOLDER = " MultiplayerGames"
35
36
private const val AUTOSAVE_FILE_NAME = " Autosave"
36
37
const val SETTINGS_FILE_NAME = " GameSettings.json"
38
+ const val MOD_LIST_CACHE_FILE_NAME = " ModListCache.json"
37
39
38
40
class UncivFiles (
39
41
/* *
@@ -142,14 +144,6 @@ class UncivFiles(
142
144
return deleteSave(getSave(gameName))
143
145
}
144
146
145
- /* *
146
- * @return `true` if successful.
147
- * @throws SecurityException when delete access was denied
148
- */
149
- fun deleteMultiplayerSave (gameName : String ): Boolean {
150
- return deleteSave(getMultiplayerSave(gameName))
151
- }
152
-
153
147
/* *
154
148
* Only use this with a [FileHandle] obtained by one of the methods of this class!
155
149
*
@@ -162,6 +156,7 @@ class UncivFiles(
162
156
}
163
157
164
158
// endregion
159
+
165
160
// region Saving
166
161
167
162
fun saveGame (game : GameInfo , gameName : String , saveCompletionCallback : (Exception ? ) -> Unit = { if (it != null) throw it }): FileHandle {
@@ -253,9 +248,6 @@ class UncivFiles(
253
248
return gameInfoFromString(gameData)
254
249
}
255
250
256
- fun loadGamePreviewByName (gameName : String ) =
257
- loadGamePreviewFromFile(getMultiplayerSave(gameName))
258
-
259
251
fun loadGamePreviewFromFile (gameFile : FileHandle ): GameInfoPreview {
260
252
return json().fromJson(GameInfoPreview ::class .java, gameFile) ? : throw emptyFile(gameFile)
261
253
}
@@ -296,6 +288,7 @@ class UncivFiles(
296
288
297
289
298
290
// endregion
291
+
299
292
// region Settings
300
293
301
294
private fun getGeneralSettingsFile (): FileHandle {
@@ -357,6 +350,34 @@ class UncivFiles(
357
350
return game
358
351
}
359
352
353
+ // endregion
354
+
355
+ // region Mod caching
356
+ fun saveModCache (modDataList : List <ModUIData >){
357
+ val file = getLocalFile(MOD_LIST_CACHE_FILE_NAME )
358
+ try {
359
+ json().toJson(modDataList, file)
360
+ }
361
+ catch (ex: Exception ){ // Not a huge deal if this fails
362
+ Log .error(" Error saving mod cache" , ex)
363
+ }
364
+ }
365
+
366
+
367
+ fun loadModCache (): List <ModUIData >{
368
+ val file = getLocalFile(MOD_LIST_CACHE_FILE_NAME )
369
+ if (! file.exists()) return emptyList()
370
+ try {
371
+ return json().fromJsonFile(Array <ModUIData >::class .java, file)
372
+ .toList()
373
+ }
374
+ catch (ex: Exception ){ // Not a huge deal if this fails
375
+ Log .error(" Error loading mod cache" , ex)
376
+ return emptyList()
377
+ }
378
+ }
379
+
380
+
360
381
// endregion
361
382
362
383
companion object {
0 commit comments