From 51f03da346bfbbffa81455220b55c6857cad0a3b Mon Sep 17 00:00:00 2001 From: Jason Schadewald Date: Wed, 30 Aug 2023 13:03:32 -0400 Subject: [PATCH] fix(settings): stop writing legacy configuration file (#702) Removes code that wrote to a legacy TerasologyLauncherSettings.properties Still reads from the legacy file if it cannot find the new JSON config. Co-authored-by: Tobias Nett --- .../launcher/settings/LauncherSettings.java | 2 +- .../launcher/settings/Settings.java | 39 +------------------ .../settings/TestLauncherSettings.java | 2 +- 3 files changed, 4 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/terasology/launcher/settings/LauncherSettings.java b/src/main/java/org/terasology/launcher/settings/LauncherSettings.java index b82e40a3..bf3346ee 100644 --- a/src/main/java/org/terasology/launcher/settings/LauncherSettings.java +++ b/src/main/java/org/terasology/launcher/settings/LauncherSettings.java @@ -65,7 +65,7 @@ public class LauncherSettings { static final String LAST_PLAYED_GAME_VERSION_DEFAULT = ""; static final String LAST_INSTALLED_GAME_VERSION_DEFAULT = ""; - static final String LAUNCHER_SETTINGS_FILE_NAME = "TerasologyLauncherSettings.properties"; + static final String LAUNCHER_LEGACY_SETTINGS_FILE_NAME = "TerasologyLauncherSettings.properties"; private final Properties properties; diff --git a/src/main/java/org/terasology/launcher/settings/Settings.java b/src/main/java/org/terasology/launcher/settings/Settings.java index e731693b..b97da0a8 100644 --- a/src/main/java/org/terasology/launcher/settings/Settings.java +++ b/src/main/java/org/terasology/launcher/settings/Settings.java @@ -29,7 +29,6 @@ import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.lang.reflect.Type; import java.nio.file.Files; import java.nio.file.Path; @@ -105,26 +104,6 @@ static Settings fromLegacy(LauncherSettings legacyLauncherSettings) { return jsonSettings; } - static LauncherSettings toLegacy(Settings settings) { - LauncherSettings legacy = new LauncherSettings(new Properties()); - - legacy.setLocale(settings.locale.get()); - legacy.setMaxHeapSize(settings.maxHeapSize.get()); - legacy.setInitialHeapSize(settings.minHeapSize.get()); - legacy.setLogLevel(settings.logLevel.get()); - legacy.setGameDirectory(settings.gameDirectory.get()); - legacy.setGameDirectory(settings.gameDataDirectory.get()); - legacy.setKeepDownloadedFiles(settings.keepDownloadedFiles.get()); - legacy.setShowPreReleases(settings.showPreReleases.get()); - legacy.setCloseLauncherAfterGameStart(settings.closeLauncherAfterGameStart.get()); - legacy.setLastPlayedGameVersion(settings.lastPlayedGameVersion.get()); - - legacy.setUserJavaParameters(String.join(" ", settings.userJavaParameters.get())); - legacy.setUserGameParameters(String.join(" ", settings.userGameParameters.get())); - - return legacy; - } - /** * Load the launcher settings from disk. * @@ -168,20 +147,13 @@ public static Settings load(final Path path) { } /** - * Write the launcher settings to disk. + * Write the launcher settings to disk in JSON format. * * The given {@code path} must be the direct parent folder of where the launcher settings should be stored. * - * The launcher settings are persisted to different formats (to have a fail-over phase before deprecating the legacy - * format). Calling this method will store the settings in the following format: - * - * * @param settings the launcher settings to persist * @param path the path to the folder where the launcher settings file should be written to - * @throws IOException + * @throws IOException if the file cannot be written */ public static synchronized void store(final Settings settings, final Path path) throws IOException { logger.debug("Writing launcher settings to '{}'.", path); @@ -189,13 +161,6 @@ public static synchronized void store(final Settings settings, final Path path) Files.createDirectories(path); } - Path legacyPath = path.resolve(LEGACY_FILE_NAME); - try (OutputStream outputStream = Files.newOutputStream(legacyPath)) { - toLegacy(settings).getProperties().store(outputStream, "Terasology Launcher - Settings"); - } - - //TODO: For the switch, only write JSON. For some failover safety we may write both formats for one or two - // releases before fully deprecating the Properties. Path jsonPath = path.resolve(JSON_FILE_NAME); logger.debug("Writing launcher settings to '{}'.", jsonPath); try (FileWriter writer = new FileWriter(jsonPath.toFile())) { diff --git a/src/test/java/org/terasology/launcher/settings/TestLauncherSettings.java b/src/test/java/org/terasology/launcher/settings/TestLauncherSettings.java index bd8f4bd1..2fe75140 100644 --- a/src/test/java/org/terasology/launcher/settings/TestLauncherSettings.java +++ b/src/test/java/org/terasology/launcher/settings/TestLauncherSettings.java @@ -67,7 +67,7 @@ private void assertPropertiesEqual() throws Exception { @BeforeEach void setup() { - testPropertiesFile = tempDirectory.resolve(LauncherSettings.LAUNCHER_SETTINGS_FILE_NAME); + testPropertiesFile = tempDirectory.resolve(LauncherSettings.LAUNCHER_LEGACY_SETTINGS_FILE_NAME); launcherSettings = Settings.getDefault(); }