Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9fc652f

Browse files
committedMay 11, 2018
Refactor installer
1 parent 9891ca2 commit 9fc652f

20 files changed

+551
-694
lines changed
 

‎.gitignore

+9-34
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,9 @@
1-
# Compiled class file
2-
*.class
3-
4-
# Push files
5-
Update-git.bat
6-
7-
# Log file
8-
*.log
9-
10-
# BlueJ files
11-
*.ctxt
12-
13-
# Mobile Tools for Java (J2ME)
14-
.mtj.tmp/
15-
16-
# Package Files #
17-
*.jar
18-
*.war
19-
*.ear
20-
*.zip
21-
*.tar.gz
22-
*.rar
23-
24-
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
25-
hs_err_pid*
26-
27-
# eclipse
28-
.classpath
29-
.project
30-
.settings/
31-
/bin/
32-
33-
# maven
34-
/target/
1+
/*
2+
!/.gitignore
3+
!/src
4+
!/gradle
5+
!/Patches
6+
!/init
7+
!/README.md
8+
!/build.gradle
9+
!/versions.json

‎README.md

+8-14
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,25 @@ Using the installer
88
-------------------
99

1010
To install EMC simply [download the latest version of this installer](https://github.com/Moudoux/EMC-Installer/releases).
11-
Run it with `java -jar Installer.jar`, after that open your Minecraft launcher and select `release EMC_1.12`.
11+
Run it with `java -jar Installer.jar`, after that open your Minecraft launcher and select `release 1.12.2-EMC`.
1212

1313
Making sure the installation was successful
1414
-------------------
1515

16-
You can type `.version` to check what EMC version you are running, you can type `.cinfo` to see what client is loaded.
16+
You can type `.version` to check what EMC version you are running, you can type `.mods` to see what client is loaded.
1717

1818
Installing a mod
1919
-------------------
2020

21-
To install a mod made for [EMC framework](https://github.com/Moudoux/EMC) simply drag and drop the `Client.jar` file in
22-
`.minecraft/versions/EMC_1.12/`. The client must be named `Client.jar`.
21+
To install a mod made for [EMC framework](https://github.com/Moudoux/EMC) simply drag and drop the mod jar file in
22+
`.minecraft/libraries/EMC/`.
2323

24-
Building
24+
Building and bundling mods
2525
-------------------
2626

27-
Open the EMC.json file and set Minecraft versoin and patch file (<MCVersion>-<Patch Revision>.patch)
28-
Compile the code with all dependencies, open the jar, create a folder called `assets`, in the assets add your `Client.jar` jar (Optional)
29-
30-
Making the patch file
31-
-------------------
32-
33-
To make the patch file, download the latest version of this installer, then run
34-
35-
`java -jar Installer.jar --gen <Original Minecraft jar> <Minecraft jar with EMC installed> <Patch file>`
27+
Compile the installer or grab the latest release, open it with any archive manager,
28+
open the EMC.json file and set the name field to whatever you want, finally add all the mods you
29+
want to bundle in the `mods` array. Now drag the mod jar files you want to bundle into the `assets` dir inside the installer.
3630

3731
License
3832
-------------------

‎build.gradle

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
group 'me.deftware'
2+
version '1.0.0'
3+
4+
apply plugin: 'java'
5+
6+
sourceCompatibility = 1.8
7+
8+
repositories {
9+
mavenCentral()
10+
}
11+
12+
dependencies {
13+
testCompile group: 'junit', name: 'junit', version: '4.12'
14+
}
15+
group 'me.deftware.emc'
16+
version '1.0-SNAPSHOT'
17+
18+
apply plugin: 'java'
19+
20+
sourceCompatibility = 1.8
21+
22+
repositories {
23+
mavenCentral()
24+
}
25+
26+
dependencies {
27+
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
28+
compile group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'
29+
testCompile group: 'junit', name: 'junit', version: '4.12'
30+
}

‎gradle/wrapper/gradle-wrapper.jar

53.4 KB
Binary file not shown.
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Thu May 10 19:17:16 CEST 2018
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-all.zip

‎pom.xml

-90
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,30 @@
1-
package me.deftware.emc.Installer;
2-
3-
import java.awt.Window;
4-
import java.io.BufferedReader;
5-
import java.io.InputStream;
6-
import java.io.InputStreamReader;
7-
8-
import javax.swing.SwingUtilities;
1+
package me.deftware.emc.installer;
92

103
import com.google.gson.Gson;
114
import com.google.gson.JsonObject;
5+
import me.deftware.emc.installer.ui.InstallerUI;
6+
import me.deftware.emc.installer.utils.WebUtils;
127

13-
import me.deftware.emc.ui.Progressbar;
14-
import me.deftware.emc.ui.UI;
15-
import me.deftware.emc.utils.WebUtils;
8+
import javax.swing.*;
169

1710
public class Main {
1811

1912
public static final String versionsURL = "https://raw.githubusercontent.com/Moudoux/EMC/master/versions.json";
20-
public static JsonObject versionsJson;
21-
public static JsonObject emcJson;
22-
public static String name;
2313

2414
public static void main(String[] args) {
25-
Progressbar pBar = new Progressbar("Loading installer...", 1);
26-
new Thread(() -> {
27-
try {
28-
String line;
29-
InputStream in = Main.class.getResourceAsStream("/EMC.json");
30-
StringBuilder result = new StringBuilder("");
31-
while ((line = new BufferedReader(new InputStreamReader(in)).readLine()) != null) {
32-
result.append(line);
15+
try {
16+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
17+
new Thread(() -> {
18+
try {
19+
JsonObject json = new Gson().fromJson(WebUtils.get(versionsURL), JsonObject.class);
20+
InstallerUI.create(json).setVisible(true);
21+
} catch (Exception e) {
22+
e.printStackTrace();
3323
}
34-
in.close();
35-
emcJson = new Gson().fromJson(result.toString(), JsonObject.class);
36-
versionsJson = new Gson().fromJson(WebUtils.get(versionsURL), JsonObject.class);
37-
name = emcJson.get("name").getAsString();
38-
pBar.updateBar(1);
39-
Window w = SwingUtilities.getWindowAncestor(pBar);
40-
w.setVisible(false);
41-
new UI(versionsJson);
42-
} catch (Exception e) {
43-
e.printStackTrace();
44-
}
45-
}).start();
24+
}).start();
25+
} catch (Exception e) {
26+
e.printStackTrace();
27+
}
4628
}
4729

4830
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="me.deftware.emc.installer.ui.DialogUI">
3+
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4+
<margin top="10" left="10" bottom="10" right="10"/>
5+
<constraints>
6+
<xy x="48" y="54" width="436" height="297"/>
7+
</constraints>
8+
<properties/>
9+
<border type="none"/>
10+
<children>
11+
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
12+
<margin top="0" left="0" bottom="0" right="0"/>
13+
<constraints>
14+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
15+
</constraints>
16+
<properties/>
17+
<border type="none"/>
18+
<children>
19+
<hspacer id="98af6">
20+
<constraints>
21+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
22+
</constraints>
23+
</hspacer>
24+
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
25+
<margin top="0" left="0" bottom="0" right="0"/>
26+
<constraints>
27+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
28+
</constraints>
29+
<properties/>
30+
<border type="none"/>
31+
<children>
32+
<component id="e7465" class="javax.swing.JButton" binding="buttonOK">
33+
<constraints>
34+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
35+
</constraints>
36+
<properties>
37+
<text value="Continue"/>
38+
</properties>
39+
</component>
40+
</children>
41+
</grid>
42+
</children>
43+
</grid>
44+
<grid id="e3588" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
45+
<margin top="0" left="0" bottom="0" right="0"/>
46+
<constraints>
47+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
48+
</constraints>
49+
<properties/>
50+
<border type="none"/>
51+
<children>
52+
<component id="f718c" class="javax.swing.JLabel" binding="modalText">
53+
<constraints>
54+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
55+
</constraints>
56+
<properties>
57+
<text value="Label"/>
58+
</properties>
59+
</component>
60+
<hspacer id="4b1c9">
61+
<constraints>
62+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
63+
</constraints>
64+
</hspacer>
65+
<vspacer id="eb79e">
66+
<constraints>
67+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
68+
</constraints>
69+
</vspacer>
70+
</children>
71+
</grid>
72+
</children>
73+
</grid>
74+
</form>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package me.deftware.emc.installer.ui;
2+
3+
import javax.swing.*;
4+
import java.awt.*;
5+
import java.awt.event.WindowAdapter;
6+
import java.awt.event.WindowEvent;
7+
8+
public class DialogUI extends JDialog {
9+
10+
private JPanel contentPane;
11+
private JButton buttonOK;
12+
private JLabel modalText;
13+
private DialogCallback cb;
14+
15+
public DialogUI(String text, String title, boolean continueButton, DialogCallback cb) {
16+
this.cb = cb;
17+
setContentPane(contentPane);
18+
setModal(true);
19+
getRootPane().setDefaultButton(buttonOK);
20+
buttonOK.addActionListener((e) -> onContinue());
21+
addWindowListener(new WindowAdapter() {
22+
@Override
23+
public void windowClosing(WindowEvent e) {
24+
onContinue();
25+
}
26+
});
27+
buttonOK.setVisible(continueButton);
28+
setTitle(title);
29+
modalText.setText(text);
30+
pack();
31+
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
32+
setLocation(dim.width / 2 - getSize().width / 2, dim.height / 2 - getSize().height / 2);
33+
}
34+
35+
public void onContinue() {
36+
if (cb != null) {
37+
cb.onCallback();
38+
}
39+
dispose();
40+
}
41+
42+
@FunctionalInterface
43+
public interface DialogCallback {
44+
45+
void onCallback();
46+
47+
}
48+
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="me.deftware.emc.installer.ui.InstallerUI">
3+
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="12" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4+
<margin top="0" left="0" bottom="0" right="0"/>
5+
<constraints>
6+
<xy x="20" y="20" width="539" height="294"/>
7+
</constraints>
8+
<properties/>
9+
<border type="none"/>
10+
<children>
11+
<component id="d3219" class="javax.swing.JButton" binding="installButton" default-binding="true">
12+
<constraints>
13+
<grid row="9" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
14+
</constraints>
15+
<properties>
16+
<enabled value="true"/>
17+
<text value="Install"/>
18+
</properties>
19+
</component>
20+
<component id="94dab" class="javax.swing.JButton" binding="cancelButton" default-binding="true">
21+
<constraints>
22+
<grid row="9" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
23+
</constraints>
24+
<properties>
25+
<enabled value="true"/>
26+
<text value="Cancel"/>
27+
</properties>
28+
</component>
29+
<component id="77b2b" class="javax.swing.JComboBox" binding="comboBox1" default-binding="true">
30+
<constraints>
31+
<grid row="1" column="0" row-span="5" col-span="2" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
32+
</constraints>
33+
<properties>
34+
<model/>
35+
</properties>
36+
</component>
37+
<component id="1cc5c" class="javax.swing.JRadioButton" binding="withOptiFineRadioButton" default-binding="true">
38+
<constraints>
39+
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
40+
</constraints>
41+
<properties>
42+
<selected value="false"/>
43+
<text value="With OptiFine"/>
44+
</properties>
45+
</component>
46+
<component id="8dd64" class="javax.swing.JRadioButton" binding="forForgeRadioButton" default-binding="true">
47+
<constraints>
48+
<grid row="8" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
49+
</constraints>
50+
<properties>
51+
<text value="For Forge"/>
52+
</properties>
53+
</component>
54+
<hspacer id="b4a4d">
55+
<constraints>
56+
<grid row="10" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
57+
</constraints>
58+
</hspacer>
59+
<component id="b7df6" class="javax.swing.JLabel">
60+
<constraints>
61+
<grid row="6" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
62+
</constraints>
63+
<properties>
64+
<text value="Select below if you want to install for Forge or OptiFine. "/>
65+
</properties>
66+
</component>
67+
<hspacer id="3d03">
68+
<constraints>
69+
<grid row="10" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
70+
</constraints>
71+
</hspacer>
72+
<component id="8998d" class="javax.swing.JLabel">
73+
<constraints>
74+
<grid row="7" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
75+
</constraints>
76+
<properties>
77+
<text value="Leave blank if you wish to use Aristois without Forge/OptiFine"/>
78+
</properties>
79+
</component>
80+
<component id="39125" class="javax.swing.JLabel">
81+
<constraints>
82+
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
83+
</constraints>
84+
<properties>
85+
<text value="Select which Minecraft version you want to install for:"/>
86+
</properties>
87+
</component>
88+
<component id="a58b4" class="javax.swing.JLabel">
89+
<constraints>
90+
<grid row="11" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
91+
</constraints>
92+
<properties>
93+
<text value="Made by https://deftware.me/"/>
94+
</properties>
95+
</component>
96+
</children>
97+
</grid>
98+
</form>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package me.deftware.emc.installer.ui;
2+
3+
import com.google.gson.*;
4+
import me.deftware.emc.installer.Main;
5+
import me.deftware.emc.installer.utils.JSONGenerator;
6+
import me.deftware.emc.installer.utils.Utils;
7+
import me.deftware.emc.installer.utils.WebUtils;
8+
import org.apache.commons.io.IOUtils;
9+
10+
import javax.swing.*;
11+
import javax.swing.border.EmptyBorder;
12+
import java.awt.*;
13+
import java.awt.event.ActionListener;
14+
import java.io.*;
15+
import java.nio.file.Files;
16+
17+
public class InstallerUI {
18+
19+
private JButton installButton;
20+
private JButton cancelButton;
21+
private JComboBox comboBox1;
22+
private JRadioButton withOptiFineRadioButton;
23+
private JRadioButton forForgeRadioButton;
24+
private JPanel mainPanel;
25+
private JsonObject json, internalJson;
26+
private String clientName;
27+
28+
public InstallerUI(JsonObject json, JFrame frame) {
29+
try {
30+
String line;
31+
InputStream in = Main.class.getResourceAsStream("/EMC.json");
32+
StringBuilder result = new StringBuilder("");
33+
while ((line = new BufferedReader(new InputStreamReader(in)).readLine()) != null) {
34+
result.append(line);
35+
}
36+
in.close();
37+
internalJson = new Gson().fromJson(result.toString(), JsonObject.class);
38+
} catch (Exception ex) {
39+
ex.printStackTrace();
40+
}
41+
clientName = internalJson.get("name").getAsString();
42+
frame.setTitle(clientName + " installer");
43+
this.json = json;
44+
ActionListener listener = ((e) -> {
45+
withOptiFineRadioButton.setSelected(!e.getActionCommand().equals("forge"));
46+
forForgeRadioButton.setSelected(e.getActionCommand().equals("forge"));
47+
});
48+
withOptiFineRadioButton.addActionListener(listener);
49+
forForgeRadioButton.addActionListener(listener);
50+
forForgeRadioButton.setActionCommand("forge");
51+
withOptiFineRadioButton.setActionCommand("opti");
52+
installButton.addActionListener((e) -> install());
53+
cancelButton.addActionListener((e) -> System.exit(0));
54+
json.entrySet().forEach((entry) -> comboBox1.addItem(entry.getKey()));
55+
}
56+
57+
public static JFrame create(JsonObject json) {
58+
JFrame frame = new JFrame("");
59+
InstallerUI ui = new InstallerUI(json, frame);
60+
JPanel panel = ui.mainPanel;
61+
panel.setBorder(new EmptyBorder(10, 10, 10, 10));
62+
frame.setContentPane(panel);
63+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
64+
frame.pack();
65+
frame.setMinimumSize(new Dimension(400, 0));
66+
frame.setResizable(false);
67+
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
68+
frame.setLocation(dim.width / 2 - frame.getSize().width / 2, dim.height / 2 - frame.getSize().height / 2);
69+
return frame;
70+
}
71+
72+
private void install() {
73+
String mcVersion = comboBox1.getSelectedItem().toString();
74+
String[] jsonValue = json.get(mcVersion).getAsString().split(",");
75+
String optifineVersion = jsonValue[1], emcVersion = jsonValue[0];
76+
DialogUI dialog = new DialogUI("Installing " + clientName + ", please wait...","",false, () -> {
77+
new DialogUI("Install complete, the installer will now exit", "Done", true, () -> System.exit(0)).setVisible(true);
78+
});
79+
new Thread(() -> {
80+
try {
81+
new Thread(() -> dialog.setVisible(true)).start();
82+
// Download required libs
83+
if (withOptiFineRadioButton.isSelected()) {
84+
// Download and install OptiFine
85+
File optifineDir = new File(Utils.getMinecraftRoot() + "versions" +
86+
File.separator + mcVersion + "-" + optifineVersion.replace("_" + mcVersion, "").replace(".jar", ""));
87+
if (!optifineDir.exists()) {
88+
File optifine = new File(Utils.getMinecraftRoot() + "optifine_installer.jar");
89+
String website = WebUtils.get("https://optifine.net/adloadx?f=" + optifineVersion);
90+
website = "https://optifine.net/downloadx" + website.split("downloadx")[1].split("'")[0];
91+
WebUtils.download(website, optifine.getAbsolutePath());
92+
System.out.println(
93+
IOUtils.toString(new ProcessBuilder("java", "-cp", optifine.getAbsolutePath(), "optifine.Installer")
94+
.start().getInputStream()));
95+
optifine.delete();
96+
}
97+
} else if (forForgeRadioButton.isSelected()) {
98+
// Download and install EMC
99+
String link = "https://github.com/Moudoux/EMC/raw/master/maven/me/deftware/EMC-Forge/"
100+
+ emcVersion + "/EMC-Forge-" + emcVersion + "-full.jar";
101+
new File(Utils.getMinecraftRoot() + "mods" + File.separator + mcVersion + File.separator).mkdirs();
102+
WebUtils.download(link, Utils.getMinecraftRoot() + "mods" + File.separator + mcVersion
103+
+ File.separator + "EMC.jar");
104+
}
105+
// Make JSON
106+
if (!forForgeRadioButton.isSelected()) {
107+
// Client json
108+
JsonObject json = JSONGenerator.generateClientJSON(clientName, mcVersion, emcVersion, withOptiFineRadioButton.isSelected() ? optifineVersion : "");
109+
File clientDir = new File(Utils.getMinecraftRoot() + "versions" + File.separator + mcVersion + "-" + clientName + File.separator);
110+
clientDir.mkdirs();
111+
try (Writer writer = new FileWriter(new File(clientDir.getAbsolutePath() + File.separator + mcVersion + "-" + clientName + ".json"))) {
112+
new GsonBuilder().setPrettyPrinting().create().toJson(json, writer);
113+
}
114+
// Install launcher profile
115+
File profiles_json = new File(Utils.getMinecraftRoot() + "launcher_profiles.json");
116+
JsonObject launcherJson = new JsonParser().parse(Files.newBufferedReader(profiles_json.toPath())).getAsJsonObject();
117+
JsonObject profiles = launcherJson.get("profiles").getAsJsonObject();
118+
if (!profiles.has(mcVersion + "-" + clientName)) {
119+
profiles.add(mcVersion + "-" + clientName, JSONGenerator.generateLaunchProfile(clientName, mcVersion));
120+
}
121+
launcherJson.addProperty("selectedProfile", mcVersion + "-" + clientName);
122+
try (Writer writer = new FileWriter(profiles_json)) {
123+
new GsonBuilder().setPrettyPrinting().create().toJson(launcherJson, writer);
124+
}
125+
}
126+
// Install bundled EMC mods
127+
File EMC_LIBS = new File(
128+
Utils.getMinecraftRoot() + "libraries" + File.separator + "EMC" + File.separator);
129+
EMC_LIBS.mkdirs();
130+
internalJson.get("mods").getAsJsonArray().forEach((mod) -> {
131+
String name = mod.getAsString();
132+
File m = new File(EMC_LIBS.getAbsolutePath() + File.separator + name);
133+
if (m.exists()) {
134+
m.delete();
135+
}
136+
Utils.extractAsset("/assets/" + name, m);
137+
});
138+
dialog.onContinue();
139+
} catch (Exception ex) {
140+
ex.printStackTrace();
141+
}
142+
}).start();
143+
}
144+
145+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package me.deftware.emc.installer.utils;
2+
3+
import com.google.gson.JsonArray;
4+
import com.google.gson.JsonObject;
5+
import com.google.gson.JsonPrimitive;
6+
7+
import java.text.SimpleDateFormat;
8+
import java.util.Date;
9+
10+
public class JSONGenerator {
11+
12+
public static JsonObject generateLaunchProfile(String name, String mcVersion) {
13+
JsonObject json = new JsonObject();
14+
json.add("name", new JsonPrimitive(name));
15+
json.add("type", new JsonPrimitive("custom"));
16+
json.add("icon", new JsonPrimitive("Diamond_Block"));
17+
json.add("lastVersionId", new JsonPrimitive(mcVersion + "-" + name));
18+
return json;
19+
}
20+
21+
public static JsonObject generateClientJSON(String clientName, String mcVersion, String emcVersion, String optifineVersion) {
22+
String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + "T" + new SimpleDateFormat("hh:mm:ss").format(new Date()) + "-05:00";
23+
JsonObject jsonObject = new JsonObject();
24+
String tweaker = "--username ${auth_player_name} " +
25+
"--version ${version_name} " +
26+
"--gameDir ${game_directory} " +
27+
"--assetsDir ${assets_root} " +
28+
"--assetIndex ${assets_index_name} " +
29+
"--uuid ${auth_uuid} " +
30+
"--accessToken ${auth_access_token} " +
31+
"--userType ${user_type} " +
32+
"--tweakClass me.deftware.launch.Launcher";
33+
if (!optifineVersion.equals("")) {
34+
tweaker += " --tweakClass optifine.OptiFineForgeTweaker";
35+
}
36+
// Properties
37+
jsonObject.add("inheritsFrom", new JsonPrimitive(mcVersion));
38+
jsonObject.add("id", new JsonPrimitive(mcVersion + "-" + clientName));
39+
jsonObject.add("time", new JsonPrimitive(date));
40+
jsonObject.add("releaseTime", new JsonPrimitive(date));
41+
jsonObject.add("type", new JsonPrimitive("release"));
42+
jsonObject.add("minecraftArguments", new JsonPrimitive(tweaker));
43+
jsonObject.add("mainClass", new JsonPrimitive("net.minecraft.launchwrapper.Launch"));
44+
jsonObject.add("minimumLauncherVersion", new JsonPrimitive("0"));
45+
jsonObject.add("jar", new JsonPrimitive(mcVersion));
46+
jsonObject.add("downloads", new JsonObject());
47+
// Libraries
48+
JsonArray libsArray = new JsonArray();
49+
libsArray.add(genArrayObject("name", "net.minecraft:launchwrapper:1.12", "", ""));
50+
libsArray.add(genArrayObject("name", "me.deftware:EMC:" + emcVersion, "url",
51+
"https://github.com/Moudoux/EMC/raw/master/maven/"));
52+
if (!optifineVersion.equals("")) {
53+
libsArray.add(genArrayObject("name", "optifine:OptiFine:" + optifineVersion.split("OptiFine_")[1].replace(".jar", ""), "", ""));
54+
}
55+
libsArray.add(genArrayObject("name", "org.spongepowered:mixin:0.7.1-SNAPSHOT", "url",
56+
"http://dl.liteloader.com/versions/"));
57+
libsArray.add(genArrayObject("name", "net.jodah:typetools:0.5.0", "url",
58+
"https://repo.maven.apache.org/maven2/"));
59+
jsonObject.add("libraries", libsArray);
60+
return jsonObject;
61+
}
62+
63+
private static JsonObject genArrayObject(String name, String n, String url, String u) {
64+
JsonObject obj = new JsonObject();
65+
obj.addProperty(name, n);
66+
if (!url.equals("")) {
67+
obj.addProperty(url, u);
68+
}
69+
return obj;
70+
}
71+
72+
}

‎src/main/java/me/deftware/emc/utils/OSUtils.java ‎src/main/java/me/deftware/emc/installer/utils/OSUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package me.deftware.emc.utils;
1+
package me.deftware.emc.installer.utils;
22

33
public class OSUtils {
44

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package me.deftware.emc.installer.utils;
2+
3+
import me.deftware.emc.installer.Main;
4+
import org.apache.commons.io.IOUtils;
5+
6+
import java.io.File;
7+
import java.io.FileOutputStream;
8+
import java.io.InputStream;
9+
import java.io.OutputStream;
10+
11+
public class Utils {
12+
13+
public static String getMinecraftRoot() {
14+
if (OSUtils.isWindows()) {
15+
return System.getenv("APPDATA") + File.separator + ".minecraft" + File.separator;
16+
} else if (OSUtils.isLinux()) {
17+
return System.getProperty("user.home") + File.separator + ".minecraft" + File.separator;
18+
} else if (OSUtils.isMac()) {
19+
return System.getProperty("user.home") + File.separator + "Library" + File.separator + "Application Support"
20+
+ File.separator + "minecraft" + File.separator;
21+
}
22+
return "";
23+
}
24+
25+
public static boolean extractAsset(String asset, File output) {
26+
try {
27+
if (output.exists()) {
28+
output.delete();
29+
}
30+
InputStream in = Main.class.getResourceAsStream(asset);
31+
OutputStream out = new FileOutputStream(output);
32+
IOUtils.copy(in, out);
33+
in.close();
34+
out.close();
35+
return true;
36+
} catch (Exception ex) {
37+
return false;
38+
}
39+
}
40+
41+
}

‎src/main/java/me/deftware/emc/utils/WebUtils.java ‎src/main/java/me/deftware/emc/installer/utils/WebUtils.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
package me.deftware.emc.utils;
1+
package me.deftware.emc.installer.utils;
22

3+
import javax.net.ssl.HttpsURLConnection;
34
import java.io.BufferedReader;
45
import java.io.FileOutputStream;
56
import java.io.InputStream;
@@ -8,8 +9,6 @@
89
import java.net.URL;
910
import java.net.URLConnection;
1011

11-
import javax.net.ssl.HttpsURLConnection;
12-
1312
public class WebUtils {
1413

1514
public static void download(String uri, String fileName) throws Exception {

‎src/main/java/me/deftware/emc/optifine/OptifineInstaller.java

-27
This file was deleted.

‎src/main/java/me/deftware/emc/ui/Progressbar.java

-33
This file was deleted.

‎src/main/java/me/deftware/emc/ui/UI.java

-327
This file was deleted.

‎src/main/java/me/deftware/emc/utils/Utils.java

-131
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)
Please sign in to comment.