fix IllegalStateException crashes the application

This commit is contained in:
huangyuhui
2016-01-09 13:24:40 +08:00
parent 296df23e15
commit 6c8c189b72
10 changed files with 453 additions and 27 deletions

View File

@@ -0,0 +1,30 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.launch;
/**
*
* @author huangyuhui
*/
public class GameException extends RuntimeException {
public GameException(String message) {
super(message);
}
}

View File

@@ -85,13 +85,8 @@ public class GameLauncher {
try {
loader = provider.provideMinecraftLoader(result);
} catch (IllegalStateException e) {
HMCLog.err("Failed to get minecraft loader", e);
failEvent.execute(C.i18n("launch.circular_dependency_versions"));
return null;
} catch (Exception e) {
failEvent.execute(C.i18n("launch.failed"));
HMCLog.err("Failed to get minecraft loader", e);
} catch (GameException e) {
failEvent.execute(C.i18n("launch.failed") + ", " + e.getMessage());
return null;
}
@@ -106,7 +101,14 @@ public class GameLauncher {
}
HMCLog.log("Unpacking natives...");
if (!decompressNativesEvent.execute(provider.getDecompressLibraries(loader.getMinecraftVersion()))) {
DecompressLibraryJob job = null;
try {
job = provider.getDecompressLibraries(loader.getMinecraftVersion());
} catch (GameException e) {
failEvent.execute(C.i18n("launch.failed") + ", " + e.getMessage());
return null;
}
if (!decompressNativesEvent.execute(job)) {
failEvent.execute(C.i18n("launch.failed"));
return null;
}

View File

@@ -48,7 +48,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
DownloadType dt;
String text;
public MinecraftLoader(Profile ver, IMinecraftProvider provider, UserProfileProvider lr) throws IllegalStateException {
public MinecraftLoader(Profile ver, IMinecraftProvider provider, UserProfileProvider lr) throws GameException {
super(ver, provider, lr);
}

View File

@@ -29,7 +29,7 @@ import org.jackhuang.hellominecraft.utils.code.DigestUtils;
*/
public final class OfflineAuthenticator extends IAuthenticator {
Map<String, String> uuidMap = null;
Map<String, String> uuidMap = new HashMap<>();
public OfflineAuthenticator(String clientToken) {
super(clientToken);
@@ -38,11 +38,11 @@ public final class OfflineAuthenticator extends IAuthenticator {
@Override
public void onLoadSettings(Map m) {
super.onLoadSettings(m);
if (m == null)
return;
Object o = m.get("uuidMap");
if (o != null && o instanceof Map)
uuidMap = (Map) o;
else
uuidMap = new HashMap<>();
uuidMap = (Map<String, String>) o;
}
@Override

View File

@@ -22,6 +22,8 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.launcher.launch.GameException;
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
import org.jackhuang.hellominecraft.launcher.utils.assets.AssetsIndex;
import org.jackhuang.hellominecraft.utils.ArrayUtils;
@@ -78,7 +80,7 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
if (inheritsFrom == null)
return this;
if (!resolvedSoFar.add(id))
throw new IllegalStateException("Circular dependency detected.");
throw new GameException(C.i18n("launch.circular_dependency_versions"));
MinecraftVersion parent = manager.getVersionById(inheritsFrom);
if (parent == null) {

View File

@@ -26,6 +26,7 @@ import java.util.Map;
import java.util.TreeMap;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.launch.GameException;
import org.jackhuang.hellominecraft.launcher.launch.GameLauncher;
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftAssetService;
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftDownloadService;
@@ -211,7 +212,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
@Override
public GameLauncher.DecompressLibraryJob getDecompressLibraries(MinecraftVersion v) {
if (v.libraries == null)
throw new IllegalStateException("Wrong format: minecraft.json");
throw new GameException("Wrong format: minecraft.json");
ArrayList<File> unzippings = new ArrayList<>();
ArrayList<String[]> extractRules = new ArrayList<>();
for (IMinecraftLibrary l : v.libraries) {
@@ -236,7 +237,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
@Override
public IMinecraftLoader provideMinecraftLoader(UserProfileProvider p)
throws IllegalStateException {
throws GameException {
return new MinecraftLoader(profile, this, p);
}

View File

@@ -896,11 +896,8 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
private void btnRemoveProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveProfileActionPerformed
if (MessageBox.Show(C.i18n("ui.message.sure_remove", getProfile().getName()), MessageBox.YES_NO_OPTION) == MessageBox.NO_OPTION)
return;
String name = getProfile().getName();
if (Settings.delProfile(getProfile())) {
cboProfiles.removeItem(name);
prepare(getProfile());
}
if (Settings.delProfile(getProfile()))
loadProfiles();
}//GEN-LAST:event_btnRemoveProfileActionPerformed
private void cboVersionsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboVersionsItemStateChanged
@@ -1197,8 +1194,6 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
}
//</editor-fold>
// <editor-fold defaultstate="collapsed" desc="Game Download">
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Installer">
String getMinecraftVersionFormatted() {
return minecraftVersion == null ? "" : (StrUtils.formatVersion(minecraftVersion.version) == null) ? mcVersion : minecraftVersion.version;