Skip to content

Commit

Permalink
Pushed 2.2 release
Browse files Browse the repository at this point in the history
- Added a small loading text on the button when selecting optional resources (untested)
- Added the translation for the previous text.
- Fixed the update checker detecting the same update as new (In reality, i just forgot to change the version number previously)
- Made IOExceptions now try again their task once after 1 second instead of directly failing. This should fix, or at least negate, the dumb things that the Curseforge launcher does that caused the mod to fail.
- Updated the Zip4J library to 2.11.1

- Reorganized certain functions
- Rewrote some function comments to be javadocs instead.
- Cleaned up the code base a little
- Bumped the version number to 2.2
  • Loading branch information
HRudyPlayZ committed Aug 5, 2022
1 parent 3eab937 commit cf7155a
Show file tree
Hide file tree
Showing 53 changed files with 1,036 additions and 441 deletions.
24 changes: 12 additions & 12 deletions src/main/java/com/hrudyplayz/mcinstanceloader/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static void secondPhase() {
// ===== STEP 4: Zip the pack folder =====
if (!Config.disableAutomaticZipCreation && !FileHelper.exists(Config.configFolder + "pack.mcinstance") && !FileHelper.exists(Config.configFolder + "pack.mcinstance.disabled")) {
LogHelper.info("No pack.instance file found, created one from the pack folder.");
ZipHelper.zip(Config.configFolder + "pack", Config.configFolder + "pack.mcinstance");
ZipHelper.zip(Config.configFolder + "pack", Config.configFolder + "pack.mcinstance", false, true);
}

// ===== STEP 5: Resources download =====
Expand Down Expand Up @@ -432,11 +432,11 @@ public static void downloadResources() {
if (object.downloadFile()) {
if (!object.checkHash()) throwError("Could not verify the hash of " + object.name + ".");
else if (!object.checkCache() && !Config.disableCache) {
if (object.SHA512 != null) FileHelper.copy(object.destination, "mcinstance-cache" + File.separator + "SHA512-" + object.SHA512, true);
else if (object.SHA256 != null) FileHelper.copy(object.destination, "mcinstance-cache" + File.separator + "SHA256-" + object.SHA256, true);
else if (object.SHA1 != null) FileHelper.copy(object.destination, "mcinstance-cache" + File.separator + "SHA1-" + object.SHA1, true);
else if (object.MD5 != null) FileHelper.copy(object.destination, "mcinstance-cache" + File.separator + "MD5-" + object.MD5, true);
else if (object.CRC32 != null) FileHelper.copy(object.destination, "mcinstance-cache" + File.separator + "CRC32-" + object.CRC32, true);
if (object.SHA512 != null) FileHelper.copy(object.destination, "mcinstance-cache" + File.separator + "SHA512-" + object.SHA512);
else if (object.SHA256 != null) FileHelper.copy(object.destination, "mcinstance-cache" + File.separator + "SHA256-" + object.SHA256);
else if (object.SHA1 != null) FileHelper.copy(object.destination, "mcinstance-cache" + File.separator + "SHA1-" + object.SHA1);
else if (object.MD5 != null) FileHelper.copy(object.destination, "mcinstance-cache" + File.separator + "MD5-" + object.MD5);
else if (object.CRC32 != null) FileHelper.copy(object.destination, "mcinstance-cache" + File.separator + "CRC32-" + object.CRC32);
}
}
else throwError("Error while downloading " + object.name + ".");
Expand Down Expand Up @@ -473,7 +473,7 @@ public static void copyOverrides() {
LogHelper.verboseInfo("Merging " + s + " with the original folder.");

// Tries to move (merge) the file, if it fails it throws an error.
if (!FileHelper.copy(Config.configFolder + "temp" + File.separator + "overrides" + File.separator + s, s, false)) throwError("Error while merging the file " + s + " from the overrides folder.");
if (!FileHelper.copy(Config.configFolder + "temp" + File.separator + "overrides" + File.separator + s, s)) throwError("Error while merging the file " + s + " from the overrides folder.");

errorContext = ""; // Resets the errorContext, so it can be reused for the next resource or the next step.
}
Expand Down Expand Up @@ -505,7 +505,7 @@ public static void copyCarryover() {
LogHelper.verboseInfo("Merging " + s + " from carryover to the root folder.");

// Tries to copy (merge) the file, if it fails it throws an error.
if (!FileHelper.copy("carryover" + File.separator + s, s, false)) throwError("Error while merging the file " + s + " from the carryover folder.");
if (!FileHelper.copy("carryover" + File.separator + s, s)) throwError("Error while merging the file " + s + " from the carryover folder.");

errorContext = ""; // Resets the errorContext, so it can be reused for the next resource or the next step.
}
Expand All @@ -530,7 +530,7 @@ public static void finalSetup() {
path = Config.configFolder + "pack.mcinstance";
if (!Config.skipFileDisabling && FileHelper.exists(path)) { // If the config to skip the file disabling wasn't set, it will disable or remove it.
if (Config.deleteInsteadOfRenaming) FileHelper.delete(path);
else FileHelper.move(path, path + ".disabled", true);
else FileHelper.move(path, path + ".disabled");
}
}

Expand All @@ -540,7 +540,7 @@ public static void finalSetup() {
}


public static void throwError (String text) {
public static void throwError(String text) {
// Sets the final results screen to be an error screen. Adds an error any time it gets called.
// If the amount of errors displayed is above the maximum limit, it adds to the more counter instead.

Expand Down Expand Up @@ -570,7 +570,7 @@ public static void throwError (String text) {
}
}

public static void throwSuccess (String text) {
public static void throwSuccess(String text) {
// Sets the final results screen to be the success screen, and adds the success message in it.

if (side.equals("server")) {
Expand All @@ -591,7 +591,7 @@ public static void throwSuccess (String text) {
}


public static void throwUpdateScreen () {
public static void throwUpdateScreen() {
// Sets the final results screen to be the mod update screen.

if (side.equals("server")) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ModProperties {
// General values
public static final String MODID = "mcinstanceloader";
public static final String NAME = "MCInstance Loader";
public static final String VERSION = "2.1";
public static final String VERSION = "2.2";
public static final String MC_VERSION = "1.7.10";
public static final String URL = "https://github.com/HRudyPlayZ/MCInstanceLoader/";

Expand Down Expand Up @@ -48,7 +48,7 @@ public class ModProperties {
"Also try ResourcceLoader",
"Finally updated!",
"Check the documentation on Github.",
"2.0.0.0.0, also known as 2.0: The overhaul!",
"2.2, finally bug-free (i hope).",
"Since you're here, you might want to support the mod on Github and Modrinth!",
"The most memes you can get, in one package.",
"Every modpack needs this!",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public void drawScreen(int x, int y, float renderPartialTicks) {
}


public GuiButton createButton (int id, int x, int y, int width, String text) {
public GuiButton createButton(int id, int x, int y, int width, String text) {
// Helper function to create buttons more easily, and return them to modify them afterwards.

GuiButton result = new GuiButton(id, x, y, width, 20, text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class OptionalModsGui extends GuiScreen {

public static boolean runOnceDone = false; // Only runs the runOnce function once.
public static boolean cantClick = false; // Prevents double clicking on buttons.
public static boolean waitingText = false; // Whether the confirm button text should show the waiting text instead.

public GuiScreen parentGuiScreen;

Expand Down Expand Up @@ -143,6 +144,7 @@ private void refreshGui() {
if (pageList.size() == 0) {
currentMenu += 1;
currentPage = 0;
waitingText = false;
updateChecked();
refreshGui();
return;
Expand Down Expand Up @@ -202,7 +204,10 @@ private void refreshGui() {
// Adds the "Confirm and continue" button, with the appropriate color.
String color = "";
if (!(checkedOptions.size() >= optionalList[currentMenu].minimumCheckedAmount)) color = "" + EnumChatFormatting.GRAY;
createButton(14, nextButtonX, buttonHeight, buttonWidth, color + I18n.format("gui.mcinstanceloader.confirm"));

String text = I18n.format("gui.mcinstanceloader.confirm");
if (waitingText) text = I18n.format("gui.mcinstanceloader.waitbutton");
createButton(14, nextButtonX, buttonHeight, buttonWidth, color + text);
}

@Override
Expand Down Expand Up @@ -286,10 +291,14 @@ protected void actionPerformed(GuiButton button) {
}

if (button.id == 14 && checkedOptions.size() >= optionalList[currentMenu].minimumCheckedAmount) {
waitingText = true;
refreshGui();

for (OptionalResourcesHandler.MenuOption o : checkedOptions) o.download();

currentMenu += 1;
currentPage = 0;
waitingText = false;
updateChecked();
refreshGui();
}
Expand Down Expand Up @@ -335,7 +344,7 @@ public void drawScreen(int x, int y, float renderPartialTicks) {
}


public GuiButton createButton (int id, int x, int y, int width, String text) {
public GuiButton createButton(int id, int x, int y, int width, String text) {
// Helper function to create buttons more easily, and return them to modify them afterwards.

GuiButton result = new GuiButton(id, x, y, width, 20, text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ public void download() {
if (object.downloadFile()) {
if (!object.checkHash()) Main.throwError("Could not verify the hash of " + object.name + ".");
else if (!object.checkCache() && !Config.disableCache) {
if (object.SHA512 != null) FileHelper.copy(object.destination, "mcinstance-cache" + File.separator + "SHA512-" + object.SHA512, true);
else if (object.SHA256 != null) FileHelper.copy(object.destination, "mcinstance-cache" + File.separator + "SHA256-" + object.SHA256, true);
else if (object.SHA1 != null) FileHelper.copy(object.destination, "mcinstance-cache" + File.separator + "SHA1-" + object.SHA1, true);
else if (object.MD5 != null) FileHelper.copy(object.destination, "mcinstance-cache" + File.separator + "MD5-" + object.MD5, true);
else if (object.CRC32 != null) FileHelper.copy(object.destination, "mcinstance-cache" + File.separator + "CRC32-" + object.CRC32, true);
if (object.SHA512 != null) FileHelper.copy(object.destination, "mcinstance-cache" + File.separator + "SHA512-" + object.SHA512);
else if (object.SHA256 != null) FileHelper.copy(object.destination, "mcinstance-cache" + File.separator + "SHA256-" + object.SHA256);
else if (object.SHA1 != null) FileHelper.copy(object.destination, "mcinstance-cache" + File.separator + "SHA1-" + object.SHA1);
else if (object.MD5 != null) FileHelper.copy(object.destination, "mcinstance-cache" + File.separator + "MD5-" + object.MD5);
else if (object.CRC32 != null) FileHelper.copy(object.destination, "mcinstance-cache" + File.separator + "CRC32-" + object.CRC32);
}
}
else Main.throwError("Error while downloading " + object.name + ".");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.hrudyplayz.mcinstanceloader.resources;

import net.minecraft.client.Minecraft;
import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.concurrent.TimeUnit;

import com.google.common.hash.HashCode;
import com.google.common.hash.Hashing;
Expand Down Expand Up @@ -35,6 +37,8 @@ public class ResourceObject {
public String destination = "";
public String side = "both";

private boolean hasTriedHashChecks;

public String SHA512;
public String SHA256;
public String SHA1;
Expand Down Expand Up @@ -80,8 +84,22 @@ public boolean checkHash() {
}

catch (IOException e) {
Main.errorContext = "Error while checking the SHA-512 hash.";
return false;
if (!this.hasTriedHashChecks) {
this.hasTriedHashChecks = true;
LogHelper.info("An error occured while checking the SHA-512 hash, trying again...");
try {
TimeUnit.MILLISECONDS.sleep(1000);
}
catch (InterruptedException ignore) {}

return this.checkHash();
}
else {
e.printStackTrace();
Main.errorContext = "System error while checking the SHA-512 hash.";

return false;
}
}
}

Expand All @@ -96,8 +114,22 @@ public boolean checkHash() {
}

catch (IOException e) {
Main.errorContext = "Error while checking the SHA-256 hash.";
return false;
if (!this.hasTriedHashChecks) {
this.hasTriedHashChecks = true;
LogHelper.info("An error occured while checking the SHA-256 hash, trying again...");
try {
TimeUnit.MILLISECONDS.sleep(1000);
}
catch (InterruptedException ignore) {}

return this.checkHash();
}
else {
e.printStackTrace();
Main.errorContext = "System error while checking the SHA-256 hash.";

return false;
}
}
}

Expand All @@ -112,8 +144,22 @@ public boolean checkHash() {
}

catch (IOException e) {
Main.errorContext = "Error while checking the SHA1 hash.";
return false;
if (!this.hasTriedHashChecks) {
this.hasTriedHashChecks = true;
LogHelper.info("An error occured while checking the SHA1 hash, trying again...");
try {
TimeUnit.MILLISECONDS.sleep(1000);
}
catch (InterruptedException ignore) {}

return this.checkHash();
}
else {
e.printStackTrace();
Main.errorContext = "System error while checking the SHA1 hash.";

return false;
}
}
}

Expand All @@ -128,8 +174,22 @@ public boolean checkHash() {
}

catch (IOException e) {
Main.errorContext = "Error while checking the MD5 hash.";
return false;
if (!this.hasTriedHashChecks) {
this.hasTriedHashChecks = true;
LogHelper.info("An error occured while checking the MD5 hash, trying again...");
try {
TimeUnit.MILLISECONDS.sleep(1000);
}
catch (InterruptedException ignore) {}

return this.checkHash();
}
else {
e.printStackTrace();
Main.errorContext = "System error while checking the MD5 hash.";

return false;
}
}
}

Expand All @@ -147,8 +207,22 @@ public boolean checkHash() {
}

catch (IOException e) {
Main.errorContext = "Error while checking the CRC32 hash.";
return false;
if (!this.hasTriedHashChecks) {
this.hasTriedHashChecks = true;
LogHelper.info("An error occured while checking the CRC32 hash, trying again...");
try {
TimeUnit.MILLISECONDS.sleep(1000);
}
catch (InterruptedException ignore) {}

return this.checkHash();
}
else {
e.printStackTrace();
Main.errorContext = "System error while checking the CRC32 hash.";

return false;
}
}
}

Expand All @@ -170,11 +244,11 @@ public boolean checkCache() {

String[] files = FileHelper.listDirectory("mcinstance-cache", false);
for (String s : files) {
if (this.SHA512 != null && s.equalsIgnoreCase("SHA512-" + this.SHA512)) return FileHelper.copy("mcinstance-cache" + File.separator + s, this.destination, true);
if (this.SHA256 != null && s.equalsIgnoreCase("SHA256-" + this.SHA256)) return FileHelper.copy("mcinstance-cache" + File.separator + s, this.destination, true);
if (this.SHA1 != null && s.equalsIgnoreCase("SHA1-" + this.SHA1)) return FileHelper.copy("mcinstance-cache" + File.separator + s, this.destination, true);
if (this.MD5 != null && s.equalsIgnoreCase("MD5-" + this.MD5)) return FileHelper.copy("mcinstance-cache" + File.separator + s, this.destination, true);
if (this.CRC32 != null && s.equalsIgnoreCase("CRC32-" + this.CRC32)) return FileHelper.copy("mcinstance-cache" + File.separator + s, this.destination, true);
if (this.SHA512 != null && s.equalsIgnoreCase("SHA512-" + this.SHA512)) return FileHelper.copy("mcinstance-cache" + File.separator + s, this.destination);
if (this.SHA256 != null && s.equalsIgnoreCase("SHA256-" + this.SHA256)) return FileHelper.copy("mcinstance-cache" + File.separator + s, this.destination);
if (this.SHA1 != null && s.equalsIgnoreCase("SHA1-" + this.SHA1)) return FileHelper.copy("mcinstance-cache" + File.separator + s, this.destination);
if (this.MD5 != null && s.equalsIgnoreCase("MD5-" + this.MD5)) return FileHelper.copy("mcinstance-cache" + File.separator + s, this.destination);
if (this.CRC32 != null && s.equalsIgnoreCase("CRC32-" + this.CRC32)) return FileHelper.copy("mcinstance-cache" + File.separator + s, this.destination);
}

return false;
Expand Down
Loading

0 comments on commit cf7155a

Please sign in to comment.