Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce24ae4fae | ||
|
|
16152de39d | ||
|
|
4a2ac63d25 | ||
|
|
5437968c83 | ||
|
|
8022252452 |
No files matched your search
+1
-19
@@ -22,7 +22,6 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.jackhuang.hellominecraft.util.C;
|
import org.jackhuang.hellominecraft.util.C;
|
||||||
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftAssetService;
|
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftAssetService;
|
||||||
@@ -30,7 +29,6 @@ import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
|
|||||||
import org.jackhuang.hellominecraft.launcher.core.version.AssetIndexDownloadInfo;
|
import org.jackhuang.hellominecraft.launcher.core.version.AssetIndexDownloadInfo;
|
||||||
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
|
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
|
||||||
import org.jackhuang.hellominecraft.util.MessageBox;
|
import org.jackhuang.hellominecraft.util.MessageBox;
|
||||||
import org.jackhuang.hellominecraft.util.Utils;
|
|
||||||
import org.jackhuang.hellominecraft.util.func.Function;
|
import org.jackhuang.hellominecraft.util.func.Function;
|
||||||
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
||||||
import org.jackhuang.hellominecraft.util.tasks.Task;
|
import org.jackhuang.hellominecraft.util.tasks.Task;
|
||||||
@@ -58,23 +56,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
|
|||||||
public Task downloadAssets(final MinecraftVersion mv) {
|
public Task downloadAssets(final MinecraftVersion mv) {
|
||||||
if (mv == null)
|
if (mv == null)
|
||||||
return null;
|
return null;
|
||||||
return new TaskInfo("Download Assets") {
|
return IAssetsHandler.ASSETS_HANDLER.getList(mv, service.asset()).after(IAssetsHandler.ASSETS_HANDLER.getDownloadTask(service.getDownloadType().getProvider()));
|
||||||
Collection<Task> afters = new HashSet<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<Task> getDependTasks() {
|
|
||||||
return Arrays.asList(IAssetsHandler.ASSETS_HANDLER.getList(mv, service.asset()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void executeTask() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<Task> getAfterTasks() {
|
|
||||||
return Arrays.asList(IAssetsHandler.ASSETS_HANDLER.getDownloadTask(service.getDownloadType().getProvider()));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+2
-1
@@ -96,7 +96,8 @@ public abstract class IAuthenticator {
|
|||||||
public void onLoadSettings(Map m) {
|
public void onLoadSettings(Map m) {
|
||||||
if (m == null)
|
if (m == null)
|
||||||
return;
|
return;
|
||||||
username = (String) m.get("IAuthenticator_UserName");
|
Object o = m.get("IAuthenticator_UserName");
|
||||||
|
username = o instanceof String ? (String) o : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUserName() {
|
public String getUserName() {
|
||||||
|
|||||||
+1
-1
@@ -25,7 +25,7 @@ public class CurseDownloadProvider extends MojangDownloadProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getParsedDownloadURL(String str) {
|
public String getParsedDownloadURL(String str) {
|
||||||
return str == null ? null : str.replace("http://files.minecraftforge.net/maven", "http://ftb.cursecdn.com/FTB2/maven/");
|
return str == null ? null : str.replace("http://files.minecraftforge.net/maven", "http://ftb.cursecdn.com/FTB2/maven");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -29,6 +29,6 @@ public class MinecraftRemoteVersion {
|
|||||||
public String getUrl(DownloadType type) {
|
public String getUrl(DownloadType type) {
|
||||||
if (url == null)
|
if (url == null)
|
||||||
return type.getProvider().getVersionsDownloadURL() + id + "/" + id + ".json";
|
return type.getProvider().getVersionsDownloadURL() + id + "/" + id + ".json";
|
||||||
return url;
|
return type.getProvider().getParsedDownloadURL(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -64,7 +64,7 @@ public class MojangDownloadProvider extends IDownloadProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAssetsDownloadURL() {
|
public String getAssetsDownloadURL() {
|
||||||
return "http://resources.download.minecraft.net/";
|
return "https://resources.download.minecraft.net/";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+3
-12
@@ -22,13 +22,13 @@ import java.util.ArrayList;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import org.jackhuang.hellominecraft.util.func.Consumer;
|
import org.jackhuang.hellominecraft.util.tasks.Task;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author huangyuhui
|
* @author huangyuhui
|
||||||
*/
|
*/
|
||||||
public abstract class InstallerVersionList implements Consumer<String[]> {
|
public abstract class InstallerVersionList {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refresh installer versions list from the downloaded content.
|
* Refresh installer versions list from the downloaded content.
|
||||||
@@ -37,7 +37,7 @@ public abstract class InstallerVersionList implements Consumer<String[]> {
|
|||||||
*
|
*
|
||||||
* @throws java.lang.Exception including network exceptions, IO exceptions.
|
* @throws java.lang.Exception including network exceptions, IO exceptions.
|
||||||
*/
|
*/
|
||||||
public abstract void refreshList(String[] versions) throws Exception;
|
public abstract Task refresh(String[] versions);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Installer name.
|
* Installer name.
|
||||||
@@ -117,13 +117,4 @@ public abstract class InstallerVersionList implements Consumer<String[]> {
|
|||||||
return o2.compareTo(o1);
|
return o2.compareTo(o1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void accept(String[] v) {
|
|
||||||
try {
|
|
||||||
refreshList(v);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+19
-36
@@ -27,10 +27,9 @@ import org.jackhuang.hellominecraft.launcher.core.install.liteloader.LiteLoaderV
|
|||||||
import org.jackhuang.hellominecraft.launcher.core.install.optifine.OptiFineInstaller;
|
import org.jackhuang.hellominecraft.launcher.core.install.optifine.OptiFineInstaller;
|
||||||
import org.jackhuang.hellominecraft.launcher.core.install.optifine.vanilla.OptiFineDownloadFormatter;
|
import org.jackhuang.hellominecraft.launcher.core.install.optifine.vanilla.OptiFineDownloadFormatter;
|
||||||
import org.jackhuang.hellominecraft.util.tasks.Task;
|
import org.jackhuang.hellominecraft.util.tasks.Task;
|
||||||
import org.jackhuang.hellominecraft.util.tasks.TaskInfo;
|
|
||||||
import org.jackhuang.hellominecraft.util.tasks.TaskWindow;
|
|
||||||
import org.jackhuang.hellominecraft.util.tasks.download.FileDownloadTask;
|
import org.jackhuang.hellominecraft.util.tasks.download.FileDownloadTask;
|
||||||
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
||||||
|
import org.jackhuang.hellominecraft.util.tasks.DeleteFileTask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -58,47 +57,31 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Task downloadForge(String installId, InstallerVersion v) {
|
public Task downloadForge(String installId, InstallerVersion v) {
|
||||||
return new TaskInfo("Forge Downloader") {
|
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "forge-installer.jar");
|
||||||
@Override
|
if (v.installer == null)
|
||||||
public void executeTask() {
|
return null;
|
||||||
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "forge-installer.jar");
|
else
|
||||||
if (v.installer != null)
|
return new FileDownloadTask(service.getDownloadType().getProvider().getParsedDownloadURL(v.installer), filepath).setTag("forge")
|
||||||
TaskWindow.factory()
|
.after(new ForgeInstaller(service, filepath))
|
||||||
.append(new FileDownloadTask(service.getDownloadType().getProvider().getParsedDownloadURL(v.installer), filepath).setTag("forge"))
|
.after(new DeleteFileTask(filepath));
|
||||||
.append(new ForgeInstaller(service, filepath))
|
|
||||||
.create();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Task downloadOptiFine(String installId, InstallerVersion v) {
|
public Task downloadOptiFine(String installId, InstallerVersion v) {
|
||||||
return new TaskInfo("OptiFine Downloader") {
|
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "optifine-installer.jar");
|
||||||
@Override
|
if (v.installer == null)
|
||||||
public void executeTask() {
|
return null;
|
||||||
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "optifine-installer.jar");
|
OptiFineDownloadFormatter task = new OptiFineDownloadFormatter(v.installer);
|
||||||
if (v.installer != null) {
|
return task.after(new FileDownloadTask(filepath).registerPreviousResult(task).setTag("optifine"))
|
||||||
OptiFineDownloadFormatter task = new OptiFineDownloadFormatter(v.installer);
|
.after(new OptiFineInstaller(service, installId, v, filepath))
|
||||||
TaskWindow.factory().append(task)
|
.after(new DeleteFileTask(filepath));
|
||||||
.append(new FileDownloadTask(filepath).registerPreviousResult(task).setTag("optifine"))
|
|
||||||
.append(new OptiFineInstaller(service, installId, v, filepath))
|
|
||||||
.create();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Task downloadLiteLoader(String installId, InstallerVersion v) {
|
public Task downloadLiteLoader(String installId, InstallerVersion v) {
|
||||||
return new TaskInfo("LiteLoader Downloader") {
|
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "liteloader-universal.jar");
|
||||||
@Override
|
FileDownloadTask task = (FileDownloadTask) new FileDownloadTask(v.universal, filepath).setTag("LiteLoader");
|
||||||
public void executeTask() {
|
return task.after(new LiteLoaderInstaller(service, installId, (LiteLoaderVersionList.LiteLoaderInstallerVersion) v).registerPreviousResult(task))
|
||||||
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "liteloader-universal.jar");
|
.after(new DeleteFileTask(filepath));
|
||||||
FileDownloadTask task = (FileDownloadTask) new FileDownloadTask(v.universal, filepath).setTag("LiteLoader");
|
|
||||||
TaskWindow.factory()
|
|
||||||
.append(task).append(new LiteLoaderInstaller(service, installId, (LiteLoaderVersionList.LiteLoaderInstallerVersion) v).registerPreviousResult(task))
|
|
||||||
.create();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+62
-44
@@ -18,6 +18,8 @@
|
|||||||
package org.jackhuang.hellominecraft.launcher.core.install.forge;
|
package org.jackhuang.hellominecraft.launcher.core.install.forge;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -27,7 +29,9 @@ import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
|
|||||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||||
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
|
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
|
||||||
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionNewerComparator;
|
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionNewerComparator;
|
||||||
import org.jackhuang.hellominecraft.util.NetUtils;
|
import org.jackhuang.hellominecraft.util.tasks.Task;
|
||||||
|
import org.jackhuang.hellominecraft.util.tasks.TaskInfo;
|
||||||
|
import org.jackhuang.hellominecraft.util.tasks.download.HTTPGetTask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -48,54 +52,68 @@ public class MinecraftForgeVersionList extends InstallerVersionList {
|
|||||||
public List<InstallerVersion> versions;
|
public List<InstallerVersion> versions;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refreshList(String[] needed) throws Exception {
|
public Task refresh(String[] needed) {
|
||||||
if (root != null)
|
if (root != null)
|
||||||
return;
|
return null;
|
||||||
String s = NetUtils.get(DownloadType.getSuggestedDownloadType().getProvider().getParsedDownloadURL(C.URL_FORGE_LIST));
|
return new TaskInfo(C.i18n("install.forge.get_list")) {
|
||||||
|
HTTPGetTask task = new HTTPGetTask(DownloadType.getSuggestedDownloadType().getProvider().getParsedDownloadURL(C.URL_FORGE_LIST));
|
||||||
|
|
||||||
root = C.GSON.fromJson(s, MinecraftForgeVersionRoot.class);
|
@Override
|
||||||
|
public Collection<Task> getDependTasks() {
|
||||||
versionMap = new HashMap<>();
|
return Arrays.asList(task);
|
||||||
versions = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Map.Entry<String, int[]> arr : root.mcversion.entrySet()) {
|
|
||||||
String mcver = StrUtils.formatVersion(arr.getKey());
|
|
||||||
ArrayList<InstallerVersion> al = new ArrayList<>();
|
|
||||||
for (int num : arr.getValue()) {
|
|
||||||
MinecraftForgeVersion v = root.number.get(num);
|
|
||||||
InstallerVersion iv = new InstallerVersion(v.version, StrUtils.formatVersion(v.mcversion));
|
|
||||||
for (String[] f : v.files) {
|
|
||||||
|
|
||||||
String ver = v.mcversion + "-" + v.version;
|
|
||||||
if (!StrUtils.isBlank(v.branch))
|
|
||||||
ver = ver + "-" + v.branch;
|
|
||||||
String filename = root.artifact + "-" + ver + "-" + f[1] + "." + f[0];
|
|
||||||
String url = DownloadType.getSuggestedDownloadType().getProvider().getParsedDownloadURL(root.webpath + ver + "/" + filename);
|
|
||||||
switch (f[1]) {
|
|
||||||
case "installer":
|
|
||||||
iv.installer = url;
|
|
||||||
break;
|
|
||||||
case "universal":
|
|
||||||
iv.universal = url;
|
|
||||||
break;
|
|
||||||
case "changelog":
|
|
||||||
iv.changelog = url;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (StrUtils.isBlank(iv.installer) || StrUtils.isBlank(iv.universal))
|
|
||||||
continue;
|
|
||||||
Collections.sort(al, new InstallerVersionNewerComparator());
|
|
||||||
al.add(iv);
|
|
||||||
versions.add(iv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
versionMap.put(StrUtils.formatVersion(mcver), al);
|
@Override
|
||||||
}
|
public void executeTask() throws Throwable {
|
||||||
|
if (!areDependTasksSucceeded)
|
||||||
|
return;
|
||||||
|
String s = task.getResult();
|
||||||
|
|
||||||
Collections.sort(versions, new InstallerVersionComparator());
|
root = C.GSON.fromJson(s, MinecraftForgeVersionRoot.class);
|
||||||
|
|
||||||
|
versionMap = new HashMap<>();
|
||||||
|
versions = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Map.Entry<String, int[]> arr : root.mcversion.entrySet()) {
|
||||||
|
String mcver = StrUtils.formatVersion(arr.getKey());
|
||||||
|
ArrayList<InstallerVersion> al = new ArrayList<>();
|
||||||
|
for (int num : arr.getValue()) {
|
||||||
|
MinecraftForgeVersion v = root.number.get(num);
|
||||||
|
InstallerVersion iv = new InstallerVersion(v.version, StrUtils.formatVersion(v.mcversion));
|
||||||
|
for (String[] f : v.files) {
|
||||||
|
|
||||||
|
String ver = v.mcversion + "-" + v.version;
|
||||||
|
if (!StrUtils.isBlank(v.branch))
|
||||||
|
ver = ver + "-" + v.branch;
|
||||||
|
String filename = root.artifact + "-" + ver + "-" + f[1] + "." + f[0];
|
||||||
|
String url = DownloadType.getSuggestedDownloadType().getProvider().getParsedDownloadURL(root.webpath + ver + "/" + filename);
|
||||||
|
switch (f[1]) {
|
||||||
|
case "installer":
|
||||||
|
iv.installer = url;
|
||||||
|
break;
|
||||||
|
case "universal":
|
||||||
|
iv.universal = url;
|
||||||
|
break;
|
||||||
|
case "changelog":
|
||||||
|
iv.changelog = url;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (StrUtils.isBlank(iv.installer) || StrUtils.isBlank(iv.universal))
|
||||||
|
continue;
|
||||||
|
Collections.sort(al, new InstallerVersionNewerComparator());
|
||||||
|
al.add(iv);
|
||||||
|
versions.add(iv);
|
||||||
|
}
|
||||||
|
|
||||||
|
versionMap.put(StrUtils.formatVersion(mcver), al);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(versions, new InstallerVersionComparator());
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+46
-29
@@ -19,6 +19,7 @@ package org.jackhuang.hellominecraft.launcher.core.install.liteloader;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -28,8 +29,10 @@ import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
|
|||||||
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
|
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
|
||||||
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList.InstallerVersion;
|
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList.InstallerVersion;
|
||||||
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionNewerComparator;
|
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionNewerComparator;
|
||||||
import org.jackhuang.hellominecraft.util.NetUtils;
|
|
||||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||||
|
import org.jackhuang.hellominecraft.util.tasks.Task;
|
||||||
|
import org.jackhuang.hellominecraft.util.tasks.TaskInfo;
|
||||||
|
import org.jackhuang.hellominecraft.util.tasks.download.HTTPGetTask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -50,38 +53,52 @@ public class LiteLoaderVersionList extends InstallerVersionList {
|
|||||||
public List<InstallerVersion> versions;
|
public List<InstallerVersion> versions;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refreshList(String[] needed) throws Exception {
|
public Task refresh(String[] needed) {
|
||||||
String s = NetUtils.get(C.URL_LITELOADER_LIST);
|
|
||||||
if (root != null)
|
if (root != null)
|
||||||
return;
|
return null;
|
||||||
|
return new TaskInfo(C.i18n("install.liteloader.get_list")) {
|
||||||
|
HTTPGetTask task = new HTTPGetTask(C.URL_LITELOADER_LIST);
|
||||||
|
|
||||||
root = C.GSON.fromJson(s, LiteLoaderVersionsRoot.class);
|
@Override
|
||||||
|
public Collection<Task> getDependTasks() {
|
||||||
versionMap = new HashMap<>();
|
return Arrays.asList(task);
|
||||||
versions = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Map.Entry<String, LiteLoaderMCVersions> arr : root.versions.entrySet()) {
|
|
||||||
ArrayList<InstallerVersion> al = new ArrayList<>();
|
|
||||||
LiteLoaderMCVersions mcv = arr.getValue();
|
|
||||||
if (mcv == null || mcv.artefacts == null || mcv.artefacts.get("com.mumfrey:liteloader") == null)
|
|
||||||
continue;
|
|
||||||
for (Map.Entry<String, LiteLoaderVersion> entry : mcv.artefacts.get("com.mumfrey:liteloader").entrySet()) {
|
|
||||||
if ("latest".equals(entry.getKey()))
|
|
||||||
continue;
|
|
||||||
LiteLoaderVersion v = entry.getValue();
|
|
||||||
LiteLoaderInstallerVersion iv = new LiteLoaderInstallerVersion(v.version, StrUtils.formatVersion(arr.getKey()));
|
|
||||||
iv.universal = "http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + arr.getKey() + "/" + v.file;
|
|
||||||
iv.tweakClass = v.tweakClass;
|
|
||||||
iv.libraries = Arrays.copyOf(v.libraries, v.libraries.length);
|
|
||||||
iv.installer = "http://dl.liteloader.com/redist/" + iv.mcVersion + "/liteloader-installer-" + iv.selfVersion.replace("_", "-") + ".jar";
|
|
||||||
al.add(iv);
|
|
||||||
versions.add(iv);
|
|
||||||
}
|
}
|
||||||
Collections.sort(al, new InstallerVersionNewerComparator());
|
|
||||||
versionMap.put(StrUtils.formatVersion(arr.getKey()), al);
|
|
||||||
}
|
|
||||||
|
|
||||||
Collections.sort(versions, InstallerVersionComparator.INSTANCE);
|
@Override
|
||||||
|
public void executeTask() throws Throwable {
|
||||||
|
if (!areDependTasksSucceeded)
|
||||||
|
return;
|
||||||
|
String s = task.getResult();
|
||||||
|
|
||||||
|
root = C.GSON.fromJson(s, LiteLoaderVersionsRoot.class);
|
||||||
|
|
||||||
|
versionMap = new HashMap<>();
|
||||||
|
versions = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Map.Entry<String, LiteLoaderMCVersions> arr : root.versions.entrySet()) {
|
||||||
|
ArrayList<InstallerVersion> al = new ArrayList<>();
|
||||||
|
LiteLoaderMCVersions mcv = arr.getValue();
|
||||||
|
if (mcv == null || mcv.artefacts == null || mcv.artefacts.get("com.mumfrey:liteloader") == null)
|
||||||
|
continue;
|
||||||
|
for (Map.Entry<String, LiteLoaderVersion> entry : mcv.artefacts.get("com.mumfrey:liteloader").entrySet()) {
|
||||||
|
if ("latest".equals(entry.getKey()))
|
||||||
|
continue;
|
||||||
|
LiteLoaderVersion v = entry.getValue();
|
||||||
|
LiteLoaderInstallerVersion iv = new LiteLoaderInstallerVersion(v.version, StrUtils.formatVersion(arr.getKey()));
|
||||||
|
iv.universal = "http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + arr.getKey() + "/" + v.file;
|
||||||
|
iv.tweakClass = v.tweakClass;
|
||||||
|
iv.libraries = Arrays.copyOf(v.libraries, v.libraries.length);
|
||||||
|
iv.installer = "http://dl.liteloader.com/redist/" + iv.mcVersion + "/liteloader-installer-" + iv.selfVersion.replace("_", "-") + ".jar";
|
||||||
|
al.add(iv);
|
||||||
|
versions.add(iv);
|
||||||
|
}
|
||||||
|
Collections.sort(al, new InstallerVersionNewerComparator());
|
||||||
|
versionMap.put(StrUtils.formatVersion(arr.getKey()), al);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(versions, InstallerVersionComparator.INSTANCE);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+41
-25
@@ -20,6 +20,8 @@ package org.jackhuang.hellominecraft.launcher.core.install.optifine.bmcl;
|
|||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -30,8 +32,10 @@ import org.jackhuang.hellominecraft.util.C;
|
|||||||
import org.jackhuang.hellominecraft.util.ArrayUtils;
|
import org.jackhuang.hellominecraft.util.ArrayUtils;
|
||||||
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
|
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
|
||||||
import org.jackhuang.hellominecraft.launcher.core.install.optifine.OptiFineVersion;
|
import org.jackhuang.hellominecraft.launcher.core.install.optifine.OptiFineVersion;
|
||||||
import org.jackhuang.hellominecraft.util.NetUtils;
|
|
||||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||||
|
import org.jackhuang.hellominecraft.util.tasks.Task;
|
||||||
|
import org.jackhuang.hellominecraft.util.tasks.TaskInfo;
|
||||||
|
import org.jackhuang.hellominecraft.util.tasks.download.HTTPGetTask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -55,34 +59,46 @@ public class OptiFineBMCLVersionList extends InstallerVersionList {
|
|||||||
}.getType();
|
}.getType();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refreshList(String[] needed) throws Exception {
|
public Task refresh(String[] needed) {
|
||||||
String s = NetUtils.get("http://bmclapi.bangbang93.com/optifine/versionlist");
|
return new TaskInfo(C.i18n("install.optifine.get_list")) {
|
||||||
|
HTTPGetTask task = new HTTPGetTask("http://bmclapi.bangbang93.com/optifine/versionlist");
|
||||||
|
|
||||||
versionMap = new HashMap<>();
|
@Override
|
||||||
versions = new ArrayList<>();
|
public Collection<Task> getDependTasks() {
|
||||||
|
return Arrays.asList(task);
|
||||||
if (s == null)
|
|
||||||
return;
|
|
||||||
root = C.GSON.fromJson(s, TYPE);
|
|
||||||
for (OptiFineVersion v : root) {
|
|
||||||
v.setMirror(v.getMirror().replace("http://optifine.net/http://optifine.net/", "http://optifine.net/"));
|
|
||||||
|
|
||||||
if (StrUtils.isBlank(v.getMCVersion())) {
|
|
||||||
Pattern p = Pattern.compile("OptiFine (.*) HD");
|
|
||||||
Matcher m = p.matcher(v.getVersion());
|
|
||||||
while (m.find())
|
|
||||||
v.setMCVersion(m.group(1));
|
|
||||||
}
|
}
|
||||||
InstallerVersion iv = new InstallerVersion(v.getVersion(), StrUtils.formatVersion(v.getMCVersion()));
|
|
||||||
|
|
||||||
List<InstallerVersion> al = ArrayUtils.tryGetMapWithList(versionMap, StrUtils.formatVersion(v.getMCVersion()));
|
@Override
|
||||||
//String url = "http://bmclapi.bangbang93.com/optifine/" + iv.selfVersion.replace(" ", "%20");
|
public void executeTask() throws Throwable {
|
||||||
iv.installer = iv.universal = v.getMirror();
|
String s = task.getResult();
|
||||||
al.add(iv);
|
|
||||||
versions.add(iv);
|
|
||||||
}
|
|
||||||
|
|
||||||
Collections.sort(versions, InstallerVersionComparator.INSTANCE);
|
versionMap = new HashMap<>();
|
||||||
|
versions = new ArrayList<>();
|
||||||
|
|
||||||
|
if (s == null)
|
||||||
|
return;
|
||||||
|
root = C.GSON.fromJson(s, TYPE);
|
||||||
|
for (OptiFineVersion v : root) {
|
||||||
|
v.setMirror(v.getMirror().replace("http://optifine.net/http://optifine.net/", "http://optifine.net/"));
|
||||||
|
|
||||||
|
if (StrUtils.isBlank(v.getMCVersion())) {
|
||||||
|
Pattern p = Pattern.compile("OptiFine (.*) HD");
|
||||||
|
Matcher m = p.matcher(v.getVersion());
|
||||||
|
while (m.find())
|
||||||
|
v.setMCVersion(m.group(1));
|
||||||
|
}
|
||||||
|
InstallerVersion iv = new InstallerVersion(v.getVersion(), StrUtils.formatVersion(v.getMCVersion()));
|
||||||
|
|
||||||
|
List<InstallerVersion> al = ArrayUtils.tryGetMapWithList(versionMap, StrUtils.formatVersion(v.getMCVersion()));
|
||||||
|
//String url = "http://bmclapi.bangbang93.com/optifine/" + iv.selfVersion.replace(" ", "%20");
|
||||||
|
iv.installer = iv.universal = v.getMirror();
|
||||||
|
al.add(iv);
|
||||||
|
versions.add(iv);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(versions, InstallerVersionComparator.INSTANCE);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+70
-51
@@ -20,6 +20,8 @@ package org.jackhuang.hellominecraft.launcher.core.install.optifine.vanilla;
|
|||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -32,8 +34,11 @@ import javax.xml.parsers.ParserConfigurationException;
|
|||||||
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
|
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
|
||||||
import org.jackhuang.hellominecraft.launcher.core.install.optifine.OptiFineVersion;
|
import org.jackhuang.hellominecraft.launcher.core.install.optifine.OptiFineVersion;
|
||||||
import org.jackhuang.hellominecraft.util.ArrayUtils;
|
import org.jackhuang.hellominecraft.util.ArrayUtils;
|
||||||
import org.jackhuang.hellominecraft.util.NetUtils;
|
import org.jackhuang.hellominecraft.util.C;
|
||||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||||
|
import org.jackhuang.hellominecraft.util.tasks.Task;
|
||||||
|
import org.jackhuang.hellominecraft.util.tasks.TaskInfo;
|
||||||
|
import org.jackhuang.hellominecraft.util.tasks.download.HTTPGetTask;
|
||||||
import org.w3c.dom.DOMException;
|
import org.w3c.dom.DOMException;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
@@ -59,60 +64,74 @@ public class OptiFineVersionList extends InstallerVersionList {
|
|||||||
public List<InstallerVersion> versions;
|
public List<InstallerVersion> versions;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refreshList(String[] sss) throws Exception {
|
public Task refresh(String[] sss) {
|
||||||
String content = NetUtils.get("http://optifine.net/downloads");
|
|
||||||
if (versions != null)
|
if (versions != null)
|
||||||
return;
|
return null;
|
||||||
versionMap = new HashMap<>();
|
return new TaskInfo(C.i18n("install.optifine.get_list")) {
|
||||||
versions = new ArrayList<>();
|
HTTPGetTask task = new HTTPGetTask("http://optifine.net/downloads");
|
||||||
|
|
||||||
content = content.replace(" ", " ").replace(">", ">").replace("<", "<").replace("<br>", "<br />");
|
@Override
|
||||||
|
public Collection<Task> getDependTasks() {
|
||||||
try {
|
return Arrays.asList(task);
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
|
||||||
DocumentBuilder db = factory.newDocumentBuilder();
|
|
||||||
Document doc = db.parse(new ByteArrayInputStream(content.getBytes("UTF-8")));
|
|
||||||
Element r = doc.getDocumentElement();
|
|
||||||
NodeList tables = r.getElementsByTagName("table");
|
|
||||||
for (int i = 0; i < tables.getLength(); i++) {
|
|
||||||
Element e = (Element) tables.item(i);
|
|
||||||
if ("downloadTable".equals(e.getAttribute("class"))) {
|
|
||||||
NodeList tr = e.getElementsByTagName("tr");
|
|
||||||
for (int k = 0; k < tr.getLength(); k++) {
|
|
||||||
NodeList downloadLine = ((Element) tr.item(k)).getElementsByTagName("td");
|
|
||||||
OptiFineVersion v = new OptiFineVersion();
|
|
||||||
for (int j = 0; j < downloadLine.getLength(); j++) {
|
|
||||||
Element td = (Element) downloadLine.item(j);
|
|
||||||
if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineMirror"))
|
|
||||||
v.setMirror(((Element) td.getElementsByTagName("a").item(0)).getAttribute("href"));
|
|
||||||
if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineDownload"))
|
|
||||||
v.setDownloadLink(((Element) td.getElementsByTagName("a").item(0)).getAttribute("href"));
|
|
||||||
if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineDate"))
|
|
||||||
v.setDate(td.getTextContent());
|
|
||||||
if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineFile"))
|
|
||||||
v.setVersion(td.getTextContent());
|
|
||||||
}
|
|
||||||
if (StrUtils.isBlank(v.getMCVersion())) {
|
|
||||||
Pattern p = Pattern.compile("OptiFine (.*?) ");
|
|
||||||
Matcher m = p.matcher(v.getVersion());
|
|
||||||
while (m.find())
|
|
||||||
v.setMCVersion(StrUtils.formatVersion(m.group(1)));
|
|
||||||
}
|
|
||||||
InstallerVersion iv = new InstallerVersion(v.getVersion(), StrUtils.formatVersion(v.getMCVersion()));
|
|
||||||
iv.installer = iv.universal = v.getMirror();
|
|
||||||
root.add(v);
|
|
||||||
versions.add(iv);
|
|
||||||
|
|
||||||
List<InstallerVersion> ivl = ArrayUtils.tryGetMapWithList(versionMap, StrUtils.formatVersion(v.getMCVersion()));
|
|
||||||
ivl.add(iv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (ParserConfigurationException | SAXException | IOException | DOMException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
Collections.sort(versions, InstallerVersionComparator.INSTANCE);
|
@Override
|
||||||
|
public void executeTask() throws Throwable {
|
||||||
|
if (!areDependTasksSucceeded)
|
||||||
|
return;
|
||||||
|
String content = task.getResult();
|
||||||
|
versionMap = new HashMap<>();
|
||||||
|
versions = new ArrayList<>();
|
||||||
|
|
||||||
|
content = content.replace(" ", " ").replace(">", ">").replace("<", "<").replace("<br>", "<br />");
|
||||||
|
|
||||||
|
try {
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder db = factory.newDocumentBuilder();
|
||||||
|
Document doc = db.parse(new ByteArrayInputStream(content.getBytes("UTF-8")));
|
||||||
|
Element r = doc.getDocumentElement();
|
||||||
|
NodeList tables = r.getElementsByTagName("table");
|
||||||
|
for (int i = 0; i < tables.getLength(); i++) {
|
||||||
|
Element e = (Element) tables.item(i);
|
||||||
|
if ("downloadTable".equals(e.getAttribute("class"))) {
|
||||||
|
NodeList tr = e.getElementsByTagName("tr");
|
||||||
|
for (int k = 0; k < tr.getLength(); k++) {
|
||||||
|
NodeList downloadLine = ((Element) tr.item(k)).getElementsByTagName("td");
|
||||||
|
OptiFineVersion v = new OptiFineVersion();
|
||||||
|
for (int j = 0; j < downloadLine.getLength(); j++) {
|
||||||
|
Element td = (Element) downloadLine.item(j);
|
||||||
|
if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineMirror"))
|
||||||
|
v.setMirror(((Element) td.getElementsByTagName("a").item(0)).getAttribute("href"));
|
||||||
|
if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineDownload"))
|
||||||
|
v.setDownloadLink(((Element) td.getElementsByTagName("a").item(0)).getAttribute("href"));
|
||||||
|
if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineDate"))
|
||||||
|
v.setDate(td.getTextContent());
|
||||||
|
if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineFile"))
|
||||||
|
v.setVersion(td.getTextContent());
|
||||||
|
}
|
||||||
|
if (StrUtils.isBlank(v.getMCVersion())) {
|
||||||
|
Pattern p = Pattern.compile("OptiFine (.*?) ");
|
||||||
|
Matcher m = p.matcher(v.getVersion());
|
||||||
|
while (m.find())
|
||||||
|
v.setMCVersion(StrUtils.formatVersion(m.group(1)));
|
||||||
|
}
|
||||||
|
InstallerVersion iv = new InstallerVersion(v.getVersion(), StrUtils.formatVersion(v.getMCVersion()));
|
||||||
|
iv.installer = iv.universal = v.getMirror();
|
||||||
|
root.add(v);
|
||||||
|
versions.add(iv);
|
||||||
|
|
||||||
|
List<InstallerVersion> ivl = ArrayUtils.tryGetMapWithList(versionMap, StrUtils.formatVersion(v.getMCVersion()));
|
||||||
|
ivl.add(iv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (ParserConfigurationException | SAXException | IOException | DOMException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(versions, InstallerVersionComparator.INSTANCE);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+3
-2
@@ -19,6 +19,7 @@ package org.jackhuang.hellominecraft.launcher.core.version;
|
|||||||
|
|
||||||
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
|
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
|
||||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||||
|
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -31,14 +32,14 @@ public class LibraryDownloadInfo extends GameDownloadInfo {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUrl(DownloadType dt, boolean allowSelf) {
|
public String getUrl(DownloadType dt, boolean allowSelf) {
|
||||||
String myURL = (forgeURL == null ? dt.getProvider().getLibraryDownloadURL() : forgeURL) + "/";
|
String myURL = (forgeURL == null ? dt.getProvider().getLibraryDownloadURL() : forgeURL);
|
||||||
if (StrUtils.isNotBlank(url) && allowSelf)
|
if (StrUtils.isNotBlank(url) && allowSelf)
|
||||||
myURL = url;
|
myURL = url;
|
||||||
if (!myURL.endsWith(".jar"))
|
if (!myURL.endsWith(".jar"))
|
||||||
if (path == null)
|
if (path == null)
|
||||||
return null;
|
return null;
|
||||||
else
|
else
|
||||||
myURL += path.replace('\\', '/');
|
myURL = IOUtils.addURLSeparator(myURL) + path.replace('\\', '/');
|
||||||
return myURL;
|
return myURL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,9 +25,7 @@ import org.jackhuang.hellominecraft.launcher.setting.Settings;
|
|||||||
import org.jackhuang.hellominecraft.launcher.core.install.InstallerType;
|
import org.jackhuang.hellominecraft.launcher.core.install.InstallerType;
|
||||||
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
|
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
|
||||||
import org.jackhuang.hellominecraft.util.tasks.TaskRunnable;
|
import org.jackhuang.hellominecraft.util.tasks.TaskRunnable;
|
||||||
import org.jackhuang.hellominecraft.util.tasks.TaskRunnableArg1;
|
|
||||||
import org.jackhuang.hellominecraft.util.tasks.TaskWindow;
|
import org.jackhuang.hellominecraft.util.tasks.TaskWindow;
|
||||||
import org.jackhuang.hellominecraft.util.tasks.communication.DefaultPreviousResult;
|
|
||||||
import org.jackhuang.hellominecraft.util.MessageBox;
|
import org.jackhuang.hellominecraft.util.MessageBox;
|
||||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||||
import org.jackhuang.hellominecraft.util.ui.SwingUtils;
|
import org.jackhuang.hellominecraft.util.ui.SwingUtils;
|
||||||
@@ -123,9 +121,7 @@ public class InstallerPanel extends AnimatedPanel {
|
|||||||
InstallerType id;
|
InstallerType id;
|
||||||
|
|
||||||
void refreshVersions() {
|
void refreshVersions() {
|
||||||
if (TaskWindow.factory().append(new TaskRunnableArg1<>(C.i18n("install." + id.id + ".get_list"), list)
|
if (TaskWindow.execute(list.refresh(new String[] { gsp.getMinecraftVersionFormatted() })))
|
||||||
.registerPreviousResult(new DefaultPreviousResult<>(new String[] { gsp.getMinecraftVersionFormatted() })))
|
|
||||||
.create())
|
|
||||||
loadVersions();
|
loadVersions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +135,8 @@ public class InstallerPanel extends AnimatedPanel {
|
|||||||
MessageBox.Show(C.i18n("install.not_refreshed"));
|
MessageBox.Show(C.i18n("install.not_refreshed"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Settings.getLastProfile().service().install().download(Settings.getLastProfile().getSelectedVersion(), getVersion(idx), id).after(new TaskRunnable(this::refreshVersions)).run();
|
TaskWindow.execute(Settings.getLastProfile().service().install().download(Settings.getLastProfile().getSelectedVersion(), getVersion(idx), id),
|
||||||
|
new TaskRunnable(this::refreshVersions));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadVersions() {
|
public void loadVersions() {
|
||||||
|
|||||||
@@ -52,10 +52,10 @@ import org.jackhuang.hellominecraft.util.ui.GraphicsUtils;
|
|||||||
import org.jackhuang.hellominecraft.lookandfeel.Theme;
|
import org.jackhuang.hellominecraft.lookandfeel.Theme;
|
||||||
import org.jackhuang.hellominecraft.util.MessageBox;
|
import org.jackhuang.hellominecraft.util.MessageBox;
|
||||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||||
import org.jackhuang.hellominecraft.util.Utils;
|
|
||||||
import org.jackhuang.hellominecraft.util.ui.DropShadowBorder;
|
import org.jackhuang.hellominecraft.util.ui.DropShadowBorder;
|
||||||
import org.jackhuang.hellominecraft.util.ui.TintablePanel;
|
import org.jackhuang.hellominecraft.util.ui.TintablePanel;
|
||||||
import org.jackhuang.hellominecraft.util.ui.BasicColors;
|
import org.jackhuang.hellominecraft.util.ui.BasicColors;
|
||||||
|
import org.jackhuang.hellominecraft.util.ui.SwingUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -168,7 +168,7 @@ public final class MainFrame extends DraggableFrame {
|
|||||||
|
|
||||||
ImageIcon headerIcon = Main.getIcon("icon.png");
|
ImageIcon headerIcon = Main.getIcon("icon.png");
|
||||||
this.setIconImage(headerIcon.getImage());
|
this.setIconImage(headerIcon.getImage());
|
||||||
headerIcon = Utils.scaleImage(headerIcon, 16, 16);
|
headerIcon = SwingUtils.scaleImage(headerIcon, 16, 16);
|
||||||
JLabel headerLabel = new JLabel(headerIcon);
|
JLabel headerLabel = new JLabel(headerIcon);
|
||||||
headerLabel.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
|
headerLabel.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
|
||||||
header.add(headerLabel);
|
header.add(headerLabel);
|
||||||
@@ -318,7 +318,7 @@ public final class MainFrame extends DraggableFrame {
|
|||||||
ImageIcon background;
|
ImageIcon background;
|
||||||
|
|
||||||
public void loadBackground() {
|
public void loadBackground() {
|
||||||
background = Utils.searchBackgroundImage(Main.getIcon(Settings.getInstance().getTheme().settings.get("Customized.MainFrame.background_image")), Settings.getInstance().getBgpath(), 800, 480);
|
background = SwingUtils.searchBackgroundImage(Main.getIcon(Settings.getInstance().getTheme().settings.get("Customized.MainFrame.background_image")), Settings.getInstance().getBgpath(), 800, 480);
|
||||||
if (background != null)
|
if (background != null)
|
||||||
if (backgroundLabel == null) {
|
if (backgroundLabel == null) {
|
||||||
backgroundLabel = new JLabel(background);
|
backgroundLabel = new JLabel(background);
|
||||||
|
|||||||
@@ -19,19 +19,13 @@ package org.jackhuang.hellominecraft.util;
|
|||||||
|
|
||||||
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
||||||
import com.sun.management.OperatingSystemMXBean;
|
import com.sun.management.OperatingSystemMXBean;
|
||||||
import java.awt.Image;
|
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
import java.awt.datatransfer.StringSelection;
|
import java.awt.datatransfer.StringSelection;
|
||||||
import java.io.File;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.util.Random;
|
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author huangyuhui
|
* @author huangyuhui
|
||||||
@@ -52,18 +46,6 @@ public final class Utils {
|
|||||||
return ((URLClassLoader) Utils.class.getClassLoader()).getURLs();
|
return ((URLClassLoader) Utils.class.getClassLoader()).getURLs();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[] getURLString() {
|
|
||||||
URL[] urls = ((URLClassLoader) Utils.class.getClassLoader()).getURLs();
|
|
||||||
String[] urlStrings = new String[urls.length];
|
|
||||||
for (int i = 0; i < urlStrings.length; i++)
|
|
||||||
try {
|
|
||||||
urlStrings[i] = URLDecoder.decode(urls[i].getPath(), "UTF-8");
|
|
||||||
} catch (UnsupportedEncodingException ex) {
|
|
||||||
HMCLog.warn("Unsupported UTF-8 encoding", ex);
|
|
||||||
}
|
|
||||||
return urlStrings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getSuggestedMemorySize() {
|
public static int getSuggestedMemorySize() {
|
||||||
try {
|
try {
|
||||||
OperatingSystemMXBean osmb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
|
OperatingSystemMXBean osmb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
|
||||||
@@ -80,65 +62,6 @@ public final class Utils {
|
|||||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(text), null);
|
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(text), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ImageIcon scaleImage(ImageIcon i, int x, int y) {
|
|
||||||
return new ImageIcon(i.getImage().getScaledInstance(x, y, Image.SCALE_SMOOTH));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ImageIcon searchBackgroundImage(ImageIcon init, String bgpath, int width, int height) {
|
|
||||||
Random r = new Random();
|
|
||||||
boolean loaded = false;
|
|
||||||
ImageIcon background = init;
|
|
||||||
|
|
||||||
// bgpath
|
|
||||||
if (StrUtils.isNotBlank(bgpath) && !loaded) {
|
|
||||||
String[] backgroundPath = bgpath.split(";");
|
|
||||||
if (backgroundPath.length > 0) {
|
|
||||||
int index = r.nextInt(backgroundPath.length);
|
|
||||||
background = new ImageIcon(Toolkit.getDefaultToolkit().getImage(backgroundPath[index]).getScaledInstance(width, height, Image.SCALE_DEFAULT));
|
|
||||||
HMCLog.log("Prepared background image in bgpath.");
|
|
||||||
loaded = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// bgskin
|
|
||||||
if (!loaded) {
|
|
||||||
File backgroundImageFile = new File("bg");
|
|
||||||
if (backgroundImageFile.exists() && backgroundImageFile.isDirectory()) {
|
|
||||||
String[] backgroundPath = backgroundImageFile.list();
|
|
||||||
if (backgroundPath.length > 0) {
|
|
||||||
int index = r.nextInt(backgroundPath.length);
|
|
||||||
background = new ImageIcon(Toolkit.getDefaultToolkit().getImage("bg" + File.separator + backgroundPath[index]).getScaledInstance(width, height, Image.SCALE_DEFAULT));
|
|
||||||
HMCLog.log("Prepared background image in bgskin folder.");
|
|
||||||
loaded = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// background.png
|
|
||||||
if (!loaded) {
|
|
||||||
File backgroundImageFile = new File("background.png");
|
|
||||||
if (backgroundImageFile.exists()) {
|
|
||||||
loaded = true;
|
|
||||||
background = new ImageIcon(Toolkit.getDefaultToolkit().getImage(backgroundImageFile.getAbsolutePath()).getScaledInstance(width, height, Image.SCALE_DEFAULT));
|
|
||||||
HMCLog.log("Prepared background image in background.png.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// background.jpg
|
|
||||||
if (!loaded) {
|
|
||||||
File backgroundImageFile = new File("background.jpg");
|
|
||||||
if (backgroundImageFile.exists()) {
|
|
||||||
//loaded = true;
|
|
||||||
background = new ImageIcon(Toolkit.getDefaultToolkit().getImage(backgroundImageFile.getAbsolutePath()).getScaledInstance(width, height, Image.SCALE_DEFAULT));
|
|
||||||
HMCLog.log("Prepared background image in background.jpg.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (background == null)
|
|
||||||
return init;
|
|
||||||
return background;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In order to fight against the permission manager by Minecraft Forge.
|
* In order to fight against the permission manager by Minecraft Forge.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -54,6 +54,15 @@ public class IOUtils {
|
|||||||
return path + File.separatorChar;
|
return path + File.separatorChar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String addURLSeparator(String path) {
|
||||||
|
if (path == null || path.trim().length() == 0)
|
||||||
|
return "";
|
||||||
|
if (path.charAt(path.length() - 1) == '/')
|
||||||
|
return path;
|
||||||
|
else
|
||||||
|
return path + '/';
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isSeparator(char ch) {
|
public static boolean isSeparator(char ch) {
|
||||||
return ch == File.separatorChar || ch == '/' || ch == '\\';
|
return ch == File.separatorChar || ch == '/' || ch == '\\';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,8 @@ public class ZipEngine {
|
|||||||
files = new File[1];
|
files = new File[1];
|
||||||
files[0] = source;
|
files[0] = source;
|
||||||
}
|
}
|
||||||
|
if (files == null)
|
||||||
|
return;
|
||||||
String pathName;//存相对路径(相对于待压缩的根目录)
|
String pathName;//存相对路径(相对于待压缩的根目录)
|
||||||
for (File file : files)
|
for (File file : files)
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Hello Minecraft! Launcher.
|
||||||
|
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see {http://www.gnu.org/licenses/}.
|
||||||
|
*/
|
||||||
|
package org.jackhuang.hellominecraft.util.tasks;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author huangyuhui
|
||||||
|
*/
|
||||||
|
public class DeleteFileTask extends Task {
|
||||||
|
|
||||||
|
File f;
|
||||||
|
|
||||||
|
public DeleteFileTask(File f) {
|
||||||
|
this.f = f;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeTask() throws Throwable {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getInfo() {
|
||||||
|
return "Delete: " + f.getAbsolutePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -17,28 +17,39 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hellominecraft.util.tasks;
|
package org.jackhuang.hellominecraft.util.tasks;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author huangyuhui
|
* @author huangyuhui
|
||||||
*/
|
*/
|
||||||
public class DoubleTask extends Task {
|
public class DoubleTask extends TaskInfo {
|
||||||
|
|
||||||
Task a, b;
|
Task a, b;
|
||||||
|
|
||||||
public DoubleTask(Task a, Task b) {
|
public DoubleTask(Task a, Task b) {
|
||||||
|
this(a, b, "Double Task");
|
||||||
|
}
|
||||||
|
|
||||||
|
public DoubleTask(Task a, Task b, String info) {
|
||||||
|
super(info);
|
||||||
this.a = a;
|
this.a = a;
|
||||||
this.b = b;
|
this.b = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executeTask() throws Throwable {
|
public Collection<Task> getDependTasks() {
|
||||||
a.executeTask();
|
return Arrays.asList(a);
|
||||||
b.executeTask();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInfo() {
|
public Collection<Task> getAfterTasks() {
|
||||||
return "Double Task";
|
return Arrays.asList(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeTask() throws Throwable {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -101,6 +101,8 @@ public class TaskList extends Thread {
|
|||||||
AtomicBoolean bool = new AtomicBoolean(true);
|
AtomicBoolean bool = new AtomicBoolean(true);
|
||||||
CountDownLatch counter = new CountDownLatch(c.size());
|
CountDownLatch counter = new CountDownLatch(c.size());
|
||||||
for (Task t2 : c) {
|
for (Task t2 : c) {
|
||||||
|
if (t2 == null)
|
||||||
|
continue;
|
||||||
t2.setParallelExecuting(true);
|
t2.setParallelExecuting(true);
|
||||||
Invoker thread = new Invoker(t2, counter, bool);
|
Invoker thread = new Invoker(t2, counter, bool);
|
||||||
invokers.add(thread);
|
invokers.add(thread);
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* Hello Minecraft!.
|
|
||||||
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see {http://www.gnu.org/licenses/}.
|
|
||||||
*/
|
|
||||||
package org.jackhuang.hellominecraft.util.tasks;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import org.jackhuang.hellominecraft.util.tasks.communication.PreviousResult;
|
|
||||||
import org.jackhuang.hellominecraft.util.tasks.communication.PreviousResultRegistrar;
|
|
||||||
import org.jackhuang.hellominecraft.util.func.Consumer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author huangyuhui
|
|
||||||
* @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;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void executeTask() throws Exception {
|
|
||||||
if (al.size() != 1)
|
|
||||||
throw new IllegalStateException("the count of args is not one.");
|
|
||||||
r.accept(al.get(0).getResult());
|
|
||||||
}
|
|
||||||
|
|
||||||
ArrayList<PreviousResult<T>> al = new ArrayList();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Task registerPreviousResult(PreviousResult<T> pr) {
|
|
||||||
al.add(pr);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -216,8 +216,8 @@ public class TaskWindow extends javax.swing.JDialog
|
|||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
return;
|
return;
|
||||||
int pgs = progress * 100 / max;
|
int pgs = progress * 100 / max;
|
||||||
if (progresses.contains(idx) && progresses.get(idx) != pgs && lstDownload.getRowCount() > idx) {
|
if (progresses.size() > idx && progresses.get(idx) != pgs && lstDownload.getRowCount() > idx) {
|
||||||
SwingUtils.setValueAt(lstDownload, pgs + "%", idx, 1);
|
SwingUtils.setValueAt(lstDownload, pgs < 0 ? "???" : pgs + "%", idx, 1);
|
||||||
progresses.set(idx, pgs);
|
progresses.set(idx, pgs);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -242,7 +242,7 @@ public class TaskWindow extends javax.swing.JDialog
|
|||||||
if (taskList == null)
|
if (taskList == null)
|
||||||
return;
|
return;
|
||||||
tasks.add(task);
|
tasks.add(task);
|
||||||
progresses.add(0);
|
progresses.add(-1);
|
||||||
SwingUtils.appendLast(lstDownload, task.getInfo(), "0%");
|
SwingUtils.appendLast(lstDownload, task.getInfo(), "0%");
|
||||||
SwingUtils.moveEnd(srlDownload);
|
SwingUtils.moveEnd(srlDownload);
|
||||||
});
|
});
|
||||||
|
|||||||
+2
@@ -130,6 +130,8 @@ public class FileDownloadTask extends Task implements PreviousResult<File>, Prev
|
|||||||
if (!shouldContinue)
|
if (!shouldContinue)
|
||||||
break;
|
break;
|
||||||
try {
|
try {
|
||||||
|
if (ppl != null)
|
||||||
|
ppl.setProgress(this, -1, 1);
|
||||||
|
|
||||||
// Open connection to URL.
|
// Open connection to URL.
|
||||||
HttpURLConnection connection
|
HttpURLConnection connection
|
||||||
|
|||||||
+9
-2
@@ -57,15 +57,22 @@ public class HTTPGetTask extends TaskInfo implements PreviousResult<String> {
|
|||||||
if (repeat > 0)
|
if (repeat > 0)
|
||||||
HMCLog.warn("Failed to download, repeat: " + repeat);
|
HMCLog.warn("Failed to download, repeat: " + repeat);
|
||||||
try {
|
try {
|
||||||
|
if (ppl != null)
|
||||||
|
ppl.setProgress(this, -1, 1);
|
||||||
URLConnection conn = new URL(url).openConnection();
|
URLConnection conn = new URL(url).openConnection();
|
||||||
InputStream is = conn.getInputStream();
|
InputStream is = conn.getInputStream();
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
int i;
|
int i;
|
||||||
int size = conn.getContentLength(), read = 0;
|
int size = conn.getContentLength(), read = 0;
|
||||||
|
long lastTime = System.currentTimeMillis();
|
||||||
while ((i = is.read()) != -1) {
|
while ((i = is.read()) != -1) {
|
||||||
baos.write(i);
|
baos.write(i);
|
||||||
if (ppl != null)
|
++read;
|
||||||
ppl.setProgress(this, ++read, size);
|
long now = System.currentTimeMillis();
|
||||||
|
if (ppl != null && (now - lastTime) >= 1000) {
|
||||||
|
ppl.setProgress(this, read, size);
|
||||||
|
lastTime = now;
|
||||||
|
}
|
||||||
if (!shouldContinue)
|
if (!shouldContinue)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ package org.jackhuang.hellominecraft.util.ui;
|
|||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.EventQueue;
|
import java.awt.EventQueue;
|
||||||
import java.awt.FontMetrics;
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Frame;
|
import java.awt.Image;
|
||||||
|
import java.awt.Toolkit;
|
||||||
import java.awt.Window;
|
import java.awt.Window;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -28,7 +29,9 @@ import java.net.URI;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
import javax.swing.DefaultListModel;
|
import javax.swing.DefaultListModel;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
@@ -302,4 +305,63 @@ public class SwingUtils {
|
|||||||
else
|
else
|
||||||
thisFrame.dispose();
|
thisFrame.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ImageIcon scaleImage(ImageIcon i, int x, int y) {
|
||||||
|
return new ImageIcon(i.getImage().getScaledInstance(x, y, Image.SCALE_SMOOTH));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ImageIcon searchBackgroundImage(ImageIcon init, String bgpath, int width, int height) {
|
||||||
|
Random r = new Random();
|
||||||
|
boolean loaded = false;
|
||||||
|
ImageIcon background = init;
|
||||||
|
|
||||||
|
// bgpath
|
||||||
|
if (StrUtils.isNotBlank(bgpath) && !loaded) {
|
||||||
|
String[] backgroundPath = bgpath.split(";");
|
||||||
|
if (backgroundPath.length > 0) {
|
||||||
|
int index = r.nextInt(backgroundPath.length);
|
||||||
|
background = new ImageIcon(Toolkit.getDefaultToolkit().getImage(backgroundPath[index]).getScaledInstance(width, height, Image.SCALE_DEFAULT));
|
||||||
|
HMCLog.log("Prepared background image in bgpath.");
|
||||||
|
loaded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// bgskin
|
||||||
|
if (!loaded) {
|
||||||
|
File backgroundImageFile = new File("bg");
|
||||||
|
if (backgroundImageFile.exists() && backgroundImageFile.isDirectory()) {
|
||||||
|
String[] backgroundPath = backgroundImageFile.list();
|
||||||
|
if (backgroundPath.length > 0) {
|
||||||
|
int index = r.nextInt(backgroundPath.length);
|
||||||
|
background = new ImageIcon(Toolkit.getDefaultToolkit().getImage("bg" + File.separator + backgroundPath[index]).getScaledInstance(width, height, Image.SCALE_DEFAULT));
|
||||||
|
HMCLog.log("Prepared background image in bgskin folder.");
|
||||||
|
loaded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// background.png
|
||||||
|
if (!loaded) {
|
||||||
|
File backgroundImageFile = new File("background.png");
|
||||||
|
if (backgroundImageFile.exists()) {
|
||||||
|
loaded = true;
|
||||||
|
background = new ImageIcon(Toolkit.getDefaultToolkit().getImage(backgroundImageFile.getAbsolutePath()).getScaledInstance(width, height, Image.SCALE_DEFAULT));
|
||||||
|
HMCLog.log("Prepared background image in background.png.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// background.jpg
|
||||||
|
if (!loaded) {
|
||||||
|
File backgroundImageFile = new File("background.jpg");
|
||||||
|
if (backgroundImageFile.exists()) {
|
||||||
|
//loaded = true;
|
||||||
|
background = new ImageIcon(Toolkit.getDefaultToolkit().getImage(backgroundImageFile.getAbsolutePath()).getScaledInstance(width, height, Image.SCALE_DEFAULT));
|
||||||
|
HMCLog.log("Prepared background image in background.jpg.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (background == null)
|
||||||
|
return init;
|
||||||
|
return background;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user