diff --git a/sync-script/src/main/kotlin/JarAutoUpdater.kt b/sync-script/src/main/kotlin/JarAutoUpdater.kt index 8e4ddcd..cc947a4 100644 --- a/sync-script/src/main/kotlin/JarAutoUpdater.kt +++ b/sync-script/src/main/kotlin/JarAutoUpdater.kt @@ -1,5 +1,5 @@ import constants.ProjectInfoConstants -import constants.SyncScriptInstanceFiles +import constants.SyncScriptDotMinecraftFiles import generated.BuildConfig import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext @@ -19,7 +19,7 @@ object JarAutoUpdater { private suspend fun downloadLatestJarFile(): Result = try { val newJarFile = - SyncScriptInstanceFiles.SyncScriptData.Temp.file + SyncScriptDotMinecraftFiles.SyncScriptData.Temp.file .resolve("${ProjectInfoConstants.NORMALIZED_NAME}-new.jar") if (newJarFile.exists()) { newJarFile.delete() @@ -116,7 +116,7 @@ object JarAutoUpdater { OperatingSystem.Windows -> { // On Windows, we can't rename, delete or modify the current running JAR file due to file locking val updateBatScriptFile = - SyncScriptInstanceFiles.SyncScriptData.Temp.file + SyncScriptDotMinecraftFiles.SyncScriptData.Temp.file .resolve("update.bat") withContext(Dispatchers.IO) { updateBatScriptFile.parentFile.mkdirs() diff --git a/sync-script/src/main/kotlin/Main.kt b/sync-script/src/main/kotlin/Main.kt index c458000..db3aac9 100644 --- a/sync-script/src/main/kotlin/Main.kt +++ b/sync-script/src/main/kotlin/Main.kt @@ -2,7 +2,7 @@ import config.data.LocalJsonScriptConfigDataSource import config.data.ScriptConfigDataSource import config.models.ScriptConfig import constants.Constants -import constants.SyncScriptInstanceFiles +import constants.SyncScriptDotMinecraftFiles import generated.BuildConfig import gui.GuiState import gui.dialogs.CreateScriptConfigDialog @@ -59,7 +59,7 @@ suspend fun main(args: Array) { }.also { println(it) } } - SyncScriptInstanceFiles.SyncScriptData.Temp.file.apply { + SyncScriptDotMinecraftFiles.SyncScriptData.Temp.file.apply { if (exists()) { println( "ℹ\uFE0F The temporary folder: $path exist. " + @@ -88,7 +88,7 @@ suspend fun main(args: Array) { // Loading the script config file from json file - val scriptConfigFile = SyncScriptInstanceFiles.SyncScriptData.ScriptConfig.file + val scriptConfigFile = SyncScriptDotMinecraftFiles.SyncScriptData.ScriptConfig.file if (!scriptConfigFile.exists()) { if (GuiState.isGuiEnabled) { println( @@ -158,7 +158,7 @@ suspend fun main(args: Array) { // TODO: Plan if we should implement this in non GUI mode if (GuiState.isGuiEnabled && - !SyncScriptInstanceFiles.SyncScriptData.IsPreferencesConfigured.file + !SyncScriptDotMinecraftFiles.SyncScriptData.IsPreferencesConfigured.file .exists() ) { val newScriptConfig = QuickPreferencesDialog().showDialog() @@ -177,7 +177,7 @@ suspend fun main(args: Array) { GuiState.updateIsGuiEnabled() withContext(Dispatchers.IO) { - SyncScriptInstanceFiles.SyncScriptData.IsPreferencesConfigured.file + SyncScriptDotMinecraftFiles.SyncScriptData.IsPreferencesConfigured.file .createNewFile() } } @@ -251,7 +251,7 @@ suspend fun main(args: Array) { // The temporary folder usually contains the downloaded files which will be moved once finished // after finish syncing the contents successfully, we don't need it anymore. - SyncScriptInstanceFiles.SyncScriptData.Temp.file.apply { + SyncScriptDotMinecraftFiles.SyncScriptData.Temp.file.apply { if (exists()) { println("\uD83D\uDEAB Deleting the temporary folder: '$path' (no longer needed).") deleteRecursively() diff --git a/sync-script/src/main/kotlin/config/data/LocalJsonScriptConfigDataSource.kt b/sync-script/src/main/kotlin/config/data/LocalJsonScriptConfigDataSource.kt index a1c0b4b..934c731 100644 --- a/sync-script/src/main/kotlin/config/data/LocalJsonScriptConfigDataSource.kt +++ b/sync-script/src/main/kotlin/config/data/LocalJsonScriptConfigDataSource.kt @@ -1,29 +1,31 @@ package config.data import config.models.ScriptConfig -import constants.SyncScriptInstanceFiles +import constants.SyncScriptDotMinecraftFiles import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import kotlinx.serialization.json.Json import utils.JsonPrettyPrint class LocalJsonScriptConfigDataSource : ScriptConfigDataSource { - override suspend fun getConfig(): Result { - return try { + override suspend fun getConfig(): Result = + try { val scriptConfig = withContext(Dispatchers.IO) { - Json.decodeFromString(SyncScriptInstanceFiles.SyncScriptData.ScriptConfig.file.readText()) + Json.decodeFromString( + SyncScriptDotMinecraftFiles.SyncScriptData.ScriptConfig.file + .readText(), + ) } Result.success(scriptConfig) } catch (e: Exception) { Result.failure(e) } - } - override suspend fun replaceConfig(scriptConfig: ScriptConfig): Result { - return try { + override suspend fun replaceConfig(scriptConfig: ScriptConfig): Result = + try { withContext(Dispatchers.IO) { - val configFile = SyncScriptInstanceFiles.SyncScriptData.ScriptConfig.file + val configFile = SyncScriptDotMinecraftFiles.SyncScriptData.ScriptConfig.file if (!configFile.parentFile.exists()) { configFile.parentFile.mkdirs() } @@ -33,5 +35,4 @@ class LocalJsonScriptConfigDataSource : ScriptConfigDataSource { } catch (e: Exception) { Result.failure(e) } - } } diff --git a/sync-script/src/main/kotlin/config/models/ScriptConfig.kt b/sync-script/src/main/kotlin/config/models/ScriptConfig.kt index 97ca912..e132ec7 100644 --- a/sync-script/src/main/kotlin/config/models/ScriptConfig.kt +++ b/sync-script/src/main/kotlin/config/models/ScriptConfig.kt @@ -1,7 +1,7 @@ package config.models import constants.Constants -import constants.SyncScriptInstanceFiles +import constants.SyncScriptDotMinecraftFiles import gui.theme.Theme import gui.theme.ThemeMode import kotlinx.serialization.Serializable @@ -9,7 +9,7 @@ import syncInfo.models.Environment import syncInfo.models.SyncInfo /** - * A data class that represent the json for the [SyncScriptInstanceFiles.SyncScriptData.ScriptConfig] + * A data class that represent the json for the [SyncScriptDotMinecraftFiles.SyncScriptData.ScriptConfig] * where the user can pass some data that is needed to launch the script * */ @Serializable diff --git a/sync-script/src/main/kotlin/constants/SyncScriptInstanceFiles.kt b/sync-script/src/main/kotlin/constants/SyncScriptDotMinecraftFiles.kt similarity index 58% rename from sync-script/src/main/kotlin/constants/SyncScriptInstanceFiles.kt rename to sync-script/src/main/kotlin/constants/SyncScriptDotMinecraftFiles.kt index 2c75057..6cc534f 100644 --- a/sync-script/src/main/kotlin/constants/SyncScriptInstanceFiles.kt +++ b/sync-script/src/main/kotlin/constants/SyncScriptDotMinecraftFiles.kt @@ -8,45 +8,45 @@ import java.io.File * * This should be only used by the script that syncs the content * */ -sealed class SyncScriptInstanceFiles( +sealed class SyncScriptDotMinecraftFiles( val file: File, ) { - data object Mods : SyncScriptInstanceFiles(File(DotMinecraftFileNames.MODS_DIRECTORY)) + data object Mods : SyncScriptDotMinecraftFiles(File(DotMinecraftFileNames.MODS_DIRECTORY)) - data object ResourcePacks : SyncScriptInstanceFiles(File(DotMinecraftFileNames.RESOURCE_PACKS_DIRECTORY)) + data object ResourcePacks : SyncScriptDotMinecraftFiles(File(DotMinecraftFileNames.RESOURCE_PACKS_DIRECTORY)) - data object ShaderPacks : SyncScriptInstanceFiles(File(DotMinecraftFileNames.SHADER_PACKS_DIRECTORY)) + data object ShaderPacks : SyncScriptDotMinecraftFiles(File(DotMinecraftFileNames.SHADER_PACKS_DIRECTORY)) - data object Config : SyncScriptInstanceFiles(File(DotMinecraftFileNames.CONFIG_DIRECTORY)) + data object Config : SyncScriptDotMinecraftFiles(File(DotMinecraftFileNames.CONFIG_DIRECTORY)) - data object Saves : SyncScriptInstanceFiles(File(DotMinecraftFileNames.SAVES_DIRECTORY)) + data object Saves : SyncScriptDotMinecraftFiles(File(DotMinecraftFileNames.SAVES_DIRECTORY)) /** * A txt file contains the minecraft options/settings or data like the key bindings, sound settings * enabled resource-packs, language and the minecraft video settings, and more * */ - data object Options : SyncScriptInstanceFiles(File(DotMinecraftFileNames.OPTIONS_FILE)) + data object Options : SyncScriptDotMinecraftFiles(File(DotMinecraftFileNames.OPTIONS_FILE)) /** * A file that contains all the information about the list of servers * */ - data object ServersDat : SyncScriptInstanceFiles(File(DotMinecraftFileNames.SERVERS_FILE)) + data object ServersDat : SyncScriptDotMinecraftFiles(File(DotMinecraftFileNames.SERVERS_FILE)) /** * This directory will be created and managed by the script, it's specific to it * */ - data object SyncScriptData : SyncScriptInstanceFiles(File(DotMinecraftFileNames.SYNC_SCRIPT_DIRECTORY)) { + data object SyncScriptData : SyncScriptDotMinecraftFiles(File(DotMinecraftFileNames.SYNC_SCRIPT_DIRECTORY)) { /** * The script needs a config file that contains required data and other optional to configure it * */ - data object ScriptConfig : SyncScriptInstanceFiles(File(SyncScriptData.file, "config.json")) + data object ScriptConfig : SyncScriptDotMinecraftFiles(File(SyncScriptData.file, "config.json")) /** * A directory that contain the temporary files used by the script, * for example, when downloading a file, the content will be saved to this directory * and after finish downloading, the file will be moved into where it should. * */ - data object Temp : SyncScriptInstanceFiles(File(SyncScriptData.file, "temp")) + data object Temp : SyncScriptDotMinecraftFiles(File(SyncScriptData.file, "temp")) /** * A file will be used to indicate if the user did set up the preferences for using the script, and it will @@ -56,6 +56,6 @@ sealed class SyncScriptInstanceFiles( * it later and launch the dialog again. * */ data object IsPreferencesConfigured : - SyncScriptInstanceFiles(File(SyncScriptData.file, "isPreferencesConfigured")) + SyncScriptDotMinecraftFiles(File(SyncScriptData.file, "isPreferencesConfigured")) } } diff --git a/sync-script/src/main/kotlin/services/minecraft/MinecraftOptionsManager.kt b/sync-script/src/main/kotlin/services/minecraft/MinecraftOptionsManager.kt index 25f13d9..58bbb1c 100644 --- a/sync-script/src/main/kotlin/services/minecraft/MinecraftOptionsManager.kt +++ b/sync-script/src/main/kotlin/services/minecraft/MinecraftOptionsManager.kt @@ -1,17 +1,17 @@ package services.minecraft -import constants.SyncScriptInstanceFiles +import constants.SyncScriptDotMinecraftFiles import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import org.jetbrains.annotations.VisibleForTesting import java.io.File /** - * Helper class for reading [SyncScriptInstanceFiles.Options] file which contains Minecraft settings + * Helper class for reading [SyncScriptDotMinecraftFiles.Options] file which contains Minecraft settings * for reading and getting the properties or set them if it doesn't exist * */ object MinecraftOptionsManager { - private var optionsFile = SyncScriptInstanceFiles.Options.file + private var optionsFile = SyncScriptDotMinecraftFiles.Options.file private val properties: MutableMap = mutableMapOf() private var isLoaded = false diff --git a/sync-script/src/main/kotlin/syncService/ModsSyncService.kt b/sync-script/src/main/kotlin/syncService/ModsSyncService.kt index 8c829da..05c5149 100644 --- a/sync-script/src/main/kotlin/syncService/ModsSyncService.kt +++ b/sync-script/src/main/kotlin/syncService/ModsSyncService.kt @@ -1,6 +1,6 @@ package syncService -import constants.SyncScriptInstanceFiles +import constants.SyncScriptDotMinecraftFiles import gui.dialogs.LoadingIndicatorDialog import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext @@ -23,7 +23,7 @@ import java.io.File // mods issue when allowing the user to install other mods class ModsSyncService : SyncService { - private val modsDirectory = SyncScriptInstanceFiles.Mods.file + private val modsDirectory = SyncScriptDotMinecraftFiles.Mods.file companion object { private const val MOD_FILE_EXTENSION = "jar" @@ -82,7 +82,7 @@ class ModsSyncService : SyncService { title = "❌ Invalid Mods Folder", message = "\uD83D\uDEE0 Mods must be stored in a directory/folder \uD83D\uDCC2 called " + - "`${SyncScriptInstanceFiles.Mods.file.name}`" + + "`${SyncScriptDotMinecraftFiles.Mods.file.name}`" + ", a file was found instead.", ) } diff --git a/sync-script/src/main/kotlin/syncService/ResourcePacksSyncService.kt b/sync-script/src/main/kotlin/syncService/ResourcePacksSyncService.kt index 53e1853..a5b7ff9 100644 --- a/sync-script/src/main/kotlin/syncService/ResourcePacksSyncService.kt +++ b/sync-script/src/main/kotlin/syncService/ResourcePacksSyncService.kt @@ -1,9 +1,9 @@ package syncService -import constants.SyncScriptInstanceFiles +import constants.SyncScriptDotMinecraftFiles class ResourcePacksSyncService : SyncService { - private val resourcePacksDirectory = SyncScriptInstanceFiles.ResourcePacks.file + private val resourcePacksDirectory = SyncScriptDotMinecraftFiles.ResourcePacks.file override suspend fun syncData() { TODO("Not yet implemented") diff --git a/sync-script/src/main/kotlin/syncService/ServersSyncService.kt b/sync-script/src/main/kotlin/syncService/ServersSyncService.kt index 93132e4..f60fc85 100644 --- a/sync-script/src/main/kotlin/syncService/ServersSyncService.kt +++ b/sync-script/src/main/kotlin/syncService/ServersSyncService.kt @@ -1,9 +1,9 @@ package syncService -import constants.SyncScriptInstanceFiles +import constants.SyncScriptDotMinecraftFiles class ServersSyncService : SyncService { - private val serversFile = SyncScriptInstanceFiles.ServersDat.file + private val serversFile = SyncScriptDotMinecraftFiles.ServersDat.file override suspend fun syncData() { TODO("Not yet implemented") diff --git a/sync-script/src/main/kotlin/syncService/ShaderPacksSyncService.kt b/sync-script/src/main/kotlin/syncService/ShaderPacksSyncService.kt index 047e309..cead6f1 100644 --- a/sync-script/src/main/kotlin/syncService/ShaderPacksSyncService.kt +++ b/sync-script/src/main/kotlin/syncService/ShaderPacksSyncService.kt @@ -1,9 +1,9 @@ package syncService -import constants.SyncScriptInstanceFiles +import constants.SyncScriptDotMinecraftFiles class ShaderPacksSyncService : SyncService { - private val shaderPacksDirectory = SyncScriptInstanceFiles.ShaderPacks.file + private val shaderPacksDirectory = SyncScriptDotMinecraftFiles.ShaderPacks.file override suspend fun syncData() { TODO("Not yet implemented") diff --git a/sync-script/src/main/kotlin/utils/FileDownloader.kt b/sync-script/src/main/kotlin/utils/FileDownloader.kt index 3dd3605..a723056 100644 --- a/sync-script/src/main/kotlin/utils/FileDownloader.kt +++ b/sync-script/src/main/kotlin/utils/FileDownloader.kt @@ -1,6 +1,6 @@ package utils -import constants.SyncScriptInstanceFiles +import constants.SyncScriptDotMinecraftFiles import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import okhttp3.Request @@ -60,7 +60,7 @@ class FileDownloader( // We could use File.createTempFile from JVM, to avoid creating // files on the user system we will handle it manually val tempFile = - SyncScriptInstanceFiles.SyncScriptData.Temp.file.resolve( + SyncScriptDotMinecraftFiles.SyncScriptData.Temp.file.resolve( "${targetFile.nameWithoutExtension}-${System.currentTimeMillis()}.${targetFile.extension}", ) if (!tempFile.exists()) { @@ -107,7 +107,7 @@ class FileDownloader( e.printStackTrace() showErrorMessageAndTerminate( title = "🚫 Couldn't download the file", - message = "An unknown error occurred while downloading the file: ${e.message} from the url: $downloadUrl", + message = "An unknown error occurred while downloading the file ($downloadUrl): ${e.message}:", ) } } diff --git a/sync-script/src/test/kotlin/services/minecraft/MinecraftOptionsManagerTest.kt b/sync-script/src/test/kotlin/services/minecraft/MinecraftOptionsManagerTest.kt index 4743647..b6b6c46 100644 --- a/sync-script/src/test/kotlin/services/minecraft/MinecraftOptionsManagerTest.kt +++ b/sync-script/src/test/kotlin/services/minecraft/MinecraftOptionsManagerTest.kt @@ -1,6 +1,6 @@ package services.minecraft -import constants.SyncScriptInstanceFiles +import constants.SyncScriptDotMinecraftFiles import kotlinx.serialization.SerializationException import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json @@ -33,8 +33,8 @@ class MinecraftOptionsManagerTest { fun setUp() { testsOptionsFile = File.createTempFile( - SyncScriptInstanceFiles.Options.file.nameWithoutExtension, - ".${SyncScriptInstanceFiles.Options.file.extension}", + SyncScriptDotMinecraftFiles.Options.file.nameWithoutExtension, + ".${SyncScriptDotMinecraftFiles.Options.file.extension}", ) testsOptionsFile.deleteOnExit()