1
0
mirror of https://github.com/SKCraft/Launcher.git synced 2025-01-21 21:31:32 +01:00

Fix Updater to only download additional loader files once

Previously the launcher was downloading these files once for every
processor due to code architecture limitations. By moving the download
queueing step into BaseUpdater we ensure they are only downloaded once.
This commit is contained in:
Henry Le Grys 2021-03-10 01:13:27 +00:00
parent ae6fb109e5
commit 4552b76465
6 changed files with 59 additions and 36 deletions

View File

@ -0,0 +1,17 @@
package com.skcraft.launcher.install;
import com.skcraft.launcher.model.loader.LocalLoader;
import lombok.Data;
import java.io.File;
import java.util.HashMap;
@Data
public class InstallExtras {
private final File contentDir;
private final HashMap<String, LocalLoader> loaders;
public LocalLoader getLoader(String key) {
return loaders.get(key);
}
}

View File

@ -0,0 +1,12 @@
package com.skcraft.launcher.model.loader;
import com.skcraft.launcher.model.modpack.DownloadableFile;
import lombok.Data;
import java.util.HashMap;
@Data
public class LocalLoader {
private final LoaderManifest manifest;
private final HashMap<String, DownloadableFile.LocalFile> localFiles;
}

View File

@ -1,21 +1,12 @@
package com.skcraft.launcher.model.loader;
import com.google.common.collect.Maps;
import com.skcraft.launcher.install.InstallLog;
import com.skcraft.launcher.install.Installer;
import com.skcraft.launcher.install.ProcessorTask;
import com.skcraft.launcher.install.UpdateCache;
import com.skcraft.launcher.model.minecraft.Side;
import com.skcraft.launcher.model.modpack.DownloadableFile;
import com.skcraft.launcher.install.*;
import com.skcraft.launcher.model.modpack.ManifestEntry;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import java.io.File;
import java.util.HashMap;
@Data
@AllArgsConstructor
@NoArgsConstructor
@ -25,18 +16,9 @@ public class ProcessorEntry extends ManifestEntry {
private InstallProcessor processor;
@Override
public void install(Installer installer, InstallLog log, UpdateCache cache, File contentDir) throws Exception {
LoaderManifest loaderManifest = getManifest().getLoaders().get(loaderName);
public void install(Installer installer, InstallLog log, UpdateCache cache, InstallExtras extras) throws Exception {
LocalLoader loader = extras.getLoader(loaderName);
HashMap<String, DownloadableFile.LocalFile> localFilesMap = Maps.newHashMap();
for (DownloadableFile downloadableFile : loaderManifest.getDownloadableFiles()) {
if (downloadableFile.getSide() != Side.CLIENT) continue;
DownloadableFile.LocalFile localFile = downloadableFile.download(installer, getManifest());
localFilesMap.put(localFile.getName(), localFile);
}
installer.queueLate(new ProcessorTask(processor, loaderManifest, getManifest(), localFilesMap));
installer.queueLate(new ProcessorTask(processor, loader.getManifest(), getManifest(), loader.getLocalFiles()));
}
}

View File

@ -10,10 +10,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;
import com.google.common.io.Files;
import com.skcraft.launcher.install.InstallLog;
import com.skcraft.launcher.install.InstallLogFileMover;
import com.skcraft.launcher.install.Installer;
import com.skcraft.launcher.install.UpdateCache;
import com.skcraft.launcher.install.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
@ -50,13 +47,13 @@ public class FileInstall extends ManifestEntry {
@Override
public void install(@NonNull Installer installer, @NonNull InstallLog log,
@NonNull UpdateCache cache, @NonNull File contentDir) throws IOException {
@NonNull UpdateCache cache, InstallExtras extras) throws IOException {
if (getWhen() != null && !getWhen().matches()) {
return;
}
String targetPath = getTargetPath();
File targetFile = new File(contentDir, targetPath);
File targetFile = new File(extras.getContentDir(), targetPath);
String fileVersion = getImpliedVersion();
URL url = concat(getManifest().getObjectsUrl(), getLocation());

View File

@ -9,6 +9,7 @@ package com.skcraft.launcher.model.modpack;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.skcraft.launcher.install.InstallExtras;
import com.skcraft.launcher.install.InstallLog;
import com.skcraft.launcher.install.Installer;
import com.skcraft.launcher.install.UpdateCache;
@ -16,8 +17,6 @@ import com.skcraft.launcher.model.loader.ProcessorEntry;
import lombok.Data;
import lombok.ToString;
import java.io.File;
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
@ -35,6 +34,6 @@ public abstract class ManifestEntry {
private Manifest manifest;
private Condition when;
public abstract void install(Installer installer, InstallLog log, UpdateCache cache, File contentDir) throws Exception;
public abstract void install(Installer installer, InstallLog log, UpdateCache cache, InstallExtras extras) throws Exception;
}

View File

@ -8,6 +8,7 @@ package com.skcraft.launcher.update;
import com.google.common.base.Strings;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.skcraft.launcher.AssetsRoot;
import com.skcraft.launcher.Instance;
import com.skcraft.launcher.Launcher;
@ -16,10 +17,9 @@ import com.skcraft.launcher.dialog.FeatureSelectionDialog;
import com.skcraft.launcher.dialog.ProgressDialog;
import com.skcraft.launcher.install.*;
import com.skcraft.launcher.model.loader.LoaderManifest;
import com.skcraft.launcher.model.minecraft.Asset;
import com.skcraft.launcher.model.minecraft.AssetsIndex;
import com.skcraft.launcher.model.minecraft.Library;
import com.skcraft.launcher.model.minecraft.VersionManifest;
import com.skcraft.launcher.model.loader.LocalLoader;
import com.skcraft.launcher.model.minecraft.*;
import com.skcraft.launcher.model.modpack.DownloadableFile;
import com.skcraft.launcher.model.modpack.Feature;
import com.skcraft.launcher.model.modpack.Manifest;
import com.skcraft.launcher.model.modpack.ManifestEntry;
@ -127,8 +127,24 @@ public abstract class BaseUpdater {
}
}
// Download any extra processing files for each loader
HashMap<String, LocalLoader> loaders = Maps.newHashMap();
for (Map.Entry<String, LoaderManifest> entry : manifest.getLoaders().entrySet()) {
HashMap<String, DownloadableFile.LocalFile> localFilesMap = Maps.newHashMap();
for (DownloadableFile file : entry.getValue().getDownloadableFiles()) {
if (file.getSide() != Side.CLIENT) continue;
DownloadableFile.LocalFile localFile = file.download(installer, manifest);
localFilesMap.put(localFile.getName(), localFile);
}
loaders.put(entry.getKey(), new LocalLoader(entry.getValue(), localFilesMap));
}
InstallExtras extras = new InstallExtras(contentDir, loaders);
for (ManifestEntry entry : manifest.getTasks()) {
entry.install(installer, currentLog, updateCache, contentDir);
entry.install(installer, currentLog, updateCache, extras);
}
executeOnCompletion.add(new Runnable() {