format
This commit is contained in:
@@ -53,10 +53,14 @@ public final class Launcher {
|
||||
ArrayList<String> cmdList = new ArrayList<>();
|
||||
|
||||
for (String s : args)
|
||||
if (s.startsWith("-cp=")) classPath = classPath.concat(s.substring("-cp=".length()));
|
||||
else if (s.startsWith("-mainClass=")) mainClass = s.substring("-mainClass=".length());
|
||||
else if (s.equals("-debug")) showInfo = true;
|
||||
else cmdList.add(s);
|
||||
if (s.startsWith("-cp="))
|
||||
classPath = classPath.concat(s.substring("-cp=".length()));
|
||||
else if (s.startsWith("-mainClass="))
|
||||
mainClass = s.substring("-mainClass=".length());
|
||||
else if (s.equals("-debug"))
|
||||
showInfo = true;
|
||||
else
|
||||
cmdList.add(s);
|
||||
|
||||
String[] tokenized = StrUtils.tokenize(classPath, File.pathSeparator);
|
||||
int len = tokenized.length;
|
||||
@@ -65,7 +69,8 @@ public final class Launcher {
|
||||
LogWindow.instance.setTerminateGame(() -> Utils.shutdownForcely(1));
|
||||
try {
|
||||
File logFile = new File("hmclmc.log");
|
||||
if (!logFile.exists()) logFile.createNewFile();
|
||||
if (!logFile.exists())
|
||||
logFile.createNewFile();
|
||||
FileOutputStream tc = new FileOutputStream(logFile);
|
||||
DoubleOutputStream out = new DoubleOutputStream(tc, System.out);
|
||||
System.setOut(new LauncherPrintStream(out));
|
||||
@@ -112,7 +117,7 @@ public final class Launcher {
|
||||
|
||||
int flag = 0;
|
||||
try {
|
||||
minecraftMain.invoke(null, new Object[]{(String[]) cmdList.toArray(new String[cmdList.size()])});
|
||||
minecraftMain.invoke(null, new Object[] {(String[]) cmdList.toArray(new String[cmdList.size()])});
|
||||
} catch (Throwable throwable) {
|
||||
String trace = StrUtils.getStackTrace(throwable);
|
||||
final String advice = MinecraftCrashAdvicer.getAdvice(trace);
|
||||
|
||||
@@ -91,7 +91,7 @@ public final class Main implements Runnable {
|
||||
|
||||
try {
|
||||
sslContext = SSLContext.getInstance("TLS");
|
||||
X509TrustManager[] xtmArray = new X509TrustManager[]{XTM};
|
||||
X509TrustManager[] xtmArray = new X509TrustManager[] {XTM};
|
||||
sslContext.init(null, xtmArray, new java.security.SecureRandom());
|
||||
} catch (GeneralSecurityException gse) {
|
||||
}
|
||||
@@ -143,9 +143,9 @@ public final class Main implements Runnable {
|
||||
if (mainClass != null) {
|
||||
ArrayList<String> al = new ArrayList<>(Arrays.asList(args));
|
||||
al.add("notfound");
|
||||
new URLClassLoader(new URL[]{jar.toURI().toURL()},
|
||||
new URLClassLoader(new URL[] {jar.toURI().toURL()},
|
||||
URLClassLoader.getSystemClassLoader().getParent()).loadClass(mainClass)
|
||||
.getMethod("main", String[].class).invoke(null, new Object[]{al.toArray(new String[0])});
|
||||
.getMethod("main", String[].class).invoke(null, new Object[] {al.toArray(new String[0])});
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -216,7 +216,7 @@ public final class Main implements Runnable {
|
||||
if (map != null && map.containsKey("pack"))
|
||||
try {
|
||||
if (TaskWindow.getInstance().addTask(new Upgrader(map.get("pack"), Settings.UPDATE_CHECKER.versionString)).start()) {
|
||||
new ProcessBuilder(new String[]{IOUtils.getJavaDir(), "-jar", Upgrader.getSelf(Settings.UPDATE_CHECKER.versionString).getAbsolutePath()}).directory(new File(".")).start();
|
||||
new ProcessBuilder(new String[] {IOUtils.getJavaDir(), "-jar", Upgrader.getSelf(Settings.UPDATE_CHECKER.versionString).getAbsolutePath()}).directory(new File(".")).start();
|
||||
System.exit(0);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
@@ -231,7 +231,8 @@ public final class Main implements Runnable {
|
||||
url = map.get(OS.os().checked_name);
|
||||
else if (map.containsKey(OS.UNKOWN.checked_name))
|
||||
url = map.get(OS.UNKOWN.checked_name);
|
||||
if (url == null) url = C.URL_PUBLISH;
|
||||
if (url == null)
|
||||
url = C.URL_PUBLISH;
|
||||
try {
|
||||
java.awt.Desktop.getDesktop().browse(new URI(url));
|
||||
} catch (URISyntaxException | IOException e) {
|
||||
|
||||
@@ -58,7 +58,7 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
|
||||
HMCLog.log("On making head command.");
|
||||
|
||||
String str = v.getJavaDir();
|
||||
if(!v.getJavaDirFile().exists()) {
|
||||
if (!v.getJavaDirFile().exists()) {
|
||||
MessageBox.Show(C.i18n("launch.wrong_javadir"));
|
||||
v.setJava(null);
|
||||
str = v.getJavaDir();
|
||||
@@ -66,7 +66,8 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
|
||||
JdkVersion jv = new JdkVersion(str);
|
||||
if (Settings.getInstance().getJava().contains(jv))
|
||||
jv = Settings.getInstance().getJava().get(Settings.getInstance().getJava().indexOf(jv));
|
||||
else try {
|
||||
else
|
||||
try {
|
||||
jv = JdkVersion.getJavaVersionFromExecutable(str);
|
||||
Settings.getInstance().getJava().add(jv);
|
||||
Settings.save();
|
||||
@@ -119,7 +120,8 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
|
||||
MessageBox.Show(C.i18n("launch.too_big_memory_alloc_free_space_too_low", a));
|
||||
}
|
||||
String a = "-Xmx" + v.getMaxMemory();
|
||||
if (MathUtils.canParseInt(v.getMaxMemory())) a += "m";
|
||||
if (MathUtils.canParseInt(v.getMaxMemory()))
|
||||
a += "m";
|
||||
res.add(a);
|
||||
}
|
||||
|
||||
@@ -164,9 +166,11 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
|
||||
res.add(args.length > 1 ? args[1] : "25565");
|
||||
}
|
||||
|
||||
if (v.isFullscreen()) res.add("--fullscreen");
|
||||
if (v.isFullscreen())
|
||||
res.add("--fullscreen");
|
||||
|
||||
if (v.isDebug() && !v.isCanceledWrapper()) res.add("-debug");
|
||||
if (v.isDebug() && !v.isCanceledWrapper())
|
||||
res.add("-debug");
|
||||
|
||||
if (StrUtils.isNotBlank(v.getMinecraftArgs()))
|
||||
res.addAll(Arrays.asList(v.getMinecraftArgs().split(" ")));
|
||||
|
||||
@@ -49,13 +49,15 @@ public class DefaultGameLauncher extends GameLauncher {
|
||||
parallelTask.addDependsTask(new LibraryDownloadTask(s));
|
||||
dw.addTask(parallelTask);
|
||||
boolean flag = true;
|
||||
if (t.size() > 0) flag = dw.start();
|
||||
if (t.size() > 0)
|
||||
flag = dw.start();
|
||||
if (!flag && MessageBox.Show(C.i18n("launch.not_finished_downloading_libraries"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
|
||||
flag = true;
|
||||
return flag;
|
||||
});
|
||||
decompressNativesEvent.register((sender, value) -> {
|
||||
if (value == null) return false;
|
||||
if (value == null)
|
||||
return false;
|
||||
for (int i = 0; i < value.decompressFiles.length; i++)
|
||||
try {
|
||||
Compressor.unzip(value.decompressFiles[i], value.decompressTo, value.extractRules[i]);
|
||||
|
||||
@@ -155,7 +155,9 @@ public class GameLauncher {
|
||||
*
|
||||
* @param launcherName the name of launch bat/sh
|
||||
* @param str launch command
|
||||
*
|
||||
* @return launcher location
|
||||
*
|
||||
* @throws java.io.IOException write contents failed.
|
||||
*/
|
||||
public File makeLauncher(String launcherName, List str) throws IOException {
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
||||
|
||||
/**
|
||||
* Provide everything of the Minecraft of a Profile.
|
||||
*
|
||||
* @see org.jackhuang.hellominecraft.launcher.version.MinecraftVersionManager
|
||||
* @author huangyuhui
|
||||
*/
|
||||
@@ -40,14 +41,18 @@ public abstract class IMinecraftProvider {
|
||||
|
||||
/**
|
||||
* Get the run directory of given version.
|
||||
*
|
||||
* @param id the given version name
|
||||
*
|
||||
* @return the run directory
|
||||
*/
|
||||
public abstract File getRunDirectory(String id);
|
||||
|
||||
/**
|
||||
* Get the libraries that need to download.
|
||||
*
|
||||
* @param type where to download
|
||||
*
|
||||
* @return the library collection
|
||||
*/
|
||||
public abstract List<GameLauncher.DownloadLibraryJob> getDownloadLibraries(DownloadType type);
|
||||
@@ -62,6 +67,7 @@ public abstract class IMinecraftProvider {
|
||||
|
||||
/**
|
||||
* Returns the thing like ".minecraft/resourcepacks".
|
||||
*
|
||||
* @return the thing
|
||||
*/
|
||||
public abstract File getResourcePacks();
|
||||
@@ -86,61 +92,76 @@ public abstract class IMinecraftProvider {
|
||||
* @see org.jackhuang.hellominecraft.launcher.launch.IMinecraftLoader
|
||||
* @param p player informations, including username & auth_token
|
||||
* @param type where to download
|
||||
*
|
||||
* @return what you want
|
||||
*
|
||||
* @throws IllegalStateException circular denpendency versions
|
||||
*/
|
||||
public abstract IMinecraftLoader provideMinecraftLoader(UserProfileProvider p, DownloadType type) throws IllegalStateException;
|
||||
|
||||
/**
|
||||
* Rename version
|
||||
*
|
||||
* @param from The old name
|
||||
* @param to The new name
|
||||
*
|
||||
* @return Is the action successful?
|
||||
*/
|
||||
public abstract boolean renameVersion(String from, String to);
|
||||
|
||||
/**
|
||||
* Remove the given version from disk.
|
||||
*
|
||||
* @param a the version name
|
||||
*
|
||||
* @return Is the action successful?
|
||||
*/
|
||||
public abstract boolean removeVersionFromDisk(String a);
|
||||
|
||||
/**
|
||||
* Redownload the Minecraft json of the given version.
|
||||
*
|
||||
* @param a the given version name
|
||||
*
|
||||
* @return Is the action successful?
|
||||
*/
|
||||
public abstract boolean refreshJson(String a);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @return the version
|
||||
*/
|
||||
public abstract MinecraftVersion getOneVersion();
|
||||
|
||||
/**
|
||||
* All Minecraft version in this profile.
|
||||
*
|
||||
* @return the collection of all Minecraft version
|
||||
*/
|
||||
public abstract Collection<MinecraftVersion> getVersions();
|
||||
|
||||
/**
|
||||
* Get the Minecraft json instance of given version.
|
||||
*
|
||||
* @param id the given version name
|
||||
*
|
||||
* @return the Minecraft json instance
|
||||
*/
|
||||
public abstract MinecraftVersion getVersionById(String id);
|
||||
|
||||
/**
|
||||
* getVersions().size()
|
||||
*
|
||||
* @return getVersions().size()
|
||||
*/
|
||||
public abstract int getVersionCount();
|
||||
@@ -152,8 +173,10 @@ public abstract class IMinecraftProvider {
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
@@ -36,7 +36,8 @@ public class LaunchScriptFinisher implements Event<List<String>> {
|
||||
boolean flag = false;
|
||||
try {
|
||||
String s = JOptionPane.showInputDialog(C.i18n("mainwindow.enter_script_name"));
|
||||
if (s != null) MessageBox.Show(C.i18n("mainwindow.make_launch_succeed") + " " + ((GameLauncher) sender).makeLauncher(s, str).getAbsolutePath());
|
||||
if (s != null)
|
||||
MessageBox.Show(C.i18n("mainwindow.make_launch_succeed") + " " + ((GameLauncher) sender).makeLauncher(s, str).getAbsolutePath());
|
||||
flag = true;
|
||||
} catch (IOException ex) {
|
||||
MessageBox.Show(C.i18n("mainwindow.make_launch_script_failed"));
|
||||
|
||||
@@ -67,7 +67,8 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
|
||||
}
|
||||
library += IOUtils.tryGetCanonicalFilePath(provider.getMinecraftJar()) + File.pathSeparator;
|
||||
library = library.substring(0, library.length() - File.pathSeparator.length());
|
||||
if (v.isCanceledWrapper()) res.add("-cp");
|
||||
if (v.isCanceledWrapper())
|
||||
res.add("-cp");
|
||||
res.add(library);
|
||||
String mainClass = version.mainClass;
|
||||
res.add((v.isCanceledWrapper() ? "" : "-mainClass=") + mainClass);
|
||||
@@ -76,12 +77,11 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
|
||||
String[] splitted = org.jackhuang.hellominecraft.utils.StrUtils.tokenize(arg);
|
||||
|
||||
if (!checkAssetsExist())
|
||||
if (MessageBox.Show(C.i18n("assets.no_assets"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
|
||||
if (MessageBox.Show(C.i18n("assets.no_assets"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
|
||||
IAssetsHandler.ASSETS_HANDLER.getList(version, provider, (value) -> {
|
||||
if (value != null)
|
||||
TaskWindow.getInstance().addTask(IAssetsHandler.ASSETS_HANDLER.getDownloadTask(dt.getProvider())).start();
|
||||
});
|
||||
}
|
||||
|
||||
String game_assets = reconstructAssets().getAbsolutePath();
|
||||
|
||||
@@ -133,7 +133,8 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
|
||||
try {
|
||||
AssetsIndex index = (AssetsIndex) C.gson.fromJson(FileUtils.readFileToString(indexFile, "UTF-8"), AssetsIndex.class);
|
||||
|
||||
if (index == null) return false;
|
||||
if (index == null)
|
||||
return false;
|
||||
for (Map.Entry entry : index.getFileMap().entrySet())
|
||||
if (!new File(new File(objectDir, ((AssetsObject) entry.getValue()).getHash().substring(0, 2)), ((AssetsObject) entry.getValue()).getHash()).exists())
|
||||
return false;
|
||||
@@ -159,7 +160,8 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
|
||||
try {
|
||||
AssetsIndex index = (AssetsIndex) C.gson.fromJson(FileUtils.readFileToString(indexFile, "UTF-8"), AssetsIndex.class);
|
||||
|
||||
if (index == null) return assetsDir;
|
||||
if (index == null)
|
||||
return assetsDir;
|
||||
if (index.isVirtual()) {
|
||||
int cnt = 0;
|
||||
HMCLog.log("Reconstructing virtual assets folder at " + virtualRoot);
|
||||
@@ -174,7 +176,8 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
|
||||
}
|
||||
}
|
||||
// If the scale new format existent file is lower then 0.1, use the old format.
|
||||
if (cnt * 10 < tot) return assetsDir;
|
||||
if (cnt * 10 < tot)
|
||||
return assetsDir;
|
||||
}
|
||||
} catch (IOException | JsonSyntaxException e) {
|
||||
HMCLog.warn("Failed to create virutal assets.", e);
|
||||
|
||||
@@ -67,7 +67,8 @@ public final class Profile {
|
||||
|
||||
public Profile(Profile v) {
|
||||
this();
|
||||
if (v == null) return;
|
||||
if (v == null)
|
||||
return;
|
||||
name = v.name;
|
||||
gameDir = v.gameDir;
|
||||
maxMemory = v.maxMemory;
|
||||
@@ -89,25 +90,30 @@ public final class Profile {
|
||||
}
|
||||
|
||||
public IMinecraftProvider getMinecraftProvider() {
|
||||
if (minecraftProvider == null) minecraftProvider = new MinecraftVersionManager(this);
|
||||
if (minecraftProvider == null)
|
||||
minecraftProvider = new MinecraftVersionManager(this);
|
||||
return minecraftProvider;
|
||||
}
|
||||
|
||||
public MinecraftVersion getSelectedMinecraftVersion() {
|
||||
if (StrUtils.isBlank(selectedMinecraftVersion)) {
|
||||
MinecraftVersion v = getMinecraftProvider().getOneVersion();
|
||||
if (v == null) return null;
|
||||
if (v == null)
|
||||
return null;
|
||||
selectedMinecraftVersion = v.id;
|
||||
return v;
|
||||
}
|
||||
MinecraftVersion v = getMinecraftProvider().getVersionById(selectedMinecraftVersion);
|
||||
if (v == null) v = getMinecraftProvider().getOneVersion();
|
||||
if (v != null) setSelectedMinecraftVersion(v.id);
|
||||
if (v == null)
|
||||
v = getMinecraftProvider().getOneVersion();
|
||||
if (v != null)
|
||||
setSelectedMinecraftVersion(v.id);
|
||||
return v;
|
||||
}
|
||||
|
||||
public String getGameDir() {
|
||||
if (StrUtils.isBlank(gameDir)) gameDir = MCUtils.getInitGameDir().getPath();
|
||||
if (StrUtils.isBlank(gameDir))
|
||||
gameDir = MCUtils.getInitGameDir().getPath();
|
||||
return IOUtils.addSeparator(gameDir);
|
||||
}
|
||||
|
||||
@@ -132,8 +138,10 @@ public final class Profile {
|
||||
|
||||
public String getJavaDir() {
|
||||
Java j = getJava();
|
||||
if (j.getHome() == null) return javaDir;
|
||||
else return j.getJava();
|
||||
if (j.getHome() == null)
|
||||
return javaDir;
|
||||
else
|
||||
return j.getJava();
|
||||
}
|
||||
|
||||
public String getSettingsJavaDir() {
|
||||
@@ -169,14 +177,16 @@ public final class Profile {
|
||||
this.java = Settings.JAVA.get(0).getName();
|
||||
else {
|
||||
int idx = Settings.JAVA.indexOf(java);
|
||||
if (idx == -1) return;
|
||||
if (idx == -1)
|
||||
return;
|
||||
this.java = java.getName();
|
||||
}
|
||||
Settings.save();
|
||||
}
|
||||
|
||||
public File getFolder(String folder) {
|
||||
if (getSelectedMinecraftVersion() == null) return new File(getCanonicalGameDirFile(), folder);
|
||||
if (getSelectedMinecraftVersion() == null)
|
||||
return new File(getCanonicalGameDirFile(), folder);
|
||||
return new File(getMinecraftProvider().getRunDirectory(getSelectedMinecraftVersion().id), folder);
|
||||
}
|
||||
|
||||
@@ -193,7 +203,8 @@ public final class Profile {
|
||||
}
|
||||
|
||||
public String getJavaArgs() {
|
||||
if (StrUtils.isBlank(javaArgs)) return "";
|
||||
if (StrUtils.isBlank(javaArgs))
|
||||
return "";
|
||||
return javaArgs;
|
||||
}
|
||||
|
||||
@@ -207,7 +218,8 @@ public final class Profile {
|
||||
}
|
||||
|
||||
public String getMaxMemory() {
|
||||
if (StrUtils.isBlank(maxMemory)) return String.valueOf(Utils.getSuggestedMemorySize());
|
||||
if (StrUtils.isBlank(maxMemory))
|
||||
return String.valueOf(Utils.getSuggestedMemorySize());
|
||||
return maxMemory;
|
||||
}
|
||||
|
||||
@@ -217,7 +229,8 @@ public final class Profile {
|
||||
}
|
||||
|
||||
public String getWidth() {
|
||||
if (StrUtils.isBlank(width)) return "854";
|
||||
if (StrUtils.isBlank(width))
|
||||
return "854";
|
||||
return width;
|
||||
}
|
||||
|
||||
@@ -226,7 +239,8 @@ public final class Profile {
|
||||
}
|
||||
|
||||
public String getHeight() {
|
||||
if (StrUtils.isBlank(height)) return "480";
|
||||
if (StrUtils.isBlank(height))
|
||||
return "480";
|
||||
return height;
|
||||
}
|
||||
|
||||
@@ -236,7 +250,8 @@ public final class Profile {
|
||||
}
|
||||
|
||||
public String getUserProperties() {
|
||||
if (userProperties == null) return "";
|
||||
if (userProperties == null)
|
||||
return "";
|
||||
return userProperties;
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,8 @@ public final class Settings {
|
||||
HMCLog.log("Settings file is empty, use the default settings.");
|
||||
else {
|
||||
Config d = C.gsonPrettyPrinting.fromJson(str, Config.class);
|
||||
if (d != null) c = d;
|
||||
if (d != null)
|
||||
c = d;
|
||||
}
|
||||
HMCLog.log("Initialized settings.");
|
||||
} catch (IOException | JsonSyntaxException e) {
|
||||
|
||||
@@ -60,7 +60,7 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
|
||||
t.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
} else if(s.contains("java.lang.NoClassDefFoundError") || s.contains("java.lang.IncompatibleClassChangeError") || s.contains("java.lang.ClassFormatError")) {
|
||||
} else if (s.contains("java.lang.NoClassDefFoundError") || s.contains("java.lang.IncompatibleClassChangeError") || s.contains("java.lang.ClassFormatError")) {
|
||||
System.out.println(C.i18n("crash.NoClassDefFound"));
|
||||
try {
|
||||
MessageBox.Show(C.i18n("crash.NoClassDefFound"));
|
||||
@@ -68,7 +68,7 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
|
||||
t.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
} else if(s.contains("java.lang.OutOfMemoryError")) {
|
||||
} else if (s.contains("java.lang.OutOfMemoryError")) {
|
||||
System.out.println("FUCKING MEMORY LIMIT!");
|
||||
return false;
|
||||
}
|
||||
@@ -78,7 +78,8 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
|
||||
@Override
|
||||
public void uncaughtException(Thread t, Throwable e) {
|
||||
String s = StrUtils.getStackTrace(e);
|
||||
if (!s.contains("org.jackhuang.hellominecraft")) return;
|
||||
if (!s.contains("org.jackhuang.hellominecraft"))
|
||||
return;
|
||||
try {
|
||||
String text = "\n---- Hello Minecraft! Crash Report ----\n";
|
||||
text += " Version: " + Main.makeVersion() + "\n";
|
||||
@@ -90,8 +91,10 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
|
||||
text += " Operating System: " + System.getProperty("os.name") + " (" + System.getProperty("os.arch") + ") version " + System.getProperty("os.version") + "\n";
|
||||
text += " Java Version: " + System.getProperty("java.version") + ", " + System.getProperty("java.vendor") + "\n";
|
||||
text += " Java VM Version: " + System.getProperty("java.vm.name") + " (" + System.getProperty("java.vm.info") + "), " + System.getProperty("java.vm.vendor") + "\n";
|
||||
if (enableLogger) HMCLog.err(text);
|
||||
else System.out.println(text);
|
||||
if (enableLogger)
|
||||
HMCLog.err(text);
|
||||
else
|
||||
System.out.println(text);
|
||||
|
||||
if (checkThrowable(e)) {
|
||||
SwingUtilities.invokeLater(() -> LogWindow.instance.showAsCrashWindow(UpdateChecker.OUT_DATED));
|
||||
@@ -111,7 +114,8 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
|
||||
private static final HashSet<String> throwableSet = new HashSet<>();
|
||||
|
||||
void reportToServer(String text, String stacktrace) {
|
||||
if (throwableSet.contains(stacktrace)) return;
|
||||
if (throwableSet.contains(stacktrace))
|
||||
return;
|
||||
throwableSet.add(stacktrace);
|
||||
new Thread(() -> {
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
|
||||
@@ -131,7 +131,8 @@ public final class MCUtils {
|
||||
return r;
|
||||
}
|
||||
int k = i;
|
||||
while (tmp[k] >= 48 && tmp[k] <= 57 || tmp[k] == 46) k--;
|
||||
while (tmp[k] >= 48 && tmp[k] <= 57 || tmp[k] == 46)
|
||||
k--;
|
||||
k++;
|
||||
r.version = new String(tmp, k, i - k + 1);
|
||||
}
|
||||
@@ -214,7 +215,8 @@ public final class MCUtils {
|
||||
}
|
||||
|
||||
public static String minecraft() {
|
||||
if (OS.os() == OS.OSX) return "minecraft";
|
||||
if (OS.os() == OS.OSX)
|
||||
return "minecraft";
|
||||
return ".minecraft";
|
||||
}
|
||||
|
||||
@@ -224,7 +226,8 @@ public final class MCUtils {
|
||||
gameDir = new File(gameDir, MCUtils.minecraft());
|
||||
if (!gameDir.exists()) {
|
||||
File newFile = MCUtils.getLocation();
|
||||
if (newFile.exists()) gameDir = newFile;
|
||||
if (newFile.exists())
|
||||
gameDir = newFile;
|
||||
}
|
||||
}
|
||||
return gameDir;
|
||||
@@ -246,7 +249,7 @@ public final class MCUtils {
|
||||
MinecraftVersion mv;
|
||||
try {
|
||||
mv = C.gson.fromJson(FileUtils.readFileToStringQuietly(mvt), MinecraftVersion.class);
|
||||
} catch(JsonSyntaxException ex) {
|
||||
} catch (JsonSyntaxException ex) {
|
||||
HMCLog.err("Failed to parse minecraft version json.", ex);
|
||||
mv = null;
|
||||
}
|
||||
|
||||
@@ -67,10 +67,12 @@ public class ModInfo implements Comparable<ModInfo> {
|
||||
}
|
||||
|
||||
public static boolean isFileMod(File file) {
|
||||
if (file == null) return false;
|
||||
if (file == null)
|
||||
return false;
|
||||
String name = file.getName();
|
||||
boolean disabled = name.endsWith(".disabled");
|
||||
if (disabled) name = name.substring(0, name.length() - ".disabled".length());
|
||||
if (disabled)
|
||||
name = name.substring(0, name.length() - ".disabled".length());
|
||||
return name.endsWith(".zip") || name.endsWith(".jar");
|
||||
}
|
||||
|
||||
@@ -80,11 +82,15 @@ public class ModInfo implements Comparable<ModInfo> {
|
||||
try {
|
||||
ZipFile jar = new ZipFile(f);
|
||||
ZipEntry entry = jar.getEntry("mcmod.info");
|
||||
if (entry == null) return i;
|
||||
if (entry == null)
|
||||
return i;
|
||||
else {
|
||||
List<ModInfo> m = C.gson.fromJson(new InputStreamReader(jar.getInputStream(entry)), new TypeToken<List<ModInfo>>() {
|
||||
}.getType());
|
||||
if (m != null && m.size() > 0) { i = m.get(0); i.location = f; }
|
||||
if (m != null && m.size() > 0) {
|
||||
i = m.get(0);
|
||||
i.location = f;
|
||||
}
|
||||
}
|
||||
jar.close();
|
||||
return i;
|
||||
|
||||
@@ -107,7 +107,8 @@ public class AssetsMojangLoader extends IAssetsHandler {
|
||||
@Override
|
||||
public boolean isVersionAllowed(String formattedVersion) {
|
||||
VersionNumber ur = VersionNumber.check(formattedVersion);
|
||||
if (ur == null) return false;
|
||||
if (ur == null)
|
||||
return false;
|
||||
return VersionNumber.check("1.6.0").compareTo(ur) <= 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,8 @@ public class AssetsMojangOldLoader extends IAssetsHandler {
|
||||
@Override
|
||||
public boolean isVersionAllowed(String formattedVersion) {
|
||||
VersionNumber r = VersionNumber.check(formattedVersion);
|
||||
if (r == null) return false;
|
||||
if (r == null)
|
||||
return false;
|
||||
return VersionNumber.check("1.7.2").compareTo(r) >= 0
|
||||
&& VersionNumber.check("1.6.0").compareTo(r) <= 0;
|
||||
}
|
||||
|
||||
@@ -38,10 +38,13 @@ public class AssetsObject {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
AssetsObject that = (AssetsObject) o;
|
||||
if (this.size != that.size) return false;
|
||||
if (this.size != that.size)
|
||||
return false;
|
||||
return this.hash.equals(that.hash);
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +78,7 @@ public abstract class IAssetsHandler {
|
||||
* Will be invoked when the user invoked "Download all assets".
|
||||
*
|
||||
* @param sourceType Download Source
|
||||
*
|
||||
* @return Download File Task
|
||||
*/
|
||||
public abstract Task getDownloadTask(IDownloadProvider sourceType);
|
||||
@@ -106,8 +107,10 @@ public abstract class IAssetsHandler {
|
||||
String mark = assetsDownloadURLs.get(i);
|
||||
String url = u + mark;
|
||||
File location = assetsLocalNames.get(i);
|
||||
if (!location.getParentFile().exists()) location.getParentFile().mkdirs();
|
||||
if (location.isDirectory()) continue;
|
||||
if (!location.getParentFile().exists())
|
||||
location.getParentFile().mkdirs();
|
||||
if (location.isDirectory())
|
||||
continue;
|
||||
boolean need = true;
|
||||
try {
|
||||
if (location.exists()) {
|
||||
@@ -126,7 +129,8 @@ public abstract class IAssetsHandler {
|
||||
HMCLog.warn("Failed to get hash: " + location, e);
|
||||
need = !location.exists();
|
||||
}
|
||||
if (need) al.add(new FileDownloadTask(url, location).setTag(mark));
|
||||
if (need)
|
||||
al.add(new FileDownloadTask(url, location).setTag(mark));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ public abstract class IAuthenticator {
|
||||
* Login Method
|
||||
*
|
||||
* @param info username & password
|
||||
*
|
||||
* @return login result
|
||||
*/
|
||||
public abstract UserProfileProvider login(LoginInfo info);
|
||||
|
||||
@@ -61,12 +61,12 @@ public final class SkinmeAuthenticator extends IAuthenticator {
|
||||
String hashCode = DigestUtils.sha1Hex(DigestUtils.md5Hex(DigestUtils.sha1Hex(pwd) + pwd) + str);
|
||||
String data = getCharacter(usr, hashCode, null);
|
||||
String[] sl = data.split(":");
|
||||
if (null != sl[0]) switch (sl[0]) {
|
||||
if (null != sl[0])
|
||||
switch (sl[0]) {
|
||||
case "0":
|
||||
req.setSuccess(false);
|
||||
if(sl[1].contains("No Valid Character")) {
|
||||
if (sl[1].contains("No Valid Character"))
|
||||
sl[1] = C.i18n("login.no_valid_character");
|
||||
}
|
||||
req.setErrorReason(sl[1]);
|
||||
break;
|
||||
case "1": {
|
||||
|
||||
@@ -70,7 +70,8 @@ public final class YggdrasilAuthenticator extends IAuthenticator {
|
||||
ua.setUsername(usr);
|
||||
try {
|
||||
ua.logIn();
|
||||
if (!ua.isLoggedIn()) throw new Exception(C.i18n("login.wrong_password"));
|
||||
if (!ua.isLoggedIn())
|
||||
throw new Exception(C.i18n("login.wrong_password"));
|
||||
GameProfile selectedProfile = ua.getSelectedProfile();
|
||||
GameProfile[] profiles = ua.getAvailableProfiles();
|
||||
String[] names;
|
||||
@@ -94,7 +95,8 @@ public final class YggdrasilAuthenticator extends IAuthenticator {
|
||||
result.setUserProperties(new GsonBuilder().registerTypeAdapter(PropertyMap.class, new PropertyMap.LegacySerializer()).create().toJson(ua.getUserProperties()));
|
||||
result.setUserPropertyMap(new GsonBuilder().registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create().toJson(ua.getUserProperties()));
|
||||
String authToken = ua.getAuthenticatedToken();
|
||||
if (authToken == null) authToken = "0";
|
||||
if (authToken == null)
|
||||
authToken = "0";
|
||||
result.setAccessToken(authToken);
|
||||
result.setSession(authToken);
|
||||
} catch (Exception ex) {
|
||||
@@ -123,7 +125,8 @@ public final class YggdrasilAuthenticator extends IAuthenticator {
|
||||
}
|
||||
|
||||
public void onLoadSettings(Map settings) {
|
||||
if (settings == null) return;
|
||||
if (settings == null)
|
||||
return;
|
||||
ua.loadFromStorage(settings);
|
||||
}
|
||||
|
||||
@@ -132,7 +135,8 @@ public final class YggdrasilAuthenticator extends IAuthenticator {
|
||||
UserProfileProvider info = new UserProfileProvider();
|
||||
try {
|
||||
ua.logIn();
|
||||
if (!ua.isLoggedIn()) throw new Exception(C.i18n("login.wrong_password"));
|
||||
if (!ua.isLoggedIn())
|
||||
throw new Exception(C.i18n("login.wrong_password"));
|
||||
GameProfile profile = ua.getSelectedProfile();
|
||||
info.setUserName(profile.name);
|
||||
info.setSuccess(true);
|
||||
|
||||
@@ -48,7 +48,6 @@ public class YggdrasilAuthentication {
|
||||
}
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Get/Set">
|
||||
|
||||
public void setUsername(String username) {
|
||||
if ((isLoggedIn()) && (canPlayOnline()))
|
||||
throw new IllegalStateException("Cannot change username while logged in & online");
|
||||
@@ -120,7 +119,7 @@ public class YggdrasilAuthentication {
|
||||
@Deprecated
|
||||
public String getSessionToken() {
|
||||
if (isLoggedIn() && getSelectedProfile() != null && canPlayOnline())
|
||||
return String.format("token:%s:%s", new Object[]{getAuthenticatedToken(), getSelectedProfile().id});
|
||||
return String.format("token:%s:%s", new Object[] {getAuthenticatedToken(), getSelectedProfile().id});
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -129,9 +128,7 @@ public class YggdrasilAuthentication {
|
||||
}
|
||||
|
||||
// </editor-fold>
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Log In/Out">
|
||||
|
||||
public boolean canPlayOnline() {
|
||||
return isLoggedIn() && getSelectedProfile() != null && this.isOnline;
|
||||
}
|
||||
@@ -209,7 +206,6 @@ public class YggdrasilAuthentication {
|
||||
// </editor-fold>
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Settings Storage">
|
||||
|
||||
public void loadFromStorage(Map<String, Object> credentials) {
|
||||
logOut();
|
||||
|
||||
@@ -259,7 +255,6 @@ public class YggdrasilAuthentication {
|
||||
}
|
||||
|
||||
// </editor-fold>
|
||||
|
||||
protected Response request(URL url, Object input) throws AuthenticationException {
|
||||
try {
|
||||
String jsonResult = input == null ? NetUtils.doGet(url) : NetUtils.post(url, GSON.toJson(input), "application/json", proxy);
|
||||
|
||||
@@ -42,9 +42,12 @@ public class BMCLAPIDownloadProvider implements IDownloadProvider {
|
||||
|
||||
@Override
|
||||
public InstallerVersionList getInstallerByType(String type) {
|
||||
if (type.equalsIgnoreCase("forge")) return getForgeInstaller();
|
||||
if (type.equalsIgnoreCase("liteloader")) return getLiteLoaderInstaller();
|
||||
if (type.equalsIgnoreCase("optifine")) return getOptiFineInstaller();
|
||||
if (type.equalsIgnoreCase("forge"))
|
||||
return getForgeInstaller();
|
||||
if (type.equalsIgnoreCase("liteloader"))
|
||||
return getLiteLoaderInstaller();
|
||||
if (type.equalsIgnoreCase("optifine"))
|
||||
return getOptiFineInstaller();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,9 +41,12 @@ public class MojangDownloadProvider implements IDownloadProvider {
|
||||
|
||||
@Override
|
||||
public InstallerVersionList getInstallerByType(String type) {
|
||||
if (type.equalsIgnoreCase("forge")) return getForgeInstaller();
|
||||
if (type.equalsIgnoreCase("liteloader")) return getLiteLoaderInstaller();
|
||||
if (type.equalsIgnoreCase("optifine")) return getOptiFineInstaller();
|
||||
if (type.equalsIgnoreCase("forge"))
|
||||
return getForgeInstaller();
|
||||
if (type.equalsIgnoreCase("liteloader"))
|
||||
return getLiteLoaderInstaller();
|
||||
if (type.equalsIgnoreCase("optifine"))
|
||||
return getOptiFineInstaller();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,5 +52,4 @@ public class RapidDataDownloadProvider extends MojangDownloadProvider {
|
||||
return str == null ? null : str.replace("http://files.minecraftforge.net/maven", "http://mirrors.rapiddata.org/forge/maven");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ public abstract class InstallerVersionList implements Consumer<String[]> {
|
||||
* Refresh installer versions list from the downloaded content.
|
||||
*
|
||||
* @param versions Minecraft versions you need to refresh
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
public abstract void refreshList(String[] versions) throws Exception;
|
||||
|
||||
@@ -40,7 +40,8 @@ public class PackMinecraftInstaller {
|
||||
public void install() throws IOException {
|
||||
File file = new File(IOUtils.currentDir(), "HMCL-MERGE-TEMP");
|
||||
file.mkdirs();
|
||||
for (String src1 : src) Compressor.unzip(new File(src1), file);
|
||||
for (String src1 : src)
|
||||
Compressor.unzip(new File(src1), file);
|
||||
Compressor.zip(file, dest);
|
||||
FileUtils.deleteDirectory(file);
|
||||
}
|
||||
|
||||
@@ -98,7 +98,8 @@ public class ForgeInstaller extends Task {
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
BufferedOutputStream bos = new BufferedOutputStream(fos);
|
||||
int c;
|
||||
while ((c = is.read()) != -1) bos.write((byte) c);
|
||||
while ((c = is.read()) != -1)
|
||||
bos.write((byte) c);
|
||||
bos.close();
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -39,7 +39,8 @@ public class ForgeBMCLVersionList extends InstallerVersionList {
|
||||
private static ForgeBMCLVersionList instance;
|
||||
|
||||
public static ForgeBMCLVersionList getInstance() {
|
||||
if (instance == null) instance = new ForgeBMCLVersionList();
|
||||
if (instance == null)
|
||||
instance = new ForgeBMCLVersionList();
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -55,7 +56,8 @@ public class ForgeBMCLVersionList extends InstallerVersionList {
|
||||
}
|
||||
|
||||
for (String x : neededVersions) {
|
||||
if (versionMap.containsKey(x)) continue;
|
||||
if (versionMap.containsKey(x))
|
||||
continue;
|
||||
String s = NetUtils.doGet("http://bmclapi2.bangbang93.com/forge/minecraft/" + x);
|
||||
|
||||
if (s == null)
|
||||
@@ -83,10 +85,13 @@ public class ForgeBMCLVersionList extends InstallerVersionList {
|
||||
|
||||
@Override
|
||||
public List<InstallerVersion> getVersions(String mcVersion) {
|
||||
if (versions == null || versionMap == null) return null;
|
||||
if (StrUtils.isBlank(mcVersion)) return versions;
|
||||
if (versions == null || versionMap == null)
|
||||
return null;
|
||||
if (StrUtils.isBlank(mcVersion))
|
||||
return versions;
|
||||
List c = versionMap.get(mcVersion);
|
||||
if (c == null) return versions;
|
||||
if (c == null)
|
||||
return versions;
|
||||
Collections.sort(c, InstallerVersionComparator.INSTANCE);
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,8 @@ public class MinecraftForgeVersionList extends InstallerVersionList {
|
||||
@Override
|
||||
public void refreshList(String[] needed) throws Exception {
|
||||
String s = NetUtils.doGet(Settings.getInstance().getDownloadSource().getProvider().getParsedLibraryDownloadURL(C.URL_FORGE_LIST));
|
||||
if (root != null) return;
|
||||
if (root != null)
|
||||
return;
|
||||
|
||||
root = C.gson.fromJson(s, MinecraftForgeVersionRoot.class);
|
||||
|
||||
@@ -96,10 +97,13 @@ public class MinecraftForgeVersionList extends InstallerVersionList {
|
||||
|
||||
@Override
|
||||
public List<InstallerVersion> getVersions(String mcVersion) {
|
||||
if (versions == null || versionMap == null) return null;
|
||||
if (StrUtils.isBlank(mcVersion)) return versions;
|
||||
if (versions == null || versionMap == null)
|
||||
return null;
|
||||
if (StrUtils.isBlank(mcVersion))
|
||||
return versions;
|
||||
List c = versionMap.get(mcVersion);
|
||||
if (c == null) return versions;
|
||||
if (c == null)
|
||||
return versions;
|
||||
Collections.sort(c, InstallerVersionComparator.INSTANCE);
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,8 @@ public class LiteLoaderInstaller extends Task implements PreviousResultRegistrar
|
||||
setFailReason(new RuntimeException(C.i18n("install.no_version")));
|
||||
return false;
|
||||
}
|
||||
if (pre.size() != 1 && installer == null) throw new IllegalStateException("No registered previous task.");
|
||||
if (pre.size() != 1 && installer == null)
|
||||
throw new IllegalStateException("No registered previous task.");
|
||||
if (installer == null)
|
||||
installer = pre.get(pre.size() - 1).getResult();
|
||||
try {
|
||||
|
||||
@@ -51,7 +51,8 @@ public class LiteLoaderVersionList extends InstallerVersionList {
|
||||
@Override
|
||||
public void refreshList(String[] needed) throws Exception {
|
||||
String s = NetUtils.doGet(C.URL_LITELOADER_LIST);
|
||||
if (root != null) return;
|
||||
if (root != null)
|
||||
return;
|
||||
|
||||
root = C.gson.fromJson(s, LiteLoaderVersionsRoot.class);
|
||||
|
||||
@@ -62,7 +63,8 @@ public class LiteLoaderVersionList extends InstallerVersionList {
|
||||
ArrayList<InstallerVersion> al = new ArrayList<>();
|
||||
LiteLoaderMCVersions mcv = arr.getValue();
|
||||
for (Map.Entry<String, LiteLoaderVersion> entry : mcv.artefacts.get("com.mumfrey:liteloader").entrySet()) {
|
||||
if ("latest".equals(entry.getKey())) continue;
|
||||
if ("latest".equals(entry.getKey()))
|
||||
continue;
|
||||
LiteLoaderVersion v = entry.getValue();
|
||||
LiteLoaderInstallerVersion iv = new LiteLoaderInstallerVersion(v.version, StrUtils.formatVersion(arr.getKey()));
|
||||
iv.universal = "http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + arr.getKey() + "/" + v.file;
|
||||
@@ -81,10 +83,13 @@ public class LiteLoaderVersionList extends InstallerVersionList {
|
||||
|
||||
@Override
|
||||
public List<InstallerVersion> getVersions(String mcVersion) {
|
||||
if (versions == null || versionMap == null) return null;
|
||||
if (StrUtils.isBlank(mcVersion)) return versions;
|
||||
if (versions == null || versionMap == null)
|
||||
return null;
|
||||
if (StrUtils.isBlank(mcVersion))
|
||||
return versions;
|
||||
List c = versionMap.get(mcVersion);
|
||||
if (c == null) return versions;
|
||||
if (c == null)
|
||||
return versions;
|
||||
Collections.sort(c, InstallerVersionComparator.INSTANCE);
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -21,5 +21,6 @@ package org.jackhuang.hellominecraft.launcher.utils.installers.optifine;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class OptiFineVersion {
|
||||
|
||||
public String dl, ver, date, mirror, mcver;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,8 @@ public class OptiFineBMCLVersionList extends InstallerVersionList {
|
||||
versionMap = new HashMap<>();
|
||||
versions = new ArrayList<>();
|
||||
|
||||
if (s == null) return;
|
||||
if (s == null)
|
||||
return;
|
||||
root = C.gson.fromJson(s, new TypeToken<ArrayList<OptiFineVersion>>() {
|
||||
}.getType());
|
||||
for (OptiFineVersion v : root) {
|
||||
@@ -65,7 +66,8 @@ public class OptiFineBMCLVersionList extends InstallerVersionList {
|
||||
if (StrUtils.isBlank(v.mcver)) {
|
||||
Pattern p = Pattern.compile("OptiFine (.*) HD");
|
||||
Matcher m = p.matcher(v.ver);
|
||||
while (m.find()) v.mcver = m.group(1);
|
||||
while (m.find())
|
||||
v.mcver = m.group(1);
|
||||
}
|
||||
InstallerVersion iv = new InstallerVersion(v.ver, StrUtils.formatVersion(v.mcver));
|
||||
|
||||
@@ -81,10 +83,13 @@ public class OptiFineBMCLVersionList extends InstallerVersionList {
|
||||
|
||||
@Override
|
||||
public List<InstallerVersion> getVersions(String mcVersion) {
|
||||
if (versions == null || versionMap == null) return null;
|
||||
if (StrUtils.isBlank(mcVersion)) return versions;
|
||||
if (versions == null || versionMap == null)
|
||||
return null;
|
||||
if (StrUtils.isBlank(mcVersion))
|
||||
return versions;
|
||||
List c = versionMap.get(mcVersion);
|
||||
if (c == null) return versions;
|
||||
if (c == null)
|
||||
return versions;
|
||||
Collections.sort(c, InstallerVersionComparator.INSTANCE);
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,8 @@ public class OptiFineDownloadFormatter extends Task implements PreviousResult<St
|
||||
String content = NetUtils.doGet(url);
|
||||
Pattern p = Pattern.compile("\"downloadx\\?f=OptiFine(.*)\"");
|
||||
Matcher m = p.matcher(content);
|
||||
while (m.find()) result = m.group(1);
|
||||
while (m.find())
|
||||
result = m.group(1);
|
||||
result = "http://optifine.net/downloadx?f=OptiFine" + result;
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
|
||||
@@ -60,7 +60,8 @@ public class OptiFineVersionList extends InstallerVersionList {
|
||||
@Override
|
||||
public void refreshList(String[] sss) throws Exception {
|
||||
String content = NetUtils.doGet("http://optifine.net/downloads");
|
||||
if (versions != null) return;
|
||||
if (versions != null)
|
||||
return;
|
||||
versionMap = new HashMap<>();
|
||||
versions = new ArrayList<>();
|
||||
|
||||
@@ -93,7 +94,8 @@ public class OptiFineVersionList extends InstallerVersionList {
|
||||
if (StrUtils.isBlank(v.mcver)) {
|
||||
Pattern p = Pattern.compile("OptiFine (.*?) ");
|
||||
Matcher m = p.matcher(v.ver);
|
||||
while (m.find()) v.mcver = StrUtils.formatVersion(m.group(1));
|
||||
while (m.find())
|
||||
v.mcver = StrUtils.formatVersion(m.group(1));
|
||||
}
|
||||
InstallerVersion iv = new InstallerVersion(v.ver, StrUtils.formatVersion(v.mcver));
|
||||
iv.installer = iv.universal = v.mirror;
|
||||
@@ -119,10 +121,13 @@ public class OptiFineVersionList extends InstallerVersionList {
|
||||
|
||||
@Override
|
||||
public List<InstallerVersion> getVersions(String mcVersion) {
|
||||
if (versions == null || versionMap == null) return null;
|
||||
if (StrUtils.isBlank(mcVersion)) return versions;
|
||||
if (versions == null || versionMap == null)
|
||||
return null;
|
||||
if (StrUtils.isBlank(mcVersion))
|
||||
return versions;
|
||||
List c = versionMap.get(mcVersion);
|
||||
if (c == null) return versions;
|
||||
if (c == null)
|
||||
return versions;
|
||||
Collections.sort(c, InstallerVersionComparator.INSTANCE);
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -64,9 +64,11 @@ public class Upgrader extends Task {
|
||||
HashMap<String, String> json = new HashMap<>();
|
||||
File f = getSelf(newestVersion);
|
||||
try {
|
||||
if (!f.getParentFile().exists()) f.getParentFile().mkdirs();
|
||||
if (!f.getParentFile().exists())
|
||||
f.getParentFile().mkdirs();
|
||||
|
||||
for (int i = 0; f.exists(); i++) f = new File(BASE_FOLDER, "HMCL-" + newestVersion + (i > 0 ? "-" + i : "") + ".jar");
|
||||
for (int i = 0; f.exists(); i++)
|
||||
f = new File(BASE_FOLDER, "HMCL-" + newestVersion + (i > 0 ? "-" + i : "") + ".jar");
|
||||
f.createNewFile();
|
||||
|
||||
try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(f))) {
|
||||
|
||||
@@ -121,8 +121,10 @@ public class MinecraftLibrary extends IMinecraftLibrary {
|
||||
|
||||
@Override
|
||||
public String getDownloadURL(String urlBase, DownloadType downloadType) {
|
||||
if (StrUtils.isNotBlank(url) && downloadType.getProvider().isAllowedToUseSelfURL()) urlBase = this.url;
|
||||
if (urlBase.endsWith(".jar")) return urlBase;
|
||||
if (StrUtils.isNotBlank(url) && downloadType.getProvider().isAllowedToUseSelfURL())
|
||||
urlBase = this.url;
|
||||
if (urlBase.endsWith(".jar"))
|
||||
return urlBase;
|
||||
return urlBase + formatted.replace('\\', '/');
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,8 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
|
||||
this.inheritsFrom = inheritsFrom;
|
||||
this.minimumLauncherVersion = minimumLauncherVersion;
|
||||
this.hidden = hidden;
|
||||
if (libraries == null) this.libraries = new ArrayList<>();
|
||||
if (libraries == null)
|
||||
this.libraries = new ArrayList<>();
|
||||
else {
|
||||
this.libraries = new ArrayList<>(libraries.size());
|
||||
for (IMinecraftLibrary library : libraries)
|
||||
@@ -81,7 +82,8 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
|
||||
|
||||
MinecraftVersion parent = manager.getVersionById(inheritsFrom);
|
||||
if (parent == null) {
|
||||
if (!manager.install(inheritsFrom, sourceType)) return this;
|
||||
if (!manager.install(inheritsFrom, sourceType))
|
||||
return this;
|
||||
parent = manager.getVersionById(inheritsFrom);
|
||||
}
|
||||
parent = parent.resolve(manager, resolvedSoFar, sourceType);
|
||||
|
||||
@@ -95,18 +95,21 @@ public final class MinecraftVersionManager extends IMinecraftProvider {
|
||||
|
||||
File version = new File(baseFolder, "versions");
|
||||
File[] files = version.listFiles();
|
||||
if (files == null || files.length == 0) return;
|
||||
if (files == null || files.length == 0)
|
||||
return;
|
||||
|
||||
for (File dir : files) {
|
||||
String id = dir.getName();
|
||||
File jsonFile = new File(dir, id + ".json");
|
||||
|
||||
if (!dir.isDirectory()) continue;
|
||||
if (!dir.isDirectory())
|
||||
continue;
|
||||
boolean ask = false;
|
||||
File[] jsons = null;
|
||||
if (!jsonFile.exists()) {
|
||||
jsons = FileUtils.searchSuffix(dir, "json");
|
||||
if (jsons.length == 1) ask = true;
|
||||
if (jsons.length == 1)
|
||||
ask = true;
|
||||
}
|
||||
if (ask) {
|
||||
HMCLog.warn("Found not matched filenames version: " + id + ", json: " + jsons[0].getName());
|
||||
@@ -121,20 +124,23 @@ public final class MinecraftVersionManager extends IMinecraftProvider {
|
||||
MinecraftVersion mcVersion;
|
||||
try {
|
||||
mcVersion = C.gson.fromJson(FileUtils.readFileToString(jsonFile), MinecraftVersion.class);
|
||||
if (mcVersion == null) throw new RuntimeException("Wrong json format, got null.");
|
||||
if (mcVersion == null)
|
||||
throw new RuntimeException("Wrong json format, got null.");
|
||||
} catch (IOException | RuntimeException e) {
|
||||
HMCLog.warn("Found wrong format json, try to fix it.", e);
|
||||
if (MessageBox.Show(C.i18n("launcher.versions_json_not_formatted", id), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
|
||||
refreshJson(id);
|
||||
try {
|
||||
mcVersion = C.gson.fromJson(FileUtils.readFileToString(jsonFile), MinecraftVersion.class);
|
||||
if (mcVersion == null) throw new RuntimeException("Wrong json format, got null.");
|
||||
if (mcVersion == null)
|
||||
throw new RuntimeException("Wrong json format, got null.");
|
||||
} catch (IOException | RuntimeException ex) {
|
||||
HMCLog.err("Retried but still failed.");
|
||||
HMCLog.warn("Ignoring: " + dir + ", the json of this Minecraft is malformed.", ex);
|
||||
continue;
|
||||
}
|
||||
} else continue;
|
||||
} else
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
if (!id.equals(mcVersion.id)) {
|
||||
@@ -156,7 +162,8 @@ public final class MinecraftVersionManager extends IMinecraftProvider {
|
||||
@Override
|
||||
public boolean removeVersionFromDisk(String name) {
|
||||
File version = new File(baseFolder, "versions/" + name);
|
||||
if (!version.exists()) return true;
|
||||
if (!version.exists())
|
||||
return true;
|
||||
|
||||
versions.remove(name);
|
||||
return FileUtils.deleteDirectoryQuietly(version);
|
||||
@@ -192,7 +199,8 @@ public final class MinecraftVersionManager extends IMinecraftProvider {
|
||||
@Override
|
||||
public boolean refreshAssetsIndex(String id) {
|
||||
MinecraftVersion mv = getVersionById(id);
|
||||
if (mv == null) return false;
|
||||
if (mv == null)
|
||||
return false;
|
||||
return MCUtils.downloadMinecraftAssetsIndex(new File(baseFolder, "assets"), mv.assets, Settings.getInstance().getDownloadSource());
|
||||
}
|
||||
|
||||
@@ -218,7 +226,8 @@ public final class MinecraftVersionManager extends IMinecraftProvider {
|
||||
|
||||
@Override
|
||||
public List<ModInfo> listMods() {
|
||||
if (profile.getSelectedMinecraftVersion() == null) return new ArrayList<>();
|
||||
if (profile.getSelectedMinecraftVersion() == null)
|
||||
return new ArrayList<>();
|
||||
File modsFolder = new File(getRunDirectory(profile.getSelectedMinecraftVersion().id), "mods");
|
||||
ArrayList<ModInfo> mods = new ArrayList<>();
|
||||
File[] fs = modsFolder.listFiles();
|
||||
@@ -245,7 +254,8 @@ public final class MinecraftVersionManager extends IMinecraftProvider {
|
||||
@Override
|
||||
public List<GameLauncher.DownloadLibraryJob> getDownloadLibraries(DownloadType downloadType) {
|
||||
ArrayList<DownloadLibraryJob> downloadLibraries = new ArrayList<>();
|
||||
if(profile.getSelectedMinecraftVersion() == null) return downloadLibraries;
|
||||
if (profile.getSelectedMinecraftVersion() == null)
|
||||
return downloadLibraries;
|
||||
MinecraftVersion v = profile.getSelectedMinecraftVersion().resolve(this, Settings.getInstance().getDownloadSource());
|
||||
if (v.libraries != null)
|
||||
for (IMinecraftLibrary l : v.libraries) {
|
||||
@@ -281,7 +291,8 @@ public final class MinecraftVersionManager extends IMinecraftProvider {
|
||||
@Override
|
||||
public GameLauncher.DecompressLibraryJob getDecompressLibraries() {
|
||||
MinecraftVersion v = profile.getSelectedMinecraftVersion().resolve(this, Settings.getInstance().getDownloadSource());
|
||||
if (v.libraries == null) return null;
|
||||
if (v.libraries == null)
|
||||
return null;
|
||||
ArrayList<File> unzippings = new ArrayList<>();
|
||||
ArrayList<String[]> extractRules = new ArrayList<>();
|
||||
for (IMinecraftLibrary l : v.libraries) {
|
||||
@@ -334,6 +345,7 @@ public final class MinecraftVersionManager extends IMinecraftProvider {
|
||||
@Override
|
||||
public void onLaunch() {
|
||||
File resourcePacks = getResourcePacks();
|
||||
if (!resourcePacks.exists()) resourcePacks.mkdirs();
|
||||
if (!resourcePacks.exists())
|
||||
resourcePacks.mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,11 +26,12 @@ import javax.swing.JFrame;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class DraggableFrame extends JFrame
|
||||
implements MouseListener, MouseMotionListener {
|
||||
implements MouseListener, MouseMotionListener {
|
||||
|
||||
private int dragGripX;
|
||||
private int dragGripY;
|
||||
|
||||
@SuppressWarnings("LeakingThisInConstructor")
|
||||
public DraggableFrame() {
|
||||
setUndecorated(true);
|
||||
addMouseListener(this);
|
||||
|
||||
@@ -119,7 +119,8 @@ public class GameSettingsPanel extends javax.swing.JPanel implements DropTargetL
|
||||
itm = new JMenuItem(C.i18n("folder.game"));
|
||||
itm.addActionListener((e) -> {
|
||||
Profile v = getProfile();
|
||||
if (v != null) v.getMinecraftProvider().openSelf(mcVersion);
|
||||
if (v != null)
|
||||
v.getMinecraftProvider().openSelf(mcVersion);
|
||||
});
|
||||
ppmExplore.add(itm);
|
||||
itm = new JMenuItem(C.i18n("folder.mod"));
|
||||
@@ -227,13 +228,19 @@ public class GameSettingsPanel extends javax.swing.JPanel implements DropTargetL
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
switch (tabInstallers.getSelectedIndex()) {
|
||||
case 0: if (!a) forge.refreshVersions();
|
||||
case 0:
|
||||
if (!a)
|
||||
forge.refreshVersions();
|
||||
a = true;
|
||||
break;
|
||||
case 1: if (!b) optifine.refreshVersions();
|
||||
case 1:
|
||||
if (!b)
|
||||
optifine.refreshVersions();
|
||||
b = true;
|
||||
break;
|
||||
case 2: if (!c) liteloader.refreshVersions();
|
||||
case 2:
|
||||
if (!c)
|
||||
liteloader.refreshVersions();
|
||||
c = true;
|
||||
break;
|
||||
}
|
||||
@@ -242,8 +249,10 @@ 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");
|
||||
if (name.equals("Default"))
|
||||
name = C.i18n("settings.default");
|
||||
if (name.equals("Custom"))
|
||||
name = C.i18n("settings.custom");
|
||||
cboJava.addItem(name);
|
||||
}
|
||||
|
||||
@@ -1122,7 +1131,8 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
// <editor-fold defaultstate="collapsed" desc="UI Events">
|
||||
private void cboProfilesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboProfilesItemStateChanged
|
||||
if (isLoading) return;
|
||||
if (isLoading)
|
||||
return;
|
||||
profile = getProfile();
|
||||
if (profile.getMinecraftProvider().getVersionCount() <= 0)
|
||||
versionChanged(profile, null);
|
||||
@@ -1136,8 +1146,10 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
||||
}//GEN-LAST:event_btnNewProfileActionPerformed
|
||||
|
||||
private void btnRemoveProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveProfileActionPerformed
|
||||
if (profile == null) return;
|
||||
if (MessageBox.Show(C.i18n("ui.message.sure_remove", profile.getName()), MessageBox.YES_NO_OPTION) == MessageBox.NO_OPTION) return;
|
||||
if (profile == null)
|
||||
return;
|
||||
if (MessageBox.Show(C.i18n("ui.message.sure_remove", profile.getName()), MessageBox.YES_NO_OPTION) == MessageBox.NO_OPTION)
|
||||
return;
|
||||
if (Settings.delProfile(profile)) {
|
||||
cboProfiles.removeItem(profile.getName());
|
||||
profile = Settings.getOneProfile();
|
||||
@@ -1332,13 +1344,15 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
||||
}//GEN-LAST:event_txtWidthFocusLost
|
||||
|
||||
private void txtGameDirFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtGameDirFocusLost
|
||||
if (profile == null) return;
|
||||
if (profile == null)
|
||||
return;
|
||||
profile.setGameDir(txtGameDir.getText());
|
||||
loadVersions();
|
||||
}//GEN-LAST:event_txtGameDirFocusLost
|
||||
|
||||
private void btnChoosingJavaDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChoosingJavaDirActionPerformed
|
||||
if (cboJava.getSelectedIndex() != 1) return;
|
||||
if (cboJava.getSelectedIndex() != 1)
|
||||
return;
|
||||
JFileChooser fc = new JFileChooser();
|
||||
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||
fc.setDialogTitle(C.i18n("settings.choose_javapath"));
|
||||
@@ -1376,25 +1390,29 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
||||
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||
fc.setDialogTitle(C.I18N.getString("mods.choose_mod"));
|
||||
fc.setMultiSelectionEnabled(true);
|
||||
if (fc.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) return;
|
||||
if (fc.showOpenDialog(this) != JFileChooser.APPROVE_OPTION)
|
||||
return;
|
||||
boolean flag = false;
|
||||
for (File f : fc.getSelectedFiles())
|
||||
if (!addMod(f)) flag |= true;
|
||||
if (!addMod(f))
|
||||
flag |= true;
|
||||
if (flag)
|
||||
MessageBox.Show(C.I18N.getString("mods.failed"));
|
||||
}//GEN-LAST:event_btnAddModActionPerformed
|
||||
|
||||
boolean addMod(File f) {
|
||||
try {
|
||||
if (!ModInfo.isFileMod(f) || mods == null) return false;
|
||||
if (!ModInfo.isFileMod(f) || mods == null)
|
||||
return false;
|
||||
File newf = profile.getFolder("mods");
|
||||
if (newf == null) return false;
|
||||
if (newf == null)
|
||||
return false;
|
||||
newf.mkdirs();
|
||||
newf = new File(newf, f.getName());
|
||||
FileUtils.copyFile(f, newf);
|
||||
ModInfo i = ModInfo.readModInfo(f);
|
||||
mods.add(i);
|
||||
((DefaultTableModel) lstExternalMods.getModel()).addRow(new Object[]{i.isActive(), i.location.getName(), i.version});
|
||||
((DefaultTableModel) lstExternalMods.getModel()).addRow(new Object[] {i.isActive(), i.location.getName(), i.version});
|
||||
return true;
|
||||
} catch (IOException ex) {
|
||||
HMCLog.warn("Failed to copy mod", ex);
|
||||
@@ -1460,9 +1478,11 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
||||
private void btnCleanGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCleanGameActionPerformed
|
||||
File f = getProfile().getMinecraftProvider().getRunDirectory(mcVersion);
|
||||
String[] dir = {"logs", "asm", "NVIDIA", "crash-reports", "server-resource-packs", "natives", "native"};
|
||||
for (String s : dir) FileUtils.deleteDirectoryQuietly(new File(f, s));
|
||||
for (String s : dir)
|
||||
FileUtils.deleteDirectoryQuietly(new File(f, s));
|
||||
String[] files = {"output-client.log", "usercache.json", "usernamecache.json", "hmclmc.log"};
|
||||
for (String s : files) new File(f, s).delete();
|
||||
for (String s : files)
|
||||
new File(f, s).delete();
|
||||
for (MinecraftVersion s : getProfile().getMinecraftProvider().getVersions())
|
||||
FileUtils.deleteDirectoryQuietly(new File(getProfile().getGameDirFile(), "versions" + File.separator + s.id + File.separator + s.id + "-natives"));
|
||||
}//GEN-LAST:event_btnCleanGameActionPerformed
|
||||
@@ -1475,7 +1495,8 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
||||
Profile firstProfile = null, selectedProfile = null;
|
||||
int index = 0, i = 0;
|
||||
for (Profile s : Settings.getProfilesFiltered()) {
|
||||
if (firstProfile == null) firstProfile = s;
|
||||
if (firstProfile == null)
|
||||
firstProfile = s;
|
||||
cboProfiles.addItem(s.getName());
|
||||
if (Settings.getInstance().getLast() != null && Settings.getInstance().getLast().equals(s.getName())) {
|
||||
index = i;
|
||||
@@ -1483,13 +1504,15 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (selectedProfile == null) selectedProfile = Settings.getOneProfile();
|
||||
if (selectedProfile == null)
|
||||
selectedProfile = Settings.getOneProfile();
|
||||
|
||||
isLoading = false;
|
||||
if (index < cboProfiles.getItemCount()) {
|
||||
cboProfiles.setSelectedIndex(index);
|
||||
profile = selectedProfile;
|
||||
if (profile == null) profile = firstProfile;
|
||||
if (profile == null)
|
||||
profile = firstProfile;
|
||||
prepare(profile);
|
||||
loadVersions();
|
||||
}
|
||||
@@ -1498,11 +1521,13 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
||||
final Profile getProfile() {
|
||||
if (cboProfiles.getSelectedIndex() >= 0)
|
||||
return Settings.getProfile(cboProfiles.getSelectedItem().toString());
|
||||
else return null;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
void prepare(Profile profile) {
|
||||
if (profile == null) return;
|
||||
if (profile == null)
|
||||
return;
|
||||
txtWidth.setText(profile.getWidth());
|
||||
txtHeight.setText(profile.getHeight());
|
||||
txtMaxMemory.setText(profile.getMaxMemory());
|
||||
@@ -1530,7 +1555,8 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
||||
}
|
||||
|
||||
void loadVersions() {
|
||||
if (profile == null) return;
|
||||
if (profile == null)
|
||||
return;
|
||||
isLoading = true;
|
||||
cboVersions.removeAllItems();
|
||||
int index = 0, i = 0;
|
||||
@@ -1538,11 +1564,13 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
||||
String selectedMC = selVersion == null ? null : selVersion.id;
|
||||
for (MinecraftVersion each : profile.getMinecraftProvider().getVersions()) {
|
||||
cboVersions.addItem(each.id);
|
||||
if (each.id.equals(selectedMC)) index = i;
|
||||
if (each.id.equals(selectedMC))
|
||||
index = i;
|
||||
i++;
|
||||
}
|
||||
isLoading = false;
|
||||
if (index < cboVersions.getItemCount()) cboVersions.setSelectedIndex(index);
|
||||
if (index < cboVersions.getItemCount())
|
||||
cboVersions.setSelectedIndex(index);
|
||||
|
||||
reloadMods();
|
||||
}
|
||||
@@ -1563,7 +1591,8 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
||||
*/
|
||||
void loadMinecraftVersion(MinecraftVersion v) {
|
||||
txtMinecraftVersion.setText("");
|
||||
if (v == null) return;
|
||||
if (v == null)
|
||||
return;
|
||||
File minecraftJar = v.getJar(profile.getGameDirFile());
|
||||
minecraftVersion = MCUtils.minecraftVersion(minecraftJar);
|
||||
txtMinecraftVersion.setText(MinecraftVersionRequest.getResponse(minecraftVersion));
|
||||
@@ -1573,7 +1602,8 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
||||
public int assetsType;
|
||||
|
||||
private void downloadAssets(final IAssetsHandler type) {
|
||||
if (mcVersion == null || profile == null) return;
|
||||
if (mcVersion == null || profile == null)
|
||||
return;
|
||||
type.getList(profile.getMinecraftProvider().getVersionById(mcVersion), profile.getMinecraftProvider(), (value) -> {
|
||||
if (value != null)
|
||||
SwingUtilities.invokeLater(() -> TaskWindow.getInstance().addTask(type.getDownloadTask(Settings.getInstance().getDownloadSource().getProvider())).start());
|
||||
@@ -1593,14 +1623,16 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
||||
return true;
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
DefaultTableModel model = (DefaultTableModel) lstDownloads.getModel();
|
||||
while (model.getRowCount() > 0) model.removeRow(0);
|
||||
while (model.getRowCount() > 0)
|
||||
model.removeRow(0);
|
||||
for (MinecraftRemoteVersion ver : v.versions) {
|
||||
Object[] line = new Object[3];
|
||||
line[0] = ver.id;
|
||||
line[1] = ver.time;
|
||||
if (StrUtils.equalsOne(ver.type, "old_beta", "old_alpha", "release", "snapshot"))
|
||||
line[2] = C.i18n("versions." + ver.type);
|
||||
else line[2] = ver.type;
|
||||
else
|
||||
line[2] = ver.type;
|
||||
model.addRow(line);
|
||||
}
|
||||
lstDownloads.updateUI();
|
||||
@@ -1621,7 +1653,8 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
||||
}
|
||||
|
||||
void downloadMinecraft(DownloadType index) {
|
||||
if (profile == null) return;
|
||||
if (profile == null)
|
||||
return;
|
||||
if (lstDownloads.getSelectedRow() < 0)
|
||||
refreshDownloads(Settings.getInstance().getDownloadSource());
|
||||
if (lstDownloads.getSelectedRow() < 0) {
|
||||
@@ -1687,7 +1720,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
||||
void refreshVersions() {
|
||||
list = Settings.getInstance().getDownloadSource().getProvider().getInstallerByType(id);
|
||||
if (TaskWindow.getInstance().addTask(new TaskRunnableArg1<>(C.i18n("install." + id + ".get_list"), list)
|
||||
.registerPreviousResult(new DefaultPreviousResult<>(new String[]{getMinecraftVersionFormatted()})))
|
||||
.registerPreviousResult(new DefaultPreviousResult<>(new String[] {getMinecraftVersionFormatted()})))
|
||||
.start())
|
||||
loadVersions();
|
||||
}
|
||||
@@ -1708,7 +1741,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
||||
for (InstallerVersionList.InstallerVersion v : ver) {
|
||||
Object a = v.selfVersion == null ? "null" : v.selfVersion;
|
||||
Object b = v.mcVersion == null ? "null" : v.mcVersion;
|
||||
Object[] row = new Object[]{a, b};
|
||||
Object[] row = new Object[] {a, b};
|
||||
model.addRow(row);
|
||||
}
|
||||
table.updateUI();
|
||||
@@ -1744,7 +1777,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
||||
SwingUtils.clearDefaultTable(lstExternalMods);
|
||||
DefaultTableModel model = (DefaultTableModel) lstExternalMods.getModel();
|
||||
for (ModInfo info : mods)
|
||||
model.addRow(new Object[]{info.isActive(), info.getFileName(), info.version});
|
||||
model.addRow(new Object[] {info.isActive(), info.getFileName(), info.version});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1763,10 +1796,12 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
||||
|
||||
public void onSelected() {
|
||||
loadProfiles();
|
||||
if (profile == null) return;
|
||||
if (profile == null)
|
||||
return;
|
||||
if (profile.getMinecraftProvider().getVersionCount() <= 0)
|
||||
versionChanged(profile, null);
|
||||
else versionChanged(getProfile(), (String) cboVersions.getSelectedItem());
|
||||
else
|
||||
versionChanged(getProfile(), (String) cboVersions.getSelectedItem());
|
||||
}
|
||||
|
||||
public void showGameDownloads() {
|
||||
|
||||
@@ -29,7 +29,7 @@ import javax.swing.JLabel;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class HeaderTab extends JLabel
|
||||
implements MouseListener {
|
||||
implements MouseListener {
|
||||
|
||||
private boolean isActive;
|
||||
private final DefaultButtonModel model;
|
||||
|
||||
@@ -186,7 +186,8 @@ public final class MainFrame extends DraggableFrame {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (UpdateChecker.OUT_DATED) Main.update();
|
||||
if (UpdateChecker.OUT_DATED)
|
||||
Main.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -275,9 +275,11 @@ public class MainPagePanel extends javax.swing.JPanel {
|
||||
}//GEN-LAST:event_txtPlayerNameFocusLost
|
||||
|
||||
private void cboLoginModeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboLoginModeItemStateChanged
|
||||
if (preaparingAuth) return;
|
||||
if (preaparingAuth)
|
||||
return;
|
||||
int index = cboLoginMode.getSelectedIndex();
|
||||
if (index < 0) return;
|
||||
if (index < 0)
|
||||
return;
|
||||
|
||||
IAuthenticator l = IAuthenticator.LOGINS.get(index);
|
||||
if (l.isHidePasswordBox()) {
|
||||
@@ -289,10 +291,13 @@ public class MainPagePanel extends javax.swing.JPanel {
|
||||
}
|
||||
|
||||
CardLayout cl = (CardLayout) pnlPassword.getLayout();
|
||||
if (l.isLoggedIn()) cl.last(pnlPassword);
|
||||
else cl.first(pnlPassword);
|
||||
if (l.isLoggedIn())
|
||||
cl.last(pnlPassword);
|
||||
else
|
||||
cl.first(pnlPassword);
|
||||
String username = Settings.getInstance().getUsername();
|
||||
if (StrUtils.isNotBlank(username)) txtPlayerName.setText(username);
|
||||
if (StrUtils.isNotBlank(username))
|
||||
txtPlayerName.setText(username);
|
||||
|
||||
Settings.getInstance().setLoginType(index);
|
||||
}//GEN-LAST:event_cboLoginModeItemStateChanged
|
||||
@@ -321,12 +326,14 @@ public class MainPagePanel extends javax.swing.JPanel {
|
||||
}//GEN-LAST:event_txtPasswordActionPerformed
|
||||
|
||||
private void btnLogoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLogoutActionPerformed
|
||||
if (preaparingAuth) return;
|
||||
if (preaparingAuth)
|
||||
return;
|
||||
int index = cboLoginMode.getSelectedIndex();
|
||||
|
||||
IAuthenticator l = IAuthenticator.LOGINS.get(index);
|
||||
CardLayout cl = (CardLayout) pnlPassword.getLayout();
|
||||
if (l.isLoggedIn()) l.logout();
|
||||
if (l.isLoggedIn())
|
||||
l.logout();
|
||||
cl.first(pnlPassword);
|
||||
}//GEN-LAST:event_btnLogoutActionPerformed
|
||||
|
||||
@@ -334,22 +341,27 @@ public class MainPagePanel extends javax.swing.JPanel {
|
||||
if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
Settings.getInstance().setUsername(txtPlayerName.getText());
|
||||
int index = cboLoginMode.getSelectedIndex();
|
||||
if (index < 0) return;
|
||||
if (index < 0)
|
||||
return;
|
||||
IAuthenticator l = IAuthenticator.LOGINS.get(index);
|
||||
if (l.isHidePasswordBox()) btnRunActionPerformed();
|
||||
else if (!l.isLoggedIn()) txtPassword.requestFocus();
|
||||
if (l.isHidePasswordBox())
|
||||
btnRunActionPerformed();
|
||||
else if (!l.isLoggedIn())
|
||||
txtPassword.requestFocus();
|
||||
}
|
||||
}//GEN-LAST:event_txtPlayerNameKeyPressed
|
||||
|
||||
private void txtPasswordKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPasswordKeyPressed
|
||||
if (evt.getKeyCode() == KeyEvent.VK_ENTER) btnRunActionPerformed();
|
||||
if (evt.getKeyCode() == KeyEvent.VK_ENTER)
|
||||
btnRunActionPerformed();
|
||||
}//GEN-LAST:event_txtPasswordKeyPressed
|
||||
|
||||
boolean isLaunching = false;
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Game Launch">
|
||||
void genLaunchCode(final Consumer<GameLauncher> listener) {
|
||||
if (isLaunching || getCurrentProfile() == null) return;
|
||||
if (isLaunching || getCurrentProfile() == null)
|
||||
return;
|
||||
isLaunching = true;
|
||||
HMCLog.log("Start generating launching command...");
|
||||
File file = getCurrentProfile().getCanonicalGameDirFile();
|
||||
@@ -379,7 +391,8 @@ public class MainPagePanel extends javax.swing.JPanel {
|
||||
Thread.currentThread().setName("Game Launcher");
|
||||
DefaultGameLauncher gl = new DefaultGameLauncher(getCurrentProfile(), li, l, Settings.getInstance().getDownloadSource());
|
||||
gl.failEvent.register((sender, s) -> {
|
||||
if (s != null) MessageBox.Show(s);
|
||||
if (s != null)
|
||||
MessageBox.Show(s);
|
||||
MainFrame.instance.closeMessage();
|
||||
isLaunching = false;
|
||||
return true;
|
||||
@@ -417,7 +430,8 @@ public class MainPagePanel extends javax.swing.JPanel {
|
||||
}
|
||||
|
||||
void loadFromSettings() {
|
||||
for (Profile s : Settings.getProfilesFiltered()) cboProfiles.addItem(s.getName());
|
||||
for (Profile s : Settings.getProfilesFiltered())
|
||||
cboProfiles.addItem(s.getName());
|
||||
}
|
||||
|
||||
boolean showedNoVersion = false;
|
||||
@@ -433,7 +447,7 @@ public class MainPagePanel extends javax.swing.JPanel {
|
||||
if (getCurrentProfile().getMinecraftProvider().getVersions().isEmpty()) {
|
||||
if (!showedNoVersion)
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
if(MessageBox.Show(C.i18n("mainwindow.no_version"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
|
||||
if (MessageBox.Show(C.i18n("mainwindow.no_version"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
|
||||
MainFrame.instance.selectTab("game");
|
||||
MainFrame.instance.gamePanel.showGameDownloads();
|
||||
}
|
||||
@@ -441,12 +455,15 @@ public class MainPagePanel extends javax.swing.JPanel {
|
||||
});
|
||||
} else {
|
||||
for (MinecraftVersion mcVersion : getCurrentProfile().getMinecraftProvider().getVersions()) {
|
||||
if (mcVersion.hidden) continue;
|
||||
if (mcVersion.hidden)
|
||||
continue;
|
||||
cboVersions.addItem(mcVersion.id);
|
||||
if (mcVersion.id.equals(selectedMC)) index = i;
|
||||
if (mcVersion.id.equals(selectedMC))
|
||||
index = i;
|
||||
i++;
|
||||
}
|
||||
if (index < cboVersions.getItemCount()) cboVersions.setSelectedIndex(index);
|
||||
if (index < cboVersions.getItemCount())
|
||||
cboVersions.setSelectedIndex(index);
|
||||
}
|
||||
}
|
||||
isLoading = false;
|
||||
|
||||
@@ -147,7 +147,6 @@ public final class NewProfileWindow extends javax.swing.JDialog {
|
||||
this.dispose();
|
||||
}//GEN-LAST:event_btnCancelActionPerformed
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton btnCancel;
|
||||
private javax.swing.JButton btnOK;
|
||||
|
||||
@@ -21,7 +21,7 @@ if (!hasProperty('mainClass')) {
|
||||
}
|
||||
|
||||
if (System.getenv("BUILD_NUMBER") != null)
|
||||
version = System.getenv("BUILD_NUMBER")
|
||||
version = System.getenv("BUILD_NUMBER")
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
|
||||
@@ -35,7 +35,7 @@ public final class C {
|
||||
ResourceBundle rb = null;
|
||||
try {
|
||||
rb = ResourceBundle.getBundle("org/jackhuang/hellominecraft/launcher/I18N");
|
||||
} catch(Throwable t) {
|
||||
} catch (Throwable t) {
|
||||
rb = null;
|
||||
System.out.println("Did you delete I18N.properties?");
|
||||
t.printStackTrace();
|
||||
|
||||
@@ -37,9 +37,8 @@ public class AppenderControl {
|
||||
|
||||
public void callAppender(LogEvent event) {
|
||||
if ((this.level != null)
|
||||
&& (this.intLevel < event.level.level)) {
|
||||
&& (this.intLevel < event.level.level))
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.recursive.get() != null) {
|
||||
System.err.println("Recursive call to appender " + this.appender.getName());
|
||||
@@ -53,16 +52,14 @@ public class AppenderControl {
|
||||
} catch (RuntimeException ex) {
|
||||
System.err.println("An exception occurred processing Appender " + this.appender.getName());
|
||||
ex.printStackTrace();
|
||||
if (!this.appender.ignoreExceptions()) {
|
||||
if (!this.appender.ignoreExceptions())
|
||||
throw ex;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.err.println("An exception occurred processing Appender " + this.appender.getName());
|
||||
ex.printStackTrace();
|
||||
if (!this.appender.ignoreExceptions()) {
|
||||
if (!this.appender.ignoreExceptions())
|
||||
throw new LoggingException(ex);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
this.recursive.set(null);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.jackhuang.hellominecraft.logging.layout.DefaultLayout;
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
|
||||
public class Configuration {
|
||||
|
||||
public ArrayList<IAppender> appenders = new ArrayList<IAppender>();
|
||||
|
||||
@@ -27,8 +27,11 @@ import org.jackhuang.hellominecraft.logging.layout.ILayout;
|
||||
public interface IAppender {
|
||||
|
||||
void append(LogEvent event);
|
||||
|
||||
String getName();
|
||||
|
||||
boolean ignoreExceptions();
|
||||
|
||||
ILayout<? extends Serializable> getLayout();
|
||||
|
||||
}
|
||||
|
||||
@@ -48,10 +48,9 @@ public abstract class OutputStreamAppender extends AbstractAppender {
|
||||
this.readLock.lock();
|
||||
try {
|
||||
byte[] bytes = getLayout().toByteArray(event);
|
||||
if (bytes.length > 0) {
|
||||
if (bytes.length > 0)
|
||||
stream.write(bytes);
|
||||
}
|
||||
if(event.thrown != null)
|
||||
if (event.thrown != null)
|
||||
event.thrown.printStackTrace(new PrintStream(stream));
|
||||
} catch (IOException ex) {
|
||||
System.err.println("Unable to write to stream for appender: " + getName());
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.jackhuang.hellominecraft.logging.LogEvent;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class DefaultLayout extends AbstractStringLayout {
|
||||
|
||||
private static final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.jackhuang.hellominecraft.logging.LogEvent;
|
||||
public interface ILayout<T extends Serializable> {
|
||||
|
||||
byte[] toByteArray(LogEvent event);
|
||||
|
||||
T toSerializable(LogEvent event);
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.jackhuang.hellominecraft.logging.message.ParameterizedMessageFactory;
|
||||
import org.jackhuang.hellominecraft.logging.message.StringFormattedMessage;
|
||||
|
||||
public abstract class AbstractLogger
|
||||
implements ILogger {
|
||||
implements ILogger {
|
||||
|
||||
public static final Class<? extends IMessageFactory> DEFAULT_MESSAGE_FACTORY_CLASS = ParameterizedMessageFactory.class;
|
||||
|
||||
@@ -60,10 +60,9 @@ public abstract class AbstractLogger
|
||||
|
||||
@Override
|
||||
public void catching(Level level, Throwable t) {
|
||||
if (isEnabled(level, (Object) null, null)) {
|
||||
if (isEnabled(level, (Object) null, null))
|
||||
log(level, this.messageFactory.newMessage(CATCHING), t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void catching(Throwable t) {
|
||||
@@ -72,38 +71,33 @@ public abstract class AbstractLogger
|
||||
|
||||
@Override
|
||||
public void debug(IMessage msg) {
|
||||
if (isEnabled(Level.DEBUG, msg, null)) {
|
||||
if (isEnabled(Level.DEBUG, msg, null))
|
||||
log(Level.DEBUG, msg, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(IMessage msg, Throwable t) {
|
||||
if (isEnabled(Level.DEBUG, msg, t)) {
|
||||
if (isEnabled(Level.DEBUG, msg, t))
|
||||
log(Level.DEBUG, msg, t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(Object message) {
|
||||
if (isEnabled(Level.DEBUG, message, null)) {
|
||||
if (isEnabled(Level.DEBUG, message, null))
|
||||
log(Level.DEBUG, this.messageFactory.newMessage(message), null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(Object message, Throwable t) {
|
||||
if (isEnabled(Level.DEBUG, message, t)) {
|
||||
if (isEnabled(Level.DEBUG, message, t))
|
||||
log(Level.DEBUG, this.messageFactory.newMessage(message), t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String message) {
|
||||
if (isEnabled(Level.DEBUG, message)) {
|
||||
if (isEnabled(Level.DEBUG, message))
|
||||
log(Level.DEBUG, this.messageFactory.newMessage(message), null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String message, Object[] params) {
|
||||
@@ -115,10 +109,9 @@ public abstract class AbstractLogger
|
||||
|
||||
@Override
|
||||
public void debug(String message, Throwable t) {
|
||||
if (isEnabled(Level.DEBUG, message, t)) {
|
||||
if (isEnabled(Level.DEBUG, message, t))
|
||||
log(Level.DEBUG, this.messageFactory.newMessage(message), t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void entry() {
|
||||
@@ -127,66 +120,57 @@ public abstract class AbstractLogger
|
||||
|
||||
@Override
|
||||
public void entry(Object[] params) {
|
||||
if (isEnabled(Level.TRACE, (Object) null, null)) {
|
||||
if (isEnabled(Level.TRACE, (Object) null, null))
|
||||
log(Level.TRACE, entryMsg(params.length, params), null);
|
||||
}
|
||||
}
|
||||
|
||||
private IMessage entryMsg(int count, Object[] params) {
|
||||
if (count == 0) {
|
||||
if (count == 0)
|
||||
return this.messageFactory.newMessage("entry");
|
||||
}
|
||||
StringBuilder sb = new StringBuilder("entry params(");
|
||||
int i = 0;
|
||||
for (Object parm : params) {
|
||||
if (parm != null) {
|
||||
if (parm != null)
|
||||
sb.append(parm.toString());
|
||||
} else {
|
||||
else
|
||||
sb.append("null");
|
||||
}
|
||||
i++;
|
||||
if (i < params.length) {
|
||||
if (i < params.length)
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
sb.append(")");
|
||||
return this.messageFactory.newMessage(sb.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(IMessage msg) {
|
||||
if (isEnabled(Level.ERROR, msg, null)) {
|
||||
if (isEnabled(Level.ERROR, msg, null))
|
||||
log(Level.ERROR, msg, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(IMessage msg, Throwable t) {
|
||||
if (isEnabled(Level.ERROR, msg, t)) {
|
||||
if (isEnabled(Level.ERROR, msg, t))
|
||||
log(Level.ERROR, msg, t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(Object message) {
|
||||
if (isEnabled(Level.ERROR, message, null)) {
|
||||
if (isEnabled(Level.ERROR, message, null))
|
||||
log(Level.ERROR, this.messageFactory.newMessage(message), null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(Object message, Throwable t) {
|
||||
if (isEnabled(Level.ERROR, message, t)) {
|
||||
if (isEnabled(Level.ERROR, message, t))
|
||||
log(Level.ERROR, this.messageFactory.newMessage(message), t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String message) {
|
||||
if (isEnabled(Level.ERROR, message)) {
|
||||
if (isEnabled(Level.ERROR, message))
|
||||
log(Level.ERROR, this.messageFactory.newMessage(message), null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String message, Object[] params) {
|
||||
@@ -198,45 +182,39 @@ public abstract class AbstractLogger
|
||||
|
||||
@Override
|
||||
public void error(String message, Throwable t) {
|
||||
if (isEnabled(Level.ERROR, message, t)) {
|
||||
if (isEnabled(Level.ERROR, message, t))
|
||||
log(Level.ERROR, this.messageFactory.newMessage(message), t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fatal(IMessage msg) {
|
||||
if (isEnabled(Level.FATAL, msg, null)) {
|
||||
if (isEnabled(Level.FATAL, msg, null))
|
||||
log(Level.FATAL, msg, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fatal(IMessage msg, Throwable t) {
|
||||
if (isEnabled(Level.FATAL, msg, t)) {
|
||||
if (isEnabled(Level.FATAL, msg, t))
|
||||
log(Level.FATAL, msg, t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fatal(Object message) {
|
||||
if (isEnabled(Level.FATAL, message, null)) {
|
||||
if (isEnabled(Level.FATAL, message, null))
|
||||
log(Level.FATAL, this.messageFactory.newMessage(message), null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fatal(Object message, Throwable t) {
|
||||
if (isEnabled(Level.FATAL, message, t)) {
|
||||
if (isEnabled(Level.FATAL, message, t))
|
||||
log(Level.FATAL, this.messageFactory.newMessage(message), t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fatal(String message) {
|
||||
if (isEnabled(Level.FATAL, message)) {
|
||||
if (isEnabled(Level.FATAL, message))
|
||||
log(Level.FATAL, this.messageFactory.newMessage(message), null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fatal(String message, Object[] params) {
|
||||
@@ -248,10 +226,9 @@ public abstract class AbstractLogger
|
||||
|
||||
@Override
|
||||
public void fatal(String message, Throwable t) {
|
||||
if (isEnabled(Level.FATAL, message, t)) {
|
||||
if (isEnabled(Level.FATAL, message, t))
|
||||
log(Level.FATAL, this.messageFactory.newMessage(message), t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
@@ -260,38 +237,33 @@ public abstract class AbstractLogger
|
||||
|
||||
@Override
|
||||
public void info(IMessage msg) {
|
||||
if (isEnabled(Level.INFO, msg, null)) {
|
||||
if (isEnabled(Level.INFO, msg, null))
|
||||
log(Level.INFO, msg, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(IMessage msg, Throwable t) {
|
||||
if (isEnabled(Level.INFO, msg, t)) {
|
||||
if (isEnabled(Level.INFO, msg, t))
|
||||
log(Level.INFO, msg, t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(Object message) {
|
||||
if (isEnabled(Level.INFO, message, null)) {
|
||||
if (isEnabled(Level.INFO, message, null))
|
||||
log(Level.INFO, this.messageFactory.newMessage(message), null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(Object message, Throwable t) {
|
||||
if (isEnabled(Level.INFO, message, t)) {
|
||||
if (isEnabled(Level.INFO, message, t))
|
||||
log(Level.INFO, this.messageFactory.newMessage(message), t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String message) {
|
||||
if (isEnabled(Level.INFO, message)) {
|
||||
if (isEnabled(Level.INFO, message))
|
||||
log(Level.INFO, this.messageFactory.newMessage(message), null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String message, Object[] params) {
|
||||
@@ -303,10 +275,9 @@ public abstract class AbstractLogger
|
||||
|
||||
@Override
|
||||
public void info(String message, Throwable t) {
|
||||
if (isEnabled(Level.INFO, message, t)) {
|
||||
if (isEnabled(Level.INFO, message, t))
|
||||
log(Level.INFO, this.messageFactory.newMessage(message), t);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract boolean isEnabled(Level paramLevel, IMessage paramIMessage, Throwable paramThrowable);
|
||||
|
||||
@@ -358,38 +329,33 @@ public abstract class AbstractLogger
|
||||
|
||||
@Override
|
||||
public void log(Level level, IMessage msg) {
|
||||
if (isEnabled(level, msg, null)) {
|
||||
if (isEnabled(level, msg, null))
|
||||
log(level, msg, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(Level level, IMessage msg, Throwable t) {
|
||||
if (isEnabled(level, msg, t)) {
|
||||
if (isEnabled(level, msg, t))
|
||||
abstractLog(level, msg, t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(Level level, Object message) {
|
||||
if (isEnabled(level, message, null)) {
|
||||
if (isEnabled(level, message, null))
|
||||
log(level, this.messageFactory.newMessage(message), null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(Level level, Object message, Throwable t) {
|
||||
if (isEnabled(level, message, t)) {
|
||||
if (isEnabled(level, message, t))
|
||||
log(level, this.messageFactory.newMessage(message), t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(Level level, String message) {
|
||||
if (isEnabled(level, message)) {
|
||||
if (isEnabled(level, message))
|
||||
log(level, this.messageFactory.newMessage(message), null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(Level level, String message, Object[] params) {
|
||||
@@ -401,10 +367,9 @@ public abstract class AbstractLogger
|
||||
|
||||
@Override
|
||||
public void log(Level level, String message, Throwable t) {
|
||||
if (isEnabled(level, message, t)) {
|
||||
if (isEnabled(level, message, t))
|
||||
log(level, this.messageFactory.newMessage(message), t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printf(Level level, String format, Object[] params) {
|
||||
@@ -421,9 +386,8 @@ public abstract class AbstractLogger
|
||||
|
||||
@Override
|
||||
public <T extends Throwable> T throwing(Level level, T t) {
|
||||
if (isEnabled(level, (Object) null, null)) {
|
||||
if (isEnabled(level, (Object) null, null))
|
||||
log(level, this.messageFactory.newMessage(THROWING), t);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -434,38 +398,33 @@ public abstract class AbstractLogger
|
||||
|
||||
@Override
|
||||
public void trace(IMessage msg) {
|
||||
if (isEnabled(Level.TRACE, msg, null)) {
|
||||
if (isEnabled(Level.TRACE, msg, null))
|
||||
log(Level.TRACE, msg, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(IMessage msg, Throwable t) {
|
||||
if (isEnabled(Level.TRACE, msg, t)) {
|
||||
if (isEnabled(Level.TRACE, msg, t))
|
||||
log(Level.TRACE, msg, t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(Object message) {
|
||||
if (isEnabled(Level.TRACE, message, null)) {
|
||||
if (isEnabled(Level.TRACE, message, null))
|
||||
log(Level.TRACE, this.messageFactory.newMessage(message), null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(Object message, Throwable t) {
|
||||
if (isEnabled(Level.TRACE, message, t)) {
|
||||
if (isEnabled(Level.TRACE, message, t))
|
||||
log(Level.TRACE, this.messageFactory.newMessage(message), t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(String message) {
|
||||
if (isEnabled(Level.TRACE, message)) {
|
||||
if (isEnabled(Level.TRACE, message))
|
||||
log(Level.TRACE, this.messageFactory.newMessage(message), null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(String message, Object[] params) {
|
||||
@@ -477,45 +436,39 @@ public abstract class AbstractLogger
|
||||
|
||||
@Override
|
||||
public void trace(String message, Throwable t) {
|
||||
if (isEnabled(Level.TRACE, message, t)) {
|
||||
if (isEnabled(Level.TRACE, message, t))
|
||||
log(Level.TRACE, this.messageFactory.newMessage(message), t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(IMessage msg) {
|
||||
if (isEnabled(Level.WARN, msg, null)) {
|
||||
if (isEnabled(Level.WARN, msg, null))
|
||||
log(Level.WARN, msg, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(IMessage msg, Throwable t) {
|
||||
if (isEnabled(Level.WARN, msg, t)) {
|
||||
if (isEnabled(Level.WARN, msg, t))
|
||||
log(Level.WARN, msg, t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(Object message) {
|
||||
if (isEnabled(Level.WARN, message, null)) {
|
||||
if (isEnabled(Level.WARN, message, null))
|
||||
log(Level.WARN, this.messageFactory.newMessage(message), null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(Object message, Throwable t) {
|
||||
if (isEnabled(Level.WARN, message, t)) {
|
||||
if (isEnabled(Level.WARN, message, t))
|
||||
log(Level.WARN, this.messageFactory.newMessage(message), t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String message) {
|
||||
if (isEnabled(Level.WARN, message)) {
|
||||
if (isEnabled(Level.WARN, message))
|
||||
log(Level.WARN, this.messageFactory.newMessage(message), null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String message, Object[] params) {
|
||||
@@ -527,8 +480,7 @@ public abstract class AbstractLogger
|
||||
|
||||
@Override
|
||||
public void warn(String message, Throwable t) {
|
||||
if (isEnabled(Level.WARN, message, t)) {
|
||||
if (isEnabled(Level.WARN, message, t))
|
||||
log(Level.WARN, this.messageFactory.newMessage(message), t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,10 +42,9 @@ public class Logger extends AbstractLogger {
|
||||
}
|
||||
|
||||
public synchronized void setLevel(Level level) {
|
||||
if (level != null) {
|
||||
if (level != null)
|
||||
this.config = new PrivateConfig(this.config, level);
|
||||
}
|
||||
}
|
||||
|
||||
public Level getLevel() {
|
||||
return this.config.level;
|
||||
@@ -67,10 +66,9 @@ public class Logger extends AbstractLogger {
|
||||
}
|
||||
|
||||
protected void callAppenders(LogEvent event) {
|
||||
for (AppenderControl control : this.appenders.values()) {
|
||||
for (AppenderControl control : this.appenders.values())
|
||||
control.callAppender(event);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(Level level, String msg) {
|
||||
@@ -107,9 +105,8 @@ public class Logger extends AbstractLogger {
|
||||
|
||||
public Map<String, IAppender> getAppenders() {
|
||||
Map map = new HashMap();
|
||||
for (Map.Entry entry : this.appenders.entrySet()) {
|
||||
for (Map.Entry entry : this.appenders.entrySet())
|
||||
map.put(entry.getKey(), ((AppenderControl) entry.getValue()).getAppender());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -132,7 +129,7 @@ public class Logger extends AbstractLogger {
|
||||
this.logger = logger;
|
||||
|
||||
this.config = c;
|
||||
for(IAppender appender : config.appenders)
|
||||
for (IAppender appender : config.appenders)
|
||||
addAppender(appender);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,28 +40,25 @@ public class SimpleLogger extends AbstractLogger {
|
||||
this.level = defaultLevel;
|
||||
if (showShortLogName) {
|
||||
int index = name.lastIndexOf(".");
|
||||
if ((index > 0) && (index < name.length())) {
|
||||
if ((index > 0) && (index < name.length()))
|
||||
this.logName = name.substring(index + 1);
|
||||
} else {
|
||||
else
|
||||
this.logName = name;
|
||||
}
|
||||
} else if (showLogName) {
|
||||
} else if (showLogName)
|
||||
this.logName = name;
|
||||
} else {
|
||||
else
|
||||
this.logName = null;
|
||||
}
|
||||
this.showDateTime = showDateTime;
|
||||
this.showContextMap = showContextMap;
|
||||
this.stream = stream;
|
||||
|
||||
if (showDateTime) {
|
||||
if (showDateTime)
|
||||
try {
|
||||
this.dateFormatter = new SimpleDateFormat(dateTimeFormat);
|
||||
} catch (IllegalArgumentException e) {
|
||||
this.dateFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS zzz");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setStream(PrintStream stream) {
|
||||
this.stream = stream;
|
||||
@@ -72,10 +69,9 @@ public class SimpleLogger extends AbstractLogger {
|
||||
}
|
||||
|
||||
public void setLevel(Level level) {
|
||||
if (level != null) {
|
||||
if (level != null)
|
||||
this.level = level;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void abstractLog(Level level, IMessage msg, Throwable throwable) {
|
||||
@@ -100,11 +96,10 @@ public class SimpleLogger extends AbstractLogger {
|
||||
sb.append(msg.getFormattedMessage());
|
||||
Object[] params = msg.getParameters();
|
||||
Throwable t;
|
||||
if ((throwable == null) && (params != null) && ((params[(params.length - 1)] instanceof Throwable))) {
|
||||
if ((throwable == null) && (params != null) && ((params[(params.length - 1)] instanceof Throwable)))
|
||||
t = (Throwable) params[(params.length - 1)];
|
||||
} else {
|
||||
else
|
||||
t = throwable;
|
||||
}
|
||||
if (t != null) {
|
||||
sb.append(' ');
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
@@ -21,7 +21,7 @@ package org.jackhuang.hellominecraft.logging.message;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public abstract class AbstractMessageFactory
|
||||
implements IMessageFactory {
|
||||
implements IMessageFactory {
|
||||
|
||||
@Override
|
||||
public IMessage newMessage(Object message) {
|
||||
|
||||
@@ -23,8 +23,12 @@ import java.io.Serializable;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public interface IMessage extends Serializable {
|
||||
|
||||
String getFormattedMessage();
|
||||
|
||||
String getFormat();
|
||||
|
||||
Object[] getParameters();
|
||||
|
||||
Throwable getThrowable();
|
||||
}
|
||||
|
||||
@@ -17,15 +17,14 @@
|
||||
package org.jackhuang.hellominecraft.logging.message;
|
||||
|
||||
public class ObjectMessage
|
||||
implements IMessage {
|
||||
implements IMessage {
|
||||
|
||||
private static final long serialVersionUID = -5903272448334166185L;
|
||||
private final transient Object obj;
|
||||
|
||||
public ObjectMessage(Object obj) {
|
||||
if (obj == null) {
|
||||
if (obj == null)
|
||||
obj = "null";
|
||||
}
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
@@ -41,17 +40,15 @@ public class ObjectMessage
|
||||
|
||||
@Override
|
||||
public Object[] getParameters() {
|
||||
return new Object[]{this.obj};
|
||||
return new Object[] {this.obj};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
}
|
||||
if ((o == null) || (getClass() != o.getClass())) {
|
||||
if ((o == null) || (getClass() != o.getClass()))
|
||||
return false;
|
||||
}
|
||||
|
||||
ObjectMessage that = (ObjectMessage) o;
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import java.util.Set;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class ParameterizedMessage
|
||||
implements IMessage {
|
||||
implements IMessage {
|
||||
|
||||
public static final String RECURSION_PREFIX = "[...";
|
||||
public static final String RECURSION_SUFFIX = "...]";
|
||||
@@ -67,17 +67,16 @@ public class ParameterizedMessage
|
||||
}
|
||||
|
||||
public ParameterizedMessage(String messagePattern, Object arg) {
|
||||
this(messagePattern, new Object[]{arg});
|
||||
this(messagePattern, new Object[] {arg});
|
||||
}
|
||||
|
||||
public ParameterizedMessage(String messagePattern, Object arg1, Object arg2) {
|
||||
this(messagePattern, new Object[]{arg1, arg2});
|
||||
this(messagePattern, new Object[] {arg1, arg2});
|
||||
}
|
||||
|
||||
private String[] parseArguments(Object[] arguments) {
|
||||
if (arguments == null) {
|
||||
if (arguments == null)
|
||||
return null;
|
||||
}
|
||||
int argsCount = countArgumentPlaceholders(this.messagePattern);
|
||||
int resultArgCount = arguments.length;
|
||||
if ((argsCount < arguments.length)
|
||||
@@ -94,18 +93,16 @@ public class ParameterizedMessage
|
||||
strArgs[0] = deepToString(arguments);
|
||||
} else {
|
||||
strArgs = new String[resultArgCount];
|
||||
for (int i = 0; i < strArgs.length; i++) {
|
||||
for (int i = 0; i < strArgs.length; i++)
|
||||
strArgs[i] = deepToString(arguments[i]);
|
||||
}
|
||||
}
|
||||
return strArgs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFormattedMessage() {
|
||||
if (this.formattedMessage == null) {
|
||||
if (this.formattedMessage == null)
|
||||
this.formattedMessage = formatMessage(this.messagePattern, this.stringArgs);
|
||||
}
|
||||
return this.formattedMessage;
|
||||
}
|
||||
|
||||
@@ -116,9 +113,8 @@ public class ParameterizedMessage
|
||||
|
||||
@Override
|
||||
public Object[] getParameters() {
|
||||
if (this.argArray != null) {
|
||||
if (this.argArray != null)
|
||||
return this.argArray;
|
||||
}
|
||||
return this.stringArgs;
|
||||
}
|
||||
|
||||
@@ -133,8 +129,10 @@ public class ParameterizedMessage
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
|
||||
ParameterizedMessage that = (ParameterizedMessage) o;
|
||||
if (this.messagePattern != null ? !this.messagePattern.equals(that.messagePattern) : that.messagePattern != null)
|
||||
@@ -159,9 +157,9 @@ public class ParameterizedMessage
|
||||
int currentArgument = 0;
|
||||
for (int i = 0; i < messagePattern.length(); i++) {
|
||||
char curChar = messagePattern.charAt(i);
|
||||
if (curChar == ESCAPE_CHAR) {
|
||||
if (curChar == ESCAPE_CHAR)
|
||||
escapeCounter++;
|
||||
} else if ((curChar == DELIM_START)
|
||||
else if ((curChar == DELIM_START)
|
||||
&& (i < messagePattern.length() - 1)
|
||||
&& (messagePattern.charAt(i + 1) == DELIM_STOP)) {
|
||||
int escapedEscapes = escapeCounter / 2;
|
||||
@@ -193,18 +191,20 @@ public class ParameterizedMessage
|
||||
}
|
||||
|
||||
public static int countArgumentPlaceholders(String messagePattern) {
|
||||
if (messagePattern == null) return 0;
|
||||
if (messagePattern == null)
|
||||
return 0;
|
||||
|
||||
int delim = messagePattern.indexOf(123);
|
||||
|
||||
if (delim == -1) return 0;
|
||||
if (delim == -1)
|
||||
return 0;
|
||||
int result = 0;
|
||||
boolean isEscaped = false;
|
||||
for (int i = 0; i < messagePattern.length(); i++) {
|
||||
char curChar = messagePattern.charAt(i);
|
||||
if (curChar == ESCAPE_CHAR) {
|
||||
if (curChar == ESCAPE_CHAR)
|
||||
isEscaped = !isEscaped;
|
||||
} else if (curChar == DELIM_START) {
|
||||
else if (curChar == DELIM_START) {
|
||||
if ((!isEscaped)
|
||||
&& (i < messagePattern.length() - 1)
|
||||
&& (messagePattern.charAt(i + 1) == DELIM_STOP)) {
|
||||
@@ -213,16 +213,17 @@ public class ParameterizedMessage
|
||||
}
|
||||
|
||||
isEscaped = false;
|
||||
} else {
|
||||
} else
|
||||
isEscaped = false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String deepToString(Object o) {
|
||||
if (o == null) return null;
|
||||
if (o instanceof String) return (String) o;
|
||||
if (o == null)
|
||||
return null;
|
||||
if (o instanceof String)
|
||||
return (String) o;
|
||||
StringBuilder str = new StringBuilder();
|
||||
Set dejaVu = new HashSet();
|
||||
recursiveDeepToString(o, str, dejaVu);
|
||||
@@ -239,53 +240,57 @@ public class ParameterizedMessage
|
||||
return;
|
||||
}
|
||||
Class oClass = o.getClass();
|
||||
if (oClass.isArray()) {
|
||||
if (oClass == byte[].class) {
|
||||
if (oClass.isArray())
|
||||
if (oClass == byte[].class)
|
||||
str.append(Arrays.toString((byte[]) (byte[]) o));
|
||||
} else if (oClass == short[].class) {
|
||||
else if (oClass == short[].class)
|
||||
str.append(Arrays.toString((short[]) (short[]) o));
|
||||
} else if (oClass == int[].class) {
|
||||
else if (oClass == int[].class)
|
||||
str.append(Arrays.toString((int[]) (int[]) o));
|
||||
} else if (oClass == long[].class) {
|
||||
else if (oClass == long[].class)
|
||||
str.append(Arrays.toString((long[]) (long[]) o));
|
||||
} else if (oClass == float[].class) {
|
||||
else if (oClass == float[].class)
|
||||
str.append(Arrays.toString((float[]) (float[]) o));
|
||||
} else if (oClass == double[].class) {
|
||||
else if (oClass == double[].class)
|
||||
str.append(Arrays.toString((double[]) (double[]) o));
|
||||
} else if (oClass == boolean[].class) {
|
||||
else if (oClass == boolean[].class)
|
||||
str.append(Arrays.toString((boolean[]) (boolean[]) o));
|
||||
} else if (oClass == char[].class) {
|
||||
else if (oClass == char[].class)
|
||||
str.append(Arrays.toString((char[]) (char[]) o));
|
||||
} else {
|
||||
else {
|
||||
String id = identityToString(o);
|
||||
if (dejaVu.contains(id)) {
|
||||
if (dejaVu.contains(id))
|
||||
str.append("[...").append(id).append("...]");
|
||||
} else {
|
||||
else {
|
||||
dejaVu.add(id);
|
||||
Object[] oArray = (Object[]) (Object[]) o;
|
||||
str.append("[");
|
||||
boolean first = true;
|
||||
for (Object current : oArray) {
|
||||
if (first) first = false;
|
||||
else str.append(", ");
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
str.append(", ");
|
||||
recursiveDeepToString(current, str, new HashSet(dejaVu));
|
||||
}
|
||||
str.append("]");
|
||||
}
|
||||
}
|
||||
} else if ((o instanceof Map)) {
|
||||
else if ((o instanceof Map)) {
|
||||
String id = identityToString(o);
|
||||
if (dejaVu.contains(id)) {
|
||||
if (dejaVu.contains(id))
|
||||
str.append("[...").append(id).append("...]");
|
||||
} else {
|
||||
else {
|
||||
dejaVu.add(id);
|
||||
Map oMap = (Map) o;
|
||||
str.append("{");
|
||||
boolean isFirst = true;
|
||||
for (Object o1 : oMap.entrySet()) {
|
||||
Map.Entry current = (Map.Entry) o1;
|
||||
if (isFirst) isFirst = false;
|
||||
else str.append(", ");
|
||||
if (isFirst)
|
||||
isFirst = false;
|
||||
else
|
||||
str.append(", ");
|
||||
Object key = current.getKey();
|
||||
Object value = current.getValue();
|
||||
recursiveDeepToString(key, str, new HashSet(dejaVu));
|
||||
@@ -296,17 +301,19 @@ public class ParameterizedMessage
|
||||
}
|
||||
} else if ((o instanceof Collection)) {
|
||||
String id = identityToString(o);
|
||||
if (dejaVu.contains(id)) {
|
||||
if (dejaVu.contains(id))
|
||||
str.append("[...").append(id).append("...]");
|
||||
} else {
|
||||
else {
|
||||
dejaVu.add(id);
|
||||
Collection oCol = (Collection) o;
|
||||
str.append("[");
|
||||
boolean isFirst = true;
|
||||
for (Iterator i$ = oCol.iterator(); i$.hasNext();) {
|
||||
Object anOCol = i$.next();
|
||||
if (isFirst) isFirst = false;
|
||||
else str.append(", ");
|
||||
if (isFirst)
|
||||
isFirst = false;
|
||||
else
|
||||
str.append(", ");
|
||||
recursiveDeepToString(anOCol, str, new HashSet(dejaVu));
|
||||
}
|
||||
str.append("]");
|
||||
@@ -316,7 +323,7 @@ public class ParameterizedMessage
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
||||
|
||||
str.append(format.format(date));
|
||||
} else {
|
||||
} else
|
||||
try {
|
||||
str.append(o.toString());
|
||||
} catch (Throwable t) {
|
||||
@@ -333,15 +340,15 @@ public class ParameterizedMessage
|
||||
str.append("!!!]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String identityToString(Object obj) {
|
||||
if (obj == null) return null;
|
||||
return obj.getClass().getName()+"@"+Integer.toHexString(System.identityHashCode(obj));
|
||||
if (obj == null)
|
||||
return null;
|
||||
return obj.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(obj));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ParameterizedMessage[messagePattern="+this.messagePattern+", stringArgs="+Arrays.toString(this.stringArgs)+", throwable="+this.throwable+"]";
|
||||
return "ParameterizedMessage[messagePattern=" + this.messagePattern + ", stringArgs=" + Arrays.toString(this.stringArgs) + ", throwable=" + this.throwable + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ package org.jackhuang.hellominecraft.logging.message;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class SimpleMessage
|
||||
implements IMessage {
|
||||
implements IMessage {
|
||||
|
||||
private static final long serialVersionUID = -8398002534962715992L;
|
||||
private final String message;
|
||||
@@ -51,12 +51,10 @@ public class SimpleMessage
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
}
|
||||
if ((o == null) || (getClass() != o.getClass())) {
|
||||
if ((o == null) || (getClass() != o.getClass()))
|
||||
return false;
|
||||
}
|
||||
|
||||
SimpleMessage that = (SimpleMessage) o;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.Arrays;
|
||||
import java.util.IllegalFormatException;
|
||||
|
||||
public class StringFormattedMessage
|
||||
implements IMessage {
|
||||
implements IMessage {
|
||||
|
||||
private static final long serialVersionUID = -665975803997290697L;
|
||||
private final String messagePattern;
|
||||
@@ -32,16 +32,14 @@ public class StringFormattedMessage
|
||||
public StringFormattedMessage(String messagePattern, Object[] arguments) {
|
||||
this.messagePattern = messagePattern;
|
||||
this.argArray = arguments;
|
||||
if ((arguments != null) && (arguments.length > 0) && ((arguments[(arguments.length - 1)] instanceof Throwable))) {
|
||||
if ((arguments != null) && (arguments.length > 0) && ((arguments[(arguments.length - 1)] instanceof Throwable)))
|
||||
this.throwable = ((Throwable) arguments[(arguments.length - 1)]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFormattedMessage() {
|
||||
if (this.formattedMessage == null) {
|
||||
if (this.formattedMessage == null)
|
||||
this.formattedMessage = formatMessage(this.messagePattern, this.argArray);
|
||||
}
|
||||
return this.formattedMessage;
|
||||
}
|
||||
|
||||
@@ -52,9 +50,8 @@ public class StringFormattedMessage
|
||||
|
||||
@Override
|
||||
public Object[] getParameters() {
|
||||
if (this.argArray != null) {
|
||||
if (this.argArray != null)
|
||||
return this.argArray;
|
||||
}
|
||||
return this.stringArgs;
|
||||
}
|
||||
|
||||
@@ -70,18 +67,15 @@ public class StringFormattedMessage
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
}
|
||||
if ((o == null) || (getClass() != o.getClass())) {
|
||||
if ((o == null) || (getClass() != o.getClass()))
|
||||
return false;
|
||||
}
|
||||
|
||||
StringFormattedMessage that = (StringFormattedMessage) o;
|
||||
|
||||
if (this.messagePattern != null ? !this.messagePattern.equals(that.messagePattern) : that.messagePattern != null) {
|
||||
if (this.messagePattern != null ? !this.messagePattern.equals(that.messagePattern) : that.messagePattern != null)
|
||||
return false;
|
||||
}
|
||||
|
||||
return Arrays.equals(this.stringArgs, that.stringArgs);
|
||||
}
|
||||
|
||||
@@ -98,7 +98,8 @@ public class TaskList extends Thread {
|
||||
}
|
||||
while (!runningThread.isEmpty())
|
||||
try {
|
||||
if (this.isInterrupted()) return;
|
||||
if (this.isInterrupted())
|
||||
return;
|
||||
Thread.sleep(1);
|
||||
} catch (InterruptedException ignore) {
|
||||
}
|
||||
@@ -119,7 +120,7 @@ public class TaskList extends Thread {
|
||||
boolean returns = false;
|
||||
try {
|
||||
returns = t.executeTask();
|
||||
} catch(Throwable e) {
|
||||
} catch (Throwable e) {
|
||||
t.setFailReason(e);
|
||||
}
|
||||
if (returns) {
|
||||
@@ -144,7 +145,7 @@ public class TaskList extends Thread {
|
||||
|
||||
threadPool.clear();
|
||||
totTask = taskQueue.size();
|
||||
while(!taskQueue.isEmpty())
|
||||
while (!taskQueue.isEmpty())
|
||||
executeTask(taskQueue.remove(0));
|
||||
if (shouldContinue)
|
||||
for (Runnable d : allDone)
|
||||
@@ -160,7 +161,8 @@ public class TaskList extends Thread {
|
||||
while (!threadPool.isEmpty())
|
||||
synchronized (threadPool) {
|
||||
InvokeThread it = threadPool.iterator().next();
|
||||
if (!it.task.abort()) it.interrupt();
|
||||
if (!it.task.abort())
|
||||
it.interrupt();
|
||||
threadPool.remove(it);
|
||||
}
|
||||
this.interrupt();
|
||||
|
||||
@@ -27,7 +27,9 @@ import org.jackhuang.hellominecraft.utils.functions.Consumer;
|
||||
* @param <T> Runnable<T>
|
||||
*/
|
||||
public class TaskRunnableArg1<T> extends TaskInfo implements PreviousResultRegistrar<T> {
|
||||
|
||||
private final Consumer<T> r;
|
||||
|
||||
public TaskRunnableArg1(String info, Consumer<T> r) {
|
||||
super(info);
|
||||
this.r = r;
|
||||
@@ -35,11 +37,12 @@ public class TaskRunnableArg1<T> extends TaskInfo implements PreviousResultRegis
|
||||
|
||||
@Override
|
||||
public boolean executeTask() {
|
||||
if(al.size() != 1) throw new IllegalStateException("the count of args is not one.");
|
||||
if (al.size() != 1)
|
||||
throw new IllegalStateException("the count of args is not one.");
|
||||
try {
|
||||
r.accept(al.get(0).getResult());
|
||||
return true;
|
||||
} catch(Throwable t) {
|
||||
} catch (Throwable t) {
|
||||
setFailReason(t);
|
||||
return false;
|
||||
}
|
||||
@@ -53,6 +56,4 @@ public class TaskRunnableArg1<T> extends TaskInfo implements PreviousResultRegis
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -30,7 +30,7 @@ import org.jackhuang.hellominecraft.utils.SwingUtils;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class TaskWindow extends javax.swing.JDialog
|
||||
implements ProgressProviderListener, Runnable, DoingDoneListener<Task> {
|
||||
implements ProgressProviderListener, Runnable, DoingDoneListener<Task> {
|
||||
|
||||
private static final TaskWindow instance = new TaskWindow();
|
||||
|
||||
@@ -72,14 +72,16 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
}
|
||||
|
||||
public synchronized void clean() {
|
||||
if (isVisible()) return;
|
||||
if (isVisible())
|
||||
return;
|
||||
taskList = new TaskList();
|
||||
taskList.addTaskListener(this);
|
||||
taskList.addAllDoneListener(this);
|
||||
}
|
||||
|
||||
public boolean start() {
|
||||
if (isVisible() || taskList == null || taskList.isAlive()) return false;
|
||||
if (isVisible() || taskList == null || taskList.isAlive())
|
||||
return false;
|
||||
pgsTotal.setValue(0);
|
||||
suc = false;
|
||||
SwingUtils.clearDefaultTable(lstDownload);
|
||||
@@ -169,7 +171,8 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
}//GEN-LAST:event_btnCancelActionPerformed
|
||||
|
||||
private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
|
||||
if(taskList == null) return;
|
||||
if (taskList == null)
|
||||
return;
|
||||
tasks.clear();
|
||||
|
||||
if (!this.failReasons.isEmpty()) {
|
||||
@@ -203,7 +206,8 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
public void setProgress(Task task, int progress, int max) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
int idx = tasks.indexOf(task);
|
||||
if (idx == -1) return;
|
||||
if (idx == -1)
|
||||
return;
|
||||
int pgs = progress * 100 / max;
|
||||
if (progresses.contains(idx) && progresses.get(idx) != pgs && lstDownload.getRowCount() > idx) {
|
||||
SwingUtils.setValueAt(lstDownload, pgs + "%", idx, 1);
|
||||
@@ -224,7 +228,8 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
task.setProgressProviderListener(this);
|
||||
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
if(taskList == null) return;
|
||||
if (taskList == null)
|
||||
return;
|
||||
tasks.add(task);
|
||||
progresses.add(0);
|
||||
SwingUtils.appendLast(lstDownload, task.getInfo(), "0%");
|
||||
@@ -239,11 +244,13 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
@Override
|
||||
public void onDone(Task task) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
if(taskList == null) return;
|
||||
if (taskList == null)
|
||||
return;
|
||||
pgsTotal.setMaximum(taskList.taskCount());
|
||||
pgsTotal.setValue(pgsTotal.getValue() + 1);
|
||||
int idx = tasks.indexOf(task);
|
||||
if (idx == -1) return;
|
||||
if (idx == -1)
|
||||
return;
|
||||
tasks.remove(idx);
|
||||
progresses.remove(idx);
|
||||
SwingUtils.removeRow(lstDownload, idx);
|
||||
@@ -253,12 +260,14 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
@Override
|
||||
public void onFailed(Task task) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
if(taskList == null) return;
|
||||
if (taskList == null)
|
||||
return;
|
||||
failReasons.add(task.getInfo() + ": " + (null == task.getFailReason() ? "No exception" : (StrUtils.isBlank(task.getFailReason().getLocalizedMessage()) ? task.getFailReason().getClass().getSimpleName() : task.getFailReason().getLocalizedMessage())));
|
||||
pgsTotal.setMaximum(taskList.taskCount());
|
||||
pgsTotal.setValue(pgsTotal.getValue() + 1);
|
||||
int idx = tasks.indexOf(task);
|
||||
if (idx == -1) return;
|
||||
if (idx == -1)
|
||||
return;
|
||||
SwingUtils.setValueAt(lstDownload, task.getFailReason(), idx, 0);
|
||||
SwingUtils.setValueAt(lstDownload, "0%", idx, 1);
|
||||
SwingUtils.moveEnd(srlDownload);
|
||||
@@ -273,14 +282,17 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
@Override
|
||||
public void setStatus(Task task, String sta) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
if(taskList == null) return;
|
||||
if (taskList == null)
|
||||
return;
|
||||
int idx = tasks.indexOf(task);
|
||||
if (idx == -1) return;
|
||||
if (idx == -1)
|
||||
return;
|
||||
SwingUtils.setValueAt(lstDownload, task.getInfo() + ": " + sta, idx, 0);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TaskWindowFactory {
|
||||
|
||||
LinkedList<Task> ll = new LinkedList<>();
|
||||
|
||||
public TaskWindowFactory addTask(Task t) {
|
||||
@@ -289,10 +301,12 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
}
|
||||
|
||||
public boolean start() {
|
||||
synchronized(instance) {
|
||||
if (instance.isVisible()) return false;
|
||||
synchronized (instance) {
|
||||
if (instance.isVisible())
|
||||
return false;
|
||||
TaskWindow tw = inst();
|
||||
for(Task t : ll) tw.addTask(t);
|
||||
for (Task t : ll)
|
||||
tw.addTask(t);
|
||||
return tw.start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ public interface PreviousResultRegistrar<T> {
|
||||
/**
|
||||
*
|
||||
* @param pr previous task handler
|
||||
*
|
||||
* @return task self instance
|
||||
*/
|
||||
Task registerPreviousResult(PreviousResult<T> pr);
|
||||
|
||||
@@ -25,5 +25,6 @@ import org.jackhuang.hellominecraft.tasks.ProgressProviderListener;
|
||||
public interface DownloadListener extends ProgressProviderListener {
|
||||
|
||||
boolean OnFailed();
|
||||
|
||||
void OnFailedMoreThan5Times(String url);
|
||||
}
|
||||
@@ -167,7 +167,8 @@ public class FileDownloadTask extends Task implements PreviousResult<File>, Prev
|
||||
if (aborted)
|
||||
tempFile.delete();
|
||||
else {
|
||||
if (filePath.exists()) filePath.delete();
|
||||
if (filePath.exists())
|
||||
filePath.delete();
|
||||
tempFile.renameTo(filePath);
|
||||
}
|
||||
if (ppl != null)
|
||||
|
||||
@@ -52,7 +52,8 @@ public class HTTPGetTask extends TaskInfo implements PreviousResult<String> {
|
||||
@Override
|
||||
public boolean executeTask() {
|
||||
for (int repeat = 0; repeat < 6; repeat++) {
|
||||
if (repeat > 0) HMCLog.warn("Failed to download, repeat: " + repeat);
|
||||
if (repeat > 0)
|
||||
HMCLog.warn("Failed to download, repeat: " + repeat);
|
||||
try {
|
||||
URLConnection conn = new URL(url).openConnection();
|
||||
InputStream is = conn.getInputStream();
|
||||
@@ -61,13 +62,11 @@ public class HTTPGetTask extends TaskInfo implements PreviousResult<String> {
|
||||
int size = conn.getContentLength(), read = 0;
|
||||
while ((i = is.read()) != -1) {
|
||||
baos.write(i);
|
||||
if (ppl != null) {
|
||||
if (ppl != null)
|
||||
ppl.setProgress(this, ++read, size);
|
||||
}
|
||||
if (!shouldContinue) {
|
||||
if (!shouldContinue)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
result = baos.toString();
|
||||
tdtsl.execute(result);
|
||||
return true;
|
||||
|
||||
@@ -78,8 +78,10 @@ public class ArrayUtils {
|
||||
}
|
||||
|
||||
public static <K> K getEnd(K[] k) {
|
||||
if (k == null) return null;
|
||||
else return k[k.length - 1];
|
||||
if (k == null)
|
||||
return null;
|
||||
else
|
||||
return k[k.length - 1];
|
||||
}
|
||||
|
||||
public static List tryGetMapWithList(Map map, String key) {
|
||||
|
||||
@@ -29,13 +29,15 @@ import java.util.Iterator;
|
||||
public final class CollectionUtils {
|
||||
|
||||
public static <T> void forEach(Collection<T> coll, Consumer<T> p) {
|
||||
for (T t : coll) p.accept(t);
|
||||
for (T t : coll)
|
||||
p.accept(t);
|
||||
}
|
||||
|
||||
public static <T> Collection<T> sortOut(Collection<T> coll, Predicate<T> p) {
|
||||
ArrayList<T> newColl = new ArrayList<>();
|
||||
forEach(coll, t -> {
|
||||
if (p.apply(t)) newColl.add(t);
|
||||
if (p.apply(t))
|
||||
newColl.add(t);
|
||||
});
|
||||
return newColl;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,8 @@ public class EventHandler<T> {
|
||||
public boolean execute(T x) {
|
||||
boolean flag = true;
|
||||
for (Event<T> t : handlers)
|
||||
if (!t.call(sender, x)) flag = false;
|
||||
if (!t.call(sender, x))
|
||||
flag = false;
|
||||
return flag;
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ public class LogWindowOutputStream extends OutputStream {
|
||||
|
||||
@Override
|
||||
public final void write(int paramInt) {
|
||||
append(new String(new byte[]{(byte) paramInt}));
|
||||
append(new String(new byte[] {(byte) paramInt}));
|
||||
}
|
||||
|
||||
public static void dispose() {
|
||||
|
||||
@@ -44,9 +44,12 @@ public class MathUtils {
|
||||
return Integer.parseInt(s);
|
||||
} catch (Exception e) {
|
||||
int a = parseInt(s.substring(0, s.length() - 1), def);
|
||||
if (s.endsWith("g")) return a * 1024;
|
||||
else if (s.endsWith("k")) return a / 1024;
|
||||
else return a;
|
||||
if (s.endsWith("g"))
|
||||
return a * 1024;
|
||||
else if (s.endsWith("k"))
|
||||
return a / 1024;
|
||||
else
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,7 @@ public final class NetUtils {
|
||||
* @param requestParameters - all the request parameters (Example:
|
||||
* "param1=val1¶m2=val2"). Note: This method will add the question mark
|
||||
* (?) to the request - DO NOT add it yourself
|
||||
*
|
||||
* @return - The response from the end point
|
||||
*/
|
||||
public static String sendGetRequest(String endpoint,
|
||||
@@ -157,7 +158,8 @@ public final class NetUtils {
|
||||
os = con.getOutputStream();
|
||||
IOUtils.write(post, os, DEFAULT_CHARSET);
|
||||
} finally {
|
||||
if (os != null) IOUtils.closeQuietly(os);
|
||||
if (os != null)
|
||||
IOUtils.closeQuietly(os);
|
||||
}
|
||||
|
||||
String result = null;
|
||||
@@ -165,8 +167,9 @@ public final class NetUtils {
|
||||
try {
|
||||
is = con.getInputStream();
|
||||
result = getStreamContent(is);
|
||||
} catch(IOException ex) {
|
||||
if (is != null) IOUtils.closeQuietly(is);
|
||||
} catch (IOException ex) {
|
||||
if (is != null)
|
||||
IOUtils.closeQuietly(is);
|
||||
is = con.getErrorStream();
|
||||
result = getStreamContent(is);
|
||||
}
|
||||
|
||||
@@ -34,38 +34,33 @@ public final class StrUtils {
|
||||
public static String substring(String src, int start_idx, int end_idx) {
|
||||
byte[] b = src.getBytes();
|
||||
String tgt = "";
|
||||
for (int i = start_idx; i <= end_idx; i++) {
|
||||
for (int i = start_idx; i <= end_idx; i++)
|
||||
tgt += (char) b[i];
|
||||
}
|
||||
return tgt;
|
||||
}
|
||||
|
||||
public static String makeCommand(List<String> cmd) {
|
||||
StringBuilder cmdbuf = new StringBuilder(120);
|
||||
for (int i = 0; i < cmd.size(); i++) {
|
||||
if (i > 0) {
|
||||
if (i > 0)
|
||||
cmdbuf.append(' ');
|
||||
}
|
||||
String s = cmd.get(i);
|
||||
if (s.indexOf(' ') >= 0 || s.indexOf('\t') >= 0) {
|
||||
if (s.indexOf(' ') >= 0 || s.indexOf('\t') >= 0)
|
||||
if (s.charAt(0) != '"') {
|
||||
cmdbuf.append('"');
|
||||
cmdbuf.append(s);
|
||||
if (s.endsWith("\\")) {
|
||||
if (s.endsWith("\\"))
|
||||
cmdbuf.append("\\");
|
||||
}
|
||||
cmdbuf.append('"');
|
||||
} else if (s.endsWith("\"")) {
|
||||
} else if (s.endsWith("\""))
|
||||
/* The argument has already been quoted. */
|
||||
cmdbuf.append(s);
|
||||
} else {
|
||||
else
|
||||
/* Unmatched quote for the argument. */
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
} else {
|
||||
else
|
||||
cmdbuf.append(s);
|
||||
}
|
||||
}
|
||||
String str = cmdbuf.toString();
|
||||
|
||||
return str;
|
||||
@@ -76,119 +71,99 @@ public final class StrUtils {
|
||||
}
|
||||
|
||||
public static boolean startsWithOne(String[] a, String match) {
|
||||
if (a == null) {
|
||||
if (a == null)
|
||||
return false;
|
||||
}
|
||||
for (String b : a) {
|
||||
if (startsWith(match, b)) {
|
||||
for (String b : a)
|
||||
if (startsWith(match, b))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean equalsOne(String base, String... a) {
|
||||
for (String s : a) {
|
||||
if (base.equals(s)) {
|
||||
for (String s : a)
|
||||
if (base.equals(s))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean containsOne(List<String> base, List<String> match) {
|
||||
for (String a : base) {
|
||||
for (String b : match) {
|
||||
if (a.toLowerCase().contains(b.toLowerCase())) {
|
||||
for (String a : base)
|
||||
for (String b : match)
|
||||
if (a.toLowerCase().contains(b.toLowerCase()))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int getCharShowTime(String s, char c) {
|
||||
int res = 0;
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
if (s.charAt(i) == c) {
|
||||
for (int i = 0; i < s.length(); i++)
|
||||
if (s.charAt(i) == c)
|
||||
res++;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static String formatVersion(String ver) {
|
||||
if (isBlank(ver)) {
|
||||
if (isBlank(ver))
|
||||
return null;
|
||||
else
|
||||
for (char ch : ver.toCharArray())
|
||||
if ((ch < '0' || ch > '9') && ch != '.')
|
||||
return null;
|
||||
} else {
|
||||
for(char ch : ver.toCharArray()) {
|
||||
if((ch < '0' || ch > '9') && ch != '.') return null;
|
||||
}
|
||||
}
|
||||
int i = getCharShowTime(ver, '.');
|
||||
if (i == 1) {
|
||||
if (i == 1)
|
||||
return ver + ".0";
|
||||
} else {
|
||||
else
|
||||
return ver;
|
||||
}
|
||||
}
|
||||
|
||||
public static String parseParams(String addBefore, Collection paramArrayOfObject, String paramString) {
|
||||
return parseParams(addBefore, paramArrayOfObject.toArray(), paramString);
|
||||
}
|
||||
|
||||
public static String parseParams(String addBefore, Object[] paramArrayOfObject, String paramString) {
|
||||
if (paramArrayOfObject == null) {
|
||||
if (paramArrayOfObject == null)
|
||||
return "";
|
||||
}
|
||||
StringBuilder localStringBuffer = new StringBuilder();
|
||||
for (int i = 0; i < paramArrayOfObject.length; i++) {
|
||||
Object localObject = paramArrayOfObject[i];
|
||||
if (i > 0) {
|
||||
if (i > 0)
|
||||
localStringBuffer.append(addBefore).append(paramString);
|
||||
}
|
||||
if (localObject == null) {
|
||||
if (localObject == null)
|
||||
localStringBuffer.append("null");
|
||||
} else if (localObject.getClass().isArray()) {
|
||||
else if (localObject.getClass().isArray()) {
|
||||
localStringBuffer.append("[");
|
||||
|
||||
if ((localObject instanceof Object[])) {
|
||||
Object[] arrayOfObject = (Object[]) localObject;
|
||||
localStringBuffer.append(parseParams(addBefore, arrayOfObject, paramString));
|
||||
} else {
|
||||
} else
|
||||
for (int j = 0; j < Array.getLength(localObject); j++) {
|
||||
if (j > 0) {
|
||||
if (j > 0)
|
||||
localStringBuffer.append(paramString);
|
||||
}
|
||||
localStringBuffer.append(addBefore).append(Array.get(localObject, j));
|
||||
}
|
||||
}
|
||||
localStringBuffer.append("]");
|
||||
} else {
|
||||
} else
|
||||
localStringBuffer.append(addBefore).append(paramArrayOfObject[i]);
|
||||
}
|
||||
}
|
||||
return localStringBuffer.toString();
|
||||
}
|
||||
|
||||
public static boolean isEquals(String base, String to) {
|
||||
if (base == null) {
|
||||
if (base == null)
|
||||
return (to == null);
|
||||
} else {
|
||||
else
|
||||
return base.equals(to);
|
||||
}
|
||||
}
|
||||
|
||||
public static Dimension parseDimension(String str) {
|
||||
String[] tokenized = tokenize(str, "x,");
|
||||
if (tokenized.length != 2) {
|
||||
if (tokenized.length != 2)
|
||||
return null;
|
||||
}
|
||||
int i = MathUtils.parseInt(tokenized[0], -1);
|
||||
int j = MathUtils.parseInt(tokenized[1], -1);
|
||||
if ((i < 0) || (j < 0)) {
|
||||
if ((i < 0) || (j < 0))
|
||||
return null;
|
||||
}
|
||||
return new Dimension(i, j);
|
||||
}
|
||||
|
||||
@@ -210,10 +185,9 @@ public final class StrUtils {
|
||||
public static String trimExtension(String filename) {
|
||||
if ((filename != null) && (filename.length() > 0)) {
|
||||
int i = filename.lastIndexOf('.');
|
||||
if ((i > -1) && (i < (filename.length()))) {
|
||||
if ((i > -1) && (i < (filename.length())))
|
||||
return filename.substring(0, i);
|
||||
}
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,11 +41,12 @@ public class SwingUtils {
|
||||
* @param titleA The title of each column.
|
||||
* @param typesA The type of each column value.
|
||||
* @param canEditA Is column editable?
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static DefaultTableModel makeDefaultTableModel(String[] titleA, final Class[] typesA, final boolean[] canEditA) {
|
||||
return new javax.swing.table.DefaultTableModel(
|
||||
new Object[][]{},
|
||||
new Object[][] {},
|
||||
titleA) {
|
||||
Class[] types = typesA;
|
||||
boolean[] canEdit = canEditA;
|
||||
@@ -99,6 +100,7 @@ public class SwingUtils {
|
||||
* Get the DefaultListModel from JList.
|
||||
*
|
||||
* @param list
|
||||
*
|
||||
* @return Forcely Type casted to DefaultListModel
|
||||
*/
|
||||
public static DefaultListModel getDefaultListModel(JList list) {
|
||||
@@ -152,12 +154,14 @@ public class SwingUtils {
|
||||
}
|
||||
|
||||
public static String getParsedJPanelText(JLabel jLabel1, String longString) {
|
||||
if (StrUtils.isBlank(longString)) return longString;
|
||||
if (StrUtils.isBlank(longString))
|
||||
return longString;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
char[] chars = longString.toCharArray();
|
||||
FontMetrics fontMetrics = jLabel1.getFontMetrics(jLabel1.getFont());
|
||||
for (int beginIndex = 0, limit = 1;; limit++) {
|
||||
if (beginIndex + limit >= chars.length) break;
|
||||
if (beginIndex + limit >= chars.length)
|
||||
break;
|
||||
if (fontMetrics.charsWidth(chars, beginIndex, limit) < jLabel1.getWidth()) {
|
||||
if (beginIndex + limit < chars.length)
|
||||
continue;
|
||||
|
||||
@@ -60,7 +60,9 @@ public final class Utils {
|
||||
Field field = ClassLoader.class.getDeclaredField("usr_paths");
|
||||
field.setAccessible(true);
|
||||
String[] paths = (String[]) field.get(null);
|
||||
for (String path : paths) if (s.equals(path)) return;
|
||||
for (String path : paths)
|
||||
if (s.equals(path))
|
||||
return;
|
||||
String[] tmp = new String[paths.length + 1];
|
||||
System.arraycopy(paths, 0, tmp, 0, paths.length);
|
||||
tmp[paths.length] = s;
|
||||
@@ -166,6 +168,7 @@ public final class Utils {
|
||||
|
||||
/**
|
||||
* In order to fight against the permission manager by Minecraft Forge.
|
||||
*
|
||||
* @param status exit code
|
||||
*/
|
||||
public static void shutdownForcely(int status) {
|
||||
@@ -181,6 +184,7 @@ public final class Utils {
|
||||
}
|
||||
|
||||
public static void requireNonNull(Object o) {
|
||||
if (o == null) throw new NullPointerException("Oh dear, there is a problem...");
|
||||
if (o == null)
|
||||
throw new NullPointerException("Oh dear, there is a problem...");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,9 +68,12 @@ public final class VersionNumber implements Comparable<VersionNumber> {
|
||||
|
||||
@Override
|
||||
public int compareTo(VersionNumber o) {
|
||||
if (isOlder(this, o)) return -1;
|
||||
else if (isOlder(o, this)) return 1;
|
||||
else return 0;
|
||||
if (isOlder(this, o))
|
||||
return -1;
|
||||
else if (isOlder(o, this))
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,12 +61,10 @@ public class Base64 {
|
||||
|
||||
public static byte[] decode(char[] data) {
|
||||
int len = ((data.length + 3) / 4) * 3;
|
||||
if (data.length > 0 && data[data.length - 1] == '=') {
|
||||
if (data.length > 0 && data[data.length - 1] == '=')
|
||||
--len;
|
||||
}
|
||||
if (data.length > 1 && data[data.length - 2] == '=') {
|
||||
if (data.length > 1 && data[data.length - 2] == '=')
|
||||
--len;
|
||||
}
|
||||
byte[] out = new byte[len];
|
||||
int shift = 0;
|
||||
int accum = 0;
|
||||
@@ -83,9 +81,8 @@ public class Base64 {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (index != out.length) {
|
||||
if (index != out.length)
|
||||
throw new Error("miscalculated data length!");
|
||||
}
|
||||
return out;
|
||||
}
|
||||
private static final char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
|
||||
@@ -93,18 +90,14 @@ public class Base64 {
|
||||
private static final byte[] codes = new byte[256];
|
||||
|
||||
static {
|
||||
for (int i = 0; i < 256; i++) {
|
||||
for (int i = 0; i < 256; i++)
|
||||
codes[i] = -1;
|
||||
}
|
||||
for (int i = 'A'; i <= 'Z'; i++) {
|
||||
for (int i = 'A'; i <= 'Z'; i++)
|
||||
codes[i] = (byte) (i - 'A');
|
||||
}
|
||||
for (int i = 'a'; i <= 'z'; i++) {
|
||||
for (int i = 'a'; i <= 'z'; i++)
|
||||
codes[i] = (byte) (26 + i - 'a');
|
||||
}
|
||||
for (int i = '0'; i <= '9'; i++) {
|
||||
for (int i = '0'; i <= '9'; i++)
|
||||
codes[i] = (byte) (52 + i - '0');
|
||||
}
|
||||
codes['+'] = 62;
|
||||
codes['/'] = 63;
|
||||
}
|
||||
|
||||
@@ -30,9 +30,8 @@ public class Hex {
|
||||
public static byte[] decodeHex(char[] data) throws Exception {
|
||||
int len = data.length;
|
||||
|
||||
if ((len & 0x1) != 0) {
|
||||
if ((len & 0x1) != 0)
|
||||
throw new Exception("Odd number of characters.");
|
||||
}
|
||||
|
||||
byte[] out = new byte[len >> 1];
|
||||
|
||||
@@ -74,9 +73,8 @@ public class Hex {
|
||||
|
||||
protected static int toDigit(char ch, int index) throws Exception {
|
||||
int digit = Character.digit(ch, 16);
|
||||
if (digit == -1) {
|
||||
if (digit == -1)
|
||||
throw new Exception("Illegal hexadecimal character " + ch + " at index " + index);
|
||||
}
|
||||
return digit;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,8 @@ public class TrueFunction implements NonFunction<Boolean> {
|
||||
|
||||
public static final TrueFunction instance = new TrueFunction();
|
||||
|
||||
private TrueFunction(){}
|
||||
private TrueFunction() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean apply() {
|
||||
|
||||
@@ -44,6 +44,7 @@ public class Compressor {
|
||||
*
|
||||
* @param sourceDir 源文件夹
|
||||
* @param zipFile 压缩生成的zip文件路径。
|
||||
*
|
||||
* @throws java.io.IOException 压缩失败或无法读取
|
||||
*/
|
||||
public static void zip(File sourceDir, File zipFile) throws IOException {
|
||||
@@ -113,6 +114,7 @@ public class Compressor {
|
||||
* @param zipFileName zip文件路径
|
||||
* @param extPlace 待压缩文件根目录
|
||||
* @param without 带前缀的不解压
|
||||
*
|
||||
* @throws java.io.IOException 解压失败或无法写入
|
||||
*/
|
||||
public static void unzip(File zipFileName, File extPlace, String[] without) throws IOException {
|
||||
@@ -125,7 +127,8 @@ public class Compressor {
|
||||
while (e.hasMoreElements()) {
|
||||
ZipEntry zipEnt = (ZipEntry) e.nextElement();
|
||||
gbkPath = zipEnt.getName();
|
||||
if (StrUtils.startsWithOne(without, gbkPath)) continue;
|
||||
if (StrUtils.startsWithOne(without, gbkPath))
|
||||
continue;
|
||||
if (zipEnt.isDirectory()) {
|
||||
strtemp = strPath + File.separator + gbkPath;
|
||||
File dir = new File(strtemp);
|
||||
@@ -161,6 +164,7 @@ public class Compressor {
|
||||
*
|
||||
* @param destFile zip1
|
||||
* @param srcFile zip2
|
||||
*
|
||||
* @throws java.io.IOException 无法写入或读取
|
||||
*/
|
||||
public static void merge(File destFile, File srcFile) throws IOException {
|
||||
|
||||
@@ -435,9 +435,11 @@ public class FileUtils {
|
||||
public static File[] searchSuffix(File dir, String suffix) {
|
||||
ArrayList<File> al = new ArrayList();
|
||||
File[] files = dir.listFiles();
|
||||
if (files == null) return new File[0];
|
||||
if (files == null)
|
||||
return new File[0];
|
||||
for (File f : files)
|
||||
if (f.getName().endsWith(suffix)) al.add(f);
|
||||
if (f.getName().endsWith(suffix))
|
||||
al.add(f);
|
||||
return al.toArray(new File[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,10 +284,9 @@ public class IOUtils {
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(jp.getRawProcess().getInputStream()))) {
|
||||
jp.getRawProcess().waitFor();
|
||||
String line;
|
||||
while((line = br.readLine()) != null) {
|
||||
while ((line = br.readLine()) != null)
|
||||
lines.add(line);
|
||||
}
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
@@ -297,10 +296,9 @@ public class IOUtils {
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(jp.getRawProcess().getErrorStream()))) {
|
||||
jp.getRawProcess().waitFor();
|
||||
String line;
|
||||
while((line = br.readLine()) != null) {
|
||||
while ((line = br.readLine()) != null)
|
||||
lines.add(line);
|
||||
}
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,8 @@ public class Java {
|
||||
if (obj instanceof Java) {
|
||||
Java j = (Java) obj;
|
||||
return (j.getName() == null && this.getName() == null) || ((Java) obj).getName().equals(this.getName());
|
||||
} else return false;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,8 +89,10 @@ public class Java {
|
||||
for (String java : javas) {
|
||||
int s = 0;
|
||||
for (char c : java.toCharArray())
|
||||
if (c == '.') s++;
|
||||
if (s <= 1) continue;
|
||||
if (c == '.')
|
||||
s++;
|
||||
if (s <= 1)
|
||||
continue;
|
||||
String javahome = queryRegValue(java, "JavaHome");
|
||||
if (javahome != null)
|
||||
ans.add(new Java(java.substring("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\".length()), javahome));
|
||||
@@ -98,8 +101,10 @@ public class Java {
|
||||
for (String java : javas) {
|
||||
int s = 0;
|
||||
for (char c : java.toCharArray())
|
||||
if (c == '.') s++;
|
||||
if (s <= 1) continue;
|
||||
if (c == '.')
|
||||
s++;
|
||||
if (s <= 1)
|
||||
continue;
|
||||
String javahome = queryRegValue(java, "JavaHome");
|
||||
if (javahome != null)
|
||||
ans.add(new Java(java.substring("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\".length()), javahome));
|
||||
@@ -111,7 +116,7 @@ public class Java {
|
||||
}
|
||||
|
||||
private static List<String> queryRegSubFolders(String location) throws IOException, InterruptedException {
|
||||
String[] cmd = new String[]{"cmd", "/c", "reg", "query", location};
|
||||
String[] cmd = new String[] {"cmd", "/c", "reg", "query", location};
|
||||
List<String> l = IOUtils.readProcessByInputStream(cmd);
|
||||
List<String> ans = new ArrayList<>();
|
||||
for (String line : l)
|
||||
@@ -121,11 +126,12 @@ public class Java {
|
||||
}
|
||||
|
||||
private static String queryRegValue(String location, String name) throws IOException, InterruptedException {
|
||||
String[] cmd = new String[]{"cmd", "/c", "reg", "query", location, "/v", name};
|
||||
String[] cmd = new String[] {"cmd", "/c", "reg", "query", location, "/v", name};
|
||||
List<String> l = IOUtils.readProcessByInputStream(cmd);
|
||||
boolean last = false;
|
||||
for (String s : l) {
|
||||
if (s.trim().isEmpty()) continue;
|
||||
if (s.trim().isEmpty())
|
||||
continue;
|
||||
if (last == true && s.trim().startsWith(name)) {
|
||||
int begins = s.indexOf(name);
|
||||
if (begins > 0) {
|
||||
@@ -137,7 +143,8 @@ public class Java {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (s.trim().equals(location)) last = true;
|
||||
if (s.trim().equals(location))
|
||||
last = true;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,8 @@ public class JavaProcess {
|
||||
public JavaProcess(List<String> commands, Process process, ProcessManager pm) {
|
||||
this.commands = commands;
|
||||
this.process = process;
|
||||
if (pm != null) pm.registerProcess(this);
|
||||
if (pm != null)
|
||||
pm.registerProcess(this);
|
||||
}
|
||||
|
||||
public JavaProcess(String[] commands, Process process, ProcessManager pm) {
|
||||
|
||||
@@ -40,16 +40,16 @@ public class JavaProcessMonitor {
|
||||
|
||||
public void start() {
|
||||
Event<JavaProcess> event = (sender2, t) -> {
|
||||
if(t.getExitCode() != 0) {
|
||||
if (t.getExitCode() != 0)
|
||||
MessageBox.Show(C.i18n("launch.exited_abnormally"));
|
||||
}
|
||||
processThreadStopped((ProcessThread) sender2, false);
|
||||
return true;
|
||||
};
|
||||
Event<JavaProcess> event2 = (sender3, p1) -> {
|
||||
if (p1.getExitCode() != 0 && p1.getStdErrLines().size() > 0 && StrUtils.containsOne(p1.getStdErrLines(), Arrays.asList("Could not create the Java Virtual Machine.",
|
||||
"Error occurred during initialization of VM",
|
||||
"A fatal exception has occurred. Program will exit."))) MessageBox.Show(C.i18n("launch.cannot_create_jvm"));
|
||||
"A fatal exception has occurred. Program will exit.")))
|
||||
MessageBox.Show(C.i18n("launch.cannot_create_jvm"));
|
||||
processThreadStopped((ProcessThread) sender3, false);
|
||||
return true;
|
||||
};
|
||||
@@ -71,7 +71,8 @@ public class JavaProcessMonitor {
|
||||
al.remove(t);
|
||||
al.removeAll(CollectionUtils.sortOut(al, t1 -> !t1.isAlive()));
|
||||
if (al.isEmpty() || forceTermintate) {
|
||||
for (Thread a : al) a.interrupt();
|
||||
for (Thread a : al)
|
||||
a.interrupt();
|
||||
al.clear();
|
||||
stoppedEvent.execute(p);
|
||||
}
|
||||
|
||||
@@ -55,9 +55,10 @@ public final class JdkVersion {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof JdkVersion)) return false;
|
||||
if (!(obj instanceof JdkVersion))
|
||||
return false;
|
||||
JdkVersion b = (JdkVersion) obj;
|
||||
if(b.location == null || location == null)
|
||||
if (b.location == null || location == null)
|
||||
return b.location == location;
|
||||
return new File(b.location).equals(new File(location));
|
||||
}
|
||||
@@ -69,7 +70,8 @@ public final class JdkVersion {
|
||||
|
||||
public JdkVersion(String location) {
|
||||
File f = new File(location);
|
||||
if (f.exists() && f.isFile()) f = f.getParentFile();
|
||||
if (f.exists() && f.isFile())
|
||||
f = f.getParentFile();
|
||||
this.location = f.getAbsolutePath();
|
||||
}
|
||||
|
||||
@@ -110,12 +112,17 @@ public final class JdkVersion {
|
||||
}
|
||||
|
||||
private static int parseVersion(String javaVersion) {
|
||||
if (StrUtils.isBlank(javaVersion)) return UNKOWN;
|
||||
if (StrUtils.isBlank(javaVersion))
|
||||
return UNKOWN;
|
||||
int a = UNKOWN;
|
||||
if (javaVersion.contains("1.9.")) a = JAVA_19;
|
||||
else if (javaVersion.contains("1.8.")) a = JAVA_18;
|
||||
else if (javaVersion.contains("1.7.")) a = JAVA_17;
|
||||
else if (javaVersion.contains("1.6.")) a = JAVA_16;
|
||||
if (javaVersion.contains("1.9."))
|
||||
a = JAVA_19;
|
||||
else if (javaVersion.contains("1.8."))
|
||||
a = JAVA_18;
|
||||
else if (javaVersion.contains("1.7."))
|
||||
a = JAVA_17;
|
||||
else if (javaVersion.contains("1.6."))
|
||||
a = JAVA_16;
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -124,6 +131,7 @@ public final class JdkVersion {
|
||||
* <code>System.getProperty("java.version")</code>.
|
||||
*
|
||||
* @return the full Java version string
|
||||
*
|
||||
* @see System#getProperty(String)
|
||||
*/
|
||||
public static String getJavaVersion() {
|
||||
@@ -138,6 +146,7 @@ public final class JdkVersion {
|
||||
* rn a code comparable to the JAVA_XX codes in this class
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @see #JAVA_13
|
||||
* @see #JAVA_14
|
||||
* @see #JAVA_15
|
||||
@@ -156,11 +165,11 @@ public final class JdkVersion {
|
||||
private static final Pattern p = Pattern.compile("java version \"[1-9]*\\.[1-9]*\\.[0-9]*(.*?)\"");
|
||||
|
||||
public static JdkVersion getJavaVersionFromExecutable(String file) throws IOException {
|
||||
String[] str = new String[]{file, "-version"};
|
||||
String[] str = new String[] {file, "-version"};
|
||||
Platform platform = Platform.BIT_32;
|
||||
String ver = null;
|
||||
try {
|
||||
for(String line : IOUtils.readProcessByErrorStream(str)) {
|
||||
for (String line : IOUtils.readProcessByErrorStream(str)) {
|
||||
Matcher m = p.matcher(line);
|
||||
if (m.find()) {
|
||||
ver = m.group();
|
||||
|
||||
@@ -88,6 +88,7 @@ public class MessageBox {
|
||||
* @param Msg The Message
|
||||
* @param Title The title of MsgBox.
|
||||
* @param Option The type of MsgBox.
|
||||
*
|
||||
* @return user operation.
|
||||
*/
|
||||
public static int Show(String Msg, String Title, int Option) {
|
||||
@@ -107,6 +108,7 @@ public class MessageBox {
|
||||
*
|
||||
* @param Msg The Message
|
||||
* @param Option The type of MsgBox.
|
||||
*
|
||||
* @return User Operation
|
||||
*/
|
||||
public static int Show(String Msg, int Option) {
|
||||
@@ -117,6 +119,7 @@ public class MessageBox {
|
||||
* Show Default MsgBox
|
||||
*
|
||||
* @param Msg The Message
|
||||
*
|
||||
* @return User Operation
|
||||
*/
|
||||
public static int Show(String Msg) {
|
||||
|
||||
@@ -56,8 +56,8 @@ public class ProcessThread extends Thread {
|
||||
HMCLog.warn("Unsupported encoding: " + System.getProperty("sun.jnu.encoding", "UTF-8"), ex);
|
||||
br = new InputStreamReader(in);
|
||||
}
|
||||
}
|
||||
else br = null;
|
||||
} else
|
||||
br = null;
|
||||
|
||||
int ch;
|
||||
String line = "";
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.awt.image.Raster;
|
||||
import java.awt.image.WritableRaster;
|
||||
|
||||
public abstract class AbstractFilter
|
||||
implements BufferedImageOp {
|
||||
implements BufferedImageOp {
|
||||
|
||||
@Override
|
||||
public abstract BufferedImage filter(BufferedImage paramBufferedImage1, BufferedImage paramBufferedImage2);
|
||||
|
||||
@@ -24,11 +24,11 @@ import java.awt.Color;
|
||||
*/
|
||||
public class BasicColors {
|
||||
|
||||
private static Color getWebColor(String c){
|
||||
private static Color getWebColor(String c) {
|
||||
return new Color(
|
||||
Integer.parseInt(c.substring(0,2),16),
|
||||
Integer.parseInt(c.substring(2,4),16),
|
||||
Integer.parseInt(c.substring(4,6),16)
|
||||
Integer.parseInt(c.substring(0, 2), 16),
|
||||
Integer.parseInt(c.substring(2, 4), 16),
|
||||
Integer.parseInt(c.substring(4, 6), 16)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,9 +27,8 @@ public class FastBlurFilter extends AbstractFilter {
|
||||
}
|
||||
|
||||
public FastBlurFilter(int radius) {
|
||||
if (radius < 1) {
|
||||
if (radius < 1)
|
||||
radius = 1;
|
||||
}
|
||||
|
||||
this.radius = radius;
|
||||
}
|
||||
@@ -43,9 +42,8 @@ public class FastBlurFilter extends AbstractFilter {
|
||||
int width = src.getWidth();
|
||||
int height = src.getHeight();
|
||||
|
||||
if (dst == null) {
|
||||
if (dst == null)
|
||||
dst = createCompatibleDestImage(src, null);
|
||||
}
|
||||
|
||||
int[] srcPixels = new int[width * height];
|
||||
int[] dstPixels = new int[width * height];
|
||||
@@ -68,23 +66,19 @@ public class FastBlurFilter extends AbstractFilter {
|
||||
int srcIndex = 0;
|
||||
|
||||
int[] sumLookupTable = new int[256 * windowSize];
|
||||
for (int i = 0; i < sumLookupTable.length; i++) {
|
||||
for (int i = 0; i < sumLookupTable.length; i++)
|
||||
sumLookupTable[i] = (i / windowSize);
|
||||
}
|
||||
|
||||
int[] indexLookupTable = new int[radiusPlusOne];
|
||||
if (radius < width) {
|
||||
for (int i = 0; i < indexLookupTable.length; i++) {
|
||||
if (radius < width)
|
||||
for (int i = 0; i < indexLookupTable.length; i++)
|
||||
indexLookupTable[i] = i;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < width; i++) {
|
||||
else {
|
||||
for (int i = 0; i < width; i++)
|
||||
indexLookupTable[i] = i;
|
||||
}
|
||||
for (int i = width; i < indexLookupTable.length; i++) {
|
||||
for (int i = width; i < indexLookupTable.length; i++)
|
||||
indexLookupTable[i] = (width - 1);
|
||||
}
|
||||
}
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
int sumBlue;
|
||||
@@ -113,14 +107,12 @@ public class FastBlurFilter extends AbstractFilter {
|
||||
dstIndex += height;
|
||||
|
||||
int nextPixelIndex = x + radiusPlusOne;
|
||||
if (nextPixelIndex >= width) {
|
||||
if (nextPixelIndex >= width)
|
||||
nextPixelIndex = width - 1;
|
||||
}
|
||||
|
||||
int previousPixelIndex = x - radius;
|
||||
if (previousPixelIndex < 0) {
|
||||
if (previousPixelIndex < 0)
|
||||
previousPixelIndex = 0;
|
||||
}
|
||||
|
||||
int nextPixel = srcPixels[(srcIndex + nextPixelIndex)];
|
||||
int previousPixel = srcPixels[(srcIndex + previousPixelIndex)];
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
package org.tukaani.xz;
|
||||
|
||||
import java.io.InputStream;
|
||||
@@ -16,6 +15,7 @@ import org.tukaani.xz.simple.ARM;
|
||||
* BCJ filter for little endian ARM instructions.
|
||||
*/
|
||||
public class ARMOptions extends BCJOptions {
|
||||
|
||||
private static final int ALIGNMENT = 4;
|
||||
|
||||
public ARMOptions() {
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
package org.tukaani.xz;
|
||||
|
||||
import java.io.InputStream;
|
||||
@@ -16,6 +15,7 @@ import org.tukaani.xz.simple.ARMThumb;
|
||||
* BCJ filter for little endian ARM-Thumb instructions.
|
||||
*/
|
||||
public class ARMThumbOptions extends BCJOptions {
|
||||
|
||||
private static final int ALIGNMENT = 2;
|
||||
|
||||
public ARMThumbOptions() {
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
package org.tukaani.xz;
|
||||
|
||||
abstract class BCJCoder implements FilterCoder {
|
||||
|
||||
public static final long X86_FILTER_ID = 0x04;
|
||||
public static final long POWERPC_FILTER_ID = 0x05;
|
||||
public static final long IA64_FILTER_ID = 0x06;
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
package org.tukaani.xz;
|
||||
|
||||
import java.io.InputStream;
|
||||
import org.tukaani.xz.simple.*;
|
||||
|
||||
class BCJDecoder extends BCJCoder implements FilterDecoder {
|
||||
|
||||
private final long filterID;
|
||||
private final int startOffset;
|
||||
|
||||
@@ -21,19 +21,18 @@ class BCJDecoder extends BCJCoder implements FilterDecoder {
|
||||
assert isBCJFilterID(filterID);
|
||||
this.filterID = filterID;
|
||||
|
||||
if (props.length == 0) {
|
||||
if (props.length == 0)
|
||||
startOffset = 0;
|
||||
} else if (props.length == 4) {
|
||||
else if (props.length == 4) {
|
||||
int n = 0;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
n |= (props[i] & 0xFF) << (i * 8);
|
||||
|
||||
startOffset = n;
|
||||
} else {
|
||||
} else
|
||||
throw new UnsupportedOptionsException(
|
||||
"Unsupported BCJ filter properties");
|
||||
}
|
||||
}
|
||||
|
||||
public int getMemoryUsage() {
|
||||
return SimpleInputStream.getMemoryUsage();
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
package org.tukaani.xz;
|
||||
|
||||
class BCJEncoder extends BCJCoder implements FilterEncoder {
|
||||
|
||||
private final BCJOptions options;
|
||||
private final long filterID;
|
||||
private final byte[] props;
|
||||
@@ -18,16 +18,16 @@ class BCJEncoder extends BCJCoder implements FilterEncoder {
|
||||
assert isBCJFilterID(filterID);
|
||||
int startOffset = options.getStartOffset();
|
||||
|
||||
if (startOffset == 0) {
|
||||
if (startOffset == 0)
|
||||
props = new byte[0];
|
||||
} else {
|
||||
else {
|
||||
props = new byte[4];
|
||||
for (int i = 0; i < 4; ++i)
|
||||
props[i] = (byte)(startOffset >>> (i * 8));
|
||||
props[i] = (byte) (startOffset >>> (i * 8));
|
||||
}
|
||||
|
||||
this.filterID = filterID;
|
||||
this.options = (BCJOptions)options.clone();
|
||||
this.options = (BCJOptions) options.clone();
|
||||
}
|
||||
|
||||
public long getFilterID() {
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
package org.tukaani.xz;
|
||||
|
||||
abstract class BCJOptions extends FilterOptions {
|
||||
|
||||
private final int alignment;
|
||||
int startOffset = 0;
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user