Compare commits

...
74 Commits
Author SHA1 Message Date
huangyuhui 005589955c modpack update 2016-01-23 19:49:12 +08:00
huangyuhui 3bdaaddcd8 add some localization items 2016-01-23 18:04:30 +08:00
huangyuhui 08301bed8d test ModpackManager 2016-01-23 16:52:40 +08:00
huangyuhui 102205de40 initializing modpack coding process 2016-01-23 12:23:56 +08:00
huangyuhui 0da589374a reconstruct code 2016-01-20 19:24:35 +08:00
huangyuhui ab08a8d3f5 getting core 4 2016-01-19 23:16:13 +08:00
huangyuhui ec5bb40758 getting core 3 2016-01-19 22:44:09 +08:00
huangyuhui bbf7f2f3f0 getting core 2 2016-01-19 22:42:06 +08:00
huangyuhui d488df81a6 getting core 2016-01-19 22:40:23 +08:00
huangyuhui d207fa3dfb reconstruct codes 2016-01-19 22:28:50 +08:00
huangyuhui f32ce42af3 Added a console log to warn the user when "always close the launcher" option turned on 2016-01-12 21:54:20 +08:00
huangyuhui 9835aa4110 Fix 'refreshVersions' calling too many times 2016-01-10 10:04:50 +08:00
huangyuhui 6c8c189b72 fix IllegalStateException crashes the application 2016-01-09 13:24:40 +08:00
huangyuhui 296df23e15 Added uuid storage in order to prevent uuid problem 2016-01-08 19:55:52 +08:00
huangyuhui 38027fc5af Fix stackoverflow 2016-01-03 22:50:58 +08:00
huangyuhui 90ab9c088e Merge branch 'master' of https://github.com/huanghongxun/HMCL 2016-01-03 19:22:40 +08:00
huangyuhui 93d747f080 add a link about mod pack 2016-01-03 19:21:52 +08:00
unknown 66c502d424 fix lookandfeel crash in windows 2016-01-02 22:56:46 +08:00
huangyuhui 3e5823b647 commit 2016-01-02 21:06:39 +08:00
huangyuhui c33383733f Changed --version 2016-01-02 12:54:24 +08:00
huangyuhui a62848d4fa each authenticator has its own username now 2016-01-02 10:26:48 +08:00
huangyuhui b82243a9c0 update code style 2016-01-01 11:03:09 +08:00
huangyuhui 1f7eb04215 Fix NullPointerException in SwingUtils.invokeAndWait 2016-01-01 10:51:44 +08:00
huangyuhui 6968809499 supported linux memory reading 2015-12-31 21:30:39 +08:00
huangyuhui 5f78f2725a fix some bugs 2015-12-30 18:51:38 +08:00
huangyuhui 3471b4fec7 fixed crashing when removing mods 2015-12-29 20:35:40 +08:00
huangyuhui e3f0254736 fix some ui problems 2015-12-29 13:57:15 +08:00
huangyuhui 07357db42d why does the ui crash 2015-12-27 10:59:03 +08:00
huanghongxun b1c6c3549f fix hmcsm 2015-12-17 22:25:03 +08:00
huanghongxun 7174e117e3 clean up 2015-12-17 22:12:01 +08:00
huanghongxun eff087d9f0 change to C.i18n 2015-12-17 20:35:23 +08:00
huanghongxun 38460678db change to C.i18n 2015-12-17 19:37:48 +08:00
huanghongxun d3372e6a60 Merge branch 'master' of https://github.com/huanghongxun/HMCL
修改:     HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/utils/auth/SkinmeAuthenticator.java
	修改:     HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N.properties
	修改:     HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_zh_CN.properties
	修改:     README.md
2015-12-17 18:13:30 +08:00
huanghongxun 2b17095c88 add i18n 2015-12-17 18:06:19 +08:00
huanghongxun 4e5fd99a3c Merge pull request #12 from LasmGratel/master
Change the format of lang files.
2015-12-17 12:47:10 +08:00
LasmGratel 02e94da4b8 remove useless files 2015-12-16 21:15:54 +08:00
LasmGratel c6fc2cc685 convert I18N from latin2 format to utf-8 format
edit README.md
2015-12-16 21:14:29 +08:00
huanghongxun 81443b8252 Add an option to disable animations 2015-12-16 12:35:04 +08:00
huanghongxun 713a0171cc Reconstruct codes 2015-12-15 21:39:53 +08:00
huanghongxun b3fb372e3b New animationsublime_text launch4jlinux.cpp 2015-12-12 21:00:32 +08:00
huanghongxun 68a734adb0 Removed redundant codes 2015-12-12 13:01:18 +08:00
huanghongxun 8186482a11 Extracted the codes about installing 2.0 2015-12-11 21:18:51 +08:00
huanghongxun d052442aea Extracted the codes about installing 2015-12-11 21:15:56 +08:00
huanghongxun 78c46aeb64 Add --proxy 2015-12-10 20:34:02 +08:00
huanghongxun e91d4c5477 Try to fix some problems 2015-12-10 14:06:56 +08:00
huanghongxun 52c43bde06 Fixed swing syncing bugs 2015-12-09 23:24:24 +08:00
huanghongxun a436e10d93 Reconstructed too many codes 2015-12-09 21:03:56 +08:00
huanghongxun 8e2fa57868 Removed AssetsMojangOldLoader.java 2015-12-07 13:41:13 +08:00
huanghongxun d3ad805ad3 Change the license to GPL v3 to be compatible with Apache License 2.0. 2015-12-05 21:41:50 +08:00
huanghongxun f0212ea4eb Reconstruct codes. 2015-12-03 20:11:52 +08:00
huanghongxun b6cb5f0bee add lite mod description in mod panel. 2015-12-01 18:20:03 +08:00
huanghongxun 73a9fbb1c4 localized some items in English. 2015-11-30 20:27:24 +08:00
huanghongxun 626cc2f6ed why is a non-null variable null? 2015-11-29 18:19:50 +08:00
huanghongxun 151b865dc5 fix performance problem about downloading file. 2015-11-23 18:28:16 +08:00
huanghongxun c76b0e0ffb add debug information. 2015-11-22 17:50:00 +08:00
huanghongxun 2dede7dea1 clean 2015-11-22 16:07:39 +08:00
huanghongxun 159a992081 format 2015-11-17 12:51:04 +08:00
huanghongxun 39b6d68006 Fixed logging conflicting with Log4j and Minecraft. 2015-11-16 23:26:23 +08:00
huanghongxun b7aa99550d Added logging highlight. 2015-11-16 18:41:28 +08:00
huanghongxun 990f830300 Fixed many bugs 2015-11-15 16:19:10 +08:00
huanghongxun f508645496 cleaning codes. 2015-11-11 22:07:01 +08:00
huanghongxun b65be375e7 Clean redundancy codes. 2015-10-26 13:02:06 +08:00
huanghongxun b9c03d6ec3 clean code. 2015-10-05 21:55:30 +08:00
huanghongxun 1d252ea71c clean 2015-10-05 16:41:36 +08:00
huanghongxun c561faf1f7 fix git. 2015-10-04 23:40:42 +08:00
huanghongxun a58aeee40c test 2015-10-04 09:31:07 +08:00
huanghongxun 9b95f9d2d7 rapiddata 2015-09-29 13:48:12 +08:00
huanghongxun 7916715efa fix CI. 2015-09-07 13:28:56 +08:00
huanghongxun 01526546b1 Fix: TaskWindow causes NullPointerException. 2015-09-07 13:00:54 +08:00
huanghongxun 6e003a7364 Fixed wrong action in mod management. 2015-09-04 19:24:26 +08:00
huanghongxun e727ca331f Fix syncing TaskWindow. 2015-09-02 18:57:24 +08:00
huanghongxun f9968580af Redesign the UI. 2015-08-31 21:06:35 +08:00
huanghongxun 981a11d98b Fix Minecraft crashing when in offline & multiplayer mode. 2015-08-27 13:02:55 +08:00
huanghongxun fef88c0144 Add #5 (1) 2015-08-26 20:23:41 +08:00
662 changed files with 38253 additions and 17935 deletions

No files matched your search

