fix: move .hmcl directory to $HOME/.cache/hmcl to fulfill XDG standard. Closes #849.

This commit is contained in:
huanghongxun 2021-03-07 13:21:57 +08:00
parent d22dae9834
commit 7ece35e28a
4 changed files with 19 additions and 10 deletions

View File

@ -17,11 +17,12 @@
*/
package org.jackhuang.hmcl;
import java.nio.file.Path;
import org.jackhuang.hmcl.util.io.JarUtils;
import org.jackhuang.hmcl.util.platform.OperatingSystem;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
* Stores metadata about this application.
*/
@ -39,5 +40,14 @@ public final class Metadata {
public static final String PUBLISH_URL = "http://www.mcbbs.net/thread-142335-1-1.html";
public static final Path MINECRAFT_DIRECTORY = OperatingSystem.getWorkingDirectory("minecraft");
public static final Path HMCL_DIRECTORY = OperatingSystem.getWorkingDirectory("hmcl");
public static final Path HMCL_DIRECTORY = getHMCLDirectory();
private static Path getHMCLDirectory() {
String home = System.getProperty("user.home", ".");
if (OperatingSystem.CURRENT_OS == OperatingSystem.LINUX) {
// to fulfill XDG standard.
return Paths.get(home, ".cache", "hmcl");
}
return OperatingSystem.getWorkingDirectory("hmcl");
}
}

View File

@ -22,6 +22,7 @@ import com.jfoenix.controls.JFXDialogLayout;
import javafx.scene.control.Label;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import org.jackhuang.hmcl.Metadata;
import org.jackhuang.hmcl.ui.construct.DialogCloseEvent;
import static org.jackhuang.hmcl.Metadata.CHANGELOG_URL;
@ -29,8 +30,6 @@ import static org.jackhuang.hmcl.setting.ConfigHolder.config;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
public class UpgradeDialog extends JFXDialogLayout {
private final WebView webView = new WebView();
public UpgradeDialog(Runnable updateRunnable) {
{
setHeading(new Label(i18n("update.changelog")));
@ -38,6 +37,7 @@ public class UpgradeDialog extends JFXDialogLayout {
{
WebView webView = new WebView();
webView.getEngine().setUserDataDirectory(Metadata.HMCL_DIRECTORY.toFile());
WebEngine engine = webView.getEngine();
engine.load(CHANGELOG_URL + config().getUpdateChannel().channelName);
engine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> {

View File

@ -25,6 +25,7 @@ import javafx.scene.layout.StackPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import org.jackhuang.hmcl.Metadata;
import static org.jackhuang.hmcl.setting.ConfigHolder.config;
import static org.jackhuang.hmcl.ui.FXUtils.newImage;
@ -43,6 +44,7 @@ public class WebStage extends Stage {
setScene(new Scene(pane, width, height));
getScene().getStylesheets().addAll(config().getTheme().getStylesheets());
getIcons().add(newImage("/assets/img/icon.png"));
webView.getEngine().setUserDataDirectory(Metadata.HMCL_DIRECTORY.toFile());
webView.setContextMenuEnabled(false);
progressBar.progressProperty().bind(webView.getEngine().getLoadWorker().progressProperty());

View File

@ -24,7 +24,6 @@ import org.jackhuang.hmcl.util.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.math.BigInteger;
import java.net.URL;
@ -47,8 +46,8 @@ import static org.jackhuang.hmcl.util.DigestUtils.getDigest;
public class FileDownloadTask extends FetchTask<Void> {
public static class IntegrityCheck {
private String algorithm;
private String checksum;
private final String algorithm;
private final String checksum;
public IntegrityCheck(String algorithm, String checksum) {
this.algorithm = requireNonNull(algorithm);
@ -83,8 +82,6 @@ public class FileDownloadTask extends FetchTask<Void> {
private final File file;
private final IntegrityCheck integrityCheck;
private Path candidate;
private RandomAccessFile rFile;
private InputStream stream;
private final ArrayList<IntegrityCheckHandler> integrityCheckHandlers = new ArrayList<>();
/**