mirror of
https://github.com/SKCraft/Launcher.git
synced 2025-01-23 21:51:26 +01:00
Improved assets expanding, downloader messages.
This commit is contained in:
parent
e60d556d02
commit
51907d99b3
@ -7,11 +7,13 @@
|
||||
package com.skcraft.launcher;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import com.skcraft.concurrency.ProgressObservable;
|
||||
import com.skcraft.launcher.model.minecraft.Asset;
|
||||
import com.skcraft.launcher.model.minecraft.AssetsIndex;
|
||||
import com.skcraft.launcher.model.minecraft.VersionManifest;
|
||||
import com.skcraft.launcher.persistence.Persistence;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.java.Log;
|
||||
|
||||
import java.io.File;
|
||||
@ -19,6 +21,8 @@ import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.skcraft.launcher.util.SharedLocale._;
|
||||
|
||||
@Log
|
||||
public class AssetsRoot {
|
||||
|
||||
@ -38,27 +42,67 @@ public class AssetsRoot {
|
||||
return new File(dir, "objects/" + hash.substring(0, 2) + "/" + hash);
|
||||
}
|
||||
|
||||
public File buildAssetTree(VersionManifest versionManifest) throws IOException {
|
||||
public AssetsTreeBuilder createAssetsBuilder(@NonNull VersionManifest versionManifest) {
|
||||
String indexId = versionManifest.getAssetsIndex();
|
||||
|
||||
log.info("Building asset virtual tree for '" + versionManifest + "'");
|
||||
|
||||
AssetsIndex index = Persistence.read(getIndexPath(versionManifest), AssetsIndex.class);
|
||||
File treeDir = new File(dir, "virtual/" + indexId);
|
||||
treeDir.mkdirs();
|
||||
return new AssetsTreeBuilder(index, treeDir);
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Asset> entry : index.getObjects().entrySet()) {
|
||||
File objectPath = getObjectPath(entry.getValue());
|
||||
File virtualPath = new File(treeDir, entry.getKey());
|
||||
virtualPath.getParentFile().mkdirs();
|
||||
if (!virtualPath.exists()) {
|
||||
log.log(Level.INFO, "Copying {0} to {1}...", new Object[] {
|
||||
objectPath.getAbsolutePath(), virtualPath.getAbsolutePath()});
|
||||
Files.copy(objectPath, virtualPath);
|
||||
public class AssetsTreeBuilder implements ProgressObservable {
|
||||
private final AssetsIndex index;
|
||||
private final File destDir;
|
||||
private final int count;
|
||||
private int processed = 0;
|
||||
|
||||
public AssetsTreeBuilder(AssetsIndex index, File destDir) {
|
||||
this.index = index;
|
||||
this.destDir = destDir;
|
||||
count = index.getObjects().size();
|
||||
}
|
||||
|
||||
public File build() throws IOException, LauncherException {
|
||||
AssetsRoot.log.info("Building asset virtual tree at '" + destDir.getAbsolutePath() + "'...");
|
||||
|
||||
for (Map.Entry<String, Asset> entry : index.getObjects().entrySet()) {
|
||||
File objectPath = getObjectPath(entry.getValue());
|
||||
File virtualPath = new File(destDir, entry.getKey());
|
||||
virtualPath.getParentFile().mkdirs();
|
||||
if (!virtualPath.exists()) {
|
||||
log.log(Level.INFO, "Copying {0} to {1}...", new Object[] {
|
||||
objectPath.getAbsolutePath(), virtualPath.getAbsolutePath()});
|
||||
|
||||
if (!objectPath.exists()) {
|
||||
String message = _("assets.missingObject", objectPath.getAbsolutePath());
|
||||
throw new LauncherException("Missing object " + objectPath.getAbsolutePath(), message);
|
||||
}
|
||||
|
||||
Files.copy(objectPath, virtualPath);
|
||||
}
|
||||
processed++;
|
||||
}
|
||||
|
||||
return destDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getProgress() {
|
||||
if (count == 0) {
|
||||
return -1;
|
||||
} else {
|
||||
return processed / (double) count;
|
||||
}
|
||||
}
|
||||
|
||||
return treeDir;
|
||||
@Override
|
||||
public String getStatus() {
|
||||
if (count == 0) {
|
||||
return _("assets.expanding1", count, count - processed);
|
||||
} else {
|
||||
return _("assets.expandingN", count, count - processed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -155,7 +155,9 @@ public class HttpDownloader implements Downloader {
|
||||
|
||||
@Override
|
||||
public synchronized String getStatus() {
|
||||
if (running.size() > 0) {
|
||||
if (running.size() == 1) {
|
||||
return _("downloader.downloadingItem", running.get(0).getName()) + "\n" + running.get(0).getStatus();
|
||||
} else if (running.size() > 0) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (HttpDownloadJob job : running) {
|
||||
builder.append("\n");
|
||||
@ -171,7 +173,7 @@ public class HttpDownloader implements Downloader {
|
||||
private final File destFile;
|
||||
private final List<URL> urls;
|
||||
private final long size;
|
||||
private String name;
|
||||
@Getter private String name;
|
||||
private HttpRequest request;
|
||||
|
||||
private HttpDownloadJob(File destFile, List<URL> urls, long size, String name) {
|
||||
|
@ -101,8 +101,9 @@ public class InstanceLauncher implements Callable<Process>, ProgressObservable {
|
||||
assetsIndex = mapper.readValue(assetsRoot.getIndexPath(versionManifest), AssetsIndex.class);
|
||||
|
||||
// Copy over assets to the tree
|
||||
progress = new DefaultProgress(0.1, _("instanceLauncher.preparingAssets"));
|
||||
virtualAssetsDir = assetsRoot.buildAssetTree(versionManifest);
|
||||
AssetsRoot.AssetsTreeBuilder assetsBuilder = assetsRoot.createAssetsBuilder(versionManifest);
|
||||
progress = assetsBuilder;
|
||||
virtualAssetsDir = assetsBuilder.build();
|
||||
|
||||
progress = new DefaultProgress(0.9, _("instanceLauncher.collectingArgs"));
|
||||
|
||||
@ -306,12 +307,12 @@ public class InstanceLauncher implements Callable<Process>, ProgressObservable {
|
||||
|
||||
@Override
|
||||
public double getProgress() {
|
||||
return -1;
|
||||
return progress.getProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStatus() {
|
||||
return null;
|
||||
return progress.getStatus();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -120,7 +120,8 @@ console.hideWindow=Hide Window
|
||||
console.confirmKill=Are sure that you wish to close the game forcefully? You may lose data.
|
||||
console.confirmKillTitle=Are you sure?
|
||||
|
||||
downloader.downloadingList=Downloading {0} file(s)... ({1} remaining)
|
||||
downloader.downloadingItem=Downloading {0}...
|
||||
downloader.downloadingList=Downloading {0} files... ({1} remaining)
|
||||
downloader.jobProgress={1,number}%\t{0}
|
||||
downloader.jobPending=...\t{0}
|
||||
downloader.noDownloads=No pending downloads.
|
||||
@ -144,6 +145,10 @@ instanceResetter.resetting=Resetting {0}...
|
||||
instanceLoader.loadingLocal=Loading local instances from disk...
|
||||
instanceLoader.checkingRemote=Checking for new modpacks...
|
||||
instanceLauncher.preparing=Preparing for launch...
|
||||
instanceLauncher.preparingAssets=Preparing assets for game...
|
||||
instanceLauncher.preparingAssets=Preparing {0} assets for game...
|
||||
instanceLauncher.collectingArgs=Collecting arguments...
|
||||
instanceLauncher.startingJava=Starting java...
|
||||
instanceLauncher.startingJava=Starting java...
|
||||
|
||||
assets.expanding1=Expanding {0} asset... ({1} remaining)
|
||||
assets.expandingN=Expanding {0} assets... ({1} remaining)
|
||||
assets.missingObject=You need to force update this instance because the file at ''{0}'' is missing.
|
Loading…
Reference in New Issue
Block a user