Regular → Executable
+1
View File
@@ -22,5 +22,6 @@ hs_err_pid*
HMCLAPI/build/
HMCL/build/
HMCLServer/
HMCSM/build/
MetroLookAndFeel/build/
Regular → Executable
+2 -2
View File
@@ -6,10 +6,10 @@
<source-level>1.8</source-level>
<common-tasks>
<task>
<display-name>makeExecutable</display-name>
<display-name>launch4j</display-name>
<non-blocking>no</non-blocking>
<task-names>
<name must-exist="yes">makeExecutable</name>
<name must-exist="yes">launch4j</name>
</task-names>
<task-args/>
<task-jvm-args/>
Regular → Executable
BIN
View File
Binary file not shown.
Regular → Executable
+16 -49
View File
@@ -1,18 +1,19 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
import java.util.jar.JarOutputStream
import java.util.zip.ZipEntry
@@ -25,7 +26,7 @@ if (!hasProperty('mainClass')) {
ext.mainClass = 'org.jackhuang.hellominecraft.launcher.Main'
}
def buildnumber = System.getenv("BUILD_NUMBER") == null ? ".0" : "."+System.getenv("BUILD_NUMBER")
def buildnumber = System.getenv("BUILD_NUMBER") == null ? ".7" : "."+System.getenv("BUILD_NUMBER")
String mavenGroupId = 'HMCL'
String mavenVersion = '2.3.5' + buildnumber
@@ -40,6 +41,10 @@ buildscript {
repositories {
mavenCentral();
maven {
url "https://libraries.minecraft.net"
}
dependencies {
classpath 'net.sf.proguard:proguard-gradle:4.10'
classpath 'edu.sc.seis.gradle:launch4j:1.0.6'
@@ -69,52 +74,14 @@ jar {
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
manifest {
attributes 'Created-By' : 'Copyright(c) 2013-2014 huangyuhui.',
attributes 'Created-By' : 'Copyright(c) 2013-2016 huangyuhui.',
'Main-Class' : mainClass
}
}
task proguard(type: proguard.gradle.ProGuardTask, dependsOn: jar) {
ext {
def re = jar.classifier
injar = jar.archivePath
jar.classifier = ''
outjar = jar.archivePath
jar.classifier = re
}
injars injar
outjars outjar
printmapping "obfuscate_" + version + ".map"
configuration 'proguard.pro'
}
task makeExecutable(dependsOn: jar) << {
ext {
jar.classifier = ''
makeExecutableinjar = jar.archivePath
jar.classifier = ''
makeExecutableoutjar = jar.archivePath
jar.classifier = ''
}
def loc = new File(project.buildDir, "libs/" + makeExecutableoutjar.getName().substring(0, makeExecutableoutjar.getName().length()-4)+".exe")
def fos = new FileOutputStream(loc)
def is = new FileInputStream(new File(project.buildDir, '../HMCLauncher.exe'))
int read
def bytes = new byte[8192]
while((read = is.read(bytes)) != -1)
fos.write(bytes, 0, read);
is.close()
is = new FileInputStream(makeExecutableinjar)
while((read = is.read(bytes)) != -1)
fos.write(bytes, 0, read);
is.close()
fos.close()
}
/*
launch4j {
launch4jCmd = 'D:\\Develop\\Java\\Launch4j\\launch4j.exe'
//launch4jCmd = '/home/huangyuhui/softwares/launch4j/launch4j'
supportUrl = 'http://www.mcbbs.net/thread-142335-1-1.html'
jreMinVersion = '1.6.0'
@@ -128,7 +95,7 @@ launch4j {
outfile = mavenGroupId + '-' + mavenVersion + '.exe'
messagesJreVersionError = 'This application requires a Java Runtime Environment installation, or the runtime is corrupted.\n\u6ca1\u6709\u627e\u5230\u004a\u0061\u0076\u0061\u8fd0\u884c\u65f6\uff0c\u8bf7\u4e0d\u8981\u4f7f\u7528\u7eff\u8272\u004a\u0061\u0076\u0061\uff0c\u8bf7\u4f7f\u7528\u5b89\u88c5\u7248\u7684\u004a\u0061\u0076\u0061\uff0c\u70b9\u51fb\u786e\u5b9a\u8fdb\u5165\u004a\u0061\u0076\u0061\u5b89\u88c5\u9875\u9762\u3002'
}
*/
processResources {
from(sourceSets.main.resources.srcDirs) {
exclude 'icon.icns'
Regular → Executable
View File
File mode changed.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Vendored Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
+91 -38
View File
@@ -1,39 +1,40 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher;
import java.io.File;
import java.io.FileOutputStream;
import java.lang.reflect.Method;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import javax.swing.SwingUtilities;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.utils.functions.TrueFunction;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.views.LogWindow;
import org.jackhuang.hellominecraft.launcher.launch.MinecraftCrashAdvicer;
import org.jackhuang.hellominecraft.utils.views.LogWindow;
import org.jackhuang.hellominecraft.launcher.utils.MinecraftCrashAdvicer;
import org.jackhuang.hellominecraft.utils.DoubleOutputStream;
import org.jackhuang.hellominecraft.utils.system.JdkVersion;
import org.jackhuang.hellominecraft.utils.LauncherPrintStream;
import org.jackhuang.hellominecraft.utils.system.MessageBox;
import org.jackhuang.hellominecraft.utils.system.Platform;
import org.jackhuang.hellominecraft.utils.MathUtils;
import org.jackhuang.hellominecraft.utils.MessageBox;
import org.jackhuang.hellominecraft.utils.Utils;
/**
@@ -46,33 +47,50 @@ public final class Launcher {
System.out.println(s);
}
static String classPath = "", proxyHost = "", proxyPort = "", proxyUsername = "", proxyPassword = "";
public static void main(String[] args) {
Thread.currentThread().setName("launcher");
println("*** " + Main.makeTitle() + " ***");
LogWindow.instance.setTerminateGame(Utils::shutdownForcely);
boolean showInfo = false;
String classPath = "";
String mainClass = "net.minecraft.client.Minecraft";
ArrayList<String> cmdList = new ArrayList<>();
for (String s : args)
if (s.startsWith("-cp=")) classPath = classPath.concat(s.substring("-cp=".length()));
else if (s.startsWith("-mainClass=")) mainClass = s.substring("-mainClass=".length());
else if (s.equals("-debug")) showInfo = true;
else cmdList.add(s);
String[] cmds = (String[]) cmdList.toArray(new String[cmdList.size()]);
if (s.startsWith("-cp="))
classPath = classPath.concat(s.substring("-cp=".length()));
else if (s.startsWith("-mainClass="))
mainClass = s.substring("-mainClass=".length());
else if (s.startsWith("-proxyHost="))
proxyHost = s.substring("-proxyHost=".length());
else if (s.startsWith("-proxyPort="))
proxyPort = s.substring("-proxyPort=".length());
else if (s.startsWith("-proxyUsername="))
proxyUsername = s.substring("-proxyUsername=".length());
else if (s.startsWith("-proxyPassword="))
proxyPassword = s.substring("-proxyPassword=".length());
else if (s.equals("-debug"))
showInfo = true;
else
cmdList.add(s);
String[] tokenized = StrUtils.tokenize(classPath, File.pathSeparator);
int len = tokenized.length;
if (showInfo) {
LogWindow.INSTANCE.setTerminateGame(() -> {
try {
Utils.shutdownForcely(1);
} catch (Exception e) {
MessageBox.Show(C.i18n("launcher.exit_failed"));
HMCLog.err("Failed to shutdown forcely", e);
}
});
try {
File logFile = new File("hmclmc.log");
if (!logFile.exists()) logFile.createNewFile();
if (!logFile.exists())
logFile.createNewFile();
FileOutputStream tc = new FileOutputStream(logFile);
DoubleOutputStream out = new DoubleOutputStream(tc, System.out);
System.setOut(new LauncherPrintStream(out));
@@ -86,11 +104,24 @@ public final class Launcher {
println("Arguments: {\n" + StrUtils.parseParams(" ", args, "\n") + "\n}");
println("Main Class: " + mainClass);
println("Class Path: {\n" + StrUtils.parseParams(" ", tokenized, "\n") + "\n}");
SwingUtilities.invokeLater(() -> LogWindow.instance.setVisible(true));
SwingUtilities.invokeLater(() -> LogWindow.INSTANCE.setVisible(true));
}
if (!JdkVersion.isJava64Bit() && Platform.getPlatform() == Platform.BIT_64)
MessageBox.Show(C.i18n("advice.os64butjdk32"));
if (StrUtils.isNotBlank(proxyHost) && StrUtils.isNotBlank(proxyPort) && MathUtils.canParseInt(proxyPort)) {
HMCLog.log("Initializing customized proxy");
System.setProperty("http.proxyHost", proxyHost);
System.setProperty("http.proxyPort", proxyPort);
if (StrUtils.isNotBlank(proxyUsername) && StrUtils.isNotBlank(proxyPassword))
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(proxyUsername, proxyPassword.toCharArray());
}
});
//PROXY = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(Settings.getInstance().getProxyHost(), Integer.parseInt(Settings.getInstance().getProxyPort())));
} else {
//PROXY = Proxy.NO_PROXY;
}
URL[] urls = new URL[len];
@@ -105,8 +136,10 @@ public final class Launcher {
}
Method minecraftMain;
URLClassLoader ucl = new URLClassLoader(urls, URLClassLoader.getSystemClassLoader().getParent());
Thread.currentThread().setContextClassLoader(ucl);
try {
minecraftMain = new URLClassLoader(urls, URLClassLoader.getSystemClassLoader().getParent()).loadClass(mainClass).getMethod("main", String[].class);
minecraftMain = ucl.loadClass(mainClass).getMethod("main", String[].class);
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException t) {
MessageBox.Show(C.i18n("crash.main_class_not_found"));
println("Minecraft main class not found.");
@@ -116,21 +149,41 @@ public final class Launcher {
println("*** Launching Game ***");
int flag = 0;
try {
minecraftMain.invoke(null, new Object[]{cmds});
minecraftMain.invoke(null, new Object[] { (String[]) cmdList.toArray(new String[cmdList.size()]) });
} catch (Throwable throwable) {
HMCLog.err("Cought exception!");
String trace = StrUtils.getStackTrace(throwable);
final String advice = MinecraftCrashAdvicer.getAdvice(trace);
MessageBox.Show(C.i18n("crash.minecraft") + ": " + advice);
LogWindow.instance.log(C.i18n("crash.minecraft"));
LogWindow.instance.log(advice);
LogWindow.instance.log(trace);
LogWindow.instance.setExit(TrueFunction.instance);
LogWindow.instance.setVisible(true);
System.err.println(C.i18n("crash.minecraft"));
System.err.println(advice);
System.err.println(trace);
LogWindow.INSTANCE.setExit(() -> true);
LogWindow.INSTANCE.setVisible(true);
flag = 1;
}
println("*** Game Exited ***");
try {
Utils.shutdownForcely(flag);
} catch (Exception e) {
MessageBox.Show(C.i18n("launcher.exit_failed"));
HMCLog.err("Failed to shutdown forcely", e);
}
}
/*
* static Object getShutdownHaltLock() {
* try {
* Class z = Class.forName("java.lang.Shutdown");
* Field haltLock = z.getDeclaredField("haltLock");
* haltLock.setAccessible(true);
* return haltLock.get(null);
* } catch (Throwable ex) {
* ex.printStackTrace();
* return new Object();
* }
* }
*/
}
+55 -111
View File
@@ -1,66 +1,54 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.GeneralSecurityException;
import java.security.cert.X509Certificate;
import java.text.ParseException;
import java.util.Map;
import java.util.jar.JarFile;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.X509TrustManager;
import javax.swing.ImageIcon;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.launch.GameLauncher;
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
import org.jackhuang.hellominecraft.launcher.api.PluginManager;
import org.jackhuang.hellominecraft.launcher.core.launch.GameLauncher;
import org.jackhuang.hellominecraft.launcher.utils.CrashReporter;
import org.jackhuang.hellominecraft.logging.Configuration;
import org.jackhuang.hellominecraft.logging.appender.ConsoleAppender;
import org.jackhuang.hellominecraft.logging.layout.DefaultLayout;
import org.jackhuang.hellominecraft.views.LogWindow;
import org.jackhuang.hellominecraft.utils.logging.Configuration;
import org.jackhuang.hellominecraft.utils.logging.appender.ConsoleAppender;
import org.jackhuang.hellominecraft.utils.logging.layout.DefaultLayout;
import org.jackhuang.hellominecraft.utils.views.LogWindow;
import org.jackhuang.hellominecraft.launcher.settings.Settings;
import org.jackhuang.hellominecraft.launcher.utils.upgrade.Upgrader;
import org.jackhuang.hellominecraft.launcher.utils.upgrade.IUpgrader;
import org.jackhuang.hellominecraft.launcher.views.MainFrame;
import org.jackhuang.hellominecraft.lookandfeel.HelloMinecraftLookAndFeel;
import org.jackhuang.hellominecraft.tasks.TaskWindow;
import org.jackhuang.hellominecraft.utils.ArrayUtils;
import org.jackhuang.hellominecraft.utils.system.MessageBox;
import org.jackhuang.hellominecraft.utils.MathUtils;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.utils.VersionNumber;
import org.jackhuang.hellominecraft.utils.system.FileUtils;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
import org.jackhuang.hellominecraft.utils.system.OS;
import org.jackhuang.hellominecraft.utils.system.Compressor;
import rx.concurrency.Schedulers;
/**
*
@@ -68,7 +56,7 @@ import org.jackhuang.hellominecraft.utils.system.OS;
*/
public final class Main implements Runnable {
private static final X509TrustManager xtm = new X509TrustManager() {
private static final X509TrustManager XTM = new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) {
}
@@ -82,26 +70,27 @@ public final class Main implements Runnable {
return null;
}
};
private static final HostnameVerifier hnv = (hostname, session) -> true;
private static final HostnameVerifier HNV = (hostname, session) -> true;
static {
SSLContext sslContext = null;
try {
sslContext = SSLContext.getInstance("TLS");
X509TrustManager[] xtmArray = new X509TrustManager[]{xtm};
X509TrustManager[] xtmArray = new X509TrustManager[] { XTM };
sslContext.init(null, xtmArray, new java.security.SecureRandom());
} catch (GeneralSecurityException gse) {
}
if (sslContext != null)
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(hnv);
HttpsURLConnection.setDefaultHostnameVerifier(HNV);
}
public static String launcherName = "Hello Minecraft! Launcher";
public static byte firstVer = 2, secondVer = 3, thirdVer = 5, forthVer = 0;
public static int minimumLauncherVersion = 16;
public static final String LAUNCHER_NAME = "Hello Minecraft! Launcher";
public static final byte VERSION_FIRST = 2, VERSION_SECOND = 3, VERSION_THIRD = 5, VERSION_FORTH = 8;
public static final int MINIMUM_LAUNCHER_VERSION = 16;
//public static Proxy PROXY;
/**
* Make the version of HMCL.
@@ -109,7 +98,7 @@ public final class Main implements Runnable {
* @return the version: firstVer.secondVer.thirdVer
*/
public static String makeVersion() {
return "" + firstVer + '.' + secondVer + '.' + thirdVer + '.' + forthVer;
return "" + VERSION_FIRST + '.' + VERSION_SECOND + '.' + VERSION_THIRD + '.' + VERSION_FORTH;
}
/**
@@ -118,38 +107,21 @@ public final class Main implements Runnable {
* @return the MainWindow title.
*/
public static String makeTitle() {
return launcherName + ' ' + makeVersion();
return LAUNCHER_NAME + ' ' + makeVersion();
}
public static final Main instance = new Main();
public static final Main INSTANCE = new Main();
public static HelloMinecraftLookAndFeel LOOK_AND_FEEL;
public static void main(String[] args) {
@SuppressWarnings({ "CallToPrintStackTrace", "UseSpecificCatch" })
public static void main(String[] args) throws IOException {
{
if (!ArrayUtils.contains(args, "nofound"))
try {
File f = Upgrader.HMCL_VER_FILE;
if (f.exists()) {
Map<String, String> m = C.gson.fromJson(FileUtils.readFileToString(f), Map.class);
String s = m.get("ver");
if (s != null && VersionNumber.check(s).compareTo(new VersionNumber(firstVer, secondVer, thirdVer)) > 0) {
String j = m.get("loc");
if (j != null) {
File jar = new File(j);
if (jar.exists()) {
JarFile jarFile = new JarFile(jar);
String mainClass = jarFile.getManifest().getMainAttributes().getValue("Main-Class");
if (mainClass != null) {
new URLClassLoader(new URL[]{jar.toURI().toURL()}, URLClassLoader.getSystemClassLoader().getParent()).loadClass(mainClass).getMethod("main", String[].class).invoke(null, new Object[]{new String[]{"nofound"}});
return;
}
}
}
}
}
} catch (Throwable t) {
t.printStackTrace();
}
//PluginManager.getServerPlugin();
if (IUpgrader.NOW_UPGRADER.parseArguments(new VersionNumber(VERSION_FIRST, VERSION_SECOND, VERSION_THIRD), args))
return;
System.setProperty("sun.java2d.noddraw", "true");
Thread.setDefaultUncaughtExceptionHandler(new CrashReporter(true));
try {
@@ -164,18 +136,22 @@ public final class Main implements Runnable {
HMCLog.log("*** " + Main.makeTitle() + " ***");
LogWindow.instance.clean();
LogWindow.instance.setTerminateGame(GameLauncher.PROCESS_MANAGER::stopAllProcesses);
LogWindow.INSTANCE.clean();
LogWindow.INSTANCE.setTerminateGame(GameLauncher.PROCESS_MANAGER::stopAllProcesses);
try {
UIManager.setLookAndFeel(new HelloMinecraftLookAndFeel());
LOOK_AND_FEEL = new HelloMinecraftLookAndFeel(Settings.getInstance().getTheme().settings);
UIManager.setLookAndFeel(LOOK_AND_FEEL);
} catch (ParseException | UnsupportedLookAndFeelException ex) {
HMCLog.warn("Failed to set look and feel...", ex);
}
Settings.UPDATE_CHECKER.start();
Settings.UPDATE_CHECKER.outdated.register(IUpgrader.NOW_UPGRADER);
Settings.UPDATE_CHECKER.process(false).subscribeOn(Schedulers.newThread()).subscribe(t
-> Main.invokeUpdate());
if (StrUtils.isNotBlank(Settings.getInstance().getProxyHost()) && StrUtils.isNotBlank(Settings.getInstance().getProxyPort())) {
if (StrUtils.isNotBlank(Settings.getInstance().getProxyHost()) && StrUtils.isNotBlank(Settings.getInstance().getProxyPort()) && MathUtils.canParseInt(Settings.getInstance().getProxyPort())) {
HMCLog.log("Initializing customized proxy");
System.setProperty("http.proxyHost", Settings.getInstance().getProxyHost());
System.setProperty("http.proxyPort", Settings.getInstance().getProxyPort());
if (StrUtils.isNotBlank(Settings.getInstance().getProxyUserName()) && StrUtils.isNotBlank(Settings.getInstance().getProxyPassword()))
@@ -187,7 +163,12 @@ public final class Main implements Runnable {
});
}
MainFrame.showMainFrame(Settings.isFirstLoad());
try {
PluginManager.NOW_PLUGIN.showUI();
} catch (Throwable t) {
new CrashReporter(false).uncaughtException(Thread.currentThread(), t);
System.exit(1);
}
}
}
@@ -196,45 +177,8 @@ public final class Main implements Runnable {
GameLauncher.PROCESS_MANAGER.stopAllProcesses();
}
public static void update() {
Settings.UPDATE_CHECKER.requestDownloadLink(() -> {
SwingUtilities.invokeLater(() -> {
Map<String, String> map = Settings.UPDATE_CHECKER.download_link;
if (map != null && map.containsKey("pack"))
try {
if (TaskWindow.getInstance().addTask(new Upgrader(map.get("pack"), Settings.UPDATE_CHECKER.versionString)).start()) {
new ProcessBuilder(new String[]{IOUtils.getJavaDir(), "-jar", Upgrader.getSelf(Settings.UPDATE_CHECKER.versionString).getAbsolutePath()}).directory(new File(".")).start();
System.exit(0);
}
} catch (IOException ex) {
HMCLog.warn("Failed to create upgrader", ex);
}
if (MessageBox.Show(C.i18n("update.newest_version") + Settings.UPDATE_CHECKER.getNewVersion().firstVer + "." + Settings.UPDATE_CHECKER.getNewVersion().secondVer + "." + Settings.UPDATE_CHECKER.getNewVersion().thirdVer + "\n"
+ C.i18n("update.should_open_link"),
MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
String url = C.URL_PUBLISH;
if (map != null)
if (map.containsKey(OS.os().checked_name))
url = map.get(OS.os().checked_name);
else if (map.containsKey(OS.UNKOWN.checked_name))
url = map.get(OS.UNKOWN.checked_name);
if (url == null) url = C.URL_PUBLISH;
try {
java.awt.Desktop.getDesktop().browse(new URI(url));
} catch (URISyntaxException | IOException e) {
HMCLog.warn("Failed to browse uri: " + url, e);
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
cb.setContents(new StringSelection(url), null);
MessageBox.Show(C.i18n("update.no_browser"));
}
}
});
});
}
public static void invokeUpdate() {
MainFrame.instance.invokeUpdate();
MainFrame.INSTANCE.invokeUpdate();
}
public static ImageIcon getIcon(String path) {
@@ -0,0 +1,63 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.api;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.settings.Profile;
import org.jackhuang.hellominecraft.launcher.core.auth.AuthenticationException;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.utils.functions.Consumer;
/**
*
* @author huangyuhui
*/
public interface IPlugin {
/**
* You can modify the application actions by this method.
*
* @param profile info to the Minecraft Loader
*
* @return For example, you can implement IMinecraftProvider to support
* MultiMC
*/
IMinecraftService provideMinecraftService(Profile profile);
/**
* Register authenticators by calling IAuthenticator.LOGINS.add.
*
* @param apply call apply.accept(your authenticator)
*/
void onRegisterAuthenticators(Consumer<IAuthenticator> apply);
/**
* Open your customized UI.
*/
void showUI();
/**
* Add your server ip or modify the access token.
*
* @param result What you want.
*/
void onProcessingLoginResult(UserProfileProvider result) throws AuthenticationException;
void onInitializingProfile(Profile p);
}
@@ -0,0 +1,43 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.api;
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
import org.jackhuang.hellominecraft.launcher.settings.DefaultPlugin;
/**
*
* @author huangyuhui
*/
public class PluginManager {
public static IPlugin NOW_PLUGIN = new DefaultPlugin();
public static void getServerPlugin() {
try {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Class c = cl.loadClass("org.jackhuang.hellominecraft.launcher.servers.ServerPlugin");
IPlugin p = (IPlugin) c.newInstance();
NOW_PLUGIN = p;
} catch (ClassNotFoundException ignore) {
} catch (Exception e) {
HMCLog.err("Failed to new instance");
}
}
}
@@ -0,0 +1,41 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core;
/**
*
* @author huangyuhui
*/
public class GameException extends Exception {
public GameException() {
}
public GameException(String message) {
super(message);
}
public GameException(String message, Throwable cause) {
super(message, cause);
}
public GameException(Throwable cause) {
super(cause);
}
}
@@ -1,20 +1,21 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.settings;
package org.jackhuang.hellominecraft.launcher.core;
/**
*
@@ -0,0 +1,90 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core;
import java.io.File;
import java.io.IOException;
import org.jackhuang.hellominecraft.utils.system.FileUtils;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
import org.jackhuang.hellominecraft.utils.system.OS;
/**
*
* @author huang
*/
public final class MCUtils {
public static File getWorkingDirectory(String baseName) {
String userhome = System.getProperty("user.home", ".");
File file;
switch (OS.os()) {
case LINUX:
file = new File(userhome, '.' + baseName + '/');
break;
case WINDOWS:
String appdata = System.getenv("APPDATA");
if (appdata != null)
file = new File(appdata, "." + baseName + '/');
else
file = new File(userhome, '.' + baseName + '/');
break;
case OSX:
file = new File(userhome, "Library/Application Support/" + baseName);
break;
default:
file = new File(userhome, baseName + '/');
}
return file;
}
public static File getLocation() {
return getWorkingDirectory("minecraft");
}
public static boolean is16Folder(String path) {
path = IOUtils.addSeparator(path);
return new File(path, "versions").exists();
}
public static String minecraft() {
if (OS.os() == OS.OSX)
return "minecraft";
return ".minecraft";
}
public static File getInitGameDir() {
File gameDir = IOUtils.currentDir();
if (gameDir.exists()) {
gameDir = new File(gameDir, MCUtils.minecraft());
if (!gameDir.exists()) {
File newFile = MCUtils.getLocation();
if (newFile.exists())
gameDir = newFile;
}
}
return gameDir;
}
public static String profile = "{\"selectedProfile\": \"(Default)\",\"profiles\": {\"(Default)\": {\"name\": \"(Default)\"}},\"clientToken\": \"88888888-8888-8888-8888-888888888888\"}";
public static void tryWriteProfile(File gameDir) throws IOException {
File file = new File(gameDir, "launcher_profiles.json");
if (!file.exists())
FileUtils.writeStringToFile(file, profile);
}
}
@@ -0,0 +1,146 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.utils.system.FileUtils;
/**
*
* @author huangyuhui
*/
public class ModInfo implements Comparable<ModInfo> {
public File location;
public String modid, name, description, author, version, mcversion, url, updateUrl, credits;
public String[] authorList;
public boolean isActive() {
return !location.getName().endsWith(".disabled");
}
public void reverseModState() {
File f = location, newf;
if (f.getName().endsWith(".disabled"))
newf = new File(f.getParentFile(), f.getName().substring(0, f.getName().length() - ".disabled".length()));
else
newf = new File(f.getParentFile(), f.getName() + ".disabled");
if (f.renameTo(newf))
location = newf;
}
@Override
public int compareTo(ModInfo o) {
return getFileName().toLowerCase().compareTo(o.getFileName().toLowerCase());
}
public String getName() {
return name == null ? FileUtils.removeExtension(location.getName()) : name;
}
public String getAuthor() {
if (authorList != null && authorList.length > 0)
return StrUtils.parseParams("", authorList, ", ");
else if (StrUtils.isNotBlank(author))
return author;
else
return "Unknown";
}
@Override
public boolean equals(Object obj) {
return obj != null && obj instanceof ModInfo && (((ModInfo) obj).location == location || ((ModInfo) obj).location.equals(location));
}
@Override
public int hashCode() {
return location.hashCode();
}
@Override
public String toString() {
return getFileName();
}
public String getFileName() {
String n = location.getName();
return FileUtils.removeExtension(isActive() ? n : n.substring(0, n.length() - ".disabled".length()));
}
public static boolean isFileMod(File file) {
if (file == null)
return false;
String name = file.getName();
boolean disabled = name.endsWith(".disabled");
if (disabled)
name = name.substring(0, name.length() - ".disabled".length());
return name.endsWith(".zip") || name.endsWith(".jar") || name.endsWith("litemod");
}
private static ModInfo getForgeModInfo(File f, ZipFile jar, ZipEntry entry) throws IOException {
ModInfo i = new ModInfo();
i.location = f;
List<ModInfo> m = C.gson.fromJson(new InputStreamReader(jar.getInputStream(entry)),
new TypeToken<List<ModInfo>>() {
}.getType());
if (m != null && m.size() > 0) {
i = m.get(0);
i.location = f;
}
return i;
}
private static ModInfo getLiteLoaderModInfo(File f, ZipFile jar, ZipEntry entry) throws IOException {
ModInfo m = C.gson.fromJson(new InputStreamReader(jar.getInputStream(entry)),
ModInfo.class);
if (m == null)
m = new ModInfo();
m.location = f;
return m;
}
public static ModInfo readModInfo(File f) {
ModInfo i = new ModInfo();
i.location = f;
try {
try (ZipFile jar = new ZipFile(f)) {
ZipEntry entry = jar.getEntry("mcmod.info");
if (entry != null)
return getForgeModInfo(f, jar, entry);
entry = jar.getEntry("litemod.json");
if (entry != null)
return getLiteLoaderModInfo(f, jar, entry);
return i;
}
} catch (IOException ex) {
HMCLog.warn("File " + f + " is not a jar.", ex);
} catch (JsonSyntaxException ignore) {
}
return i;
}
}
@@ -1,20 +1,21 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.assets;
package org.jackhuang.hellominecraft.launcher.core.assets;
import java.util.HashSet;
import java.util.LinkedHashMap;
@@ -0,0 +1,117 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.assets;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftAssetService;
import org.jackhuang.hellominecraft.utils.tasks.Task;
import org.jackhuang.hellominecraft.utils.system.FileUtils;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.launcher.core.download.IDownloadProvider;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.utils.VersionNumber;
import rx.Observable;
import rx.Observer;
/**
*
* @author huangyuhui
*/
public class AssetsMojangLoader extends IAssetsHandler {
public AssetsMojangLoader(String name) {
super(name);
}
@Override
public Observable<String[]> getList(MinecraftVersion mv, IMinecraftAssetService mp) {
return Observable.<String[]>createWithEmptySubscription((Observer<String[]> t1) -> {
if (mv == null) {
t1.onError(null);
return;
}
String assetsId = mv.assets == null ? "legacy" : mv.assets;
File assets = mp.getAssets();
HMCLog.log("Get index: " + assetsId);
File f = IOUtils.tryGetCanonicalFile(new File(assets, "indexes/" + assetsId + ".json"));
if (!f.exists() && !mp.downloadMinecraftAssetsIndex(assetsId)) {
t1.onError(null);
return;
}
String result;
try {
result = FileUtils.readFileToString(f);
} catch (IOException ex) {
HMCLog.warn("Failed to read index json: " + f, ex);
t1.onError(null);
return;
}
if (StrUtils.isBlank(result)) {
HMCLog.err("Index json is empty, please redownload it!");
t1.onError(null);
return;
}
AssetsIndex o;
try {
o = C.gson.fromJson(result, AssetsIndex.class);
} catch (Exception e) {
HMCLog.err("Failed to parse index json, please redownload it!", e);
t1.onError(null);
return;
}
assetsDownloadURLs = new ArrayList<>();
assetsLocalNames = new ArrayList<>();
ArrayList<String> al = new ArrayList<>();
contents = new ArrayList<>();
if (o != null && o.getFileMap() != null)
for (Map.Entry<String, AssetsObject> e : o.getFileMap().entrySet()) {
Contents c = new Contents();
c.eTag = e.getValue().getHash();
c.key = c.eTag.substring(0, 2) + "/" + e.getValue().getHash();
c.size = e.getValue().getSize();
contents.add(c);
assetsDownloadURLs.add(c.key);
assetsLocalNames.add(new File(assets, "objects" + File.separator + c.key.replace("/", File.separator)));
al.add(e.getKey());
}
t1.onNext(al.toArray(new String[1]));
t1.onCompleted();
});
}
@Override
public Task getDownloadTask(IDownloadProvider sourceType) {
return new AssetsTask(sourceType.getAssetsDownloadURL());
}
@Override
public boolean isVersionAllowed(String formattedVersion) {
VersionNumber ur = VersionNumber.check(formattedVersion);
if (ur == null)
return false;
return VersionNumber.check("1.6.0").compareTo(ur) <= 0;
}
}
@@ -1,20 +1,21 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.assets;
package org.jackhuang.hellominecraft.launcher.core.assets;
/**
*
@@ -38,10 +39,13 @@ public class AssetsObject {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
AssetsObject that = (AssetsObject) o;
if (this.size != that.size) return false;
if (this.size != that.size)
return false;
return this.hash.equals(that.hash);
}
@@ -1,20 +1,21 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.assets;
package org.jackhuang.hellominecraft.launcher.core.assets;
/**
*
@@ -1,20 +1,21 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.assets;
package org.jackhuang.hellominecraft.launcher.core.assets;
import java.io.File;
import java.io.FileInputStream;
@@ -22,17 +23,17 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
import org.jackhuang.hellominecraft.launcher.utils.download.IDownloadProvider;
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
import org.jackhuang.hellominecraft.tasks.Task;
import org.jackhuang.hellominecraft.tasks.download.FileDownloadTask;
import org.jackhuang.hellominecraft.utils.functions.Consumer;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftAssetService;
import org.jackhuang.hellominecraft.launcher.core.download.IDownloadProvider;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.utils.tasks.Task;
import org.jackhuang.hellominecraft.utils.tasks.download.FileDownloadTask;
import org.jackhuang.hellominecraft.utils.code.DigestUtils;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
import org.jackhuang.hellominecraft.utils.NetUtils;
import rx.Observable;
/**
* Assets
@@ -50,18 +51,10 @@ public abstract class IAssetsHandler {
this.name = name;
}
private static final List<IAssetsHandler> assetsHandlers = new ArrayList<>();
public static IAssetsHandler getAssetsHandler(int i) {
return assetsHandlers.get(i);
}
public static List<IAssetsHandler> getAssetsHandlers() {
return assetsHandlers;
}
public static final IAssetsHandler ASSETS_HANDLER;
static {
assetsHandlers.add(new AssetsMojangLoader(C.i18n("assets.list.1_7_3_after")));
ASSETS_HANDLER = new AssetsMojangLoader(C.i18n("assets.list.1_7_3_after"));
}
/**
@@ -76,33 +69,21 @@ public abstract class IAssetsHandler {
/**
* All the files assets needed
*
* @param x finished event
* @param mv The version that needs assets
* @param mp Asset Service
* @param x finished event
*/
public abstract void getList(Consumer<String[]> x);
public abstract Observable<String[]> getList(MinecraftVersion mv, IMinecraftAssetService mp);
/**
* Will be invoked when the user invoked "Download all assets".
*
* @param sourceType Download Source
*
* @return Download File Task
*/
public abstract Task getDownloadTask(IDownloadProvider sourceType);
/**
* assets path
*/
protected MinecraftVersion mv;
protected IMinecraftProvider mp;
/**
* @param mp
* @param mv
*/
public void setAssets(IMinecraftProvider mp, MinecraftVersion mv) {
this.mp = mp;
this.mv = mv;
}
public abstract boolean isVersionAllowed(String formattedVersion);
protected class AssetsTask extends Task {
@@ -115,11 +96,9 @@ public abstract class IAssetsHandler {
}
@Override
public boolean executeTask() {
if (mv == null || assetsDownloadURLs == null) {
setFailReason(new RuntimeException(C.i18n("assets.not_refreshed")));
return false;
}
public void executeTask() {
if (assetsDownloadURLs == null)
throw new IllegalStateException(C.i18n("assets.not_refreshed"));
int max = assetsDownloadURLs.size();
al = new ArrayList<>();
int hasDownloaded = 0;
@@ -127,8 +106,10 @@ public abstract class IAssetsHandler {
String mark = assetsDownloadURLs.get(i);
String url = u + mark;
File location = assetsLocalNames.get(i);
if (!location.getParentFile().exists()) location.getParentFile().mkdirs();
if (location.isDirectory()) continue;
if (!location.getParentFile().exists())
location.getParentFile().mkdirs();
if (location.isDirectory())
continue;
boolean need = true;
try {
if (location.exists()) {
@@ -147,9 +128,9 @@ public abstract class IAssetsHandler {
HMCLog.warn("Failed to get hash: " + location, e);
need = !location.exists();
}
if (need) al.add(new FileDownloadTask(url, location).setTag(mark));
if (need)
al.add(new FileDownloadTask(url, location).setTag(mark));
}
return true;
}
@Override
@@ -0,0 +1,116 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.assets;
import com.google.gson.JsonSyntaxException;
import java.io.File;
import java.io.IOException;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftAssetService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.utils.tasks.Task;
import org.jackhuang.hellominecraft.utils.tasks.TaskWindow;
import org.jackhuang.hellominecraft.utils.tasks.download.FileDownloadTask;
import org.jackhuang.hellominecraft.utils.system.FileUtils;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
import rx.concurrency.Schedulers;
/**
*
* @author huangyuhui
*/
public class MinecraftAssetService extends IMinecraftAssetService {
public MinecraftAssetService(IMinecraftService service) {
super(service);
}
@Override
public Task downloadAssets(String mcVersion) {
return new Task() {
@Override
public void executeTask() throws Throwable {
IAssetsHandler type = IAssetsHandler.ASSETS_HANDLER;
type.getList(service.version().getVersionById(mcVersion), service.asset())
.subscribeOn(Schedulers.newThread())
.observeOn(Schedulers.eventQueue())
.subscribe((t) -> TaskWindow.getInstance().addTask(type.getDownloadTask(service.getDownloadType().getProvider())).start());
}
@Override
public String getInfo() {
return "Download Assets";
}
};
}
@Override
public boolean refreshAssetsIndex(String id) {
MinecraftVersion mv = service.version().getVersionById(id);
if (mv == null)
return false;
return downloadMinecraftAssetsIndex(mv.assets);
}
@Override
public boolean downloadMinecraftAssetsIndex(String assetsId) {
String aurl = service.getDownloadType().getProvider().getIndexesDownloadURL();
File assetsLocation = getAssets();
assetsLocation.mkdirs();
File assetsIndex = new File(assetsLocation, "indexes/" + assetsId + ".json");
File renamed = null;
if (assetsIndex.exists()) {
renamed = new File(assetsLocation, "indexes/" + assetsId + "-renamed.json");
assetsIndex.renameTo(renamed);
}
if (TaskWindow.getInstance()
.addTask(new FileDownloadTask(aurl + assetsId + ".json", IOUtils.tryGetCanonicalFile(assetsIndex)).setTag(assetsId + ".json"))
.start()) {
if (renamed != null)
renamed.delete();
return true;
}
if (renamed != null)
renamed.renameTo(assetsIndex);
return false;
}
@Override
public File getAssets() {
return new File(service.baseDirectory(), "assets");
}
@Override
public File getAssetObject(String assetVersion, String name) throws IOException {
File assetsDir = getAssets();
File indexDir = new File(assetsDir, "indexes");
File objectsDir = new File(assetsDir, "objects");
File indexFile = new File(indexDir, assetVersion + ".json");
try {
AssetsIndex index = (AssetsIndex) C.gson.fromJson(FileUtils.readFileToString(indexFile, "UTF-8"), AssetsIndex.class);
String hash = ((AssetsObject) index.getFileMap().get(name)).getHash();
return new File(objectsDir, hash.substring(0, 2) + "/" + hash);
} catch (JsonSyntaxException e) {
throw new IOException("Assets file format malformed.", e);
}
}
}
@@ -0,0 +1,36 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.auth;
public class AuthenticationException extends Exception {
public AuthenticationException() {
}
public AuthenticationException(String message) {
super(message);
}
public AuthenticationException(String message, Throwable cause) {
super(message, cause);
}
public AuthenticationException(Throwable cause) {
super(cause);
}
}
@@ -0,0 +1,101 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.auth;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import org.jackhuang.hellominecraft.utils.code.DigestUtils;
/**
*
* @author huangyuhui
*/
public final class BestLogin extends IAuthenticator {
public BestLogin(String clientToken) {
super(clientToken);
}
@Override
public UserProfileProvider login(LoginInfo info) throws AuthenticationException {
try {
String request = "bl:l:" + info.username + ":" + DigestUtils.sha1Hex(info.password);
Socket socket = new Socket("auth.zhh0000zhh.com", 8);
OutputStream os = socket.getOutputStream();
os.write(request.length());
os.write(request.getBytes());
UserProfileProvider lr = new UserProfileProvider();
InputStream is = socket.getInputStream();
int code = is.read();
switch (code) {
case -1:
throw new AuthenticationException("internet error.");
case 200:
throw new AuthenticationException("server restarting.");
case 255:
throw new AuthenticationException("unknown error");
case 3:
throw new AuthenticationException("unregistered.");
case 50:
throw new AuthenticationException("please update your launcher and act your account.");
case 2:
throw new AuthenticationException("wrong password.");
case 100:
throw new AuthenticationException("server reloading.");
case 0:
byte[] b = new byte[64];
is.read(b, 0, b.length);
String[] ss = new String(b).split(":");
lr.setUserName(info.username);
lr.setUserId(ss[1]);
lr.setSession(ss[0]);
lr.setAccessToken(ss[0]);
break;
}
lr.setUserType("Legacy");
return lr;
} catch (IOException t) {
throw new AuthenticationException(t);
}
}
@Override
public String id() {
return "best";
}
@Override
public String getName() {
return "BestLogin";
}
@Override
public UserProfileProvider loginBySettings() {
return null;
}
@Override
public void logout() {
}
}
@@ -0,0 +1,105 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.auth;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jackhuang.hellominecraft.launcher.api.PluginManager;
/**
* Login interface
*
* @author huangyuhui
*/
public abstract class IAuthenticator {
public static final List<IAuthenticator> LOGINS = new ArrayList<>();
static {
PluginManager.NOW_PLUGIN.onRegisterAuthenticators(LOGINS::add);
}
protected String clientToken, username;
public IAuthenticator(String clientToken) {
this.clientToken = clientToken;
}
/**
* Login Method
*
* @param info username & password
*
* @return login result
*
* @throws
* org.jackhuang.hellominecraft.launcher.core.auth.AuthenticationException
*/
public abstract UserProfileProvider login(LoginInfo info) throws AuthenticationException;
public abstract String id();
/**
*
* @return the name of login method.
*/
public abstract String getName();
/**
* Has password?
*
* @return has password?
*/
public boolean hasPassword() {
return true;
}
public boolean isLoggedIn() {
return false;
}
public void setRememberMe(boolean is) {
}
public abstract UserProfileProvider loginBySettings() throws AuthenticationException;
public abstract void logout();
public Map onSaveSettings() {
HashMap m = new HashMap();
m.put("IAuthenticator_UserName", username);
return m;
}
public void onLoadSettings(Map m) {
if (m == null)
return;
username = (String) m.get("IAuthenticator_UserName");
}
public String getUsername() {
return username;
}
public void setUsername(String s) {
username = s;
}
}
@@ -1,20 +1,21 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.auth;
package org.jackhuang.hellominecraft.launcher.core.auth;
/**
*
@@ -0,0 +1,104 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.auth;
import java.util.HashMap;
import java.util.Map;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.utils.code.DigestUtils;
/**
*
* @author huangyuhui
*/
public final class OfflineAuthenticator extends IAuthenticator {
Map<String, String> uuidMap = new HashMap<>();
public OfflineAuthenticator(String clientToken) {
super(clientToken);
}
@Override
public void onLoadSettings(Map m) {
super.onLoadSettings(m);
if (m == null)
return;
Object o = m.get("uuidMap");
if (o != null && o instanceof Map)
uuidMap = (Map<String, String>) o;
}
@Override
public Map onSaveSettings() {
Map m = super.onSaveSettings();
m.put("uuidMap", m);
return m;
}
@Override
public UserProfileProvider login(LoginInfo info) throws AuthenticationException {
if (StrUtils.isBlank(info.username))
throw new AuthenticationException(C.i18n("login.no_Player007"));
UserProfileProvider result = new UserProfileProvider();
result.setUserName(info.username);
String uuid = getUUIDFromUserName(info.username);
if (uuidMap != null && uuidMap.containsKey(uuid))
uuid = uuidMap.get(info.username);
else {
if (uuidMap == null)
uuidMap = new HashMap<>();
uuidMap.put(info.username, uuid);
}
result.setSession(uuid);
result.setUserId(uuid);
result.setAccessToken(uuid);
result.setUserType("Legacy");
return result;
}
public static String getUUIDFromUserName(String str) {
return DigestUtils.md5Hex(str);
}
@Override
public String id() {
return "offline";
}
@Override
public String getName() {
return C.i18n("login.methods.offline");
}
@Override
public boolean hasPassword() {
return false;
}
@Override
public UserProfileProvider loginBySettings() {
return null;
}
@Override
public void logout() {
}
}
@@ -1,26 +1,26 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.auth;
package org.jackhuang.hellominecraft.launcher.core.auth;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.utils.code.DigestUtils;
import org.jackhuang.hellominecraft.utils.NetUtils;
import org.jackhuang.hellominecraft.views.Selector;
import org.jackhuang.hellominecraft.utils.views.Selector;
/**
*
@@ -37,22 +37,15 @@ public final class SkinmeAuthenticator extends IAuthenticator {
}
public String getCharacter(String user, String hash, String $char) throws Exception {
if ($char == null)
return NetUtils.doGet(
"http://www.skinme.cc/api/login.php?user=" + user + "&hash=" + hash);
else
return NetUtils.doGet(
"http://www.skinme.cc/api/login.php?user=" + user + "&hash=" + hash + "&char=" + $char);
return NetUtils.get(
"http://www.skinme.cc/api/login.php?user=" + user + "&hash=" + hash + (($char == null) ? "" : ("&char=" + $char)));
}
@Override
public UserProfileProvider login(LoginInfo info) {
public UserProfileProvider login(LoginInfo info) throws AuthenticationException {
UserProfileProvider req = new UserProfileProvider();
if (info.username == null || !info.username.contains("@")) {
req.setSuccess(false);
req.setErrorReason(C.i18n("login.not_email"));
return req;
}
if (info.username == null || !info.username.contains("@"))
throw new AuthenticationException(C.i18n("login.not_email"));
try {
String usr = info.username.toLowerCase();
String pwd = info.password;
@@ -61,16 +54,13 @@ public final class SkinmeAuthenticator extends IAuthenticator {
String hashCode = DigestUtils.sha1Hex(DigestUtils.md5Hex(DigestUtils.sha1Hex(pwd) + pwd) + str);
String data = getCharacter(usr, hashCode, null);
String[] sl = data.split(":");
if (null != sl[0]) switch (sl[0]) {
if (null != sl[0])
switch (sl[0]) {
case "0":
req.setSuccess(false);
if(sl[1].contains("No Valid Character")) {
if (sl[1].contains("No Valid Character"))
sl[1] = C.i18n("login.no_valid_character");
}
req.setErrorReason(sl[1]);
break;
throw new AuthenticationException(sl[1]);
case "1": {
req.setSuccess(true);
String[] s = parseType1(sl[1]);
req.setUserName(s[0]);
req.setSession(s[1]);
@@ -79,7 +69,6 @@ public final class SkinmeAuthenticator extends IAuthenticator {
break;
}
case "2": {
req.setSuccess(true);
String[] charators = sl[1].split(";");
int len = charators.length;
String[] $char = new String[len];
@@ -92,10 +81,9 @@ public final class SkinmeAuthenticator extends IAuthenticator {
}
Selector s = new Selector(null, user, C.i18n("login.choose_charactor"));
s.setVisible(true);
if (s.sel == Selector.failedToSel) {
req.setSuccess(false);
req.setErrorReason(C.i18n("message.cancelled"));
} else {
if (s.sel == Selector.FAILED_TO_SELECT)
throw new AuthenticationException(C.i18n("message.cancelled"));
else {
int index = s.sel;
String character = $char[index];
sl = getCharacter(usr, hashCode, character).split(":");
@@ -107,21 +95,20 @@ public final class SkinmeAuthenticator extends IAuthenticator {
}
break;
}
}
}
req.setUserType("Legacy");
return req;
} catch (Exception e) {
HMCLog.warn("Failed to login skinme.", e);
req.setUserName(info.username);
req.setSuccess(false);
req.setUserType("Legacy");
req.setErrorReason(e.getMessage());
return req;
throw new AuthenticationException(e);
}
}
@Override
public String id() {
return "skinme";
}
@Override
public String getName() {
return "Skinme";
@@ -1,20 +1,23 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.auth;
package org.jackhuang.hellominecraft.launcher.core.auth;
import org.jackhuang.hellominecraft.launcher.core.version.ServerInfo;
/**
*
@@ -51,25 +54,11 @@ public final class UserProfileProvider {
}
public void setAccessToken(String accessToken) {
if (accessToken == null)
accessToken = "0";
this.accessToken = accessToken;
}
public boolean isSuccessful() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getErrorReason() {
return error;
}
public void setErrorReason(String error) {
this.error = error;
}
public String getUserProperties() {
return userProperties;
}
@@ -114,11 +103,18 @@ public final class UserProfileProvider {
private String userId = "";
private String session = "";
private String accessToken = "";
private boolean success = false;
private String error = "";
private String userProperties = "{}";
private String userPropertyMap = "{}";
private String otherInfo = "";
private String clientIdentifier = "";
private String userType = "Offline";
private ServerInfo server = null;
public ServerInfo getServer() {
return server;
}
public void setServer(ServerInfo server) {
this.server = server;
}
}
@@ -0,0 +1,140 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.auth;
import com.google.gson.GsonBuilder;
import java.net.Proxy;
import java.util.Map;
import javax.swing.JOptionPane;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.utils.ArrayUtils;
import org.jackhuang.hellominecraft.utils.views.Selector;
import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.GameProfile;
import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.PropertyMap;
import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.YggdrasilAuthentication;
import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.UUIDTypeAdapter;
/**
*
* @author huangyuhui
*/
public final class YggdrasilAuthenticator extends IAuthenticator {
YggdrasilAuthentication ua;
public YggdrasilAuthenticator(String clientToken) {
super(clientToken);
ua = new YggdrasilAuthentication(Proxy.NO_PROXY, clientToken);
}
@Override
public UserProfileProvider login(LoginInfo info) throws AuthenticationException {
UserProfileProvider result = new UserProfileProvider();
result.setUserType("mojang");
if (ua.canPlayOnline()) {
result.setUserName(info.username);
result.setUserId(UUIDTypeAdapter.fromUUID(ua.getSelectedProfile().id));
} else {
String usr = info.username;
if (info.username == null || !info.username.contains("@"))
throw new AuthenticationException(C.i18n("login.not_email"));
String pwd = info.password;
if (!ua.isLoggedIn())
ua.setPassword(pwd);
ua.setUsername(usr);
ua.logIn();
if (!ua.isLoggedIn())
throw new AuthenticationException(C.i18n("login.wrong_password"));
GameProfile selectedProfile = ua.getSelectedProfile();
GameProfile[] profiles = ua.getAvailableProfiles();
String username;
if (selectedProfile == null)
if (ArrayUtils.isNotEmpty(profiles)) {
String[] names = new String[profiles.length];
for (int i = 0; i < profiles.length; i++)
names[i] = profiles[i].name;
Selector s = new Selector(null, names, C.i18n("login.choose_charactor"));
s.setVisible(true);
selectedProfile = profiles[s.sel];
username = names[s.sel];
} else
username = JOptionPane.showInputDialog(C.i18n("login.no_charactor"));
else
username = selectedProfile.name;
result.setUserName(username);
result.setUserId(selectedProfile == null ? OfflineAuthenticator.getUUIDFromUserName(username) : UUIDTypeAdapter.fromUUID(selectedProfile.id));
}
result.setUserProperties(new GsonBuilder().registerTypeAdapter(PropertyMap.class, new PropertyMap.LegacySerializer()).create().toJson(ua.getUserProperties()));
result.setUserPropertyMap(new GsonBuilder().registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create().toJson(ua.getUserProperties()));
result.setAccessToken(ua.getAuthenticatedToken());
result.setSession(ua.getAuthenticatedToken());
return result;
}
@Override
public boolean isLoggedIn() {
return ua.isLoggedIn();
}
@Override
public String id() {
return "yggdrasil";
}
@Override
public String getName() {
return C.i18n("login.methods.yggdrasil");
}
@Override
public Map onSaveSettings() {
Map m = ua.saveForStorage();
m.putAll(super.onSaveSettings());
return m;
}
@Override
public void onLoadSettings(Map settings) {
super.onLoadSettings(settings);
if (settings == null)
return;
ua.loadFromStorage(settings);
}
@Override
public UserProfileProvider loginBySettings() throws AuthenticationException {
UserProfileProvider result = new UserProfileProvider();
ua.logIn();
if (!ua.isLoggedIn())
throw new AuthenticationException(C.i18n("login.wrong_password"));
GameProfile profile = ua.getSelectedProfile();
result.setUserName(profile.name);
result.setUserId(profile.id.toString());
result.setUserProperties(new GsonBuilder().registerTypeAdapter(PropertyMap.class, new PropertyMap.LegacySerializer()).create().toJson(ua.getUserProperties()));
result.setUserPropertyMap(new GsonBuilder().registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create().toJson(ua.getUserProperties()));
result.setAccessToken(ua.getAuthenticatedToken());
result.setSession(ua.getAuthenticatedToken());
return result;
}
@Override
public void logout() {
ua.logOut();
}
}
@@ -0,0 +1,37 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil;
import java.util.HashMap;
public class AuthenticationRequest {
public HashMap<String, Object> agent;
public String username, password, clientToken;
public boolean requestUser = true;
public AuthenticationRequest(String username, String password, String clientToken) {
agent = new HashMap<>();
agent.put("name", "Minecraft");
agent.put("version", 1);
this.username = username;
this.password = password;
this.clientToken = clientToken;
}
}
@@ -0,0 +1,84 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import java.lang.reflect.Type;
import java.util.UUID;
import org.jackhuang.hellominecraft.utils.StrUtils;
public class GameProfile {
public final UUID id;
public final String name;
public final PropertyMap properties = new PropertyMap();
public GameProfile(UUID id, String name) {
if (id == null && StrUtils.isBlank(name))
throw new IllegalArgumentException("Name and ID cannot both be blank");
this.id = id;
this.name = name;
}
public boolean isComplete() {
return id != null && StrUtils.isNotBlank(name);
}
@Override
public boolean equals(Object o) {
System.out.println("hello?");
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
GameProfile that = (GameProfile) o;
if (id != null ? !id.equals(that.id) : that.id != null)
return false;
return name != null ? name.equals(that.name) : that.name == null;
}
public static class GameProfileSerializer implements JsonSerializer<GameProfile>, JsonDeserializer<GameProfile> {
@Override
public GameProfile deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject object = (JsonObject) json;
UUID id = object.has("id") ? (UUID) context.deserialize(object.get("id"), UUID.class) : null;
String name = object.has("name") ? object.getAsJsonPrimitive("name").getAsString() : null;
return new GameProfile(id, name);
}
@Override
public JsonElement serialize(GameProfile src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject result = new JsonObject();
if (src.id != null)
result.add("id", context.serialize(src.id));
if (src.name != null)
result.addProperty("name", src.name);
return result;
}
}
}
@@ -0,0 +1,28 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil;
public class Property {
public final String name, value;
public Property(String name, String value) {
this.name = name;
this.value = value;
}
}
@@ -0,0 +1,112 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
public class PropertyMap extends HashMap<String, Property> {
public List<Map<String, String>> list() {
List<Map<String, String>> properties = new ArrayList<>();
for (Property profileProperty : values()) {
Map<String, String> property = new HashMap<>();
property.put("name", profileProperty.name);
property.put("value", profileProperty.value);
properties.add(property);
}
return properties;
}
public void fromList(List<Map<String, String>> list) {
try {
for (Map<String, String> propertyMap : list) {
String name = propertyMap.get("name");
String value = propertyMap.get("value");
}
} catch (Throwable t) {
HMCLog.warn("Failed to deserialize properties", t);
}
}
public static class Serializer implements JsonSerializer<PropertyMap>, JsonDeserializer<PropertyMap> {
@Override
public PropertyMap deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
PropertyMap result = new PropertyMap();
if ((json instanceof JsonObject)) {
JsonObject object = (JsonObject) json;
for (Map.Entry<String, JsonElement> entry : object.entrySet())
if (entry.getValue() instanceof JsonArray)
for (JsonElement element : (JsonArray) entry.getValue())
result.put(entry.getKey(),
new Property((String) entry.getKey(), element.getAsString()));
} else if ((json instanceof JsonArray))
for (JsonElement element : (JsonArray) json)
if ((element instanceof JsonObject)) {
JsonObject object = (JsonObject) element;
String name = object.getAsJsonPrimitive("name").getAsString();
String value = object.getAsJsonPrimitive("value").getAsString();
}
return result;
}
@Override
public JsonElement serialize(PropertyMap src, Type typeOfSrc, JsonSerializationContext context) {
JsonArray result = new JsonArray();
for (Property property : src.values()) {
JsonObject object = new JsonObject();
object.addProperty("name", property.name);
object.addProperty("value", property.value);
result.add(object);
}
return result;
}
}
public static class LegacySerializer
implements JsonSerializer<PropertyMap> {
@Override
public JsonElement serialize(PropertyMap src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject result = new JsonObject();
for (String key : src.keySet()) {
JsonArray values = new JsonArray();
values.add(new JsonPrimitive(src.get(key).value));
result.add(key, values);
}
return result;
}
}
}
@@ -0,0 +1,31 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil;
public class RefreshRequest {
public String clientToken;
public String accessToken;
public GameProfile selectedProfile;
public boolean requestUser = true;
public RefreshRequest(String accessToken, String clientToken) {
this.clientToken = clientToken;
this.accessToken = accessToken;
}
}
@@ -0,0 +1,30 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil;
public class Response {
public String accessToken, clientToken;
public GameProfile selectedProfile;
public GameProfile[] availableProfiles;
public User user;
public String error;
public String errorMessage;
public String cause;
}
@@ -0,0 +1,45 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.util.UUID;
public class UUIDTypeAdapter extends TypeAdapter<UUID> {
@Override
public void write(JsonWriter out, UUID value) throws IOException {
out.value(fromUUID(value));
}
@Override
public UUID read(JsonReader in) throws IOException {
return fromString(in.nextString());
}
public static String fromUUID(UUID value) {
return value.toString().replace("-", "");
}
public static UUID fromString(String input) {
return UUID.fromString(input.replaceFirst("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5"));
}
}
@@ -0,0 +1,24 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil;
public class User {
public String id;
public PropertyMap properties;
}
@@ -0,0 +1,231 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil;
import org.jackhuang.hellominecraft.launcher.core.auth.AuthenticationException;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import java.io.IOException;
import java.net.Proxy;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
import org.jackhuang.hellominecraft.utils.NetUtils;
import org.jackhuang.hellominecraft.utils.StrUtils;
public class YggdrasilAuthentication {
public static final Gson GSON = new GsonBuilder()
.registerTypeAdapter(GameProfile.class, new GameProfile.GameProfileSerializer())
.registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer())
.registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
protected static final String BASE_URL = "https://authserver.mojang.com/";
protected static final URL ROUTE_AUTHENTICATE = NetUtils.constantURL(BASE_URL + "authenticate");
protected static final URL ROUTE_REFRESH = NetUtils.constantURL(BASE_URL + "refresh");
protected static final String STORAGE_KEY_ACCESS_TOKEN = "accessToken";
protected static final String STORAGE_KEY_PROFILE_NAME = "displayName";
protected static final String STORAGE_KEY_PROFILE_ID = "uuid";
protected static final String STORAGE_KEY_PROFILE_PROPERTIES = "profileProperties";
protected static final String STORAGE_KEY_USER_NAME = "username";
protected static final String STORAGE_KEY_USER_ID = "userid";
protected static final String STORAGE_KEY_USER_PROPERTIES = "userProperties";
private final Proxy proxy;
private final String clientToken;
private final PropertyMap userProperties = new PropertyMap();
private String userid, username, password, accessToken;
private GameProfile selectedProfile;
private GameProfile[] profiles;
private boolean isOnline;
public YggdrasilAuthentication(Proxy proxy, String clientToken) {
this.proxy = proxy;
this.clientToken = clientToken;
}
// <editor-fold defaultstate="collapsed" desc="Get/Set">
public void setUsername(String username) {
if ((isLoggedIn()) && (canPlayOnline()))
throw new IllegalStateException("Cannot change username while logged in & online");
this.username = username;
}
public void setPassword(String password) {
if ((isLoggedIn()) && (canPlayOnline()) && (StrUtils.isNotBlank(password)))
throw new IllegalStateException("Cannot set password while logged in & online");
this.password = password;
}
public GameProfile getSelectedProfile() {
return this.selectedProfile;
}
public String getUserId() {
return this.userid;
}
public PropertyMap getUserProperties() {
if (isLoggedIn())
return (PropertyMap) userProperties.clone();
return new PropertyMap();
}
public GameProfile[] getAvailableProfiles() {
return profiles;
}
public String getAuthenticatedToken() {
return this.accessToken;
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Log In/Out">
public boolean canPlayOnline() {
return isLoggedIn() && getSelectedProfile() != null && this.isOnline;
}
public boolean canLogIn() {
return !canPlayOnline() && StrUtils.isNotBlank(username) && (StrUtils.isNotBlank(password) || StrUtils.isNotBlank(getAuthenticatedToken()));
}
public boolean isLoggedIn() {
return StrUtils.isNotBlank(this.accessToken);
}
public void logIn() throws AuthenticationException {
if (StrUtils.isBlank(username))
throw new AuthenticationException(C.i18n("login.invalid_username"));
if (StrUtils.isNotBlank(getAuthenticatedToken())) {
if (StrUtils.isBlank(getUserId()))
if (StrUtils.isBlank(username))
userid = username;
else
throw new AuthenticationException(C.i18n("login.invalid_uuid_and_username"));
loggedIn(ROUTE_REFRESH, new RefreshRequest(getAuthenticatedToken(), clientToken));
} else if (StrUtils.isNotBlank(password))
loggedIn(ROUTE_AUTHENTICATE, new AuthenticationRequest(username, password, clientToken));
else
throw new AuthenticationException(C.i18n("login.invalid_password"));
}
private void loggedIn(URL url, Object input) throws AuthenticationException {
try {
String jsonResult = input == null ? NetUtils.get(url) : NetUtils.post(url, GSON.toJson(input), "application/json", proxy);
Response response = (Response) GSON.fromJson(jsonResult, Response.class);
if (StrUtils.isNotBlank(response.error)) {
HMCLog.err("Failed to log in, the auth server returned an error: " + response.error + ", message: " + response.errorMessage + ", cause: " + response.cause);
if (response.errorMessage.contains("Invalid token"))
response.errorMessage = C.i18n("login.invalid_token");
throw new AuthenticationException("Request error: " + response.errorMessage);
}
if (!clientToken.equals(response.clientToken))
throw new AuthenticationException(C.i18n("login.changed_client_token"));
User user = response.user;
userid = user != null && user.id != null ? user.id : username;
isOnline = true;
profiles = response.availableProfiles;
selectedProfile = response.selectedProfile;
userProperties.clear();
this.accessToken = response.accessToken;
if (user != null && user.properties != null)
userProperties.putAll(user.properties);
} catch (IOException | IllegalStateException | JsonParseException e) {
throw new AuthenticationException(C.i18n("login.failed.connect_authentication_server"), e);
}
}
public void logOut() {
password = null;
userid = null;
selectedProfile = null;
userProperties.clear();
accessToken = null;
profiles = null;
isOnline = false;
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Settings Storage">
public void loadFromStorage(Map<String, Object> credentials) {
logOut();
setUsername((String) credentials.get(STORAGE_KEY_USER_NAME));
if (credentials.containsKey(STORAGE_KEY_USER_ID))
userid = (String) credentials.get(STORAGE_KEY_USER_ID);
else
userid = username;
if (credentials.containsKey(STORAGE_KEY_USER_PROPERTIES))
userProperties.fromList((List<Map<String, String>>) credentials.get(STORAGE_KEY_USER_PROPERTIES));
if ((credentials.containsKey(STORAGE_KEY_PROFILE_NAME)) && (credentials.containsKey(STORAGE_KEY_PROFILE_ID))) {
GameProfile profile = new GameProfile(UUIDTypeAdapter.fromString((String) credentials.get(STORAGE_KEY_PROFILE_ID)), (String) credentials.get(STORAGE_KEY_PROFILE_NAME));
if (credentials.containsKey(STORAGE_KEY_PROFILE_PROPERTIES))
profile.properties.fromList((List<Map<String, String>>) credentials.get(STORAGE_KEY_PROFILE_PROPERTIES));
selectedProfile = profile;
}
this.accessToken = (String) credentials.get(STORAGE_KEY_ACCESS_TOKEN);
}
public Map<String, Object> saveForStorage() {
Map<String, Object> result = new HashMap<>();
if (username != null)
result.put(STORAGE_KEY_USER_NAME, username);
if (getUserId() != null)
result.put(STORAGE_KEY_USER_ID, getUserId());
if (!getUserProperties().isEmpty())
result.put(STORAGE_KEY_USER_PROPERTIES, getUserProperties().list());
GameProfile sel = getSelectedProfile();
if (sel != null) {
result.put(STORAGE_KEY_PROFILE_NAME, sel.name);
result.put(STORAGE_KEY_PROFILE_ID, sel.id);
if (!sel.properties.isEmpty())
result.put(STORAGE_KEY_PROFILE_PROPERTIES, sel.properties.list());
}
if (StrUtils.isNotBlank(getAuthenticatedToken()))
result.put(STORAGE_KEY_ACCESS_TOKEN, getAuthenticatedToken());
return result;
}
// </editor-fold>
}
@@ -1,50 +1,43 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.download;
package org.jackhuang.hellominecraft.launcher.core.download;
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionList;
/**
*
* @author huangyuhui
*/
public class BMCLAPIDownloadProvider implements IDownloadProvider {
public class BMCLAPIDownloadProvider extends IDownloadProvider {
@Override
public InstallerVersionList getForgeInstaller() {
return org.jackhuang.hellominecraft.launcher.utils.installers.forge.bmcl.ForgeBMCLVersionList.getInstance();
return org.jackhuang.hellominecraft.launcher.core.installers.forge.MinecraftForgeVersionList.getInstance();
}
@Override
public InstallerVersionList getLiteLoaderInstaller() {
return org.jackhuang.hellominecraft.launcher.utils.installers.liteloader.LiteLoaderVersionList.getInstance();
return org.jackhuang.hellominecraft.launcher.core.installers.liteloader.LiteLoaderVersionList.getInstance();
}
@Override
public InstallerVersionList getOptiFineInstaller() {
return org.jackhuang.hellominecraft.launcher.utils.installers.optifine.bmcl.OptiFineBMCLVersionList.getInstance();
}
@Override
public InstallerVersionList getInstallerByType(String type) {
if (type.equalsIgnoreCase("forge")) return getForgeInstaller();
if (type.equalsIgnoreCase("liteloader")) return getLiteLoaderInstaller();
if (type.equalsIgnoreCase("optifine")) return getOptiFineInstaller();
return null;
return org.jackhuang.hellominecraft.launcher.core.installers.optifine.bmcl.OptiFineBMCLVersionList.getInstance();
}
@Override
@@ -74,7 +67,7 @@ public class BMCLAPIDownloadProvider implements IDownloadProvider {
@Override
public String getParsedLibraryDownloadURL(String str) {
return str.replace("http://files.minecraftforge.net/maven", "http://bmclapi2.bangbang93.com/maven");
return str == null ? null : str.replace("http://files.minecraftforge.net/maven", "http://bmclapi2.bangbang93.com/maven");
}
@Override
@@ -0,0 +1,31 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.download;
/**
*
* @author huangyuhui
*/
public class CurseDownloadProvider extends MojangDownloadProvider {
@Override
public String getParsedLibraryDownloadURL(String str) {
return str == null ? null : str.replace("http://files.minecraftforge.net/maven", "http://ftb.cursecdn.com/FTB2/maven/");
}
}
@@ -0,0 +1,37 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.download;
import java.io.File;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
/**
*
* @author huangyuhui
*/
public class DownloadLibraryJob {
public String url, name;
public File path;
public DownloadLibraryJob(String n, String u, File p) {
url = u;
name = n;
path = IOUtils.tryGetCanonicalFile(p);
}
}
@@ -0,0 +1,61 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.download;
import org.jackhuang.hellominecraft.utils.C;
/**
*
* @author huangyuhui
*/
public enum DownloadType {
Mojang(C.i18n("download.mojang"), new MojangDownloadProvider()),
BMCL(C.i18n("download.BMCL"), new BMCLAPIDownloadProvider()),
RapidData(C.i18n("download.rapid_data"), new RapidDataDownloadProvider()),
Curse("Curse CDN", new CurseDownloadProvider());
private final String name;
private final IDownloadProvider provider;
DownloadType(String a, IDownloadProvider provider) {
name = a;
this.provider = provider;
}
public IDownloadProvider getProvider() {
return provider;
}
public String getName() {
return name;
}
private static DownloadType suggestedDownloadType = Mojang;
public static DownloadType getSuggestedDownloadType() {
return suggestedDownloadType;
}
public static void setSuggestedDownloadType(DownloadType suggestedDownloadType) {
if (suggestedDownloadType == null)
throw new IllegalArgumentException("download type should not be null.");
DownloadType.suggestedDownloadType = suggestedDownloadType;
}
}
@@ -0,0 +1,61 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.download;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerType;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionList;
/**
*
* @author huangyuhui
*/
public abstract class IDownloadProvider {
public InstallerVersionList getInstallerByType(InstallerType type) {
switch (type) {
case Forge:
return getForgeInstaller();
case LiteLoader:
return getLiteLoaderInstaller();
case Optifine:
return getOptiFineInstaller();
default:
return null;
}
}
public abstract InstallerVersionList getForgeInstaller();
public abstract InstallerVersionList getLiteLoaderInstaller();
public abstract InstallerVersionList getOptiFineInstaller();
public abstract String getLibraryDownloadURL();
public abstract String getVersionsDownloadURL();
public abstract String getIndexesDownloadURL();
public abstract String getVersionsListDownloadURL();
public abstract String getAssetsDownloadURL();
public abstract String getParsedLibraryDownloadURL(String str);
public abstract boolean isAllowedToUseSelfURL();
}
@@ -0,0 +1,166 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.download;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftDownloadService;
import com.google.gson.JsonSyntaxException;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.version.IMinecraftLibrary;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.utils.tasks.TaskWindow;
import org.jackhuang.hellominecraft.utils.tasks.download.FileDownloadTask;
import org.jackhuang.hellominecraft.utils.NetUtils;
import org.jackhuang.hellominecraft.utils.system.FileUtils;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
import org.jackhuang.hellominecraft.utils.version.MinecraftRemoteVersion;
import org.jackhuang.hellominecraft.utils.version.MinecraftRemoteVersions;
import rx.Observable;
/**
*
* @author huangyuhui
*/
public class MinecraftDownloadService extends IMinecraftDownloadService {
public MinecraftDownloadService(IMinecraftService service) {
super(service);
}
@Override
public List<DownloadLibraryJob> getDownloadLibraries(MinecraftVersion mv) throws GameException {
ArrayList<DownloadLibraryJob> downloadLibraries = new ArrayList<>();
if (mv == null)
return downloadLibraries;
MinecraftVersion v = mv.resolve(service.version());
if (v.libraries != null)
for (IMinecraftLibrary l : v.libraries) {
l.init();
if (l.allow()) {
File ff = l.getFilePath(service.baseDirectory());
if (!ff.exists()) {
String libURL = service.getDownloadType().getProvider().getLibraryDownloadURL() + "/";
libURL = service.getDownloadType().getProvider().getParsedLibraryDownloadURL(l.getDownloadURL(libURL, service.getDownloadType()));
if (libURL != null)
downloadLibraries.add(new DownloadLibraryJob(l.name, libURL, ff));
}
}
}
return downloadLibraries;
}
@Override
public MinecraftVersion downloadMinecraft(String id) {
String vurl = service.getDownloadType().getProvider().getVersionsDownloadURL() + id + "/";
File vpath = new File(service.baseDirectory(), "versions/" + id);
File mvt = new File(vpath, id + ".json");
File mvj = new File(vpath, id + ".jar");
vpath.mkdirs();
mvt.delete();
mvj.delete();
if (TaskWindow.getInstance()
.addTask(new FileDownloadTask(vurl + id + ".json", IOUtils.tryGetCanonicalFile(mvt)).setTag(id + ".json"))
.addTask(new FileDownloadTask(vurl + id + ".jar", IOUtils.tryGetCanonicalFile(mvj)).setTag(id + ".jar"))
.start())
try {
return C.gson.fromJson(FileUtils.readFileToStringQuietly(mvt), MinecraftVersion.class);
} catch (JsonSyntaxException ex) {
HMCLog.err("Failed to parse minecraft version json.", ex);
}
else
FileUtils.deleteDirectoryQuietly(vpath);
return null;
}
@Override
public boolean downloadMinecraftJar(String id) {
String vurl = service.getDownloadType().getProvider().getVersionsDownloadURL() + id + "/";
File vpath = new File(service.baseDirectory(), "versions/" + id);
File mvv = new File(vpath, id + ".jar"), moved = null;
if (mvv.exists()) {
moved = new File(vpath, id + "-renamed.jar");
mvv.renameTo(moved);
}
File mvt = new File(vpath, id + ".jar");
vpath.mkdirs();
if (TaskWindow.getInstance()
.addTask(new FileDownloadTask(vurl + id + ".jar", IOUtils.tryGetCanonicalFile(mvt)).setTag(id + ".jar"))
.start()) {
if (moved != null)
moved.delete();
return true;
} else {
mvt.delete();
if (moved != null)
moved.renameTo(mvt);
return false;
}
}
@Override
public boolean downloadMinecraftJarTo(String id, File mvt) {
String vurl = service.getDownloadType().getProvider().getVersionsDownloadURL() + id + "/";
if (TaskWindow.getInstance()
.addTask(new FileDownloadTask(vurl + id + ".jar", IOUtils.tryGetCanonicalFile(mvt)).setTag(id + ".jar"))
.start())
return true;
else {
mvt.delete();
return false;
}
}
@Override
public boolean downloadMinecraftVersionJson(String id) {
String vurl = service.getDownloadType().getProvider().getVersionsDownloadURL() + id + "/";
File vpath = new File(service.baseDirectory(), "versions/" + id);
File mvv = new File(vpath, id + ".json"), moved = null;
if (mvv.exists()) {
moved = new File(vpath, id + "-renamed.json");
mvv.renameTo(moved);
}
File mvt = new File(vpath, id + ".json");
vpath.mkdirs();
if (TaskWindow.getInstance()
.addTask(new FileDownloadTask(vurl + id + ".json", IOUtils.tryGetCanonicalFile(mvt)).setTag(id + ".json"))
.start()) {
if (moved != null)
moved.delete();
return true;
} else {
mvt.delete();
if (moved != null)
moved.renameTo(mvt);
return false;
}
}
@Override
public Observable<MinecraftRemoteVersion> getRemoteVersions() {
return NetUtils.getRx(service.getDownloadType().getProvider().getVersionsListDownloadURL())
.map(r -> C.gson.fromJson(r, MinecraftRemoteVersions.class))
.filter(r -> r != null && r.versions != null)
.flatMap(r -> Observable.from(r.versions));
}
}
@@ -1,50 +1,43 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.download;
package org.jackhuang.hellominecraft.launcher.core.download;
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionList;
/**
*
* @author huangyuhui
*/
public class MojangDownloadProvider implements IDownloadProvider {
public class MojangDownloadProvider extends IDownloadProvider {
@Override
public InstallerVersionList getForgeInstaller() {
return org.jackhuang.hellominecraft.launcher.utils.installers.forge.vanilla.MinecraftForgeVersionList.getInstance();
return org.jackhuang.hellominecraft.launcher.core.installers.forge.MinecraftForgeVersionList.getInstance();
}
@Override
public InstallerVersionList getLiteLoaderInstaller() {
return org.jackhuang.hellominecraft.launcher.utils.installers.liteloader.LiteLoaderVersionList.getInstance();
return org.jackhuang.hellominecraft.launcher.core.installers.liteloader.LiteLoaderVersionList.getInstance();
}
@Override
public InstallerVersionList getOptiFineInstaller() {
return org.jackhuang.hellominecraft.launcher.utils.installers.optifine.vanilla.OptiFineVersionList.getInstance();
}
@Override
public InstallerVersionList getInstallerByType(String type) {
if (type.equalsIgnoreCase("forge")) return getForgeInstaller();
if (type.equalsIgnoreCase("liteloader")) return getLiteLoaderInstaller();
if (type.equalsIgnoreCase("optifine")) return getOptiFineInstaller();
return null;
return org.jackhuang.hellominecraft.launcher.core.installers.optifine.vanilla.OptiFineVersionList.getInstance();
}
@Override
@@ -0,0 +1,56 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.download;
/**
*
* @author huangyuhui
*/
public class RapidDataDownloadProvider extends MojangDownloadProvider {
@Override
public String getAssetsDownloadURL() {
return "http://mirrors.rapiddata.org/resources.download.minecraft.net/";
}
@Override
public String getLibraryDownloadURL() {
return "http://mirrors.rapiddata.org/libraries.minecraft.net";
}
@Override
public String getIndexesDownloadURL() {
return "http://mirrors.rapiddata.org/Minecraft.Download/indexes/";
}
@Override
public String getVersionsDownloadURL() {
return "http://mirrors.rapiddata.org/Minecraft.Download/versions/";
}
@Override
public String getVersionsListDownloadURL() {
return "http://mirrors.rapiddata.org/Minecraft.Download/versions/versions.json";
}
@Override
public String getParsedLibraryDownloadURL(String str) {
return str == null ? null : str.replace("http://files.minecraftforge.net/maven", "http://mirrors.rapiddata.org/forge/maven");
}
}
@@ -1,24 +1,25 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.installers;
package org.jackhuang.hellominecraft.launcher.core.installers;
import com.google.gson.annotations.SerializedName;
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
import org.jackhuang.hellominecraft.launcher.utils.installers.forge.Install;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.launcher.core.installers.forge.Install;
/**
*
@@ -0,0 +1,36 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.installers;
/**
*
* @author huangyuhui
*/
public enum InstallerType {
Forge("forge"), Optifine("optifine"), LiteLoader("liteloader");
public final String id;
private InstallerType(String id) {
this.id = id;
}
public String getLocalizedName() {
return this.name();
}
}
@@ -1,21 +1,23 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.installers;
package org.jackhuang.hellominecraft.launcher.core.installers;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import org.jackhuang.hellominecraft.utils.functions.Consumer;
@@ -30,13 +32,42 @@ public abstract class InstallerVersionList implements Consumer<String[]> {
* Refresh installer versions list from the downloaded content.
*
* @param versions Minecraft versions you need to refresh
* @throws java.lang.Exception
*
* @throws java.lang.Exception including network exceptions, IO exceptions.
*/
public abstract void refreshList(String[] versions) throws Exception;
/**
* Installer name.
*
* @return installer name.
*/
public abstract String getName();
public abstract List<InstallerVersion> getVersions(String mcVersion);
/**
* Get installers you want.
*
* @param mcVersion the installers to this Minecraft version.
*
* @return cached result.
*/
protected abstract List<InstallerVersion> getVersionsImpl(String mcVersion);
/**
* Get installers you want, please cache this method's result to save time.
*
* @param mcVersion the installers to this Minecraft version.
*
* @return a copy of the cached data to prevent
* ConcurrentModificationException.
*/
public List<InstallerVersion> getVersions(String mcVersion) {
List<InstallerVersion> a = getVersionsImpl(mcVersion);
if (a == null)
return null;
else
return new ArrayList<>(a);
}
public static class InstallerVersion implements Comparable<InstallerVersion> {
@@ -1,23 +1,24 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.installers;
package org.jackhuang.hellominecraft.launcher.core.installers;
import java.util.Comparator;
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList.InstallerVersion;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionList.InstallerVersion;
/**
*
@@ -0,0 +1,104 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.installers;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftInstallerService;
import java.io.File;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionList.InstallerVersion;
import org.jackhuang.hellominecraft.launcher.core.installers.forge.ForgeInstaller;
import org.jackhuang.hellominecraft.launcher.core.installers.liteloader.LiteLoaderInstaller;
import org.jackhuang.hellominecraft.launcher.core.installers.liteloader.LiteLoaderVersionList;
import org.jackhuang.hellominecraft.launcher.core.installers.optifine.OptiFineInstaller;
import org.jackhuang.hellominecraft.launcher.core.installers.optifine.vanilla.OptiFineDownloadFormatter;
import org.jackhuang.hellominecraft.utils.tasks.Task;
import org.jackhuang.hellominecraft.utils.tasks.TaskInfo;
import org.jackhuang.hellominecraft.utils.tasks.TaskWindow;
import org.jackhuang.hellominecraft.utils.tasks.download.FileDownloadTask;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
/**
*
* @author huangyuhui
*/
public final class MinecraftInstallerService extends IMinecraftInstallerService {
public MinecraftInstallerService(IMinecraftService service) {
super(service);
}
@Override
public Task download(String installId, InstallerVersion v, InstallerType type) {
switch (type) {
case Forge:
return downloadForge(installId, v);
case Optifine:
return downloadOptifine(installId, v);
case LiteLoader:
return downloadLiteLoader(installId, v);
default:
return null;
}
}
@Override
public Task downloadForge(String installId, InstallerVersion v) {
return new TaskInfo("Forge Downloader") {
@Override
public void executeTask() {
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "forge-installer.jar");
if (v.installer != null)
TaskWindow.getInstance()
.addTask(new FileDownloadTask(service.getDownloadType().getProvider().getParsedLibraryDownloadURL(v.installer), filepath).setTag("forge"))
.addTask(new ForgeInstaller(service, filepath, v))
.start();
}
};
}
@Override
public Task downloadOptifine(String installId, InstallerVersion v) {
return new TaskInfo("OptiFine Downloader") {
@Override
public void executeTask() {
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "optifine-installer.jar");
if (v.installer != null) {
OptiFineDownloadFormatter task = new OptiFineDownloadFormatter(v.installer);
TaskWindow.getInstance().addTask(task)
.addTask(new FileDownloadTask(filepath).registerPreviousResult(task).setTag("optifine"))
.addTask(new OptiFineInstaller(service, installId, v, filepath))
.start();
}
}
};
}
@Override
public Task downloadLiteLoader(String installId, InstallerVersion v) {
return new TaskInfo("LiteLoader Downloader") {
@Override
public void executeTask() {
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "liteloader-universal.jar");
FileDownloadTask task = (FileDownloadTask) new FileDownloadTask(v.universal, filepath).setTag("LiteLoader");
TaskWindow.getInstance()
.addTask(task).addTask(new LiteLoaderInstaller(service, installId, (LiteLoaderVersionList.LiteLoaderInstallerVersion) v).registerPreviousResult(task))
.start();
}
};
}
}
@@ -1,20 +1,21 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.installers;
package org.jackhuang.hellominecraft.launcher.core.installers;
import java.io.File;
import java.io.IOException;
@@ -40,8 +41,9 @@ public class PackMinecraftInstaller {
public void install() throws IOException {
File file = new File(IOUtils.currentDir(), "HMCL-MERGE-TEMP");
file.mkdirs();
for (String src1 : src) Compressor.unzip(new File(src1), file);
Compressor.zip(file, dest);
for (String src1 : src)
Compressor.unzip(new File(src1), file);
Compressor.zip(file.getAbsolutePath(), dest.getAbsolutePath());
FileUtils.deleteDirectory(file);
}
}
@@ -0,0 +1,107 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.installers.forge;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallProfile;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionList.InstallerVersion;
import org.jackhuang.hellominecraft.utils.tasks.Task;
import org.jackhuang.hellominecraft.utils.system.FileUtils;
import org.jackhuang.hellominecraft.utils.NetUtils;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
import org.jackhuang.hellominecraft.utils.MessageBox;
/**
*
* @author huangyuhui
*/
public class ForgeInstaller extends Task {
public File gameDir;
public File forgeInstaller;
public IMinecraftService mp;
public InstallerVersion installerVersion;
public ForgeInstaller(IMinecraftService mp, File forgeInstaller, InstallerVersion installerVersion) {
this.gameDir = mp.baseDirectory();
this.forgeInstaller = forgeInstaller;
this.mp = mp;
this.installerVersion = installerVersion;
}
@Override
public void executeTask() throws Exception {
HMCLog.log("Extracting install profiles...");
ZipFile zipFile = new ZipFile(forgeInstaller);
ZipEntry entry = zipFile.getEntry("install_profile.json");
String content = NetUtils.getStreamContent(zipFile.getInputStream(entry));
InstallProfile profile = C.gsonPrettyPrinting.fromJson(content, InstallProfile.class);
File from = new File(gameDir, "versions" + File.separator + profile.install.minecraft);
if (!from.exists())
if (MessageBox.Show(C.i18n("install.no_version_if_intall")) == MessageBox.YES_OPTION) {
if (!mp.version().install(profile.install.minecraft, null))
throw new IllegalStateException(C.i18n("install.no_version"));
} else
throw new IllegalStateException(C.i18n("install.no_version"));
File to = new File(gameDir, "versions" + File.separator + profile.install.target);
to.mkdirs();
HMCLog.log("Copying jar..." + profile.install.minecraft + ".jar to " + profile.install.target + ".jar");
FileUtils.copyFile(new File(from, profile.install.minecraft + ".jar"),
new File(to, profile.install.target + ".jar"));
HMCLog.log("Creating new version profile..." + profile.install.target + ".json");
/*
* for (MinecraftLibrary library : profile.versionInfo.libraries)
* if (library.name.startsWith("net.minecraftforge:forge:"))
* library.url = installerVersion.universal;
*/
FileUtils.write(new File(to, profile.install.target + ".json"), C.gsonPrettyPrinting.toJson(profile.versionInfo));
HMCLog.log("Extracting universal forge pack..." + profile.install.filePath);
entry = zipFile.getEntry(profile.install.filePath);
InputStream is = zipFile.getInputStream(entry);
MinecraftLibrary forge = new MinecraftLibrary(profile.install.path);
forge.init();
File file = new File(gameDir, "libraries/" + forge.formatted);
file.getParentFile().mkdirs();
try (FileOutputStream fos = new FileOutputStream(file); BufferedOutputStream bos = new BufferedOutputStream(fos)) {
int c;
while ((c = is.read()) != -1)
bos.write((byte) c);
}
}
@Override
public String getInfo() {
return C.i18n("install.forge.install");
}
}
@@ -1,25 +1,26 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.installers.forge;
package org.jackhuang.hellominecraft.launcher.core.installers.forge;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.jackhuang.hellominecraft.launcher.utils.installers.PackMinecraftInstaller;
import org.jackhuang.hellominecraft.launcher.core.installers.PackMinecraftInstaller;
/**
*
@@ -1,20 +1,21 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.installers.forge;
package org.jackhuang.hellominecraft.launcher.core.installers.forge;
/**
*
@@ -1,20 +1,21 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.installers.forge.vanilla;
package org.jackhuang.hellominecraft.launcher.core.installers.forge;
/**
*
@@ -1,30 +1,32 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.installers.forge.vanilla;
package org.jackhuang.hellominecraft.launcher.core.installers.forge;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList;
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionNewerComparator;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionList;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionNewerComparator;
import org.jackhuang.hellominecraft.utils.NetUtils;
/**
@@ -47,8 +49,9 @@ public class MinecraftForgeVersionList extends InstallerVersionList {
@Override
public void refreshList(String[] needed) throws Exception {
String s = NetUtils.doGet(C.URL_FORGE_LIST);
if (root != null) return;
if (root != null)
return;
String s = NetUtils.get(DownloadType.getSuggestedDownloadType().getProvider().getParsedLibraryDownloadURL(C.URL_FORGE_LIST));
root = C.gson.fromJson(s, MinecraftForgeVersionRoot.class);
@@ -67,17 +70,17 @@ public class MinecraftForgeVersionList extends InstallerVersionList {
if (!StrUtils.isBlank(v.branch))
ver = ver + "-" + v.branch;
String filename = root.artifact + "-" + ver + "-" + f[1] + "." + f[0];
String url = root.webpath + ver + "/" + filename;
String url = DownloadType.getSuggestedDownloadType().getProvider().getParsedLibraryDownloadURL(root.webpath + ver + "/" + filename);
switch (f[1]) {
case "installer":
iv.installer = url;
break;
case "universal":
iv.universal = url;
break;
case "changelog":
iv.changelog = url;
break;
case "installer":
iv.installer = url;
break;
case "universal":
iv.universal = url;
break;
case "changelog":
iv.changelog = url;
break;
}
}
if (StrUtils.isBlank(iv.installer) || StrUtils.isBlank(iv.universal))
@@ -94,11 +97,14 @@ public class MinecraftForgeVersionList extends InstallerVersionList {
}
@Override
public List<InstallerVersion> getVersions(String mcVersion) {
if (versions == null || versionMap == null) return null;
if (StrUtils.isBlank(mcVersion)) return versions;
public List<InstallerVersion> getVersionsImpl(String mcVersion) {
if (versions == null || versionMap == null)
return null;
if (StrUtils.isBlank(mcVersion))
return versions;
List c = versionMap.get(mcVersion);
if (c == null) return versions;
if (c == null)
return versions;
Collections.sort(c, InstallerVersionComparator.INSTANCE);
return c;
}
@@ -1,20 +1,21 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.installers.forge.vanilla;
package org.jackhuang.hellominecraft.launcher.core.installers.forge;
import java.util.Map;
@@ -0,0 +1,97 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.installers.liteloader;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.utils.tasks.Task;
import org.jackhuang.hellominecraft.utils.tasks.communication.PreviousResult;
import org.jackhuang.hellominecraft.utils.tasks.communication.PreviousResultRegistrar;
import org.jackhuang.hellominecraft.utils.system.FileUtils;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
/**
*
* @author huangyuhui
*/
public class LiteLoaderInstaller extends Task implements PreviousResultRegistrar<File> {
public LiteLoaderVersionList.LiteLoaderInstallerVersion version;
public File installer;
public String installId;
public IMinecraftService service;
public LiteLoaderInstaller(IMinecraftService service, String installId, LiteLoaderVersionList.LiteLoaderInstallerVersion v) {
this(service, installId, v, null);
}
public LiteLoaderInstaller(IMinecraftService service, String installId, LiteLoaderVersionList.LiteLoaderInstallerVersion v, File installer) {
this.service = service;
this.installId = installId;
this.version = v;
this.installer = installer;
}
@Override
public void executeTask() throws Exception {
if (installId == null)
throw new IllegalStateException(C.i18n("install.no_version"));
if (pre.size() != 1 && installer == null)
throw new IllegalStateException("No registered previous task.");
if (installer == null)
installer = pre.get(pre.size() - 1).getResult();
MinecraftVersion mv = (MinecraftVersion) service.version().getVersionById(installId).clone();
mv.inheritsFrom = mv.id;
mv.jar = mv.jar == null ? mv.id : mv.jar;
mv.libraries = new ArrayList(Arrays.asList(version.libraries));
MinecraftLibrary ml = new MinecraftLibrary("com.mumfrey:liteloader:" + version.selfVersion);
//ml.url = "http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + version.mcVersion + "/liteloader-" + version.selfVersion + ".jar";
mv.libraries.add(0, ml);
FileUtils.copyFile(installer, new File(service.baseDirectory(), "libraries/com/mumfrey/liteloader/" + version.selfVersion + "/liteloader-" + version.selfVersion + ".jar"));
mv.id += "-LiteLoader" + version.selfVersion;
mv.mainClass = "net.minecraft.launchwrapper.Launch";
mv.minecraftArguments += " --tweakClass " + version.tweakClass;
File folder = new File(service.baseDirectory(), "versions/" + mv.id);
folder.mkdirs();
File json = new File(folder, mv.id + ".json");
HMCLog.log("Creating new version profile..." + mv.id + ".json");
FileUtils.write(json, C.gsonPrettyPrinting.toJson(mv));
}
@Override
public String getInfo() {
return C.i18n("install.liteloader.install");
}
ArrayList<PreviousResult<File>> pre = new ArrayList<>();
@Override
public Task registerPreviousResult(PreviousResult pr) {
pre.add(pr);
return this;
}
}
@@ -1,20 +1,21 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.installers.liteloader;
package org.jackhuang.hellominecraft.launcher.core.installers.liteloader;
import java.util.Map;
@@ -1,22 +1,23 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.installers.liteloader;
package org.jackhuang.hellominecraft.launcher.core.installers.liteloader;
import org.jackhuang.hellominecraft.launcher.version.MinecraftLibrary;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
/**
*
@@ -1,20 +1,21 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.installers.liteloader;
package org.jackhuang.hellominecraft.launcher.core.installers.liteloader;
import java.util.ArrayList;
import java.util.Arrays;
@@ -22,11 +23,11 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.launcher.version.MinecraftLibrary;
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList;
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList.InstallerVersion;
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionNewerComparator;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionList;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionList.InstallerVersion;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionNewerComparator;
import org.jackhuang.hellominecraft.utils.NetUtils;
import org.jackhuang.hellominecraft.utils.StrUtils;
@@ -50,8 +51,9 @@ public class LiteLoaderVersionList extends InstallerVersionList {
@Override
public void refreshList(String[] needed) throws Exception {
String s = NetUtils.doGet(C.URL_LITELOADER_LIST);
if (root != null) return;
String s = NetUtils.get(C.URL_LITELOADER_LIST);
if (root != null)
return;
root = C.gson.fromJson(s, LiteLoaderVersionsRoot.class);
@@ -62,7 +64,8 @@ public class LiteLoaderVersionList extends InstallerVersionList {
ArrayList<InstallerVersion> al = new ArrayList<>();
LiteLoaderMCVersions mcv = arr.getValue();
for (Map.Entry<String, LiteLoaderVersion> entry : mcv.artefacts.get("com.mumfrey:liteloader").entrySet()) {
if ("latest".equals(entry.getKey())) continue;
if ("latest".equals(entry.getKey()))
continue;
LiteLoaderVersion v = entry.getValue();
LiteLoaderInstallerVersion iv = new LiteLoaderInstallerVersion(v.version, StrUtils.formatVersion(arr.getKey()));
iv.universal = "http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + arr.getKey() + "/" + v.file;
@@ -80,11 +83,14 @@ public class LiteLoaderVersionList extends InstallerVersionList {
}
@Override
public List<InstallerVersion> getVersions(String mcVersion) {
if (versions == null || versionMap == null) return null;
if (StrUtils.isBlank(mcVersion)) return versions;
public List<InstallerVersion> getVersionsImpl(String mcVersion) {
if (versions == null || versionMap == null)
return null;
if (StrUtils.isBlank(mcVersion))
return versions;
List c = versionMap.get(mcVersion);
if (c == null) return versions;
if (c == null)
return versions;
Collections.sort(c, InstallerVersionComparator.INSTANCE);
return c;
}
@@ -1,20 +1,21 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.installers.liteloader;
package org.jackhuang.hellominecraft.launcher.core.installers.liteloader;
/**
*
@@ -1,20 +1,21 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.installers.liteloader;
package org.jackhuang.hellominecraft.launcher.core.installers.liteloader;
import java.util.Map;
@@ -0,0 +1,94 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.installers.optifine;
import java.io.File;
import java.util.ArrayList;
import java.util.zip.ZipFile;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionList;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.utils.tasks.Task;
import org.jackhuang.hellominecraft.utils.tasks.communication.PreviousResult;
import org.jackhuang.hellominecraft.utils.tasks.communication.PreviousResultRegistrar;
import org.jackhuang.hellominecraft.utils.system.FileUtils;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
/**
*
* @author huangyuhui
*/
public class OptiFineInstaller extends Task implements PreviousResultRegistrar<File> {
public File installer;
public IMinecraftService service;
public InstallerVersionList.InstallerVersion version;
public String installId;
public OptiFineInstaller(IMinecraftService service, String installId, InstallerVersionList.InstallerVersion version) {
this(service, installId, version, null);
}
public OptiFineInstaller(IMinecraftService service, String installId, InstallerVersionList.InstallerVersion version, File installer) {
this.service = service;
this.installId = installId;
this.installer = installer;
this.version = version;
}
@Override
public void executeTask() throws Exception {
if (installId == null)
throw new Exception(C.i18n("install.no_version"));
String selfId = version.selfVersion;
MinecraftVersion mv = (MinecraftVersion) service.version().getVersionById(installId).clone();
mv.inheritsFrom = mv.id;
mv.jar = mv.jar == null ? mv.id : mv.jar;
mv.libraries.clear();
mv.libraries.add(0, new MinecraftLibrary("optifine:OptiFine:" + selfId));
FileUtils.copyFile(installer, new File(service.baseDirectory(), "libraries/optifine/OptiFine/" + selfId + "/OptiFine-" + selfId + ".jar"));
mv.id += "-" + selfId;
if (new ZipFile(installer).getEntry("optifine/OptiFineTweaker.class") != null) {
if (!mv.mainClass.startsWith("net.minecraft.launchwrapper.")) {
mv.mainClass = "net.minecraft.launchwrapper.Launch";
mv.libraries.add(1, new MinecraftLibrary("net.minecraft:launchwrapper:1.7"));
}
mv.minecraftArguments += " --tweakClass optifine.OptiFineTweaker";
}
File loc = new File(service.baseDirectory(), "versions/" + mv.id);
loc.mkdirs();
File json = new File(loc, mv.id + ".json");
FileUtils.writeStringToFile(json, C.gsonPrettyPrinting.toJson(mv, MinecraftVersion.class));
}
@Override
public String getInfo() {
return "Optifine Installer";
}
ArrayList<PreviousResult<File>> pre = new ArrayList();
@Override
public Task registerPreviousResult(PreviousResult pr) {
pre.add(pr);
return this;
}
}
@@ -1,25 +1,27 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.installers.optifine;
package org.jackhuang.hellominecraft.launcher.core.installers.optifine;
/**
*
* @author huangyuhui
*/
public class OptiFineVersion {
public String dl, ver, date, mirror, mcver;
}
@@ -1,20 +1,21 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.installers.optifine.bmcl;
package org.jackhuang.hellominecraft.launcher.core.installers.optifine.bmcl;
import com.google.gson.reflect.TypeToken;
import java.util.ArrayList;
@@ -24,10 +25,10 @@ import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.utils.ArrayUtils;
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList;
import org.jackhuang.hellominecraft.launcher.utils.installers.optifine.OptiFineVersion;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionList;
import org.jackhuang.hellominecraft.launcher.core.installers.optifine.OptiFineVersion;
import org.jackhuang.hellominecraft.utils.NetUtils;
import org.jackhuang.hellominecraft.utils.StrUtils;
@@ -51,21 +52,23 @@ public class OptiFineBMCLVersionList extends InstallerVersionList {
@Override
public void refreshList(String[] needed) throws Exception {
String s = NetUtils.doGet("http://bmclapi.bangbang93.com/optifine/versionlist");
String s = NetUtils.get("http://bmclapi.bangbang93.com/optifine/versionlist");
versionMap = new HashMap<>();
versions = new ArrayList<>();
if (s == null) return;
if (s == null)
return;
root = C.gson.fromJson(s, new TypeToken<ArrayList<OptiFineVersion>>() {
}.getType());
}.getType());
for (OptiFineVersion v : root) {
v.mirror = v.mirror.replace("http://optifine.net/http://optifine.net/", "http://optifine.net/");
if (StrUtils.isBlank(v.mcver)) {
Pattern p = Pattern.compile("OptiFine (.*) HD");
Matcher m = p.matcher(v.ver);
while (m.find()) v.mcver = m.group(1);
while (m.find())
v.mcver = m.group(1);
}
InstallerVersion iv = new InstallerVersion(v.ver, StrUtils.formatVersion(v.mcver));
@@ -80,11 +83,14 @@ public class OptiFineBMCLVersionList extends InstallerVersionList {
}
@Override
public List<InstallerVersion> getVersions(String mcVersion) {
if (versions == null || versionMap == null) return null;
if (StrUtils.isBlank(mcVersion)) return versions;
public List<InstallerVersion> getVersionsImpl(String mcVersion) {
if (versions == null || versionMap == null)
return null;
if (StrUtils.isBlank(mcVersion))
return versions;
List c = versionMap.get(mcVersion);
if (c == null) return versions;
if (c == null)
return versions;
Collections.sort(c, InstallerVersionComparator.INSTANCE);
return c;
}
@@ -0,0 +1,58 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.installers.optifine.vanilla;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.utils.tasks.Task;
import org.jackhuang.hellominecraft.utils.tasks.communication.PreviousResult;
import org.jackhuang.hellominecraft.utils.NetUtils;
/**
*
* @author huangyuhui
*/
public class OptiFineDownloadFormatter extends Task implements PreviousResult<String> {
String url, result;
public OptiFineDownloadFormatter(String url) {
this.url = url;
}
@Override
public void executeTask() throws Exception {
String content = NetUtils.get(url);
Pattern p = Pattern.compile("\"downloadx\\?f=OptiFine(.*)\"");
Matcher m = p.matcher(content);
while (m.find())
result = m.group(1);
result = "http://optifine.net/downloadx?f=OptiFine" + result;
}
@Override
public String getInfo() {
return C.i18n("install.optifine.get_download_link");
}
@Override
public String getResult() {
return result;
}
}
@@ -1,23 +1,24 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.utils.installers.optifine.vanilla;
package org.jackhuang.hellominecraft.launcher.core.installers.optifine.vanilla;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringBufferInputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -28,8 +29,8 @@ import java.util.regex.Pattern;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList;
import org.jackhuang.hellominecraft.launcher.utils.installers.optifine.OptiFineVersion;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionList;
import org.jackhuang.hellominecraft.launcher.core.installers.optifine.OptiFineVersion;
import org.jackhuang.hellominecraft.utils.ArrayUtils;
import org.jackhuang.hellominecraft.utils.NetUtils;
import org.jackhuang.hellominecraft.utils.StrUtils;
@@ -59,8 +60,9 @@ public class OptiFineVersionList extends InstallerVersionList {
@Override
public void refreshList(String[] sss) throws Exception {
String content = NetUtils.doGet("http://optifine.net/downloads");
if (versions != null) return;
String content = NetUtils.get("http://optifine.net/downloads");
if (versions != null)
return;
versionMap = new HashMap<>();
versions = new ArrayList<>();
@@ -69,7 +71,7 @@ public class OptiFineVersionList extends InstallerVersionList {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder db = factory.newDocumentBuilder();
Document doc = db.parse(new StringBufferInputStream(content));
Document doc = db.parse(new ByteArrayInputStream(content.getBytes()));
Element r = doc.getDocumentElement();
NodeList tables = r.getElementsByTagName("table");
for (int i = 0; i < tables.getLength(); i++) {
@@ -93,7 +95,8 @@ public class OptiFineVersionList extends InstallerVersionList {
if (StrUtils.isBlank(v.mcver)) {
Pattern p = Pattern.compile("OptiFine (.*?) ");
Matcher m = p.matcher(v.ver);
while (m.find()) v.mcver = StrUtils.formatVersion(m.group(1));
while (m.find())
v.mcver = StrUtils.formatVersion(m.group(1));
}
InstallerVersion iv = new InstallerVersion(v.ver, StrUtils.formatVersion(v.mcver));
iv.installer = iv.universal = v.mirror;
@@ -118,11 +121,14 @@ public class OptiFineVersionList extends InstallerVersionList {
}
@Override
public List<InstallerVersion> getVersions(String mcVersion) {
if (versions == null || versionMap == null) return null;
if (StrUtils.isBlank(mcVersion)) return versions;
public List<InstallerVersion> getVersionsImpl(String mcVersion) {
if (versions == null || versionMap == null)
return null;
if (StrUtils.isBlank(mcVersion))
return versions;
List c = versionMap.get(mcVersion);
if (c == null) return versions;
if (c == null)
return versions;
Collections.sort(c, InstallerVersionComparator.INSTANCE);
return c;
}
@@ -1,35 +1,37 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.launch;
package org.jackhuang.hellominecraft.launcher.core.launch;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftLoader;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
import org.jackhuang.hellominecraft.launcher.Launcher;
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.settings.Profile;
import org.jackhuang.hellominecraft.launcher.settings.Settings;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.utils.system.JdkVersion;
import org.jackhuang.hellominecraft.utils.MathUtils;
import org.jackhuang.hellominecraft.utils.system.MessageBox;
import org.jackhuang.hellominecraft.utils.MessageBox;
import org.jackhuang.hellominecraft.utils.system.OS;
import org.jackhuang.hellominecraft.utils.system.Platform;
import org.jackhuang.hellominecraft.utils.StrUtils;
@@ -41,45 +43,36 @@ import org.jackhuang.hellominecraft.utils.Utils;
*/
public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
protected Profile v;
protected LaunchOptions options;
protected UserProfileProvider lr;
protected File gameDir;
protected IMinecraftProvider provider;
protected IMinecraftService service;
protected final MinecraftVersion version;
public AbstractMinecraftLoader(Profile ver, IMinecraftProvider provider, UserProfileProvider lr) {
public AbstractMinecraftLoader(LaunchOptions options, IMinecraftService service, String versionId, UserProfileProvider lr) throws GameException {
this.lr = lr;
v = ver;
this.provider = provider;
gameDir = v.getCanonicalGameDirFile();
this.options = options;
this.service = service;
this.gameDir = service.baseDirectory();
this.version = service.version().getVersionById(versionId).resolve(service.version());
}
@Override
public MinecraftVersion getMinecraftVersion() {
return version;
}
public void makeHeadCommand(List<String> res) {
HMCLog.log("On making head command.");
String str = v.getJavaDir();
if(!v.getJavaDirFile().exists()) {
MessageBox.Show(C.i18n("launch.wrong_javadir"));
v.setJava(null);
str = v.getJavaDir();
}
JdkVersion jv = new JdkVersion(str);
if (Settings.getInstance().getJava().contains(jv))
jv = Settings.getInstance().getJava().get(Settings.getInstance().getJava().indexOf(jv));
else try {
jv = JdkVersion.getJavaVersionFromExecutable(str);
Settings.getInstance().getJava().add(jv);
Settings.save();
} catch (IOException ex) {
HMCLog.warn("Failed to get java version", ex);
jv = null;
}
res.add(str);
JdkVersion jv = options.getJava();
res.add(options.getJavaDir());
if (v.hasJavaArgs())
res.addAll(Arrays.asList(StrUtils.tokenize(v.getJavaArgs())));
if (options.hasJavaArgs())
res.addAll(Arrays.asList(StrUtils.tokenize(options.getJavaArgs())));
if (!v.isNoJVMArgs()) {
if (!options.isNoJVMArgs()) {
appendJVMArgs(res);
if (jv == null || !jv.isEarlyAccess()) {
@@ -92,11 +85,11 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
res.add("-Xmn128m");
}
if (!StrUtils.isBlank(v.getPermSize()))
if (!StrUtils.isBlank(options.getPermSize()))
if (jv == null || jv.getParsedVersion() < JdkVersion.JAVA_18)
res.add("-XX:PermSize=" + v.getPermSize() + "m");
res.add("-XX:PermSize=" + options.getPermSize() + "m");
else if (jv.getParsedVersion() >= JdkVersion.JAVA_18)
res.add("-XX:MetaspaceSize=" + v.getPermSize() + "m");
res.add("-XX:MetaspaceSize=" + options.getPermSize() + "m");
}
if (jv != null) {
@@ -108,8 +101,8 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
if (jv != null && jv.getPlatform() == Platform.BIT_32 && Platform.getPlatform() == Platform.BIT_64)
MessageBox.Show(C.i18n("advice.os64butjdk32"));
if (!StrUtils.isBlank(v.getMaxMemory())) {
int mem = MathUtils.parseMemory(v.getMaxMemory(), 2147483647);
if (!StrUtils.isBlank(options.getMaxMemory())) {
int mem = MathUtils.parseMemory(options.getMaxMemory(), 2147483647);
if (jv != null && jv.getPlatform() == Platform.BIT_32 && mem > 1024)
MessageBox.Show(C.i18n("launch.too_big_memory_alloc_64bit"));
else {
@@ -118,20 +111,20 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
if (a > 0 && a < mem)
MessageBox.Show(C.i18n("launch.too_big_memory_alloc_free_space_too_low", a));
}
String a = "-Xmx" + v.getMaxMemory();
if (MathUtils.canParseInt(v.getMaxMemory())) a += "m";
String a = "-Xmx" + options.getMaxMemory();
if (MathUtils.canParseInt(options.getMaxMemory()))
a += "m";
res.add(a);
}
res.add("-Djava.library.path=" + provider.getDecompressNativesToLocation().getPath());
res.add("-Djava.library.path=" + service.version().getDecompressNativesToLocation(version).getPath());
res.add("-Dfml.ignoreInvalidMinecraftCertificates=true");
res.add("-Dfml.ignorePatchDiscrepancies=true");
if (OS.os() != OS.WINDOWS)
res.add("-Duser.home=" + gameDir.getParent());
res.add("-Dhellominecraftlauncher.gamedir=" + gameDir.getAbsolutePath());
if (!v.isCanceledWrapper()) {
if (!options.isCanceledWrapper()) {
res.add("-cp");
res.add(StrUtils.parseParams("", Utils.getURL(), File.pathSeparator));
res.add(Launcher.class.getCanonicalName());
@@ -139,7 +132,7 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
}
@Override
public List<String> makeLaunchingCommand() {
public List<String> makeLaunchingCommand() throws GameException {
HMCLog.log("*** Make shell command ***");
ArrayList<String> res = new ArrayList<>();
@@ -149,33 +142,47 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
HMCLog.log("On making launcher args.");
if (StrUtils.isNotBlank(v.getHeight()) && StrUtils.isNotBlank(v.getWidth())) {
if (StrUtils.isNotBlank(options.getHeight()) && StrUtils.isNotBlank(options.getWidth())) {
res.add("--height");
res.add(v.getHeight());
res.add(options.getHeight());
res.add("--width");
res.add(v.getWidth());
res.add(options.getWidth());
}
if (StrUtils.isNotBlank(v.getServerIp())) {
String[] args = v.getServerIp().split(":");
String serverIp = options.getServerIp();
if (lr.getServer() != null)
serverIp = lr.getServer().addr;
if (StrUtils.isNotBlank(serverIp)) {
String[] args = serverIp.split(":");
res.add("--server");
res.add(args[0]);
res.add("--port");
res.add(args.length > 1 ? args[1] : "25565");
}
if (v.isFullscreen()) res.add("--fullscreen");
if (options.isFullscreen())
res.add("--fullscreen");
if (v.isDebug() && !v.isCanceledWrapper()) res.add("-debug");
if (options.isDebug() && !options.isCanceledWrapper())
res.add("-debug");
if (StrUtils.isNotBlank(v.getMinecraftArgs()))
res.addAll(Arrays.asList(v.getMinecraftArgs().split(" ")));
if (StrUtils.isNotBlank(options.getProxyHost()) && StrUtils.isNotBlank(options.getProxyPort()) && MathUtils.canParseInt(options.getProxyPort())) {
res.add("-proxyHost=" + options.getProxyHost());
res.add("-proxyPort=" + options.getProxyPort());
if (StrUtils.isNotBlank(options.getProxyUser()) && StrUtils.isNotBlank(options.getProxyPass())) {
res.add("-proxyUsername=" + options.getProxyUser());
res.add("-proxyPassword=" + options.getProxyPass());
}
}
if (StrUtils.isNotBlank(options.getMinecraftArgs()))
res.addAll(Arrays.asList(options.getMinecraftArgs().split(" ")));
return res;
}
/**
* You must do these things:<br />
* You must do these things:
* <ul>
* <li>minecraft class path</li>
* <li>main class</li>
@@ -184,12 +191,8 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
*
* @param list the command list you shoud edit.
*/
protected abstract void makeSelf(List<String> list);
protected abstract void makeSelf(List<String> list) throws GameException;
protected void appendJVMArgs(List<String> list) {
}
public Profile getUserVersion() {
return v;
}
}
@@ -0,0 +1,68 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui
*
* 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 org.jackhuang.hellominecraft.launcher.core.launch;
import java.io.IOException;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.auth.LoginInfo;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadLibraryJob;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.utils.tasks.ParallelTask;
import org.jackhuang.hellominecraft.utils.tasks.TaskWindow;
import org.jackhuang.hellominecraft.utils.system.Compressor;
import org.jackhuang.hellominecraft.utils.MessageBox;
import org.jackhuang.hellominecraft.utils.StrUtils;
public class DefaultGameLauncher extends GameLauncher {
public DefaultGameLauncher(LaunchOptions options, IMinecraftService service, LoginInfo info, IAuthenticator lg) {
super(options, service, info, lg);
register();
}
private void register() {
downloadLibrariesEvent.register((sender, t) -> {
final TaskWindow.TaskWindowFactory dw = TaskWindow.getInstance();
ParallelTask parallelTask = new ParallelTask();
for (DownloadLibraryJob s : t)
parallelTask.addDependsTask(new LibraryDownloadTask(s));
dw.addTask(parallelTask);
boolean flag = true;
if (t.size() > 0)
flag = dw.start();
if (!flag && MessageBox.Show(C.i18n("launch.not_finished_downloading_libraries"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
flag = true;
return flag;
});
decompressNativesEvent.register((sender, value) -> {
if (value == null)
return false;
for (int i = 0; i < value.decompressFiles.length; i++)
try {
String[] rules = value.extractRules[i];
Compressor.unzip(value.decompressFiles[i], value.decompressTo, t -> !StrUtils.startsWithOne(rules, t), false);
} catch (IOException ex) {
HMCLog.err("Unable to decompress library file: " + value.decompressFiles[i] + " to " + value.decompressTo, ex);
}
return true;
});
}
}
@@ -0,0 +1,186 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui
*
* 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 org.jackhuang.hellominecraft.launcher.core.launch;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftLoader;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.util.List;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
import org.jackhuang.hellominecraft.launcher.api.PluginManager;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.auth.LoginInfo;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.core.auth.AuthenticationException;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadLibraryJob;
import org.jackhuang.hellominecraft.launcher.core.version.DecompressLibraryJob;
import org.jackhuang.hellominecraft.utils.system.FileUtils;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
import org.jackhuang.hellominecraft.utils.system.JavaProcess;
import org.jackhuang.hellominecraft.utils.MessageBox;
import org.jackhuang.hellominecraft.utils.system.OS;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.utils.EventHandler;
import org.jackhuang.hellominecraft.utils.system.ProcessManager;
public class GameLauncher {
public static final ProcessManager PROCESS_MANAGER = new ProcessManager();
LaunchOptions options;
IMinecraftService service;
LoginInfo info;
UserProfileProvider result;
IAuthenticator login;
public final EventHandler<List<DownloadLibraryJob>> downloadLibrariesEvent = new EventHandler(this);
public final EventHandler<List<String>> successEvent = new EventHandler(this);
public final EventHandler<JavaProcess> launchEvent = new EventHandler(this);
public final EventHandler<DecompressLibraryJob> decompressNativesEvent = new EventHandler(this);
public GameLauncher(LaunchOptions options, IMinecraftService version, LoginInfo info, IAuthenticator lg) {
this.options = options;
this.service = version;
this.info = info;
this.login = lg;
}
private Object tag;
public Object getTag() {
return tag;
}
public void setTag(Object tag) {
this.tag = tag;
}
public IMinecraftLoader makeLaunchCommand() throws AuthenticationException, GameException {
HMCLog.log("Logging in...");
IMinecraftLoader loader;
if (info != null)
result = login.login(info);
else
result = login.loginBySettings();
if (result == null)
throw new AuthenticationException("Result can not be null.");
PluginManager.NOW_PLUGIN.onProcessingLoginResult(result);
loader = service.launch(options, result);
File file = service.version().getDecompressNativesToLocation(loader.getMinecraftVersion());
if (file != null)
FileUtils.cleanDirectoryQuietly(file);
HMCLog.log("Detecting libraries...");
if (!downloadLibrariesEvent.execute(service.download().getDownloadLibraries(loader.getMinecraftVersion())))
throw new GameException("Failed to download libraries");
HMCLog.log("Unpacking natives...");
DecompressLibraryJob job = service.version().getDecompressLibraries(loader.getMinecraftVersion());
if (!decompressNativesEvent.execute(job))
throw new GameException("Failed to decompress natives");
successEvent.execute(loader.makeLaunchingCommand());
return loader;
}
/**
* Launch the game "as soon as possible".
*
* @param str launch command
*
* @throws IOException failed creating process
*/
public void launch(List str) throws IOException {
if (!service.version().onLaunch())
return;
if (StrUtils.isNotBlank(options.getPrecalledCommand())) {
Process p = Runtime.getRuntime().exec(options.getPrecalledCommand());
try {
if (p != null && p.isAlive())
p.waitFor();
} catch (InterruptedException ex) {
HMCLog.warn("Failed to invoke precalled command", ex);
}
}
HMCLog.log("Starting process");
ProcessBuilder builder = new ProcessBuilder(str);
if (options.getLaunchVersion() == null || service.baseDirectory() == null)
throw new Error("Fucking bug!");
builder.directory(service.version().getRunDirectory(options.getLaunchVersion()))
.environment().put("APPDATA", service.baseDirectory().getAbsolutePath());
JavaProcess jp = new JavaProcess(str, builder.start(), PROCESS_MANAGER);
HMCLog.log("The game process have been started");
launchEvent.execute(jp);
}
/**
* According to the name...
*
* @param launcherName the name of launch bat/sh
* @param str launch command
*
* @return launcher location
*
* @throws java.io.IOException write contents failed.
*/
public File makeLauncher(String launcherName, List str) throws IOException {
HMCLog.log("Making shell launcher...");
service.version().onLaunch();
boolean isWin = OS.os() == OS.WINDOWS;
File f = new File(launcherName + (isWin ? ".bat" : ".sh"));
if (!f.exists())
f.createNewFile();
BufferedWriter writer;
try {
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), System.getProperty("sun.jnu.encoding", "UTF-8")));
} catch (UnsupportedEncodingException ex) {
HMCLog.warn("Failed to create writer, will try again.", ex);
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f)));
}
if (isWin) {
writer.write("@echo off");
writer.newLine();
String appdata = IOUtils.tryGetCanonicalFilePath(service.baseDirectory());
if (appdata != null) {
writer.write("set appdata=" + appdata);
writer.newLine();
}
}
if (StrUtils.isNotBlank(options.getPrecalledCommand())) {
writer.write(options.getPrecalledCommand());
writer.newLine();
}
writer.write(StrUtils.makeCommand(str));
writer.close();
if (!f.setExecutable(true)) {
HMCLog.warn("Failed to give launcher permission.");
MessageBox.Show(C.i18n("launch.failed_sh_permission"));
}
HMCLog.log("Command: " + StrUtils.parseParams("", str, " "));
return f;
}
}
@@ -0,0 +1,240 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.launch;
import java.io.File;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.version.GameDirType;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.utils.system.JdkVersion;
/**
*
* @author huangyuhui
*/
public class LaunchOptions {
private String name, versionName, javaArgs, minecraftArgs, maxMemory, permSize, width, height, userProperties, serverIp;
private String proxyHost, proxyPort, proxyUser, proxyPass, javaDir, launchVersion;
private boolean fullscreen, debug, noJVMArgs, canceledWrapper;
private JdkVersion java;
private File gameDir;
private GameDirType gameDirType;
protected transient IMinecraftService service;
public String getVersionName() {
return versionName;
}
public void setVersionName(String versionName) {
this.versionName = versionName;
}
public File getGameDir() {
return gameDir;
}
public void setGameDir(File gameDir) {
this.gameDir = gameDir;
}
public void setJavaDir(String javaDir) {
this.javaDir = javaDir;
}
public String getJavaDir() {
return javaDir;
}
public JdkVersion getJava() {
return java;
}
public void setJava(JdkVersion java) {
this.java = java;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getJavaArgs() {
return javaArgs;
}
public void setJavaArgs(String javaArgs) {
this.javaArgs = javaArgs;
}
public boolean hasJavaArgs() {
return StrUtils.isNotBlank(getJavaArgs().trim());
}
public String getMaxMemory() {
return maxMemory;
}
public void setMaxMemory(String maxMemory) {
this.maxMemory = maxMemory;
}
public String getWidth() {
return width;
}
public void setWidth(String width) {
this.width = width;
}
public String getHeight() {
return height;
}
public void setHeight(String height) {
this.height = height;
}
public String getUserProperties() {
if (userProperties == null)
return "";
return userProperties;
}
public void setUserProperties(String userProperties) {
this.userProperties = userProperties;
}
public boolean isFullscreen() {
return fullscreen;
}
public void setFullscreen(boolean fullscreen) {
this.fullscreen = fullscreen;
}
public boolean isDebug() {
return debug;
}
public void setDebug(boolean debug) {
this.debug = debug;
}
public GameDirType getGameDirType() {
return gameDirType;
}
public void setGameDirType(GameDirType gameDirType) {
this.gameDirType = gameDirType;
}
public String getPermSize() {
return permSize;
}
public void setPermSize(String permSize) {
this.permSize = permSize;
}
public boolean isNoJVMArgs() {
return noJVMArgs;
}
public void setNoJVMArgs(boolean noJVMArgs) {
this.noJVMArgs = noJVMArgs;
}
public String getMinecraftArgs() {
return minecraftArgs;
}
public void setMinecraftArgs(String minecraftArgs) {
this.minecraftArgs = minecraftArgs;
}
public boolean isCanceledWrapper() {
return canceledWrapper;
}
public void setCanceledWrapper(boolean canceledWrapper) {
this.canceledWrapper = canceledWrapper;
}
public String getServerIp() {
return serverIp;
}
public void setServerIp(String serverIp) {
this.serverIp = serverIp;
}
public String getProxyHost() {
return proxyHost;
}
public void setProxyHost(String proxyHost) {
this.proxyHost = proxyHost;
}
public String getProxyPort() {
return proxyPort;
}
public void setProxyPort(String proxyPort) {
this.proxyPort = proxyPort;
}
public String getProxyUser() {
return proxyUser;
}
public void setProxyUser(String proxyUser) {
this.proxyUser = proxyUser;
}
public String getProxyPass() {
return proxyPass;
}
public void setProxyPass(String proxyPass) {
this.proxyPass = proxyPass;
}
private String precalledCommand;
public String getPrecalledCommand() {
return precalledCommand;
}
public void setPrecalledCommand(String precalledCommand) {
this.precalledCommand = precalledCommand;
}
public String getLaunchVersion() {
return launchVersion;
}
public void setLaunchVersion(String launchVersion) {
this.launchVersion = launchVersion;
}
}
@@ -1,20 +1,21 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.launch;
package org.jackhuang.hellominecraft.launcher.core.launch;
import java.io.File;
import java.io.FileInputStream;
@@ -26,9 +27,10 @@ import java.util.Arrays;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.jar.Pack200;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.tasks.download.FileDownloadTask;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadLibraryJob;
import org.jackhuang.hellominecraft.utils.tasks.download.FileDownloadTask;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
import org.tukaani.xz.XZInputStream;
@@ -38,48 +40,46 @@ import org.tukaani.xz.XZInputStream;
*/
public class LibraryDownloadTask extends FileDownloadTask {
GameLauncher.DownloadLibraryJob job;
DownloadLibraryJob job;
public LibraryDownloadTask(GameLauncher.DownloadLibraryJob job) {
public LibraryDownloadTask(DownloadLibraryJob job) {
super();
this.job = job;
}
@Override
public boolean executeTask() {
try {
File packFile = new File(job.path.getParentFile(), job.path.getName() + ".pack.xz");
if (job.name.contains("typesafe") && download(new URL(job.url + ".pack.xz"), packFile)) {
unpackLibrary(job.path, packFile);
packFile.delete();
return true;
} else {
if (job.name.startsWith("net.minecraftforge:forge:")) {
String[] s = job.name.split(":");
if (s.length == 3)
job.url = "http://files.minecraftforge.net/maven/net/minecraftforge/forge/" + s[2] + "/forge-" + s[2] + "-universal.jar";
}
if (job.name.startsWith("com.mumfrey:liteloader:")) {
String[] s = job.name.split(":");
if (s.length == 3 && s[2].length() > 3)
job.url = "http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + s[2].substring(0, s[2].length() - 3) + "/liteloader-" + s[2] + ".jar";
}
return download(new URL(job.url), job.path);
}
} catch (Exception ex) {
setFailReason(ex);
return false;
public void executeTask() throws Throwable {
File packFile = new File(job.path.getParentFile(), job.path.getName() + ".pack.xz");
/*
* if (job.name.contains("typesafe")) {
* download(new URL(job.url + ".pack.xz"), packFile);
* unpackLibrary(job.path, packFile);
* packFile.delete();
* } else {
*/
if (job.name.startsWith("net.minecraftforge:forge:")) {
String[] s = job.name.split(":");
if (s.length == 3)
job.url = "http://files.minecraftforge.net/maven/net/minecraftforge/forge/" + s[2] + "/forge-" + s[2] + "-universal.jar";
}
}
boolean download(URL url, File filePath) {
this.url = url;
this.filePath = filePath;
return super.executeTask();
if (job.name.startsWith("com.mumfrey:liteloader:")) {
String[] s = job.name.split(":");
if (s.length == 3 && s[2].length() > 3)
job.url = "http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + s[2].substring(0, s[2].length() - 3) + "/liteloader-" + s[2] + ".jar";
}
download(new URL(job.url), job.path);
//}
}
void download(URL url, File filePath) throws Throwable {
this.url = url;
this.filePath = filePath;
super.executeTask();
}
@SuppressWarnings("UnusedAssignment")
public static void unpackLibrary(File output, File input)
throws IOException {
throws IOException {
HMCLog.log("Unpacking " + input);
if (output.exists())
output.delete();
@@ -0,0 +1,186 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui
*
* 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 org.jackhuang.hellominecraft.launcher.core.launch;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import com.google.gson.JsonSyntaxException;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
import org.jackhuang.hellominecraft.launcher.Main;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
import org.jackhuang.hellominecraft.launcher.core.assets.AssetsIndex;
import org.jackhuang.hellominecraft.launcher.core.assets.AssetsObject;
import org.jackhuang.hellominecraft.launcher.core.assets.IAssetsHandler;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
import org.jackhuang.hellominecraft.utils.system.OS;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
import org.jackhuang.hellominecraft.utils.tasks.TaskWindow;
import org.jackhuang.hellominecraft.utils.system.FileUtils;
import org.jackhuang.hellominecraft.utils.MessageBox;
import org.jackhuang.hellominecraft.utils.StrUtils;
/**
*
* @author huangyuhui
*/
public class MinecraftLoader extends AbstractMinecraftLoader {
DownloadType dt;
String text;
public MinecraftLoader(LaunchOptions p, IMinecraftService provider, UserProfileProvider lr) throws GameException {
super(p, provider, p.getLaunchVersion(), lr);
}
@Override
protected void makeSelf(List<String> res) throws GameException {
String library = options.isCanceledWrapper() ? "" : "-cp=";
for (MinecraftLibrary l : version.libraries) {
l.init();
if (l.allow() && !l.isRequiredToUnzip())
library += l.getFilePath(gameDir).getAbsolutePath() + File.pathSeparator;
}
File f = version.getJar(service.baseDirectory());
if (!f.exists())
throw new GameException("Minecraft jar does not exists");
library += IOUtils.tryGetCanonicalFilePath(f) + File.pathSeparator;
library = library.substring(0, library.length() - File.pathSeparator.length());
if (options.isCanceledWrapper())
res.add("-cp");
res.add(library);
String mainClass = version.mainClass;
res.add((options.isCanceledWrapper() ? "" : "-mainClass=") + mainClass);
String[] splitted = StrUtils.tokenize(version.minecraftArguments);
if (!checkAssetsExist())
if (MessageBox.Show(C.i18n("assets.no_assets"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
IAssetsHandler.ASSETS_HANDLER.getList(version, service.asset()).subscribe(a -> {
});
TaskWindow.getInstance().addTask(IAssetsHandler.ASSETS_HANDLER.getDownloadTask(service.getDownloadType().getProvider())).start();
}
String game_assets = reconstructAssets().getAbsolutePath();
for (String t : splitted) {
t = t.replace("${auth_player_name}", lr.getUserName());
t = t.replace("${auth_session}", lr.getSession());
t = t.replace("${auth_uuid}", lr.getUserId());
t = t.replace("${version_name}", Main.makeTitle());
t = t.replace("${profile_name}", options.getName());
t = t.replace("${game_directory}", service.version().getRunDirectory(version.id).getAbsolutePath());
t = t.replace("${game_assets}", game_assets);
t = t.replace("${assets_root}", service.asset().getAssets().getAbsolutePath());
t = t.replace("${auth_access_token}", lr.getAccessToken());
t = t.replace("${user_type}", lr.getUserType());
t = t.replace("${assets_index_name}", version.getAssets());
t = t.replace("${user_properties}", lr.getUserProperties());
res.add(t);
}
if (res.indexOf("--gameDir") != -1 && res.indexOf("--workDir") != -1) {
res.add("--workDir");
res.add(gameDir.getAbsolutePath());
}
}
@Override
protected void appendJVMArgs(List<String> list) {
super.appendJVMArgs(list);
try {
if (OS.os() == OS.OSX) {
list.add("-Xdock:icon=" + service.asset().getAssetObject(version.assets, "icons/minecraft.icns").getAbsolutePath());
list.add("-Xdock:name=Minecraft");
}
} catch (IOException e) {
HMCLog.err("Failed to append jvm arguments when searching for asset objects.", e);
}
}
private boolean checkAssetsExist() {
File assetsDir = new File(service.baseDirectory(), "assets");
File indexDir = new File(assetsDir, "indexes");
File objectDir = new File(assetsDir, "objects");
File indexFile = new File(indexDir, version.getAssets() + ".json");
if (!assetsDir.exists() && !indexFile.isFile())
return false;
try {
AssetsIndex index = (AssetsIndex) C.gson.fromJson(FileUtils.readFileToString(indexFile, "UTF-8"), AssetsIndex.class);
if (index == null)
return false;
for (Map.Entry entry : index.getFileMap().entrySet())
if (!new File(new File(objectDir, ((AssetsObject) entry.getValue()).getHash().substring(0, 2)), ((AssetsObject) entry.getValue()).getHash()).exists())
return false;
return true;
} catch (IOException | JsonSyntaxException e) {
return false;
}
}
private File reconstructAssets() {
File assetsDir = new File(service.baseDirectory(), "assets");
File indexDir = new File(assetsDir, "indexes");
File objectDir = new File(assetsDir, "objects");
String assetVersion = version.getAssets();
File indexFile = new File(indexDir, assetVersion + ".json");
File virtualRoot = new File(new File(assetsDir, "virtual"), assetVersion);
if (!indexFile.isFile()) {
HMCLog.warn("No assets index file " + virtualRoot + "; can't reconstruct assets");
return assetsDir;
}
try {
AssetsIndex index = (AssetsIndex) C.gson.fromJson(FileUtils.readFileToString(indexFile, "UTF-8"), AssetsIndex.class);
if (index == null)
return assetsDir;
if (index.isVirtual()) {
int cnt = 0;
HMCLog.log("Reconstructing virtual assets folder at " + virtualRoot);
int tot = index.getFileMap().entrySet().size();
for (Map.Entry entry : index.getFileMap().entrySet()) {
File target = new File(virtualRoot, (String) entry.getKey());
File original = new File(new File(objectDir, ((AssetsObject) entry.getValue()).getHash().substring(0, 2)), ((AssetsObject) entry.getValue()).getHash());
if (original.exists()) {
cnt++;
if (!target.isFile())
FileUtils.copyFile(original, target, false);
}
}
// If the scale new format existent file is lower then 0.1, use the old format.
if (cnt * 10 < tot)
return assetsDir;
}
} catch (IOException | JsonSyntaxException e) {
HMCLog.warn("Failed to create virutal assets.", e);
}
return virtualRoot;
}
}
@@ -0,0 +1,119 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.mod;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftModService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.ModInfo;
import org.jackhuang.hellominecraft.utils.code.DigestUtils;
import org.jackhuang.hellominecraft.utils.system.FileUtils;
/**
*
* @author huangyuhui
*/
public class MinecraftModService extends IMinecraftModService {
Map<String, List<ModInfo>> modCache = Collections.synchronizedMap(new HashMap<>());
public MinecraftModService(IMinecraftService service) {
super(service);
}
@Override
public List<ModInfo> getMods(String id) {
if (modCache.containsKey(id))
return modCache.get(id);
else
return recacheMods(id);
}
@Override
public List<ModInfo> recacheMods(String id) {
File modsFolder = service.version().getRunDirectory(id, "mods");
ArrayList<ModInfo> mods = new ArrayList<>();
File[] fs = modsFolder.listFiles();
if (fs != null)
for (File f : fs)
if (ModInfo.isFileMod(f)) {
ModInfo m = ModInfo.readModInfo(f);
if (m != null)
mods.add(m);
} else if (f.isDirectory()) {
File[] ss = f.listFiles();
if (ss != null)
for (File ff : ss)
if (ModInfo.isFileMod(ff)) {
ModInfo m = ModInfo.readModInfo(ff);
if (m != null)
mods.add(m);
}
}
Collections.sort(mods);
return modCache.put(id, mods);
}
@Override
public boolean addMod(String id, File f) {
try {
if (!ModInfo.isFileMod(f))
return false;
File modsFolder = service.version().getRunDirectory(id, "mods");
if (modsFolder == null)
return false;
modsFolder.mkdirs();
File newf = new File(modsFolder, f.getName());
FileUtils.copyFile(f, newf);
ModInfo i = ModInfo.readModInfo(f);
modCache.get(id).add(i);
return true;
} catch (IOException ex) {
HMCLog.warn("Failed to copy mod", ex);
return false;
}
}
@Override
public void removeMod(String id, Object[] rows) {
if (rows.length == 0)
return;
for (Object r : rows)
if (r instanceof ModInfo)
((ModInfo) r).location.delete();
else if (r instanceof Number)
getMods(id).get(((Number) r).intValue()).location.delete();
recacheMods(id);
}
public String[] checkMd5s(String id) throws IOException {
String[] res = new String[getMods(id).size()];
for (int i = 0; i < res.length; i++)
res[i] = DigestUtils.md5Hex(new FileInputStream(getMods(id).get(i).location));
return res;
}
}
@@ -0,0 +1,158 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.mod;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.FileSystemException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftProvider;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.utils.system.Compressor;
import org.jackhuang.hellominecraft.utils.system.FileUtils;
import org.jackhuang.hellominecraft.utils.system.ZipEngine;
import org.jackhuang.hellominecraft.utils.version.MinecraftVersionRequest;
/**
* A mod pack(*.zip) includes these things:
* <ul>
* <li>sth created by the game automatically, including "mods", "scripts",
* "config", etc..
* <li>pack.json, the same as Minecraft version configuration file:
* "gameDir/versions/{MCVER}/{MCVER}.json", will be renamed to that one.
* <li>all things should be included in "minecraft" folder under the root
* folder.
* </ul>
*
* This class can manage mod packs, for example, importing and exporting, the
* format of game is the offical one.
* Not compatible with MultiMC(no instance.cfg processor) & FTB(not leaving
* mcversion(jar) in pack.json).
*
* @author huangyuhui
*/
public final class ModpackManager {
public static void install(File input, IMinecraftService service, String id) throws IOException, FileAlreadyExistsException {
File versions = new File(service.baseDirectory(), "versions");
File oldFile = new File(versions, "minecraft"), newFile = null;
if (oldFile.exists()) {
newFile = new File(versions, "minecraft-" + System.currentTimeMillis());
if (newFile.isDirectory())
FileUtils.deleteDirectory(newFile);
else if (newFile.isFile())
newFile.delete();
oldFile.renameTo(newFile);
}
File preVersion = new File(versions, id), preVersionRenamed = null;
if (preVersion.exists()) {
String preId = id + "-" + System.currentTimeMillis();
preVersion.renameTo(preVersionRenamed = new File(versions, preId));
new File(preVersionRenamed, id + ".json").renameTo(new File(preVersionRenamed, preId + ".json"));
new File(preVersionRenamed, id + ".jar").renameTo(new File(preVersionRenamed, preId + ".jar"));
}
try {
AtomicInteger b = new AtomicInteger(0);
HMCLog.log("Decompressing modpack");
Compressor.unzip(input, versions, t -> {
if (t.equals("minecraft/pack.json"))
b.incrementAndGet();
return true;
}, true);
if (b.get() < 1)
throw new FileNotFoundException(C.i18n("modpack.incorrect_format.no_json"));
File nowFile = new File(versions, id);
oldFile.renameTo(nowFile);
File json = new File(nowFile, "pack.json");
MinecraftVersion mv = C.gson.fromJson(FileUtils.readFileToString(json), MinecraftVersion.class);
if (mv.jar == null)
throw new FileNotFoundException(C.i18n("modpack.incorrect_format.no_jar"));
service.download().downloadMinecraftJarTo(mv.jar, new File(nowFile, id + ".jar"));
mv.jar = null;
FileUtils.writeStringToFile(json, C.gsonPrettyPrinting.toJson(mv));
json.renameTo(new File(nowFile, id + ".json"));
if (preVersionRenamed != null) {
File presaves = new File(preVersionRenamed, "saves");
File saves = new File(nowFile, "saves");
if (presaves.exists()) {
FileUtils.deleteDirectory(saves);
FileUtils.copyDirectory(presaves, saves);
}
}
} finally {
FileUtils.deleteDirectoryQuietly(oldFile);
if (newFile != null)
newFile.renameTo(oldFile);
}
}
/**
* Export the game to a mod pack file.
*
* @param output mod pack file.
* @param baseFolder if the game dir type is ROOT_FOLDER, use ".minecraft",
* or use ".minecraft/versions/{MCVER}/"
* @param version to locate version.json
*
* @throws IOException if create tmp directory failed
*/
public static void export(File output, IMinecraftProvider provider, String version, List<String> blacklist) throws IOException, GameException {
ArrayList<String> b = new ArrayList<>(Arrays.asList(new String[] { "usernamecache.json", "asm", "logs", "backups", "versions", "assets", "usercache.json", "libraries", "crash-reports", "launcher_profiles.json", "NVIDIA", "TCNodeTracker" }));
if (blacklist != null)
b.addAll(blacklist);
HMCLog.log("Compressing game files without some files in blacklist, including files or directories: usernamecache.json, asm, logs, backups, versions, assets, usercache.json, libraries, crash-reports, launcher_profiles.json, NVIDIA, TCNodeTracker");
ZipEngine zip = null;
try {
zip = new ZipEngine(output);
zip.putDirectory(provider.getRunDirectory(version), (String x, Boolean y) -> {
for (String s : b)
if (y) {
if (x.startsWith(s + "/"))
return null;
} else if (x.equals(s))
return null;
return "minecraft/" + x;
});
MinecraftVersion mv = provider.getVersionById(version).resolve(provider);
mv.runDir = "version";
MinecraftVersionRequest r = MinecraftVersionRequest.minecraftVersion(provider.getMinecraftJar(version));
if (r.type != MinecraftVersionRequest.OK)
throw new FileSystemException(C.i18n("modpack.cannot_read_version") + ": " + MinecraftVersionRequest.getResponse(r));
mv.jar = r.version;
zip.putTextFile(C.gsonPrettyPrinting.toJson(mv), "minecraft/pack.json");
} finally {
if (zip != null)
zip.closeFile();
}
}
}
@@ -0,0 +1,50 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.service;
import java.io.File;
import java.io.IOException;
import org.jackhuang.hellominecraft.utils.tasks.Task;
/**
*
* @author huangyuhui
*/
public abstract class IMinecraftAssetService extends IMinecraftBasicService {
public IMinecraftAssetService(IMinecraftService service) {
super(service);
}
public abstract Task downloadAssets(String mcVersion);
public abstract File getAssets();
/**
* Redownload the Asset index json of the given version.
*
* @param a the given version name
*
* @return Is the action successful?
*/
public abstract boolean refreshAssetsIndex(String a);
public abstract boolean downloadMinecraftAssetsIndex(String assetsId);
public abstract File getAssetObject(String assetVersion, String name) throws IOException;
}
@@ -0,0 +1,32 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.service;
/**
*
* @author huangyuhui
*/
public abstract class IMinecraftBasicService {
public IMinecraftService service;
public IMinecraftBasicService(IMinecraftService service) {
this.service = service;
}
}
@@ -0,0 +1,55 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.service;
import java.io.File;
import java.util.List;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadLibraryJob;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.utils.version.MinecraftRemoteVersion;
import rx.Observable;
/**
*
* @author huangyuhui
*/
public abstract class IMinecraftDownloadService extends IMinecraftBasicService {
public IMinecraftDownloadService(IMinecraftService service) {
super(service);
}
public abstract MinecraftVersion downloadMinecraft(String id);
public abstract boolean downloadMinecraftJar(String id);
public abstract boolean downloadMinecraftJarTo(String id, File f);
public abstract boolean downloadMinecraftVersionJson(String id);
/**
* Get the libraries that need to download.
*
* @return the library collection
*/
public abstract List<DownloadLibraryJob> getDownloadLibraries(MinecraftVersion mv) throws GameException;
public abstract Observable<MinecraftRemoteVersion> getRemoteVersions();
}
@@ -0,0 +1,42 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.service;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerType;
import org.jackhuang.hellominecraft.launcher.core.installers.InstallerVersionList;
import org.jackhuang.hellominecraft.utils.tasks.Task;
/**
*
* @author huangyuhui
*/
public abstract class IMinecraftInstallerService extends IMinecraftBasicService {
public IMinecraftInstallerService(IMinecraftService service) {
super(service);
}
public abstract Task download(String installId, InstallerVersionList.InstallerVersion v, InstallerType type);
public abstract Task downloadForge(String installId, InstallerVersionList.InstallerVersion v);
public abstract Task downloadOptifine(String installId, InstallerVersionList.InstallerVersion v);
public abstract Task downloadLiteLoader(String installId, InstallerVersionList.InstallerVersion v);
}
@@ -0,0 +1,33 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui
*
* 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 org.jackhuang.hellominecraft.launcher.core.service;
import java.util.List;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
/**
*
* @author huangyuhui
*/
public interface IMinecraftLoader {
MinecraftVersion getMinecraftVersion();
List<String> makeLaunchingCommand() throws GameException;
}
@@ -0,0 +1,41 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui
*
* 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 org.jackhuang.hellominecraft.launcher.core.service;
import java.io.File;
import java.util.List;
import org.jackhuang.hellominecraft.launcher.core.ModInfo;
/**
*
* @author huangyuhui
*/
public abstract class IMinecraftModService extends IMinecraftBasicService {
public IMinecraftModService(IMinecraftService service) {
super(service);
}
public abstract List<ModInfo> getMods(String id);
public abstract List<ModInfo> recacheMods(String id);
public abstract boolean addMod(String id, File f);
public abstract void removeMod(String id, Object[] mods);
}
@@ -0,0 +1,166 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui
*
* 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 org.jackhuang.hellominecraft.launcher.core.service;
import java.io.File;
import java.util.Collection;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.version.DecompressLibraryJob;
import org.jackhuang.hellominecraft.launcher.core.version.GameDirType;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.utils.functions.Consumer;
/**
* Provide everything of the Minecraft of a Profile.
*
* @see
* org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersionManager
* @author huangyuhui
*/
public abstract class IMinecraftProvider {
protected IMinecraftService service;
public IMinecraftProvider(IMinecraftService service) {
this.service = service;
}
/**
* To download mod packs.
*/
public abstract void initializeMiencraft();
/**
* Get the run directory of given version.
*
* @param id the given version name
*
* @return the run directory
*/
public abstract File getRunDirectory(String id);
public File getRunDirectory(String id, String subFolder) {
return new File(getRunDirectory(id), subFolder);
}
public abstract void open(String version, String folder);
/**
* Install a new version to this profile.
*
* @param version the new version name
*
* @return Is the action successful?
*/
public abstract boolean install(String version, Consumer<MinecraftVersion> callback);
/**
* Returns the thing like ".minecraft/resourcepacks".
*
* @return the thing
*/
public abstract File getResourcePacks();
/**
*
* @param v should be resolved
*
* @return libraries of resolved minecraft version v.
*/
public abstract DecompressLibraryJob getDecompressLibraries(MinecraftVersion v) throws GameException;
public abstract File getDecompressNativesToLocation(MinecraftVersion v);
/**
* @return the Minecraft jar of selected version.
*/
public abstract File getMinecraftJar(String id);
protected GameDirType gameDirType = GameDirType.ROOT_FOLDER;
public void setGameDirType(GameDirType gameDirType) {
this.gameDirType = gameDirType;
}
/**
* Rename version
*
* @param from The old name
* @param to The new name
*
* @return Is the action successful?
*/
public abstract boolean renameVersion(String from, String to);
/**
* Remove the given version from disk.
*
* @param a the version name
*
* @return Is the action successful?
*/
public abstract boolean removeVersionFromDisk(String a);
/**
* Choose a version randomly.
*
* @return the version
*/
public abstract MinecraftVersion getOneVersion();
/**
* All Minecraft version in this profile.
*
* @return the collection of all Minecraft version
*/
public abstract Collection<MinecraftVersion> getVersions();
/**
* Get the Minecraft json instance of given version.
*
* @param id the given version name
*
* @return the Minecraft json instance
*/
public abstract MinecraftVersion getVersionById(String id);
/**
* getVersions().size()
*
* @return getVersions().size()
*/
public abstract int getVersionCount();
/**
* Refind the versions in this profile.
*/
public abstract void refreshVersions();
/**
* Clean redundant files.
*/
public abstract void cleanFolder();
/**
* When GameLauncher launches the game, this function will be called.
*
* @return if false, will break the launch process.
*/
public abstract boolean onLaunch();
}
@@ -0,0 +1,60 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.service;
import java.io.File;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
import org.jackhuang.hellominecraft.launcher.core.launch.LaunchOptions;
/**
*
* @author huangyuhui
*/
public abstract class IMinecraftService {
public abstract File baseDirectory();
public DownloadType getDownloadType() {
return DownloadType.getSuggestedDownloadType();
}
public abstract IMinecraftAssetService asset();
public abstract IMinecraftDownloadService download();
public abstract IMinecraftModService mod();
public abstract IMinecraftProvider version();
public abstract IMinecraftInstallerService install();
/**
* Provide the Minecraft Loader to generate the launching command.
*
* @see org.jackhuang.hellominecraft.launcher.core.service.IMinecraftLoader
* @param p player informations, including username & auth_token
*
* @return what you want
*
* @throws GameException circular denpendency versions
*/
public abstract IMinecraftLoader launch(LaunchOptions options, UserProfileProvider p) throws GameException;
}
@@ -0,0 +1,38 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.version;
import java.io.File;
/**
*
* @author huangyuhui
*/
public class DecompressLibraryJob {
public File[] decompressFiles;
public String[][] extractRules;
public File decompressTo;
public DecompressLibraryJob(File[] decompressFiles, String[][] extractRules, File decompressTo) {
this.decompressFiles = decompressFiles;
this.extractRules = extractRules;
this.decompressTo = decompressTo;
}
}
@@ -1,20 +1,21 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.version;
package org.jackhuang.hellominecraft.launcher.core.version;
import java.util.Arrays;
@@ -1,20 +1,21 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.version;
package org.jackhuang.hellominecraft.launcher.core.version;
/**
*
@@ -1,23 +1,24 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.version;
package org.jackhuang.hellominecraft.launcher.core.version;
import java.io.File;
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
/**
*
@@ -1,26 +1,26 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.version;
package org.jackhuang.hellominecraft.launcher.core.version;
import java.io.File;
import java.util.ArrayList;
import java.util.Set;
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftProvider;
/**
*
@@ -48,7 +48,7 @@ public class MinecraftClassicVersion extends MinecraftVersion {
}
@Override
public MinecraftVersion resolve(IMinecraftProvider manager, Set<String> resolvedSoFar, DownloadType sourceType) {
public MinecraftVersion resolve(IMinecraftProvider manager, Set<String> resolvedSoFar) {
return this;
}
@@ -1,25 +1,26 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.version;
package org.jackhuang.hellominecraft.launcher.core.version;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
import org.jackhuang.hellominecraft.utils.system.OS;
import org.jackhuang.hellominecraft.utils.system.Platform;
import org.jackhuang.hellominecraft.utils.StrUtils;
@@ -104,10 +105,10 @@ public class MinecraftLibrary extends IMinecraftLibrary {
str = str.replace('.', File.separatorChar);
if (natives == null)
str += File.separator + s[1] + File.separator + s[2]
+ File.separator + s[1] + '-' + s[2] + ".jar";
+ File.separator + s[1] + '-' + s[2] + ".jar";
else {
str += File.separator + s[1] + File.separator + s[2]
+ File.separator + s[1] + '-' + s[2] + '-';
+ File.separator + s[1] + '-' + s[2] + '-';
str += getNative();
str += ".jar";
}
@@ -121,8 +122,10 @@ public class MinecraftLibrary extends IMinecraftLibrary {
@Override
public String getDownloadURL(String urlBase, DownloadType downloadType) {
if (StrUtils.isNotBlank(url) && downloadType.getProvider().isAllowedToUseSelfURL()) urlBase = this.url;
if (urlBase.endsWith(".jar")) return urlBase;
if (StrUtils.isNotBlank(url) && downloadType.getProvider().isAllowedToUseSelfURL())
urlBase = this.url;
if (urlBase.endsWith(".jar"))
return urlBase;
return urlBase + formatted.replace('\\', '/');
}
@@ -1,23 +1,24 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.version;
package org.jackhuang.hellominecraft.launcher.core.version;
import java.io.File;
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
/**
*
@@ -1,29 +1,31 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.version;
package org.jackhuang.hellominecraft.launcher.core.version;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
import org.jackhuang.hellominecraft.launcher.utils.assets.AssetsIndex;
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftProvider;
import org.jackhuang.hellominecraft.launcher.core.assets.AssetsIndex;
import org.jackhuang.hellominecraft.utils.ArrayUtils;
/**
@@ -33,7 +35,7 @@ import org.jackhuang.hellominecraft.utils.ArrayUtils;
public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion> {
public String minecraftArguments, mainClass, time, id, type, processArguments,
releaseTime, assets, jar, inheritsFrom;
releaseTime, assets, jar, inheritsFrom, runDir;
public int minimumLauncherVersion;
public boolean hidden;
@@ -42,7 +44,7 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
public MinecraftVersion() {
}
public MinecraftVersion(String minecraftArguments, String mainClass, String time, String id, String type, String processArguments, String releaseTime, String assets, String jar, String inheritsFrom, int minimumLauncherVersion, List<MinecraftLibrary> libraries, boolean hidden) {
public MinecraftVersion(String minecraftArguments, String mainClass, String time, String id, String type, String processArguments, String releaseTime, String assets, String jar, String inheritsFrom, String runDir, int minimumLauncherVersion, List<MinecraftLibrary> libraries, boolean hidden) {
this();
this.minecraftArguments = minecraftArguments;
this.mainClass = mainClass;
@@ -56,7 +58,9 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
this.inheritsFrom = inheritsFrom;
this.minimumLauncherVersion = minimumLauncherVersion;
this.hidden = hidden;
if (libraries == null) this.libraries = new ArrayList<>();
this.runDir = runDir;
if (libraries == null)
this.libraries = new ArrayList<>();
else {
this.libraries = new ArrayList<>(libraries.size());
for (IMinecraftLibrary library : libraries)
@@ -66,33 +70,34 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
@Override
public Object clone() {
return new MinecraftVersion(minecraftArguments, mainClass, time, id, type, processArguments, releaseTime, assets, jar, inheritsFrom, minimumLauncherVersion, libraries, hidden);
return new MinecraftVersion(minecraftArguments, mainClass, time, id, type, processArguments, releaseTime, assets, jar, inheritsFrom, runDir, minimumLauncherVersion, libraries, hidden);
}
public MinecraftVersion resolve(IMinecraftProvider manager, DownloadType sourceType) {
return resolve(manager, new HashSet<>(), sourceType);
public MinecraftVersion resolve(IMinecraftProvider provider) throws GameException {
return resolve(provider, new HashSet<>());
}
protected MinecraftVersion resolve(IMinecraftProvider manager, Set<String> resolvedSoFar, DownloadType sourceType) {
protected MinecraftVersion resolve(IMinecraftProvider provider, Set<String> resolvedSoFar) throws GameException {
if (inheritsFrom == null)
return this;
if (!resolvedSoFar.add(id))
throw new IllegalStateException("Circular dependency detected.");
throw new GameException(C.i18n("launch.circular_dependency_versions"));
MinecraftVersion parent = manager.getVersionById(inheritsFrom);
MinecraftVersion parent = provider.getVersionById(inheritsFrom);
if (parent == null) {
if (!manager.install(inheritsFrom, sourceType)) return this;
parent = manager.getVersionById(inheritsFrom);
if (!provider.install(inheritsFrom, t -> t.hidden = true))
return this;
parent = provider.getVersionById(inheritsFrom);
}
parent = parent.resolve(manager, resolvedSoFar, sourceType);
parent = parent.resolve(provider, resolvedSoFar);
MinecraftVersion result = new MinecraftVersion(
this.minecraftArguments != null ? this.minecraftArguments : parent.minecraftArguments,
this.mainClass != null ? this.mainClass : parent.mainClass,
this.time, this.id, this.type, parent.processArguments, this.releaseTime,
this.assets != null ? this.assets : parent.assets,
this.jar != null ? this.jar : parent.jar,
null, parent.minimumLauncherVersion,
this.libraries != null ? ArrayUtils.merge(this.libraries, parent.libraries) : parent.libraries, this.hidden);
this.minecraftArguments != null ? this.minecraftArguments : parent.minecraftArguments,
this.mainClass != null ? this.mainClass : parent.mainClass,
this.time, this.id, this.type, parent.processArguments, this.releaseTime,
this.assets != null ? this.assets : parent.assets,
this.jar != null ? this.jar : parent.jar,
null, this.runDir, parent.minimumLauncherVersion,
this.libraries != null ? ArrayUtils.merge(this.libraries, parent.libraries) : parent.libraries, this.hidden);
return result;
}
@@ -109,7 +114,7 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
public File getNatives(File gameDir) {
return new File(gameDir, "versions/" + id + "/" + id
+ "-natives");
+ "-natives");
}
public boolean isAllowedToUnpackNatives() {
@@ -0,0 +1,288 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.version;
import com.google.gson.JsonSyntaxException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.TreeMap;
import org.jackhuang.hellominecraft.utils.C;
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftProvider;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.utils.system.FileUtils;
import org.jackhuang.hellominecraft.launcher.core.MCUtils;
import org.jackhuang.hellominecraft.utils.tasks.DecompressTask;
import org.jackhuang.hellominecraft.utils.tasks.TaskWindow;
import org.jackhuang.hellominecraft.utils.tasks.download.FileDownloadTask;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
import org.jackhuang.hellominecraft.utils.MessageBox;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.utils.functions.Consumer;
import org.jackhuang.hellominecraft.utils.views.SwingUtils;
/**
*
* @author huangyuhui
*/
public class MinecraftVersionManager extends IMinecraftProvider {
final Map<String, MinecraftVersion> versions = new TreeMap();
/**
*
* @param p
*/
public MinecraftVersionManager(IMinecraftService p) {
super(p);
}
@Override
public Collection<MinecraftVersion> getVersions() {
return versions.values();
}
@Override
public int getVersionCount() {
return versions.size();
}
@Override
public void refreshVersions() {
try {
MCUtils.tryWriteProfile(service.baseDirectory());
} catch (IOException ex) {
HMCLog.warn("Failed to create launcher_profiles.json, Forge/LiteLoader installer will not work.", ex);
}
versions.clear();
File oldDir = new File(service.baseDirectory(), "bin");
if (oldDir.exists()) {
MinecraftClassicVersion v = new MinecraftClassicVersion();
versions.put(v.id, v);
}
File version = new File(service.baseDirectory(), "versions");
File[] files = version.listFiles();
if (files == null || files.length == 0)
return;
for (File dir : files) {
String id = dir.getName();
File jsonFile = new File(dir, id + ".json");
if (!dir.isDirectory())
continue;
boolean ask = false;
File[] jsons = null;
if (!jsonFile.exists()) {
jsons = FileUtils.searchSuffix(dir, "json");
if (jsons.length == 1)
ask = true;
}
if (ask) {
HMCLog.warn("Found not matched filenames version: " + id + ", json: " + jsons[0].getName());
if (MessageBox.Show(String.format(C.i18n("launcher.versions_json_not_matched"), id, jsons[0].getName()), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
jsons[0].renameTo(new File(jsons[0].getParent(), id + ".json"));
}
if (!jsonFile.exists()) {
if (MessageBox.Show(C.i18n("launcher.versions_json_not_matched_cannot_auto_completion", id), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
FileUtils.deleteDirectoryQuietly(dir);
continue;
}
MinecraftVersion mcVersion;
try {
mcVersion = C.gson.fromJson(FileUtils.readFileToString(jsonFile), MinecraftVersion.class);
if (mcVersion == null)
throw new GameException("Wrong json format, got null.");
} catch (IOException | GameException e) {
HMCLog.warn("Found wrong format json, try to fix it.", e);
if (MessageBox.Show(C.i18n("launcher.versions_json_not_formatted", id), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
service.download().downloadMinecraftVersionJson(id);
try {
mcVersion = C.gson.fromJson(FileUtils.readFileToString(jsonFile), MinecraftVersion.class);
if (mcVersion == null)
throw new GameException("Wrong json format, got null.");
} catch (IOException | GameException ex) {
HMCLog.warn("Ignoring: " + dir + ", the json of this Minecraft is malformed.", ex);
continue;
}
} else
continue;
}
try {
if (!id.equals(mcVersion.id)) {
HMCLog.warn("Found: " + dir + ", it contains id: " + mcVersion.id + ", expected: " + id + ", this app will fix this problem.");
mcVersion.id = id;
FileUtils.writeQuietly(jsonFile, C.gsonPrettyPrinting.toJson(mcVersion));
}
if (mcVersion.libraries != null)
for (MinecraftLibrary ml : mcVersion.libraries)
ml.init();
versions.put(id, mcVersion);
} catch (Exception e) {
HMCLog.warn("Ignoring: " + dir + ", the json of this Minecraft is malformed.", e);
}
}
}
@Override
public boolean removeVersionFromDisk(String name) {
File version = new File(service.baseDirectory(), "versions/" + name);
if (!version.exists())
return true;
versions.remove(name);
return FileUtils.deleteDirectoryQuietly(version);
}
@Override
public boolean renameVersion(String from, String to) {
try {
File fromJson = new File(service.baseDirectory(), "versions/" + from + "/" + from + ".json");
MinecraftVersion mcVersion = C.gson.fromJson(FileUtils.readFileToString(fromJson), MinecraftVersion.class);
mcVersion.id = to;
FileUtils.writeQuietly(fromJson, C.gsonPrettyPrinting.toJson(mcVersion));
File toDir = new File(service.baseDirectory(), "versions/" + to);
new File(service.baseDirectory(), "versions/" + from).renameTo(toDir);
File toJson = new File(toDir, to + ".json");
File toJar = new File(toDir, to + ".jar");
new File(toDir, from + ".json").renameTo(toJson);
File newJar = new File(toDir, from + ".jar");
if (newJar.exists())
newJar.renameTo(toJar);
return true;
} catch (IOException | JsonSyntaxException e) {
HMCLog.warn("Failed to rename " + from + " to " + to + ", the json of this Minecraft is malformed.", e);
return false;
}
}
@Override
public File getRunDirectory(String id) {
if ("version".equals(versions.get(id).runDir))
return new File(service.baseDirectory(), "versions/" + id + "/");
switch (gameDirType) {
case VERSION_FOLDER:
return new File(service.baseDirectory(), "versions/" + id + "/");
default:
return service.baseDirectory();
}
}
@Override
public boolean install(String id, Consumer<MinecraftVersion> callback) {
MinecraftVersion v = service.download().downloadMinecraft(id);
if (callback != null) {
callback.accept(v);
File mvt = new File(service.baseDirectory(), "versions/" + id + "/" + id + ".json");
FileUtils.writeQuietly(mvt, C.gsonPrettyPrinting.toJson(v));
}
if (v != null) {
refreshVersions();
return true;
}
return false;
}
@Override
public void open(String mv, String name) {
SwingUtils.openFolder((name == null) ? getRunDirectory(mv) : new File(getRunDirectory(mv), name));
}
@Override
public DecompressLibraryJob getDecompressLibraries(MinecraftVersion v) throws GameException {
if (v.libraries == null)
throw new GameException("Wrong format: minecraft.json");
ArrayList<File> unzippings = new ArrayList<>();
ArrayList<String[]> extractRules = new ArrayList<>();
for (IMinecraftLibrary l : v.libraries) {
l.init();
if (l.isRequiredToUnzip() && v.isAllowedToUnpackNatives()) {
unzippings.add(IOUtils.tryGetCanonicalFile(l.getFilePath(service.baseDirectory())));
extractRules.add(l.getDecompressExtractRules());
}
}
return new DecompressLibraryJob(unzippings.toArray(new File[0]), extractRules.toArray(new String[0][]), getDecompressNativesToLocation(v));
}
@Override
public File getDecompressNativesToLocation(MinecraftVersion v) {
return v == null ? null : v.getNatives(service.baseDirectory());
}
@Override
public File getMinecraftJar(String id) {
if (versions.containsKey(id))
return versions.get(id).getJar(service.baseDirectory());
else
return null;
}
@Override
public MinecraftVersion getOneVersion() {
return versions.isEmpty() ? null : versions.values().iterator().next();
}
@Override
public MinecraftVersion getVersionById(String id) {
return StrUtils.isBlank(id) ? null : versions.get(id);
}
@Override
public File getResourcePacks() {
return new File(service.baseDirectory(), "resourcepacks");
}
@Override
public boolean onLaunch() {
File resourcePacks = getResourcePacks();
if (!resourcePacks.exists())
resourcePacks.mkdirs();
return true;
}
@Override
public void cleanFolder() {
for (MinecraftVersion s : getVersions()) {
FileUtils.deleteDirectoryQuietly(new File(service.baseDirectory(), "versions" + File.separator + s.id + File.separator + s.id + "-natives"));
File f = getRunDirectory(s.id);
String[] dir = { "logs", "asm", "NVIDIA", "crash-reports", "server-resource-packs", "natives", "native" };
for (String str : dir)
FileUtils.deleteDirectoryQuietly(new File(f, str));
String[] files = { "output-client.log", "usercache.json", "usernamecache.json", "hmclmc.log" };
for (String str : files)
new File(f, str).delete();
}
}
@Override
public void initializeMiencraft() {
}
private void downloadModpack(String url) throws IOException {
File tmp = File.createTempFile("hmcl", ".zip");
TaskWindow.getInstance().addTask(new FileDownloadTask(url, tmp)).addTask(new DecompressTask(tmp, service.baseDirectory())).start();
}
}
@@ -1,20 +1,21 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.version;
package org.jackhuang.hellominecraft.launcher.core.version;
/**
*
@@ -1,20 +1,21 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.version;
package org.jackhuang.hellominecraft.launcher.core.version;
/**
*
@@ -1,20 +1,21 @@
/*
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software; you can redistribute it and/or modify
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 2 of the License, or
* 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
* 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.
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.version;
package org.jackhuang.hellominecraft.launcher.core.version;
/**
*
@@ -0,0 +1,54 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 org.jackhuang.hellominecraft.launcher.core.version;
import java.io.File;
import java.util.HashMap;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import org.jackhuang.hellominecraft.utils.tasks.download.FileDownloadTask;
import org.jackhuang.hellominecraft.utils.Utils;
/**
*
* @author huangyuhui
*/
public class ServerInfo {
public String name, addr, picurl, type, info, wfjc, tsjs, version, url, depend;
public String[] md5;
public int port;
public Icon icon;
public static final HashMap<String, Icon> CACHE = new HashMap<>();
public void downloadIcon() {
if (icon == null && Utils.isURL(picurl))
if (CACHE.containsKey(picurl))
icon = CACHE.get(picurl);
else
try {
File tmp = File.createTempFile("HMCLSERVER", ".png");
FileDownloadTask.download(picurl, tmp, null);
CACHE.put(picurl, icon = new ImageIcon(tmp.getAbsolutePath()));
} catch (Throwable e) {
throw new RuntimeException("Failed to download icon", e);
}
}
}
Loaded 100 of 662 files, more files were not shown because too many files have changed in this diff. Show more