mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FEATURE] Safe config write
This commit is contained in:
parent
0d1b32fc1c
commit
553cdf5250
1 changed files with 7 additions and 6 deletions
|
@ -28,10 +28,7 @@
|
||||||
import pro.gravit.utils.helper.JVMHelper;
|
import pro.gravit.utils.helper.JVMHelper;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
|
@ -148,9 +145,11 @@ public LaunchServerRuntimeConfig readRuntimeConfig() throws IOException {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeConfig(LaunchServerConfig config) throws IOException {
|
public void writeConfig(LaunchServerConfig config) throws IOException {
|
||||||
try (Writer writer = IOHelper.newWriter(configFile)) {
|
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||||
|
try (Writer writer = IOHelper.newWriter(output)) {
|
||||||
if (Launcher.gsonManager.configGson != null) {
|
if (Launcher.gsonManager.configGson != null) {
|
||||||
Launcher.gsonManager.configGson.toJson(config, writer);
|
Launcher.gsonManager.configGson.toJson(config, writer);
|
||||||
|
IOHelper.write(configFile, output.toByteArray());
|
||||||
} else {
|
} else {
|
||||||
logger.error("Error writing LaunchServer runtime config file. Gson is null");
|
logger.error("Error writing LaunchServer runtime config file. Gson is null");
|
||||||
}
|
}
|
||||||
|
@ -159,9 +158,11 @@ public void writeConfig(LaunchServerConfig config) throws IOException {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeRuntimeConfig(LaunchServerRuntimeConfig config) throws IOException {
|
public void writeRuntimeConfig(LaunchServerRuntimeConfig config) throws IOException {
|
||||||
try (Writer writer = IOHelper.newWriter(runtimeConfigFile)) {
|
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||||
|
try (Writer writer = IOHelper.newWriter(output)) {
|
||||||
if (Launcher.gsonManager.configGson != null) {
|
if (Launcher.gsonManager.configGson != null) {
|
||||||
Launcher.gsonManager.configGson.toJson(config, writer);
|
Launcher.gsonManager.configGson.toJson(config, writer);
|
||||||
|
IOHelper.write(runtimeConfigFile, output.toByteArray());
|
||||||
} else {
|
} else {
|
||||||
logger.error("Error writing LaunchServer runtime config file. Gson is null");
|
logger.error("Error writing LaunchServer runtime config file. Gson is null");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue