Fix crash when user set common directory to an invalid path

This commit is contained in:
huanghongxun
2018-09-26 19:00:31 +08:00
parent 5f686f7205
commit 5a0e17b121

View File

@@ -17,11 +17,15 @@
*/
package org.jackhuang.hmcl.setting;
import javafx.beans.binding.Bindings;
import javafx.scene.text.Font;
import org.jackhuang.hmcl.Launcher;
import org.jackhuang.hmcl.game.HMCLCacheRepository;
import org.jackhuang.hmcl.util.CacheRepository;
import java.nio.file.InvalidPathException;
import java.nio.file.Paths;
import static org.jackhuang.hmcl.setting.ConfigHolder.config;
public class Settings {
@@ -49,7 +53,15 @@ public class Settings {
Profiles.init();
CacheRepository.setInstance(HMCLCacheRepository.REPOSITORY);
HMCLCacheRepository.REPOSITORY.directoryProperty().bind(config().commonDirectoryProperty());
HMCLCacheRepository.REPOSITORY.directoryProperty().bind(Bindings.createStringBinding(() -> {
String str = config().getCommonDirectory();
try {
Paths.get(str);
return str;
} catch (InvalidPathException e) {
return getDefaultCommonDirectory();
}
}, config().commonDirectoryProperty()));
}
public Font getFont() {