Skip to content

Commit

Permalink
feat: {#303] automatically install LegacyJavaFixer if it should be
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanTheAllmighty committed Jun 8, 2019
1 parent 924c44c commit c609bdc
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -13,3 +13,4 @@
- Allow packs to set min/max java versions for their packs
- Allow packs to disable edit mods button
- Add browse button to java path box
- Automatically install LegacyJavaFixer if it should be installed
2 changes: 2 additions & 0 deletions src/main/java/com/atlauncher/data/Constants.java
Expand Up @@ -24,6 +24,8 @@ public class Constants {
public static final String PASTE_CHECK_URL = "https://paste.atlauncher.com";
public static final String PASTE_API_URL = "https://paste.atlauncher.com/api/create";
public static final String FORGE_MAVEN = "https://files.minecraftforge.net/maven/net/minecraftforge/forge/";
public static final String LEGACY_JAVA_FIXER_URL = "https://files.minecraftforge.net/LegacyJavaFixer/legacyjavafixer-1.0.jar";
public static final String LEGACY_JAVA_FIXER_MD5 = "12c337cb2445b56b097e7c25a5642710";
public static final Server[] SERVERS = new Server[] {
new Server("Auto", "download.nodecdn.net/containers/atl", true, false, true),
new Server("Master Server (Testing Only)", "master.atlcdn.net", false, true, true) };
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/atlauncher/data/Instance.java
Expand Up @@ -1453,7 +1453,18 @@ public void run() {
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
int detectedError = 0;

while ((line = br.readLine()) != null) {
if (line.contains("java.lang.OutOfMemoryError")) {
detectedError = MinecraftError.OUT_OF_MEMORY;
}

if (line.contains("java.util.ConcurrentModificationException")
&& Utils.matchVersion(Instance.this.getMinecraftVersion(), "1.6", true, true)) {
detectedError = MinecraftError.CONCURRENT_MODIFICATION_ERROR_1_6;
}

if (!LogManager.showDebug) {
line = line.replace(account.getMinecraftUsername(), "**MINECRAFTUSERNAME**");
line = line.replace(account.getUsername(), "**MINECRAFTUSERNAME**");
Expand Down Expand Up @@ -1525,6 +1536,10 @@ public void run() {
}
}

if (detectedError != 0) {
MinecraftError.showInformationPopup(detectedError);
}

App.settings.setMinecraftLaunched(false);
if (!App.settings.isInOfflineMode()) {
if (isLeaderboardsEnabled() && isLoggingEnabled() && !isDev()
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/com/atlauncher/data/MinecraftError.java
@@ -0,0 +1,57 @@
/*
* ATLauncher - https://github.com/ATLauncher/ATLauncher
* Copyright (C) 2013 ATLauncher
*
* 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 com.atlauncher.data;

import com.atlauncher.App;
import com.atlauncher.utils.HTMLUtils;

import java.io.File;

import javax.swing.JOptionPane;

public class MinecraftError {
static final int OUT_OF_MEMORY = 1;
static final int CONCURRENT_MODIFICATION_ERROR_1_6 = 2;

static void showInformationPopup(int error) {
switch (error) {
case MinecraftError.OUT_OF_MEMORY:
MinecraftError.showOutOfMemoryPopup();
case MinecraftError.CONCURRENT_MODIFICATION_ERROR_1_6:
MinecraftError.showConcurrentModificationError16();
}
}

static void showOutOfMemoryPopup() {
String[] options = { Language.INSTANCE.localize("common.ok") };
JOptionPane.showOptionDialog(App.settings.getParent(),
HTMLUtils.centerParagraph(
Language.INSTANCE.localizeWithReplace("instancecrash.outofmemory", "<br/><br/>")),
Language.INSTANCE.localize("instance.aboutyourcrash"), JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
}

static void showConcurrentModificationError16() {
String[] options = { Language.INSTANCE.localize("common.ok") };
JOptionPane.showOptionDialog(App.settings.getParent(),
HTMLUtils.centerParagraph(Language.INSTANCE
.localizeWithReplace("instancecrash.concurrentmodificationerror16", "<br/><br/>")),
Language.INSTANCE.localize("instance.aboutyourcrash"), JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/atlauncher/utils/Utils.java
Expand Up @@ -2236,4 +2236,25 @@ public static String convertMavenIdentifierToPath(String identifier) {
public static File convertMavenIdentifierToFile(String identifier, File base) {
return new File(base, convertMavenIdentifierToPath(identifier).replace("/", File.separatorChar + ""));
}

public static boolean matchVersion(String version, String matches, boolean lessThan, boolean equal) {
String[] versionParts = version.split("\\.", 3);
String[] matchedParts = matches.split("\\.", 2);

if (equal && versionParts[0].equals(matchedParts[0]) && versionParts[1].equals(matchedParts[1])) {
return true;
}

if (lessThan && versionParts[0].equals(matchedParts[0])
&& Integer.parseInt(versionParts[1]) < Integer.parseInt(matchedParts[1])) {
return true;
}

if (!lessThan && versionParts[0].equals(matchedParts[0])
&& Integer.parseInt(versionParts[1]) > Integer.parseInt(matchedParts[1])) {
return true;
}

return false;
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/atlauncher/workers/InstanceInstaller.java
Expand Up @@ -40,6 +40,7 @@
import com.atlauncher.Gsons;
import com.atlauncher.LogManager;
import com.atlauncher.data.APIResponse;
import com.atlauncher.data.Constants;
import com.atlauncher.data.DisableableMod;
import com.atlauncher.data.Downloadable;
import com.atlauncher.data.Instance;
Expand Down Expand Up @@ -488,6 +489,12 @@ private List<Downloadable> getDownloadableMods() {
}
}

if (Utils.matchVersion(this.getVersion().getMinecraftVersion().getVersion(), "1.6", true, true)) {
mods.add(new Downloadable(Constants.LEGACY_JAVA_FIXER_URL,
new File(App.settings.getDownloadsDir(), "legacyjavafixer-1.0.jar"),
Constants.LEGACY_JAVA_FIXER_MD5, -1, this, false));
}

return mods;
}

Expand All @@ -505,6 +512,11 @@ private void installMods() {
mod.install(this);
}
}

if (Utils.matchVersion(this.getVersion().getMinecraftVersion().getVersion(), "1.6", true, true)) {
Utils.copyFile(new File(App.settings.getDownloadsDir(), "legacyjavafixer-1.0.jar"),
this.getModsDirectory());
}
}

public boolean hasRecommendedMods() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/lang/english.lang
Expand Up @@ -380,3 +380,5 @@ tools.serverchecker.serveredited=Server Edited Successfully
tools.serverchecker.serverexistshost=Already checking a server with the same host/ip and port. Please change the name and try again!
tools.serverchecker.serverexistsname=Already checking a server with the same name. Please change the name and try again!
tools.serverchecker.servers=Servers
instancecrash.outofmemory=Minecraft has crashed due to insufficent memory being allocated.%sPlease go to the settings tab and increase the maximum memory option and then try launching the instance again.
instancecrash.concurrentmodificationerror16=Minecraft has crashed due to an incompatability with Forge and your version of Java.%sPlease reinstall the instance to automatically fix the problem, and then try launching the instance again.

0 comments on commit c609bdc

Please sign in to comment.