Skip to content

Commit

Permalink
Preferences file read after deletion (FAForever#1627)
Browse files Browse the repository at this point in the history
  • Loading branch information
1-alex98 authored and Chris Haggan committed Apr 15, 2022
1 parent 67f2c05 commit 7f720e8
Showing 1 changed file with 10 additions and 4 deletions.
Expand Up @@ -43,8 +43,8 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.MessageDigest;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.MessageFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -148,8 +148,9 @@ public Path getPreferencesDirectory() {
@Override
public void afterPropertiesSet() throws IOException {
if (Files.exists(preferencesFilePath)) {
deleteFileIfEmpty();
readExistingFile(preferencesFilePath);
if (!deleteFileIfEmpty()) {
readExistingFile(preferencesFilePath);
}
} else {
preferences = new Preferences();
}
Expand Down Expand Up @@ -181,11 +182,16 @@ public static void configureLogging() {

/**
* It may happen that the file is empty when the process is forcibly killed, so remove the file if that happened.
*
* @return true if the file was deleted
*/
private void deleteFileIfEmpty() throws IOException {
private boolean deleteFileIfEmpty() throws IOException {
if (Files.size(preferencesFilePath) == 0) {
Files.delete(preferencesFilePath);
preferences = new Preferences();
return true;
}
return false;
}

public Path getFafBinDirectory() {
Expand Down

0 comments on commit 7f720e8

Please sign in to comment.