1
0
mirror of https://github.com/SKCraft/Launcher.git synced 2024-11-24 12:16:28 +01:00

Catch instance removal failures.

This commit is contained in:
sk89q 2014-01-09 09:53:19 -08:00
parent 41d412d3b5
commit 2f7410eca4
5 changed files with 59 additions and 16 deletions

View File

@ -7,13 +7,16 @@
package com.skcraft.launcher;
import com.google.common.io.Closer;
import lombok.extern.java.Log;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Properties;
import java.util.regex.Pattern;
@Log
public final class LauncherUtils {
private static final Pattern absoluteUrlPattern = Pattern.compile("^[A-Za-z0-9\\-]+://.*$");
@ -70,7 +73,7 @@ public final class LauncherUtils {
public static void interruptibleDelete(File file) throws IOException, InterruptedException {
public static void interruptibleDelete(File file, List<File> failures) throws IOException, InterruptedException {
checkInterrupted();
if (file.isDirectory()) {
@ -81,16 +84,22 @@ public final class LauncherUtils {
}
for (File f : files) {
interruptibleDelete(f);
interruptibleDelete(f, failures);
}
file.delete();
if (!file.delete()) {
log.warning("Failed to delete " + file.getAbsolutePath());
failures.add(file);
}
} else {
if (!file.exists()) {
throw new FileNotFoundException("Does not exist: " + file);
}
file.delete();
if (!file.delete()) {
log.warning("Failed to delete " + file.getAbsolutePath());
failures.add(file);
}
}
}

View File

@ -14,6 +14,7 @@ import lombok.NonNull;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.concurrent.Callable;
import static com.skcraft.launcher.util.SharedLocale._;
@ -55,7 +56,7 @@ public class HardResetter implements Callable<Instance>, ProgressObservable {
try {
if (dir.isDirectory()) {
currentDir = dir;
LauncherUtils.interruptibleDelete(dir);
LauncherUtils.interruptibleDelete(dir, new ArrayList<File>());
}
} finally {
currentDir = null;

View File

@ -8,11 +8,15 @@ package com.skcraft.launcher.update;
import com.skcraft.concurrency.ProgressObservable;
import com.skcraft.launcher.Instance;
import com.skcraft.launcher.LauncherException;
import com.skcraft.launcher.LauncherUtils;
import com.skcraft.launcher.persistence.Persistence;
import lombok.NonNull;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import static com.skcraft.launcher.LauncherUtils.checkInterrupted;
@ -46,11 +50,18 @@ public class Remover implements Callable<Instance>, ProgressObservable {
Thread.sleep(2000);
List<File> failures = new ArrayList<File>();
try {
LauncherUtils.interruptibleDelete(instance.getDir());
LauncherUtils.interruptibleDelete(instance.getDir(), failures);
} catch (IOException e) {
Thread.sleep(1000);
LauncherUtils.interruptibleDelete(instance.getDir());
LauncherUtils.interruptibleDelete(instance.getDir(), failures);
}
if (failures.size() > 0) {
throw new LauncherException(failures.size() + " failed to delete",
_("instanceDeleter.failures", failures.size()));
}
return instance;

View File

@ -132,37 +132,54 @@ public class Updater extends BaseUpdater implements Callable<Instance>, Progress
instance.setLocal(true);
Persistence.commitAndForget(instance);
// Install package and get the manifests
// Read manifest
log.info("Reading package manifest...");
progress = new DefaultProgress(-1, _("instanceUpdater.readingManifest"));
Manifest manifest = installPackage(installer, instance);
// Read version manifest
log.info("Reading version manifest...");
progress = new DefaultProgress(-1, _("instanceUpdater.readingVersion"));
VersionManifest version = readVersionManifest(manifest);
URL url = manifest.getLibrariesUrl();
if (url != null) {
librarySources.add(url);
}
progress = new DefaultProgress(-1, _("instanceUpdater.buildingDownloadList"));
// Install the .jar
File jarPath = launcher.getJarPath(version);
URL jarSource = launcher.propUrl("jarUrl", version.getId());
log.info("JAR at " + jarPath.getAbsolutePath() + ", fetched from " + jarSource);
installJar(installer, jarPath, jarSource);
// Download libraries and assets
// Download libraries
log.info("Enumerating libraries to download...");
URL url = manifest.getLibrariesUrl();
if (url != null) {
log.info("Added library source: " + url);
librarySources.add(url);
}
progress = new DefaultProgress(-1, _("instanceUpdater.collectingLibraries"));
installLibraries(installer, version, launcher.getLibrariesDir(), librarySources);
// Download assets
log.info("Enumerating assets to download...");
progress = new DefaultProgress(-1, _("instanceUpdater.collectingAssets"));
installAssets(installer, version, launcher.propUrl("assetsIndexUrl", version.getAssetsIndex()), assetsSources);
progress = ProgressFilter.between(installer.getDownloader(), 0, 0.9);
log.info("Executing download phase...");
progress = ProgressFilter.between(installer.getDownloader(), 0, 0.98);
installer.download();
progress = ProgressFilter.between(installer, 0.9, 1);
log.info("Executing install phase...");
progress = ProgressFilter.between(installer, 0.98, 1);
installer.execute();
log.info("Completing...");
complete();
// Update the instance's information
log.info("Writing instance information...");
instance.setVersion(manifest.getVersion());
instance.setUpdatePending(false);
instance.setInstalled(true);

View File

@ -150,7 +150,12 @@ instanceUpdater.preparingUpdate=Preparing to update...
instanceUpdater.readingManifest=Reading package manifest...
instanceUpdater.readingVersion=Reading version manifest...
instanceUpdater.buildingDownloadList=Collecting files to download...
instanceUpdater.collectingLibraries=Collecting libraries to download...
instanceUpdater.collectingAssets=Collecting assets to download...
instanceDeleter.deleting=Deleting {0}...
instanceDeleter.failures={0} file(s) could not be deleted.
instanceResetter.resetting=Resetting {0}...
instanceLoader.loadingLocal=Loading local instances from disk...
instanceLoader.checkingRemote=Checking for new modpacks...