diff --git a/src/main/java/com/seibel/lod/core/JarMain.java b/src/main/java/com/seibel/lod/core/JarMain.java index 9d83ce21d..0f409deb4 100644 --- a/src/main/java/com/seibel/lod/core/JarMain.java +++ b/src/main/java/com/seibel/lod/core/JarMain.java @@ -6,10 +6,9 @@ import com.seibel.lod.core.jar.DarkModeDetector; import com.seibel.lod.core.jar.JarUtils; import com.seibel.lod.core.jar.gui.BaseJFrame; import com.seibel.lod.core.jar.gui.cusomJObject.JBox; -import com.seibel.lod.core.jar.installer.GitlabGetter; -import com.seibel.lod.core.jar.JarDependencySetup; import com.seibel.lod.core.jar.installer.ModrinthGetter; import com.seibel.lod.core.jar.installer.WebDownloader; +import com.seibel.lod.core.jar.JarDependencySetup; import javax.swing.*; import java.awt.*; @@ -23,7 +22,7 @@ import java.util.concurrent.atomic.AtomicReference; * * @author coolGi */ -// Once built it would be in core/build/libs/DistantHorizons-1.7.0a-dev-all.jar +// Once built it would be in core/build/libs/DistantHorizons--dev-all.jar public class JarMain { public static final boolean isDarkTheme = DarkModeDetector.isDarkMode(); public static boolean isOffline = WebDownloader.netIsAvailable(); @@ -48,9 +47,13 @@ public class JarMain { // JOptionPane.showMessageDialog(null, "The GUI for the standalone jar isn't made yet\nIf you want to use the mod then put it in your mods folder", "Distant Horizons", JOptionPane.WARNING_MESSAGE); - if (getOperatingSystem().equals(OperatingSystem.MACOS)) { - System.out.println("If you want the installer then please use Linux or for the time being.\nMacOS support/testing will come later on"); - } +// if (getOperatingSystem().equals(OperatingSystem.MACOS)) { +// System.out.println("If you want the installer then please use Linux or Windows for the time being.\nMacOS support/testing will come later on"); +// } + + // Code will be changed later on to allow resizing and work better + + BaseJFrame frame = new BaseJFrame(false, true); frame.addExtraButtons(frame.getWidth(), 0, true, false); diff --git a/src/main/java/com/seibel/lod/core/config/Config.java b/src/main/java/com/seibel/lod/core/config/Config.java index 7544e812c..d02850c79 100644 --- a/src/main/java/com/seibel/lod/core/config/Config.java +++ b/src/main/java/com/seibel/lod/core/config/Config.java @@ -68,6 +68,8 @@ public class Config public static ConfigCategory advanced = new ConfigCategory.Builder().set(Advanced.class).build(); + public static ConfigCategory autoUpdater = new ConfigCategory.Builder().set(AutoUpdater.class).build(); + public static ConfigEntry optionsButton = new ConfigEntry.Builder() .set(true) .comment("Show the lod button in the options screen next to fov") @@ -874,5 +876,21 @@ public class Config .build(); } } + + + public static class AutoUpdater + { + public static ConfigEntry enableAutoUpdater = new ConfigEntry.Builder() + .set(true) + .comment("Automatically checks for updates on game launch") + .build(); + + public static ConfigEntry promptForUpdate = new ConfigEntry.Builder() + .set(true) + .comment("When there is a new update available it would prompt the user whether they would like to update \n" + + "If set to false then it would update the mod in the background without informing/annoying the user \n" + + "So it is recommended to keep it off unless you are always sure you want the mod to be on the latest version") + .build(); + } } } diff --git a/src/main/java/com/seibel/lod/core/jar/JarUtils.java b/src/main/java/com/seibel/lod/core/jar/JarUtils.java index 17dd6e179..60cfda204 100644 --- a/src/main/java/com/seibel/lod/core/jar/JarUtils.java +++ b/src/main/java/com/seibel/lod/core/jar/JarUtils.java @@ -2,6 +2,7 @@ package com.seibel.lod.core.jar; import java.io.*; import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; public class JarUtils { public static final File jarFile = new File(JarUtils.class.getProtectionDomain().getCodeSource().getLocation().getPath()); @@ -42,4 +43,46 @@ public class JarUtils { return result.toString(); } + + /** + * Checks the checksum of a file given an algorithm + * + * @param digest What algorithem to use
+ * Eg.
+ * MessageDigest.getInstance("MD5")
+ * MessageDigest.getInstance("SHA-256")
+ * @param file Location of the file + * @return Checksum + */ + // Stolen from https://howtodoinjava.com/java/java-security/sha-md5-file-checksum-hash/ + public static String getFileChecksum(MessageDigest digest, File file) throws IOException { + //Get file input stream for reading the file content + FileInputStream fis = new FileInputStream(file); + + //Create byte array to read data in chunks + byte[] byteArray = new byte[1024]; + int bytesCount = 0; + + //Read file data and update in message digest + while ((bytesCount = fis.read(byteArray)) != -1) { + digest.update(byteArray, 0, bytesCount); + }; + + //close the stream; We don't need it now. + fis.close(); + + //Get the hash's bytes + byte[] bytes = digest.digest(); + + //This bytes[] has bytes in decimal format; + //Convert it to hexadecimal format + StringBuilder sb = new StringBuilder(); + for(int i=0; i< bytes.length ;i++) + { + sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1)); + } + + //return complete hash + return sb.toString(); + } } diff --git a/src/main/java/com/seibel/lod/core/jar/installer/ModrinthGetter.java b/src/main/java/com/seibel/lod/core/jar/installer/ModrinthGetter.java index 2c1652f73..575c25b3f 100644 --- a/src/main/java/com/seibel/lod/core/jar/installer/ModrinthGetter.java +++ b/src/main/java/com/seibel/lod/core/jar/installer/ModrinthGetter.java @@ -69,25 +69,21 @@ public class ModrinthGetter { } } - public static List getReleaseIDInMcVersion(String mcVersion) { - List releaseID = new ArrayList<>(); - - for (int i = 0; i < projectRelease.size(); i++) { - JSONObject currentRelease = (JSONObject) projectRelease.get(i); - if (((List) currentRelease.get("game_versions")).contains(mcVersion)) - releaseID.add(currentRelease.get("id").toString()); - } - - return releaseID; + public static String getLatestNameForVersion(String mcVer) { + return releaseNames.get(((List) mcVerToReleaseID.get(mcVer)).get(0)); } - public static URL getDownloadFromReleaseID(String ID) { - for (int i = 0; i < projectRelease.size(); i++) { - JSONObject currentRelease = (JSONObject) projectRelease.get(i); - if (currentRelease.get("id").toString().equals(ID)) - try { - return new URL(((JSONObject) ((JSONArray) currentRelease.get("files")).get(0)).get("url").toString()); - } catch (Exception e) { e.printStackTrace(); } - } - return null; + public static URL getLatestDownloadForVersion(String mcVer) { + return downloadUrl.get(((List) mcVerToReleaseID.get(mcVer)).get(0)); + } + public static String getLatestShaForVersion(String mcVer) { + return ((JSONObject) + ((JSONObject) + ((JSONArray) + ((JSONObject) projectRelease.get(mcVersions.indexOf(mcVer))) + .get("files")) + .get(0)) + .get("hashes")) + .get("sha1") + .toString(); } } diff --git a/src/main/java/com/seibel/lod/core/wrapperInterfaces/IVersionConstants.java b/src/main/java/com/seibel/lod/core/wrapperInterfaces/IVersionConstants.java index ffd94537e..79be1ae80 100644 --- a/src/main/java/com/seibel/lod/core/wrapperInterfaces/IVersionConstants.java +++ b/src/main/java/com/seibel/lod/core/wrapperInterfaces/IVersionConstants.java @@ -41,4 +41,5 @@ public interface IVersionConstants extends IBindable boolean isVanillaRenderedChunkSquare(); + String getMinecraftVersion(); } diff --git a/src/main/resources/assets/lod/lang/en_us.json b/src/main/resources/assets/lod/lang/en_us.json index f0bdc9b23..363a459e6 100644 --- a/src/main/resources/assets/lod/lang/en_us.json +++ b/src/main/resources/assets/lod/lang/en_us.json @@ -283,6 +283,17 @@ "lod.config.client.advanced.lodOnlyMode.@tooltip": "Due to some demand for playing without vanilla terrains, \nwe decided to add this mode for fun. \n\n§6NOTE§r: Do not report any issues when this mode is on! \n Again, this setting is only for fun, and mod \n compatibility is not guaranteed. \n", + "lod.config.client.autoUpdater": + "Auto Updater", + "lod.config.client.autoUpdater.enableAutoUpdater": + "Enable auto updater", + "lod.config.client.autoUpdater.enableAutoUpdater.@tooltip": + "Automatically updates the mod when an update is available", + "lod.config.client.autoUpdater.promptForUpdate": + "Prompt for update", + "lod.config.client.autoUpdater.promptForUpdate.@tooltip": + "If disabled then when an update is available then it would update without prompting the user", + "lod.config.enum.EHorizontalResolution.BLOCK": "Block", "lod.config.enum.EHorizontalResolution.TWO_BLOCKS":