add: clear button for cache directory

This commit is contained in:
huanghongxun
2020-02-17 00:46:11 +08:00
parent a1226012ff
commit bc4b41e8cd
9 changed files with 23 additions and 3 deletions

View File

@@ -40,9 +40,11 @@ import org.jackhuang.hmcl.upgrade.UpdateChecker;
import org.jackhuang.hmcl.upgrade.UpdateHandler; import org.jackhuang.hmcl.upgrade.UpdateHandler;
import org.jackhuang.hmcl.util.Logging; import org.jackhuang.hmcl.util.Logging;
import org.jackhuang.hmcl.util.i18n.Locales; import org.jackhuang.hmcl.util.i18n.Locales;
import org.jackhuang.hmcl.util.io.FileUtils;
import org.jackhuang.hmcl.util.javafx.SafeStringConverter; import org.jackhuang.hmcl.util.javafx.SafeStringConverter;
import java.awt.*; import java.awt.*;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.Proxy; import java.net.Proxy;
import java.nio.file.Files; import java.nio.file.Files;
@@ -251,4 +253,9 @@ public final class SettingsPage extends SettingsView implements DecoratorPage {
protected void onSponsor() { protected void onSponsor() {
FXUtils.openLink("https://hmcl.huangyuhui.net/api/redirect/sponsor"); FXUtils.openLink("https://hmcl.huangyuhui.net/api/redirect/sponsor");
} }
@Override
protected void clearCacheDirectory() {
FileUtils.cleanDirectoryQuietly(new File(Settings.instance().getCommonDirectory(), "cache"));
}
} }

View File

@@ -183,6 +183,14 @@ public abstract class SettingsView extends StackPane {
fileCommonLocation.setHasSubtitle(true); fileCommonLocation.setHasSubtitle(true);
fileCommonLocation.setCustomText("settings.custom"); fileCommonLocation.setCustomText("settings.custom");
{
JFXButton cleanButton = new JFXButton(i18n("launcher.cache_directory.clean"));
cleanButton.setOnMouseClicked(e -> clearCacheDirectory());
cleanButton.getStyleClass().add("jfx-button-border");
fileCommonLocation.setHeaderRight(cleanButton);
}
settingsPane.getContent().add(fileCommonLocation); settingsPane.getContent().add(fileCommonLocation);
} }
@@ -526,4 +534,5 @@ public abstract class SettingsView extends StackPane {
protected abstract void onHelp(); protected abstract void onHelp();
protected abstract void onExportLogs(); protected abstract void onExportLogs();
protected abstract void onSponsor(); protected abstract void onSponsor();
protected abstract void clearCacheDirectory();
} }

View File

