Fix crash when user set common directory to an invalid path
This commit is contained in:
@@ -17,11 +17,15 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.setting;
|
package org.jackhuang.hmcl.setting;
|
||||||
|
|
||||||
|
import javafx.beans.binding.Bindings;
|
||||||
import javafx.scene.text.Font;
|
import javafx.scene.text.Font;
|
||||||
import org.jackhuang.hmcl.Launcher;
|
import org.jackhuang.hmcl.Launcher;
|
||||||
import org.jackhuang.hmcl.game.HMCLCacheRepository;
|
import org.jackhuang.hmcl.game.HMCLCacheRepository;
|
||||||
import org.jackhuang.hmcl.util.CacheRepository;
|
import org.jackhuang.hmcl.util.CacheRepository;
|
||||||
|
|
||||||
|
import java.nio.file.InvalidPathException;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
import static org.jackhuang.hmcl.setting.ConfigHolder.config;
|
import static org.jackhuang.hmcl.setting.ConfigHolder.config;
|
||||||
|
|
||||||
public class Settings {
|
public class Settings {
|
||||||
@@ -49,7 +53,15 @@ public class Settings {
|
|||||||
Profiles.init();
|
Profiles.init();
|
||||||
|
|
||||||
CacheRepository.setInstance(HMCLCacheRepository.REPOSITORY);
|
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() {
|
public Font getFont() {
|
||||||
|
|||||||
Reference in New Issue
Block a user