|
30 | 30 | import org.jackhuang.hmcl.event.EventPriority; |
31 | 31 | import org.jackhuang.hmcl.event.RefreshedVersionsEvent; |
32 | 32 | import org.jackhuang.hmcl.game.GameRepository; |
33 | | -import org.jackhuang.hmcl.game.HMCLGameRepository; |
34 | 33 | import org.jackhuang.hmcl.setting.Profile; |
| 34 | +import org.jackhuang.hmcl.task.Schedulers; |
| 35 | +import org.jackhuang.hmcl.task.Task; |
| 36 | +import org.jackhuang.hmcl.ui.Controllers; |
35 | 37 | import org.jackhuang.hmcl.ui.FXUtils; |
36 | 38 | import org.jackhuang.hmcl.ui.SVG; |
37 | 39 | import org.jackhuang.hmcl.ui.WeakListenerHolder; |
38 | 40 | import org.jackhuang.hmcl.ui.animation.TransitionPane; |
39 | 41 | import org.jackhuang.hmcl.ui.construct.*; |
40 | 42 | import org.jackhuang.hmcl.ui.decorator.DecoratorAnimatedPage; |
41 | 43 | import org.jackhuang.hmcl.ui.decorator.DecoratorPage; |
| 44 | +import org.jackhuang.hmcl.util.StringUtils; |
42 | 45 | import org.jackhuang.hmcl.util.io.FileUtils; |
43 | 46 |
|
| 47 | +import java.nio.file.Path; |
44 | 48 | import java.util.Optional; |
45 | 49 | import java.util.function.Supplier; |
46 | 50 |
|
@@ -186,15 +190,34 @@ private void redownloadAssetIndex() { |
186 | 190 | } |
187 | 191 |
|
188 | 192 | private void clearLibraries() { |
189 | | - FileUtils.deleteDirectoryQuietly(getProfile().getRepository().getBaseDirectory().resolve("libraries")); |
| 193 | + var libraries = getProfile().getRepository().getBaseDirectory().resolve("libraries"); |
| 194 | + Task.runAsync(Schedulers.io(), () -> { |
| 195 | + FileUtils.deleteDirectoryQuietly(libraries); |
| 196 | + }).whenComplete(Schedulers.javafx(), (exception) -> { |
| 197 | + if (exception != null) { |
| 198 | + Controllers.dialog(i18n("message.failed") + "\n" + StringUtils.getStackTrace(exception), i18n("message.error"), MessageDialogPane.MessageType.ERROR); |
| 199 | + } |
| 200 | + }).start(); |
190 | 201 | } |
191 | 202 |
|
192 | 203 | private void clearAssets() { |
193 | | - HMCLGameRepository baseDirectory = getProfile().getRepository(); |
194 | | - FileUtils.deleteDirectoryQuietly(baseDirectory.getBaseDirectory().resolve("assets")); |
195 | | - if (version.get() != null) { |
196 | | - FileUtils.deleteDirectoryQuietly(baseDirectory.getRunDirectory(version.get().getVersion()).resolve("resources")); |
197 | | - } |
| 204 | + Path assetsDir = getProfile().getRepository().getBaseDirectory().resolve("assets"); |
| 205 | + |
| 206 | + Profile.ProfileVersion currentVersion = version.get(); |
| 207 | + Path resourcesDir = currentVersion != null |
| 208 | + ? getProfile().getRepository().getRunDirectory(currentVersion.getVersion()).resolve("resources") |
| 209 | + : null; |
| 210 | + |
| 211 | + Task.runAsync(Schedulers.io(), () -> { |
| 212 | + FileUtils.deleteDirectoryQuietly(assetsDir); |
| 213 | + if (resourcesDir != null) { |
| 214 | + FileUtils.deleteDirectoryQuietly(resourcesDir); |
| 215 | + } |
| 216 | + }).whenComplete(Schedulers.javafx(), (exception) -> { |
| 217 | + if (exception != null) { |
| 218 | + Controllers.dialog(i18n("message.failed") + "\n" + StringUtils.getStackTrace(exception), i18n("message.error"), MessageDialogPane.MessageType.ERROR); |
| 219 | + } |
| 220 | + }).start(); |
198 | 221 | } |
199 | 222 |
|
200 | 223 | private void clearJunkFiles() { |
|
0 commit comments