From c9d825b6c128a3f09679db7e58db768bacf8e330 Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Tue, 23 Oct 2018 14:08:51 +0800 Subject: [PATCH] Add a button for cleaning crash-reports and logs manually --- .../org/jackhuang/hmcl/game/HMCLGameRepository.java | 10 ++++++++++ .../main/java/org/jackhuang/hmcl/ui/Controllers.java | 2 +- .../org/jackhuang/hmcl/ui/versions/VersionPage.java | 3 ++- .../java/org/jackhuang/hmcl/ui/versions/Versions.java | 10 ++++++++++ HMCL/src/main/resources/assets/lang/I18N.properties | 1 + HMCL/src/main/resources/assets/lang/I18N_zh.properties | 1 + .../main/resources/assets/lang/I18N_zh_CN.properties | 1 + 7 files changed, 26 insertions(+), 2 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java b/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java index 2d21b77a6..ace6ee34e 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java @@ -93,6 +93,16 @@ public class HMCLGameRepository extends DefaultGameRepository { refreshVersionsAsync().start(); } + private void clean(File directory) throws IOException { + FileUtils.deleteDirectory(new File(directory, "crash-reports")); + FileUtils.deleteDirectory(new File(directory, "logs")); + } + + public void clean(String id) throws IOException { + clean(getBaseDirectory()); + clean(getRunDirectory(id)); + } + private File getVersionSettingFile(String id) { return new File(getVersionRoot(id), "hmclversion.cfg"); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java index acd0e49be..d6c96a637 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java @@ -156,7 +156,7 @@ public final class Controllers { .collect(Collectors.toList()); if (!modpacks.isEmpty()) { File modpack = modpacks.get(0); - Controllers.getDecorator().startWizard(new ModpackInstallWizardProvider(modpack), i18n("install.modpack")); + Controllers.getDecorator().startWizard(new ModpackInstallWizardProvider(Profiles.getSelectedProfile(), modpack), i18n("install.modpack")); event.setDropCompleted(true); } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionPage.java index e2b3ff197..1478afee4 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionPage.java @@ -98,7 +98,8 @@ public final class VersionPage extends StackPane implements DecoratorPage { new IconedMenuItem(null, i18n("version.manage.rename"), FXUtils.withJFXPopupClosing(() -> Versions.renameVersion(profile, version), managementPopup)), new IconedMenuItem(null, i18n("version.manage.remove"), FXUtils.withJFXPopupClosing(() -> Versions.deleteVersion(profile, version), managementPopup)), new IconedMenuItem(null, i18n("version.manage.redownload_assets_index"), FXUtils.withJFXPopupClosing(() -> new GameAssetIndexDownloadTask(profile.getDependency(), profile.getRepository().getResolvedVersion(version)).start(), managementPopup)), - new IconedMenuItem(null, i18n("version.manage.remove_libraries"), FXUtils.withJFXPopupClosing(() -> FileUtils.deleteDirectoryQuietly(new File(profile.getRepository().getBaseDirectory(), "libraries")), managementPopup)) + new IconedMenuItem(null, i18n("version.manage.remove_libraries"), FXUtils.withJFXPopupClosing(() -> FileUtils.deleteDirectoryQuietly(new File(profile.getRepository().getBaseDirectory(), "libraries")), managementPopup)), + new IconedMenuItem(null, i18n("version.manage.clean"), FXUtils.withJFXPopupClosing(() -> Versions.cleanVersion(profile, version), managementPopup)) ); FXUtils.installTooltip(btnDelete, i18n("version.manage.remove")); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/Versions.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/Versions.java index 70c770d31..2e6fc0173 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/Versions.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/Versions.java @@ -35,12 +35,14 @@ import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.construct.DialogCloseEvent; import org.jackhuang.hmcl.ui.construct.MessageBox; import org.jackhuang.hmcl.ui.export.ExportWizardProvider; +import org.jackhuang.hmcl.util.Logging; import org.jackhuang.hmcl.util.io.FileUtils; import org.jackhuang.hmcl.util.platform.OperatingSystem; import java.io.File; import java.io.IOException; import java.util.concurrent.atomic.AtomicReference; +import java.util.logging.Level; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; @@ -100,6 +102,14 @@ public class Versions { } } + public static void cleanVersion(Profile profile, String id) { + try { + profile.getRepository().clean(id); + } catch (IOException e) { + Logging.LOG.log(Level.WARNING, "Unable to clean game directory", e); + } + } + public static void generateLaunchScript(Profile profile, String id) { if (checkForLaunching(profile, id)) { GameRepository repository = profile.getRepository(); diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index f2478bb93..b929e057f 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -382,6 +382,7 @@ version.launch_script.failed=Unable to make launch script. version.launch_script.save=Save the launch script version.launch_script.success=Finished script creation, %s. version.manage=Game List +version.manage.clean=Clean game directory version.manage.manage=Manage Game version.manage.redownload_assets_index=Redownload Assets Index version.manage.remove=Delete this game diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index ebaa9cce9..eaf971055 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -382,6 +382,7 @@ version.launch_script.failed=生成啟動腳本失敗 version.launch_script.save=儲存啟動腳本 version.launch_script.success=啟動腳本已生成完畢:%s version.manage=遊戲列表 +version.manage.clean=清理遊戲目錄 version.manage.manage=游戏管理 version.manage.redownload_assets_index=更新資源列表 version.manage.remove=刪除該版本 diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties index afb20d57c..1747a0dc4 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -382,6 +382,7 @@ version.launch_script.failed=生成启动脚本失败 version.launch_script.save=保存启动脚本 version.launch_script.success=启动脚本已生成完毕:%s version.manage=游戏列表 +version.manage.clean=清理游戏目录 version.manage.manage=游戏管理 version.manage.redownload_assets_index=更新资源列表 version.manage.remove=删除该版本