Fixed NullPointerException when failed to check newest version
This commit is contained in:
@@ -94,9 +94,7 @@ public final class Main implements Runnable {
|
|||||||
return "HMCL" + ' ' + LAUNCHER_VERSION;
|
return "HMCL" + ' ' + LAUNCHER_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
//private static HelloMinecraftLookAndFeel LOOK_AND_FEEL;
|
public static final Logger LOGGER = Logger.getLogger(Main.class.getName());
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(Main.class.getName());
|
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.util.upgrade;
|
package org.jackhuang.hmcl.util.upgrade;
|
||||||
|
|
||||||
|
import com.google.gson.JsonSyntaxException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
@@ -24,6 +25,7 @@ import java.net.URISyntaxException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
|
import java.security.PrivilegedActionException;
|
||||||
import java.security.PrivilegedExceptionAction;
|
import java.security.PrivilegedExceptionAction;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -33,10 +35,11 @@ import java.util.Map;
|
|||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
import java.util.jar.JarOutputStream;
|
import java.util.jar.JarOutputStream;
|
||||||
import java.util.jar.Pack200;
|
import java.util.jar.Pack200;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
import org.jackhuang.hmcl.Main;
|
||||||
import org.jackhuang.hmcl.api.event.SimpleEvent;
|
import org.jackhuang.hmcl.api.event.SimpleEvent;
|
||||||
import org.jackhuang.hmcl.util.C;
|
import org.jackhuang.hmcl.util.C;
|
||||||
import org.jackhuang.hmcl.api.HMCLog;
|
|
||||||
import org.jackhuang.hmcl.core.MCUtils;
|
import org.jackhuang.hmcl.core.MCUtils;
|
||||||
import org.jackhuang.hmcl.util.task.Task;
|
import org.jackhuang.hmcl.util.task.Task;
|
||||||
import org.jackhuang.hmcl.util.task.TaskWindow;
|
import org.jackhuang.hmcl.util.task.TaskWindow;
|
||||||
@@ -57,7 +60,7 @@ import org.jackhuang.hmcl.util.sys.OS;
|
|||||||
*/
|
*/
|
||||||
public class AppDataUpgrader extends IUpgrader {
|
public class AppDataUpgrader extends IUpgrader {
|
||||||
|
|
||||||
private boolean launchNewerVersion(String[] args, File jar) throws Exception {
|
private boolean launchNewerVersion(String[] args, File jar) throws IOException, PrivilegedActionException {
|
||||||
try (JarFile jarFile = new JarFile(jar)) {
|
try (JarFile jarFile = new JarFile(jar)) {
|
||||||
String mainClass = jarFile.getManifest().getMainAttributes().getValue("Main-Class");
|
String mainClass = jarFile.getManifest().getMainAttributes().getValue("Main-Class");
|
||||||
if (mainClass != null) {
|
if (mainClass != null) {
|
||||||
@@ -77,9 +80,9 @@ public class AppDataUpgrader extends IUpgrader {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void parseArguments(VersionNumber nowVersion, String[] args) {
|
public void parseArguments(VersionNumber nowVersion, String[] args) {
|
||||||
|
File f = AppDataUpgraderPackGzTask.HMCL_VER_FILE;
|
||||||
if (!ArrayUtils.contains(args, "--noupdate"))
|
if (!ArrayUtils.contains(args, "--noupdate"))
|
||||||
try {
|
try {
|
||||||
File f = AppDataUpgraderPackGzTask.HMCL_VER_FILE;
|
|
||||||
if (f.exists()) {
|
if (f.exists()) {
|
||||||
Map<String, String> m = C.GSON.fromJson(FileUtils.read(f), Map.class);
|
Map<String, String> m = C.GSON.fromJson(FileUtils.read(f), Map.class);
|
||||||
String s = m.get("ver");
|
String s = m.get("ver");
|
||||||
@@ -92,8 +95,10 @@ public class AppDataUpgrader extends IUpgrader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (JsonSyntaxException ex) {
|
||||||
HMCLog.err("Failed to execute newer version application", t);
|
f.delete();
|
||||||
|
} catch (IOException | PrivilegedActionException t) {
|
||||||
|
Main.LOGGER.log(Level.SEVERE, "Failed to execute newer version application", t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +119,7 @@ public class AppDataUpgrader extends IUpgrader {
|
|||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
HMCLog.err("Failed to create upgrader", ex);
|
Main.LOGGER.log(Level.SEVERE, "Failed to create upgrader", ex);
|
||||||
}
|
}
|
||||||
else if (map != null && map.containsKey("pack") && !StrUtils.isBlank(map.get("pack")))
|
else if (map != null && map.containsKey("pack") && !StrUtils.isBlank(map.get("pack")))
|
||||||
try {
|
try {
|
||||||
@@ -126,7 +131,7 @@ public class AppDataUpgrader extends IUpgrader {
|
|||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
HMCLog.err("Failed to create upgrader", ex);
|
Main.LOGGER.log(Level.SEVERE, "Failed to create upgrader", ex);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String url = C.URL_PUBLISH;
|
String url = C.URL_PUBLISH;
|
||||||
@@ -140,7 +145,7 @@ public class AppDataUpgrader extends IUpgrader {
|
|||||||
try {
|
try {
|
||||||
java.awt.Desktop.getDesktop().browse(new URI(url));
|
java.awt.Desktop.getDesktop().browse(new URI(url));
|
||||||
} catch (URISyntaxException | IOException e) {
|
} catch (URISyntaxException | IOException e) {
|
||||||
HMCLog.warn("Failed to browse uri: " + url, e);
|
Main.LOGGER.log(Level.WARNING, "Failed to browse uri: " + url, e);
|
||||||
Utils.setClipborad(url);
|
Utils.setClipborad(url);
|
||||||
MessageBox.show(C.i18n("update.no_browser"));
|
MessageBox.show(C.i18n("update.no_browser"));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user