|
27 | 27 | import javafx.scene.control.ToggleGroup; |
28 | 28 | import javafx.scene.layout.*; |
29 | 29 | import org.jackhuang.hmcl.setting.DownloadProviders; |
| 30 | +import org.jackhuang.hmcl.setting.EnumCommonDirectory; |
| 31 | +import org.jackhuang.hmcl.setting.Settings; |
30 | 32 | import org.jackhuang.hmcl.task.FetchTask; |
31 | 33 | import org.jackhuang.hmcl.ui.FXUtils; |
32 | 34 | import org.jackhuang.hmcl.ui.WeakListenerHolder; |
33 | 35 | import org.jackhuang.hmcl.ui.construct.*; |
34 | 36 | import org.jackhuang.hmcl.util.i18n.I18n; |
| 37 | +import org.jackhuang.hmcl.util.io.FileUtils; |
35 | 38 | import org.jackhuang.hmcl.util.javafx.SafeStringConverter; |
36 | 39 |
|
37 | 40 | import java.net.Proxy; |
| 41 | +import java.nio.file.Path; |
| 42 | +import java.util.Arrays; |
| 43 | +import java.util.Optional; |
38 | 44 | import java.util.concurrent.atomic.AtomicBoolean; |
39 | 45 | import java.util.function.Function; |
40 | 46 |
|
@@ -98,9 +104,37 @@ public DownloadSettingsPage() { |
98 | 104 | } |
99 | 105 |
|
100 | 106 | { |
| 107 | + var downloadList = new ComponentList(); |
| 108 | + |
101 | 109 | VBox downloadThreads = new VBox(16); |
102 | | - downloadThreads.getStyleClass().add("card-non-transparent"); |
| 110 | + |
| 111 | + ComponentSublist fileCommonLocationSublist = new ComponentSublist(); |
| 112 | + |
103 | 113 | { |
| 114 | + { |
| 115 | + MultiFileItem<EnumCommonDirectory> fileCommonLocation = new MultiFileItem<>(); |
| 116 | + fileCommonLocation.loadChildren(Arrays.asList( |
| 117 | + new MultiFileItem.Option<>(i18n("launcher.cache_directory.default"), EnumCommonDirectory.DEFAULT), |
| 118 | + new MultiFileItem.FileOption<>(i18n("settings.custom"), EnumCommonDirectory.CUSTOM) |
| 119 | + .setChooserTitle(i18n("launcher.cache_directory.choose")) |
| 120 | + .setSelectionMode(FileSelector.SelectionMode.DIRECTORY) |
| 121 | + .bindBidirectional(config().commonDirectoryProperty()) |
| 122 | + )); |
| 123 | + fileCommonLocation.selectedDataProperty().bindBidirectional(config().commonDirTypeProperty()); |
| 124 | + |
| 125 | + fileCommonLocationSublist.getContent().add(fileCommonLocation); |
| 126 | + fileCommonLocationSublist.setTitle(i18n("launcher.cache_directory")); |
| 127 | + fileCommonLocationSublist.setHasSubtitle(true); |
| 128 | + fileCommonLocationSublist.subtitleProperty().bind( |
| 129 | + Bindings.createObjectBinding(() -> Optional.ofNullable(Settings.instance().getCommonDirectory()) |
| 130 | + .orElse(i18n("launcher.cache_directory.disabled")), |
| 131 | + config().commonDirectoryProperty(), config().commonDirTypeProperty())); |
| 132 | + |
| 133 | + JFXButton cleanButton = FXUtils.newBorderButton(i18n("launcher.cache_directory.clean")); |
| 134 | + cleanButton.setOnAction(e -> clearCacheDirectory()); |
| 135 | + fileCommonLocationSublist.setHeaderRight(cleanButton); |
| 136 | + } |
| 137 | + |
104 | 138 | { |
105 | 139 | JFXCheckBox chkAutoDownloadThreads = new JFXCheckBox(i18n("settings.launcher.download.threads.auto")); |
106 | 140 | VBox.setMargin(chkAutoDownloadThreads, new Insets(8, 0, 0, 0)); |
@@ -153,7 +187,8 @@ public DownloadSettingsPage() { |
153 | 187 | } |
154 | 188 | } |
155 | 189 |
|
156 | | - content.getChildren().addAll(ComponentList.createComponentListTitle(i18n("download")), downloadThreads); |
| 190 | + downloadList.getContent().addAll(fileCommonLocationSublist, downloadThreads); |
| 191 | + content.getChildren().addAll(ComponentList.createComponentListTitle(i18n("download")), downloadList); |
157 | 192 | } |
158 | 193 |
|
159 | 194 | { |
@@ -330,4 +365,11 @@ public DownloadSettingsPage() { |
330 | 365 | } |
331 | 366 |
|
332 | 367 | } |
| 368 | + |
| 369 | + private void clearCacheDirectory() { |
| 370 | + String commonDirectory = Settings.instance().getCommonDirectory(); |
| 371 | + if (commonDirectory != null) { |
| 372 | + FileUtils.cleanDirectoryQuietly(Path.of(commonDirectory, "cache")); |
| 373 | + } |
| 374 | + } |
333 | 375 | } |
0 commit comments