Skip to content

Commit

Permalink
fix(settings): stop writing legacy configuration file (#702)
Browse files Browse the repository at this point in the history
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 <skaldarnar@gmail.com>
  • Loading branch information
jschadewald and skaldarnar committed Aug 30, 2023
1 parent 8924b28 commit 51f03da
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
39 changes: 2 additions & 37 deletions src/main/java/org/terasology/launcher/settings/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -168,34 +147,20 @@ 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:
* <ul>
* <li>JSON</li>
* <li>Java {@link Properties}</li>
* </ul>
*
* @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);
if (Files.notExists(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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 51f03da

Please sign in to comment.