Merge pull request #5898 from deathbeam/fix-corrupted-settings
Implement locking and corrupted file sanitization to ConfigManager
This commit is contained in:
@@ -36,9 +36,13 @@ import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.nio.channels.FileLock;
|
||||
import java.nio.charset.Charset;
|
||||
import java.time.Instant;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
@@ -179,7 +183,7 @@ public class ConfigManager
|
||||
|
||||
try (FileInputStream in = new FileInputStream(propertiesFile))
|
||||
{
|
||||
properties.load(in);
|
||||
properties.load(new InputStreamReader(in, Charset.forName("UTF-8")));
|
||||
}
|
||||
catch (FileNotFoundException ex)
|
||||
{
|
||||
@@ -199,6 +203,7 @@ public class ConfigManager
|
||||
if (split.length != 2)
|
||||
{
|
||||
log.debug("Properties key malformed!: {}", groupAndKey);
|
||||
properties.remove(groupAndKey);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -225,7 +230,16 @@ public class ConfigManager
|
||||
|
||||
try (FileOutputStream out = new FileOutputStream(propertiesFile))
|
||||
{
|
||||
properties.store(out, "RuneLite configuration");
|
||||
final FileLock lock = out.getChannel().lock();
|
||||
|
||||
try
|
||||
{
|
||||
properties.store(new OutputStreamWriter(out, Charset.forName("UTF-8")), "RuneLite configuration");
|
||||
}
|
||||
finally
|
||||
{
|
||||
lock.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user