Add JarUtil/SelfUpdater error handling
This commit is contained in:
@@ -19,6 +19,10 @@
|
||||
|
||||
package com.seibel.distanthorizons.core.jar;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
@@ -34,12 +38,21 @@ import java.util.Objects;
|
||||
*/
|
||||
public class JarUtils
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
@Nullable
|
||||
public static File jarFile = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
static
|
||||
{
|
||||
try
|
||||
{
|
||||
jarFile = new File(JarUtils.class.getProtectionDomain().getCodeSource().getLocation().toURI()); // Always safe
|
||||
} catch (Exception e) { e.printStackTrace(); }
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.warn("Unable to get jarFile, Error: "+e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -104,7 +104,9 @@ public class SelfUpdater
|
||||
// Some init stuff
|
||||
// We use sha1 to check the version as our versioning system is different to the one on modrinth
|
||||
if (!ModrinthGetter.init())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!ModrinthGetter.mcVersions.contains(mcVersion))
|
||||
{
|
||||
LOGGER.warn("Minecraft version ["+ mcVersion +"] is not findable on Modrinth, only findable versions are ["+ ModrinthGetter.mcVersions.toString() +"]");
|
||||
@@ -113,7 +115,14 @@ public class SelfUpdater
|
||||
|
||||
// Check the sha's of both our stuff
|
||||
if (currentJarSha.equals(ModrinthGetter.getLatestShaForVersion(mcVersion)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (JarUtils.jarFile == null)
|
||||
{
|
||||
LOGGER.warn("Unable to get the DH jar file, self updating disabled.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
LOGGER.info("New version (" + ModrinthGetter.getLatestNameForVersion(mcVersion) + ") of " + ModInfo.READABLE_NAME + " is available");
|
||||
@@ -300,6 +309,10 @@ public class SelfUpdater
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (JarUtils.jarFile == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user