Api
This commit is contained in:
@@ -39,7 +39,7 @@ import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipFile
|
||||
|
||||
if (!hasProperty('mainClass')) {
|
||||
ext.mainClass = 'org.jackhuang.hellominecraft.launcher.Main'
|
||||
ext.mainClass = 'org.jackhuang.hmcl.Main'
|
||||
}
|
||||
|
||||
def buildnumber = System.getenv("TRAVIS_BUILD_NUMBER")
|
||||
@@ -63,7 +63,6 @@ String mavenArtifactId = name
|
||||
|
||||
task generateSources(type: Copy) {
|
||||
from 'src/main/java'
|
||||
from 'src/core/java'
|
||||
into "$buildDir/generated-src"
|
||||
filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [
|
||||
'HELLO_MINECRAFT_LAUNCHER_VERSION_FOR_GRADLE_REPLACING': mavenVersion
|
||||
@@ -85,30 +84,6 @@ macAppBundle {
|
||||
javaProperties.put("apple.laf.useScreenMenuBar", "true")
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
java {
|
||||
srcDirs = [
|
||||
'src/core/java/',
|
||||
'src/main/java/'
|
||||
]
|
||||
}
|
||||
resources {
|
||||
srcDirs = ['src/main/resources/']
|
||||
}
|
||||
}
|
||||
core {
|
||||
java {
|
||||
compileClasspath += main.compileClasspath
|
||||
runtimeClasspath += main.runtimeClasspath
|
||||
srcDirs 'src/core/java/'
|
||||
}
|
||||
resources {
|
||||
srcDirs 'src/main/resources/'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
configurations {
|
||||
coreCompile.extendsFrom compile
|
||||
coreRuntime.extendsFrom runtime
|
||||
@@ -124,26 +99,26 @@ configure(install.repositories.mavenInstaller) {
|
||||
|
||||
dependencies {
|
||||
compile project(":HMCLaF")
|
||||
compile project(":HMCUtils")
|
||||
compile group: "org.commonjava.googlecode.markdown4j", name: "markdown4j", version: "2.2-cj-1.0"
|
||||
compile project(":HMCLAPI")
|
||||
compile project(":HMCLCore")
|
||||
}
|
||||
|
||||
retrolambda {
|
||||
javaVersion = JavaVersion.VERSION_1_6
|
||||
javaVersion = JavaVersion.VERSION_1_7
|
||||
}
|
||||
|
||||
jar {
|
||||
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
|
||||
|
||||
manifest {
|
||||
attributes 'Created-By' : 'Copyright(c) 2013-2016 huangyuhui.',
|
||||
attributes 'Created-By' : 'Copyright(c) 2013-2017 huangyuhui.',
|
||||
'Main-Class' : mainClass
|
||||
}
|
||||
}
|
||||
|
||||
launch4j {
|
||||
supportUrl = 'http://www.mcbbs.net/thread-142335-1-1.html'
|
||||
jreMinVersion = '1.6.0'
|
||||
jreMinVersion = '1.7.0'
|
||||
|
||||
mainClassName = mainClass
|
||||
icon = new File(project.buildDir, '../icon.ico').absolutePath
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* 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.util.ui.Page;
|
||||
|
||||
/**
|
||||
* Used for adding tab page to MainFrame.
|
||||
*
|
||||
* @author huang
|
||||
*/
|
||||
public interface AddTabCallback {
|
||||
|
||||
/**
|
||||
* Add your tab page to MainFrame.
|
||||
*
|
||||
* @param tabPage your customized tab page.
|
||||
* @param id the id of your page.
|
||||
* @param title you are supposed to localize your texts.
|
||||
*/
|
||||
void addTab(Page tabPage, String id, String title);
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* 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 javax.swing.JFrame;
|
||||
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
|
||||
import org.jackhuang.hellominecraft.util.func.Consumer;
|
||||
|
||||
/**
|
||||
* Each plugin must implement this interface.
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public interface IPlugin {
|
||||
|
||||
/**
|
||||
* Register authenticators by calling IAuthenticator.LOGINS.add.
|
||||
*
|
||||
* @param apply call apply.accept(your authenticator)
|
||||
*/
|
||||
void onRegisterAuthenticators(Consumer<IAuthenticator> apply);
|
||||
|
||||
/**
|
||||
* Call callback.addTab to add your customized panel to MainFrame RootPane.
|
||||
*
|
||||
* @param frame MainFrame
|
||||
* @param callback call this if you want.
|
||||
*/
|
||||
void onAddTab(JFrame frame, AddTabCallback callback);
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* 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 java.util.ArrayList;
|
||||
import javax.swing.JFrame;
|
||||
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
|
||||
import org.jackhuang.hellominecraft.util.func.Consumer;
|
||||
|
||||
/**
|
||||
* Can be only called by HMCL.
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class PluginManager {
|
||||
|
||||
private static final ArrayList<IPlugin> PLUGINS = new ArrayList<>();
|
||||
|
||||
public static void getPlugin(Class<?> cls) {
|
||||
try {
|
||||
IPlugin p = (IPlugin) cls.newInstance();
|
||||
PLUGINS.add(p);
|
||||
} catch (Throwable e) {
|
||||
System.err.println("Failed to new instance");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void fireRegisterAuthenticators(Consumer<IAuthenticator> callback) {
|
||||
for (IPlugin p : PLUGINS)
|
||||
p.onRegisterAuthenticators(callback);
|
||||
}
|
||||
|
||||
public static void fireAddTab(JFrame frame, AddTabCallback callback) {
|
||||
for (IPlugin p : PLUGINS)
|
||||
p.onAddTab(frame, callback);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* 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.event.config;
|
||||
|
||||
import org.jackhuang.hellominecraft.api.SimpleEvent;
|
||||
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
|
||||
|
||||
/**
|
||||
* This event gets fired when the authenticator changed.
|
||||
* <br>
|
||||
* This event is fired on the {@link org.jackhuang.hellominecraft.api.HMCAPI#EVENT_BUS}
|
||||
* @param source {@link org.jackhuang.hellominecraft.launcher.setting.Config}
|
||||
* @param IAuthenticator the new authenticator.
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class AuthenticatorChangedEvent extends SimpleEvent<IAuthenticator> {
|
||||
|
||||
public AuthenticatorChangedEvent(Object source, IAuthenticator value) {
|
||||
super(source, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* 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.event.config;
|
||||
|
||||
import org.jackhuang.hellominecraft.api.SimpleEvent;
|
||||
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
|
||||
|
||||
/**
|
||||
* This event gets fired when the download type changed.
|
||||
* <br>
|
||||
* This event is fired on the {@link org.jackhuang.hellominecraft.api.HMCAPI#EVENT_BUS}
|
||||
* @param source {@link org.jackhuang.hellominecraft.launcher.setting.Config}
|
||||
* @param DownloadType the new downlaod type
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class DownloadTypeChangedEvent extends SimpleEvent<DownloadType> {
|
||||
|
||||
public DownloadTypeChangedEvent(Object source, DownloadType value) {
|
||||
super(source, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* 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.event.config;
|
||||
|
||||
import org.jackhuang.hellominecraft.api.SimpleEvent;
|
||||
import org.jackhuang.hellominecraft.lookandfeel.Theme;
|
||||
|
||||
/**
|
||||
* This event gets fired when the application theme changed.
|
||||
* <br>
|
||||
* This event is fired on the {@link org.jackhuang.hellominecraft.api.HMCAPI#EVENT_BUS}
|
||||
* @param source {@link org.jackhuang.hellominecraft.launcher.setting.Config}
|
||||
* @param Theme the changed theme
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class ThemeChangedEvent extends SimpleEvent<Theme> {
|
||||
|
||||
public ThemeChangedEvent(Object source, Theme value) {
|
||||
super(source, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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.event.launch;
|
||||
|
||||
import org.jackhuang.hellominecraft.api.ResultedSimpleEvent;
|
||||
|
||||
/**
|
||||
* This event gets fired when we are launching a game and going to decompress natives.
|
||||
* <br>
|
||||
* This event is {@link org.jackhuang.hellominecraft.api.ResultedEvent}
|
||||
* If this event is failed, the launching process will be terminated.
|
||||
* <br>
|
||||
* This event is fired on the {@link org.jackhuang.hellominecraft.api.HMCAPI#EVENT_BUS}
|
||||
* @param source {@link org.jackhuang.hellominecraft.launcher.core.launch.GameLauncher}
|
||||
* @param DecompressLibraryJob libraries to be decompressed
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class DecompressLibrariesEvent extends ResultedSimpleEvent<DecompressLibraryJob> {
|
||||
|
||||
public DecompressLibrariesEvent(Object source, DecompressLibraryJob value) {
|
||||
super(source, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* 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.event.launch;
|
||||
|
||||
import java.io.File;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.Extract;
|
||||
|
||||
/**
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class DecompressLibraryJob {
|
||||
|
||||
public File[] decompressFiles;
|
||||
public Extract[] extractRules;
|
||||
private File decompressTo;
|
||||
|
||||
/**
|
||||
* The length of these 2 arrays must be the same.
|
||||
*
|
||||
* @param decompressFiles
|
||||
* @param extractRules
|
||||
* @param decompressTo folder
|
||||
*/
|
||||
public DecompressLibraryJob(File[] decompressFiles, Extract[] extractRules, File decompressTo) {
|
||||
this.decompressFiles = decompressFiles.clone();
|
||||
this.extractRules = extractRules.clone();
|
||||
this.decompressTo = decompressTo;
|
||||
}
|
||||
|
||||
public File getDecompressTo() {
|
||||
return decompressTo;
|
||||
}
|
||||
|
||||
public void setDecompressTo(File decompressTo) {
|
||||
this.decompressTo = decompressTo;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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.event.launch;
|
||||
|
||||
import java.util.List;
|
||||
import org.jackhuang.hellominecraft.api.ResultedSimpleEvent;
|
||||
|
||||
/**
|
||||
* This event gets fired when we are launching a game and there are some libraries to be downloaded.
|
||||
* <br>
|
||||
* This event is {@link org.jackhuang.hellominecraft.api.ResultedEvent}
|
||||
* If this event is failed, the launching process will be terminated.
|
||||
* <br>
|
||||
* This event is fired on the {@link org.jackhuang.hellominecraft.api.HMCAPI#EVENT_BUS}
|
||||
* @param source {@link org.jackhuang.hellominecraft.launcher.core.launch.GameLauncher}
|
||||
* Passed value List<DownloadLibraryJob>: libraries to be downloaded.
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class DownloadLibrariesEvent extends ResultedSimpleEvent<List<DownloadLibraryJob>> {
|
||||
|
||||
public DownloadLibrariesEvent(Object sender, List<DownloadLibraryJob> lists) {
|
||||
super(sender, lists);
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* 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.event.launch;
|
||||
|
||||
import java.io.File;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.IMinecraftLibrary;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class DownloadLibraryJob {
|
||||
|
||||
public IMinecraftLibrary lib;
|
||||
public String url;
|
||||
public File path;
|
||||
|
||||
public DownloadLibraryJob(IMinecraftLibrary n, String u, File p) {
|
||||
url = u;
|
||||
lib = n;
|
||||
path = p;
|
||||
}
|
||||
|
||||
public DownloadLibraryJob parse() {
|
||||
String name = lib.name;
|
||||
if (name.startsWith("net.minecraftforge:forge:")) {
|
||||
String[] s = name.split(":");
|
||||
if (s.length == 3)
|
||||
url = "http://files.minecraftforge.net/maven/net/minecraftforge/forge/" + s[2] + "/forge-" + s[2] + "-universal.jar";
|
||||
}
|
||||
if (name.startsWith("com.mumfrey:liteloader:")) {
|
||||
String[] s = name.split(":");
|
||||
if (s.length == 3 && s[2].length() > 3)
|
||||
url = "http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + s[2].substring(0, s[2].length() - 3) + "/liteloader-" + s[2] + ".jar";
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* 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.event.launch;
|
||||
|
||||
import org.jackhuang.hellominecraft.api.SimpleEvent;
|
||||
import org.jackhuang.hellominecraft.util.sys.JavaProcess;
|
||||
|
||||
/**
|
||||
* This event gets fired when we launched the game.
|
||||
* <br>
|
||||
* This event is fired on the {@link org.jackhuang.hellominecraft.api.HMCAPI#EVENT_BUS}
|
||||
* @param source {@link org.jackhuang.hellominecraft.launcher.core.launch.GameLauncher}
|
||||
* @param JavaProcess the game process
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class LaunchEvent extends SimpleEvent<JavaProcess> {
|
||||
|
||||
public LaunchEvent(Object source, JavaProcess value) {
|
||||
super(source, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* 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.event.launch;
|
||||
|
||||
import java.util.List;
|
||||
import org.jackhuang.hellominecraft.api.SimpleEvent;
|
||||
|
||||
/**
|
||||
* This event gets fired when we make the launching command successfully(not launched the game process).
|
||||
* <br>
|
||||
* This event is fired on the {@link org.jackhuang.hellominecraft.api.HMCAPI#EVENT_BUS}
|
||||
* @param source {@link org.jackhuang.hellominecraft.launcher.core.launch.GameLauncher}
|
||||
* @param List<String> Our launching command.
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class LaunchSucceededEvent extends SimpleEvent<List<String>>{
|
||||
|
||||
public LaunchSucceededEvent(Object source, List<String> value) {
|
||||
super(source, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* 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.event.launch;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public enum LaunchingState {
|
||||
Starting,
|
||||
LoggingIn,
|
||||
GeneratingLaunchingCodes,
|
||||
DownloadingLibraries,
|
||||
DecompressingNatives,
|
||||
Done
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* 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.event.launch;
|
||||
|
||||
import org.jackhuang.hellominecraft.api.SimpleEvent;
|
||||
|
||||
/**
|
||||
* This event gets fired when we are launching a game and mark what things we are doing.
|
||||
* <br>
|
||||
* This event is fired on the {@link org.jackhuang.hellominecraft.api.HMCAPI#EVENT_BUS}
|
||||
* @param source {@link org.jackhuang.hellominecraft.launcher.core.launch.GameLauncher}
|
||||
* @param LaunchingState the launching state.
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class LaunchingStateChangedEvent extends SimpleEvent<LaunchingState> {
|
||||
|
||||
public LaunchingStateChangedEvent(Object source, LaunchingState value) {
|
||||
super(source, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* 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.event.launch;
|
||||
|
||||
import org.jackhuang.hellominecraft.api.SimpleEvent;
|
||||
import org.jackhuang.hellominecraft.launcher.core.launch.LaunchOptions;
|
||||
|
||||
/**
|
||||
* This event gets fired before generating launch command.
|
||||
* <br>
|
||||
* Pay attension: If you need to terminate the launching process, you must throw
|
||||
* {@link org.jackhuang.hellominecraft.launcher.core.RuntimeGameException anyway.
|
||||
* <br>
|
||||
* This event is fired on the {@link org.jackhuang.hellominecraft.api.HMCAPI#EVENT_BUS}
|
||||
* @param source {@link org.jackhuang.hellominecraft.launcher.core.launch.GameLauncher}
|
||||
* @param LaunchOptions you can modify the value of this event to control the launching process.
|
||||
* @author huang
|
||||
*/
|
||||
public class ProcessingLaunchOptionsEvent extends SimpleEvent<LaunchOptions> {
|
||||
|
||||
public ProcessingLaunchOptionsEvent(Object source, LaunchOptions value) {
|
||||
super(source, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* 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.event.launch;
|
||||
|
||||
import org.jackhuang.hellominecraft.api.SimpleEvent;
|
||||
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
|
||||
|
||||
/**
|
||||
* This event gets fired when we successfully logged in.
|
||||
* <br>
|
||||
* Pay attension: If you need to terminate the launching process, you must throw
|
||||
* {@link org.jackhuang.hellominecraft.launcher.core.RuntimeGameException anyway.
|
||||
* <br>
|
||||
* This event is fired on the {@link org.jackhuang.hellominecraft.api.HMCAPI#EVENT_BUS}
|
||||
* @param source {@link org.jackhuang.hellominecraft.launcher.core.launch.GameLauncher}
|
||||
* @param UserProfileProvider you can modify the value of this event to control the user profile.
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class ProcessingLoginResultEvent extends SimpleEvent<UserProfileProvider> {
|
||||
|
||||
public ProcessingLoginResultEvent(Object source, UserProfileProvider value) {
|
||||
super(source, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* 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.event.version;
|
||||
|
||||
import org.jackhuang.hellominecraft.api.SimpleEvent;
|
||||
|
||||
/**
|
||||
* This event gets fired when a minecraft version has been loaded.
|
||||
* <br>
|
||||
* This event is fired on the {@link org.jackhuang.hellominecraft.api.HMCAPI#EVENT_BUS}
|
||||
* @param source {@link org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersionManager}
|
||||
* @param String the version id.
|
||||
* @author huang
|
||||
*/
|
||||
public class LoadedOneVersionEvent extends SimpleEvent<String> {
|
||||
|
||||
public LoadedOneVersionEvent(Object source, String value) {
|
||||
super(source, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* 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.event.version;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.EventObject;
|
||||
import org.jackhuang.hellominecraft.util.Wrapper;
|
||||
|
||||
/**
|
||||
* This event gets fired when we getting minecraft library path.
|
||||
* <br>
|
||||
* This event is fired on the {@link org.jackhuang.hellominecraft.api.HMCAPI#EVENT_BUS}
|
||||
* @param source {@link org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary}
|
||||
* @param {@code Wrapper<File>} modify this thing to change to your wanted mc lib.
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class MinecraftLibraryPathEvent extends EventObject {
|
||||
|
||||
String location;
|
||||
Wrapper<File> file;
|
||||
|
||||
public MinecraftLibraryPathEvent(Object source, String location, Wrapper<File> value) {
|
||||
super(source);
|
||||
this.location = location;
|
||||
this.file = value;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public Wrapper<File> getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* 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.event.version;
|
||||
|
||||
import org.jackhuang.hellominecraft.api.SimpleEvent;
|
||||
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
|
||||
|
||||
/**
|
||||
* This event gets fired when all the versions in .minecraft folder are loaded.
|
||||
* <br>
|
||||
* This event is fired on the {@link org.jackhuang.hellominecraft.api.HMCAPI#EVENT_BUS}
|
||||
* @param source {@link org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersionManager}
|
||||
* @param IMinecraftService the .minecraft folder.
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class RefreshedVersionsEvent extends SimpleEvent<IMinecraftService> {
|
||||
|
||||
public RefreshedVersionsEvent(Object source, IMinecraftService value) {
|
||||
super(source, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* 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.event.version;
|
||||
|
||||
import org.jackhuang.hellominecraft.api.SimpleEvent;
|
||||
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
|
||||
|
||||
/**
|
||||
* This event gets fired when loading versions in a .minecraft folder.
|
||||
* <br>
|
||||
* This event is fired on the {@link org.jackhuang.hellominecraft.api.HMCAPI#EVENT_BUS}
|
||||
* @param source {@link org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersionManager}
|
||||
* @param IMinecraftService .minecraft folder.
|
||||
* @author huang
|
||||
*/
|
||||
public class RefreshingVersionsEvent extends SimpleEvent<IMinecraftService> {
|
||||
|
||||
public RefreshingVersionsEvent(Object source, IMinecraftService value) {
|
||||
super(source, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Thrown if we have some problem generating launch command.
|
||||
* @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,81 +0,0 @@
|
||||
/*
|
||||
* 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.util.sys.FileUtils;
|
||||
import org.jackhuang.hellominecraft.util.sys.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 String minecraft() {
|
||||
if (OS.os() == OS.OSX)
|
||||
return "minecraft";
|
||||
return ".minecraft";
|
||||
}
|
||||
|
||||
public static File getInitGameDir() {
|
||||
File gameDir = new File(MCUtils.minecraft());
|
||||
if (!gameDir.exists()) {
|
||||
File newFile = MCUtils.getLocation();
|
||||
if (newFile.exists())
|
||||
gameDir = newFile;
|
||||
}
|
||||
return gameDir;
|
||||
}
|
||||
|
||||
public static final 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.write(file, PROFILE);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* 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 huang
|
||||
*/
|
||||
public class RuntimeGameException extends RuntimeException {
|
||||
|
||||
public RuntimeGameException() {
|
||||
}
|
||||
|
||||
public RuntimeGameException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public RuntimeGameException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public RuntimeGameException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* 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.asset;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class AssetsIndex {
|
||||
|
||||
public static final String DEFAULT_ASSET_NAME = "legacy";
|
||||
|
||||
@SerializedName("objects")
|
||||
public Map<String, AssetsObject> objects;
|
||||
|
||||
@SerializedName("virtual")
|
||||
public boolean virtual;
|
||||
|
||||
public AssetsIndex() {
|
||||
this.objects = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
public Map<String, AssetsObject> getFileMap() {
|
||||
return this.objects;
|
||||
}
|
||||
|
||||
public Set<AssetsObject> getUniqueObjects() {
|
||||
return new HashSet<>(this.objects.values());
|
||||
}
|
||||
|
||||
public boolean isVirtual() {
|
||||
return this.virtual;
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
* 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.asset;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.util.log.HMCLog;
|
||||
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftAssetService;
|
||||
import org.jackhuang.hellominecraft.util.task.Task;
|
||||
import org.jackhuang.hellominecraft.util.sys.FileUtils;
|
||||
import org.jackhuang.hellominecraft.util.sys.IOUtils;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
import org.jackhuang.hellominecraft.launcher.core.download.IDownloadProvider;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
|
||||
import org.jackhuang.hellominecraft.util.VersionNumber;
|
||||
import org.jackhuang.hellominecraft.util.task.TaskInfo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class AssetsMojangLoader extends IAssetsHandler {
|
||||
|
||||
public AssetsMojangLoader(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task getList(final MinecraftVersion mv, final IMinecraftAssetService mp) {
|
||||
Objects.requireNonNull(mv);
|
||||
String assetsId = mv.getAssetsIndex().getId();
|
||||
File assets = mp.getAssets(assetsId);
|
||||
HMCLog.log("Gathering asset index: " + assetsId);
|
||||
File f = mp.getIndexFile(assetsId);
|
||||
return new TaskInfo("Gather asset index") {
|
||||
@Override
|
||||
public Collection<Task> getDependTasks() {
|
||||
if (!f.exists())
|
||||
return Arrays.asList(mp.downloadMinecraftAssetsIndex(mv.getAssetsIndex()));
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
if (!areDependTasksSucceeded)
|
||||
throw new IllegalStateException("Failed to get asset index");
|
||||
String result = FileUtils.read(f);
|
||||
if (StrUtils.isBlank(result))
|
||||
throw new IllegalStateException("Index json is empty, please redownload it!");
|
||||
AssetsIndex o = C.GSON.fromJson(result, AssetsIndex.class);
|
||||
assetsDownloadURLs = new ArrayList<>();
|
||||
assetsLocalNames = new ArrayList<>();
|
||||
assetsObjects = new ArrayList<>();
|
||||
HashSet<String> loadedHashes = new HashSet<>();
|
||||
int pgs = 0;
|
||||
if (o != null && o.getFileMap() != null)
|
||||
for (Map.Entry<String, AssetsObject> e : o.getFileMap().entrySet()) {
|
||||
if (loadedHashes.contains(e.getValue().getHash()))
|
||||
continue;
|
||||
loadedHashes.add(e.getValue().getHash());
|
||||
assetsObjects.add(e.getValue());
|
||||
assetsDownloadURLs.add(e.getValue().getLocation());
|
||||
assetsLocalNames.add(mp.getAssetObject(assetsId, e.getValue()));
|
||||
if (ppl != null)
|
||||
ppl.setProgress(this, ++pgs, o.getFileMap().size());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@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,72 +0,0 @@
|
||||
/*
|
||||
* 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.asset;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class AssetsObject {
|
||||
|
||||
private String hash;
|
||||
private long size;
|
||||
|
||||
public void setHash(String hash) {
|
||||
this.hash = hash;
|
||||
}
|
||||
|
||||
public void setSize(long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public AssetsObject(String hash, long size) {
|
||||
this.hash = hash;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public String getHash() {
|
||||
return this.hash;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return this.size;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return hash.substring(0, 2) + "/" + hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
AssetsObject that = (AssetsObject) o;
|
||||
if (this.size != that.size)
|
||||
return false;
|
||||
return this.hash.equals(that.hash);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = this.hash.hashCode();
|
||||
result = 31 * result + (int) (this.size ^ this.size >>> 32);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
/*
|
||||
* 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.asset;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.util.log.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.util.task.Task;
|
||||
import org.jackhuang.hellominecraft.util.net.FileDownloadTask;
|
||||
import org.jackhuang.hellominecraft.util.code.DigestUtils;
|
||||
import org.jackhuang.hellominecraft.util.sys.FileUtils;
|
||||
import org.jackhuang.hellominecraft.util.sys.IOUtils;
|
||||
import org.jackhuang.hellominecraft.util.task.TaskInfo;
|
||||
|
||||
/**
|
||||
* Assets
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public abstract class IAssetsHandler {
|
||||
|
||||
protected ArrayList<String> assetsDownloadURLs;
|
||||
protected ArrayList<File> assetsLocalNames;
|
||||
protected final String name;
|
||||
protected List<AssetsObject> assetsObjects;
|
||||
|
||||
public IAssetsHandler(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static final IAssetsHandler ASSETS_HANDLER;
|
||||
|
||||
static {
|
||||
ASSETS_HANDLER = new AssetsMojangLoader(C.i18n("assets.list.1_7_3_after"));
|
||||
}
|
||||
|
||||
/**
|
||||
* interface name
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* All the files assets needed
|
||||
*
|
||||
* @param mv The version that needs assets
|
||||
* @param mp Asset Service
|
||||
* @return just run it!
|
||||
*/
|
||||
public abstract Task 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);
|
||||
|
||||
public abstract boolean isVersionAllowed(String formattedVersion);
|
||||
|
||||
protected class AssetsTask extends TaskInfo {
|
||||
|
||||
ArrayList<Task> al;
|
||||
String u;
|
||||
|
||||
public AssetsTask(String url) {
|
||||
super(C.i18n("assets.download"));
|
||||
this.u = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) {
|
||||
if (assetsDownloadURLs == null || assetsLocalNames == null || assetsObjects == null)
|
||||
throw new IllegalStateException(C.i18n("assets.not_refreshed"));
|
||||
int max = assetsDownloadURLs.size();
|
||||
al = new ArrayList<>();
|
||||
int hasDownloaded = 0;
|
||||
for (int i = 0; i < max; i++) {
|
||||
String mark = assetsDownloadURLs.get(i);
|
||||
String url = u + mark;
|
||||
File location = assetsLocalNames.get(i);
|
||||
if (!FileUtils.makeDirectory(location.getParentFile()))
|
||||
HMCLog.warn("Failed to make directories: " + location.getParent());
|
||||
if (location.isDirectory())
|
||||
continue;
|
||||
boolean need = true;
|
||||
try {
|
||||
if (location.exists()) {
|
||||
FileInputStream fis = FileUtils.openInputStream(location);
|
||||
String sha = DigestUtils.sha1Hex(IOUtils.toByteArray(fis));
|
||||
IOUtils.closeQuietly(fis);
|
||||
if (assetsObjects.get(i).getHash().equals(sha)) {
|
||||
++hasDownloaded;
|
||||
HMCLog.log("File " + assetsLocalNames.get(i) + " has been downloaded successfully, skipped downloading.");
|
||||
if (ppl != null)
|
||||
ppl.setProgress(this, hasDownloaded, max);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
HMCLog.warn("Failed to get hash: " + location, e);
|
||||
need = !location.exists();
|
||||
}
|
||||
if (need)
|
||||
al.add(new FileDownloadTask(url, location).setTag(assetsObjects.get(i).getHash()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Task> getAfterTasks() {
|
||||
return al;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,224 +0,0 @@
|
||||
/*
|
||||
* 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.asset;
|
||||
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import org.jackhuang.hellominecraft.launcher.core.GameException;
|
||||
import org.jackhuang.hellominecraft.launcher.core.launch.IAssetProvider;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftAssetService;
|
||||
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.AssetIndexDownloadInfo;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
|
||||
import org.jackhuang.hellominecraft.util.MessageBox;
|
||||
import org.jackhuang.hellominecraft.util.log.HMCLog;
|
||||
import org.jackhuang.hellominecraft.util.task.Task;
|
||||
import org.jackhuang.hellominecraft.util.task.TaskWindow;
|
||||
import org.jackhuang.hellominecraft.util.net.FileDownloadTask;
|
||||
import org.jackhuang.hellominecraft.util.sys.FileUtils;
|
||||
import org.jackhuang.hellominecraft.util.sys.IOUtils;
|
||||
import org.jackhuang.hellominecraft.util.task.TaskInfo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class MinecraftAssetService extends IMinecraftAssetService {
|
||||
|
||||
public MinecraftAssetService(IMinecraftService service) {
|
||||
super(service);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task downloadAssets(final String mcVersion) throws GameException {
|
||||
return downloadAssets(service.version().getVersionById(mcVersion));
|
||||
}
|
||||
|
||||
public Task downloadAssets(final MinecraftVersion mv) throws GameException {
|
||||
if (mv == null)
|
||||
return null;
|
||||
return IAssetsHandler.ASSETS_HANDLER.getList(mv.resolve(service.version()), service.asset()).with(IAssetsHandler.ASSETS_HANDLER.getDownloadTask(service.getDownloadType().getProvider()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean refreshAssetsIndex(String id) throws GameException {
|
||||
MinecraftVersion mv = service.version().getVersionById(id);
|
||||
if (mv == null)
|
||||
return false;
|
||||
return downloadMinecraftAssetsIndexAsync(mv.resolve(service.version()).getAssetsIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task downloadMinecraftAssetsIndex(AssetIndexDownloadInfo assetIndex) {
|
||||
File assetsLocation = getAssets(assetIndex.getId());
|
||||
if (!FileUtils.makeDirectory(assetsLocation))
|
||||
HMCLog.warn("Failed to make directories: " + assetsLocation);
|
||||
File assetsIndex = getIndexFile(assetIndex.getId());
|
||||
File renamed = null;
|
||||
if (assetsIndex.exists()) {
|
||||
renamed = new File(assetsLocation, "indexes/" + assetIndex.getId() + "-renamed.json");
|
||||
if (assetsIndex.renameTo(renamed))
|
||||
HMCLog.warn("Failed to rename " + assetsIndex + " to " + renamed);
|
||||
}
|
||||
File renamedFinal = renamed;
|
||||
return new TaskInfo("Download Asset Index") {
|
||||
@Override
|
||||
public Collection<Task> getDependTasks() {
|
||||
return Arrays.asList(new FileDownloadTask(assetIndex.getUrl(service.getDownloadType()), IOUtils.tryGetCanonicalFile(assetsIndex), assetIndex.sha1).setTag(assetIndex.getId() + ".json"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
if (areDependTasksSucceeded) {
|
||||
if (renamedFinal != null && !renamedFinal.delete())
|
||||
HMCLog.warn("Failed to delete " + renamedFinal + ", maybe you should do it.");
|
||||
} else if (renamedFinal != null && !renamedFinal.renameTo(assetsIndex))
|
||||
HMCLog.warn("Failed to rename " + renamedFinal + " to " + assetsIndex);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean downloadMinecraftAssetsIndexAsync(AssetIndexDownloadInfo assetIndex) {
|
||||
File assetsDir = getAssets(assetIndex.getId());
|
||||
if (!FileUtils.makeDirectory(assetsDir))
|
||||
HMCLog.warn("Failed to make directories: " + assetsDir);
|
||||
File assetsIndex = getIndexFile(assetIndex.getId());
|
||||
File renamed = null;
|
||||
if (assetsIndex.exists()) {
|
||||
renamed = new File(assetsDir, "indexes/" + assetIndex.getId() + "-renamed.json");
|
||||
if (assetsIndex.renameTo(renamed))
|
||||
HMCLog.warn("Failed to rename " + assetsIndex + " to " + renamed);
|
||||
}
|
||||
if (TaskWindow.factory()
|
||||
.append(new FileDownloadTask(assetIndex.getUrl(service.getDownloadType()), IOUtils.tryGetCanonicalFile(assetsIndex), assetIndex.sha1).setTag(assetIndex.getId() + ".json"))
|
||||
.execute()) {
|
||||
if (renamed != null && !renamed.delete())
|
||||
HMCLog.warn("Failed to delete " + renamed + ", maybe you should do it.");
|
||||
return true;
|
||||
}
|
||||
if (renamed != null && !renamed.renameTo(assetsIndex))
|
||||
HMCLog.warn("Failed to rename " + renamed + " to " + assetsIndex);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getAssets(String assetId) {
|
||||
return new File(service.baseDirectory(), "assets");
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getIndexFile(String assetId) {
|
||||
return new File(getAssets(assetId), "indexes/" + assetId + ".json");
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getAssetObject(String assetId, String name) throws IOException {
|
||||
try {
|
||||
AssetsIndex index = (AssetsIndex) C.GSON.fromJson(FileUtils.read(getIndexFile(assetId), "UTF-8"), AssetsIndex.class);
|
||||
return getAssetObject(assetId, (AssetsObject) index.getFileMap().get(name));
|
||||
} catch (JsonSyntaxException e) {
|
||||
throw new IOException("Assets file format malformed.", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean checkAssetsExistance(AssetIndexDownloadInfo assetIndex) {
|
||||
String assetId = assetIndex.getId();
|
||||
File indexFile = getIndexFile(assetId);
|
||||
File assetDir = getAssets(assetId);
|
||||
|
||||
if (!getAssets(assetId).exists() || !indexFile.isFile())
|
||||
return false;
|
||||
|
||||
try {
|
||||
String assetIndexContent = FileUtils.read(indexFile, "UTF-8");
|
||||
AssetsIndex index = (AssetsIndex) C.GSON.fromJson(assetIndexContent, AssetsIndex.class);
|
||||
|
||||
if (index == null)
|
||||
return false;
|
||||
for (Map.Entry<String, AssetsObject> entry : index.getFileMap().entrySet())
|
||||
if (!assetObjectPath(assetDir, (AssetsObject) entry.getValue()).exists())
|
||||
return false;
|
||||
return true;
|
||||
} catch (IOException | JsonSyntaxException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected File reconstructAssets(AssetIndexDownloadInfo assetIndex) {
|
||||
File assetsDir = getAssets(assetIndex.getId());
|
||||
String assetVersion = assetIndex.getId();
|
||||
File indexFile = getIndexFile(assetVersion);
|
||||
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 {
|
||||
String assetIndexContent = FileUtils.read(indexFile, "UTF-8");
|
||||
AssetsIndex index = (AssetsIndex) C.GSON.fromJson(assetIndexContent, 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<String, AssetsObject> entry : index.getFileMap().entrySet()) {
|
||||
File target = new File(virtualRoot, (String) entry.getKey());
|
||||
File original = assetObjectPath(assetsDir, (AssetsObject) entry.getValue());
|
||||
if (original.exists()) {
|
||||
cnt++;
|
||||
if (!target.isFile())
|
||||
FileUtils.copyFile(original, target);
|
||||
}
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getAssetObject(String assetId, AssetsObject object) {
|
||||
return assetObjectPath(getAssets(assetId), object);
|
||||
}
|
||||
|
||||
public File assetObjectPath(File assetDir, AssetsObject object) {
|
||||
return new File(assetDir, "objects/" + object.getLocation());
|
||||
}
|
||||
|
||||
public final IAssetProvider ASSET_PROVIDER_IMPL = (t, allow) -> {
|
||||
if (allow && !checkAssetsExistance(t.getAssetsIndex()))
|
||||
if (MessageBox.show(C.i18n("assets.no_assets"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
|
||||
TaskWindow.factory().execute(downloadAssets(t));
|
||||
return reconstructAssets(t.getAssetsIndex()).getAbsolutePath();
|
||||
};
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Thrown if we are trying to log in but there's some problems like password wrong.
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
/*
|
||||
* 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.fireRegisterAuthenticators(LOGINS::add);
|
||||
}
|
||||
|
||||
protected String clientToken, username, password;
|
||||
|
||||
public IAuthenticator(String clientToken) {
|
||||
this.clientToken = clientToken;
|
||||
}
|
||||
|
||||
public String getClientToken() {
|
||||
return 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<String, String> m = new HashMap<>();
|
||||
m.put("IAuthenticator_UserName", username);
|
||||
return m;
|
||||
}
|
||||
|
||||
public void onLoadSettings(Map<?, ?> m) {
|
||||
if (m == null)
|
||||
return;
|
||||
Object o = m.get("IAuthenticator_UserName");
|
||||
username = o instanceof String ? (String) o : "";
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUserName(String s) {
|
||||
username = s;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public final class LoginInfo {
|
||||
|
||||
public String username, password;
|
||||
|
||||
public LoginInfo(String username, String password) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* 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.util.C;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
import org.jackhuang.hellominecraft.util.code.DigestUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public final class OfflineAuthenticator extends IAuthenticator {
|
||||
|
||||
Map 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<?, ?>) o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map onSaveSettings() {
|
||||
Map m = super.onSaveSettings();
|
||||
m.put("uuidMap", uuidMap);
|
||||
return m;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserProfileProvider login(LoginInfo info) throws AuthenticationException {
|
||||
if (StrUtils.isBlank(info.username))
|
||||
throw new AuthenticationException(C.i18n("login.no_Player007"));
|
||||
String uuid = getUUIDFromUserName(info.username);
|
||||
if (uuidMap != null && uuidMap.containsKey(info.username) && uuidMap.get(info.username) instanceof String)
|
||||
uuid = (String) uuidMap.get(info.username);
|
||||
else {
|
||||
if (uuidMap == null)
|
||||
uuidMap = new HashMap<>();
|
||||
uuidMap.put(info.username, uuid);
|
||||
}
|
||||
return new UserProfileProvider()
|
||||
.setUserName(info.username)
|
||||
.setSession(uuid)
|
||||
.setUserId(uuid)
|
||||
.setAccessToken(uuid)
|
||||
.setUserType("Legacy")
|
||||
.setClientIdentifier(clientToken);
|
||||
}
|
||||
|
||||
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,118 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public final class UserProfileProvider {
|
||||
|
||||
public String getUserName() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public UserProfileProvider setUserName(String username) {
|
||||
this.username = username;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public UserProfileProvider setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getSession() {
|
||||
return session;
|
||||
}
|
||||
|
||||
public UserProfileProvider setSession(String session) {
|
||||
this.session = session;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public UserProfileProvider setAccessToken(String accessToken) {
|
||||
if (accessToken == null)
|
||||
accessToken = "0";
|
||||
this.accessToken = accessToken;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getUserProperties() {
|
||||
return userProperties;
|
||||
}
|
||||
|
||||
public UserProfileProvider setUserProperties(String userProperties) {
|
||||
this.userProperties = userProperties;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getUserPropertyMap() {
|
||||
return userPropertyMap;
|
||||
}
|
||||
|
||||
public UserProfileProvider setUserPropertyMap(String userPropertyMap) {
|
||||
this.userPropertyMap = userPropertyMap;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getOtherInfo() {
|
||||
return otherInfo;
|
||||
}
|
||||
|
||||
public UserProfileProvider setOtherInfo(String otherInfo) {
|
||||
this.otherInfo = otherInfo;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getClientIdentifier() {
|
||||
return clientIdentifier;
|
||||
}
|
||||
|
||||
public UserProfileProvider setClientIdentifier(String clientIdentifier) {
|
||||
this.clientIdentifier = clientIdentifier;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getUserType() {
|
||||
return userType;
|
||||
}
|
||||
|
||||
public UserProfileProvider setUserType(String userType) {
|
||||
this.userType = userType;
|
||||
return this;
|
||||
}
|
||||
|
||||
private String username = "";
|
||||
private String userId = "";
|
||||
private String session = "";
|
||||
private String accessToken = "";
|
||||
private String userProperties = "{}";
|
||||
private String userPropertyMap = "{}";
|
||||
private String otherInfo = "";
|
||||
private String clientIdentifier = "";
|
||||
private String userType = "Offline";
|
||||
}
|
||||
@@ -1,143 +0,0 @@
|
||||
/*
|
||||
* 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.util.C;
|
||||
import org.jackhuang.hellominecraft.util.ArrayUtils;
|
||||
import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.GameProfile;
|
||||
import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.UUIDTypeAdapter;
|
||||
import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.PropertyMap;
|
||||
import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.YggdrasilAuthentication;
|
||||
import org.jackhuang.hellominecraft.util.ui.SwingUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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();
|
||||
if (ua.canPlayOnline()) {
|
||||
result.setUserName(info.username)
|
||||
.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;
|
||||
int sel = SwingUtils.select(names, C.i18n("login.choose_charactor"));
|
||||
if (sel == -1)
|
||||
throw new AuthenticationException("No selection");
|
||||
selectedProfile = profiles[sel];
|
||||
username = names[sel];
|
||||
} else
|
||||
username = JOptionPane.showInputDialog(C.i18n("login.no_charactor"));
|
||||
else
|
||||
username = selectedProfile.name;
|
||||
if (username == null)
|
||||
throw new AuthenticationException("No player");
|
||||
result.setUserName(username)
|
||||
.setUserId(selectedProfile == null ? OfflineAuthenticator.getUUIDFromUserName(username) : UUIDTypeAdapter.fromUUID(selectedProfile.id));
|
||||
}
|
||||
return result.setUserType("mojang")
|
||||
.setUserProperties(new GsonBuilder().registerTypeAdapter(PropertyMap.class, new PropertyMap.LegacySerializer()).create().toJson(ua.getUserProperties()))
|
||||
.setUserPropertyMap(new GsonBuilder().registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create().toJson(ua.getUserProperties()))
|
||||
.setAccessToken(ua.getAuthenticatedToken())
|
||||
.setSession(ua.getAuthenticatedToken())
|
||||
.setClientIdentifier(clientToken);
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* 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 {
|
||||
|
||||
private HashMap<String, Object> agent;
|
||||
private String username, password, clientToken;
|
||||
private boolean requestUser = true;
|
||||
|
||||
public HashMap<String, Object> getAgent() {
|
||||
return agent;
|
||||
}
|
||||
|
||||
public void setAgent(HashMap<String, Object> agent) {
|
||||
this.agent = agent;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUserName(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getClientToken() {
|
||||
return clientToken;
|
||||
}
|
||||
|
||||
public void setClientToken(String clientToken) {
|
||||
this.clientToken = clientToken;
|
||||
}
|
||||
|
||||
public boolean isRequestUser() {
|
||||
return requestUser;
|
||||
}
|
||||
|
||||
public void setRequestUser(boolean requestUser) {
|
||||
this.requestUser = requestUser;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* 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.Objects;
|
||||
import java.util.UUID;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
|
||||
public class GameProfile {
|
||||
|
||||
public final UUID id;
|
||||
public final String name;
|
||||
public final PropertyMap properties = new PropertyMap();
|
||||
private boolean legacy;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public boolean isLegacy() {
|
||||
return legacy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 29 * hash + Objects.hashCode(this.id);
|
||||
hash = 29 * hash + Objects.hashCode(this.name);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
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 {
|
||||
if (!(json instanceof JsonObject))
|
||||
throw new JsonParseException("The json element is not a JsonObject.");
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* 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.util.log.HMCLog;
|
||||
|
||||
public class PropertyMap extends HashMap<String, Property> {
|
||||
|
||||
private static final long serialVersionUID = 362498820763181265L;
|
||||
|
||||
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");
|
||||
put(name, new Property(name, 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();
|
||||
result.put(name, new Property(name, value));
|
||||
}
|
||||
|
||||
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 (PropertyMap.Entry<String, Property> entry : src.entrySet()) {
|
||||
JsonArray values = new JsonArray();
|
||||
values.add(new JsonPrimitive(entry.getValue().value));
|
||||
result.add(entry.getKey(), values);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* 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 {
|
||||
|
||||
private String clientToken;
|
||||
private String accessToken;
|
||||
private GameProfile selectedProfile;
|
||||
private boolean requestUser = true;
|
||||
|
||||
public RefreshRequest(String accessToken, String clientToken) {
|
||||
this.clientToken = clientToken;
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
|
||||
public String getClientToken() {
|
||||
return clientToken;
|
||||
}
|
||||
|
||||
public void setClientToken(String clientToken) {
|
||||
this.clientToken = clientToken;
|
||||
}
|
||||
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public void setAccessToken(String accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
|
||||
public GameProfile getSelectedProfile() {
|
||||
return selectedProfile;
|
||||
}
|
||||
|
||||
public void setSelectedProfile(GameProfile selectedProfile) {
|
||||
this.selectedProfile = selectedProfile;
|
||||
}
|
||||
|
||||
public boolean isRequestUser() {
|
||||
return requestUser;
|
||||
}
|
||||
|
||||
public void setRequestUser(boolean requestUser) {
|
||||
this.requestUser = requestUser;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* 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.annotations.SerializedName;
|
||||
|
||||
public class Response {
|
||||
|
||||
@SerializedName("accessToken")
|
||||
public String accessToken;
|
||||
@SerializedName("clientToken")
|
||||
public String clientToken;
|
||||
@SerializedName("selectedProfile")
|
||||
public GameProfile selectedProfile;
|
||||
@SerializedName("availableProfiles")
|
||||
public GameProfile[] availableProfiles;
|
||||
@SerializedName("user")
|
||||
public User user;
|
||||
@SerializedName("error")
|
||||
public String error;
|
||||
@SerializedName("errorMessage")
|
||||
public String errorMessage;
|
||||
@SerializedName("cause")
|
||||
public String cause;
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* 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"));
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* 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 {
|
||||
|
||||
private String id;
|
||||
private PropertyMap properties;
|
||||
|
||||
public User() {
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public PropertyMap getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(PropertyMap properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huang
|
||||
*/
|
||||
public enum UserType {
|
||||
|
||||
LEGACY("legacy"), MOJANG("mojang");
|
||||
|
||||
private static final Map<String, UserType> BY_NAME;
|
||||
private final String name;
|
||||
|
||||
private UserType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static UserType byName(String name) {
|
||||
return (UserType) BY_NAME.get(name.toLowerCase());
|
||||
}
|
||||
|
||||
public static UserType byLegacy(boolean isLegacy) {
|
||||
return isLegacy ? LEGACY : MOJANG;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
static {
|
||||
BY_NAME = new HashMap();
|
||||
for (UserType type : values())
|
||||
BY_NAME.put(type.name, type);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huang
|
||||
*/
|
||||
public class ValidateRequest {
|
||||
private String clientToken;
|
||||
private String accessToken;
|
||||
|
||||
public ValidateRequest(YggdrasilAuthentication authentication) {
|
||||
clientToken = authentication.getClientToken();
|
||||
accessToken = authentication.getAuthenticatedToken();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,274 +0,0 @@
|
||||
/*
|
||||
* 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.util.ArrayUtils;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.util.log.HMCLog;
|
||||
import org.jackhuang.hellominecraft.util.net.NetUtils;
|
||||
import org.jackhuang.hellominecraft.util.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 URL ROUTE_VALIDATE = NetUtils.constantURL(BASE_URL + "validate");
|
||||
|
||||
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 UserType userType;
|
||||
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() {
|
||||
if (profiles == null)
|
||||
return null;
|
||||
else
|
||||
return profiles.clone();
|
||||
}
|
||||
|
||||
public String getAuthenticatedToken() {
|
||||
return this.accessToken;
|
||||
}
|
||||
|
||||
public String getClientToken() {
|
||||
return clientToken;
|
||||
}
|
||||
|
||||
// </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"));
|
||||
if (checkTokenValidity()) {
|
||||
isOnline = true;
|
||||
return;
|
||||
}
|
||||
logInImpl(ROUTE_REFRESH, new RefreshRequest(getAuthenticatedToken(), clientToken));
|
||||
} else if (StrUtils.isNotBlank(password))
|
||||
logInImpl(ROUTE_AUTHENTICATE, new AuthenticationRequest(username, password, clientToken));
|
||||
else
|
||||
throw new AuthenticationException(C.i18n("login.invalid_password"));
|
||||
}
|
||||
|
||||
private void logInImpl(URL url, Object input) throws AuthenticationException {
|
||||
Response response = makeRequest(url, input, Response.class);
|
||||
|
||||
if (!clientToken.equals(response.clientToken))
|
||||
throw new AuthenticationException(C.i18n("login.changed_client_token"));
|
||||
|
||||
if (response.selectedProfile != null)
|
||||
userType = UserType.byLegacy(response.selectedProfile.isLegacy());
|
||||
else if (ArrayUtils.isNotEmpty(response.availableProfiles))
|
||||
userType = UserType.byLegacy(response.availableProfiles[0].isLegacy());
|
||||
|
||||
User user = response.user;
|
||||
userid = user != null && user.getId() != null ? user.getId() : username;
|
||||
|
||||
isOnline = true;
|
||||
profiles = response.availableProfiles;
|
||||
selectedProfile = response.selectedProfile;
|
||||
userProperties.clear();
|
||||
this.accessToken = response.accessToken;
|
||||
|
||||
if (user != null && user.getProperties() != null)
|
||||
userProperties.putAll(user.getProperties());
|
||||
}
|
||||
|
||||
protected <T extends Response> T makeRequest(URL url, Object input, Class<T> clazz)
|
||||
throws AuthenticationException {
|
||||
try {
|
||||
String jsonResult = input == null ? NetUtils.get(url, proxy) : NetUtils.post(url, GSON.toJson(input), "application/json", proxy);
|
||||
T response = (T) GSON.fromJson(jsonResult, clazz);
|
||||
if (response == null)
|
||||
return null;
|
||||
|
||||
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 != null && response.errorMessage.contains("Invalid token"))
|
||||
response.errorMessage = C.i18n("login.invalid_token");
|
||||
throw new AuthenticationException("Request error: " + response.errorMessage);
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (IOException | IllegalStateException | JsonParseException e) {
|
||||
throw new AuthenticationException(C.i18n("login.failed.connect_authentication_server"), e);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean checkTokenValidity() {
|
||||
ValidateRequest request = new ValidateRequest(this);
|
||||
try {
|
||||
makeRequest(ROUTE_VALIDATE, request, Response.class);
|
||||
return true;
|
||||
} catch (AuthenticationException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
try {
|
||||
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);
|
||||
} catch (Exception e) {
|
||||
HMCLog.err("Failed to load yggdrasil authenticator settings, maybe its format is malformed.", e);
|
||||
|
||||
logOut();
|
||||
}
|
||||
}
|
||||
|
||||
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,85 +0,0 @@
|
||||
/*
|
||||
* 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.install.InstallerVersionList;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class BMCLAPIDownloadProvider extends IDownloadProvider {
|
||||
|
||||
@Override
|
||||
public InstallerVersionList getForgeInstaller() {
|
||||
return org.jackhuang.hellominecraft.launcher.core.install.forge.MinecraftForgeVersionList.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstallerVersionList getLiteLoaderInstaller() {
|
||||
return org.jackhuang.hellominecraft.launcher.core.install.liteloader.LiteLoaderVersionList.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstallerVersionList getOptiFineInstaller() {
|
||||
return org.jackhuang.hellominecraft.launcher.core.install.optifine.bmcl.OptiFineBMCLVersionList.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLibraryDownloadURL() {
|
||||
return "http://bmclapi2.bangbang93.com/libraries";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersionsDownloadURL() {
|
||||
return "http://bmclapi2.bangbang93.com/versions/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIndexesDownloadURL() {
|
||||
return "http://bmclapi2.bangbang93.com/indexes/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersionsListDownloadURL() {
|
||||
return "http://bmclapi2.bangbang93.com/mc/game/version_manifest.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAssetsDownloadURL() {
|
||||
return "http://bmclapi2.bangbang93.com/assets/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParsedDownloadURL(String str) {
|
||||
return str == null ? null
|
||||
: str.replace("https://launchermeta.mojang.com", "http://bmclapi2.bangbang93.com")
|
||||
.replace("https://launcher.mojang.com", "http://bmclapi2.bangbang93.com")
|
||||
.replace("https://libraries.minecraft.net", "http://bmclapi2.bangbang93.com/libraries")
|
||||
.replace("http://files.minecraftforge.net/maven", "http://bmclapi2.bangbang93.com/maven")
|
||||
.replace(C.URL_LITELOADER_LIST, "http://bmclapi2.bangbang93.com/maven/com/mumfrey/liteloader/versions.json")
|
||||
.replace("http://dl.liteloader.com/versions", "http://bmclapi2.bangbang93.com/maven");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowedToUseSelfURL() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* 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 getParsedDownloadURL(String str) {
|
||||
return str == null ? null : str.replace("http://files.minecraftforge.net/maven", "http://ftb.cursecdn.com/FTB2/maven");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* 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.api.HMCAPI;
|
||||
import org.jackhuang.hellominecraft.launcher.api.event.config.DownloadTypeChangedEvent;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.util.task.TaskWindow;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public enum DownloadType {
|
||||
|
||||
Mojang("download.mojang", new MojangDownloadProvider()),
|
||||
BMCL("download.BMCL", new BMCLAPIDownloadProvider()),
|
||||
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 C.i18n(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.");
|
||||
TaskWindow.downloadSource = suggestedDownloadType.getName();
|
||||
DownloadType.suggestedDownloadType = suggestedDownloadType;
|
||||
}
|
||||
|
||||
static {
|
||||
HMCAPI.EVENT_BUS.channel(DownloadTypeChangedEvent.class).register(t -> setSuggestedDownloadType(t.getValue()));
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* 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.install.InstallerType;
|
||||
import org.jackhuang.hellominecraft.launcher.core.install.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();
|
||||
|
||||
/**
|
||||
* For example, minecraft.json/assetIndex/url or
|
||||
* minecraft.json/downloads/client/url
|
||||
*
|
||||
* @param str baseURL
|
||||
*
|
||||
* @return parsedURL
|
||||
*/
|
||||
public abstract String getParsedDownloadURL(String str);
|
||||
|
||||
public abstract boolean isAllowedToUseSelfURL();
|
||||
}
|
||||
@@ -1,164 +0,0 @@
|
||||
/*
|
||||
* 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.api.event.launch.DownloadLibraryJob;
|
||||
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftDownloadService;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.util.log.HMCLog;
|
||||
import org.jackhuang.hellominecraft.launcher.core.GameException;
|
||||
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.GameDownloadInfo;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.IMinecraftLibrary;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
|
||||
import org.jackhuang.hellominecraft.util.net.FileDownloadTask;
|
||||
import org.jackhuang.hellominecraft.util.func.Function;
|
||||
import org.jackhuang.hellominecraft.util.sys.FileUtils;
|
||||
import org.jackhuang.hellominecraft.util.task.Task;
|
||||
import org.jackhuang.hellominecraft.util.task.TaskInfo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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());
|
||||
for (IMinecraftLibrary l : v.getLibraries())
|
||||
if (l != null && l.allow() && l.getDownloadInfo() != null) {
|
||||
File ff = l.getFilePath(service.baseDirectory());
|
||||
if (!ff.exists()) {
|
||||
String libURL = l.getDownloadInfo().getUrl(service.getDownloadType());
|
||||
if (libURL != null)
|
||||
downloadLibraries.add(new DownloadLibraryJob(l, libURL, ff));
|
||||
}
|
||||
}
|
||||
return downloadLibraries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task downloadMinecraft(String id) {
|
||||
return new TaskInfo("Download Minecraft") {
|
||||
@Override
|
||||
public Collection<Task> getDependTasks() {
|
||||
return Arrays.asList(downloadMinecraftVersionJson(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
File vpath = new File(service.baseDirectory(), "versions/" + id);
|
||||
if (!areDependTasksSucceeded) {
|
||||
FileUtils.deleteDirectory(vpath);
|
||||
throw new RuntimeException("Cannot continue because of download failing.");
|
||||
}
|
||||
File mvj = new File(vpath, id + ".jar");
|
||||
if (mvj.exists() && !mvj.delete())
|
||||
HMCLog.warn("Failed to delete " + mvj);
|
||||
try {
|
||||
MinecraftVersion mv = C.GSON.fromJson(FileUtils.readQuietly(new File(vpath, id + ".json")), MinecraftVersion.class);
|
||||
if (mv == null)
|
||||
throw new JsonSyntaxException("incorrect version");
|
||||
|
||||
afters.add(downloadMinecraftJar(mv, mvj));
|
||||
} catch (JsonSyntaxException ex) {
|
||||
HMCLog.err("Failed to parse minecraft version json.", ex);
|
||||
FileUtils.deleteDirectory(vpath);
|
||||
}
|
||||
}
|
||||
|
||||
Collection<Task> afters = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public Collection<Task> getAfterTasks() {
|
||||
return afters;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static class DownloadTypeSwitcher implements Function<Integer, String> {
|
||||
|
||||
String suffix;
|
||||
|
||||
public DownloadTypeSwitcher(String suffix) {
|
||||
this.suffix = suffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apply(Integer t) {
|
||||
return DownloadType.values()[t / 2].getProvider().getVersionsDownloadURL() + suffix;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task downloadMinecraftJar(MinecraftVersion mv, File mvj) {
|
||||
GameDownloadInfo i = mv.getClientDownloadInfo();
|
||||
return new FileDownloadTask(i.getUrl(service.getDownloadType()), mvj, i.sha1)
|
||||
.setFailedCallbackReturnsNewURL(new DownloadTypeSwitcher(mv.id + "/" + mv.id + ".jar")).setTag(mv.id + ".jar");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task downloadMinecraftVersionJson(String id) {
|
||||
return new TaskInfo("Download Minecraft Json") {
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
List<MinecraftRemoteVersion> versions = MinecraftRemoteVersions.getRemoteVersions(service.getDownloadType()).justDo();
|
||||
MinecraftRemoteVersion currentVersion = null;
|
||||
for (MinecraftRemoteVersion v : versions)
|
||||
if (id.equals(v.id)) {
|
||||
currentVersion = v;
|
||||
break;
|
||||
}
|
||||
if (currentVersion == null)
|
||||
throw new RuntimeException("Cannot find version: " + id + " in remote repository.");
|
||||
String jsonURL = currentVersion.getUrl(service.getDownloadType());
|
||||
File vpath = new File(service.baseDirectory(), "versions/" + id);
|
||||
File mvt = new File(vpath, id + ".json");
|
||||
if (!FileUtils.makeDirectory(vpath))
|
||||
HMCLog.warn("Failed to make directories: " + vpath);
|
||||
if (mvt.exists() && !mvt.delete())
|
||||
HMCLog.warn("Failed to delete " + mvt);
|
||||
|
||||
afters.add(new FileDownloadTask(jsonURL, mvt).setTag(id + ".json"));
|
||||
}
|
||||
|
||||
Collection<Task> afters = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public Collection<Task> getAfterTasks() {
|
||||
return afters;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Hello Minecraft!.
|
||||
* 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 com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class MinecraftRemoteLatestVersion {
|
||||
|
||||
@SerializedName("snapshot")
|
||||
public String snapshot;
|
||||
|
||||
@SerializedName("release")
|
||||
public String release;
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Hello Minecraft!.
|
||||
* 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 com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class MinecraftRemoteVersion {
|
||||
|
||||
@SerializedName("id")
|
||||
public String id;
|
||||
@SerializedName("time")
|
||||
public String time;
|
||||
@SerializedName("releaseTime")
|
||||
public String releaseTime;
|
||||
@SerializedName("type")
|
||||
public String type;
|
||||
@SerializedName("url")
|
||||
private String url;
|
||||
|
||||
public String getUrl(DownloadType type) {
|
||||
if (url == null)
|
||||
return type.getProvider().getVersionsDownloadURL() + id + "/" + id + ".json";
|
||||
return type.getProvider().getParsedDownloadURL(url);
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Hello Minecraft!.
|
||||
* 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 com.google.gson.annotations.SerializedName;
|
||||
import java.util.ArrayList;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.util.net.NetUtils;
|
||||
import org.jackhuang.hellominecraft.util.AbstractSwingWorker;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class MinecraftRemoteVersions {
|
||||
|
||||
@SerializedName("versions")
|
||||
public ArrayList<MinecraftRemoteVersion> versions;
|
||||
@SerializedName("latest")
|
||||
public MinecraftRemoteLatestVersion latest;
|
||||
|
||||
private static volatile MinecraftRemoteVersions INSTANCE = null;
|
||||
private static final Object INSTANCE_LOCK = new Object();
|
||||
|
||||
public static RemoteVersionsTask getRemoteVersions(DownloadType type) {
|
||||
return new RemoteVersionsTask(type) {
|
||||
@Override
|
||||
public void work() throws Exception {
|
||||
synchronized (INSTANCE_LOCK) {
|
||||
if (INSTANCE != null)
|
||||
send(INSTANCE.versions.toArray(new MinecraftRemoteVersion[INSTANCE.versions.size()]));
|
||||
else
|
||||
super.work();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static RemoteVersionsTask refreshRomoteVersions(DownloadType type) {
|
||||
return new RemoteVersionsTask(type);
|
||||
}
|
||||
|
||||
public static class RemoteVersionsTask extends AbstractSwingWorker<MinecraftRemoteVersion> {
|
||||
|
||||
DownloadType type;
|
||||
|
||||
public RemoteVersionsTask(DownloadType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void work() throws Exception {
|
||||
MinecraftRemoteVersions r = C.GSON.fromJson(NetUtils.get(type.getProvider().getVersionsListDownloadURL()), MinecraftRemoteVersions.class);
|
||||
if (r != null && r.versions != null) {
|
||||
INSTANCE = r;
|
||||
send(r.versions.toArray(new MinecraftRemoteVersion[r.versions.size()]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* 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.util.Locale;
|
||||
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
|
||||
import org.jackhuang.hellominecraft.util.lang.SupportedLocales;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class MojangDownloadProvider extends IDownloadProvider {
|
||||
|
||||
@Override
|
||||
public InstallerVersionList getForgeInstaller() {
|
||||
return org.jackhuang.hellominecraft.launcher.core.install.forge.MinecraftForgeVersionList.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstallerVersionList getLiteLoaderInstaller() {
|
||||
return org.jackhuang.hellominecraft.launcher.core.install.liteloader.LiteLoaderVersionList.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstallerVersionList getOptiFineInstaller() {
|
||||
return org.jackhuang.hellominecraft.launcher.core.install.optifine.vanilla.OptiFineVersionList.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLibraryDownloadURL() {
|
||||
return "https://libraries.minecraft.net";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersionsDownloadURL() {
|
||||
return "http://s3.amazonaws.com/Minecraft.Download/versions/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIndexesDownloadURL() {
|
||||
return "http://s3.amazonaws.com/Minecraft.Download/indexes/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersionsListDownloadURL() {
|
||||
return "https://launchermeta.mojang.com/mc/game/version_manifest.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAssetsDownloadURL() {
|
||||
return "http://resources.download.minecraft.net/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowedToUseSelfURL() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParsedDownloadURL(String str) {
|
||||
if (str == null)
|
||||
return null;
|
||||
else if (str.contains("scala-swing") || str.contains("scala-xml") || str.contains("scala-parser-combinators"))
|
||||
return str.replace("http://files.minecraftforge.net/maven", "http://ftb.cursecdn.com/FTB2/maven/");
|
||||
else if (str.contains("typesafe") || str.contains("scala"))
|
||||
if (SupportedLocales.NOW_LOCALE.self == Locale.CHINA)
|
||||
return str.replace("http://files.minecraftforge.net/maven", "http://maven.aliyun.com/nexus/content/groups/public");
|
||||
else
|
||||
return str.replace("http://files.minecraftforge.net/maven", "http://repo1.maven.org/maven2");
|
||||
else
|
||||
return str;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* 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.install;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
|
||||
import org.jackhuang.hellominecraft.launcher.core.install.forge.Install;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class InstallProfile {
|
||||
|
||||
@SerializedName("install")
|
||||
public Install install;
|
||||
@SerializedName("versionInfo")
|
||||
public MinecraftVersion versionInfo;
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* 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.install;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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,136 +0,0 @@
|
||||
/*
|
||||
* 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.install;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
import org.jackhuang.hellominecraft.util.task.Task;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public abstract class InstallerVersionList {
|
||||
|
||||
public Map<String, List<InstallerVersion>> versionMap;
|
||||
public List<InstallerVersion> versions;
|
||||
|
||||
/**
|
||||
* Refresh installer versions list from the downloaded content.
|
||||
*
|
||||
* @param versions Minecraft versions you need to refresh
|
||||
*
|
||||
* @throws java.lang.Exception including network exceptions, IO exceptions.
|
||||
*/
|
||||
public abstract Task refresh(String[] versions);
|
||||
|
||||
/**
|
||||
* Installer name.
|
||||
*
|
||||
* @return installer name.
|
||||
*/
|
||||
public abstract String getName();
|
||||
|
||||
/**
|
||||
* Get installers you want.
|
||||
*
|
||||
* @param mcVersion the installers to this Minecraft version.
|
||||
*
|
||||
* @return cached result.
|
||||
*/
|
||||
public List<InstallerVersion> getVersionsImpl(String mcVersion) {
|
||||
if (versions == null || versionMap == null)
|
||||
return null;
|
||||
if (StrUtils.isBlank(mcVersion))
|
||||
return versions;
|
||||
List<InstallerVersion> c = versionMap.get(mcVersion);
|
||||
if (c == null)
|
||||
return versions;
|
||||
Collections.sort(c, InstallerVersionComparator.INSTANCE);
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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> {
|
||||
|
||||
public String selfVersion, mcVersion;
|
||||
public String installer, universal;
|
||||
public String changelog;
|
||||
|
||||
public InstallerVersion(String selfVersion, String mcVersion) {
|
||||
this.selfVersion = selfVersion;
|
||||
this.mcVersion = mcVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(InstallerVersion o) {
|
||||
return selfVersion.compareTo(o.selfVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return selfVersion.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
final InstallerVersion other = (InstallerVersion) obj;
|
||||
return Objects.equals(this.selfVersion, other.selfVersion);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class InstallerVersionComparator implements Comparator<InstallerVersion>, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 3276198781795213723L;
|
||||
|
||||
public static final InstallerVersionComparator INSTANCE = new InstallerVersionComparator();
|
||||
|
||||
@Override
|
||||
public int compare(InstallerVersion o1, InstallerVersion o2) {
|
||||
return o2.compareTo(o1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* 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.install;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Comparator;
|
||||
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList.InstallerVersion;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class InstallerVersionNewerComparator implements Comparator<InstallerVersion>, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 14758562453742645L;
|
||||
|
||||
@Override
|
||||
public int compare(InstallerVersion o1, InstallerVersion o2) {
|
||||
return o2.compareTo(o1);
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* 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.install;
|
||||
|
||||
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.install.InstallerVersionList.InstallerVersion;
|
||||
import org.jackhuang.hellominecraft.launcher.core.install.forge.ForgeInstaller;
|
||||
import org.jackhuang.hellominecraft.launcher.core.install.liteloader.LiteLoaderInstaller;
|
||||
import org.jackhuang.hellominecraft.launcher.core.install.liteloader.LiteLoaderInstallerVersion;
|
||||
import org.jackhuang.hellominecraft.launcher.core.install.optifine.OptiFineInstaller;
|
||||
import org.jackhuang.hellominecraft.launcher.core.install.optifine.vanilla.OptiFineDownloadFormatter;
|
||||
import org.jackhuang.hellominecraft.util.task.Task;
|
||||
import org.jackhuang.hellominecraft.util.net.FileDownloadTask;
|
||||
import org.jackhuang.hellominecraft.util.sys.IOUtils;
|
||||
import org.jackhuang.hellominecraft.util.task.DeleteFileTask;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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) {
|
||||
File filepath = IOUtils.tryGetCanonicalFile("forge-installer.jar");
|
||||
if (v.installer == null)
|
||||
return null;
|
||||
else
|
||||
return new FileDownloadTask(service.getDownloadType().getProvider().getParsedDownloadURL(v.installer), filepath).setTag("forge")
|
||||
.with(new ForgeInstaller(service, filepath))
|
||||
.with(new DeleteFileTask(filepath));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task downloadOptiFine(String installId, InstallerVersion v) {
|
||||
File filepath = IOUtils.tryGetCanonicalFile("optifine-installer.jar");
|
||||
if (v.installer == null)
|
||||
return null;
|
||||
OptiFineDownloadFormatter task = new OptiFineDownloadFormatter(v.installer);
|
||||
return task.with(new FileDownloadTask(filepath).registerPreviousResult(task).setTag("optifine"))
|
||||
.with(new OptiFineInstaller(service, installId, v, filepath))
|
||||
.with(new DeleteFileTask(filepath));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task downloadLiteLoader(String installId, InstallerVersion v) {
|
||||
if (!(v instanceof LiteLoaderInstallerVersion))
|
||||
throw new Error("Download lite loader but the version is not ll's.");
|
||||
File filepath = IOUtils.tryGetCanonicalFile("liteloader-universal.jar");
|
||||
FileDownloadTask task = (FileDownloadTask) new FileDownloadTask(v.universal, filepath).setTag("LiteLoader");
|
||||
return task.with(new LiteLoaderInstaller(service, installId, (LiteLoaderInstallerVersion) v).registerPreviousResult(task))
|
||||
.with(new DeleteFileTask(filepath));
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* 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.install.forge;
|
||||
|
||||
import org.jackhuang.hellominecraft.launcher.core.install.InstallProfile;
|
||||
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.api.HMCAPI;
|
||||
import org.jackhuang.hellominecraft.launcher.api.event.version.MinecraftLibraryPathEvent;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.util.log.HMCLog;
|
||||
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
|
||||
import org.jackhuang.hellominecraft.util.task.Task;
|
||||
import org.jackhuang.hellominecraft.util.sys.FileUtils;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
|
||||
import org.jackhuang.hellominecraft.util.MessageBox;
|
||||
import org.jackhuang.hellominecraft.util.Wrapper;
|
||||
import org.jackhuang.hellominecraft.util.sys.IOUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class ForgeInstaller extends Task {
|
||||
|
||||
public File gameDir;
|
||||
public File forgeInstaller;
|
||||
public IMinecraftService mp;
|
||||
|
||||
public ForgeInstaller(IMinecraftService mp, File forgeInstaller) {
|
||||
this.gameDir = mp.baseDirectory();
|
||||
this.forgeInstaller = forgeInstaller;
|
||||
this.mp = mp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Exception {
|
||||
HMCLog.log("Extracting install profiles...");
|
||||
|
||||
try (ZipFile zipFile = new ZipFile(forgeInstaller)) {
|
||||
ZipEntry entry = zipFile.getEntry("install_profile.json");
|
||||
String content = IOUtils.toString(zipFile.getInputStream(entry));
|
||||
InstallProfile profile = C.GSON.fromJson(content, InstallProfile.class);
|
||||
File from = new File(gameDir, "versions" + File.separator + profile.install.getMinecraft());
|
||||
if (!from.exists())
|
||||
if (MessageBox.show(C.i18n("install.no_version_if_intall")) == MessageBox.YES_OPTION) {
|
||||
if (!mp.version().install(profile.install.getMinecraft(), 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.getTarget());
|
||||
if (!FileUtils.makeDirectory(to))
|
||||
HMCLog.warn("Failed to make new version folder " + to);
|
||||
|
||||
HMCLog.log("Copying jar..." + profile.install.getMinecraft() + ".jar to " + profile.install.getTarget() + ".jar");
|
||||
FileUtils.copyFile(new File(from, profile.install.getMinecraft() + ".jar"),
|
||||
new File(to, profile.install.getTarget() + ".jar"));
|
||||
|
||||
HMCLog.log("Creating new version profile..." + profile.install.getTarget() + ".json");
|
||||
FileUtils.write(new File(to, profile.install.getTarget() + ".json"), C.GSON.toJson(profile.versionInfo));
|
||||
|
||||
HMCLog.log("Extracting universal forge pack..." + profile.install.getFilePath());
|
||||
entry = zipFile.getEntry(profile.install.getFilePath());
|
||||
InputStream is = zipFile.getInputStream(entry);
|
||||
MinecraftLibrary forge = new MinecraftLibrary(profile.install.getPath());
|
||||
|
||||
String path = "libraries/" + forge.getDownloadInfo().path;
|
||||
MinecraftLibraryPathEvent event = new MinecraftLibraryPathEvent(this, path, new Wrapper<>(new File(gameDir, path)));
|
||||
HMCAPI.EVENT_BUS.fireChannel(event);
|
||||
File file = event.getFile().getValue();
|
||||
|
||||
if (!FileUtils.makeDirectory(file.getParentFile()))
|
||||
HMCLog.warn("Failed to make library directory " + file.getParent());
|
||||
try (FileOutputStream fos = FileUtils.openOutputStream(file)) {
|
||||
IOUtils.copyStream(is, fos);
|
||||
}
|
||||
mp.version().refreshVersions();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInfo() {
|
||||
return C.i18n("install.forge.install");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* 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.install.forge;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class Install {
|
||||
|
||||
@SerializedName("profileName")
|
||||
private String profileName;
|
||||
@SerializedName("target")
|
||||
private String target;
|
||||
@SerializedName("path")
|
||||
private String path;
|
||||
@SerializedName("version")
|
||||
private String version;
|
||||
@SerializedName("filePath")
|
||||
private String filePath;
|
||||
@SerializedName("welcome")
|
||||
private String welcome;
|
||||
@SerializedName("minecraft")
|
||||
private String minecraft;
|
||||
@SerializedName("mirrorList")
|
||||
private String mirrorList;
|
||||
@SerializedName("logo")
|
||||
private String logo;
|
||||
|
||||
public Install() {
|
||||
}
|
||||
|
||||
public String getProfileName() {
|
||||
return profileName;
|
||||
}
|
||||
|
||||
public void setProfileName(String profileName) {
|
||||
this.profileName = profileName;
|
||||
}
|
||||
|
||||
public String getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTarget(String target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
public String getWelcome() {
|
||||
return welcome;
|
||||
}
|
||||
|
||||
public void setWelcome(String welcome) {
|
||||
this.welcome = welcome;
|
||||
}
|
||||
|
||||
public String getMinecraft() {
|
||||
return minecraft;
|
||||
}
|
||||
|
||||
public void setMinecraft(String minecraft) {
|
||||
this.minecraft = minecraft;
|
||||
}
|
||||
|
||||
public String getMirrorList() {
|
||||
return mirrorList;
|
||||
}
|
||||
|
||||
public void setMirrorList(String mirrorList) {
|
||||
this.mirrorList = mirrorList;
|
||||
}
|
||||
|
||||
public String getLogo() {
|
||||
return logo;
|
||||
}
|
||||
|
||||
public void setLogo(String logo) {
|
||||
this.logo = logo;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* 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.install.forge;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class MinecraftForgeVersion {
|
||||
|
||||
public String branch, mcversion, jobver, version;
|
||||
public int build;
|
||||
public double modified;
|
||||
public String[][] files;
|
||||
|
||||
public String getBranch() {
|
||||
return branch;
|
||||
}
|
||||
|
||||
public void setBranch(String branch) {
|
||||
this.branch = branch;
|
||||
}
|
||||
|
||||
public String getMCVersion() {
|
||||
return mcversion;
|
||||
}
|
||||
|
||||
public void setMCVersion(String mcversion) {
|
||||
this.mcversion = mcversion;
|
||||
}
|
||||
|
||||
public String getJobver() {
|
||||
return jobver;
|
||||
}
|
||||
|
||||
public void setJobver(String jobver) {
|
||||
this.jobver = jobver;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public int getBuild() {
|
||||
return build;
|
||||
}
|
||||
|
||||
public void setBuild(int build) {
|
||||
this.build = build;
|
||||
}
|
||||
|
||||
public double getModified() {
|
||||
return modified;
|
||||
}
|
||||
|
||||
public void setModified(double modified) {
|
||||
this.modified = modified;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
/*
|
||||
* 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.install.forge;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
|
||||
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionNewerComparator;
|
||||
import org.jackhuang.hellominecraft.util.task.Task;
|
||||
import org.jackhuang.hellominecraft.util.task.TaskInfo;
|
||||
import org.jackhuang.hellominecraft.util.net.HTTPGetTask;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class MinecraftForgeVersionList extends InstallerVersionList {
|
||||
|
||||
private static volatile MinecraftForgeVersionList instance;
|
||||
|
||||
public static MinecraftForgeVersionList getInstance() {
|
||||
if (instance == null)
|
||||
instance = new MinecraftForgeVersionList();
|
||||
return instance;
|
||||
}
|
||||
|
||||
public MinecraftForgeVersionRoot root;
|
||||
|
||||
@Override
|
||||
public Task refresh(String[] needed) {
|
||||
if (root != null)
|
||||
return null;
|
||||
return new TaskInfo(C.i18n("install.forge.get_list")) {
|
||||
HTTPGetTask task = new HTTPGetTask(DownloadType.getSuggestedDownloadType().getProvider().getParsedDownloadURL(C.URL_FORGE_LIST));
|
||||
|
||||
@Override
|
||||
public Collection<Task> getDependTasks() {
|
||||
return Arrays.asList(task.setTag("Official Forge Download Site"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
if (!areDependTasksSucceeded)
|
||||
return;
|
||||
String s = task.getResult();
|
||||
|
||||
root = C.GSON.fromJson(s, MinecraftForgeVersionRoot.class);
|
||||
|
||||
versionMap = new HashMap<>();
|
||||
versions = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<String, int[]> arr : root.mcversion.entrySet()) {
|
||||
String mcver = StrUtils.formatVersion(arr.getKey());
|
||||
ArrayList<InstallerVersion> al = new ArrayList<>();
|
||||
for (int num : arr.getValue()) {
|
||||
MinecraftForgeVersion v = root.number.get(num);
|
||||
InstallerVersion iv = new InstallerVersion(v.version, StrUtils.formatVersion(v.mcversion));
|
||||
for (String[] f : v.files) {
|
||||
|
||||
String ver = v.mcversion + "-" + v.version;
|
||||
if (!StrUtils.isBlank(v.branch))
|
||||
ver = ver + "-" + v.branch;
|
||||
String filename = root.artifact + "-" + ver + "-" + f[1] + "." + f[0];
|
||||
String url = DownloadType.getSuggestedDownloadType().getProvider().getParsedDownloadURL(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;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (StrUtils.isBlank(iv.installer) || StrUtils.isBlank(iv.universal))
|
||||
continue;
|
||||
Collections.sort(al, new InstallerVersionNewerComparator());
|
||||
al.add(iv);
|
||||
versions.add(iv);
|
||||
}
|
||||
|
||||
versionMap.put(StrUtils.formatVersion(mcver), al);
|
||||
}
|
||||
|
||||
Collections.sort(versions, new InstallerVersionComparator());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Forge - MinecraftForge Offical Site";
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* 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.install.forge;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class MinecraftForgeVersionRoot {
|
||||
|
||||
@SerializedName("artifact")
|
||||
public String artifact;
|
||||
@SerializedName("webpath")
|
||||
public String webpath;
|
||||
@SerializedName("adfly")
|
||||
public String adfly;
|
||||
@SerializedName("homepage")
|
||||
public String homepage;
|
||||
@SerializedName("name")
|
||||
public String name;
|
||||
@SerializedName("branches")
|
||||
public Map<String, int[]> branches;
|
||||
@SerializedName("mcversion")
|
||||
public Map<String, int[]> mcversion;
|
||||
@SerializedName("promos")
|
||||
public Map<String, Integer> promos;
|
||||
@SerializedName("number")
|
||||
public Map<Integer, MinecraftForgeVersion> number;
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* 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.install.liteloader;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import org.jackhuang.hellominecraft.api.HMCAPI;
|
||||
import org.jackhuang.hellominecraft.launcher.api.event.version.MinecraftLibraryPathEvent;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.util.log.HMCLog;
|
||||
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
|
||||
import org.jackhuang.hellominecraft.util.task.Task;
|
||||
import org.jackhuang.hellominecraft.util.task.comm.PreviousResult;
|
||||
import org.jackhuang.hellominecraft.util.task.comm.PreviousResultRegistrar;
|
||||
import org.jackhuang.hellominecraft.util.sys.FileUtils;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
|
||||
import org.jackhuang.hellominecraft.util.Wrapper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class LiteLoaderInstaller extends Task implements PreviousResultRegistrar<File> {
|
||||
|
||||
public LiteLoaderInstallerVersion version;
|
||||
public File installer;
|
||||
public String installId;
|
||||
public IMinecraftService service;
|
||||
|
||||
public LiteLoaderInstaller(IMinecraftService service, String installId, LiteLoaderInstallerVersion v) {
|
||||
this(service, installId, v, null);
|
||||
}
|
||||
|
||||
public LiteLoaderInstaller(IMinecraftService service, String installId, LiteLoaderInstallerVersion v, File installer) {
|
||||
this.service = service;
|
||||
this.installId = installId;
|
||||
this.version = v;
|
||||
this.installer = installer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) 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);
|
||||
|
||||
String path = "libraries/com/mumfrey/liteloader/" + version.selfVersion + "/liteloader-" + version.selfVersion + ".jar";
|
||||
MinecraftLibraryPathEvent event = new MinecraftLibraryPathEvent(this, path, new Wrapper<>(new File(service.baseDirectory(), path)));
|
||||
HMCAPI.EVENT_BUS.fireChannel(event);
|
||||
FileUtils.copyFile(installer, event.getFile().getValue());
|
||||
|
||||
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);
|
||||
if (!FileUtils.makeDirectory(folder))
|
||||
HMCLog.warn("Failed to create new liteloader version " + folder);
|
||||
File json = new File(folder, mv.id + ".json");
|
||||
HMCLog.log("Creating new version profile..." + mv.id + ".json");
|
||||
FileUtils.write(json, C.GSON.toJson(mv));
|
||||
|
||||
service.version().refreshVersions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInfo() {
|
||||
return C.i18n("install.liteloader.install");
|
||||
}
|
||||
|
||||
ArrayList<PreviousResult<File>> pre = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public Task registerPreviousResult(PreviousResult<File> pr) {
|
||||
pre.add(pr);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* 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.install.liteloader;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huang
|
||||
*/
|
||||
public class LiteLoaderInstallerVersion extends InstallerVersionList.InstallerVersion {
|
||||
|
||||
public MinecraftLibrary[] libraries;
|
||||
public String tweakClass;
|
||||
|
||||
public LiteLoaderInstallerVersion(String selfVersion, String mcVersion) {
|
||||
super(selfVersion, mcVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 13 * hash + Arrays.deepHashCode(this.libraries);
|
||||
hash = 13 * hash + Objects.hashCode(this.tweakClass);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null || !(obj instanceof LiteLoaderVersionList))
|
||||
return false;
|
||||
if (this == obj)
|
||||
return true;
|
||||
final LiteLoaderInstallerVersion other = (LiteLoaderInstallerVersion) obj;
|
||||
if (!Objects.equals(this.tweakClass, other.tweakClass))
|
||||
return false;
|
||||
return Arrays.deepEquals(this.libraries, other.libraries);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* 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.install.liteloader;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class LiteLoaderMCVersions {
|
||||
|
||||
@SerializedName("artefacts")
|
||||
public Map<String, Map<String, LiteLoaderVersion>> artefacts;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* 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.install.liteloader;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class LiteLoaderVersion {
|
||||
|
||||
@SerializedName("tweakClass")
|
||||
public String tweakClass;
|
||||
@SerializedName("file")
|
||||
public String file;
|
||||
@SerializedName("version")
|
||||
public String version;
|
||||
@SerializedName("md5")
|
||||
public String md5;
|
||||
@SerializedName("timestamp")
|
||||
public String timestamp;
|
||||
@SerializedName("libraries")
|
||||
public MinecraftLibrary[] libraries;
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
* 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.install.liteloader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
|
||||
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionNewerComparator;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
import org.jackhuang.hellominecraft.util.task.Task;
|
||||
import org.jackhuang.hellominecraft.util.task.TaskInfo;
|
||||
import org.jackhuang.hellominecraft.util.net.HTTPGetTask;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class LiteLoaderVersionList extends InstallerVersionList {
|
||||
|
||||
private static volatile LiteLoaderVersionList instance = null;
|
||||
|
||||
public static LiteLoaderVersionList getInstance() {
|
||||
if (instance == null)
|
||||
instance = new LiteLoaderVersionList();
|
||||
return instance;
|
||||
}
|
||||
|
||||
public LiteLoaderVersionsRoot root;
|
||||
|
||||
@Override
|
||||
public Task refresh(String[] needed) {
|
||||
if (root != null)
|
||||
return null;
|
||||
return new TaskInfo(C.i18n("install.liteloader.get_list")) {
|
||||
HTTPGetTask task = new HTTPGetTask(DownloadType.getSuggestedDownloadType().getProvider().getParsedDownloadURL(C.URL_LITELOADER_LIST));
|
||||
|
||||
@Override
|
||||
public Collection<Task> getDependTasks() {
|
||||
return Arrays.asList(task.setTag("Official Liteloader Download Site"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
if (!areDependTasksSucceeded)
|
||||
return;
|
||||
String s = task.getResult();
|
||||
|
||||
root = C.GSON.fromJson(s, LiteLoaderVersionsRoot.class);
|
||||
|
||||
versionMap = new HashMap<>();
|
||||
versions = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<String, LiteLoaderMCVersions> arr : root.versions.entrySet()) {
|
||||
ArrayList<InstallerVersion> al = new ArrayList<>();
|
||||
LiteLoaderMCVersions mcv = arr.getValue();
|
||||
if (mcv == null || mcv.artefacts == null || mcv.artefacts.get("com.mumfrey:liteloader") == null)
|
||||
continue;
|
||||
for (Map.Entry<String, LiteLoaderVersion> entry : mcv.artefacts.get("com.mumfrey:liteloader").entrySet()) {
|
||||
if ("latest".equals(entry.getKey()))
|
||||
continue;
|
||||
LiteLoaderVersion v = entry.getValue();
|
||||
LiteLoaderInstallerVersion iv = new LiteLoaderInstallerVersion(v.version, StrUtils.formatVersion(arr.getKey()));
|
||||
iv.universal = DownloadType.getSuggestedDownloadType().getProvider().getParsedDownloadURL("http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + arr.getKey() + "/" + v.file);
|
||||
iv.tweakClass = v.tweakClass;
|
||||
iv.libraries = Arrays.copyOf(v.libraries, v.libraries.length);
|
||||
iv.installer = "http://dl.liteloader.com/redist/" + iv.mcVersion + "/liteloader-installer-" + iv.selfVersion.replace("_", "-") + ".jar";
|
||||
al.add(iv);
|
||||
versions.add(iv);
|
||||
}
|
||||
Collections.sort(al, new InstallerVersionNewerComparator());
|
||||
versionMap.put(StrUtils.formatVersion(arr.getKey()), al);
|
||||
}
|
||||
|
||||
Collections.sort(versions, InstallerVersionComparator.INSTANCE);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "LiteLoader - LiteLoader Official Site(By: Mumfrey)";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* 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.install.liteloader;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class LiteLoaderVersionsMeta {
|
||||
|
||||
@SerializedName("versions")
|
||||
private String description;
|
||||
@SerializedName("authors")
|
||||
private String authors;
|
||||
@SerializedName("url")
|
||||
private String url;
|
||||
|
||||
public LiteLoaderVersionsMeta() {
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getAuthors() {
|
||||
return authors;
|
||||
}
|
||||
|
||||
public void setAuthors(String authors) {
|
||||
this.authors = authors;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* 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.install.liteloader;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class LiteLoaderVersionsRoot {
|
||||
|
||||
@SerializedName("versions")
|
||||
public Map<String, LiteLoaderMCVersions> versions;
|
||||
@SerializedName("meta")
|
||||
public LiteLoaderVersionsMeta meta;
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
* 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.install.optifine;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.zip.ZipFile;
|
||||
import org.jackhuang.hellominecraft.api.HMCAPI;
|
||||
import org.jackhuang.hellominecraft.launcher.api.event.version.MinecraftLibraryPathEvent;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
|
||||
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.LibrariesDownloadInfo;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.LibraryDownloadInfo;
|
||||
import org.jackhuang.hellominecraft.util.task.Task;
|
||||
import org.jackhuang.hellominecraft.util.task.comm.PreviousResult;
|
||||
import org.jackhuang.hellominecraft.util.task.comm.PreviousResultRegistrar;
|
||||
import org.jackhuang.hellominecraft.util.sys.FileUtils;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
|
||||
import org.jackhuang.hellominecraft.util.Wrapper;
|
||||
import org.jackhuang.hellominecraft.util.log.HMCLog;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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, File installer) {
|
||||
this.service = service;
|
||||
this.installId = installId;
|
||||
this.installer = installer;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) 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();
|
||||
MinecraftLibrary library = new MinecraftLibrary("optifine:OptiFine:" + selfId);
|
||||
library.downloads = new LibrariesDownloadInfo();
|
||||
library.downloads.artifact = new LibraryDownloadInfo();
|
||||
library.downloads.artifact.path = "optifine/OptiFine/" + selfId + "/OptiFine-" + selfId + ".jar";
|
||||
library.downloads.artifact.url = version.universal;
|
||||
library.downloads.artifact.sha1 = null;
|
||||
library.downloads.artifact.size = 0;
|
||||
mv.libraries.add(0, library);
|
||||
|
||||
MinecraftLibraryPathEvent event = new MinecraftLibraryPathEvent(this, "libraries/" + library.downloads.artifact.path, new Wrapper<>(new File(service.baseDirectory(), "libraries/" + library.downloads.artifact.path)));
|
||||
HMCAPI.EVENT_BUS.fireChannel(event);
|
||||
FileUtils.copyFile(installer, event.getFile().getValue());
|
||||
|
||||
mv.id += "-" + selfId;
|
||||
try (ZipFile zipFile = new ZipFile(installer)) {
|
||||
if (zipFile.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"));
|
||||
}
|
||||
if (!mv.minecraftArguments.contains("FMLTweaker"))
|
||||
mv.minecraftArguments += " --tweakClass optifine.OptiFineTweaker";
|
||||
}
|
||||
}
|
||||
File loc = new File(service.baseDirectory(), "versions/" + mv.id);
|
||||
if (!FileUtils.makeDirectory(loc))
|
||||
HMCLog.warn("Failed to make directories: " + loc);
|
||||
File json = new File(loc, mv.id + ".json");
|
||||
FileUtils.write(json, C.GSON.toJson(mv, MinecraftVersion.class));
|
||||
|
||||
service.version().refreshVersions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInfo() {
|
||||
return "OptiFine Installer";
|
||||
}
|
||||
|
||||
ArrayList<PreviousResult<File>> pre = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public Task registerPreviousResult(PreviousResult<File> pr) {
|
||||
pre.add(pr);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* 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.install.optifine;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class OptiFineVersion {
|
||||
|
||||
private String dl, ver, date, mirror, mcversion;
|
||||
public String patch, type; // For BMCLAPI2.
|
||||
|
||||
public String getDownloadLink() {
|
||||
return dl;
|
||||
}
|
||||
|
||||
public void setDownloadLink(String dl) {
|
||||
this.dl = dl;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return ver;
|
||||
}
|
||||
|
||||
public void setVersion(String ver) {
|
||||
this.ver = ver;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(String date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public String getMirror() {
|
||||
return mirror;
|
||||
}
|
||||
|
||||
public void setMirror(String mirror) {
|
||||
this.mirror = mirror;
|
||||
}
|
||||
|
||||
public String getMCVersion() {
|
||||
return mcversion;
|
||||
}
|
||||
|
||||
public void setMCVersion(String mcver) {
|
||||
this.mcversion = mcver;
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* 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.install.optifine.bmcl;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.util.ArrayUtils;
|
||||
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
|
||||
import org.jackhuang.hellominecraft.launcher.core.install.optifine.OptiFineVersion;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
import org.jackhuang.hellominecraft.util.task.Task;
|
||||
import org.jackhuang.hellominecraft.util.task.TaskInfo;
|
||||
import org.jackhuang.hellominecraft.util.net.HTTPGetTask;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class OptiFineBMCLVersionList extends InstallerVersionList {
|
||||
|
||||
private static OptiFineBMCLVersionList instance;
|
||||
|
||||
public static OptiFineBMCLVersionList getInstance() {
|
||||
if (null == instance)
|
||||
instance = new OptiFineBMCLVersionList();
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ArrayList<OptiFineVersion> root;
|
||||
|
||||
private static final Type TYPE = new TypeToken<ArrayList<OptiFineVersion>>() {
|
||||
}.getType();
|
||||
|
||||
@Override
|
||||
public Task refresh(String[] needed) {
|
||||
return new TaskInfo(C.i18n("install.optifine.get_list")) {
|
||||
HTTPGetTask task = new HTTPGetTask("http://bmclapi.bangbang93.com/optifine/versionlist");
|
||||
|
||||
@Override
|
||||
public Collection<Task> getDependTasks() {
|
||||
return Arrays.asList(task.setTag("BMCL Optifine Download Site"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
String s = task.getResult();
|
||||
|
||||
versionMap = new HashMap<>();
|
||||
versions = new ArrayList<>();
|
||||
|
||||
HashSet<String> duplicates = new HashSet<>();
|
||||
|
||||
if (s == null)
|
||||
return;
|
||||
root = C.GSON.fromJson(s, TYPE);
|
||||
for (OptiFineVersion v : root) {
|
||||
v.setVersion(v.type + '_' + v.patch);
|
||||
v.setMirror(String.format("http://bmclapi2.bangbang93.com/optifine/%s/%s/%s", v.getMCVersion(), v.type, v.patch));
|
||||
if (duplicates.contains(v.getMirror()))
|
||||
continue;
|
||||
else
|
||||
duplicates.add(v.getMirror());
|
||||
InstallerVersion iv = new InstallerVersion(v.getVersion(), StrUtils.formatVersion(v.getMCVersion()));
|
||||
|
||||
List<InstallerVersion> al = ArrayUtils.tryGetMapWithList(versionMap, StrUtils.formatVersion(v.getMCVersion()));
|
||||
iv.installer = iv.universal = v.getMirror();
|
||||
al.add(iv);
|
||||
versions.add(iv);
|
||||
}
|
||||
|
||||
Collections.sort(versions, InstallerVersionComparator.INSTANCE);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "OptiFine - BMCLAPI(By: bangbang93)";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* 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.install.optifine.vanilla;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.util.task.Task;
|
||||
import org.jackhuang.hellominecraft.util.task.comm.PreviousResult;
|
||||
import org.jackhuang.hellominecraft.util.net.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(boolean areDependTasksSucceeded) 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,138 +0,0 @@
|
||||
/*
|
||||
* 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.install.optifine.vanilla;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
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.core.install.InstallerVersionList;
|
||||
import org.jackhuang.hellominecraft.launcher.core.install.optifine.OptiFineVersion;
|
||||
import org.jackhuang.hellominecraft.util.ArrayUtils;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
import org.jackhuang.hellominecraft.util.task.Task;
|
||||
import org.jackhuang.hellominecraft.util.task.TaskInfo;
|
||||
import org.jackhuang.hellominecraft.util.net.HTTPGetTask;
|
||||
import org.w3c.dom.DOMException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class OptiFineVersionList extends InstallerVersionList {
|
||||
|
||||
private static OptiFineVersionList instance;
|
||||
|
||||
public static OptiFineVersionList getInstance() {
|
||||
if (null == instance)
|
||||
instance = new OptiFineVersionList();
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ArrayList<OptiFineVersion> root = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public Task refresh(String[] sss) {
|
||||
if (versions != null)
|
||||
return null;
|
||||
return new TaskInfo(C.i18n("install.optifine.get_list")) {
|
||||
HTTPGetTask task = new HTTPGetTask("http://optifine.net/downloads");
|
||||
|
||||
@Override
|
||||
public Collection<Task> getDependTasks() {
|
||||
return Arrays.asList(task.setTag("Optifine Download Site"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
if (!areDependTasksSucceeded)
|
||||
return;
|
||||
String content = task.getResult();
|
||||
versionMap = new HashMap<>();
|
||||
versions = new ArrayList<>();
|
||||
|
||||
content = content.replace(" ", " ").replace(">", ">").replace("<", "<").replace("<br>", "<br />");
|
||||
|
||||
try {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db = factory.newDocumentBuilder();
|
||||
Document doc = db.parse(new ByteArrayInputStream(content.getBytes("UTF-8")));
|
||||
Element r = doc.getDocumentElement();
|
||||
NodeList tables = r.getElementsByTagName("table");
|
||||
for (int i = 0; i < tables.getLength(); i++) {
|
||||
Element e = (Element) tables.item(i);
|
||||
if ("downloadTable".equals(e.getAttribute("class"))) {
|
||||
NodeList tr = e.getElementsByTagName("tr");
|
||||
for (int k = 0; k < tr.getLength(); k++) {
|
||||
NodeList downloadLine = ((Element) tr.item(k)).getElementsByTagName("td");
|
||||
OptiFineVersion v = new OptiFineVersion();
|
||||
for (int j = 0; j < downloadLine.getLength(); j++) {
|
||||
Element td = (Element) downloadLine.item(j);
|
||||
if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineMirror"))
|
||||
v.setMirror(((Element) td.getElementsByTagName("a").item(0)).getAttribute("href"));
|
||||
if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineDownload"))
|
||||
v.setDownloadLink(((Element) td.getElementsByTagName("a").item(0)).getAttribute("href"));
|
||||
if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineDate"))
|
||||
v.setDate(td.getTextContent());
|
||||
if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineFile"))
|
||||
v.setVersion(td.getTextContent());
|
||||
}
|
||||
if (StrUtils.isBlank(v.getMCVersion())) {
|
||||
Pattern p = Pattern.compile("OptiFine (.*?) ");
|
||||
Matcher m = p.matcher(v.getVersion());
|
||||
while (m.find())
|
||||
v.setMCVersion(StrUtils.formatVersion(m.group(1)));
|
||||
}
|
||||
InstallerVersion iv = new InstallerVersion(v.getVersion(), StrUtils.formatVersion(v.getMCVersion()));
|
||||
iv.installer = iv.universal = v.getMirror();
|
||||
root.add(v);
|
||||
versions.add(iv);
|
||||
|
||||
List<InstallerVersion> ivl = ArrayUtils.tryGetMapWithList(versionMap, StrUtils.formatVersion(v.getMCVersion()));
|
||||
ivl.add(iv);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ParserConfigurationException | SAXException | IOException | DOMException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
Collections.sort(versions, InstallerVersionComparator.INSTANCE);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "OptiFine - OptiFine Official Site";
|
||||
}
|
||||
}
|
||||
@@ -1,196 +0,0 @@
|
||||
/*
|
||||
* 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.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.util.log.HMCLog;
|
||||
import org.jackhuang.hellominecraft.util.sys.JdkVersion;
|
||||
import org.jackhuang.hellominecraft.util.MathUtils;
|
||||
import org.jackhuang.hellominecraft.util.MessageBox;
|
||||
import org.jackhuang.hellominecraft.util.sys.OS;
|
||||
import org.jackhuang.hellominecraft.util.sys.Platform;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
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.launcher.core.service.IMinecraftService;
|
||||
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftLoader;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
|
||||
|
||||
protected LaunchOptions options;
|
||||
protected UserProfileProvider lr;
|
||||
protected File gameDir;
|
||||
protected IMinecraftService service;
|
||||
protected final MinecraftVersion version;
|
||||
|
||||
public AbstractMinecraftLoader(LaunchOptions options, IMinecraftService service, String versionId, UserProfileProvider lr) throws GameException {
|
||||
if (service.version().getVersionById(versionId) == null)
|
||||
throw new GameException("No version: " + versionId);
|
||||
this.lr = lr;
|
||||
|
||||
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.");
|
||||
|
||||
if (StrUtils.isNotBlank(options.getWrapper()))
|
||||
res.add(options.getWrapper());
|
||||
|
||||
JdkVersion jv = options.getJava();
|
||||
res.add(options.getJavaDir());
|
||||
|
||||
if (options.hasJavaArgs())
|
||||
res.addAll(Arrays.asList(StrUtils.tokenize(options.getJavaArgs())));
|
||||
|
||||
if (!options.isNoJVMArgs()) {
|
||||
appendJVMArgs(res);
|
||||
|
||||
if (jv == null || !jv.isEarlyAccess()) {
|
||||
if (OS.os() == OS.WINDOWS)
|
||||
res.add("-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump");
|
||||
if (jv != null && jv.getParsedVersion() >= JdkVersion.JAVA_17)
|
||||
res.add("-XX:+UseG1GC");
|
||||
else
|
||||
res.add("-Xincgc");
|
||||
res.add("-XX:-UseAdaptiveSizePolicy");
|
||||
res.add("-XX:-OmitStackTraceInFastThrow");
|
||||
|
||||
res.add("-Xmn128m");
|
||||
}
|
||||
if (!StrUtils.isBlank(options.getPermSize()))
|
||||
if (jv == null || jv.getParsedVersion() < JdkVersion.JAVA_18)
|
||||
res.add("-XX:PermSize=" + options.getPermSize() + "m");
|
||||
else if (jv.getParsedVersion() >= JdkVersion.JAVA_18)
|
||||
res.add("-XX:MetaspaceSize=" + options.getPermSize() + "m");
|
||||
}
|
||||
|
||||
if (jv != null) {
|
||||
HMCLog.log("Java Version: " + jv.getVersion());
|
||||
HMCLog.log("Java Platform: " + jv.getPlatform().getBit());
|
||||
}
|
||||
HMCLog.log("System Platform: " + Platform.getPlatform().getBit());
|
||||
|
||||
if (jv != null && jv.getPlatform() == Platform.BIT_32 && Platform.getPlatform() == Platform.BIT_64)
|
||||
MessageBox.show(C.i18n("advice.os64butjdk32"));
|
||||
|
||||
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 {
|
||||
long a = OS.getTotalPhysicalMemory() / 1024 / 1024;
|
||||
HMCLog.log("System Physical Memory: " + a);
|
||||
if (a > 0 && a < mem)
|
||||
MessageBox.show(C.i18n("launch.too_big_memory_alloc_free_space_too_low", a));
|
||||
}
|
||||
String a = "-Xmx" + options.getMaxMemory();
|
||||
if (MathUtils.canParseInt(options.getMaxMemory()))
|
||||
a += "m";
|
||||
res.add(a);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> makeLaunchingCommand() throws GameException {
|
||||
HMCLog.log("*** Make shell command ***");
|
||||
|
||||
ArrayList<String> res = new ArrayList<>();
|
||||
|
||||
makeHeadCommand(res);
|
||||
makeSelf(res);
|
||||
|
||||
HMCLog.log("On making launcher args.");
|
||||
|
||||
if (StrUtils.isNotBlank(options.getHeight()) && StrUtils.isNotBlank(options.getWidth())) {
|
||||
res.add("--height");
|
||||
res.add(options.getHeight());
|
||||
res.add("--width");
|
||||
res.add(options.getWidth());
|
||||
}
|
||||
|
||||
String serverIp = options.getServerIp();
|
||||
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 (options.isFullscreen())
|
||||
res.add("--fullscreen");
|
||||
|
||||
if (StrUtils.isNotBlank(options.getProxyHost()) && StrUtils.isNotBlank(options.getProxyPort()) && MathUtils.canParseInt(options.getProxyPort())) {
|
||||
res.add("--proxyHost");
|
||||
res.add(options.getProxyHost());
|
||||
res.add("--proxyPort");
|
||||
res.add(options.getProxyPort());
|
||||
if (StrUtils.isNotBlank(options.getProxyUser()) && StrUtils.isNotBlank(options.getProxyPass())) {
|
||||
res.add("--proxyUser");
|
||||
res.add(options.getProxyUser());
|
||||
res.add("-=proxyPass");
|
||||
res.add(options.getProxyPass());
|
||||
}
|
||||
}
|
||||
|
||||
if (StrUtils.isNotBlank(options.getMinecraftArgs()))
|
||||
res.addAll(Arrays.asList(options.getMinecraftArgs().split(" ")));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* You must do these things:
|
||||
* <ul>
|
||||
* <li>minecraft class path</li>
|
||||
* <li>main class</li>
|
||||
* <li>minecraft arguments</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list the command list you shoud edit.
|
||||
*/
|
||||
protected abstract void makeSelf(List<String> list) throws GameException;
|
||||
|
||||
protected void appendJVMArgs(List<String> list) {
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* 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 java.util.HashSet;
|
||||
import java.util.List;
|
||||
import org.jackhuang.hellominecraft.api.HMCAPI;
|
||||
import org.jackhuang.hellominecraft.api.ResultedSimpleEvent;
|
||||
import org.jackhuang.hellominecraft.launcher.api.event.launch.DecompressLibrariesEvent;
|
||||
import org.jackhuang.hellominecraft.launcher.api.event.launch.DownloadLibrariesEvent;
|
||||
import org.jackhuang.hellominecraft.launcher.api.event.launch.DownloadLibraryJob;
|
||||
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
|
||||
import org.jackhuang.hellominecraft.launcher.core.auth.LoginInfo;
|
||||
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.util.MessageBox;
|
||||
import org.jackhuang.hellominecraft.util.log.HMCLog;
|
||||
import org.jackhuang.hellominecraft.util.sys.CompressingUtils;
|
||||
import org.jackhuang.hellominecraft.util.task.ParallelTask;
|
||||
import org.jackhuang.hellominecraft.util.task.TaskWindow;
|
||||
|
||||
|
||||
public class DefaultGameLauncher extends GameLauncher {
|
||||
|
||||
public DefaultGameLauncher(LaunchOptions options, IMinecraftService service, LoginInfo info, IAuthenticator lg) {
|
||||
super(options, service, info, lg);
|
||||
register();
|
||||
}
|
||||
|
||||
private void register() {
|
||||
HMCAPI.EVENT_BUS.channel(DownloadLibrariesEvent.class).register(t -> {
|
||||
ResultedSimpleEvent<List<DownloadLibraryJob>> event = (ResultedSimpleEvent) t;
|
||||
final TaskWindow.TaskWindowFactory dw = TaskWindow.factory();
|
||||
ParallelTask parallelTask = new ParallelTask();
|
||||
HashSet<String> names = new HashSet<>();
|
||||
for (DownloadLibraryJob s : t.getValue()) {
|
||||
if (names.contains(s.lib.name))
|
||||
continue;
|
||||
names.add(s.lib.name);
|
||||
parallelTask.addTask(new LibraryDownloadTask(s));
|
||||
}
|
||||
dw.append(parallelTask);
|
||||
boolean flag = true;
|
||||
if (t.getValue().size() > 0)
|
||||
flag = dw.execute();
|
||||
if (!flag && MessageBox.show(C.i18n("launch.not_finished_downloading_libraries"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
|
||||
flag = true;
|
||||
t.setResult(flag);
|
||||
});
|
||||
HMCAPI.EVENT_BUS.channel(DecompressLibrariesEvent.class).register(t -> {
|
||||
if (t.getValue() == null) {
|
||||
t.setResult(false);
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < t.getValue().decompressFiles.length; i++)
|
||||
try {
|
||||
CompressingUtils.unzip(t.getValue().decompressFiles[i], t.getValue().getDecompressTo(), t.getValue().extractRules[i]::allow, false);
|
||||
} catch (IOException ex) {
|
||||
HMCLog.err("Unable to decompress library: " + t.getValue().decompressFiles[i] + " to " + t.getValue().getDecompressTo(), ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,201 +0,0 @@
|
||||
/*
|
||||
* 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.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.List;
|
||||
import org.jackhuang.hellominecraft.api.HMCAPI;
|
||||
import org.jackhuang.hellominecraft.launcher.api.event.launch.DecompressLibrariesEvent;
|
||||
import org.jackhuang.hellominecraft.launcher.api.event.launch.DecompressLibraryJob;
|
||||
import org.jackhuang.hellominecraft.launcher.api.event.launch.DownloadLibrariesEvent;
|
||||
import org.jackhuang.hellominecraft.launcher.api.event.launch.LaunchEvent;
|
||||
import org.jackhuang.hellominecraft.launcher.api.event.launch.LaunchSucceededEvent;
|
||||
import org.jackhuang.hellominecraft.launcher.api.event.launch.LaunchingState;
|
||||
import org.jackhuang.hellominecraft.launcher.api.event.launch.LaunchingStateChangedEvent;
|
||||
import org.jackhuang.hellominecraft.launcher.api.event.launch.ProcessingLoginResultEvent;
|
||||
import org.jackhuang.hellominecraft.launcher.core.GameException;
|
||||
import org.jackhuang.hellominecraft.launcher.core.RuntimeGameException;
|
||||
import org.jackhuang.hellominecraft.launcher.core.auth.AuthenticationException;
|
||||
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.service.IMinecraftLoader;
|
||||
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
import org.jackhuang.hellominecraft.util.code.Charsets;
|
||||
import org.jackhuang.hellominecraft.util.log.HMCLog;
|
||||
import org.jackhuang.hellominecraft.util.sys.FileUtils;
|
||||
import org.jackhuang.hellominecraft.util.sys.IOUtils;
|
||||
import org.jackhuang.hellominecraft.util.sys.JavaProcess;
|
||||
import org.jackhuang.hellominecraft.util.sys.OS;
|
||||
import org.jackhuang.hellominecraft.util.sys.ProcessManager;
|
||||
|
||||
public class GameLauncher {
|
||||
|
||||
public static final ProcessManager PROCESS_MANAGER = new ProcessManager();
|
||||
LaunchOptions options;
|
||||
IMinecraftService service;
|
||||
LoginInfo info;
|
||||
UserProfileProvider result;
|
||||
IAuthenticator login;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the launch command.
|
||||
* @throws AuthenticationException having trouble logging in.
|
||||
* @throws GameException having trouble completing the game or making lanch command.
|
||||
* @throws RuntimeGameException will be thrown when someone processing login result.
|
||||
* @see LaunchingStateChangedEvent
|
||||
* @see DecompressLibrariesEvent
|
||||
* @see LaunchSucceededEvent
|
||||
* @see DownloadLibrariesEvent
|
||||
* @see ProcessingLoginResultEvent
|
||||
*/
|
||||
public void makeLaunchCommand() throws AuthenticationException, GameException, RuntimeGameException {
|
||||
HMCLog.log("Building process");
|
||||
HMCLog.log("Logging in...");
|
||||
HMCAPI.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(this, LaunchingState.LoggingIn));
|
||||
IMinecraftLoader loader;
|
||||
if (info != null)
|
||||
result = login.login(info);
|
||||
else
|
||||
result = login.loginBySettings();
|
||||
if (result == null)
|
||||
throw new AuthenticationException("Result can not be null.");
|
||||
HMCAPI.EVENT_BUS.fireChannel(new ProcessingLoginResultEvent(this, result));
|
||||
|
||||
HMCAPI.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(this, LaunchingState.GeneratingLaunchingCodes));
|
||||
loader = service.launch(options, result);
|
||||
|
||||
File file = service.version().getDecompressNativesToLocation(loader.getMinecraftVersion());
|
||||
if (file != null)
|
||||
FileUtils.cleanDirectoryQuietly(file);
|
||||
|
||||
if (!options.isNotCheckGame()) {
|
||||
HMCLog.log("Detecting libraries...");
|
||||
HMCAPI.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(this, LaunchingState.DownloadingLibraries));
|
||||
if (!HMCAPI.EVENT_BUS.fireChannelResulted(new DownloadLibrariesEvent(this, service.download().getDownloadLibraries(loader.getMinecraftVersion()))))
|
||||
throw new GameException("Failed to download libraries");
|
||||
}
|
||||
|
||||
HMCLog.log("Unpacking natives...");
|
||||
HMCAPI.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(this, LaunchingState.DecompressingNatives));
|
||||
DecompressLibraryJob job = service.version().getDecompressLibraries(loader.getMinecraftVersion());
|
||||
if (!HMCAPI.EVENT_BUS.fireChannelResulted(new DecompressLibrariesEvent(this, job)))
|
||||
throw new GameException("Failed to decompress natives");
|
||||
|
||||
HMCAPI.EVENT_BUS.fireChannel(new LaunchSucceededEvent(this, loader.makeLaunchingCommand()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch the game "as soon as possible".
|
||||
*
|
||||
* @param str launch command
|
||||
* @throws IOException failed creating process
|
||||
*/
|
||||
public void launch(List<String> str) throws IOException {
|
||||
if (!service.version().onLaunch(options.getLaunchVersion()))
|
||||
return;
|
||||
if (StrUtils.isNotBlank(options.getPrecalledCommand())) {
|
||||
Process p = Runtime.getRuntime().exec(options.getPrecalledCommand());
|
||||
try {
|
||||
if (p.isAlive())
|
||||
p.waitFor();
|
||||
} catch (InterruptedException ex) {
|
||||
HMCLog.warn("Failed to invoke precalled command", ex);
|
||||
}
|
||||
}
|
||||
HMCLog.log("Starting process");
|
||||
HMCLog.log(str.toString());
|
||||
ProcessBuilder builder = new ProcessBuilder(str);
|
||||
if (options.getLaunchVersion() == null || service.baseDirectory() == null)
|
||||
throw new Error("Fucking bug!");
|
||||
builder.redirectErrorStream(true).directory(service.version().getRunDirectory(options.getLaunchVersion()))
|
||||
.environment().put("APPDATA", service.baseDirectory().getAbsolutePath());
|
||||
JavaProcess jp = new JavaProcess(str, builder.start(), PROCESS_MANAGER);
|
||||
HMCLog.log("Have started the process");
|
||||
HMCAPI.EVENT_BUS.fireChannel(new LaunchEvent(this, 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<String> str) throws IOException {
|
||||
HMCLog.log("Making shell launcher...");
|
||||
service.version().onLaunch(options.getLaunchVersion());
|
||||
boolean isWin = OS.os() == OS.WINDOWS;
|
||||
File f = new File(launcherName + (isWin ? ".bat" : ".sh"));
|
||||
if (!f.exists() && !f.createNewFile())
|
||||
HMCLog.warn("Failed to create " + f);
|
||||
BufferedWriter writer;
|
||||
try (FileOutputStream fos = FileUtils.openOutputStream(f)) {
|
||||
writer = new BufferedWriter(new OutputStreamWriter(fos, Charsets.toCharset()));
|
||||
if (isWin) {
|
||||
writer.write("@echo off");
|
||||
writer.newLine();
|
||||
String appdata = IOUtils.tryGetCanonicalFilePath(service.baseDirectory());
|
||||
if (appdata != null) {
|
||||
writer.write("set appdata=" + appdata);
|
||||
writer.newLine();
|
||||
writer.write("cd /D %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))
|
||||
throw new IOException(C.i18n("launch.failed_sh_permission"));
|
||||
|
||||
HMCLog.log("Command: " + StrUtils.parseParams("", str, " "));
|
||||
return f;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* 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 org.jackhuang.hellominecraft.launcher.core.GameException;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huang
|
||||
*/
|
||||
public interface IAssetProvider {
|
||||
|
||||
String provide(MinecraftVersion mv, Boolean allowChecking) throws GameException;
|
||||
}
|
||||
@@ -1,233 +0,0 @@
|
||||
/*
|
||||
* 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.version.GameDirType;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
import org.jackhuang.hellominecraft.util.sys.JdkVersion;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class LaunchOptions {
|
||||
|
||||
private String name, versionName, javaArgs, minecraftArgs, maxMemory, permSize, width, height, serverIp, wrapper;
|
||||
private String proxyHost, proxyPort, proxyUser, proxyPass, javaDir, launchVersion, type, precalledCommand;
|
||||
private boolean fullscreen, noJVMArgs, notCheckGame;
|
||||
private JdkVersion java;
|
||||
private File gameDir;
|
||||
private GameDirType gameDirType;
|
||||
|
||||
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 getWrapper() {
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
public void setWrapper(String wrapper) {
|
||||
this.wrapper = wrapper;
|
||||
}
|
||||
|
||||
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 boolean isFullscreen() {
|
||||
return fullscreen;
|
||||
}
|
||||
|
||||
public void setFullscreen(boolean fullscreen) {
|
||||
this.fullscreen = fullscreen;
|
||||
}
|
||||
|
||||
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 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public boolean isNotCheckGame() {
|
||||
return notCheckGame;
|
||||
}
|
||||
|
||||
public void setNotCheckGame(boolean notCheckGame) {
|
||||
this.notCheckGame = notCheckGame;
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* 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.util.C;
|
||||
import org.jackhuang.hellominecraft.launcher.api.event.launch.DownloadLibraryJob;
|
||||
import org.jackhuang.hellominecraft.util.net.FileDownloadTask;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class LibraryDownloadTask extends FileDownloadTask {
|
||||
|
||||
DownloadLibraryJob job;
|
||||
|
||||
public LibraryDownloadTask(DownloadLibraryJob job) {
|
||||
super(job.parse().url, job.path);
|
||||
this.job = job;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInfo() {
|
||||
return C.i18n("download") + ": " + job.lib.name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* 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.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
import org.jackhuang.hellominecraft.util.log.HMCLog;
|
||||
import org.jackhuang.hellominecraft.util.sys.IOUtils;
|
||||
import org.jackhuang.hellominecraft.util.sys.OS;
|
||||
import org.jackhuang.hellominecraft.launcher.core.GameException;
|
||||
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
|
||||
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class MinecraftLoader extends AbstractMinecraftLoader {
|
||||
|
||||
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 {
|
||||
StringBuilder library = new StringBuilder("");
|
||||
ArrayList<MinecraftLibrary> opt = new ArrayList<>();
|
||||
for (MinecraftLibrary l : version.libraries)
|
||||
if (l.allow() && !l.isRequiredToUnzip()) {
|
||||
if (l.name.toLowerCase(Locale.US).contains("optifine")) {
|
||||
opt.add(l);
|
||||
continue;
|
||||
}
|
||||
File f = l.getFilePath(gameDir);
|
||||
if (f == null)
|
||||
continue;
|
||||
library.append(f.getAbsolutePath()).append(File.pathSeparator);
|
||||
}
|
||||
for (MinecraftLibrary l : opt) {
|
||||
File f = l.getFilePath(gameDir);
|
||||
if (f == null)
|
||||
continue;
|
||||
library.append(f.getAbsolutePath()).append(File.pathSeparator);
|
||||
}
|
||||
File f = version.getJar(service.baseDirectory());
|
||||
if (!f.exists())
|
||||
throw new GameException("Minecraft jar does not exists");
|
||||
library.append(IOUtils.tryGetCanonicalFilePath(f)).append(File.pathSeparator);
|
||||
res.add("-cp");
|
||||
res.add(library.toString().substring(0, library.length() - File.pathSeparator.length()));
|
||||
res.add(version.mainClass);
|
||||
|
||||
if (version.minecraftArguments == null)
|
||||
throw new GameException(new NullPointerException("Minecraft Arguments can not be null."));
|
||||
String[] splitted = StrUtils.tokenize(version.minecraftArguments);
|
||||
|
||||
String game_assets = assetProvider.provide(version, !options.isNotCheckGame());
|
||||
|
||||
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}", options.getVersionName());
|
||||
t = t.replace("${profile_name}", options.getName());
|
||||
t = t.replace("${version_type}", options.getType());
|
||||
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(version.getAssetsIndex().getId()).getAbsolutePath());
|
||||
t = t.replace("${auth_access_token}", lr.getAccessToken());
|
||||
t = t.replace("${user_type}", lr.getUserType());
|
||||
t = t.replace("${assets_index_name}", version.getAssetsIndex().getId());
|
||||
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.getAssetsIndex().getId(), "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 final IAssetProvider DEFAULT_ASSET_PROVIDER = (t, allow) -> {
|
||||
return new File(service.baseDirectory(), "assets").getAbsolutePath();
|
||||
};
|
||||
|
||||
private IAssetProvider assetProvider = DEFAULT_ASSET_PROVIDER;
|
||||
|
||||
public void setAssetProvider(IAssetProvider assetProvider) {
|
||||
if (assetProvider == null)
|
||||
this.assetProvider = DEFAULT_ASSET_PROVIDER;
|
||||
else
|
||||
this.assetProvider = assetProvider;
|
||||
}
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* 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.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.util.log.HMCLog;
|
||||
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftModService;
|
||||
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
|
||||
import org.jackhuang.hellominecraft.util.sys.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))
|
||||
mods.add(ModInfo.readModInfo(f));
|
||||
else if (f.isDirectory()) {
|
||||
File[] ss = f.listFiles();
|
||||
if (ss != null)
|
||||
for (File ff : ss)
|
||||
if (ModInfo.isFileMod(ff))
|
||||
mods.add(ModInfo.readModInfo(ff));
|
||||
}
|
||||
Collections.sort(mods);
|
||||
modCache.put(id, mods);
|
||||
return mods;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addMod(String id, File f) {
|
||||
try {
|
||||
if (!ModInfo.isFileMod(f))
|
||||
return false;
|
||||
if (!modCache.containsKey(id))
|
||||
recacheMods(id);
|
||||
File modsFolder = service.version().getRunDirectory(id, "mods");
|
||||
if (!FileUtils.makeDirectory(modsFolder))
|
||||
HMCLog.warn("Failed to make directories: " + modsFolder);
|
||||
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 boolean removeMod(String id, Object[] rows) {
|
||||
if (rows.length == 0)
|
||||
return true;
|
||||
boolean flag = true;
|
||||
for (Object r : rows)
|
||||
if (r instanceof ModInfo) {
|
||||
if (!((ModInfo) r).location.delete()) {
|
||||
HMCLog.warn("Failed to delete mod" + r);
|
||||
flag = false;
|
||||
}
|
||||
} else if (r instanceof Number)
|
||||
if (!getMods(id).get(((Number) r).intValue()).location.delete()) {
|
||||
HMCLog.warn("Failed to delete mod " + r + ", maybe not a file?");
|
||||
flag = false;
|
||||
}
|
||||
recacheMods(id);
|
||||
return flag;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huang
|
||||
*/
|
||||
public interface ModAdviser {
|
||||
|
||||
ModSuggestion advise(String fileName, boolean isDirectory);
|
||||
|
||||
public static enum ModSuggestion {
|
||||
SUGGESTED,
|
||||
NORMAL,
|
||||
HIDDEN
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,186 +0,0 @@
|
||||
/*
|
||||
* 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 com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
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.util.C;
|
||||
import org.jackhuang.hellominecraft.util.log.HMCLog;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
import org.jackhuang.hellominecraft.util.sys.FileUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class ModInfo implements Comparable<ModInfo> {
|
||||
|
||||
@SerializedName("location")
|
||||
public File location;
|
||||
@SerializedName("modid")
|
||||
public String modid;
|
||||
@SerializedName("name")
|
||||
public String name;
|
||||
@SerializedName("description")
|
||||
public String description;
|
||||
@SerializedName("author")
|
||||
public String author;
|
||||
@SerializedName("version")
|
||||
public String version;
|
||||
@SerializedName("mcversion")
|
||||
public String mcversion;
|
||||
@SerializedName("url")
|
||||
public String url;
|
||||
@SerializedName("updateUrl")
|
||||
public String updateUrl;
|
||||
@SerializedName("credits")
|
||||
public String credits;
|
||||
@SerializedName("authorList")
|
||||
public String[] authorList;
|
||||
@SerializedName("authors")
|
||||
public String[] authors;
|
||||
|
||||
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().compareToIgnoreCase(o.getFileName());
|
||||
}
|
||||
|
||||
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 (authors != null && authors.length > 0)
|
||||
return StrUtils.parseParams("", authors, ", ");
|
||||
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, JsonSyntaxException {
|
||||
ModInfo i = new ModInfo();
|
||||
i.location = f;
|
||||
|
||||
InputStreamReader streamReader = new InputStreamReader(jar.getInputStream(entry), "UTF-8");
|
||||
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonElement element = parser.parse(streamReader);
|
||||
List<ModInfo> m = null;
|
||||
if (element.isJsonArray())
|
||||
m = C.GSON.fromJson(element, new TypeToken<List<ModInfo>>() {
|
||||
}.getType());
|
||||
else if (element.isJsonObject()) {
|
||||
JsonObject modInfo = element.getAsJsonObject();
|
||||
if (modInfo.has("modList") && modInfo.get("modList").isJsonArray())
|
||||
m = C.GSON.fromJson(modInfo.get("modList"), 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), "UTF-8"), 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,273 +0,0 @@
|
||||
/*
|
||||
* 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.awt.Dimension;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.file.FileSystemException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.zip.ZipFile;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import org.jackhuang.hellominecraft.util.C;
|
||||
import org.jackhuang.hellominecraft.util.log.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.util.func.CallbackIO;
|
||||
import org.jackhuang.hellominecraft.util.sys.CompressingUtils;
|
||||
import org.jackhuang.hellominecraft.util.sys.FileUtils;
|
||||
import org.jackhuang.hellominecraft.util.sys.ZipEngine;
|
||||
import org.jackhuang.hellominecraft.util.task.Task;
|
||||
import org.jackhuang.hellominecraft.util.net.WebPage;
|
||||
import org.jackhuang.hellominecraft.util.MinecraftVersionRequest;
|
||||
import org.jackhuang.hellominecraft.util.sys.IOUtils;
|
||||
import org.jackhuang.hellominecraft.util.task.NoShownTaskException;
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
|
||||
/**
|
||||
* Install the compressed modpack.
|
||||
*
|
||||
* @param input modpack.zip
|
||||
* @param service MinecraftService, whose version service only supports
|
||||
* MinecraftVersionManager.
|
||||
* @param id new version id, if null, will use suggested name from
|
||||
* modpack
|
||||
*
|
||||
* @return The installing Task, may take long time, please consider
|
||||
* TaskWindow.
|
||||
*/
|
||||
public static Task install(JFrame parFrame, final File input, final IMinecraftService service, final String idFUCK) {
|
||||
return new Task() {
|
||||
Collection<Task> c = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
|
||||
String id = idFUCK;
|
||||
String description = C.i18n("modpack.task.install.will");
|
||||
|
||||
// Read modpack name and description from `modpack.json`
|
||||
try (ZipFile zip = new ZipFile(input)) {
|
||||
HashMap<String, String> map = C.GSON.fromJson(new InputStreamReader(zip.getInputStream(zip.getEntry("modpack.json")), "UTF-8"), HashMap.class);
|
||||
if (map != null) {
|
||||
if (id == null)
|
||||
if (map.containsKey("name") && map.get("name") instanceof String)
|
||||
id = map.get("name");
|
||||
if (id != null)
|
||||
description += id;
|
||||
if (map.containsKey("description") && map.get("description") instanceof String)
|
||||
description += "\n" + map.get("description");
|
||||
}
|
||||
if (id == null)
|
||||
throw new IllegalStateException("Illegal modpack id!");
|
||||
}
|
||||
|
||||
// Show a window to let the user know that what and how the modpack is.
|
||||
Object msgs[] = new Object[2];
|
||||
msgs[0] = C.i18n("modpack.task.install");
|
||||
msgs[1] = new WebPage(description);
|
||||
((WebPage) msgs[1]).setPreferredSize(new Dimension(800, 350));
|
||||
int result = JOptionPane.showOptionDialog(parFrame, msgs, (String) msgs[0], JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
|
||||
if (result == JOptionPane.NO_OPTION)
|
||||
throw new NoShownTaskException("Operation was canceled by user.");
|
||||
|
||||
File versions = new File(service.baseDirectory(), "versions");
|
||||
|
||||
// `minecraft` folder is the existent root folder of the modpack
|
||||
// Then we will decompress the modpack and there would be a folder named `minecraft`
|
||||
// So if `minecraft` folder does exist, backup it and then restore it.
|
||||
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())
|
||||
if (!newFile.delete())
|
||||
HMCLog.warn("Failed to delete file " + newFile);
|
||||
if (!oldFile.renameTo(newFile))
|
||||
HMCLog.warn("Failed to rename " + oldFile + " to " + newFile);
|
||||
}
|
||||
|
||||
// If the user install the modpack into an existent version, maybe it wants to update the modpack
|
||||
// So backup the game, copy the saved games.
|
||||
File preVersion = new File(versions, id), preVersionRenamed = null;
|
||||
if (preVersion.exists()) {
|
||||
HMCLog.log("Backing up the game");
|
||||
String preId = id + "-" + System.currentTimeMillis();
|
||||
if (!preVersion.renameTo(preVersionRenamed = new File(versions, preId)))
|
||||
HMCLog.warn("Failed to rename pre-version folder " + preVersion + " to a temp folder " + preVersionRenamed);
|
||||
if (!new File(preVersionRenamed, id + ".json").renameTo(new File(preVersionRenamed, preId + ".json")))
|
||||
HMCLog.warn("Failed to rename pre json to new json");
|
||||
|
||||
if (!new File(preVersionRenamed, id + ".jar").renameTo(new File(preVersionRenamed, preId + ".jar")))
|
||||
HMCLog.warn("Failed to rename pre jar to new jar");
|
||||
}
|
||||
|
||||
try {
|
||||
final AtomicInteger b = new AtomicInteger(0);
|
||||
HMCLog.log("Decompressing modpack");
|
||||
CompressingUtils.unzip(input, versions, t -> {
|
||||
if (t.equals("minecraft/pack.json"))
|
||||
b.incrementAndGet();
|
||||
return true;
|
||||
}, true);
|
||||
|
||||
// No pack.json here, illegal modpack.
|
||||
if (b.get() < 1)
|
||||
throw new FileNotFoundException(C.i18n("modpack.incorrect_format.no_json"));
|
||||
File nowFile = new File(versions, id);
|
||||
if (oldFile.exists() && !oldFile.renameTo(nowFile))
|
||||
HMCLog.warn("Failed to rename incorrect json " + oldFile + " to " + nowFile);
|
||||
|
||||
File json = new File(nowFile, "pack.json");
|
||||
MinecraftVersion mv = C.GSON.fromJson(FileUtils.read(json), MinecraftVersion.class);
|
||||
if (mv.jar == null)
|
||||
throw new FileNotFoundException(C.i18n("modpack.incorrect_format.no_jar"));
|
||||
|
||||
c.add(service.download().downloadMinecraftJar(mv, new File(nowFile, id + ".jar")));
|
||||
mv.jar = null;
|
||||
FileUtils.write(json, C.GSON.toJson(mv));
|
||||
if (!json.renameTo(new File(nowFile, id + ".json")))
|
||||
HMCLog.warn("Failed to rename pack.json to new id");
|
||||
|
||||
// Restore the saved game from the old version.
|
||||
if (preVersionRenamed != null) {
|
||||
HMCLog.log("Restoring saves");
|
||||
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))
|
||||
HMCLog.warn("Failed to restore version minecraft");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInfo() {
|
||||
return C.i18n("modpack.task.install");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Task> getAfterTasks() {
|
||||
return c;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public static final List<String> MODPACK_BLACK_LIST = Arrays.asList(new String[] { "usernamecache.json", "asm", "logs", "backups", "versions", "assets", "usercache.json", "libraries", "crash-reports", "launcher_profiles.json", "NVIDIA", "AMD", "TCNodeTracker", "screenshots", "natives", "native", "$native", "pack.json", "launcher.jar", "minetweaker.log", "launcher.pack.lzma", "hmclmc.log" });
|
||||
public static final List<String> MODPACK_SUGGESTED_BLACK_LIST = Arrays.asList(new String[] { "fonts", "saves", "servers.dat", "options.txt", "optionsof.txt", "journeymap", "optionsshaders.txt", "mods/VoxelMods" });
|
||||
|
||||
public static ModAdviser MODPACK_PREDICATE = (String fileName, boolean isDirectory) -> {
|
||||
if (match(MODPACK_BLACK_LIST, fileName, isDirectory))
|
||||
return ModAdviser.ModSuggestion.HIDDEN;
|
||||
if (match(MODPACK_SUGGESTED_BLACK_LIST, fileName, isDirectory))
|
||||
return ModAdviser.ModSuggestion.NORMAL;
|
||||
return ModAdviser.ModSuggestion.SUGGESTED;
|
||||
};
|
||||
|
||||
private static boolean match(final List<String> l, String fileName, boolean isDirectory) {
|
||||
for (String s : l)
|
||||
if (isDirectory) {
|
||||
if (fileName.startsWith(s + "/"))
|
||||
return true;
|
||||
} else if (fileName.equals(s))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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, Map<String, String> modpackPreferences, CallbackIO<ZipEngine> callback) throws IOException, GameException {
|
||||
final ArrayList<String> b = new ArrayList<>(MODPACK_BLACK_LIST);
|
||||
if (blacklist != null)
|
||||
b.addAll(blacklist);
|
||||
b.add(version + ".jar");
|
||||
b.add(version + ".json");
|
||||
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);
|
||||
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;
|
||||
mv.runDir = "version";
|
||||
zip.putTextFile(C.GSON.toJson(mv), "minecraft/pack.json");
|
||||
zip.putTextFile(C.GSON.toJson(modpackPreferences), "modpack.json");
|
||||
if (callback != null)
|
||||
callback.call(zip);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(zip);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* 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.launcher.core.GameException;
|
||||
import org.jackhuang.hellominecraft.launcher.core.asset.AssetsObject;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.AssetIndexDownloadInfo;
|
||||
import org.jackhuang.hellominecraft.util.task.Task;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public abstract class IMinecraftAssetService extends IMinecraftBasicService {
|
||||
|
||||
public IMinecraftAssetService(IMinecraftService service) {
|
||||
super(service);
|
||||
}
|
||||
|
||||
public abstract Task downloadAssets(String mcVersion) throws GameException;
|
||||
|
||||
public abstract File getAssets(String assetId);
|
||||
|
||||
public abstract File getIndexFile(String assetId);
|
||||
|
||||
/**
|
||||
* Redownload the Asset index json of the given version.
|
||||
*
|
||||
* @param mcVersion the given version name
|
||||
*
|
||||
* @return Is the action successful?
|
||||
*/
|
||||
public abstract boolean refreshAssetsIndex(String mcVersion) throws GameException;
|
||||
|
||||
public abstract boolean downloadMinecraftAssetsIndexAsync(AssetIndexDownloadInfo assetId);
|
||||
|
||||
public abstract Task downloadMinecraftAssetsIndex(AssetIndexDownloadInfo assetId);
|
||||
|
||||
public abstract File getAssetObject(String assetVersion, String name) throws IOException;
|
||||
|
||||
public abstract File getAssetObject(String assetId, AssetsObject assetsObject);
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* 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.api.event.launch.DownloadLibraryJob;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
|
||||
import org.jackhuang.hellominecraft.util.task.Task;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public abstract class IMinecraftDownloadService extends IMinecraftBasicService {
|
||||
|
||||
public IMinecraftDownloadService(IMinecraftService service) {
|
||||
super(service);
|
||||
}
|
||||
|
||||
public abstract Task downloadMinecraft(String id);
|
||||
|
||||
public abstract Task downloadMinecraftJar(MinecraftVersion mv, File f);
|
||||
|
||||
public abstract Task downloadMinecraftVersionJson(String id);
|
||||
|
||||
/**
|
||||
* Get the libraries that need to download.
|
||||
*
|
||||
* @return the library collection
|
||||
*/
|
||||
public abstract List<DownloadLibraryJob> getDownloadLibraries(MinecraftVersion mv) throws GameException;
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* 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.install.InstallerType;
|
||||
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
|
||||
import org.jackhuang.hellominecraft.util.task.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);
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* 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.mod.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 boolean removeMod(String id, Object[] mods);
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
/*
|
||||
* 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.api.event.launch.DecompressLibraryJob;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
|
||||
import org.jackhuang.hellominecraft.api.EventHandler;
|
||||
import org.jackhuang.hellominecraft.util.func.Consumer;
|
||||
import org.jackhuang.hellominecraft.util.func.Predicate;
|
||||
|
||||
/**
|
||||
* 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 abstract File versionRoot(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);
|
||||
|
||||
/**
|
||||
*
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* 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(Predicate<MinecraftVersion> p);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* Must call onRefreshingVersions, onRefreshedVersions, onLoadedVersion
|
||||
* Events.
|
||||
*/
|
||||
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(String id);
|
||||
|
||||
public File baseDirectory() {
|
||||
return service.baseDirectory();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* 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 org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class AssetIndexDownloadInfo extends GameDownloadInfo {
|
||||
|
||||
int totalSize;
|
||||
|
||||
public AssetIndexDownloadInfo() {
|
||||
}
|
||||
|
||||
public AssetIndexDownloadInfo(String id) {
|
||||
this.id = id;
|
||||
url = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCustomizedURL(DownloadType dt) {
|
||||
return dt.getProvider().getIndexesDownloadURL() + id + ".json";
|
||||
}
|
||||
|
||||
public int getTotalSize() {
|
||||
return totalSize;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* 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.annotations.SerializedName;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class Extract implements Cloneable {
|
||||
|
||||
@SerializedName("exclude")
|
||||
public List<String> exclude = new ArrayList<>();
|
||||
|
||||
public boolean allow(String path) {
|
||||
return !StrUtils.startsWithOne(exclude, path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
try {
|
||||
return super.clone();
|
||||
} catch (CloneNotSupportedException ex) {
|
||||
throw new InternalError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public enum GameDirType {
|
||||
|
||||
ROOT_FOLDER,
|
||||
VERSION_FOLDER;
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* 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.annotations.SerializedName;
|
||||
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class GameDownloadInfo implements Cloneable {
|
||||
|
||||
@SerializedName("sha1")
|
||||
public String sha1;
|
||||
@SerializedName("size")
|
||||
public int size;
|
||||
@SerializedName("url")
|
||||
public String url;
|
||||
|
||||
/**
|
||||
* Ready for AssetIndexDownloadInfo, and GameDownloadInfo also need this.
|
||||
*/
|
||||
protected String id;
|
||||
|
||||
/**
|
||||
* Get the game download url.
|
||||
*
|
||||
* @param dt where to download?
|
||||
*
|
||||
* @return the download url
|
||||
*/
|
||||
public String getUrl(DownloadType dt) {
|
||||
return getUrl(dt, dt.getProvider().isAllowedToUseSelfURL());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the game download url.
|
||||
*
|
||||
* @param dt where to download?
|
||||
* @param allowSelf allow this game to be downloaded from its modified url?
|
||||
*
|
||||
* @return the download url
|
||||
*/
|
||||
public String getUrl(DownloadType dt, boolean allowSelf) {
|
||||
if (url != null && allowSelf)
|
||||
return dt.getProvider().getParsedDownloadURL(url);
|
||||
else
|
||||
return getCustomizedURL(dt);
|
||||
}
|
||||
|
||||
protected String getCustomizedURL(DownloadType dt) {
|
||||
return dt.getProvider().getVersionsDownloadURL() + id + "/" + id + ".jar";
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
try {
|
||||
return super.clone();
|
||||
} catch (CloneNotSupportedException ex) {
|
||||
throw new Error(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user