@@ -23,7 +23,7 @@ import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.Node; import javafx.scene.Node;
@DefaultProperty("content") @DefaultProperty("content")
public final class ComponentSublist extends ComponentList { public class ComponentSublist extends ComponentList {
private final ObjectProperty<Node> headerLeft = new SimpleObjectProperty<>(this, "headerLeft"); private final ObjectProperty<Node> headerLeft = new SimpleObjectProperty<>(this, "headerLeft");
private final ObjectProperty<Node> headerRight = new SimpleObjectProperty<>(this, "headerRight"); private final ObjectProperty<Node> headerRight = new SimpleObjectProperty<>(this, "headerRight");

View File

@@ -47,7 +47,7 @@ import java.util.function.Consumer;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
public class MultiFileItem<T> extends ComponentList { public class MultiFileItem<T> extends ComponentSublist {
private final StringProperty customTitle = new SimpleStringProperty(this, "customTitle", i18n("selector.custom")); private final StringProperty customTitle = new SimpleStringProperty(this, "customTitle", i18n("selector.custom"));
private final StringProperty chooserTitle = new SimpleStringProperty(this, "chooserTitle", i18n("selector.choose_file")); private final StringProperty chooserTitle = new SimpleStringProperty(this, "chooserTitle", i18n("selector.choose_file"));
private final BooleanProperty directory = new SimpleBooleanProperty(this, "directory", false); private final BooleanProperty directory = new SimpleBooleanProperty(this, "directory", false);

View File

@@ -193,6 +193,7 @@ launcher.background=Background Image
launcher.background.choose=Choose a background image file launcher.background.choose=Choose a background image file
launcher.background.default=Standard launcher.background.default=Standard
launcher.cache_directory=Directory for caching launcher.cache_directory=Directory for caching
launcher.cache_directory.clean=Clear
launcher.cache_directory.choose=Choose the directory for caching launcher.cache_directory.choose=Choose the directory for caching
launcher.cache_directory.default=Standard launcher.cache_directory.default=Standard
launcher.cache_directory.disabled=Disabled launcher.cache_directory.disabled=Disabled

View File

@@ -190,6 +190,7 @@ launcher.background=Изображение на заднем плане
launcher.background.choose=Выберите путь до изображения на заднем плане launcher.background.choose=Выберите путь до изображения на заднем плане
launcher.background.default=Стандартное launcher.background.default=Стандартное
launcher.cache_directory=Каталог для скачки библиотек launcher.cache_directory=Каталог для скачки библиотек
launcher.cache_directory.clean=Очистить
launcher.cache_directory.choose=Выбор каталога для скачки кеша launcher.cache_directory.choose=Выбор каталога для скачки кеша
launcher.cache_directory.default=По умолчанию launcher.cache_directory.default=По умолчанию
launcher.cache_directory.disabled=Отключено launcher.cache_directory.disabled=Отключено

View File

@@ -191,6 +191,7 @@ launcher.background=背景位址
launcher.background.choose=選擇背景路徑 launcher.background.choose=選擇背景路徑
launcher.background.default=預設(自動尋找啟動器同目錄下的 background.png/jpg 及 bg 資料夾內的圖片) launcher.background.default=預設(自動尋找啟動器同目錄下的 background.png/jpg 及 bg 資料夾內的圖片)
launcher.cache_directory=檔案下載快取目錄 launcher.cache_directory=檔案下載快取目錄
launcher.cache_directory.clean=清理
launcher.cache_directory.choose=選擇檔案下載快取目錄 launcher.cache_directory.choose=選擇檔案下載快取目錄
launcher.cache_directory.default=預設 launcher.cache_directory.default=預設
launcher.cache_directory.disabled=停用 launcher.cache_directory.disabled=停用

View File

@@ -192,6 +192,7 @@ launcher.background=背景地址
launcher.background.choose=选择背景路径 launcher.background.choose=选择背景路径
launcher.background.default=默认(自动检索启动器同目录下的 background.png/jpg 及 bg 文件夹内的图片) launcher.background.default=默认(自动检索启动器同目录下的 background.png/jpg 及 bg 文件夹内的图片)
launcher.cache_directory=文件下载缓存目录 launcher.cache_directory=文件下载缓存目录
launcher.cache_directory.clean=清理
launcher.cache_directory.choose=选择文件下载缓存目录 launcher.cache_directory.choose=选择文件下载缓存目录
launcher.cache_directory.default=默认(%AppData%/.minecraft 或者 ~/.minecraft launcher.cache_directory.default=默认(%AppData%/.minecraft 或者 ~/.minecraft
launcher.cache_directory.disabled=禁用(总是使用游戏路径) launcher.cache_directory.disabled=禁用(总是使用游戏路径)

View File

@@ -48,7 +48,7 @@ public final class Schedulers {
public static synchronized ThreadPoolExecutor io() { public static synchronized ThreadPoolExecutor io() {
if (IO_EXECUTOR == null) if (IO_EXECUTOR == null)
IO_EXECUTOR = new ThreadPoolExecutor(0, 6, IO_EXECUTOR = new ThreadPoolExecutor(6, 6,
60L, TimeUnit.SECONDS, 60L, TimeUnit.SECONDS,
new SynchronousQueue<>(), new SynchronousQueue<>(),
runnable -> { runnable -> {