mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-01-12 14:14:52 +08:00
* fix #1705: Do not re-enable mod after update * update * Do not select disabled mods by default
This commit is contained in:
parent
0130676b42
commit
753ba956fe
@ -61,6 +61,7 @@ public class ModUpdatesPage extends BorderPane implements DecoratorPage {
|
||||
private final ModManager modManager;
|
||||
private final ObservableList<ModUpdateObject> objects;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public ModUpdatesPage(ModManager modManager, List<LocalModFile.ModUpdate> updates) {
|
||||
this.modManager = modManager;
|
||||
|
||||
@ -138,7 +139,7 @@ public class ModUpdatesPage extends BorderPane implements DecoratorPage {
|
||||
fireEvent(new PageCloseEvent());
|
||||
if (!task.getFailedMods().isEmpty()) {
|
||||
Controllers.dialog(i18n("mods.check_updates.failed") + "\n" +
|
||||
task.getFailedMods().stream().map(LocalModFile::getFileName).collect(Collectors.joining("\n")),
|
||||
task.getFailedMods().stream().map(LocalModFile::getFileName).collect(Collectors.joining("\n")),
|
||||
i18n("install.failed"),
|
||||
MessageDialogPane.MessageType.ERROR);
|
||||
}
|
||||
@ -192,7 +193,7 @@ public class ModUpdatesPage extends BorderPane implements DecoratorPage {
|
||||
public ModUpdateObject(LocalModFile.ModUpdate data) {
|
||||
this.data = data;
|
||||
|
||||
enabled.set(true);
|
||||
enabled.set(!data.getLocalMod().getModManager().isDisabled(data.getLocalMod().getFile()));
|
||||
fileName.set(data.getLocalMod().getFileName());
|
||||
currentVersion.set(data.getCurrentVersion().getVersion());
|
||||
targetVersion.set(data.getCandidates().get(0).getVersion());
|
||||
@ -274,28 +275,37 @@ public class ModUpdatesPage extends BorderPane implements DecoratorPage {
|
||||
setStage("mods.check_updates.update");
|
||||
getProperties().put("total", mods.size());
|
||||
|
||||
dependents = mods.stream()
|
||||
.map(mod -> {
|
||||
return Task
|
||||
.runAsync(Schedulers.javafx(), () -> mod.getKey().setOld(true))
|
||||
.thenComposeAsync(() -> {
|
||||
FileDownloadTask task = new FileDownloadTask(
|
||||
new URL(mod.getValue().getFile().getUrl()),
|
||||
modManager.getModsDirectory().resolve(mod.getValue().getFile().getFilename()).toFile());
|
||||
this.dependents = new ArrayList<>();
|
||||
for (Pair<LocalModFile, RemoteMod.Version> mod : mods) {
|
||||
LocalModFile local = mod.getKey();
|
||||
RemoteMod.Version remote = mod.getValue();
|
||||
boolean isDisabled = local.getModManager().isDisabled(local.getFile());
|
||||
|
||||
task.setName(mod.getValue().getName());
|
||||
return task;
|
||||
})
|
||||
.whenComplete(Schedulers.javafx(), exception -> {
|
||||
if (exception != null) {
|
||||
// restore state if failed
|
||||
mod.getKey().setOld(false);
|
||||
failedMods.add(mod.getKey());
|
||||
}
|
||||
})
|
||||
.withCounter("mods.check_updates.update");
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
dependents.add(Task
|
||||
.runAsync(Schedulers.javafx(), () -> local.setOld(true))
|
||||
.thenComposeAsync(() -> {
|
||||
String fileName = remote.getFile().getFilename();
|
||||
if (isDisabled)
|
||||
fileName += ModManager.DISABLED_EXTENSION;
|
||||
|
||||
FileDownloadTask task = new FileDownloadTask(
|
||||
new URL(remote.getFile().getUrl()),
|
||||
modManager.getModsDirectory().resolve(fileName).toFile());
|
||||
|
||||
task.setName(remote.getName());
|
||||
return task;
|
||||
})
|
||||
.whenComplete(Schedulers.javafx(), exception -> {
|
||||
if (exception != null) {
|
||||
// restore state if failed
|
||||
local.setOld(false);
|
||||
if (isDisabled)
|
||||
local.disable();
|
||||
failedMods.add(local);
|
||||
}
|
||||
})
|
||||
.withCounter("mods.check_updates.update"));
|
||||
}
|
||||
}
|
||||
|
||||
public List<LocalModFile> getFailedMods() {
|
||||
|
@ -170,6 +170,10 @@ public final class LocalModFile implements Comparable<LocalModFile> {
|
||||
}
|
||||
}
|
||||
|
||||
public void disable() throws IOException {
|
||||
file = modManager.disableMod(file);
|
||||
}
|
||||
|
||||
public ModUpdate checkUpdates(String gameVersion, RemoteModRepository repository) throws IOException {
|
||||
Optional<RemoteMod.Version> currentVersion = repository.getRemoteVersionByLocalFile(this, file);
|
||||
if (!currentVersion.isPresent()) return null;
|
||||
|
@ -234,7 +234,11 @@ public final class ModManager {
|
||||
|
||||
public Path disableMod(Path file) throws IOException {
|
||||
if (isOld(file)) return file; // no need to disable an old mod.
|
||||
Path disabled = file.resolveSibling(StringUtils.addSuffix(FileUtils.getName(file), DISABLED_EXTENSION));
|
||||
|
||||
String fileName = FileUtils.getName(file);
|
||||
if (fileName.endsWith(DISABLED_EXTENSION)) return file;
|
||||
|
||||
Path disabled = file.resolveSibling(fileName + DISABLED_EXTENSION);
|
||||
if (Files.exists(file))
|
||||
Files.move(file, disabled, StandardCopyOption.REPLACE_EXISTING);
|
||||
return disabled;
|
||||
|
Loading…
Reference in New Issue
Block a user