mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-18 00:10:33 -04:00
Reconstructed too many codes
This commit is contained in:
parent
8e2fa57868
commit
a436e10d93
@ -66,7 +66,7 @@ public final class Launcher {
|
|||||||
int len = tokenized.length;
|
int len = tokenized.length;
|
||||||
|
|
||||||
if (showInfo) {
|
if (showInfo) {
|
||||||
LogWindow.instance.setTerminateGame(() -> Utils.shutdownForcely(1));
|
LogWindow.INSTANCE.setTerminateGame(() -> Utils.shutdownForcely(1));
|
||||||
try {
|
try {
|
||||||
File logFile = new File("hmclmc.log");
|
File logFile = new File("hmclmc.log");
|
||||||
if (!logFile.exists())
|
if (!logFile.exists())
|
||||||
@ -84,9 +84,7 @@ public final class Launcher {
|
|||||||
println("Arguments: {\n" + StrUtils.parseParams(" ", args, "\n") + "\n}");
|
println("Arguments: {\n" + StrUtils.parseParams(" ", args, "\n") + "\n}");
|
||||||
println("Main Class: " + mainClass);
|
println("Main Class: " + mainClass);
|
||||||
println("Class Path: {\n" + StrUtils.parseParams(" ", tokenized, "\n") + "\n}");
|
println("Class Path: {\n" + StrUtils.parseParams(" ", tokenized, "\n") + "\n}");
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> LogWindow.INSTANCE.setVisible(true));
|
||||||
LogWindow.instance.setVisible(true);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
URL[] urls = new URL[len];
|
URL[] urls = new URL[len];
|
||||||
@ -126,8 +124,8 @@ public final class Launcher {
|
|||||||
System.err.println(C.i18n("crash.minecraft"));
|
System.err.println(C.i18n("crash.minecraft"));
|
||||||
System.err.println(advice);
|
System.err.println(advice);
|
||||||
System.err.println(trace);
|
System.err.println(trace);
|
||||||
LogWindow.instance.setExit(() -> true);
|
LogWindow.INSTANCE.setExit(() -> true);
|
||||||
LogWindow.instance.setVisible(true);
|
LogWindow.INSTANCE.setVisible(true);
|
||||||
flag = 1;
|
flag = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,9 +24,7 @@ import java.io.File;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Authenticator;
|
import java.net.Authenticator;
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.PasswordAuthentication;
|
import java.net.PasswordAuthentication;
|
||||||
import java.net.Proxy;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -108,7 +106,7 @@ public final class Main implements Runnable {
|
|||||||
public static String launcherName = "Hello Minecraft! Launcher";
|
public static String launcherName = "Hello Minecraft! Launcher";
|
||||||
public static byte firstVer = 2, secondVer = 3, thirdVer = 5, forthVer = 5;
|
public static byte firstVer = 2, secondVer = 3, thirdVer = 5, forthVer = 5;
|
||||||
public static int minimumLauncherVersion = 16;
|
public static int minimumLauncherVersion = 16;
|
||||||
public static Proxy PROXY;
|
//public static Proxy PROXY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make the version of HMCL.
|
* Make the version of HMCL.
|
||||||
@ -178,8 +176,8 @@ public final class Main implements Runnable {
|
|||||||
|
|
||||||
HMCLog.log("*** " + Main.makeTitle() + " ***");
|
HMCLog.log("*** " + Main.makeTitle() + " ***");
|
||||||
|
|
||||||
LogWindow.instance.clean();
|
LogWindow.INSTANCE.clean();
|
||||||
LogWindow.instance.setTerminateGame(GameLauncher.PROCESS_MANAGER::stopAllProcesses);
|
LogWindow.INSTANCE.setTerminateGame(GameLauncher.PROCESS_MANAGER::stopAllProcesses);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
UIManager.setLookAndFeel(new HelloMinecraftLookAndFeel());
|
UIManager.setLookAndFeel(new HelloMinecraftLookAndFeel());
|
||||||
@ -200,13 +198,13 @@ public final class Main implements Runnable {
|
|||||||
return new PasswordAuthentication(Settings.getInstance().getProxyUserName(), Settings.getInstance().getProxyPassword().toCharArray());
|
return new PasswordAuthentication(Settings.getInstance().getProxyUserName(), Settings.getInstance().getProxyPassword().toCharArray());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
PROXY = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(Settings.getInstance().getProxyHost(), Integer.parseInt(Settings.getInstance().getProxyPort())));
|
//PROXY = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(Settings.getInstance().getProxyHost(), Integer.parseInt(Settings.getInstance().getProxyPort())));
|
||||||
} else {
|
} else {
|
||||||
PROXY = Proxy.NO_PROXY;
|
//PROXY = Proxy.NO_PROXY;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MainFrame.showMainFrame(Settings.isFirstLoad());
|
MainFrame.showMainFrame(Settings.isFirstLoading());
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
new CrashReporter(false).uncaughtException(Thread.currentThread(), t);
|
new CrashReporter(false).uncaughtException(Thread.currentThread(), t);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
|
@ -23,7 +23,6 @@ import org.jackhuang.hellominecraft.HMCLog;
|
|||||||
import org.jackhuang.hellominecraft.launcher.launch.GameLauncher.DownloadLibraryJob;
|
import org.jackhuang.hellominecraft.launcher.launch.GameLauncher.DownloadLibraryJob;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.IAuthenticator;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.IAuthenticator;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.LoginInfo;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.LoginInfo;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
||||||
import org.jackhuang.hellominecraft.tasks.ParallelTask;
|
import org.jackhuang.hellominecraft.tasks.ParallelTask;
|
||||||
import org.jackhuang.hellominecraft.tasks.TaskWindow;
|
import org.jackhuang.hellominecraft.tasks.TaskWindow;
|
||||||
@ -37,11 +36,6 @@ public class DefaultGameLauncher extends GameLauncher {
|
|||||||
register();
|
register();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultGameLauncher(Profile version, LoginInfo info, IAuthenticator lg, DownloadType downloadType) {
|
|
||||||
super(version, info, lg, downloadType);
|
|
||||||
register();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void register() {
|
private void register() {
|
||||||
downloadLibrariesEvent.register((sender, t) -> {
|
downloadLibrariesEvent.register((sender, t) -> {
|
||||||
final TaskWindow.TaskWindowFactory dw = TaskWindow.getInstance();
|
final TaskWindow.TaskWindowFactory dw = TaskWindow.getInstance();
|
||||||
|
@ -29,7 +29,6 @@ import org.jackhuang.hellominecraft.HMCLog;
|
|||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.IAuthenticator;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.IAuthenticator;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.LoginInfo;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.LoginInfo;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.AuthenticationException;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.AuthenticationException;
|
||||||
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
||||||
@ -54,18 +53,12 @@ public class GameLauncher {
|
|||||||
public final EventHandler<List<String>> successEvent = new EventHandler(this);
|
public final EventHandler<List<String>> successEvent = new EventHandler(this);
|
||||||
public final EventHandler<JavaProcess> launchEvent = new EventHandler(this);
|
public final EventHandler<JavaProcess> launchEvent = new EventHandler(this);
|
||||||
public final EventHandler<DecompressLibraryJob> decompressNativesEvent = new EventHandler(this);
|
public final EventHandler<DecompressLibraryJob> decompressNativesEvent = new EventHandler(this);
|
||||||
DownloadType downloadType;
|
|
||||||
|
|
||||||
public GameLauncher(Profile version, LoginInfo info, IAuthenticator lg) {
|
public GameLauncher(Profile version, LoginInfo info, IAuthenticator lg) {
|
||||||
this(version, info, lg, DownloadType.Mojang);
|
|
||||||
}
|
|
||||||
|
|
||||||
public GameLauncher(Profile version, LoginInfo info, IAuthenticator lg, DownloadType downloadType) {
|
|
||||||
this.get = version;
|
this.get = version;
|
||||||
this.provider = get.getMinecraftProvider();
|
this.provider = get.getMinecraftProvider();
|
||||||
this.info = info;
|
this.info = info;
|
||||||
this.login = lg;
|
this.login = lg;
|
||||||
this.downloadType = downloadType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Profile getProfile() {
|
public Profile getProfile() {
|
||||||
@ -89,7 +82,7 @@ public class GameLauncher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
loader = provider.provideMinecraftLoader(result, downloadType);
|
loader = provider.provideMinecraftLoader(result);
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
HMCLog.err("Failed to get minecraft loader", e);
|
HMCLog.err("Failed to get minecraft loader", e);
|
||||||
failEvent.execute(C.i18n("launch.circular_dependency_versions"));
|
failEvent.execute(C.i18n("launch.circular_dependency_versions"));
|
||||||
@ -101,7 +94,7 @@ public class GameLauncher {
|
|||||||
FileUtils.cleanDirectoryQuietly(file);
|
FileUtils.cleanDirectoryQuietly(file);
|
||||||
|
|
||||||
HMCLog.log("Detecting libraries...");
|
HMCLog.log("Detecting libraries...");
|
||||||
if (!downloadLibrariesEvent.execute(provider.getDownloadLibraries(downloadType))) {
|
if (!downloadLibrariesEvent.execute(provider.getDownloadService().getDownloadLibraries())) {
|
||||||
failEvent.execute(C.i18n("launch.failed"));
|
failEvent.execute(C.i18n("launch.failed"));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -19,19 +19,24 @@ package org.jackhuang.hellominecraft.launcher.launch;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.ModInfo;
|
import org.jackhuang.hellominecraft.launcher.utils.ModInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author huangyuhui
|
* @author huangyuhui
|
||||||
*/
|
*/
|
||||||
public interface IMinecraftModService {
|
public abstract class IMinecraftModService extends IMinecraftService {
|
||||||
|
|
||||||
List<ModInfo> getMods();
|
public IMinecraftModService(Profile profile) {
|
||||||
|
super(profile);
|
||||||
|
}
|
||||||
|
|
||||||
List<ModInfo> recacheMods();
|
public abstract List<ModInfo> getMods();
|
||||||
|
|
||||||
boolean addMod(File f);
|
public abstract List<ModInfo> recacheMods();
|
||||||
|
|
||||||
void removeMod(int[] index);
|
public abstract boolean addMod(File f);
|
||||||
|
|
||||||
|
public abstract void removeMod(int[] index);
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,7 @@ package org.jackhuang.hellominecraft.launcher.launch;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
||||||
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
||||||
import org.jackhuang.hellominecraft.utils.StrUtils;
|
import org.jackhuang.hellominecraft.utils.StrUtils;
|
||||||
@ -34,7 +32,7 @@ import org.jackhuang.hellominecraft.utils.StrUtils;
|
|||||||
*/
|
*/
|
||||||
public abstract class IMinecraftProvider {
|
public abstract class IMinecraftProvider {
|
||||||
|
|
||||||
Profile profile;
|
protected Profile profile;
|
||||||
|
|
||||||
public IMinecraftProvider(Profile profile) {
|
public IMinecraftProvider(Profile profile) {
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
@ -53,20 +51,13 @@ public abstract class IMinecraftProvider {
|
|||||||
return new File(getRunDirectory(getSelectedMinecraftVersion().id), subFolder);
|
return new File(getRunDirectory(getSelectedMinecraftVersion().id), subFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the libraries that need to download.
|
|
||||||
*
|
|
||||||
* @param type where to download
|
|
||||||
*
|
|
||||||
* @return the library collection
|
|
||||||
*/
|
|
||||||
public abstract List<GameLauncher.DownloadLibraryJob> getDownloadLibraries(DownloadType type);
|
|
||||||
|
|
||||||
public abstract void open(String version, String folder);
|
public abstract void open(String version, String folder);
|
||||||
|
|
||||||
public abstract File getAssets();
|
|
||||||
|
|
||||||
public abstract IMinecraftModService getModService();
|
public abstract IMinecraftModService getModService();
|
||||||
|
|
||||||
|
public abstract IMinecraftDownloadService getDownloadService();
|
||||||
|
|
||||||
|
public abstract IMinecraftAssetService getAssetService();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the thing like ".minecraft/resourcepacks".
|
* Returns the thing like ".minecraft/resourcepacks".
|
||||||
@ -100,7 +91,7 @@ public abstract class IMinecraftProvider {
|
|||||||
*
|
*
|
||||||
* @throws IllegalStateException circular denpendency versions
|
* @throws IllegalStateException circular denpendency versions
|
||||||
*/
|
*/
|
||||||
public abstract IMinecraftLoader provideMinecraftLoader(UserProfileProvider p, DownloadType type) throws IllegalStateException;
|
public abstract IMinecraftLoader provideMinecraftLoader(UserProfileProvider p) throws IllegalStateException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rename version
|
* Rename version
|
||||||
@ -124,20 +115,13 @@ public abstract class IMinecraftProvider {
|
|||||||
/**
|
/**
|
||||||
* Redownload the Minecraft json of the given version.
|
* Redownload the Minecraft json of the given version.
|
||||||
*
|
*
|
||||||
* @param a the given version name
|
* @param id the given version name
|
||||||
*
|
*
|
||||||
* @return Is the action successful?
|
* @return Is the action successful?
|
||||||
*/
|
*/
|
||||||
public abstract boolean refreshJson(String a);
|
public boolean refreshJson(String id) {
|
||||||
|
return getDownloadService().downloadMinecraftVersionJson(id);
|
||||||
/**
|
}
|
||||||
* Redownload the Asset index json of the given version.
|
|
||||||
*
|
|
||||||
* @param a the given version name
|
|
||||||
*
|
|
||||||
* @return Is the action successful?
|
|
||||||
*/
|
|
||||||
public abstract boolean refreshAssetsIndex(String a);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Choose a version randomly.
|
* Choose a version randomly.
|
||||||
@ -199,16 +183,6 @@ public abstract class IMinecraftProvider {
|
|||||||
*/
|
*/
|
||||||
public abstract void cleanFolder();
|
public abstract void cleanFolder();
|
||||||
|
|
||||||
/**
|
|
||||||
* Install a new version to this profile.
|
|
||||||
*
|
|
||||||
* @param version the new version name
|
|
||||||
* @param type where to download
|
|
||||||
*
|
|
||||||
* @return Is the action successful?
|
|
||||||
*/
|
|
||||||
public abstract boolean install(String version, DownloadType type);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When GameLauncher launches the game, this function will be called.
|
* When GameLauncher launches the game, this function will be called.
|
||||||
*/
|
*/
|
||||||
|
@ -34,18 +34,18 @@ public class LaunchFinisher implements Event<List<String>> {
|
|||||||
public boolean call(Object sender, List<String> str) {
|
public boolean call(Object sender, List<String> str) {
|
||||||
final GameLauncher obj = (GameLauncher) sender;
|
final GameLauncher obj = (GameLauncher) sender;
|
||||||
obj.launchEvent.register((sender1, p) -> {
|
obj.launchEvent.register((sender1, p) -> {
|
||||||
if (obj.getProfile().getLauncherVisibility() == LauncherVisibility.CLOSE && !LogWindow.instance.isVisible())
|
if (obj.getProfile().getLauncherVisibility() == LauncherVisibility.CLOSE && !LogWindow.INSTANCE.isVisible())
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
else if (obj.getProfile().getLauncherVisibility() == LauncherVisibility.KEEP)
|
else if (obj.getProfile().getLauncherVisibility() == LauncherVisibility.KEEP)
|
||||||
MainFrame.INSTANCE.closeMessage();
|
MainFrame.INSTANCE.closeMessage();
|
||||||
else {
|
else {
|
||||||
if (LogWindow.instance.isVisible())
|
if (LogWindow.INSTANCE.isVisible())
|
||||||
LogWindow.instance.setExit(() -> true);
|
LogWindow.INSTANCE.setExit(() -> true);
|
||||||
MainFrame.INSTANCE.dispose();
|
MainFrame.INSTANCE.dispose();
|
||||||
}
|
}
|
||||||
JavaProcessMonitor jpm = new JavaProcessMonitor(p);
|
JavaProcessMonitor jpm = new JavaProcessMonitor(p);
|
||||||
jpm.stoppedEvent.register((sender3, t) -> {
|
jpm.stoppedEvent.register((sender3, t) -> {
|
||||||
if (obj.getProfile().getLauncherVisibility() != LauncherVisibility.KEEP && !LogWindow.instance.isVisible())
|
if (obj.getProfile().getLauncherVisibility() != LauncherVisibility.KEEP && !LogWindow.INSTANCE.isVisible())
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
@ -27,7 +27,6 @@ import org.jackhuang.hellominecraft.HMCLog;
|
|||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
||||||
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.MCUtils;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.assets.AssetsIndex;
|
import org.jackhuang.hellominecraft.launcher.utils.assets.AssetsIndex;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.assets.AssetsObject;
|
import org.jackhuang.hellominecraft.launcher.utils.assets.AssetsObject;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.assets.IAssetsHandler;
|
import org.jackhuang.hellominecraft.launcher.utils.assets.IAssetsHandler;
|
||||||
@ -46,17 +45,13 @@ import rx.concurrency.Schedulers;
|
|||||||
*/
|
*/
|
||||||
public class MinecraftLoader extends AbstractMinecraftLoader {
|
public class MinecraftLoader extends AbstractMinecraftLoader {
|
||||||
|
|
||||||
private MinecraftVersion version;
|
private final MinecraftVersion version;
|
||||||
DownloadType dt;
|
DownloadType dt;
|
||||||
String text;
|
String text;
|
||||||
|
|
||||||
public MinecraftLoader(Profile ver, IMinecraftProvider provider, UserProfileProvider lr) throws IllegalStateException {
|
public MinecraftLoader(Profile ver, IMinecraftProvider provider, UserProfileProvider lr) throws IllegalStateException {
|
||||||
this(ver, provider, lr, DownloadType.Mojang);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MinecraftLoader(Profile ver, IMinecraftProvider provider, UserProfileProvider lr, DownloadType downloadtype) throws IllegalStateException {
|
|
||||||
super(ver, provider, lr);
|
super(ver, provider, lr);
|
||||||
version = ver.getSelectedMinecraftVersion().resolve(provider, dt = downloadtype);
|
version = ver.getSelectedMinecraftVersion().resolve(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -95,7 +90,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
|
|||||||
t = t.replace("${profile_name}", provider.profile.getName());
|
t = t.replace("${profile_name}", provider.profile.getName());
|
||||||
t = t.replace("${game_directory}", provider.getRunDirectory(version.id).getAbsolutePath());
|
t = t.replace("${game_directory}", provider.getRunDirectory(version.id).getAbsolutePath());
|
||||||
t = t.replace("${game_assets}", game_assets);
|
t = t.replace("${game_assets}", game_assets);
|
||||||
t = t.replace("${assets_root}", provider.getAssets().getAbsolutePath());
|
t = t.replace("${assets_root}", provider.getAssetService().getAssets().getAbsolutePath());
|
||||||
t = t.replace("${auth_access_token}", lr.getAccessToken());
|
t = t.replace("${auth_access_token}", lr.getAccessToken());
|
||||||
t = t.replace("${user_type}", lr.getUserType());
|
t = t.replace("${user_type}", lr.getUserType());
|
||||||
t = t.replace("${assets_index_name}", version.getAssets());
|
t = t.replace("${assets_index_name}", version.getAssets());
|
||||||
@ -115,7 +110,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (OS.os() == OS.OSX) {
|
if (OS.os() == OS.OSX) {
|
||||||
list.add("-Xdock:icon=" + MCUtils.getAssetObject(C.gson, v.getCanonicalGameDir(), version.assets, "icons/minecraft.icns").getAbsolutePath());
|
list.add("-Xdock:icon=" + provider.getAssetService().getAssetObject(version.assets, "icons/minecraft.icns").getAbsolutePath());
|
||||||
list.add("-Xdock:name=Minecraft");
|
list.add("-Xdock:name=Minecraft");
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -21,9 +21,9 @@ import java.io.File;
|
|||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
||||||
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.MCUtils;
|
import org.jackhuang.hellominecraft.launcher.utils.MCUtils;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerService;
|
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerService;
|
||||||
import org.jackhuang.hellominecraft.launcher.version.GameDirType;
|
import org.jackhuang.hellominecraft.launcher.version.GameDirType;
|
||||||
import org.jackhuang.hellominecraft.launcher.version.MinecraftService;
|
|
||||||
import org.jackhuang.hellominecraft.utils.StrUtils;
|
import org.jackhuang.hellominecraft.utils.StrUtils;
|
||||||
import org.jackhuang.hellominecraft.utils.Utils;
|
import org.jackhuang.hellominecraft.utils.Utils;
|
||||||
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
||||||
@ -365,8 +365,7 @@ public final class Profile {
|
|||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
transient final MinecraftService ms = new MinecraftService(this);
|
public DownloadType getDownloadType() {
|
||||||
public MinecraftService getMinecraftService() {
|
return Settings.getInstance().getDownloadSource();
|
||||||
return ms;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,23 +46,23 @@ public final class Settings {
|
|||||||
|
|
||||||
public static final String DEFAULT_PROFILE = "Default";
|
public static final String DEFAULT_PROFILE = "Default";
|
||||||
|
|
||||||
public static final File settingsFile = new File(IOUtils.currentDir(), "hmcl.json");
|
public static final File SETTINGS_FILE = new File(IOUtils.currentDir(), "hmcl.json");
|
||||||
|
|
||||||
private static boolean isFirstLoad;
|
private static boolean isFirstLoading;
|
||||||
private static final Config settings;
|
private static final Config SETTINGS;
|
||||||
public static final UpdateChecker UPDATE_CHECKER;
|
public static final UpdateChecker UPDATE_CHECKER;
|
||||||
public static final List<Java> JAVA;
|
public static final List<Java> JAVA;
|
||||||
|
|
||||||
public static Config getInstance() {
|
public static Config getInstance() {
|
||||||
return settings;
|
return SETTINGS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isFirstLoad() {
|
public static boolean isFirstLoading() {
|
||||||
return isFirstLoad;
|
return isFirstLoading;
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
settings = initSettings();
|
SETTINGS = initSettings();
|
||||||
if (!getProfiles().containsKey(DEFAULT_PROFILE))
|
if (!getProfiles().containsKey(DEFAULT_PROFILE))
|
||||||
getProfiles().put(DEFAULT_PROFILE, new Profile());
|
getProfiles().put(DEFAULT_PROFILE, new Profile());
|
||||||
|
|
||||||
@ -84,9 +84,9 @@ public final class Settings {
|
|||||||
|
|
||||||
private static Config initSettings() {
|
private static Config initSettings() {
|
||||||
Config c = new Config();
|
Config c = new Config();
|
||||||
if (settingsFile.exists()) {
|
if (SETTINGS_FILE.exists()) {
|
||||||
try {
|
try {
|
||||||
String str = FileUtils.readFileToString(settingsFile);
|
String str = FileUtils.readFileToString(SETTINGS_FILE);
|
||||||
if (str == null || str.trim().equals(""))
|
if (str == null || str.trim().equals(""))
|
||||||
HMCLog.log("Settings file is empty, use the default settings.");
|
HMCLog.log("Settings file is empty, use the default settings.");
|
||||||
else {
|
else {
|
||||||
@ -102,17 +102,17 @@ public final class Settings {
|
|||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isFirstLoad = StrUtils.isBlank(c.getUsername());
|
isFirstLoading = StrUtils.isBlank(c.getUsername());
|
||||||
} else {
|
} else {
|
||||||
HMCLog.log("No settings file here, may be first loading.");
|
HMCLog.log("No settings file here, may be first loading.");
|
||||||
isFirstLoad = true;
|
isFirstLoading = true;
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void save() {
|
public static void save() {
|
||||||
try {
|
try {
|
||||||
FileUtils.write(settingsFile, C.gsonPrettyPrinting.toJson(settings));
|
FileUtils.write(SETTINGS_FILE, C.gsonPrettyPrinting.toJson(SETTINGS));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
HMCLog.err("Failed to save config", ex);
|
HMCLog.err("Failed to save config", ex);
|
||||||
}
|
}
|
||||||
@ -123,7 +123,7 @@ public final class Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, Profile> getProfiles() {
|
public static Map<String, Profile> getProfiles() {
|
||||||
return settings.getConfigurations();
|
return SETTINGS.getConfigurations();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setProfile(Profile ver) {
|
public static void setProfile(Profile ver) {
|
||||||
@ -135,7 +135,7 @@ public final class Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Profile getOneProfile() {
|
public static Profile getOneProfile() {
|
||||||
return settings.getConfigurations().firstEntry().getValue();
|
return SETTINGS.getConfigurations().firstEntry().getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean trySetProfile(Profile ver) {
|
public static boolean trySetProfile(Profile ver) {
|
||||||
|
@ -99,7 +99,7 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
|
|||||||
System.out.println(text);
|
System.out.println(text);
|
||||||
|
|
||||||
if (checkThrowable(e)) {
|
if (checkThrowable(e)) {
|
||||||
SwingUtilities.invokeLater(() -> LogWindow.instance.showAsCrashWindow(UpdateChecker.OUT_DATED));
|
SwingUtilities.invokeLater(() -> LogWindow.INSTANCE.showAsCrashWindow(UpdateChecker.OUT_DATED));
|
||||||
if (!UpdateChecker.OUT_DATED)
|
if (!UpdateChecker.OUT_DATED)
|
||||||
reportToServer(text, s);
|
reportToServer(text, s);
|
||||||
}
|
}
|
||||||
|
@ -17,25 +17,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hellominecraft.launcher.utils;
|
package org.jackhuang.hellominecraft.launcher.utils;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonSyntaxException;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
import java.util.zip.ZipFile;
|
|
||||||
import org.jackhuang.hellominecraft.C;
|
|
||||||
import org.jackhuang.hellominecraft.HMCLog;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.assets.AssetsIndex;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.assets.AssetsObject;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
|
||||||
import org.jackhuang.hellominecraft.tasks.TaskWindow;
|
|
||||||
import org.jackhuang.hellominecraft.tasks.download.FileDownloadTask;
|
|
||||||
import org.jackhuang.hellominecraft.utils.ArrayUtils;
|
|
||||||
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
||||||
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
||||||
import org.jackhuang.hellominecraft.version.MinecraftVersionRequest;
|
|
||||||
import org.jackhuang.hellominecraft.utils.NetUtils;
|
|
||||||
import org.jackhuang.hellominecraft.utils.system.OS;
|
import org.jackhuang.hellominecraft.utils.system.OS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,144 +29,6 @@ import org.jackhuang.hellominecraft.utils.system.OS;
|
|||||||
*/
|
*/
|
||||||
public final class MCUtils {
|
public final class MCUtils {
|
||||||
|
|
||||||
public static File getAssetObject(Gson gson, String dir, String assetVersion, String name) throws IOException {
|
|
||||||
File assetsDir = new File(dir, "assets");
|
|
||||||
File indexDir = new File(assetsDir, "indexes");
|
|
||||||
File objectsDir = new File(assetsDir, "objects");
|
|
||||||
File indexFile = new File(indexDir, assetVersion + ".json");
|
|
||||||
try {
|
|
||||||
AssetsIndex index = (AssetsIndex) gson.fromJson(FileUtils.readFileToString(indexFile, "UTF-8"), AssetsIndex.class);
|
|
||||||
|
|
||||||
String hash = ((AssetsObject) index.getFileMap().get(name)).getHash();
|
|
||||||
return new File(objectsDir, hash.substring(0, 2) + "/" + hash);
|
|
||||||
} catch (JsonSyntaxException e) {
|
|
||||||
throw new IOException("Assets file format malformed.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int lessThan32(byte[] b, int x) {
|
|
||||||
for (; x < b.length; x++)
|
|
||||||
if (b[x] < 32)
|
|
||||||
return x;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static MinecraftVersionRequest getVersionOfOldMinecraft(ZipFile file, ZipEntry entry) throws IOException {
|
|
||||||
MinecraftVersionRequest r = new MinecraftVersionRequest();
|
|
||||||
byte[] tmp = NetUtils.getBytesFromStream(file.getInputStream(entry));
|
|
||||||
|
|
||||||
byte[] bytes = "Minecraft Minecraft ".getBytes("ASCII");
|
|
||||||
int j;
|
|
||||||
if ((j = ArrayUtils.matchArray(tmp, bytes)) < 0) {
|
|
||||||
r.type = MinecraftVersionRequest.UNKOWN;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
int i = j + bytes.length;
|
|
||||||
|
|
||||||
if ((j = lessThan32(tmp, i)) < 0) {
|
|
||||||
r.type = MinecraftVersionRequest.UNKOWN;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
String ver = new String(tmp, i, j - i, "ASCII");
|
|
||||||
r.version = ver;
|
|
||||||
|
|
||||||
r.type = file.getEntry("META-INF/MANIFEST.MF") == null
|
|
||||||
? MinecraftVersionRequest.MODIFIED : MinecraftVersionRequest.OK;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static MinecraftVersionRequest getVersionOfNewMinecraft(ZipFile file, ZipEntry entry) throws IOException {
|
|
||||||
MinecraftVersionRequest r = new MinecraftVersionRequest();
|
|
||||||
byte[] tmp = NetUtils.getBytesFromStream(file.getInputStream(entry));
|
|
||||||
|
|
||||||
byte[] str = "-server.txt".getBytes("ASCII");
|
|
||||||
int j = ArrayUtils.matchArray(tmp, str);
|
|
||||||
if (j < 0) {
|
|
||||||
r.type = MinecraftVersionRequest.UNKOWN;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
int i = j + str.length;
|
|
||||||
i += 11;
|
|
||||||
j = lessThan32(tmp, i);
|
|
||||||
if (j < 0) {
|
|
||||||
r.type = MinecraftVersionRequest.UNKOWN;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
r.version = new String(tmp, i, j - i, "ASCII");
|
|
||||||
|
|
||||||
char ch = r.version.charAt(0);
|
|
||||||
// 1.8.1+
|
|
||||||
if (ch < '0' || ch > '9') {
|
|
||||||
str = "Can't keep up! Did the system time change, or is the server overloaded?".getBytes("ASCII");
|
|
||||||
j = ArrayUtils.matchArray(tmp, str);
|
|
||||||
if (j < 0) {
|
|
||||||
r.type = MinecraftVersionRequest.UNKOWN;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
i = -1;
|
|
||||||
while (j > 0) {
|
|
||||||
if (tmp[j] >= 48 && tmp[j] <= 57) {
|
|
||||||
i = j;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
j--;
|
|
||||||
}
|
|
||||||
if (i == -1) {
|
|
||||||
r.type = MinecraftVersionRequest.UNKOWN;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
int k = i;
|
|
||||||
while (tmp[k] >= 48 && tmp[k] <= 57 || tmp[k] == 46)
|
|
||||||
k--;
|
|
||||||
k++;
|
|
||||||
r.version = new String(tmp, k, i - k + 1);
|
|
||||||
}
|
|
||||||
r.type = file.getEntry("META-INF/MANIFEST.MF") == null
|
|
||||||
? MinecraftVersionRequest.MODIFIED : MinecraftVersionRequest.OK;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MinecraftVersionRequest minecraftVersion(File file) {
|
|
||||||
MinecraftVersionRequest r = new MinecraftVersionRequest();
|
|
||||||
if (!file.exists()) {
|
|
||||||
r.type = MinecraftVersionRequest.NOT_FOUND;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
if (!file.isFile()) {
|
|
||||||
r.type = MinecraftVersionRequest.NOT_FILE;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
if (!file.canRead()) {
|
|
||||||
r.type = MinecraftVersionRequest.UNREADABLE;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
ZipFile localZipFile = null;
|
|
||||||
try {
|
|
||||||
localZipFile = new ZipFile(file);
|
|
||||||
ZipEntry minecraft = localZipFile
|
|
||||||
.getEntry("net/minecraft/client/Minecraft.class");
|
|
||||||
if (minecraft != null)
|
|
||||||
return getVersionOfOldMinecraft(localZipFile, minecraft);
|
|
||||||
ZipEntry main = localZipFile.getEntry("net/minecraft/client/main/Main.class");
|
|
||||||
ZipEntry minecraftserver = localZipFile.getEntry("net/minecraft/server/MinecraftServer.class");
|
|
||||||
if ((main != null) && (minecraftserver != null))
|
|
||||||
return getVersionOfNewMinecraft(localZipFile, minecraftserver);
|
|
||||||
r.type = MinecraftVersionRequest.INVALID;
|
|
||||||
return r;
|
|
||||||
} catch (IOException localException) {
|
|
||||||
HMCLog.warn("Zip file is invalid", localException);
|
|
||||||
r.type = MinecraftVersionRequest.INVALID_JAR;
|
|
||||||
return r;
|
|
||||||
} finally {
|
|
||||||
if (localZipFile != null)
|
|
||||||
try {
|
|
||||||
localZipFile.close();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
HMCLog.warn("Failed to close zip file", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static File getWorkingDirectory(String baseName) {
|
public static File getWorkingDirectory(String baseName) {
|
||||||
String userhome = System.getProperty("user.home", ".");
|
String userhome = System.getProperty("user.home", ".");
|
||||||
File file;
|
File file;
|
||||||
@ -233,98 +80,6 @@ public final class MCUtils {
|
|||||||
return gameDir;
|
return gameDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MinecraftVersion downloadMinecraft(File gameDir, String id, DownloadType sourceType) {
|
|
||||||
String vurl = sourceType.getProvider().getVersionsDownloadURL() + id + "/";
|
|
||||||
File vpath = new File(gameDir, "versions/" + id);
|
|
||||||
File mvt = new File(vpath, id + ".json");
|
|
||||||
File mvj = new File(vpath, id + ".jar");
|
|
||||||
vpath.mkdirs();
|
|
||||||
mvt.delete();
|
|
||||||
mvj.delete();
|
|
||||||
|
|
||||||
if (TaskWindow.getInstance()
|
|
||||||
.addTask(new FileDownloadTask(vurl + id + ".json", IOUtils.tryGetCanonicalFile(mvt)).setTag(id + ".json"))
|
|
||||||
.addTask(new FileDownloadTask(vurl + id + ".jar", IOUtils.tryGetCanonicalFile(mvj)).setTag(id + ".jar"))
|
|
||||||
.start()) {
|
|
||||||
try {
|
|
||||||
return C.gson.fromJson(FileUtils.readFileToStringQuietly(mvt), MinecraftVersion.class);
|
|
||||||
} catch (JsonSyntaxException ex) {
|
|
||||||
HMCLog.err("Failed to parse minecraft version json.", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean downloadMinecraftJar(File gameDir, String id, DownloadType sourceType) {
|
|
||||||
String vurl = sourceType.getProvider().getVersionsDownloadURL() + id + "/";
|
|
||||||
File vpath = new File(gameDir, "versions/" + id);
|
|
||||||
File mvv = new File(vpath, id + ".jar"), moved = null;
|
|
||||||
if (mvv.exists()) {
|
|
||||||
moved = new File(vpath, id + "-renamed.jar");
|
|
||||||
mvv.renameTo(moved);
|
|
||||||
}
|
|
||||||
File mvt = new File(vpath, id + ".jar");
|
|
||||||
vpath.mkdirs();
|
|
||||||
if (TaskWindow.getInstance()
|
|
||||||
.addTask(new FileDownloadTask(vurl + id + ".jar", IOUtils.tryGetCanonicalFile(mvt)).setTag(id + ".jar"))
|
|
||||||
.start()) {
|
|
||||||
if (moved != null)
|
|
||||||
moved.delete();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
mvt.delete();
|
|
||||||
if (moved != null)
|
|
||||||
moved.renameTo(mvt);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean downloadMinecraftVersionJson(File gameDir, String id, DownloadType sourceType) {
|
|
||||||
String vurl = sourceType.getProvider().getVersionsDownloadURL() + id + "/";
|
|
||||||
File vpath = new File(gameDir, "versions/" + id);
|
|
||||||
File mvv = new File(vpath, id + ".json"), moved = null;
|
|
||||||
if (mvv.exists()) {
|
|
||||||
moved = new File(vpath, id + "-renamed.json");
|
|
||||||
mvv.renameTo(moved);
|
|
||||||
}
|
|
||||||
File mvt = new File(vpath, id + ".json");
|
|
||||||
vpath.mkdirs();
|
|
||||||
if (TaskWindow.getInstance()
|
|
||||||
.addTask(new FileDownloadTask(vurl + id + ".json", IOUtils.tryGetCanonicalFile(mvt)).setTag(id + ".json"))
|
|
||||||
.start()) {
|
|
||||||
if (moved != null)
|
|
||||||
moved.delete();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
mvt.delete();
|
|
||||||
if (moved != null)
|
|
||||||
moved.renameTo(mvt);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean downloadMinecraftAssetsIndex(File assetsLocation, String assetsId, DownloadType sourceType) {
|
|
||||||
String aurl = sourceType.getProvider().getIndexesDownloadURL();
|
|
||||||
|
|
||||||
assetsLocation.mkdirs();
|
|
||||||
File assetsIndex = new File(assetsLocation, "indexes/" + assetsId + ".json");
|
|
||||||
File renamed = null;
|
|
||||||
if (assetsIndex.exists()) {
|
|
||||||
renamed = new File(assetsLocation, "indexes/" + assetsId + "-renamed.json");
|
|
||||||
assetsIndex.renameTo(renamed);
|
|
||||||
}
|
|
||||||
if (TaskWindow.getInstance()
|
|
||||||
.addTask(new FileDownloadTask(aurl + assetsId + ".json", IOUtils.tryGetCanonicalFile(assetsIndex)).setTag(assetsId + ".json"))
|
|
||||||
.start()) {
|
|
||||||
if (renamed != null)
|
|
||||||
renamed.delete();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (renamed != null)
|
|
||||||
renamed.renameTo(assetsIndex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String profile = "{\"selectedProfile\": \"(Default)\",\"profiles\": {\"(Default)\": {\"name\": \"(Default)\"}},\"clientToken\": \"88888888-8888-8888-8888-888888888888\"}";
|
public static String profile = "{\"selectedProfile\": \"(Default)\",\"profiles\": {\"(Default)\": {\"name\": \"(Default)\"}},\"clientToken\": \"88888888-8888-8888-8888-888888888888\"}";
|
||||||
|
|
||||||
public static void tryWriteProfile(File gameDir) throws IOException {
|
public static void tryWriteProfile(File gameDir) throws IOException {
|
||||||
|
@ -24,12 +24,10 @@ import java.util.Map;
|
|||||||
import org.jackhuang.hellominecraft.C;
|
import org.jackhuang.hellominecraft.C;
|
||||||
import org.jackhuang.hellominecraft.HMCLog;
|
import org.jackhuang.hellominecraft.HMCLog;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Settings;
|
|
||||||
import org.jackhuang.hellominecraft.tasks.Task;
|
import org.jackhuang.hellominecraft.tasks.Task;
|
||||||
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
||||||
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
||||||
import org.jackhuang.hellominecraft.utils.StrUtils;
|
import org.jackhuang.hellominecraft.utils.StrUtils;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.MCUtils;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.download.IDownloadProvider;
|
import org.jackhuang.hellominecraft.launcher.utils.download.IDownloadProvider;
|
||||||
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
||||||
import org.jackhuang.hellominecraft.utils.VersionNumber;
|
import org.jackhuang.hellominecraft.utils.VersionNumber;
|
||||||
@ -55,10 +53,10 @@ public class AssetsMojangLoader extends IAssetsHandler {
|
|||||||
return Subscriptions.empty();
|
return Subscriptions.empty();
|
||||||
}
|
}
|
||||||
String assetsId = mv.assets == null ? "legacy" : mv.assets;
|
String assetsId = mv.assets == null ? "legacy" : mv.assets;
|
||||||
File assets = mp.getAssets();
|
File assets = mp.getAssetService().getAssets();
|
||||||
HMCLog.log("Get index: " + assetsId);
|
HMCLog.log("Get index: " + assetsId);
|
||||||
File f = IOUtils.tryGetCanonicalFile(new File(assets, "indexes/" + assetsId + ".json"));
|
File f = IOUtils.tryGetCanonicalFile(new File(assets, "indexes/" + assetsId + ".json"));
|
||||||
if (!f.exists() && !MCUtils.downloadMinecraftAssetsIndex(assets, assetsId, Settings.getInstance().getDownloadSource())) {
|
if (!f.exists() && !mp.getAssetService().downloadMinecraftAssetsIndex(assetsId)) {
|
||||||
t1.onError(null);
|
t1.onError(null);
|
||||||
return Subscriptions.empty();
|
return Subscriptions.empty();
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hellominecraft.launcher.utils.assets;
|
package org.jackhuang.hellominecraft.launcher.utils.assets;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author huangyuhui
|
* @author huangyuhui
|
||||||
|
@ -18,10 +18,10 @@
|
|||||||
package org.jackhuang.hellominecraft.launcher.utils.auth;
|
package org.jackhuang.hellominecraft.launcher.utils.auth;
|
||||||
|
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
|
import java.net.Proxy;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import org.jackhuang.hellominecraft.C;
|
import org.jackhuang.hellominecraft.C;
|
||||||
import org.jackhuang.hellominecraft.launcher.Main;
|
|
||||||
import org.jackhuang.hellominecraft.utils.ArrayUtils;
|
import org.jackhuang.hellominecraft.utils.ArrayUtils;
|
||||||
import org.jackhuang.hellominecraft.views.Selector;
|
import org.jackhuang.hellominecraft.views.Selector;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.yggdrasil.GameProfile;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.yggdrasil.GameProfile;
|
||||||
@ -39,7 +39,7 @@ public final class YggdrasilAuthenticator extends IAuthenticator {
|
|||||||
|
|
||||||
public YggdrasilAuthenticator(String clientToken) {
|
public YggdrasilAuthenticator(String clientToken) {
|
||||||
super(clientToken);
|
super(clientToken);
|
||||||
ua = new YggdrasilAuthentication(Main.PROXY, clientToken);
|
ua = new YggdrasilAuthentication(Proxy.NO_PROXY, clientToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -43,9 +43,22 @@ public final class InstallerService {
|
|||||||
public InstallerService(Profile p) {
|
public InstallerService(Profile p) {
|
||||||
this.p = p;
|
this.p = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task download(InstallerVersion v, String type) {
|
||||||
|
switch(type) {
|
||||||
|
case "forge":
|
||||||
|
return downloadForge(v);
|
||||||
|
case "optifine":
|
||||||
|
return downloadOptifine(v);
|
||||||
|
case "liteloader":
|
||||||
|
return downloadLiteLoader(v);
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Task downloadForge(InstallerVersion v) {
|
public Task downloadForge(InstallerVersion v) {
|
||||||
return new TaskInfo("OptiFine Downloader") {
|
return new TaskInfo("Forge Downloader") {
|
||||||
@Override
|
@Override
|
||||||
public void executeTask() {
|
public void executeTask() {
|
||||||
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "forge-installer.jar");
|
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "forge-installer.jar");
|
||||||
@ -75,7 +88,7 @@ public final class InstallerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Task downloadLiteLoader(InstallerVersion v) {
|
public Task downloadLiteLoader(InstallerVersion v) {
|
||||||
return new TaskInfo("OptiFine Downloader") {
|
return new TaskInfo("LiteLoader Downloader") {
|
||||||
@Override
|
@Override
|
||||||
public void executeTask() {
|
public void executeTask() {
|
||||||
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "liteloader-universal.jar");
|
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "liteloader-universal.jar");
|
||||||
|
@ -18,18 +18,15 @@
|
|||||||
package org.jackhuang.hellominecraft.launcher.utils.installers.forge;
|
package org.jackhuang.hellominecraft.launcher.utils.installers.forge;
|
||||||
|
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallProfile;
|
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallProfile;
|
||||||
import com.google.gson.JsonSyntaxException;
|
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
import org.jackhuang.hellominecraft.C;
|
import org.jackhuang.hellominecraft.C;
|
||||||
import org.jackhuang.hellominecraft.HMCLog;
|
import org.jackhuang.hellominecraft.HMCLog;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Settings;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList.InstallerVersion;
|
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList.InstallerVersion;
|
||||||
import org.jackhuang.hellominecraft.tasks.Task;
|
import org.jackhuang.hellominecraft.tasks.Task;
|
||||||
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
||||||
@ -67,7 +64,7 @@ public class ForgeInstaller extends Task {
|
|||||||
File from = new File(gameDir, "versions" + File.separator + profile.install.minecraft);
|
File from = new File(gameDir, "versions" + File.separator + profile.install.minecraft);
|
||||||
if (!from.exists())
|
if (!from.exists())
|
||||||
if (MessageBox.Show(C.i18n("install.no_version_if_intall")) == MessageBox.YES_OPTION) {
|
if (MessageBox.Show(C.i18n("install.no_version_if_intall")) == MessageBox.YES_OPTION) {
|
||||||
if (!mp.install(profile.install.minecraft, Settings.getInstance().getDownloadSource()))
|
if (!mp.getDownloadService().install(profile.install.minecraft))
|
||||||
throw new IllegalStateException(C.i18n("install.no_version"));
|
throw new IllegalStateException(C.i18n("install.no_version"));
|
||||||
} else
|
} else
|
||||||
throw new IllegalStateException(C.i18n("install.no_version"));
|
throw new IllegalStateException(C.i18n("install.no_version"));
|
||||||
|
@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
* 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.version;
|
||||||
|
|
||||||
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.jackhuang.hellominecraft.C;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftAssetService;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.utils.assets.AssetsIndex;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.utils.assets.AssetsObject;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.utils.assets.IAssetsHandler;
|
||||||
|
import org.jackhuang.hellominecraft.tasks.Task;
|
||||||
|
import org.jackhuang.hellominecraft.tasks.TaskWindow;
|
||||||
|
import org.jackhuang.hellominecraft.tasks.download.FileDownloadTask;
|
||||||
|
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
||||||
|
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
||||||
|
import rx.concurrency.Schedulers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author huangyuhui
|
||||||
|
*/
|
||||||
|
public class MinecraftAssetService extends IMinecraftAssetService {
|
||||||
|
|
||||||
|
MinecraftVersionManager mgr;
|
||||||
|
|
||||||
|
public MinecraftAssetService(Profile profile, MinecraftVersionManager mvm) {
|
||||||
|
super(profile);
|
||||||
|
|
||||||
|
mgr = mvm;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Task downloadAssets(String mcVersion) {
|
||||||
|
return new Task() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeTask() throws Throwable {
|
||||||
|
IAssetsHandler type = IAssetsHandler.ASSETS_HANDLER;
|
||||||
|
type.getList(profile.getMinecraftProvider().getVersionById(mcVersion), profile.getMinecraftProvider())
|
||||||
|
.subscribeOn(Schedulers.newThread())
|
||||||
|
.observeOn(Schedulers.eventQueue())
|
||||||
|
.subscribe((value) -> TaskWindow.getInstance().addTask(type.getDownloadTask(profile.getDownloadType().getProvider())).start());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getInfo() {
|
||||||
|
return "Download Assets";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean refreshAssetsIndex(String id) {
|
||||||
|
MinecraftVersion mv = mgr.getVersionById(id);
|
||||||
|
if (mv == null)
|
||||||
|
return false;
|
||||||
|
return downloadMinecraftAssetsIndex(mv.assets);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean downloadMinecraftAssetsIndex(String assetsId) {
|
||||||
|
String aurl = profile.getDownloadType().getProvider().getIndexesDownloadURL();
|
||||||
|
|
||||||
|
File assetsLocation = getAssets();
|
||||||
|
assetsLocation.mkdirs();
|
||||||
|
File assetsIndex = new File(assetsLocation, "indexes/" + assetsId + ".json");
|
||||||
|
File renamed = null;
|
||||||
|
if (assetsIndex.exists()) {
|
||||||
|
renamed = new File(assetsLocation, "indexes/" + assetsId + "-renamed.json");
|
||||||
|
assetsIndex.renameTo(renamed);
|
||||||
|
}
|
||||||
|
if (TaskWindow.getInstance()
|
||||||
|
.addTask(new FileDownloadTask(aurl + assetsId + ".json", IOUtils.tryGetCanonicalFile(assetsIndex)).setTag(assetsId + ".json"))
|
||||||
|
.start()) {
|
||||||
|
if (renamed != null)
|
||||||
|
renamed.delete();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (renamed != null)
|
||||||
|
renamed.renameTo(assetsIndex);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getAssets() {
|
||||||
|
return new File(profile.getCanonicalGameDirFile(), "assets");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getAssetObject(String assetVersion, String name) throws IOException {
|
||||||
|
File assetsDir = getAssets();
|
||||||
|
File indexDir = new File(assetsDir, "indexes");
|
||||||
|
File objectsDir = new File(assetsDir, "objects");
|
||||||
|
File indexFile = new File(indexDir, assetVersion + ".json");
|
||||||
|
try {
|
||||||
|
AssetsIndex index = (AssetsIndex) C.gson.fromJson(FileUtils.readFileToString(indexFile, "UTF-8"), AssetsIndex.class);
|
||||||
|
|
||||||
|
String hash = ((AssetsObject) index.getFileMap().get(name)).getHash();
|
||||||
|
return new File(objectsDir, hash.substring(0, 2) + "/" + hash);
|
||||||
|
} catch (JsonSyntaxException e) {
|
||||||
|
throw new IOException("Assets file format malformed.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -21,7 +21,6 @@ import java.io.File;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -49,7 +48,7 @@ public class MinecraftClassicVersion extends MinecraftVersion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MinecraftVersion resolve(IMinecraftProvider manager, Set<String> resolvedSoFar, DownloadType sourceType) {
|
public MinecraftVersion resolve(IMinecraftProvider manager, Set<String> resolvedSoFar) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.jackhuang.hellominecraft.HMCLog;
|
import org.jackhuang.hellominecraft.HMCLog;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftModService;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftModService;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.ModInfo;
|
import org.jackhuang.hellominecraft.launcher.utils.ModInfo;
|
||||||
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
||||||
|
|
||||||
@ -32,10 +33,11 @@ import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
|||||||
*
|
*
|
||||||
* @author huangyuhui
|
* @author huangyuhui
|
||||||
*/
|
*/
|
||||||
public class MinecraftModService implements IMinecraftModService {
|
public class MinecraftModService extends IMinecraftModService {
|
||||||
MinecraftVersionManager mgr;
|
MinecraftVersionManager mgr;
|
||||||
|
|
||||||
public MinecraftModService(MinecraftVersionManager mgr) {
|
public MinecraftModService(Profile p, MinecraftVersionManager mgr) {
|
||||||
|
super(p);
|
||||||
this.mgr = mgr;
|
this.mgr = mgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,57 +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.version;
|
|
||||||
|
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Settings;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.assets.IAssetsHandler;
|
|
||||||
import org.jackhuang.hellominecraft.tasks.Task;
|
|
||||||
import org.jackhuang.hellominecraft.tasks.TaskWindow;
|
|
||||||
import rx.concurrency.Schedulers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author huangyuhui
|
|
||||||
*/
|
|
||||||
public class MinecraftService {
|
|
||||||
|
|
||||||
Profile profile;
|
|
||||||
|
|
||||||
public MinecraftService(Profile profile) {
|
|
||||||
this.profile = profile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task downloadAssets(String mcVersion) {
|
|
||||||
return new Task() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void executeTask() throws Throwable {
|
|
||||||
IAssetsHandler type = IAssetsHandler.ASSETS_HANDLER;
|
|
||||||
type.getList(profile.getMinecraftProvider().getVersionById(mcVersion), profile.getMinecraftProvider())
|
|
||||||
.subscribeOn(Schedulers.newThread())
|
|
||||||
.observeOn(Schedulers.eventQueue())
|
|
||||||
.subscribe((value) -> TaskWindow.getInstance().addTask(type.getDownloadTask(Settings.getInstance().getDownloadSource().getProvider())).start());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getInfo() {
|
|
||||||
return "Download Assets";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -24,7 +24,6 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.assets.AssetsIndex;
|
import org.jackhuang.hellominecraft.launcher.utils.assets.AssetsIndex;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
|
|
||||||
import org.jackhuang.hellominecraft.utils.ArrayUtils;
|
import org.jackhuang.hellominecraft.utils.ArrayUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,11 +70,11 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
|
|||||||
return new MinecraftVersion(minecraftArguments, mainClass, time, id, type, processArguments, releaseTime, assets, jar, inheritsFrom, minimumLauncherVersion, libraries, hidden);
|
return new MinecraftVersion(minecraftArguments, mainClass, time, id, type, processArguments, releaseTime, assets, jar, inheritsFrom, minimumLauncherVersion, libraries, hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MinecraftVersion resolve(IMinecraftProvider manager, DownloadType sourceType) {
|
public MinecraftVersion resolve(IMinecraftProvider manager) {
|
||||||
return resolve(manager, new HashSet<>(), sourceType);
|
return resolve(manager, new HashSet<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MinecraftVersion resolve(IMinecraftProvider manager, Set<String> resolvedSoFar, DownloadType sourceType) {
|
protected MinecraftVersion resolve(IMinecraftProvider manager, Set<String> resolvedSoFar) {
|
||||||
if (inheritsFrom == null)
|
if (inheritsFrom == null)
|
||||||
return this;
|
return this;
|
||||||
if (!resolvedSoFar.add(id))
|
if (!resolvedSoFar.add(id))
|
||||||
@ -83,11 +82,11 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
|
|||||||
|
|
||||||
MinecraftVersion parent = manager.getVersionById(inheritsFrom);
|
MinecraftVersion parent = manager.getVersionById(inheritsFrom);
|
||||||
if (parent == null) {
|
if (parent == null) {
|
||||||
if (!manager.install(inheritsFrom, sourceType))
|
if (!manager.getDownloadService().install(inheritsFrom))
|
||||||
return this;
|
return this;
|
||||||
parent = manager.getVersionById(inheritsFrom);
|
parent = manager.getVersionById(inheritsFrom);
|
||||||
}
|
}
|
||||||
parent = parent.resolve(manager, resolvedSoFar, sourceType);
|
parent = parent.resolve(manager, resolvedSoFar);
|
||||||
MinecraftVersion result = new MinecraftVersion(
|
MinecraftVersion result = new MinecraftVersion(
|
||||||
this.minecraftArguments != null ? this.minecraftArguments : parent.minecraftArguments,
|
this.minecraftArguments != null ? this.minecraftArguments : parent.minecraftArguments,
|
||||||
this.mainClass != null ? this.mainClass : parent.mainClass,
|
this.mainClass != null ? this.mainClass : parent.mainClass,
|
||||||
|
@ -22,13 +22,13 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import org.jackhuang.hellominecraft.C;
|
import org.jackhuang.hellominecraft.C;
|
||||||
import org.jackhuang.hellominecraft.HMCLog;
|
import org.jackhuang.hellominecraft.HMCLog;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.GameLauncher;
|
import org.jackhuang.hellominecraft.launcher.launch.GameLauncher;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.GameLauncher.DownloadLibraryJob;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftAssetService;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftDownloadService;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftLoader;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftLoader;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftModService;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftModService;
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
||||||
@ -36,9 +36,7 @@ import org.jackhuang.hellominecraft.launcher.launch.MinecraftLoader;
|
|||||||
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.MCUtils;
|
import org.jackhuang.hellominecraft.launcher.utils.MCUtils;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
|
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
import org.jackhuang.hellominecraft.launcher.settings.Profile;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.Settings;
|
|
||||||
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
||||||
import org.jackhuang.hellominecraft.utils.MessageBox;
|
import org.jackhuang.hellominecraft.utils.MessageBox;
|
||||||
import org.jackhuang.hellominecraft.utils.Utils;
|
import org.jackhuang.hellominecraft.utils.Utils;
|
||||||
@ -49,9 +47,8 @@ import org.jackhuang.hellominecraft.utils.Utils;
|
|||||||
*/
|
*/
|
||||||
public final class MinecraftVersionManager extends IMinecraftProvider {
|
public final class MinecraftVersionManager extends IMinecraftProvider {
|
||||||
|
|
||||||
private File baseFolder;
|
File baseFolder;
|
||||||
private final Profile profile;
|
final Map<String, MinecraftVersion> versions = new TreeMap();
|
||||||
private final Map<String, MinecraftVersion> versions = new TreeMap();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -59,7 +56,9 @@ public final class MinecraftVersionManager extends IMinecraftProvider {
|
|||||||
*/
|
*/
|
||||||
public MinecraftVersionManager(Profile p) {
|
public MinecraftVersionManager(Profile p) {
|
||||||
super(p);
|
super(p);
|
||||||
this.profile = p;
|
mms = new MinecraftModService(p, this);
|
||||||
|
mds = new MinecraftDownloadService(p, this);
|
||||||
|
mas = new MinecraftAssetService(p, this);
|
||||||
refreshVersions();
|
refreshVersions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,77 +190,24 @@ public final class MinecraftVersionManager extends IMinecraftProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean refreshJson(String id) {
|
|
||||||
return MCUtils.downloadMinecraftVersionJson(baseFolder, id, Settings.getInstance().getDownloadSource());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean refreshAssetsIndex(String id) {
|
|
||||||
MinecraftVersion mv = getVersionById(id);
|
|
||||||
if (mv == null)
|
|
||||||
return false;
|
|
||||||
return MCUtils.downloadMinecraftAssetsIndex(new File(baseFolder, "assets"), mv.assets, Settings.getInstance().getDownloadSource());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean install(String id, DownloadType sourceType) {
|
|
||||||
MinecraftVersion v = MCUtils.downloadMinecraft(baseFolder, id, sourceType);
|
|
||||||
if (v != null) {
|
|
||||||
versions.put(v.id, v);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getRunDirectory(String id) {
|
public File getRunDirectory(String id) {
|
||||||
switch (profile.getGameDirType()) {
|
switch (profile.getGameDirType()) {
|
||||||
case VERSION_FOLDER:
|
case VERSION_FOLDER:
|
||||||
return new File(baseFolder, "versions/" + id + "/");
|
return new File(baseFolder, "versions/" + id + "/");
|
||||||
default:
|
default:
|
||||||
return baseFolder;
|
return baseFolder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GameLauncher.DownloadLibraryJob> getDownloadLibraries(DownloadType downloadType) {
|
|
||||||
ArrayList<DownloadLibraryJob> downloadLibraries = new ArrayList<>();
|
|
||||||
if (profile.getSelectedMinecraftVersion() == null)
|
|
||||||
return downloadLibraries;
|
|
||||||
MinecraftVersion v = profile.getSelectedMinecraftVersion().resolve(this, Settings.getInstance().getDownloadSource());
|
|
||||||
if (v.libraries != null)
|
|
||||||
for (IMinecraftLibrary l : v.libraries) {
|
|
||||||
l.init();
|
|
||||||
if (l.allow()) {
|
|
||||||
File ff = l.getFilePath(baseFolder);
|
|
||||||
if (!ff.exists()) {
|
|
||||||
String libURL = downloadType.getProvider().getLibraryDownloadURL() + "/";
|
|
||||||
libURL = downloadType.getProvider().getParsedLibraryDownloadURL(l.getDownloadURL(libURL, downloadType));
|
|
||||||
if (libURL != null)
|
|
||||||
downloadLibraries.add(new DownloadLibraryJob(l.name, libURL, ff));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return downloadLibraries;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void open(String mv, String name) {
|
public void open(String mv, String name) {
|
||||||
if (name == null)
|
Utils.openFolder((name == null) ? getRunDirectory(mv) : new File(getRunDirectory(mv), name));
|
||||||
Utils.openFolder(getRunDirectory(mv));
|
|
||||||
else
|
|
||||||
Utils.openFolder(new File(getRunDirectory(mv), name));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public File getAssets() {
|
|
||||||
return new File(profile.getCanonicalGameDirFile(), "assets");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GameLauncher.DecompressLibraryJob getDecompressLibraries() {
|
public GameLauncher.DecompressLibraryJob getDecompressLibraries() {
|
||||||
MinecraftVersion v = profile.getSelectedMinecraftVersion().resolve(this, Settings.getInstance().getDownloadSource());
|
MinecraftVersion v = profile.getSelectedMinecraftVersion().resolve(this);
|
||||||
if (v.libraries == null)
|
if (v.libraries == null)
|
||||||
return null;
|
return null;
|
||||||
ArrayList<File> unzippings = new ArrayList<>();
|
ArrayList<File> unzippings = new ArrayList<>();
|
||||||
@ -288,9 +234,9 @@ public final class MinecraftVersionManager extends IMinecraftProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMinecraftLoader provideMinecraftLoader(UserProfileProvider p, DownloadType type)
|
public IMinecraftLoader provideMinecraftLoader(UserProfileProvider p)
|
||||||
throws IllegalStateException {
|
throws IllegalStateException {
|
||||||
return new MinecraftLoader(profile, this, p, type);
|
return new MinecraftLoader(profile, this, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -334,10 +280,24 @@ public final class MinecraftVersionManager extends IMinecraftProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final MinecraftModService mms = new MinecraftModService(this);
|
final MinecraftModService mms;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMinecraftModService getModService() {
|
public IMinecraftModService getModService() {
|
||||||
return mms;
|
return mms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final MinecraftDownloadService mds;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMinecraftDownloadService getDownloadService() {
|
||||||
|
return mds;
|
||||||
|
}
|
||||||
|
|
||||||
|
final MinecraftAssetService mas;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMinecraftAssetService getAssetService() {
|
||||||
|
return mas;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1068,7 +1068,7 @@
|
|||||||
<Component id="cboVersions" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
|
<Component id="cboVersions" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
|
||||||
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
|
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
</Group>
|
</Group>
|
||||||
<EmptySpace pref="11" max="32767" attributes="0"/>
|
<EmptySpace max="32767" attributes="0"/>
|
||||||
</Group>
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
</DimensionLayout>
|
</DimensionLayout>
|
||||||
|
@ -32,8 +32,6 @@ import java.awt.event.ItemEvent;
|
|||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.swing.JFileChooser;
|
import javax.swing.JFileChooser;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
@ -48,7 +46,6 @@ import javax.swing.table.DefaultTableModel;
|
|||||||
import org.jackhuang.hellominecraft.C;
|
import org.jackhuang.hellominecraft.C;
|
||||||
import org.jackhuang.hellominecraft.HMCLog;
|
import org.jackhuang.hellominecraft.HMCLog;
|
||||||
import org.jackhuang.hellominecraft.launcher.settings.LauncherVisibility;
|
import org.jackhuang.hellominecraft.launcher.settings.LauncherVisibility;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.MCUtils;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList;
|
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList.InstallerVersion;
|
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList.InstallerVersion;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
|
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
|
||||||
@ -58,12 +55,10 @@ import org.jackhuang.hellominecraft.launcher.utils.FileNameFilter;
|
|||||||
import org.jackhuang.hellominecraft.launcher.utils.ModInfo;
|
import org.jackhuang.hellominecraft.launcher.utils.ModInfo;
|
||||||
import org.jackhuang.hellominecraft.launcher.version.GameDirType;
|
import org.jackhuang.hellominecraft.launcher.version.GameDirType;
|
||||||
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
||||||
import org.jackhuang.hellominecraft.tasks.Task;
|
|
||||||
import org.jackhuang.hellominecraft.tasks.TaskRunnable;
|
import org.jackhuang.hellominecraft.tasks.TaskRunnable;
|
||||||
import org.jackhuang.hellominecraft.tasks.TaskRunnableArg1;
|
import org.jackhuang.hellominecraft.tasks.TaskRunnableArg1;
|
||||||
import org.jackhuang.hellominecraft.tasks.TaskWindow;
|
import org.jackhuang.hellominecraft.tasks.TaskWindow;
|
||||||
import org.jackhuang.hellominecraft.tasks.communication.DefaultPreviousResult;
|
import org.jackhuang.hellominecraft.tasks.communication.DefaultPreviousResult;
|
||||||
import org.jackhuang.hellominecraft.tasks.download.HTTPGetTask;
|
|
||||||
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
||||||
import org.jackhuang.hellominecraft.utils.MessageBox;
|
import org.jackhuang.hellominecraft.utils.MessageBox;
|
||||||
import org.jackhuang.hellominecraft.version.MinecraftVersionRequest;
|
import org.jackhuang.hellominecraft.version.MinecraftVersionRequest;
|
||||||
@ -71,15 +66,14 @@ import org.jackhuang.hellominecraft.utils.system.OS;
|
|||||||
import org.jackhuang.hellominecraft.utils.StrUtils;
|
import org.jackhuang.hellominecraft.utils.StrUtils;
|
||||||
import org.jackhuang.hellominecraft.utils.SwingUtils;
|
import org.jackhuang.hellominecraft.utils.SwingUtils;
|
||||||
import org.jackhuang.hellominecraft.utils.system.Java;
|
import org.jackhuang.hellominecraft.utils.system.Java;
|
||||||
import org.jackhuang.hellominecraft.version.MinecraftRemoteVersion;
|
|
||||||
import org.jackhuang.hellominecraft.version.MinecraftRemoteVersions;
|
|
||||||
import org.jackhuang.hellominecraft.views.LogWindow;
|
import org.jackhuang.hellominecraft.views.LogWindow;
|
||||||
|
import rx.concurrency.Schedulers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author huangyuhui
|
* @author huangyuhui
|
||||||
*/
|
*/
|
||||||
public class GameSettingsPanel extends javax.swing.JPanel implements DropTargetListener {
|
public final class GameSettingsPanel extends javax.swing.JPanel implements DropTargetListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new form GameSettingsPanel
|
* Creates new form GameSettingsPanel
|
||||||
@ -92,7 +86,18 @@ public class GameSettingsPanel extends javax.swing.JPanel implements DropTargetL
|
|||||||
forge = new InstallerHelper(lstForge, "forge");
|
forge = new InstallerHelper(lstForge, "forge");
|
||||||
liteloader = new InstallerHelper(lstLiteLoader, "liteloader");
|
liteloader = new InstallerHelper(lstLiteLoader, "liteloader");
|
||||||
optifine = new InstallerHelper(lstOptifine, "optifine");
|
optifine = new InstallerHelper(lstOptifine, "optifine");
|
||||||
//<editor-fold defaultstate="collapsed" desc="Explore Menu">
|
initExplorationMenu();
|
||||||
|
initManagementMenu();
|
||||||
|
initExternalModsTable();
|
||||||
|
initTabs();
|
||||||
|
|
||||||
|
for (Java j : Settings.JAVA)
|
||||||
|
cboJava.addItem(j.getLocalizedName());
|
||||||
|
|
||||||
|
dropTarget = new DropTarget(lstExternalMods, DnDConstants.ACTION_COPY_OR_MOVE, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void initExplorationMenu() {
|
||||||
ppmExplore = new JPopupMenu();
|
ppmExplore = new JPopupMenu();
|
||||||
class ImplementedActionListener implements ActionListener {
|
class ImplementedActionListener implements ActionListener {
|
||||||
|
|
||||||
@ -127,10 +132,11 @@ public class GameSettingsPanel extends javax.swing.JPanel implements DropTargetL
|
|||||||
itm = new JMenuItem(C.i18n("folder.screenshots"));
|
itm = new JMenuItem(C.i18n("folder.screenshots"));
|
||||||
itm.addActionListener(new ImplementedActionListener("screenshots"));
|
itm.addActionListener(new ImplementedActionListener("screenshots"));
|
||||||
ppmExplore.add(itm);
|
ppmExplore.add(itm);
|
||||||
//</editor-fold>
|
}
|
||||||
//<editor-fold defaultstate="collapsed" desc="Manage Menu">
|
|
||||||
|
void initManagementMenu() {
|
||||||
ppmManage = new JPopupMenu();
|
ppmManage = new JPopupMenu();
|
||||||
itm = new JMenuItem(C.i18n("versions.manage.rename"));
|
JMenuItem itm = new JMenuItem(C.i18n("versions.manage.rename"));
|
||||||
itm.addActionListener((e) -> {
|
itm.addActionListener((e) -> {
|
||||||
Profile v = getProfile();
|
Profile v = getProfile();
|
||||||
if (v != null && mcVersion != null) {
|
if (v != null && mcVersion != null) {
|
||||||
@ -160,11 +166,12 @@ public class GameSettingsPanel extends javax.swing.JPanel implements DropTargetL
|
|||||||
itm.addActionListener((e) -> {
|
itm.addActionListener((e) -> {
|
||||||
Profile v = getProfile();
|
Profile v = getProfile();
|
||||||
if (v != null && mcVersion != null)
|
if (v != null && mcVersion != null)
|
||||||
v.getMinecraftProvider().refreshAssetsIndex(mcVersion);
|
v.getMinecraftProvider().getAssetService().refreshAssetsIndex(mcVersion);
|
||||||
});
|
});
|
||||||
ppmManage.add(itm);
|
ppmManage.add(itm);
|
||||||
//</editor-fold>
|
}
|
||||||
|
|
||||||
|
void initExternalModsTable() {
|
||||||
if (lstExternalMods.getColumnModel().getColumnCount() > 0) {
|
if (lstExternalMods.getColumnModel().getColumnCount() > 0) {
|
||||||
lstExternalMods.getColumnModel().getColumn(0).setMinWidth(17);
|
lstExternalMods.getColumnModel().getColumn(0).setMinWidth(17);
|
||||||
lstExternalMods.getColumnModel().getColumn(0).setPreferredWidth(17);
|
lstExternalMods.getColumnModel().getColumn(0).setPreferredWidth(17);
|
||||||
@ -191,6 +198,9 @@ public class GameSettingsPanel extends javax.swing.JPanel implements DropTargetL
|
|||||||
mods.get(row).reverseModState();
|
mods.get(row).reverseModState();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void initTabs() {
|
||||||
tabVersionEdit.addChangeListener(new ChangeListener() {
|
tabVersionEdit.addChangeListener(new ChangeListener() {
|
||||||
boolean a = false, b = false;
|
boolean a = false, b = false;
|
||||||
|
|
||||||
@ -218,17 +228,6 @@ public class GameSettingsPanel extends javax.swing.JPanel implements DropTargetL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (Java j : Settings.JAVA) {
|
|
||||||
String name = j.getName();
|
|
||||||
if (name.equals("Default"))
|
|
||||||
name = C.i18n("settings.default");
|
|
||||||
if (name.equals("Custom"))
|
|
||||||
name = C.i18n("settings.custom");
|
|
||||||
cboJava.addItem(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
dropTarget = new DropTarget(lstExternalMods, DnDConstants.ACTION_COPY_OR_MOVE, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1250,7 +1249,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
|||||||
|
|
||||||
private void btnDownloadAllAssetsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadAllAssetsActionPerformed
|
private void btnDownloadAllAssetsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadAllAssetsActionPerformed
|
||||||
if (mcVersion != null && profile != null)
|
if (mcVersion != null && profile != null)
|
||||||
profile.getMinecraftService().downloadAssets(mcVersion).run();
|
profile.getMinecraftProvider().getAssetService().downloadAssets(mcVersion).run();
|
||||||
}//GEN-LAST:event_btnDownloadAllAssetsActionPerformed
|
}//GEN-LAST:event_btnDownloadAllAssetsActionPerformed
|
||||||
|
|
||||||
private void txtMaxMemoryFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMaxMemoryFocusLost
|
private void txtMaxMemoryFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMaxMemoryFocusLost
|
||||||
@ -1369,7 +1368,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
|||||||
}//GEN-LAST:event_btnMakeLaunchScriptActionPerformed
|
}//GEN-LAST:event_btnMakeLaunchScriptActionPerformed
|
||||||
|
|
||||||
private void btnShowLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShowLogActionPerformed
|
private void btnShowLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShowLogActionPerformed
|
||||||
LogWindow.instance.setVisible(true);
|
LogWindow.INSTANCE.setVisible(true);
|
||||||
}//GEN-LAST:event_btnShowLogActionPerformed
|
}//GEN-LAST:event_btnShowLogActionPerformed
|
||||||
|
|
||||||
private void btnCleanGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCleanGameActionPerformed
|
private void btnCleanGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCleanGameActionPerformed
|
||||||
@ -1482,46 +1481,24 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
|||||||
txtMinecraftVersion.setText("");
|
txtMinecraftVersion.setText("");
|
||||||
if (v == null)
|
if (v == null)
|
||||||
return;
|
return;
|
||||||
File minecraftJar = v.getJar(profile.getGameDirFile());
|
minecraftVersion = MinecraftVersionRequest.minecraftVersion(v.getJar(profile.getGameDirFile()));
|
||||||
minecraftVersion = MCUtils.minecraftVersion(minecraftJar);
|
|
||||||
txtMinecraftVersion.setText(MinecraftVersionRequest.getResponse(minecraftVersion));
|
txtMinecraftVersion.setText(MinecraftVersionRequest.getResponse(minecraftVersion));
|
||||||
}
|
}
|
||||||
//</editor-fold>
|
|
||||||
// <editor-fold defaultstate="collapsed" desc="Assets">
|
|
||||||
public int assetsType;
|
|
||||||
|
|
||||||
// </editor-fold>
|
//</editor-fold>
|
||||||
// <editor-fold defaultstate="collapsed" desc="Game Download">
|
// <editor-fold defaultstate="collapsed" desc="Game Download">
|
||||||
public void refreshDownloads(final DownloadType provider) {
|
public void refreshDownloads(final DownloadType provider) {
|
||||||
TaskWindow.getInstance().addTask(new Task() {
|
DefaultTableModel model = (DefaultTableModel) lstDownloads.getModel();
|
||||||
HTTPGetTask tsk = new HTTPGetTask(provider.getProvider().getVersionsListDownloadURL());
|
while (model.getRowCount() > 0)
|
||||||
|
model.removeRow(0);
|
||||||
@Override
|
profile.getMinecraftProvider().getDownloadService().getRemoteVersions()
|
||||||
public void executeTask() {
|
.observeOn(Schedulers.eventQueue()).subscribeOn(Schedulers.newThread())
|
||||||
final MinecraftRemoteVersions v = C.gson.fromJson(tsk.getResult(), MinecraftRemoteVersions.class);
|
.subscribe((ver) -> model.addRow(new Object[] {ver.id, ver.time,
|
||||||
if (v == null || v.versions == null)
|
StrUtils.equalsOne(ver.type, "old_beta", "old_alpha", "release", "snapshot") ? C.i18n("versions." + ver.type) : ver.type}),
|
||||||
return;
|
(e) -> {
|
||||||
SwingUtilities.invokeLater(() -> {
|
MessageBox.Show("Failed to refresh download: " + e.getLocalizedMessage());
|
||||||
DefaultTableModel model = (DefaultTableModel) lstDownloads.getModel();
|
HMCLog.err("Failed to refresh download.", e);
|
||||||
while (model.getRowCount() > 0)
|
}, lstDownloads::updateUI);
|
||||||
model.removeRow(0);
|
|
||||||
for (MinecraftRemoteVersion ver : v.versions)
|
|
||||||
model.addRow(new Object[] {ver.id, ver.time,
|
|
||||||
StrUtils.equalsOne(ver.type, "old_beta", "old_alpha", "release", "snapshot") ? C.i18n("versions." + ver.type) : ver.type});
|
|
||||||
lstDownloads.updateUI();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getInfo() {
|
|
||||||
return "Format list.";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<Task> getDependTasks() {
|
|
||||||
return Arrays.asList((Task) tsk);
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void downloadMinecraft(DownloadType index) {
|
void downloadMinecraft(DownloadType index) {
|
||||||
@ -1534,7 +1511,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String id = (String) lstDownloads.getModel().getValueAt(lstDownloads.getSelectedRow(), 0);
|
String id = (String) lstDownloads.getModel().getValueAt(lstDownloads.getSelectedRow(), 0);
|
||||||
MCUtils.downloadMinecraft(profile.getGameDirFile(), id, index);
|
profile.getMinecraftProvider().getDownloadService().downloadMinecraft(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// </editor-fold>
|
// </editor-fold>
|
||||||
@ -1607,7 +1584,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
|||||||
MessageBox.Show(C.i18n("install.not_refreshed"));
|
MessageBox.Show(C.i18n("install.not_refreshed"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
profile.getInstallerService().downloadOptifine(getVersion(idx)).after(new TaskRunnable(this::refreshVersions)).run();
|
profile.getInstallerService().download(getVersion(idx), id).after(new TaskRunnable(this::refreshVersions)).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<InstallerVersionList.InstallerVersion> loadVersions(InstallerVersionList list, JTable table) {
|
private List<InstallerVersionList.InstallerVersion> loadVersions(InstallerVersionList list, JTable table) {
|
||||||
|
@ -390,7 +390,7 @@ public class MainPagePanel extends javax.swing.JPanel {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Thread.currentThread().setName("Game Launcher");
|
Thread.currentThread().setName("Game Launcher");
|
||||||
DefaultGameLauncher gl = new DefaultGameLauncher(getCurrentProfile(), li, l, Settings.getInstance().getDownloadSource());
|
DefaultGameLauncher gl = new DefaultGameLauncher(getCurrentProfile(), li, l);
|
||||||
gl.failEvent.register((sender, s) -> {
|
gl.failEvent.register((sender, s) -> {
|
||||||
if (s != null)
|
if (s != null)
|
||||||
MessageBox.Show(s);
|
MessageBox.Show(s);
|
||||||
|
@ -46,9 +46,9 @@ public class ContentGetAndShowTask extends HTTPGetTask implements Event<String>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean call(Object sender, String value) {
|
public boolean call(Object sender, String value) {
|
||||||
LogWindow.instance.clean();
|
LogWindow.INSTANCE.clean();
|
||||||
LogWindow.instance.log(value);
|
LogWindow.INSTANCE.log(value);
|
||||||
LogWindow.instance.setVisible(true);
|
LogWindow.INSTANCE.setVisible(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,11 +17,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hellominecraft.utils;
|
package org.jackhuang.hellominecraft.utils;
|
||||||
|
|
||||||
import org.jackhuang.hellominecraft.utils.functions.Consumer;
|
|
||||||
import org.jackhuang.hellominecraft.utils.functions.Predicate;
|
import org.jackhuang.hellominecraft.utils.functions.Predicate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import rx.Observable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -29,17 +29,9 @@ import java.util.Iterator;
|
|||||||
*/
|
*/
|
||||||
public final class CollectionUtils {
|
public final class CollectionUtils {
|
||||||
|
|
||||||
public static <T> void forEach(Collection<T> coll, Consumer<T> p) {
|
|
||||||
for (T t : coll)
|
|
||||||
p.accept(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> ArrayList<T> map(Collection<T> coll, Predicate<T> p) {
|
public static <T> ArrayList<T> map(Collection<T> coll, Predicate<T> p) {
|
||||||
ArrayList<T> newColl = new ArrayList<>();
|
ArrayList<T> newColl = new ArrayList<>();
|
||||||
forEach(coll, t -> {
|
Observable.from(coll).filter(p).subscribe(newColl::add);
|
||||||
if (p.apply(t))
|
|
||||||
newColl.add(t);
|
|
||||||
});
|
|
||||||
return newColl;
|
return newColl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,8 @@ import java.net.URL;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.jackhuang.hellominecraft.HMCLog;
|
import org.jackhuang.hellominecraft.HMCLog;
|
||||||
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
||||||
|
import rx.Observable;
|
||||||
|
import rx.subscriptions.Subscriptions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -156,4 +158,15 @@ public final class NetUtils {
|
|||||||
throw new IllegalArgumentException("Could not concatenate given URL with GET arguments!", ex);
|
throw new IllegalArgumentException("Could not concatenate given URL with GET arguments!", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Observable<String> getRx(String url) {
|
||||||
|
return Observable.create(t1 -> {
|
||||||
|
try {
|
||||||
|
t1.onNext(get(url));
|
||||||
|
} catch(Exception e) {
|
||||||
|
t1.onError(e);
|
||||||
|
}
|
||||||
|
return Subscriptions.empty();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.jackhuang.hellominecraft.C;
|
||||||
import org.jackhuang.hellominecraft.HMCLog;
|
import org.jackhuang.hellominecraft.HMCLog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,6 +41,14 @@ public class Java {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getLocalizedName() {
|
||||||
|
if (name.equals("Default"))
|
||||||
|
return C.i18n("settings.default");
|
||||||
|
if (name.equals("Custom"))
|
||||||
|
return C.i18n("settings.custom");
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public String getHome() {
|
public String getHome() {
|
||||||
return home;
|
return home;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hellominecraft.version;
|
package org.jackhuang.hellominecraft.version;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipFile;
|
||||||
import org.jackhuang.hellominecraft.C;
|
import org.jackhuang.hellominecraft.C;
|
||||||
|
import org.jackhuang.hellominecraft.HMCLog;
|
||||||
|
import org.jackhuang.hellominecraft.utils.ArrayUtils;
|
||||||
|
import org.jackhuang.hellominecraft.utils.NetUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author huangyuhui
|
* @author huangyuhui
|
||||||
@ -59,4 +66,127 @@ public class MinecraftVersionRequest {
|
|||||||
}
|
}
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int lessThan32(byte[] b, int x) {
|
||||||
|
for (; x < b.length; x++)
|
||||||
|
if (b[x] < 32)
|
||||||
|
return x;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MinecraftVersionRequest getVersionOfOldMinecraft(ZipFile file, ZipEntry entry) throws IOException {
|
||||||
|
MinecraftVersionRequest r = new MinecraftVersionRequest();
|
||||||
|
byte[] tmp = NetUtils.getBytesFromStream(file.getInputStream(entry));
|
||||||
|
|
||||||
|
byte[] bytes = "Minecraft Minecraft ".getBytes("ASCII");
|
||||||
|
int j;
|
||||||
|
if ((j = ArrayUtils.matchArray(tmp, bytes)) < 0) {
|
||||||
|
r.type = MinecraftVersionRequest.UNKOWN;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
int i = j + bytes.length;
|
||||||
|
|
||||||
|
if ((j = lessThan32(tmp, i)) < 0) {
|
||||||
|
r.type = MinecraftVersionRequest.UNKOWN;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
String ver = new String(tmp, i, j - i, "ASCII");
|
||||||
|
r.version = ver;
|
||||||
|
|
||||||
|
r.type = file.getEntry("META-INF/MANIFEST.MF") == null
|
||||||
|
? MinecraftVersionRequest.MODIFIED : MinecraftVersionRequest.OK;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MinecraftVersionRequest getVersionOfNewMinecraft(ZipFile file, ZipEntry entry) throws IOException {
|
||||||
|
MinecraftVersionRequest r = new MinecraftVersionRequest();
|
||||||
|
byte[] tmp = NetUtils.getBytesFromStream(file.getInputStream(entry));
|
||||||
|
|
||||||
|
byte[] str = "-server.txt".getBytes("ASCII");
|
||||||
|
int j = ArrayUtils.matchArray(tmp, str);
|
||||||
|
if (j < 0) {
|
||||||
|
r.type = MinecraftVersionRequest.UNKOWN;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
int i = j + str.length;
|
||||||
|
i += 11;
|
||||||
|
j = lessThan32(tmp, i);
|
||||||
|
if (j < 0) {
|
||||||
|
r.type = MinecraftVersionRequest.UNKOWN;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
r.version = new String(tmp, i, j - i, "ASCII");
|
||||||
|
|
||||||
|
char ch = r.version.charAt(0);
|
||||||
|
// 1.8.1+
|
||||||
|
if (ch < '0' || ch > '9') {
|
||||||
|
str = "Can't keep up! Did the system time change, or is the server overloaded?".getBytes("ASCII");
|
||||||
|
j = ArrayUtils.matchArray(tmp, str);
|
||||||
|
if (j < 0) {
|
||||||
|
r.type = MinecraftVersionRequest.UNKOWN;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
i = -1;
|
||||||
|
while (j > 0) {
|
||||||
|
if (tmp[j] >= 48 && tmp[j] <= 57) {
|
||||||
|
i = j;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
j--;
|
||||||
|
}
|
||||||
|
if (i == -1) {
|
||||||
|
r.type = MinecraftVersionRequest.UNKOWN;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
int k = i;
|
||||||
|
while (tmp[k] >= 48 && tmp[k] <= 57 || tmp[k] == 46)
|
||||||
|
k--;
|
||||||
|
k++;
|
||||||
|
r.version = new String(tmp, k, i - k + 1);
|
||||||
|
}
|
||||||
|
r.type = file.getEntry("META-INF/MANIFEST.MF") == null
|
||||||
|
? MinecraftVersionRequest.MODIFIED : MinecraftVersionRequest.OK;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MinecraftVersionRequest minecraftVersion(File file) {
|
||||||
|
MinecraftVersionRequest r = new MinecraftVersionRequest();
|
||||||
|
if (!file.exists()) {
|
||||||
|
r.type = MinecraftVersionRequest.NOT_FOUND;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
if (!file.isFile()) {
|
||||||
|
r.type = MinecraftVersionRequest.NOT_FILE;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
if (!file.canRead()) {
|
||||||
|
r.type = MinecraftVersionRequest.UNREADABLE;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
ZipFile localZipFile = null;
|
||||||
|
try {
|
||||||
|
localZipFile = new ZipFile(file);
|
||||||
|
ZipEntry minecraft = localZipFile
|
||||||
|
.getEntry("net/minecraft/client/Minecraft.class");
|
||||||
|
if (minecraft != null)
|
||||||
|
return getVersionOfOldMinecraft(localZipFile, minecraft);
|
||||||
|
ZipEntry main = localZipFile.getEntry("net/minecraft/client/main/Main.class");
|
||||||
|
ZipEntry minecraftserver = localZipFile.getEntry("net/minecraft/server/MinecraftServer.class");
|
||||||
|
if ((main != null) && (minecraftserver != null))
|
||||||
|
return getVersionOfNewMinecraft(localZipFile, minecraftserver);
|
||||||
|
r.type = MinecraftVersionRequest.INVALID;
|
||||||
|
return r;
|
||||||
|
} catch (IOException localException) {
|
||||||
|
HMCLog.warn("Zip file is invalid", localException);
|
||||||
|
r.type = MinecraftVersionRequest.INVALID_JAR;
|
||||||
|
return r;
|
||||||
|
} finally {
|
||||||
|
if (localZipFile != null)
|
||||||
|
try {
|
||||||
|
localZipFile.close();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
HMCLog.warn("Failed to close zip file", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ public class LogWindow extends javax.swing.JFrame {
|
|||||||
System.setErr(new LauncherPrintStream(err));
|
System.setErr(new LauncherPrintStream(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LogWindow instance = new LogWindow();
|
public static final LogWindow INSTANCE = new LogWindow();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called from within the constructor to initialize the form.
|
* This method is called from within the constructor to initialize the form.
|
||||||
|
@ -2478,6 +2478,10 @@ public class Observable<T> {
|
|||||||
public Observable<T> where(Func1<T, Boolean> predicate) {
|
public Observable<T> where(Func1<T, Boolean> predicate) {
|
||||||
return where(this, predicate);
|
return where(this, predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final <R> Observable<R> flatMap(Func1<? super T, ? extends Observable<? extends R>> func) {
|
||||||
|
return merge(map(func));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the last element of an observable sequence with a specified source.
|
* Returns the last element of an observable sequence with a specified source.
|
||||||
|
@ -1,7 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
* Hello Minecraft! Launcher.
|
||||||
* To change this template file, choose Tools | Templates
|
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
|
||||||
* and open the template in the editor.
|
*
|
||||||
|
* 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 rx.concurrency;
|
package rx.concurrency;
|
||||||
|
|
||||||
|
@ -55,12 +55,7 @@ public class OperationSubscribeOn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unsubscribe() {
|
public void unsubscribe() {
|
||||||
scheduler.schedule(new Action0() {
|
scheduler.schedule(underlying::unsubscribe);
|
||||||
@Override
|
|
||||||
public void call() {
|
|
||||||
underlying.unsubscribe();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright 2013 Netflix, Inc.
|
* Copyright 2013 Netflix, Inc.
|
||||||
*
|
* <p>
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
* <p>
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
* <p>
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
@ -22,24 +22,18 @@ import org.jackhuang.hellominecraft.logging.logger.Logger;
|
|||||||
/**
|
/**
|
||||||
* Allows execution of functions from multiple different languages.
|
* Allows execution of functions from multiple different languages.
|
||||||
* <p>
|
* <p>
|
||||||
* Language support is provided via implementations of {@link FunctionLanguageAdaptor}.
|
* Language support is provided via implementations of
|
||||||
|
* {@link FunctionLanguageAdaptor}.
|
||||||
* <p>
|
* <p>
|
||||||
* This class will dynamically look for known language adaptors on the classpath at startup or new ones can be registered using {@link #registerLanguageAdaptor(Class[], FunctionLanguageAdaptor)}.
|
* This class will dynamically look for known language adaptors on the classpath
|
||||||
|
* at startup or new ones can be registered using
|
||||||
|
* {@link #registerLanguageAdaptor(Class[], FunctionLanguageAdaptor)}.
|
||||||
*/
|
*/
|
||||||
public class Functions {
|
public class Functions {
|
||||||
|
|
||||||
private static final Logger logger = new Logger("Functions");
|
private static final Logger logger = new Logger("Functions");
|
||||||
|
|
||||||
private final static ConcurrentHashMap<Class<?>, FunctionLanguageAdaptor> languageAdaptors = new ConcurrentHashMap<Class<?>, FunctionLanguageAdaptor>();
|
private final static ConcurrentHashMap<Class<?>, FunctionLanguageAdaptor> languageAdaptors = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
static {
|
|
||||||
/* optimistically look for supported languages if they are in the classpath */
|
|
||||||
loadLanguageAdaptor("Groovy");
|
|
||||||
loadLanguageAdaptor("JRuby");
|
|
||||||
loadLanguageAdaptor("Clojure");
|
|
||||||
loadLanguageAdaptor("Scala");
|
|
||||||
// as new languages arise we can add them here but this does not prevent someone from using 'registerLanguageAdaptor' directly
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean loadLanguageAdaptor(String name) {
|
private static boolean loadLanguageAdaptor(String name) {
|
||||||
String className = "rx.lang." + name.toLowerCase() + "." + name + "Adaptor";
|
String className = "rx.lang." + name.toLowerCase() + "." + name + "Adaptor";
|
||||||
@ -60,9 +54,8 @@ public class Functions {
|
|||||||
|
|
||||||
public static void registerLanguageAdaptor(Class<?>[] functionClasses, FunctionLanguageAdaptor adaptor) {
|
public static void registerLanguageAdaptor(Class<?>[] functionClasses, FunctionLanguageAdaptor adaptor) {
|
||||||
for (Class<?> functionClass : functionClasses) {
|
for (Class<?> functionClass : functionClasses) {
|
||||||
if (functionClass.getPackage().getName().startsWith("java.")) {
|
if (functionClass.getPackage().getName().startsWith("java."))
|
||||||
throw new IllegalArgumentException("FunctionLanguageAdaptor implementations can not specify java.lang.* classes.");
|
throw new IllegalArgumentException("FunctionLanguageAdaptor implementations can not specify java.lang.* classes.");
|
||||||
}
|
|
||||||
languageAdaptors.put(functionClass, adaptor);
|
languageAdaptors.put(functionClass, adaptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,24 +69,24 @@ public class Functions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility method for determining the type of closure/function and executing it.
|
* Utility method for determining the type of closure/function and executing
|
||||||
*
|
* it.
|
||||||
|
*
|
||||||
* @param function
|
* @param function
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "rawtypes" })
|
@SuppressWarnings({"rawtypes"})
|
||||||
public static FuncN from(final Object function) {
|
public static FuncN from(final Object function) {
|
||||||
if (function == null) {
|
if (function == null)
|
||||||
throw new RuntimeException("function is null. Can't send arguments to null function.");
|
throw new RuntimeException("function is null. Can't send arguments to null function.");
|
||||||
}
|
|
||||||
|
|
||||||
/* check for typed Rx Function implementation first */
|
/* check for typed Rx Function implementation first */
|
||||||
if (function instanceof Function) {
|
if (function instanceof Function)
|
||||||
return fromFunction((Function) function);
|
return fromFunction((Function) function);
|
||||||
} else {
|
else
|
||||||
/* not an Rx Function so try language adaptors */
|
/* not an Rx Function so try language adaptors */
|
||||||
|
|
||||||
// check for language adaptor
|
// check for language adaptor
|
||||||
for (final Class c : languageAdaptors.keySet()) {
|
for (final Class c : languageAdaptors.keySet())
|
||||||
if (c.isInstance(function)) {
|
if (c.isInstance(function)) {
|
||||||
final FunctionLanguageAdaptor la = languageAdaptors.get(c);
|
final FunctionLanguageAdaptor la = languageAdaptors.get(c);
|
||||||
// found the language adaptor so wrap in FuncN and return
|
// found the language adaptor so wrap in FuncN and return
|
||||||
@ -105,10 +98,7 @@ public class Functions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
} // no language adaptor found
|
||||||
}
|
|
||||||
// no language adaptor found
|
|
||||||
}
|
|
||||||
|
|
||||||
// no support found
|
// no support found
|
||||||
throw new RuntimeException("Unsupported closure type: " + function.getClass().getSimpleName());
|
throw new RuntimeException("Unsupported closure type: " + function.getClass().getSimpleName());
|
||||||
@ -213,338 +203,254 @@ public class Functions {
|
|||||||
//
|
//
|
||||||
// throw new RuntimeException("Unknown implementation of Function: " + function.getClass().getSimpleName());
|
// throw new RuntimeException("Unknown implementation of Function: " + function.getClass().getSimpleName());
|
||||||
// }
|
// }
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
|
||||||
private static FuncN fromFunction(Function function) {
|
private static FuncN fromFunction(Function function) {
|
||||||
// check Func* classes
|
// check Func* classes
|
||||||
if (function instanceof Func0) {
|
if (function instanceof Func0)
|
||||||
return fromFunc((Func0) function);
|
return fromFunc((Func0) function);
|
||||||
} else if (function instanceof Func1) {
|
else if (function instanceof Func1)
|
||||||
return fromFunc((Func1) function);
|
return fromFunc((Func1) function);
|
||||||
} else if (function instanceof Func2) {
|
else if (function instanceof Func2)
|
||||||
return fromFunc((Func2) function);
|
return fromFunc((Func2) function);
|
||||||
} else if (function instanceof Func3) {
|
else if (function instanceof Func3)
|
||||||
return fromFunc((Func3) function);
|
return fromFunc((Func3) function);
|
||||||
} else if (function instanceof Func4) {
|
else if (function instanceof Func4)
|
||||||
return fromFunc((Func4) function);
|
return fromFunc((Func4) function);
|
||||||
} else if (function instanceof Func5) {
|
else if (function instanceof Func5)
|
||||||
return fromFunc((Func5) function);
|
return fromFunc((Func5) function);
|
||||||
} else if (function instanceof Func6) {
|
else if (function instanceof Func6)
|
||||||
return fromFunc((Func6) function);
|
return fromFunc((Func6) function);
|
||||||
} else if (function instanceof Func7) {
|
else if (function instanceof Func7)
|
||||||
return fromFunc((Func7) function);
|
return fromFunc((Func7) function);
|
||||||
} else if (function instanceof Func8) {
|
else if (function instanceof Func8)
|
||||||
return fromFunc((Func8) function);
|
return fromFunc((Func8) function);
|
||||||
} else if (function instanceof Func9) {
|
else if (function instanceof Func9)
|
||||||
return fromFunc((Func9) function);
|
return fromFunc((Func9) function);
|
||||||
} else if (function instanceof FuncN) {
|
else if (function instanceof FuncN)
|
||||||
return (FuncN) function;
|
return (FuncN) function;
|
||||||
} else if (function instanceof Action0) {
|
else if (function instanceof Action0)
|
||||||
return fromAction((Action0) function);
|
return fromAction((Action0) function);
|
||||||
} else if (function instanceof Action1) {
|
else if (function instanceof Action1)
|
||||||
return fromAction((Action1) function);
|
return fromAction((Action1) function);
|
||||||
} else if (function instanceof Action2) {
|
else if (function instanceof Action2)
|
||||||
return fromAction((Action2) function);
|
return fromAction((Action2) function);
|
||||||
} else if (function instanceof Action3) {
|
else if (function instanceof Action3)
|
||||||
return fromAction((Action3) function);
|
return fromAction((Action3) function);
|
||||||
}
|
|
||||||
|
|
||||||
throw new RuntimeException("Unknown implementation of Function: " + function.getClass().getSimpleName());
|
throw new RuntimeException("Unknown implementation of Function: " + function.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
|
* Convert a function to FuncN to allow heterogeneous handling of functions
|
||||||
*
|
* with different arities.
|
||||||
|
*
|
||||||
* @param f
|
* @param f
|
||||||
* @return {@link FuncN}
|
* @return {@link FuncN}
|
||||||
*/
|
*/
|
||||||
public static <R> FuncN<R> fromFunc(final Func0<R> f) {
|
public static <R> FuncN<R> fromFunc(final Func0<R> f) {
|
||||||
return new FuncN<R>() {
|
return (Object... args) -> {
|
||||||
|
if (args.length != 0)
|
||||||
@Override
|
throw new RuntimeException("Func0 expecting 0 arguments.");
|
||||||
public R call(Object... args) {
|
return f.call();
|
||||||
if (args.length != 0) {
|
|
||||||
throw new RuntimeException("Func0 expecting 0 arguments.");
|
|
||||||
}
|
|
||||||
return f.call();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
|
* Convert a function to FuncN to allow heterogeneous handling of functions
|
||||||
*
|
* with different arities.
|
||||||
|
*
|
||||||
* @param f
|
* @param f
|
||||||
* @return {@link FuncN}
|
* @return {@link FuncN}
|
||||||
*/
|
*/
|
||||||
public static <T0, R> FuncN<R> fromFunc(final Func1<T0, R> f) {
|
public static <T0, R> FuncN<R> fromFunc(final Func1<T0, R> f) {
|
||||||
return new FuncN<R>() {
|
return (Object... args) -> {
|
||||||
|
if (args.length != 1)
|
||||||
@SuppressWarnings("unchecked")
|
throw new RuntimeException("Func1 expecting 1 argument.");
|
||||||
@Override
|
return f.call((T0) args[0]);
|
||||||
public R call(Object... args) {
|
|
||||||
if (args.length != 1) {
|
|
||||||
throw new RuntimeException("Func1 expecting 1 argument.");
|
|
||||||
}
|
|
||||||
return f.call((T0) args[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
|
* Convert a function to FuncN to allow heterogeneous handling of functions
|
||||||
*
|
* with different arities.
|
||||||
|
*
|
||||||
* @param f
|
* @param f
|
||||||
* @return {@link FuncN}
|
* @return {@link FuncN}
|
||||||
*/
|
*/
|
||||||
public static <T0, T1, R> FuncN<R> fromFunc(final Func2<T0, T1, R> f) {
|
public static <T0, T1, R> FuncN<R> fromFunc(final Func2<T0, T1, R> f) {
|
||||||
return new FuncN<R>() {
|
return (Object... args) -> {
|
||||||
|
if (args.length != 2)
|
||||||
@SuppressWarnings("unchecked")
|
throw new RuntimeException("Func2 expecting 2 arguments.");
|
||||||
@Override
|
return f.call((T0) args[0], (T1) args[1]);
|
||||||
public R call(Object... args) {
|
|
||||||
if (args.length != 2) {
|
|
||||||
throw new RuntimeException("Func2 expecting 2 arguments.");
|
|
||||||
}
|
|
||||||
return f.call((T0) args[0], (T1) args[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
|
* Convert a function to FuncN to allow heterogeneous handling of functions
|
||||||
*
|
* with different arities.
|
||||||
|
*
|
||||||
* @param f
|
* @param f
|
||||||
* @return {@link FuncN}
|
* @return {@link FuncN}
|
||||||
*/
|
*/
|
||||||
public static <T0, T1, T2, R> FuncN<R> fromFunc(final Func3<T0, T1, T2, R> f) {
|
public static <T0, T1, T2, R> FuncN<R> fromFunc(final Func3<T0, T1, T2, R> f) {
|
||||||
return new FuncN<R>() {
|
return (Object... args) -> {
|
||||||
|
if (args.length != 3)
|
||||||
@SuppressWarnings("unchecked")
|
throw new RuntimeException("Func3 expecting 3 arguments.");
|
||||||
@Override
|
return f.call((T0) args[0], (T1) args[1], (T2) args[2]);
|
||||||
public R call(Object... args) {
|
|
||||||
if (args.length != 3) {
|
|
||||||
throw new RuntimeException("Func3 expecting 3 arguments.");
|
|
||||||
}
|
|
||||||
return f.call((T0) args[0], (T1) args[1], (T2) args[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
|
* Convert a function to FuncN to allow heterogeneous handling of functions
|
||||||
*
|
* with different arities.
|
||||||
|
*
|
||||||
* @param f
|
* @param f
|
||||||
* @return {@link FuncN}
|
* @return {@link FuncN}
|
||||||
*/
|
*/
|
||||||
public static <T0, T1, T2, T3, R> FuncN<R> fromFunc(final Func4<T0, T1, T2, T3, R> f) {
|
public static <T0, T1, T2, T3, R> FuncN<R> fromFunc(final Func4<T0, T1, T2, T3, R> f) {
|
||||||
return new FuncN<R>() {
|
return (Object... args) -> {
|
||||||
|
if (args.length != 4)
|
||||||
@SuppressWarnings("unchecked")
|
throw new RuntimeException("Func4 expecting 4 arguments.");
|
||||||
@Override
|
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3]);
|
||||||
public R call(Object... args) {
|
|
||||||
if (args.length != 4) {
|
|
||||||
throw new RuntimeException("Func4 expecting 4 arguments.");
|
|
||||||
}
|
|
||||||
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
|
* Convert a function to FuncN to allow heterogeneous handling of functions
|
||||||
*
|
* with different arities.
|
||||||
|
*
|
||||||
* @param f
|
* @param f
|
||||||
* @return {@link FuncN}
|
* @return {@link FuncN}
|
||||||
*/
|
*/
|
||||||
public static <T0, T1, T2, T3, T4, R> FuncN<R> fromFunc(final Func5<T0, T1, T2, T3, T4, R> f) {
|
public static <T0, T1, T2, T3, T4, R> FuncN<R> fromFunc(final Func5<T0, T1, T2, T3, T4, R> f) {
|
||||||
return new FuncN<R>() {
|
return (Object... args) -> {
|
||||||
|
if (args.length != 5)
|
||||||
@SuppressWarnings("unchecked")
|
throw new RuntimeException("Func5 expecting 5 arguments.");
|
||||||
@Override
|
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4]);
|
||||||
public R call(Object... args) {
|
|
||||||
if (args.length != 5) {
|
|
||||||
throw new RuntimeException("Func5 expecting 5 arguments.");
|
|
||||||
}
|
|
||||||
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4]);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
|
* Convert a function to FuncN to allow heterogeneous handling of functions
|
||||||
*
|
* with different arities.
|
||||||
|
*
|
||||||
* @param f
|
* @param f
|
||||||
* @return {@link FuncN}
|
* @return {@link FuncN}
|
||||||
*/
|
*/
|
||||||
public static <T0, T1, T2, T3, T4, T5, R> FuncN<R> fromFunc(final Func6<T0, T1, T2, T3, T4, T5, R> f) {
|
public static <T0, T1, T2, T3, T4, T5, R> FuncN<R> fromFunc(final Func6<T0, T1, T2, T3, T4, T5, R> f) {
|
||||||
return new FuncN<R>() {
|
return (Object... args) -> {
|
||||||
|
if (args.length != 6)
|
||||||
@SuppressWarnings("unchecked")
|
throw new RuntimeException("Func6 expecting 6 arguments.");
|
||||||
@Override
|
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5]);
|
||||||
public R call(Object... args) {
|
|
||||||
if (args.length != 6) {
|
|
||||||
throw new RuntimeException("Func6 expecting 6 arguments.");
|
|
||||||
}
|
|
||||||
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5]);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
|
* Convert a function to FuncN to allow heterogeneous handling of functions
|
||||||
*
|
* with different arities.
|
||||||
|
*
|
||||||
* @param f
|
* @param f
|
||||||
* @return {@link FuncN}
|
* @return {@link FuncN}
|
||||||
*/
|
*/
|
||||||
public static <T0, T1, T2, T3, T4, T5, T6, R> FuncN<R> fromFunc(final Func7<T0, T1, T2, T3, T4, T5, T6, R> f) {
|
public static <T0, T1, T2, T3, T4, T5, T6, R> FuncN<R> fromFunc(final Func7<T0, T1, T2, T3, T4, T5, T6, R> f) {
|
||||||
return new FuncN<R>() {
|
return (Object... args) -> {
|
||||||
|
if (args.length != 7)
|
||||||
@SuppressWarnings("unchecked")
|
throw new RuntimeException("Func7 expecting 7 arguments.");
|
||||||
@Override
|
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5], (T6) args[6]);
|
||||||
public R call(Object... args) {
|
|
||||||
if (args.length != 7) {
|
|
||||||
throw new RuntimeException("Func7 expecting 7 arguments.");
|
|
||||||
}
|
|
||||||
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5], (T6) args[6]);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
|
* Convert a function to FuncN to allow heterogeneous handling of functions
|
||||||
*
|
* with different arities.
|
||||||
|
*
|
||||||
* @param f
|
* @param f
|
||||||
* @return {@link FuncN}
|
* @return {@link FuncN}
|
||||||
*/
|
*/
|
||||||
public static <T0, T1, T2, T3, T4, T5, T6, T7, R> FuncN<R> fromFunc(final Func8<T0, T1, T2, T3, T4, T5, T6, T7, R> f) {
|
public static <T0, T1, T2, T3, T4, T5, T6, T7, R> FuncN<R> fromFunc(final Func8<T0, T1, T2, T3, T4, T5, T6, T7, R> f) {
|
||||||
return new FuncN<R>() {
|
return (Object... args) -> {
|
||||||
|
if (args.length != 8)
|
||||||
@SuppressWarnings("unchecked")
|
throw new RuntimeException("Func8 expecting 8 arguments.");
|
||||||
@Override
|
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5], (T6) args[6], (T7) args[7]);
|
||||||
public R call(Object... args) {
|
|
||||||
if (args.length != 8) {
|
|
||||||
throw new RuntimeException("Func8 expecting 8 arguments.");
|
|
||||||
}
|
|
||||||
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5], (T6) args[6], (T7) args[7]);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
|
* Convert a function to FuncN to allow heterogeneous handling of functions
|
||||||
*
|
* with different arities.
|
||||||
|
*
|
||||||
* @param f
|
* @param f
|
||||||
* @return {@link FuncN}
|
* @return {@link FuncN}
|
||||||
*/
|
*/
|
||||||
public static <T0, T1, T2, T3, T4, T5, T6, T7, T8, R> FuncN<R> fromFunc(final Func9<T0, T1, T2, T3, T4, T5, T6, T7, T8, R> f) {
|
public static <T0, T1, T2, T3, T4, T5, T6, T7, T8, R> FuncN<R> fromFunc(final Func9<T0, T1, T2, T3, T4, T5, T6, T7, T8, R> f) {
|
||||||
return new FuncN<R>() {
|
return (Object... args) -> {
|
||||||
|
if (args.length != 9)
|
||||||
@SuppressWarnings("unchecked")
|
throw new RuntimeException("Func9 expecting 9 arguments.");
|
||||||
@Override
|
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5], (T6) args[6], (T7) args[7], (T8) args[8]);
|
||||||
public R call(Object... args) {
|
|
||||||
if (args.length != 9) {
|
|
||||||
throw new RuntimeException("Func9 expecting 9 arguments.");
|
|
||||||
}
|
|
||||||
return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5], (T6) args[6], (T7) args[7], (T8) args[8]);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
|
* Convert a function to FuncN to allow heterogeneous handling of functions
|
||||||
*
|
* with different arities.
|
||||||
|
*
|
||||||
* @param f
|
* @param f
|
||||||
* @return {@link FuncN}
|
* @return {@link FuncN}
|
||||||
*/
|
*/
|
||||||
public static FuncN<Void> fromAction(final Action0 f) {
|
public static FuncN<Void> fromAction(final Action0 f) {
|
||||||
return new FuncN<Void>() {
|
return (Object... args) -> {
|
||||||
|
if (args.length != 0)
|
||||||
@Override
|
throw new RuntimeException("Action0 expecting 0 arguments.");
|
||||||
public Void call(Object... args) {
|
f.call();
|
||||||
if (args.length != 0) {
|
return null;
|
||||||
throw new RuntimeException("Action0 expecting 0 arguments.");
|
|
||||||
}
|
|
||||||
f.call();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
|
* Convert a function to FuncN to allow heterogeneous handling of functions
|
||||||
*
|
* with different arities.
|
||||||
|
*
|
||||||
* @param f
|
* @param f
|
||||||
* @return {@link FuncN}
|
* @return {@link FuncN}
|
||||||
*/
|
*/
|
||||||
public static <T0> FuncN<Void> fromAction(final Action1<T0> f) {
|
public static <T0> FuncN<Void> fromAction(final Action1<T0> f) {
|
||||||
return new FuncN<Void>() {
|
return (Object... args) -> {
|
||||||
|
if (args.length != 1)
|
||||||
@SuppressWarnings("unchecked")
|
throw new RuntimeException("Action1 expecting 1 argument.");
|
||||||
@Override
|
f.call((T0) args[0]);
|
||||||
public Void call(Object... args) {
|
return null;
|
||||||
if (args.length != 1) {
|
|
||||||
throw new RuntimeException("Action1 expecting 1 argument.");
|
|
||||||
}
|
|
||||||
f.call((T0) args[0]);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
|
* Convert a function to FuncN to allow heterogeneous handling of functions
|
||||||
*
|
* with different arities.
|
||||||
|
*
|
||||||
* @param f
|
* @param f
|
||||||
* @return {@link FuncN}
|
* @return {@link FuncN}
|
||||||
*/
|
*/
|
||||||
public static <T0, T1> FuncN<Void> fromAction(final Action2<T0, T1> f) {
|
public static <T0, T1> FuncN<Void> fromAction(final Action2<T0, T1> f) {
|
||||||
return new FuncN<Void>() {
|
return (Object... args) -> {
|
||||||
|
if (args.length != 2)
|
||||||
@SuppressWarnings("unchecked")
|
throw new RuntimeException("Action3 expecting 2 arguments.");
|
||||||
@Override
|
f.call((T0) args[0], (T1) args[1]);
|
||||||
public Void call(Object... args) {
|
return null;
|
||||||
if (args.length != 2) {
|
|
||||||
throw new RuntimeException("Action3 expecting 2 arguments.");
|
|
||||||
}
|
|
||||||
f.call((T0) args[0], (T1) args[1]);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a function to FuncN to allow heterogeneous handling of functions with different arities.
|
* Convert a function to FuncN to allow heterogeneous handling of functions
|
||||||
*
|
* with different arities.
|
||||||
|
*
|
||||||
* @param f
|
* @param f
|
||||||
* @return {@link FuncN}
|
* @return {@link FuncN}
|
||||||
*/
|
*/
|
||||||
public static <T0, T1, T2> FuncN<Void> fromAction(final Action3<T0, T1, T2> f) {
|
public static <T0, T1, T2> FuncN<Void> fromAction(final Action3<T0, T1, T2> f) {
|
||||||
return new FuncN<Void>() {
|
return (Object... args) -> {
|
||||||
|
if (args.length != 3)
|
||||||
@SuppressWarnings("unchecked")
|
throw new RuntimeException("Action3 expecting 3 arguments.");
|
||||||
@Override
|
f.call((T0) args[0], (T1) args[1], (T2) args[2]);
|
||||||
public Void call(Object... args) {
|
return null;
|
||||||
if (args.length != 3) {
|
|
||||||
throw new RuntimeException("Action3 expecting 3 arguments.");
|
|
||||||
}
|
|
||||||
f.call((T0) args[0], (T1) args[1], (T2) args[2]);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,12 +63,12 @@ public class Main {
|
|||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
HMCLog.err("There's something wrong when running server holder.", t);
|
HMCLog.err("There's something wrong when running server holder.", t);
|
||||||
|
|
||||||
LogWindow.instance.clean();
|
LogWindow.INSTANCE.clean();
|
||||||
LogWindow.instance.warning("开服器崩溃了QAQ");
|
LogWindow.INSTANCE.warning("开服器崩溃了QAQ");
|
||||||
StringWriter trace = new StringWriter();
|
StringWriter trace = new StringWriter();
|
||||||
t.printStackTrace(new PrintWriter(trace));
|
t.printStackTrace(new PrintWriter(trace));
|
||||||
LogWindow.instance.warning(trace.toString());
|
LogWindow.INSTANCE.warning(trace.toString());
|
||||||
LogWindow.instance.setVisible(true);
|
LogWindow.INSTANCE.setVisible(true);
|
||||||
|
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# Hello Minecraft! Launcher
|
# Hello Minecraft! Launcher
|
||||||
Hello Minecraft! Launcher is a Minecraft launcher.
|
Hello Minecraft! Launcher is a Minecraft launcher.
|
||||||
|
License is GPL v3, see http://www.gnu.org/licenses/.
|
||||||
|
|
||||||
### Joining
|
### Joining
|
||||||
If you really want to join the development, here's some requests.
|
If you really want to join the development, here's some requests.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user