-
Notifications
You must be signed in to change notification settings - Fork 885
修复清理游戏资源 / 库操作在 FXThread 运行的问题 #5301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "\u56FA\u6C5F\u6CB3\u6210\u5E1D\u4E1A\u7ACB\u56FD\u5BB6\u7EC8\u5F52\u4E8E\u4E71\u5149\u9634\u901D\u5343\u8F7D\u8FC7\u529F\u6210\u8005\u90FD\u4ED8\u7B11\u8C08\u95F4"
Changes from all commits
cd65820
71418ac
47ff7a9
1eb9227
f873cf9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,17 +30,21 @@ | |
| import org.jackhuang.hmcl.event.EventPriority; | ||
| import org.jackhuang.hmcl.event.RefreshedVersionsEvent; | ||
| import org.jackhuang.hmcl.game.GameRepository; | ||
| import org.jackhuang.hmcl.game.HMCLGameRepository; | ||
| import org.jackhuang.hmcl.setting.Profile; | ||
| import org.jackhuang.hmcl.task.Schedulers; | ||
| import org.jackhuang.hmcl.task.Task; | ||
| import org.jackhuang.hmcl.ui.Controllers; | ||
| import org.jackhuang.hmcl.ui.FXUtils; | ||
| import org.jackhuang.hmcl.ui.SVG; | ||
| import org.jackhuang.hmcl.ui.WeakListenerHolder; | ||
| import org.jackhuang.hmcl.ui.animation.TransitionPane; | ||
| import org.jackhuang.hmcl.ui.construct.*; | ||
| import org.jackhuang.hmcl.ui.decorator.DecoratorAnimatedPage; | ||
| import org.jackhuang.hmcl.ui.decorator.DecoratorPage; | ||
| import org.jackhuang.hmcl.util.StringUtils; | ||
| import org.jackhuang.hmcl.util.io.FileUtils; | ||
|
|
||
| import java.nio.file.Path; | ||
| import java.util.Optional; | ||
| import java.util.function.Supplier; | ||
|
|
||
|
|
@@ -186,15 +190,34 @@ private void redownloadAssetIndex() { | |
| } | ||
|
|
||
| private void clearLibraries() { | ||
| FileUtils.deleteDirectoryQuietly(getProfile().getRepository().getBaseDirectory().resolve("libraries")); | ||
| var libraries = getProfile().getRepository().getBaseDirectory().resolve("libraries"); | ||
| Task.runAsync(Schedulers.io(), () -> { | ||
| FileUtils.deleteDirectoryQuietly(libraries); | ||
| }).whenComplete(Schedulers.javafx(), (exception) -> { | ||
| if (exception != null) { | ||
| Controllers.dialog(i18n("message.failed") + "\n" + StringUtils.getStackTrace(exception), i18n("message.error"), MessageDialogPane.MessageType.ERROR); | ||
| } | ||
| }).start(); | ||
| } | ||
|
|
||
| private void clearAssets() { | ||
| HMCLGameRepository baseDirectory = getProfile().getRepository(); | ||
| FileUtils.deleteDirectoryQuietly(baseDirectory.getBaseDirectory().resolve("assets")); | ||
| if (version.get() != null) { | ||
| FileUtils.deleteDirectoryQuietly(baseDirectory.getRunDirectory(version.get().getVersion()).resolve("resources")); | ||
| } | ||
| Path assetsDir = getProfile().getRepository().getBaseDirectory().resolve("assets"); | ||
|
|
||
| Profile.ProfileVersion currentVersion = version.get(); | ||
| Path resourcesDir = currentVersion != null | ||
| ? getProfile().getRepository().getRunDirectory(currentVersion.getVersion()).resolve("resources") | ||
| : null; | ||
|
|
||
| Task.runAsync(Schedulers.io(), () -> { | ||
| FileUtils.deleteDirectoryQuietly(assetsDir); | ||
| if (resourcesDir != null) { | ||
| FileUtils.deleteDirectoryQuietly(resourcesDir); | ||
| } | ||
| }).whenComplete(Schedulers.javafx(), (exception) -> { | ||
| if (exception != null) { | ||
| Controllers.dialog(i18n("message.failed") + "\n" + StringUtils.getStackTrace(exception), i18n("message.error"), MessageDialogPane.MessageType.ERROR); | ||
| } | ||
|
Comment on lines
+211
to
+219
|
||
| }).start(); | ||
| } | ||
|
|
||
| private void clearJunkFiles() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FileUtils.deleteDirectoryQuietly(...)swallowsIOExceptionand returnsfalse, so thisTask.runAsync(...)closure will usually complete successfully even when deletion fails. As a result,whenComplete(..., exception -> ...)won’t show an error dialog on common failures. If you want to report failures, usedeleteDirectory(...)(let the exception propagate) or check the boolean result and throw/show an error accordingly.