Skip to content

Commit

Permalink
Skip installing forge while extract files exist.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZekerZhayard committed Mar 26, 2020
1 parent c04ad2e commit 812a810
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 36 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: "idea"

sourceCompatibility = targetCompatibility = 1.8

version = "1.3.0"
version = "1.3.1"
group = "io.github.zekerzhayard"
archivesBaseName = rootProject.name

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package io.github.zekerzhayard.forgewrapper.installer;

import java.io.File;
import java.net.URISyntaxException;
import java.util.function.Predicate;

import cpw.mods.modlauncher.Launcher;
import net.minecraftforge.installer.actions.ActionCanceledException;
import net.minecraftforge.installer.actions.ClientInstall;
import net.minecraftforge.installer.actions.ProgressCallback;
Expand All @@ -17,15 +15,7 @@ public ClientInstall4MultiMC(Install profile, ProgressCallback monitor) {

@Override
public boolean run(File target, Predicate<String> optionals) {
File librariesDir;
try {
File laucnher = new File(Launcher.class.getProtectionDomain().getCodeSource().getLocation().toURI());
// see https://github.com/MinecraftForge/MinecraftForge/blob/863ab2ca184cf2e2dfa134d07bfc20d6a9a6a4e8/src/main/java/net/minecraftforge/fml/relauncher/libraries/LibraryManager.java#L151
// /<version> /modlauncher /mods /cpw /libraries
librariesDir = laucnher.getParentFile().getParentFile().getParentFile().getParentFile().getParentFile();
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
File librariesDir = Main.getLibrariesDir();
File clientTarget = new File(String.format("%s/com/mojang/minecraft/%s/minecraft-%s-client.jar", librariesDir.getAbsolutePath(), this.profile.getMinecraft(), this.profile.getMinecraft()));

boolean downloadLibraries = true; // Force true when without an internet connection.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package io.github.zekerzhayard.forgewrapper.installer;

import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -14,21 +17,38 @@ public class Main {
public static void main(String[] args) throws Exception {
List<String> argsList = Stream.of(args).collect(Collectors.toList());
String version = argsList.get(argsList.indexOf("--fml.mcVersion") + 1) + "-" + argsList.get(argsList.indexOf("--fml.forgeVersion") + 1);
String installerUrl = String.format("https://files.minecraftforge.net/maven/net/minecraftforge/forge/%s/forge-%s-installer.jar", version, version);
String installerFileStr = String.format("./.forgewrapper/forge-%s-installer.jar", version);
Utils.download(installerUrl, installerFileStr);

URLClassLoader ucl = URLClassLoader.newInstance(new URL[] {
Main.class.getProtectionDomain().getCodeSource().getLocation(),
Launcher.class.getProtectionDomain().getCodeSource().getLocation(),
new File(installerFileStr).toURI().toURL()
}, null);

Class<?> installer = ucl.loadClass("io.github.zekerzhayard.forgewrapper.installer.Installer");
if (!(boolean) installer.getMethod("install").invoke(null)) {
return;

Path forgeDir = getLibrariesDir().toPath().resolve("net").resolve("minecraftforge").resolve("forge").resolve(version);
Path clientJar = forgeDir.resolve("forge-" + version + "-client.jar");
Path extraJar = forgeDir.resolve("forge-" + version + "-extra.jar");
if (Files.exists(clientJar) && Files.exists(extraJar)) {
String installerUrl = String.format("https://files.minecraftforge.net/maven/net/minecraftforge/forge/%s/forge-%s-installer.jar", version, version);
String installerFileStr = String.format("./.forgewrapper/forge-%s-installer.jar", version);
Utils.download(installerUrl, installerFileStr);

URLClassLoader ucl = URLClassLoader.newInstance(new URL[] {
Main.class.getProtectionDomain().getCodeSource().getLocation(),
Launcher.class.getProtectionDomain().getCodeSource().getLocation(),
new File(installerFileStr).toURI().toURL()
}, null);

Class<?> installer = ucl.loadClass("io.github.zekerzhayard.forgewrapper.installer.Installer");
if (!(boolean) installer.getMethod("install").invoke(null)) {
return;
}
}

Launcher.main(args);
}

public static File getLibrariesDir() {
try {
File laucnher = new File(Launcher.class.getProtectionDomain().getCodeSource().getLocation().toURI());
// see https://github.com/MinecraftForge/MinecraftForge/blob/863ab2ca184cf2e2dfa134d07bfc20d6a9a6a4e8/src/main/java/net/minecraftforge/fml/relauncher/libraries/LibraryManager.java#L151
// /<version> /modlauncher /mods /cpw /libraries
return laucnher.getParentFile().getParentFile().getParentFile().getParentFile().getParentFile();
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
}
9 changes: 0 additions & 9 deletions src/main/java/why/does/multimc/target/Me.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/resources/patches/net.minecraftforge.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"formatVersion": 1,
"mainClass": "why.does.multimc.target.Me",
"mainClass": "io.github.zekerzhayard.forgewrapper.installer.Main",
"minecraftArguments": "",
"name": "Forge",
"requires": [
Expand All @@ -14,7 +14,7 @@
"version": "{FORGE_VERSION}",
"libraries": [
{
"name": "io.github.zekerzhayard:ForgeWrapper:${version}",
"name": "io.github.zekerzhayard:Forge-Wrapper:${version}",
"MMC-hint": "local",
"MMC-filename": "ForgeWrapper-${version}.jar"
}
Expand Down

0 comments on commit 812a810

Please sign in to comment.