Merge pull request #100 from InfinityStudio/master

Rollback Changes
This commit is contained in:
huanghongxun
2017-02-01 12:22:38 +08:00
committed by GitHub
253 changed files with 6202 additions and 6488 deletions

View File

@@ -17,9 +17,6 @@ deploy:
- HMCL/build/libs/HMCL-${HMCL_VERSION_ROOT}.${TRAVIS_BUILD_NUMBER}.jar - HMCL/build/libs/HMCL-${HMCL_VERSION_ROOT}.${TRAVIS_BUILD_NUMBER}.jar
- HMCL/build/libs/HMCL-${HMCL_VERSION_ROOT}.${TRAVIS_BUILD_NUMBER}.exe - HMCL/build/libs/HMCL-${HMCL_VERSION_ROOT}.${TRAVIS_BUILD_NUMBER}.exe
- HMCL/build/libs/HMCL-${HMCL_VERSION_ROOT}.${TRAVIS_BUILD_NUMBER}-MacOSApp.zip - HMCL/build/libs/HMCL-${HMCL_VERSION_ROOT}.${TRAVIS_BUILD_NUMBER}-MacOSApp.zip
- HMCSM/build/libs/HMCSM-${HMCSM_VERSION_ROOT}.${TRAVIS_BUILD_NUMBER}.jar
- HMCSM/build/libs/HMCSM-${HMCSM_VERSION_ROOT}.${TRAVIS_BUILD_NUMBER}.exe
- HMCSM/build/libs/HMCSM-${HMCSM_VERSION_ROOT}.${TRAVIS_BUILD_NUMBER}-MacOSApp.zip
on: on:
repo: huanghongxun/HMCL repo: huanghongxun/HMCL
tags: false tags: false
@@ -28,7 +25,7 @@ install: echo "skip 'gradle assemble' step"
script: gradle build --continue script: gradle build --continue
before_cache: before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
cache: #cache:
directories: # directories:
- "$HOME/.gradle/caches/" # - "$HOME/.gradle/caches/"
- "$HOME/.gradle/wrapper/" # - "$HOME/.gradle/wrapper/"

View File

@@ -15,33 +15,16 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}. * along with this program. If not, see {http://www.gnu.org/licenses/}.
*/ */
buildscript {
repositories {
mavenCentral();
maven {
url "https://libraries.minecraft.net"
}
dependencies {
classpath 'net.sf.proguard:proguard-gradle:4.10'
classpath 'edu.sc.seis.gradle:launch4j:1.0.6'
classpath 'me.tatarka:gradle-retrolambda:3.1.0'
}
}
}
plugins { plugins {
id "edu.sc.seis.macAppBundle" version "2.1.6" id "edu.sc.seis.macAppBundle" version "2.1.6"
id "me.tatarka.retrolambda" version "3.5.0"
id 'edu.sc.seis.launch4j' version '2.3.0'
} }
import java.util.jar.JarOutputStream import java.util.jar.JarOutputStream
import java.util.zip.ZipEntry import java.util.zip.ZipEntry
import java.util.zip.ZipFile import java.util.zip.ZipFile
apply plugin: 'launch4j'
apply plugin: 'me.tatarka.retrolambda'
if (!hasProperty('mainClass')) { if (!hasProperty('mainClass')) {
ext.mainClass = 'org.jackhuang.hellominecraft.launcher.Main' ext.mainClass = 'org.jackhuang.hellominecraft.launcher.Main'
} }
@@ -50,11 +33,11 @@ def buildnumber = System.getenv("TRAVIS_BUILD_NUMBER")
if (buildnumber == null) if (buildnumber == null)
buildnumber = System.getenv("BUILD_NUMBER") buildnumber = System.getenv("BUILD_NUMBER")
if (buildnumber == null) if (buildnumber == null)
buildnumber = "233" buildnumber = "4"
def versionroot = System.getenv("VERSION_ROOT") def versionroot = System.getenv("VERSION_ROOT")
if (versionroot == null) if (versionroot == null)
versionroot = "2.4.1" versionroot = "2.6.0"
String mavenGroupId = 'HMCL' String mavenGroupId = 'HMCL'
String mavenVersion = versionroot + '.' + buildnumber String mavenVersion = versionroot + '.' + buildnumber
@@ -146,8 +129,6 @@ jar {
} }
launch4j { launch4j {
launch4jCmd = 'D:\\Develop\\Java\\Launch4j\\launch4j.exe'
//launch4jCmd = '/home/huangyuhui/softwares/launch4j/launch4j'
supportUrl = 'http://www.mcbbs.net/thread-142335-1-1.html' supportUrl = 'http://www.mcbbs.net/thread-142335-1-1.html'
jreMinVersion = '1.6.0' jreMinVersion = '1.6.0'

View File

@@ -17,7 +17,7 @@
*/ */
package org.jackhuang.hellominecraft.launcher.api; package org.jackhuang.hellominecraft.launcher.api;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
/** /**
* *
@@ -27,18 +27,11 @@ public class PluginManager {
private static IPlugin NOW_PLUGIN; private static IPlugin NOW_PLUGIN;
public static void getServerPlugin() {
try {
getPlugin(Thread.currentThread().getContextClassLoader().loadClass("org.jackhuang.hellominecraft.launcher.server.ServerPlugin"));
} catch (ClassNotFoundException ignore) {
}
}
public static void getPlugin(Class<?> cls) { public static void getPlugin(Class<?> cls) {
try { try {
IPlugin p = (IPlugin) cls.newInstance(); IPlugin p = (IPlugin) cls.newInstance();
NOW_PLUGIN = p; NOW_PLUGIN = p;
} catch (Exception e) { } catch (IllegalAccessException | InstantiationException e) {
HMCLog.err("Failed to new instance"); HMCLog.err("Failed to new instance");
} }
} }

View File

@@ -19,8 +19,8 @@ package org.jackhuang.hellominecraft.launcher.core;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.util.system.OS; import org.jackhuang.hellominecraft.util.sys.OS;
/** /**
* *

View File

@@ -38,7 +38,7 @@ public class AssetsIndex {
public boolean virtual; public boolean virtual;
public AssetsIndex() { public AssetsIndex() {
this.objects = new LinkedHashMap(); this.objects = new LinkedHashMap<>();
} }
public Map<String, AssetsObject> getFileMap() { public Map<String, AssetsObject> getFileMap() {
@@ -46,7 +46,7 @@ public class AssetsIndex {
} }
public Set<AssetsObject> getUniqueObjects() { public Set<AssetsObject> getUniqueObjects() {
return new HashSet(this.objects.values()); return new HashSet<>(this.objects.values());
} }
public boolean isVirtual() { public boolean isVirtual() {

View File

@@ -23,18 +23,18 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftAssetService; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftAssetService;
import org.jackhuang.hellominecraft.util.tasks.Task; import org.jackhuang.hellominecraft.util.task.Task;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.util.system.IOUtils; import org.jackhuang.hellominecraft.util.sys.IOUtils;
import org.jackhuang.hellominecraft.util.StrUtils; import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.launcher.core.download.IDownloadProvider; import org.jackhuang.hellominecraft.launcher.core.download.IDownloadProvider;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.util.Utils;
import org.jackhuang.hellominecraft.util.VersionNumber; import org.jackhuang.hellominecraft.util.VersionNumber;
import org.jackhuang.hellominecraft.util.tasks.TaskInfo; import org.jackhuang.hellominecraft.util.task.TaskInfo;
/** /**
* *
@@ -48,7 +48,7 @@ public class AssetsMojangLoader extends IAssetsHandler {
@Override @Override
public Task getList(final MinecraftVersion mv, final IMinecraftAssetService mp) { public Task getList(final MinecraftVersion mv, final IMinecraftAssetService mp) {
Utils.requireNonNull(mv); Objects.requireNonNull(mv);
String assetsId = mv.getAssetsIndex().getId(); String assetsId = mv.getAssetsIndex().getId();
File assets = mp.getAssets(); File assets = mp.getAssets();
HMCLog.log("Gathering asset index: " + assetsId); HMCLog.log("Gathering asset index: " + assetsId);
@@ -63,7 +63,7 @@ public class AssetsMojangLoader extends IAssetsHandler {
} }
@Override @Override
public void executeTask() throws Throwable { public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
if (!areDependTasksSucceeded) if (!areDependTasksSucceeded)
throw new IllegalStateException("Failed to get asset index"); throw new IllegalStateException("Failed to get asset index");
String result = FileUtils.read(f); String result = FileUtils.read(f);
@@ -72,7 +72,6 @@ public class AssetsMojangLoader extends IAssetsHandler {
AssetsIndex o = C.GSON.fromJson(result, AssetsIndex.class); AssetsIndex o = C.GSON.fromJson(result, AssetsIndex.class);
assetsDownloadURLs = new ArrayList<>(); assetsDownloadURLs = new ArrayList<>();
assetsLocalNames = new ArrayList<>(); assetsLocalNames = new ArrayList<>();
ArrayList<String> al = new ArrayList<>();
contents = new ArrayList<>(); contents = new ArrayList<>();
HashSet<String> loadedHashes = new HashSet<>(); HashSet<String> loadedHashes = new HashSet<>();
int pgs = 0; int pgs = 0;
@@ -88,7 +87,6 @@ public class AssetsMojangLoader extends IAssetsHandler {
contents.add(c); contents.add(c);
assetsDownloadURLs.add(c.key); assetsDownloadURLs.add(c.key);
assetsLocalNames.add(new File(assets, "objects" + File.separator + c.key.replace("/", File.separator))); assetsLocalNames.add(new File(assets, "objects" + File.separator + c.key.replace("/", File.separator)));
al.add(e.getKey());
if (ppl != null) if (ppl != null)
ppl.setProgress(this, ++pgs, o.getFileMap().size()); ppl.setProgress(this, ++pgs, o.getFileMap().size());
} }

View File

@@ -26,11 +26,6 @@ public class AssetsObject {
private String hash; private String hash;
private long size; private long size;
public AssetsObject(String hash, long size) {
this.hash = hash;
this.size = size;
}
public void setHash(String hash) { public void setHash(String hash) {
this.hash = hash; this.hash = hash;
} }

View File

@@ -28,15 +28,6 @@ public class Contents {
public Contents() { public Contents() {
} }
public Contents(String key, String eTag, String lastModified, String storageClass, long size) {
this();
this.key = key;
this.eTag = eTag;
this.lastModified = lastModified;
this.storageClass = storageClass;
this.size = size;
}
public String getKey() { public String getKey() {
return key; return key;
} }

View File

@@ -24,17 +24,16 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftAssetService; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftAssetService;
import org.jackhuang.hellominecraft.launcher.core.download.IDownloadProvider; import org.jackhuang.hellominecraft.launcher.core.download.IDownloadProvider;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.util.tasks.Task; import org.jackhuang.hellominecraft.util.task.Task;
import org.jackhuang.hellominecraft.util.tasks.download.FileDownloadTask; import org.jackhuang.hellominecraft.util.net.FileDownloadTask;
import org.jackhuang.hellominecraft.util.code.DigestUtils; import org.jackhuang.hellominecraft.util.code.DigestUtils;
import org.jackhuang.hellominecraft.util.system.IOUtils; import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.util.NetUtils; import org.jackhuang.hellominecraft.util.sys.IOUtils;
import org.jackhuang.hellominecraft.util.OverridableSwingWorker; import org.jackhuang.hellominecraft.util.task.TaskInfo;
import org.jackhuang.hellominecraft.util.tasks.TaskInfo;
/** /**
* Assets * Assets
@@ -72,7 +71,7 @@ public abstract class IAssetsHandler {
* *
* @param mv The version that needs assets * @param mv The version that needs assets
* @param mp Asset Service * @param mp Asset Service
* @param x finished event * @return just run it!
*/ */
public abstract Task getList(MinecraftVersion mv, IMinecraftAssetService mp); public abstract Task getList(MinecraftVersion mv, IMinecraftAssetService mp);
@@ -98,7 +97,7 @@ public abstract class IAssetsHandler {
} }
@Override @Override
public void executeTask() { public void executeTask(boolean areDependTasksSucceeded) {
if (assetsDownloadURLs == null || assetsLocalNames == null || contents == null) if (assetsDownloadURLs == null || assetsLocalNames == null || contents == null)
throw new IllegalStateException(C.i18n("assets.not_refreshed")); throw new IllegalStateException(C.i18n("assets.not_refreshed"));
int max = assetsDownloadURLs.size(); int max = assetsDownloadURLs.size();
@@ -108,15 +107,15 @@ public abstract class IAssetsHandler {
String mark = assetsDownloadURLs.get(i); String mark = assetsDownloadURLs.get(i);
String url = u + mark; String url = u + mark;
File location = assetsLocalNames.get(i); File location = assetsLocalNames.get(i);
if (!location.getParentFile().exists() && !location.getParentFile().mkdirs()) if (!FileUtils.makeDirectory(location.getParentFile()))
HMCLog.warn("Failed to make directories: " + location.getParent()); HMCLog.warn("Failed to make directories: " + location.getParent());
if (location.isDirectory()) if (location.isDirectory())
continue; continue;
boolean need = true; boolean need = true;
try { try {
if (location.exists()) { if (location.exists()) {
FileInputStream fis = new FileInputStream(location); FileInputStream fis = FileUtils.openInputStream(location);
String sha = DigestUtils.sha1Hex(NetUtils.getBytesFromStream(fis)); String sha = DigestUtils.sha1Hex(IOUtils.toByteArray(fis));
IOUtils.closeQuietly(fis); IOUtils.closeQuietly(fis);
if (contents.get(i).geteTag().equals(sha)) { if (contents.get(i).geteTag().equals(sha)) {
++hasDownloaded; ++hasDownloaded;
@@ -131,7 +130,7 @@ public abstract class IAssetsHandler {
need = !location.exists(); need = !location.exists();
} }
if (need) if (need)
al.add(new FileDownloadTask(url, location).setTag(mark)); al.add(new FileDownloadTask(url, location).setTag(contents.get(i).geteTag()));
} }
} }

View File

@@ -23,20 +23,21 @@ import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.launch.IAssetProvider;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftAssetService; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftAssetService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService; 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.func.BiFunction; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.task.Task;
import org.jackhuang.hellominecraft.util.tasks.Task; import org.jackhuang.hellominecraft.util.task.TaskWindow;
import org.jackhuang.hellominecraft.util.tasks.TaskWindow; import org.jackhuang.hellominecraft.util.net.FileDownloadTask;
import org.jackhuang.hellominecraft.util.tasks.download.FileDownloadTask; import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.sys.IOUtils;
import org.jackhuang.hellominecraft.util.system.IOUtils; import org.jackhuang.hellominecraft.util.task.TaskInfo;
import org.jackhuang.hellominecraft.util.tasks.TaskInfo;
/** /**
* *
@@ -49,33 +50,33 @@ public class MinecraftAssetService extends IMinecraftAssetService {
} }
@Override @Override
public Task downloadAssets(final String mcVersion) { public Task downloadAssets(final String mcVersion) throws GameException {
return downloadAssets(service.version().getVersionById(mcVersion)); return downloadAssets(service.version().getVersionById(mcVersion));
} }
public Task downloadAssets(final MinecraftVersion mv) { public Task downloadAssets(final MinecraftVersion mv) throws GameException {
if (mv == null) if (mv == null)
return null; return null;
return IAssetsHandler.ASSETS_HANDLER.getList(mv, service.asset()).after(IAssetsHandler.ASSETS_HANDLER.getDownloadTask(service.getDownloadType().getProvider())); return IAssetsHandler.ASSETS_HANDLER.getList(mv.resolve(service.version()), service.asset()).with(IAssetsHandler.ASSETS_HANDLER.getDownloadTask(service.getDownloadType().getProvider()));
} }
@Override @Override
public boolean refreshAssetsIndex(String id) { public boolean refreshAssetsIndex(String id) throws GameException {
MinecraftVersion mv = service.version().getVersionById(id); MinecraftVersion mv = service.version().getVersionById(id);
if (mv == null) if (mv == null)
return false; return false;
return downloadMinecraftAssetsIndexAsync(mv.getAssetsIndex()); return downloadMinecraftAssetsIndexAsync(mv.resolve(service.version()).getAssetsIndex());
} }
@Override @Override
public Task downloadMinecraftAssetsIndex(AssetIndexDownloadInfo assets) { public Task downloadMinecraftAssetsIndex(AssetIndexDownloadInfo assetIndex) {
File assetsLocation = getAssets(); File assetsLocation = getAssets();
if (!assetsLocation.exists() && !assetsLocation.mkdirs()) if (!FileUtils.makeDirectory(assetsLocation))
HMCLog.warn("Failed to make directories: " + assetsLocation); HMCLog.warn("Failed to make directories: " + assetsLocation);
File assetsIndex = new File(assetsLocation, "indexes/" + assets.getId() + ".json"); File assetsIndex = getIndexFile(assetIndex.getId());
File renamed = null; File renamed = null;
if (assetsIndex.exists()) { if (assetsIndex.exists()) {
renamed = new File(assetsLocation, "indexes/" + assets.getId() + "-renamed.json"); renamed = new File(assetsLocation, "indexes/" + assetIndex.getId() + "-renamed.json");
if (assetsIndex.renameTo(renamed)) if (assetsIndex.renameTo(renamed))
HMCLog.warn("Failed to rename " + assetsIndex + " to " + renamed); HMCLog.warn("Failed to rename " + assetsIndex + " to " + renamed);
} }
@@ -83,11 +84,11 @@ public class MinecraftAssetService extends IMinecraftAssetService {
return new TaskInfo("Download Asset Index") { return new TaskInfo("Download Asset Index") {
@Override @Override
public Collection<Task> getDependTasks() { public Collection<Task> getDependTasks() {
return Arrays.asList(new FileDownloadTask(assets.getUrl(service.getDownloadType()), IOUtils.tryGetCanonicalFile(assetsIndex), assets.sha1).setTag(assets.getId() + ".json")); return Arrays.asList(new FileDownloadTask(assetIndex.getUrl(service.getDownloadType()), IOUtils.tryGetCanonicalFile(assetsIndex), assetIndex.sha1).setTag(assetIndex.getId() + ".json"));
} }
@Override @Override
public void executeTask() throws Throwable { public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
if (areDependTasksSucceeded) { if (areDependTasksSucceeded) {
if (renamedFinal != null && !renamedFinal.delete()) if (renamedFinal != null && !renamedFinal.delete())
HMCLog.warn("Failed to delete " + renamedFinal + ", maybe you should do it."); HMCLog.warn("Failed to delete " + renamedFinal + ", maybe you should do it.");
@@ -98,20 +99,20 @@ public class MinecraftAssetService extends IMinecraftAssetService {
} }
@Override @Override
public boolean downloadMinecraftAssetsIndexAsync(AssetIndexDownloadInfo assets) { public boolean downloadMinecraftAssetsIndexAsync(AssetIndexDownloadInfo assetIndex) {
File assetsLocation = getAssets(); File assetsDir = getAssets();
if (!assetsLocation.exists() && !assetsLocation.mkdirs()) if (!FileUtils.makeDirectory(assetsDir))
HMCLog.warn("Failed to make directories: " + assetsLocation); HMCLog.warn("Failed to make directories: " + assetsDir);
File assetsIndex = new File(assetsLocation, "indexes/" + assets.getId() + ".json"); File assetsIndex = getIndexFile(assetIndex.getId());
File renamed = null; File renamed = null;
if (assetsIndex.exists()) { if (assetsIndex.exists()) {
renamed = new File(assetsLocation, "indexes/" + assets.getId() + "-renamed.json"); renamed = new File(assetsDir, "indexes/" + assetIndex.getId() + "-renamed.json");
if (assetsIndex.renameTo(renamed)) if (assetsIndex.renameTo(renamed))
HMCLog.warn("Failed to rename " + assetsIndex + " to " + renamed); HMCLog.warn("Failed to rename " + assetsIndex + " to " + renamed);
} }
if (TaskWindow.factory() if (TaskWindow.factory()
.append(new FileDownloadTask(assets.getUrl(service.getDownloadType()), IOUtils.tryGetCanonicalFile(assetsIndex), assets.sha1).setTag(assets.getId() + ".json")) .append(new FileDownloadTask(assetIndex.getUrl(service.getDownloadType()), IOUtils.tryGetCanonicalFile(assetsIndex), assetIndex.sha1).setTag(assetIndex.getId() + ".json"))
.create()) { .execute()) {
if (renamed != null && !renamed.delete()) if (renamed != null && !renamed.delete())
HMCLog.warn("Failed to delete " + renamed + ", maybe you should do it."); HMCLog.warn("Failed to delete " + renamed + ", maybe you should do it.");
return true; return true;
@@ -125,30 +126,27 @@ public class MinecraftAssetService extends IMinecraftAssetService {
public File getAssets() { public File getAssets() {
return new File(service.baseDirectory(), "assets"); return new File(service.baseDirectory(), "assets");
} }
private File getIndexFile(String assetVersion) {
return new File(getAssets(), "indexes/" + assetVersion + ".json");
}
@Override @Override
public File getAssetObject(String assetVersion, String name) throws IOException { public File getAssetObject(String assetVersion, String name) throws IOException {
File assetsDir = getAssets();
File indexDir = new File(assetsDir, "indexes");
File objectsDir = new File(assetsDir, "objects");
File indexFile = new File(indexDir, assetVersion + ".json");
try { try {
AssetsIndex index = (AssetsIndex) C.GSON.fromJson(FileUtils.read(indexFile, "UTF-8"), AssetsIndex.class); AssetsIndex index = (AssetsIndex) C.GSON.fromJson(FileUtils.read(getIndexFile(assetVersion), "UTF-8"), AssetsIndex.class);
String hash = ((AssetsObject) index.getFileMap().get(name)).getHash(); String hash = ((AssetsObject) index.getFileMap().get(name)).getHash();
return new File(objectsDir, hash.substring(0, 2) + "/" + hash); return new File(getAssets(), "objects/" + hash.substring(0, 2) + "/" + hash);
} catch (JsonSyntaxException e) { } catch (JsonSyntaxException e) {
throw new IOException("Assets file format malformed.", e); throw new IOException("Assets file format malformed.", e);
} }
} }
private boolean checkAssetsExistance(AssetIndexDownloadInfo assetIndex) { private boolean checkAssetsExistance(AssetIndexDownloadInfo assetIndex) {
File assetsDir = getAssets(); File indexFile = getIndexFile(assetIndex.getId());
File indexDir = new File(assetsDir, "indexes");
File objectDir = new File(assetsDir, "objects");
File indexFile = new File(indexDir, assetIndex.getId() + ".json");
if (!assetsDir.exists() || !indexFile.isFile()) if (!getAssets().exists() || !indexFile.isFile())
return false; return false;
try { try {
@@ -157,8 +155,8 @@ public class MinecraftAssetService extends IMinecraftAssetService {
if (index == null) if (index == null)
return false; return false;
for (Map.Entry entry : index.getFileMap().entrySet()) for (Map.Entry<String, AssetsObject> entry : index.getFileMap().entrySet())
if (!new File(new File(objectDir, ((AssetsObject) entry.getValue()).getHash().substring(0, 2)), ((AssetsObject) entry.getValue()).getHash()).exists()) if (!new File(getAssets(), "objects/" + ((AssetsObject) entry.getValue()).getHash().substring(0, 2) + "/" + ((AssetsObject) entry.getValue()).getHash()).exists())
return false; return false;
return true; return true;
} catch (IOException | JsonSyntaxException e) { } catch (IOException | JsonSyntaxException e) {
@@ -168,10 +166,8 @@ public class MinecraftAssetService extends IMinecraftAssetService {
private File reconstructAssets(AssetIndexDownloadInfo assetIndex) { private File reconstructAssets(AssetIndexDownloadInfo assetIndex) {
File assetsDir = getAssets(); File assetsDir = getAssets();
File indexDir = new File(assetsDir, "indexes");
File objectDir = new File(assetsDir, "objects");
String assetVersion = assetIndex.getId(); String assetVersion = assetIndex.getId();
File indexFile = new File(indexDir, assetVersion + ".json"); File indexFile = getIndexFile(assetVersion);
File virtualRoot = new File(new File(assetsDir, "virtual"), assetVersion); File virtualRoot = new File(new File(assetsDir, "virtual"), assetVersion);
if (!indexFile.isFile()) { if (!indexFile.isFile()) {
@@ -189,9 +185,9 @@ public class MinecraftAssetService extends IMinecraftAssetService {
int cnt = 0; int cnt = 0;
HMCLog.log("Reconstructing virtual assets folder at " + virtualRoot); HMCLog.log("Reconstructing virtual assets folder at " + virtualRoot);
int tot = index.getFileMap().entrySet().size(); int tot = index.getFileMap().entrySet().size();
for (Map.Entry entry : index.getFileMap().entrySet()) { for (Map.Entry<String, AssetsObject> entry : index.getFileMap().entrySet()) {
File target = new File(virtualRoot, (String) entry.getKey()); File target = new File(virtualRoot, (String) entry.getKey());
File original = new File(new File(objectDir, ((AssetsObject) entry.getValue()).getHash().substring(0, 2)), ((AssetsObject) entry.getValue()).getHash()); File original = new File(assetsDir, "objects/" + ((AssetsObject) entry.getValue()).getHash().substring(0, 2) + "/" + ((AssetsObject) entry.getValue()).getHash());
if (original.exists()) { if (original.exists()) {
cnt++; cnt++;
if (!target.isFile()) if (!target.isFile())
@@ -209,10 +205,10 @@ public class MinecraftAssetService extends IMinecraftAssetService {
return virtualRoot; return virtualRoot;
} }
public final BiFunction<MinecraftVersion, Boolean, String> ASSET_PROVIDER_IMPL = (t, allow) -> { public final IAssetProvider ASSET_PROVIDER_IMPL = (t, allow) -> {
if (allow && !checkAssetsExistance(t.getAssetsIndex())) if (allow && !checkAssetsExistance(t.getAssetsIndex()))
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)
TaskWindow.execute(downloadAssets(t)); TaskWindow.factory().execute(downloadAssets(t));
return reconstructAssets(t.getAssetsIndex()).getAbsolutePath(); return reconstructAssets(t.getAssetsIndex()).getAbsolutePath();
}; };
} }

View File

@@ -1,106 +0,0 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.core.auth;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.Charset;
import org.jackhuang.hellominecraft.util.code.DigestUtils;
/**
*
* @author huangyuhui
*/
public final class BestLogin extends IAuthenticator {
public BestLogin(String clientToken) {
super(clientToken);
}
@Override
public UserProfileProvider login(LoginInfo info) throws AuthenticationException {
try {
String request = "bl:l:" + info.username + ":" + DigestUtils.sha1Hex(info.password);
Socket socket = new Socket("auth.zhh0000zhh.com", 8);
OutputStream os = socket.getOutputStream();
os.write(request.length());
os.write(request.getBytes(Charset.forName("UTF-8")));
UserProfileProvider lr = new UserProfileProvider();
InputStream is = socket.getInputStream();
int code = is.read();
switch (code) {
case -1:
throw new AuthenticationException("internet error.");
case 200:
throw new AuthenticationException("server restarting.");
case 255:
throw new AuthenticationException("unknown error");
case 3:
throw new AuthenticationException("unregistered.");
case 50:
throw new AuthenticationException("please update your launcher and act your account.");
case 2:
throw new AuthenticationException("wrong password.");
case 100:
throw new AuthenticationException("server reloading.");
case 0:
byte[] b = new byte[64];
int x = is.read(b, 0, b.length);
if (x != -1)
throw new AuthenticationException("server response does not follow the protocol.");
String[] ss = new String(b, Charset.forName("UTF-8")).split(":");
lr.setUserName(info.username);
lr.setUserId(ss[1]);
lr.setSession(ss[0]);
lr.setAccessToken(ss[0]);
break;
default:
break;
}
lr.setUserType("Legacy");
return lr;
} catch (IOException t) {
throw new AuthenticationException(t);
}
}
@Override
public String id() {
return "best";
}
@Override
public String getName() {
return "BestLogin";
}
@Override
public UserProfileProvider loginBySettings() {
return null;
}
@Override
public void logOut() {
}
}

View File

@@ -87,13 +87,13 @@ public abstract class IAuthenticator {
public abstract void logOut(); public abstract void logOut();
public Map onSaveSettings() { public Map<?, ?> onSaveSettings() {
HashMap<String, String> m = new HashMap<>(); HashMap<String, String> m = new HashMap<>();
m.put("IAuthenticator_UserName", username); m.put("IAuthenticator_UserName", username);
return m; return m;
} }
public void onLoadSettings(Map m) { public void onLoadSettings(Map<?, ?> m) {
if (m == null) if (m == null)
return; return;
Object o = m.get("IAuthenticator_UserName"); Object o = m.get("IAuthenticator_UserName");

View File

@@ -29,7 +29,7 @@ import org.jackhuang.hellominecraft.util.code.DigestUtils;
*/ */
public final class OfflineAuthenticator extends IAuthenticator { public final class OfflineAuthenticator extends IAuthenticator {
Map<String, String> uuidMap = new HashMap<>(); Map uuidMap = new HashMap<>();
public OfflineAuthenticator(String clientToken) { public OfflineAuthenticator(String clientToken) {
super(clientToken); super(clientToken);
@@ -42,7 +42,7 @@ public final class OfflineAuthenticator extends IAuthenticator {
return; return;
Object o = m.get("uuidMap"); Object o = m.get("uuidMap");
if (o != null && o instanceof Map) if (o != null && o instanceof Map)
uuidMap = (Map<String, String>) o; uuidMap = (Map<?, ?>) o;
} }
@Override @Override
@@ -56,21 +56,21 @@ public final class OfflineAuthenticator extends IAuthenticator {
public UserProfileProvider login(LoginInfo info) throws AuthenticationException { public UserProfileProvider login(LoginInfo info) throws AuthenticationException {
if (StrUtils.isBlank(info.username)) if (StrUtils.isBlank(info.username))
throw new AuthenticationException(C.i18n("login.no_Player007")); throw new AuthenticationException(C.i18n("login.no_Player007"));
UserProfileProvider result = new UserProfileProvider();
result.setUserName(info.username);
String uuid = getUUIDFromUserName(info.username); String uuid = getUUIDFromUserName(info.username);
if (uuidMap != null && uuidMap.containsKey(uuid)) if (uuidMap != null && uuidMap.containsKey(info.username) && uuidMap.get(info.username) instanceof String)
uuid = uuidMap.get(info.username); uuid = (String) uuidMap.get(info.username);
else { else {
if (uuidMap == null) if (uuidMap == null)
uuidMap = new HashMap<>(); uuidMap = new HashMap<>();
uuidMap.put(info.username, uuid); uuidMap.put(info.username, uuid);
} }
result.setSession(uuid); return new UserProfileProvider()
result.setUserId(uuid); .setUserName(info.username)
result.setAccessToken(uuid); .setSession(uuid)
result.setUserType("Legacy"); .setUserId(uuid)
return result; .setAccessToken(uuid)
.setUserType("Legacy")
.setClientIdentifier(clientToken);
} }
public static String getUUIDFromUserName(String str) { public static String getUUIDFromUserName(String str) {

View File

@@ -1,123 +0,0 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.core.auth;
import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.code.DigestUtils;
import org.jackhuang.hellominecraft.util.NetUtils;
import org.jackhuang.hellominecraft.util.lang.SupportedLocales;
import org.jackhuang.hellominecraft.util.ui.SwingUtils;
/**
*
* @author huangyuhui
*/
public final class SkinmeAuthenticator extends IAuthenticator {
public SkinmeAuthenticator(String clientToken) {
super(clientToken);
}
public String[] parseType1(String s) {
return s.split(",");
}
public String getCharacter(String user, String hash, String $char) throws Exception {
return NetUtils.get(
"http://www.skinme.cc/api/login.php?user=" + user + "&hash=" + hash + (($char == null) ? "" : ("&char=" + $char)));
}
@Override
public UserProfileProvider login(LoginInfo info) throws AuthenticationException {
UserProfileProvider req = new UserProfileProvider();
if (info.username == null || !info.username.contains("@"))
throw new AuthenticationException(C.i18n("login.not_email"));
try {
String usr = info.username.toLowerCase(SupportedLocales.NOW_LOCALE.self);
String pwd = info.password;
String str = DigestUtils.sha1Hex(usr);
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]) {
case "0":
if (sl[1].contains("No Valid Character"))
sl[1] = C.i18n("login.no_valid_character");
throw new AuthenticationException(sl[1]);
case "1":
String[] s = parseType1(sl[1]);
req.setUserName(s[0]);
req.setSession(s[1]);
req.setUserId(s[1]);
req.setAccessToken(s[1]);
break;
case "2":
String[] charators = sl[1].split(";");
int len = charators.length;
String[] $char = new String[len];
String[] user = new String[len];
System.out.println(sl[1]);
for (int i = 0; i < len; i++) {
String[] charator = charators[i].split(",");
$char[i] = charator[0];
user[i] = charator[1];
}
int index = SwingUtils.select(user, C.i18n("login.choose_charactor"));
if (index == -1)
throw new AuthenticationException(C.i18n("message.cancelled"));
else {
String character = $char[index];
sl = getCharacter(usr, hashCode, character).split(":");
String[] s2 = parseType1(sl[1]);
req.setUserName(s2[0]);
req.setSession(s2[1]);
req.setUserId(s2[1]);
req.setAccessToken(s2[1]);
}
break;
}
req.setUserType("Legacy");
return req;
} catch (Exception e) {
throw new AuthenticationException(e);
}
}
@Override
public String id() {
return "skinme";
}
@Override
public String getName() {
return "Skinme";
}
@Override
public UserProfileProvider loginBySettings() {
return null;
}
@Override
public void logOut() {
}
}

View File

@@ -27,74 +27,83 @@ public final class UserProfileProvider {
return username; return username;
} }
public void setUserName(String username) { public UserProfileProvider setUserName(String username) {
this.username = username; this.username = username;
return this;
} }
public String getUserId() { public String getUserId() {
return userId; return userId;
} }
public void setUserId(String userId) { public UserProfileProvider setUserId(String userId) {
this.userId = userId; this.userId = userId;
return this;
} }
public String getSession() { public String getSession() {
return session; return session;
} }
public void setSession(String session) { public UserProfileProvider setSession(String session) {
this.session = session; this.session = session;
return this;
} }
public String getAccessToken() { public String getAccessToken() {
return accessToken; return accessToken;
} }
public void setAccessToken(String accessToken) { public UserProfileProvider setAccessToken(String accessToken) {
if (accessToken == null) if (accessToken == null)
accessToken = "0"; accessToken = "0";
this.accessToken = accessToken; this.accessToken = accessToken;
return this;
} }
public String getUserProperties() { public String getUserProperties() {
return userProperties; return userProperties;
} }
public void setUserProperties(String userProperties) { public UserProfileProvider setUserProperties(String userProperties) {
this.userProperties = userProperties; this.userProperties = userProperties;
return this;
} }
public String getUserPropertyMap() { public String getUserPropertyMap() {
return userPropertyMap; return userPropertyMap;
} }
public void setUserPropertyMap(String userPropertyMap) { public UserProfileProvider setUserPropertyMap(String userPropertyMap) {
this.userPropertyMap = userPropertyMap; this.userPropertyMap = userPropertyMap;
return this;
} }
public String getOtherInfo() { public String getOtherInfo() {
return otherInfo; return otherInfo;
} }
public void setOtherInfo(String otherInfo) { public UserProfileProvider setOtherInfo(String otherInfo) {
this.otherInfo = otherInfo; this.otherInfo = otherInfo;
return this;
} }
public String getClientIdentifier() { public String getClientIdentifier() {
return clientIdentifier; return clientIdentifier;
} }
public void setClientIdentifier(String clientIdentifier) { public UserProfileProvider setClientIdentifier(String clientIdentifier) {
this.clientIdentifier = clientIdentifier; this.clientIdentifier = clientIdentifier;
return this;
} }
public String getUserType() { public String getUserType() {
return userType; return userType;
} }
public void setUserType(String userType) { public UserProfileProvider setUserType(String userType) {
this.userType = userType; this.userType = userType;
return this;
} }
private String username = ""; private String username = "";

View File

@@ -24,9 +24,9 @@ import javax.swing.JOptionPane;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.ArrayUtils; import org.jackhuang.hellominecraft.util.ArrayUtils;
import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.GameProfile; import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.GameProfile;
import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.UUIDTypeAdapter;
import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.PropertyMap; import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.PropertyMap;
import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.YggdrasilAuthentication; import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.YggdrasilAuthentication;
import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.UUIDTypeAdapter;
import org.jackhuang.hellominecraft.util.ui.SwingUtils; import org.jackhuang.hellominecraft.util.ui.SwingUtils;
/** /**
@@ -45,10 +45,9 @@ public final class YggdrasilAuthenticator extends IAuthenticator {
@Override @Override
public UserProfileProvider login(LoginInfo info) throws AuthenticationException { public UserProfileProvider login(LoginInfo info) throws AuthenticationException {
UserProfileProvider result = new UserProfileProvider(); UserProfileProvider result = new UserProfileProvider();
result.setUserType("mojang");
if (ua.canPlayOnline()) { if (ua.canPlayOnline()) {
result.setUserName(info.username); result.setUserName(info.username)
result.setUserId(UUIDTypeAdapter.fromUUID(ua.getSelectedProfile().id)); .setUserId(UUIDTypeAdapter.fromUUID(ua.getSelectedProfile().id));
} else { } else {
String usr = info.username; String usr = info.username;
if (info.username == null || !info.username.contains("@")) if (info.username == null || !info.username.contains("@"))
@@ -80,14 +79,15 @@ public final class YggdrasilAuthenticator extends IAuthenticator {
username = selectedProfile.name; username = selectedProfile.name;
if (username == null) if (username == null)
throw new AuthenticationException("No player"); throw new AuthenticationException("No player");
result.setUserName(username); result.setUserName(username)
result.setUserId(selectedProfile == null ? OfflineAuthenticator.getUUIDFromUserName(username) : UUIDTypeAdapter.fromUUID(selectedProfile.id)); .setUserId(selectedProfile == null ? OfflineAuthenticator.getUUIDFromUserName(username) : UUIDTypeAdapter.fromUUID(selectedProfile.id));
} }
result.setUserProperties(new GsonBuilder().registerTypeAdapter(PropertyMap.class, new PropertyMap.LegacySerializer()).create().toJson(ua.getUserProperties())); return result.setUserType("mojang")
result.setUserPropertyMap(new GsonBuilder().registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create().toJson(ua.getUserProperties())); .setUserProperties(new GsonBuilder().registerTypeAdapter(PropertyMap.class, new PropertyMap.LegacySerializer()).create().toJson(ua.getUserProperties()))
result.setAccessToken(ua.getAuthenticatedToken()); .setUserPropertyMap(new GsonBuilder().registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create().toJson(ua.getUserProperties()))
result.setSession(ua.getAuthenticatedToken()); .setAccessToken(ua.getAuthenticatedToken())
return result; .setSession(ua.getAuthenticatedToken())
.setClientIdentifier(clientToken);
} }
@Override @Override

View File

@@ -31,7 +31,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
public class PropertyMap extends HashMap<String, Property> { public class PropertyMap extends HashMap<String, Property> {

View File

@@ -25,11 +25,6 @@ public class User {
public User() { public User() {
} }
public User(String id, PropertyMap properties) {
this.id = id;
this.properties = properties;
}
public String getId() { public String getId() {
return id; return id;
} }

View File

@@ -29,8 +29,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.util.NetUtils; import org.jackhuang.hellominecraft.util.net.NetUtils;
import org.jackhuang.hellominecraft.util.StrUtils; import org.jackhuang.hellominecraft.util.StrUtils;
public class YggdrasilAuthentication { public class YggdrasilAuthentication {
@@ -140,7 +140,7 @@ public class YggdrasilAuthentication {
private void loggedIn(URL url, Object input) throws AuthenticationException { private void loggedIn(URL url, Object input) throws AuthenticationException {
try { try {
String jsonResult = input == null ? NetUtils.get(url) : NetUtils.post(url, GSON.toJson(input), "application/json", proxy); String jsonResult = input == null ? NetUtils.get(url, proxy) : NetUtils.post(url, GSON.toJson(input), "application/json", proxy);
Response response = (Response) GSON.fromJson(jsonResult, Response.class); Response response = (Response) GSON.fromJson(jsonResult, Response.class);
if (response == null) if (response == null)
@@ -188,24 +188,30 @@ public class YggdrasilAuthentication {
public void loadFromStorage(Map<String, Object> credentials) { public void loadFromStorage(Map<String, Object> credentials) {
logOut(); logOut();
setUserName((String) credentials.get(STORAGE_KEY_USER_NAME)); try {
setUserName((String) credentials.get(STORAGE_KEY_USER_NAME));
if (credentials.containsKey(STORAGE_KEY_USER_ID)) if (credentials.containsKey(STORAGE_KEY_USER_ID))
userid = (String) credentials.get(STORAGE_KEY_USER_ID); userid = (String) credentials.get(STORAGE_KEY_USER_ID);
else else
userid = username; userid = username;
if (credentials.containsKey(STORAGE_KEY_USER_PROPERTIES)) if (credentials.containsKey(STORAGE_KEY_USER_PROPERTIES))
userProperties.fromList((List<Map<String, String>>) credentials.get(STORAGE_KEY_USER_PROPERTIES)); userProperties.fromList((List<Map<String, String>>) credentials.get(STORAGE_KEY_USER_PROPERTIES));
if ((credentials.containsKey(STORAGE_KEY_PROFILE_NAME)) && (credentials.containsKey(STORAGE_KEY_PROFILE_ID))) { if ((credentials.containsKey(STORAGE_KEY_PROFILE_NAME)) && (credentials.containsKey(STORAGE_KEY_PROFILE_ID))) {
GameProfile profile = new GameProfile(UUIDTypeAdapter.fromString((String) credentials.get(STORAGE_KEY_PROFILE_ID)), (String) credentials.get(STORAGE_KEY_PROFILE_NAME)); GameProfile profile = new GameProfile(UUIDTypeAdapter.fromString((String) credentials.get(STORAGE_KEY_PROFILE_ID)), (String) credentials.get(STORAGE_KEY_PROFILE_NAME));
if (credentials.containsKey(STORAGE_KEY_PROFILE_PROPERTIES)) if (credentials.containsKey(STORAGE_KEY_PROFILE_PROPERTIES))
profile.properties.fromList((List<Map<String, String>>) credentials.get(STORAGE_KEY_PROFILE_PROPERTIES)); profile.properties.fromList((List<Map<String, String>>) credentials.get(STORAGE_KEY_PROFILE_PROPERTIES));
selectedProfile = profile; selectedProfile = profile;
}
this.accessToken = (String) credentials.get(STORAGE_KEY_ACCESS_TOKEN);
} catch(Exception e) {
HMCLog.err("Failed to load yggdrasil authenticator settings, maybe its format is malformed.", e);
logOut();
} }
this.accessToken = (String) credentials.get(STORAGE_KEY_ACCESS_TOKEN);
} }
public Map<String, Object> saveForStorage() { public Map<String, Object> saveForStorage() {

View File

@@ -18,6 +18,7 @@
package org.jackhuang.hellominecraft.launcher.core.download; package org.jackhuang.hellominecraft.launcher.core.download;
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList; import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
import org.jackhuang.hellominecraft.util.C;
/** /**
* *
@@ -71,7 +72,9 @@ public class BMCLAPIDownloadProvider extends IDownloadProvider {
: str.replace("https://launchermeta.mojang.com", "http://bmclapi2.bangbang93.com") : str.replace("https://launchermeta.mojang.com", "http://bmclapi2.bangbang93.com")
.replace("https://launcher.mojang.com", "http://bmclapi2.bangbang93.com") .replace("https://launcher.mojang.com", "http://bmclapi2.bangbang93.com")
.replace("https://libraries.minecraft.net", "http://bmclapi2.bangbang93.com/libraries") .replace("https://libraries.minecraft.net", "http://bmclapi2.bangbang93.com/libraries")
.replace("http://files.minecraftforge.net/maven", "http://bmclapi2.bangbang93.com/maven"); .replace("http://files.minecraftforge.net/maven", "http://bmclapi2.bangbang93.com/maven")
.replace(C.URL_LITELOADER_LIST, "http://bmclapi2.bangbang93.com/maven/com/mumfrey/liteloader/versions.json")
.replace("http://dl.liteloader.com/versions", "http://bmclapi2.bangbang93.com/maven");
} }
@Override @Override

View File

@@ -19,7 +19,6 @@ package org.jackhuang.hellominecraft.launcher.core.download;
import java.io.File; import java.io.File;
import org.jackhuang.hellominecraft.launcher.core.version.IMinecraftLibrary; import org.jackhuang.hellominecraft.launcher.core.version.IMinecraftLibrary;
import org.jackhuang.hellominecraft.util.system.IOUtils;
/** /**
* *
@@ -34,6 +33,21 @@ public class DownloadLibraryJob {
public DownloadLibraryJob(IMinecraftLibrary n, String u, File p) { public DownloadLibraryJob(IMinecraftLibrary n, String u, File p) {
url = u; url = u;
lib = n; lib = n;
path = IOUtils.tryGetCanonicalFile(p); path = p;
}
public DownloadLibraryJob parse() {
String name = lib.name;
if (name.startsWith("net.minecraftforge:forge:")) {
String[] s = name.split(":");
if (s.length == 3)
url = "http://files.minecraftforge.net/maven/net/minecraftforge/forge/" + s[2] + "/forge-" + s[2] + "-universal.jar";
}
if (name.startsWith("com.mumfrey:liteloader:")) {
String[] s = name.split(":");
if (s.length == 3 && s[2].length() > 3)
url = "http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + s[2].substring(0, s[2].length() - 3) + "/liteloader-" + s[2] + ".jar";
}
return this;
} }
} }

View File

@@ -18,7 +18,7 @@
package org.jackhuang.hellominecraft.launcher.core.download; package org.jackhuang.hellominecraft.launcher.core.download;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.tasks.TaskWindow; import org.jackhuang.hellominecraft.util.task.TaskWindow;
/** /**
* *
@@ -28,7 +28,6 @@ public enum DownloadType {
Mojang("download.mojang", new MojangDownloadProvider()), Mojang("download.mojang", new MojangDownloadProvider()),
BMCL("download.BMCL", new BMCLAPIDownloadProvider()), BMCL("download.BMCL", new BMCLAPIDownloadProvider()),
//RapidData("download.rapid_data", new RapidDataDownloadProvider()),
Curse("Curse CDN", new CurseDownloadProvider()); Curse("Curse CDN", new CurseDownloadProvider());
private final String name; private final String name;

View File

@@ -26,17 +26,17 @@ import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.GameException; import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.version.GameDownloadInfo; import org.jackhuang.hellominecraft.launcher.core.version.GameDownloadInfo;
import org.jackhuang.hellominecraft.launcher.core.version.IMinecraftLibrary; import org.jackhuang.hellominecraft.launcher.core.version.IMinecraftLibrary;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.util.tasks.download.FileDownloadTask; import org.jackhuang.hellominecraft.util.net.FileDownloadTask;
import org.jackhuang.hellominecraft.util.func.Function; import org.jackhuang.hellominecraft.util.func.Function;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.util.tasks.Task; import org.jackhuang.hellominecraft.util.task.Task;
import org.jackhuang.hellominecraft.util.tasks.TaskInfo; import org.jackhuang.hellominecraft.util.task.TaskInfo;
/** /**
* *
@@ -75,7 +75,7 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
} }
@Override @Override
public void executeTask() throws Throwable { public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
File vpath = new File(service.baseDirectory(), "versions/" + id); File vpath = new File(service.baseDirectory(), "versions/" + id);
if (!areDependTasksSucceeded) { if (!areDependTasksSucceeded) {
FileUtils.deleteDirectory(vpath); FileUtils.deleteDirectory(vpath);
@@ -131,7 +131,7 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
public Task downloadMinecraftVersionJson(String id) { public Task downloadMinecraftVersionJson(String id) {
return new TaskInfo("Download Minecraft Json") { return new TaskInfo("Download Minecraft Json") {
@Override @Override
public void executeTask() throws Throwable { public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
List<MinecraftRemoteVersion> versions = MinecraftRemoteVersions.getRemoteVersions(service.getDownloadType()).justDo(); List<MinecraftRemoteVersion> versions = MinecraftRemoteVersions.getRemoteVersions(service.getDownloadType()).justDo();
MinecraftRemoteVersion currentVersion = null; MinecraftRemoteVersion currentVersion = null;
for (MinecraftRemoteVersion v : versions) for (MinecraftRemoteVersion v : versions)
@@ -144,7 +144,7 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
String jsonURL = currentVersion.getUrl(service.getDownloadType()); String jsonURL = currentVersion.getUrl(service.getDownloadType());
File vpath = new File(service.baseDirectory(), "versions/" + id); File vpath = new File(service.baseDirectory(), "versions/" + id);
File mvt = new File(vpath, id + ".json"); File mvt = new File(vpath, id + ".json");
if (!vpath.exists() && !vpath.mkdirs()) if (!FileUtils.makeDirectory(vpath))
HMCLog.warn("Failed to make directories: " + vpath); HMCLog.warn("Failed to make directories: " + vpath);
if (mvt.exists() && !mvt.delete()) if (mvt.exists() && !mvt.delete())
HMCLog.warn("Failed to delete " + mvt); HMCLog.warn("Failed to delete " + mvt);

View File

@@ -17,12 +17,18 @@
*/ */
package org.jackhuang.hellominecraft.launcher.core.download; package org.jackhuang.hellominecraft.launcher.core.download;
import com.google.gson.annotations.SerializedName;
/** /**
* *
* @author huangyuhui * @author huangyuhui
*/ */
public class MinecraftRemoteLatestVersion { public class MinecraftRemoteLatestVersion {
public String snapshot, release; @SerializedName("snapshot")
public String snapshot;
@SerializedName("release")
public String release;
} }

View File

@@ -17,13 +17,23 @@
*/ */
package org.jackhuang.hellominecraft.launcher.core.download; package org.jackhuang.hellominecraft.launcher.core.download;
import com.google.gson.annotations.SerializedName;
/** /**
* *
* @author huangyuhui * @author huangyuhui
*/ */
public class MinecraftRemoteVersion { public class MinecraftRemoteVersion {
public String id, time, releaseTime, type; @SerializedName("id")
public String id;
@SerializedName("time")
public String time;
@SerializedName("releaseTime")
public String releaseTime;
@SerializedName("type")
public String type;
@SerializedName("url")
private String url; private String url;
public String getUrl(DownloadType type) { public String getUrl(DownloadType type) {

View File

@@ -20,8 +20,8 @@ package org.jackhuang.hellominecraft.launcher.core.download;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import java.util.ArrayList; import java.util.ArrayList;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.NetUtils; import org.jackhuang.hellominecraft.util.net.NetUtils;
import org.jackhuang.hellominecraft.util.OverridableSwingWorker; import org.jackhuang.hellominecraft.util.AbstractSwingWorker;
/** /**
* *
@@ -55,7 +55,7 @@ public class MinecraftRemoteVersions {
return new RemoteVersionsTask(type); return new RemoteVersionsTask(type);
} }
public static class RemoteVersionsTask extends OverridableSwingWorker<MinecraftRemoteVersion> { public static class RemoteVersionsTask extends AbstractSwingWorker<MinecraftRemoteVersion> {
DownloadType type; DownloadType type;

View File

@@ -64,7 +64,7 @@ public class MojangDownloadProvider extends IDownloadProvider {
@Override @Override
public String getAssetsDownloadURL() { public String getAssetsDownloadURL() {
return "https://resources.download.minecraft.net/"; return "http://resources.download.minecraft.net/";
} }
@Override @Override

View File

@@ -1,56 +0,0 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.core.download;
/**
*
* @author huangyuhui
*/
public class RapidDataDownloadProvider extends MojangDownloadProvider {
@Override
public String getAssetsDownloadURL() {
return "http://mirrors.rapiddata.org/resources.download.minecraft.net/";
}
@Override
public String getLibraryDownloadURL() {
return "http://mirrors.rapiddata.org/libraries.minecraft.net";
}
@Override
public String getIndexesDownloadURL() {
return "http://mirrors.rapiddata.org/Minecraft.Download/indexes/";
}
@Override
public String getVersionsDownloadURL() {
return "http://mirrors.rapiddata.org/Minecraft.Download/versions/";
}
@Override
public String getVersionsListDownloadURL() {
return "http://mirrors.rapiddata.org/Minecraft.Download/versions/versions.json";
}
@Override
public String getParsedDownloadURL(String str) {
return str == null ? null : str.replace("http://files.minecraftforge.net/maven", "http://mirrors.rapiddata.org/forge/maven");
}
}

View File

@@ -19,16 +19,22 @@ package org.jackhuang.hellominecraft.launcher.core.install;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import org.jackhuang.hellominecraft.util.tasks.Task; import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.util.task.Task;
/** /**
* *
* @author huangyuhui * @author huangyuhui
*/ */
public abstract class InstallerVersionList { public abstract class InstallerVersionList {
public Map<String, List<InstallerVersion>> versionMap;
public List<InstallerVersion> versions;
/** /**
* Refresh installer versions list from the downloaded content. * Refresh installer versions list from the downloaded content.
@@ -53,7 +59,17 @@ public abstract class InstallerVersionList {
* *
* @return cached result. * @return cached result.
*/ */
protected abstract List<InstallerVersion> getVersionsImpl(String mcVersion); public List<InstallerVersion> getVersionsImpl(String mcVersion) {
if (versions == null || versionMap == null)
return null;
if (StrUtils.isBlank(mcVersion))
return versions;
List<InstallerVersion> c = versionMap.get(mcVersion);
if (c == null)
return versions;
Collections.sort(c, InstallerVersionComparator.INSTANCE);
return c;
}
/** /**
* Get installers you want, please cache this method's result to save time. * Get installers you want, please cache this method's result to save time.

View File

@@ -23,13 +23,13 @@ import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
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.forge.ForgeInstaller; import org.jackhuang.hellominecraft.launcher.core.install.forge.ForgeInstaller;
import org.jackhuang.hellominecraft.launcher.core.install.liteloader.LiteLoaderInstaller; import org.jackhuang.hellominecraft.launcher.core.install.liteloader.LiteLoaderInstaller;
import org.jackhuang.hellominecraft.launcher.core.install.liteloader.LiteLoaderVersionList; import org.jackhuang.hellominecraft.launcher.core.install.liteloader.LiteLoaderInstallerVersion;
import org.jackhuang.hellominecraft.launcher.core.install.optifine.OptiFineInstaller; import org.jackhuang.hellominecraft.launcher.core.install.optifine.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.task.Task;
import org.jackhuang.hellominecraft.util.tasks.download.FileDownloadTask; import org.jackhuang.hellominecraft.util.net.FileDownloadTask;
import org.jackhuang.hellominecraft.util.system.IOUtils; import org.jackhuang.hellominecraft.util.sys.IOUtils;
import org.jackhuang.hellominecraft.util.tasks.DeleteFileTask; import org.jackhuang.hellominecraft.util.task.DeleteFileTask;
/** /**
* *
@@ -62,8 +62,8 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
return null; return null;
else else
return new FileDownloadTask(service.getDownloadType().getProvider().getParsedDownloadURL(v.installer), filepath).setTag("forge") return new FileDownloadTask(service.getDownloadType().getProvider().getParsedDownloadURL(v.installer), filepath).setTag("forge")
.after(new ForgeInstaller(service, filepath)) .with(new ForgeInstaller(service, filepath))
.after(new DeleteFileTask(filepath)); .with(new DeleteFileTask(filepath));
} }
@Override @Override
@@ -72,16 +72,18 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
if (v.installer == null) if (v.installer == null)
return null; return null;
OptiFineDownloadFormatter task = new OptiFineDownloadFormatter(v.installer); OptiFineDownloadFormatter task = new OptiFineDownloadFormatter(v.installer);
return task.after(new FileDownloadTask(filepath).registerPreviousResult(task).setTag("optifine")) return task.with(new FileDownloadTask(filepath).registerPreviousResult(task).setTag("optifine"))
.after(new OptiFineInstaller(service, installId, v, filepath)) .with(new OptiFineInstaller(service, installId, v, filepath))
.after(new DeleteFileTask(filepath)); .with(new DeleteFileTask(filepath));
} }
@Override @Override
public Task downloadLiteLoader(String installId, InstallerVersion v) { public Task downloadLiteLoader(String installId, InstallerVersion v) {
if (!(v instanceof LiteLoaderInstallerVersion))
throw new Error("Download lite loader but the version is not ll's.");
File filepath = IOUtils.tryGetCanonicalFile("liteloader-universal.jar"); File filepath = IOUtils.tryGetCanonicalFile("liteloader-universal.jar");
FileDownloadTask task = (FileDownloadTask) new FileDownloadTask(v.universal, filepath).setTag("LiteLoader"); FileDownloadTask task = (FileDownloadTask) new FileDownloadTask(v.universal, filepath).setTag("LiteLoader");
return task.after(new LiteLoaderInstaller(service, installId, (LiteLoaderVersionList.LiteLoaderInstallerVersion) v).registerPreviousResult(task)) return task.with(new LiteLoaderInstaller(service, installId, (LiteLoaderInstallerVersion) v).registerPreviousResult(task))
.after(new DeleteFileTask(filepath)); .with(new DeleteFileTask(filepath));
} }
} }

View File

@@ -1,50 +0,0 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.core.install;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.jackhuang.hellominecraft.util.logging.HMCLog;
import org.jackhuang.hellominecraft.util.system.Compressor;
import org.jackhuang.hellominecraft.util.system.FileUtils;
/**
*
* @author huangyuhui
*/
public class PackMinecraftInstaller {
File dest;
ArrayList<String> src;
public PackMinecraftInstaller(ArrayList<String> src, File dest) {
this.dest = dest;
this.src = src;
}
public void install() throws IOException {
File file = new File("HMCL-MERGE-TEMP");
if (!file.exists() && !file.mkdirs())
HMCLog.warn("Failed to make directories: " + file);
for (String src1 : src)
Compressor.unzip(new File(src1), file);
Compressor.zip(file.getAbsolutePath(), dest.getAbsolutePath());
FileUtils.deleteDirectory(file);
}
}

View File

@@ -24,14 +24,13 @@ import java.io.InputStream;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.util.tasks.Task; import org.jackhuang.hellominecraft.util.task.Task;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.util.NetUtils;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
import org.jackhuang.hellominecraft.util.MessageBox; import org.jackhuang.hellominecraft.util.MessageBox;
import org.jackhuang.hellominecraft.util.system.IOUtils; import org.jackhuang.hellominecraft.util.sys.IOUtils;
/** /**
* *
@@ -50,36 +49,39 @@ public class ForgeInstaller extends Task {
} }
@Override @Override
public void executeTask() throws Exception { public void executeTask(boolean areDependTasksSucceeded) throws Exception {
HMCLog.log("Extracting install profiles..."); HMCLog.log("Extracting install profiles...");
try (ZipFile zipFile = new ZipFile(forgeInstaller)) { try (ZipFile zipFile = new ZipFile(forgeInstaller)) {
ZipEntry entry = zipFile.getEntry("install_profile.json"); ZipEntry entry = zipFile.getEntry("install_profile.json");
String content = NetUtils.getStreamContent(zipFile.getInputStream(entry)); String content = IOUtils.toString(zipFile.getInputStream(entry));
InstallProfile profile = C.GSON.fromJson(content, InstallProfile.class); InstallProfile profile = C.GSON.fromJson(content, InstallProfile.class);
File from = new File(gameDir, "versions" + File.separator + profile.install.getMinecraft()); File from = new File(gameDir, "versions" + File.separator + profile.install.getMinecraft());
if (!from.exists()) if (!from.exists())
if (MessageBox.Show(C.i18n("install.no_version_if_intall")) == MessageBox.YES_OPTION) { if (MessageBox.show(C.i18n("install.no_version_if_intall")) == MessageBox.YES_OPTION) {
if (!mp.version().install(profile.install.getMinecraft(), null)) if (!mp.version().install(profile.install.getMinecraft(), null))
throw new IllegalStateException(C.i18n("install.no_version")); throw new IllegalStateException(C.i18n("install.no_version"));
} else } else
throw new IllegalStateException(C.i18n("install.no_version")); throw new IllegalStateException(C.i18n("install.no_version"));
File to = new File(gameDir, "versions" + File.separator + profile.install.getTarget()); File to = new File(gameDir, "versions" + File.separator + profile.install.getTarget());
if (!to.exists() && !to.mkdirs()) if (!FileUtils.makeDirectory(to))
HMCLog.warn("Failed to make new version folder " + to); HMCLog.warn("Failed to make new version folder " + to);
HMCLog.log("Copying jar..." + profile.install.getMinecraft() + ".jar to " + profile.install.getTarget() + ".jar"); HMCLog.log("Copying jar..." + profile.install.getMinecraft() + ".jar to " + profile.install.getTarget() + ".jar");
FileUtils.copyFile(new File(from, profile.install.getMinecraft() + ".jar"), FileUtils.copyFile(new File(from, profile.install.getMinecraft() + ".jar"),
new File(to, profile.install.getTarget() + ".jar")); new File(to, profile.install.getTarget() + ".jar"));
HMCLog.log("Creating new version profile..." + profile.install.getTarget() + ".json"); HMCLog.log("Creating new version profile..." + profile.install.getTarget() + ".json");
FileUtils.write(new File(to, profile.install.getTarget() + ".json"), C.GSON.toJson(profile.versionInfo)); FileUtils.write(new File(to, profile.install.getTarget() + ".json"), C.GSON.toJson(profile.versionInfo));
HMCLog.log("Extracting universal forge pack..." + profile.install.getFilePath()); HMCLog.log("Extracting universal forge pack..." + profile.install.getFilePath());
entry = zipFile.getEntry(profile.install.getFilePath()); entry = zipFile.getEntry(profile.install.getFilePath());
InputStream is = zipFile.getInputStream(entry); InputStream is = zipFile.getInputStream(entry);
MinecraftLibrary forge = new MinecraftLibrary(profile.install.getPath()); MinecraftLibrary forge = new MinecraftLibrary(profile.install.getPath());
File file = new File(gameDir, "libraries/" + forge.getDownloadInfo().path); File file = new File(gameDir, "libraries/" + forge.getDownloadInfo().path);
if (file.getParentFile().mkdirs()) if (!FileUtils.makeDirectory(file))
HMCLog.warn("Failed to make library directory " + file.getParent()); HMCLog.warn("Failed to make library directory " + file.getParent());
try (FileOutputStream fos = new FileOutputStream(file)) { try (FileOutputStream fos = FileUtils.openOutputStream(file)) {
IOUtils.copyStream(is, fos); IOUtils.copyStream(is, fos);
} }
mp.version().refreshVersions(); mp.version().refreshVersions();

View File

@@ -47,19 +47,6 @@ public class Install {
public Install() { public Install() {
} }
public Install(String profileName, String target, String path, String version, String filePath, String welcome, String minecraft, String mirrorList, String logo) {
this();
this.profileName = profileName;
this.target = target;
this.path = path;
this.version = version;
this.filePath = filePath;
this.welcome = welcome;
this.minecraft = minecraft;
this.mirrorList = mirrorList;
this.logo = logo;
}
public String getProfileName() { public String getProfileName() {
return profileName; return profileName;
} }

View File

@@ -76,16 +76,4 @@ public class MinecraftForgeVersion {
this.modified = modified; this.modified = modified;
} }
public MinecraftForgeVersion() {
}
public MinecraftForgeVersion(String branch, String mcversion, String jobver, String version, int build, double modified) {
this.branch = branch;
this.mcversion = mcversion;
this.jobver = jobver;
this.version = version;
this.build = build;
this.modified = modified;
}
} }

View File

@@ -22,16 +22,15 @@ import java.util.Arrays;
import java.util.Collection; 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.Map; import java.util.Map;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
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.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.tasks.Task; import org.jackhuang.hellominecraft.util.task.Task;
import org.jackhuang.hellominecraft.util.tasks.TaskInfo; import org.jackhuang.hellominecraft.util.task.TaskInfo;
import org.jackhuang.hellominecraft.util.tasks.download.HTTPGetTask; import org.jackhuang.hellominecraft.util.net.HTTPGetTask;
/** /**
* *
@@ -48,8 +47,6 @@ public class MinecraftForgeVersionList extends InstallerVersionList {
} }
public MinecraftForgeVersionRoot root; public MinecraftForgeVersionRoot root;
public Map<String, List<InstallerVersion>> versionMap;
public List<InstallerVersion> versions;
@Override @Override
public Task refresh(String[] needed) { public Task refresh(String[] needed) {
@@ -60,11 +57,11 @@ public class MinecraftForgeVersionList extends InstallerVersionList {
@Override @Override
public Collection<Task> getDependTasks() { public Collection<Task> getDependTasks() {
return Arrays.asList(task); return Arrays.asList(task.setTag("Official Forge Download Site"));
} }
@Override @Override
public void executeTask() throws Throwable { public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
if (!areDependTasksSucceeded) if (!areDependTasksSucceeded)
return; return;
String s = task.getResult(); String s = task.getResult();
@@ -116,19 +113,6 @@ public class MinecraftForgeVersionList extends InstallerVersionList {
}; };
} }
@Override
public List<InstallerVersion> getVersionsImpl(String mcVersion) {
if (versions == null || versionMap == null)
return null;
if (StrUtils.isBlank(mcVersion))
return versions;
List c = versionMap.get(mcVersion);
if (c == null)
return versions;
Collections.sort(c, InstallerVersionComparator.INSTANCE);
return c;
}
@Override @Override
public String getName() { public String getName() {
return "Forge - MinecraftForge Offical Site"; return "Forge - MinecraftForge Offical Site";

View File

@@ -21,12 +21,12 @@ import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.util.tasks.Task; import org.jackhuang.hellominecraft.util.task.Task;
import org.jackhuang.hellominecraft.util.tasks.communication.PreviousResult; import org.jackhuang.hellominecraft.util.task.comm.PreviousResult;
import org.jackhuang.hellominecraft.util.tasks.communication.PreviousResultRegistrar; import org.jackhuang.hellominecraft.util.task.comm.PreviousResultRegistrar;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
@@ -36,16 +36,16 @@ import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
*/ */
public class LiteLoaderInstaller extends Task implements PreviousResultRegistrar<File> { public class LiteLoaderInstaller extends Task implements PreviousResultRegistrar<File> {
public LiteLoaderVersionList.LiteLoaderInstallerVersion version; public LiteLoaderInstallerVersion version;
public File installer; public File installer;
public String installId; public String installId;
public IMinecraftService service; public IMinecraftService service;
public LiteLoaderInstaller(IMinecraftService service, String installId, LiteLoaderVersionList.LiteLoaderInstallerVersion v) { public LiteLoaderInstaller(IMinecraftService service, String installId, LiteLoaderInstallerVersion v) {
this(service, installId, v, null); this(service, installId, v, null);
} }
public LiteLoaderInstaller(IMinecraftService service, String installId, LiteLoaderVersionList.LiteLoaderInstallerVersion v, File installer) { public LiteLoaderInstaller(IMinecraftService service, String installId, LiteLoaderInstallerVersion v, File installer) {
this.service = service; this.service = service;
this.installId = installId; this.installId = installId;
this.version = v; this.version = v;
@@ -53,7 +53,7 @@ public class LiteLoaderInstaller extends Task implements PreviousResultRegistrar
} }
@Override @Override
public void executeTask() throws Exception { public void executeTask(boolean areDependTasksSucceeded) throws Exception {
if (installId == null) if (installId == null)
throw new IllegalStateException(C.i18n("install.no_version")); throw new IllegalStateException(C.i18n("install.no_version"));
if (pre.size() != 1 && installer == null) if (pre.size() != 1 && installer == null)
@@ -63,7 +63,7 @@ public class LiteLoaderInstaller extends Task implements PreviousResultRegistrar
MinecraftVersion mv = (MinecraftVersion) service.version().getVersionById(installId).clone(); MinecraftVersion mv = (MinecraftVersion) service.version().getVersionById(installId).clone();
mv.inheritsFrom = mv.id; mv.inheritsFrom = mv.id;
mv.jar = mv.jar == null ? mv.id : mv.jar; mv.jar = mv.jar == null ? mv.id : mv.jar;
mv.libraries = new ArrayList(Arrays.asList(version.libraries)); mv.libraries = new ArrayList<>(Arrays.asList(version.libraries));
MinecraftLibrary ml = new MinecraftLibrary("com.mumfrey:liteloader:" + version.selfVersion); MinecraftLibrary ml = new MinecraftLibrary("com.mumfrey:liteloader:" + version.selfVersion);
//ml.url = "http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + version.mcVersion + "/liteloader-" + version.selfVersion + ".jar"; //ml.url = "http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + version.mcVersion + "/liteloader-" + version.selfVersion + ".jar";
@@ -75,7 +75,7 @@ public class LiteLoaderInstaller extends Task implements PreviousResultRegistrar
mv.mainClass = "net.minecraft.launchwrapper.Launch"; mv.mainClass = "net.minecraft.launchwrapper.Launch";
mv.minecraftArguments += " --tweakClass " + version.tweakClass; mv.minecraftArguments += " --tweakClass " + version.tweakClass;
File folder = new File(service.baseDirectory(), "versions/" + mv.id); File folder = new File(service.baseDirectory(), "versions/" + mv.id);
if (!folder.exists() && folder.mkdirs()) if (!FileUtils.makeDirectory(folder))
HMCLog.warn("Failed to create new liteloader version " + folder); HMCLog.warn("Failed to create new liteloader version " + folder);
File json = new File(folder, mv.id + ".json"); File json = new File(folder, mv.id + ".json");
HMCLog.log("Creating new version profile..." + mv.id + ".json"); HMCLog.log("Creating new version profile..." + mv.id + ".json");
@@ -92,7 +92,7 @@ public class LiteLoaderInstaller extends Task implements PreviousResultRegistrar
ArrayList<PreviousResult<File>> pre = new ArrayList<>(); ArrayList<PreviousResult<File>> pre = new ArrayList<>();
@Override @Override
public Task registerPreviousResult(PreviousResult pr) { public Task registerPreviousResult(PreviousResult<File> pr) {
pre.add(pr); pre.add(pr);
return this; return this;
} }

View File

@@ -0,0 +1,58 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.core.install.liteloader;
import java.util.Arrays;
import java.util.Objects;
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
/**
*
* @author huang
*/
public class LiteLoaderInstallerVersion extends InstallerVersionList.InstallerVersion {
public MinecraftLibrary[] libraries;
public String tweakClass;
public LiteLoaderInstallerVersion(String selfVersion, String mcVersion) {
super(selfVersion, mcVersion);
}
@Override
public int hashCode() {
int hash = 7;
hash = 13 * hash + Arrays.deepHashCode(this.libraries);
hash = 13 * hash + Objects.hashCode(this.tweakClass);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof LiteLoaderVersionList))
return false;
if (this == obj)
return true;
final LiteLoaderInstallerVersion other = (LiteLoaderInstallerVersion) obj;
if (!Objects.equals(this.tweakClass, other.tweakClass))
return false;
return Arrays.deepEquals(this.libraries, other.libraries);
}
}

View File

@@ -22,17 +22,15 @@ import java.util.Arrays;
import java.util.Collection; 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.Map; import java.util.Map;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
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.InstallerVersionNewerComparator; import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionNewerComparator;
import org.jackhuang.hellominecraft.util.StrUtils; import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.util.tasks.Task; import org.jackhuang.hellominecraft.util.task.Task;
import org.jackhuang.hellominecraft.util.tasks.TaskInfo; import org.jackhuang.hellominecraft.util.task.TaskInfo;
import org.jackhuang.hellominecraft.util.tasks.download.HTTPGetTask; import org.jackhuang.hellominecraft.util.net.HTTPGetTask;
/** /**
* *
@@ -49,23 +47,21 @@ public class LiteLoaderVersionList extends InstallerVersionList {
} }
public LiteLoaderVersionsRoot root; public LiteLoaderVersionsRoot root;
public Map<String, List<InstallerVersion>> versionMap;
public List<InstallerVersion> versions;
@Override @Override
public Task refresh(String[] needed) { public Task refresh(String[] needed) {
if (root != null) if (root != null)
return null; return null;
return new TaskInfo(C.i18n("install.liteloader.get_list")) { return new TaskInfo(C.i18n("install.liteloader.get_list")) {
HTTPGetTask task = new HTTPGetTask(C.URL_LITELOADER_LIST); HTTPGetTask task = new HTTPGetTask(DownloadType.getSuggestedDownloadType().getProvider().getParsedDownloadURL(C.URL_LITELOADER_LIST));
@Override @Override
public Collection<Task> getDependTasks() { public Collection<Task> getDependTasks() {
return Arrays.asList(task); return Arrays.asList(task.setTag("Official Liteloader Download Site"));
} }
@Override @Override
public void executeTask() throws Throwable { public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
if (!areDependTasksSucceeded) if (!areDependTasksSucceeded)
return; return;
String s = task.getResult(); String s = task.getResult();
@@ -85,7 +81,7 @@ public class LiteLoaderVersionList extends InstallerVersionList {
continue; continue;
LiteLoaderVersion v = entry.getValue(); LiteLoaderVersion v = entry.getValue();
LiteLoaderInstallerVersion iv = new LiteLoaderInstallerVersion(v.version, StrUtils.formatVersion(arr.getKey())); 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.universal = DownloadType.getSuggestedDownloadType().getProvider().getParsedDownloadURL("http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + arr.getKey() + "/" + v.file);
iv.tweakClass = v.tweakClass; iv.tweakClass = v.tweakClass;
iv.libraries = Arrays.copyOf(v.libraries, v.libraries.length); iv.libraries = Arrays.copyOf(v.libraries, v.libraries.length);
iv.installer = "http://dl.liteloader.com/redist/" + iv.mcVersion + "/liteloader-installer-" + iv.selfVersion.replace("_", "-") + ".jar"; iv.installer = "http://dl.liteloader.com/redist/" + iv.mcVersion + "/liteloader-installer-" + iv.selfVersion.replace("_", "-") + ".jar";
@@ -101,33 +97,9 @@ public class LiteLoaderVersionList extends InstallerVersionList {
}; };
} }
@Override
public List<InstallerVersion> getVersionsImpl(String mcVersion) {
if (versions == null || versionMap == null)
return null;
if (StrUtils.isBlank(mcVersion))
return versions;
List c = versionMap.get(mcVersion);
if (c == null)
return versions;
Collections.sort(c, InstallerVersionComparator.INSTANCE);
return c;
}
@Override @Override
public String getName() { public String getName() {
return "LiteLoader - LiteLoader Official Site(By: Mumfrey)"; return "LiteLoader - LiteLoader Official Site(By: Mumfrey)";
} }
public static class LiteLoaderInstallerVersion extends InstallerVersion {
public MinecraftLibrary[] libraries;
public String tweakClass;
public LiteLoaderInstallerVersion(String selfVersion, String mcVersion) {
super(selfVersion, mcVersion);
}
}
} }

View File

@@ -35,13 +35,6 @@ public class LiteLoaderVersionsMeta {
public LiteLoaderVersionsMeta() { public LiteLoaderVersionsMeta() {
} }
public LiteLoaderVersionsMeta(String description, String authors, String url) {
this();
this.description = description;
this.authors = authors;
this.url = url;
}
public String getDescription() { public String getDescription() {
return description; return description;
} }

View File

@@ -23,13 +23,13 @@ import java.util.zip.ZipFile;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList; import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionList;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.util.tasks.Task; import org.jackhuang.hellominecraft.util.task.Task;
import org.jackhuang.hellominecraft.util.tasks.communication.PreviousResult; import org.jackhuang.hellominecraft.util.task.comm.PreviousResult;
import org.jackhuang.hellominecraft.util.tasks.communication.PreviousResultRegistrar; import org.jackhuang.hellominecraft.util.task.comm.PreviousResultRegistrar;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
/** /**
* *
@@ -42,10 +42,6 @@ public class OptiFineInstaller extends Task implements PreviousResultRegistrar<F
public InstallerVersionList.InstallerVersion version; public InstallerVersionList.InstallerVersion version;
public String installId; public String installId;
public OptiFineInstaller(IMinecraftService service, String installId, InstallerVersionList.InstallerVersion version) {
this(service, installId, version, null);
}
public OptiFineInstaller(IMinecraftService service, String installId, InstallerVersionList.InstallerVersion version, File installer) { public OptiFineInstaller(IMinecraftService service, String installId, InstallerVersionList.InstallerVersion version, File installer) {
this.service = service; this.service = service;
this.installId = installId; this.installId = installId;
@@ -54,7 +50,7 @@ public class OptiFineInstaller extends Task implements PreviousResultRegistrar<F
} }
@Override @Override
public void executeTask() throws Exception { public void executeTask(boolean areDependTasksSucceeded) throws Exception {
if (installId == null) if (installId == null)
throw new Exception(C.i18n("install.no_version")); throw new Exception(C.i18n("install.no_version"));
String selfId = version.selfVersion; String selfId = version.selfVersion;
@@ -77,7 +73,7 @@ public class OptiFineInstaller extends Task implements PreviousResultRegistrar<F
} }
} }
File loc = new File(service.baseDirectory(), "versions/" + mv.id); File loc = new File(service.baseDirectory(), "versions/" + mv.id);
if (!loc.exists() && loc.mkdirs()) if (!FileUtils.makeDirectory(loc))
HMCLog.warn("Failed to make directories: " + loc); HMCLog.warn("Failed to make directories: " + loc);
File json = new File(loc, mv.id + ".json"); File json = new File(loc, mv.id + ".json");
FileUtils.write(json, C.GSON.toJson(mv, MinecraftVersion.class)); FileUtils.write(json, C.GSON.toJson(mv, MinecraftVersion.class));
@@ -90,10 +86,10 @@ public class OptiFineInstaller extends Task implements PreviousResultRegistrar<F
return "OptiFine Installer"; return "OptiFine Installer";
} }
ArrayList<PreviousResult<File>> pre = new ArrayList(); ArrayList<PreviousResult<File>> pre = new ArrayList<>();
@Override @Override
public Task registerPreviousResult(PreviousResult pr) { public Task registerPreviousResult(PreviousResult<File> pr) {
pre.add(pr); pre.add(pr);
return this; return this;
} }

View File

@@ -23,7 +23,8 @@ package org.jackhuang.hellominecraft.launcher.core.install.optifine;
*/ */
public class OptiFineVersion { public class OptiFineVersion {
private String dl, ver, date, mirror, mcver; private String dl, ver, date, mirror, mcversion;
public String patch, type; // For BMCLAPI2.
public String getDownloadLink() { public String getDownloadLink() {
return dl; return dl;
@@ -58,10 +59,10 @@ public class OptiFineVersion {
} }
public String getMCVersion() { public String getMCVersion() {
return mcver; return mcversion;
} }
public void setMCVersion(String mcver) { public void setMCVersion(String mcver) {
this.mcver = mcver; this.mcversion = mcver;
} }
} }

View File

@@ -24,18 +24,16 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jackhuang.hellominecraft.util.C; 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.StrUtils; import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.util.tasks.Task; import org.jackhuang.hellominecraft.util.task.Task;
import org.jackhuang.hellominecraft.util.tasks.TaskInfo; import org.jackhuang.hellominecraft.util.task.TaskInfo;
import org.jackhuang.hellominecraft.util.tasks.download.HTTPGetTask; import org.jackhuang.hellominecraft.util.net.HTTPGetTask;
/** /**
* *
@@ -52,8 +50,6 @@ public class OptiFineBMCLVersionList extends InstallerVersionList {
} }
public ArrayList<OptiFineVersion> root; public ArrayList<OptiFineVersion> root;
public Map<String, List<InstallerVersion>> versionMap;
public List<InstallerVersion> versions;
private static final Type TYPE = new TypeToken<ArrayList<OptiFineVersion>>() { private static final Type TYPE = new TypeToken<ArrayList<OptiFineVersion>>() {
}.getType(); }.getType();
@@ -65,32 +61,31 @@ public class OptiFineBMCLVersionList extends InstallerVersionList {
@Override @Override
public Collection<Task> getDependTasks() { public Collection<Task> getDependTasks() {
return Arrays.asList(task); return Arrays.asList(task.setTag("BMCL Optifine Download Site"));
} }
@Override @Override
public void executeTask() throws Throwable { public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
String s = task.getResult(); String s = task.getResult();
versionMap = new HashMap<>(); versionMap = new HashMap<>();
versions = new ArrayList<>(); versions = new ArrayList<>();
HashSet<String> duplicates = new HashSet<>();
if (s == null) if (s == null)
return; return;
root = C.GSON.fromJson(s, TYPE); root = C.GSON.fromJson(s, TYPE);
for (OptiFineVersion v : root) { for (OptiFineVersion v : root) {
v.setMirror(v.getMirror().replace("http://optifine.net/http://optifine.net/", "http://optifine.net/")); v.setVersion(v.type + '_' + v.patch);
v.setMirror(String.format("http://bmclapi2.bangbang93.com/optifine/%s/%s/%s", v.getMCVersion(), v.type, v.patch));
if (StrUtils.isBlank(v.getMCVersion())) { if (duplicates.contains(v.getMirror()))
Pattern p = Pattern.compile("OptiFine (.*) HD"); continue;
Matcher m = p.matcher(v.getVersion()); else
while (m.find()) duplicates.add(v.getMirror());
v.setMCVersion(m.group(1));
}
InstallerVersion iv = new InstallerVersion(v.getVersion(), StrUtils.formatVersion(v.getMCVersion())); InstallerVersion iv = new InstallerVersion(v.getVersion(), StrUtils.formatVersion(v.getMCVersion()));
List<InstallerVersion> al = ArrayUtils.tryGetMapWithList(versionMap, 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(); iv.installer = iv.universal = v.getMirror();
al.add(iv); al.add(iv);
versions.add(iv); versions.add(iv);
@@ -101,19 +96,6 @@ public class OptiFineBMCLVersionList extends InstallerVersionList {
}; };
} }
@Override
public List<InstallerVersion> getVersionsImpl(String mcVersion) {
if (versions == null || versionMap == null)
return null;
if (StrUtils.isBlank(mcVersion))
return versions;
List c = versionMap.get(mcVersion);
if (c == null)
return versions;
Collections.sort(c, InstallerVersionComparator.INSTANCE);
return c;
}
@Override @Override
public String getName() { public String getName() {
return "OptiFine - BMCLAPI(By: bangbang93)"; return "OptiFine - BMCLAPI(By: bangbang93)";

View File

@@ -20,9 +20,9 @@ package org.jackhuang.hellominecraft.launcher.core.install.optifine.vanilla;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.tasks.Task; import org.jackhuang.hellominecraft.util.task.Task;
import org.jackhuang.hellominecraft.util.tasks.communication.PreviousResult; import org.jackhuang.hellominecraft.util.task.comm.PreviousResult;
import org.jackhuang.hellominecraft.util.NetUtils; import org.jackhuang.hellominecraft.util.net.NetUtils;
/** /**
* *
@@ -37,7 +37,7 @@ public class OptiFineDownloadFormatter extends Task implements PreviousResult<St
} }
@Override @Override
public void executeTask() throws Exception { public void executeTask(boolean areDependTasksSucceeded) throws Exception {
String content = NetUtils.get(url); String content = NetUtils.get(url);
Pattern p = Pattern.compile("\"downloadx\\?f=OptiFine(.*)\""); Pattern p = Pattern.compile("\"downloadx\\?f=OptiFine(.*)\"");
Matcher m = p.matcher(content); Matcher m = p.matcher(content);

View File

@@ -25,7 +25,6 @@ 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;
import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
@@ -36,9 +35,9 @@ import org.jackhuang.hellominecraft.launcher.core.install.optifine.OptiFineVersi
import org.jackhuang.hellominecraft.util.ArrayUtils; import org.jackhuang.hellominecraft.util.ArrayUtils;
import org.jackhuang.hellominecraft.util.C; 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.task.Task;
import org.jackhuang.hellominecraft.util.tasks.TaskInfo; import org.jackhuang.hellominecraft.util.task.TaskInfo;
import org.jackhuang.hellominecraft.util.tasks.download.HTTPGetTask; import org.jackhuang.hellominecraft.util.net.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,9 +58,7 @@ public class OptiFineVersionList extends InstallerVersionList {
return instance; return instance;
} }
public ArrayList<OptiFineVersion> root = new ArrayList(); public ArrayList<OptiFineVersion> root = new ArrayList<>();
public Map<String, List<InstallerVersion>> versionMap;
public List<InstallerVersion> versions;
@Override @Override
public Task refresh(String[] sss) { public Task refresh(String[] sss) {
@@ -72,11 +69,11 @@ public class OptiFineVersionList extends InstallerVersionList {
@Override @Override
public Collection<Task> getDependTasks() { public Collection<Task> getDependTasks() {
return Arrays.asList(task); return Arrays.asList(task.setTag("Optifine Download Site"));
} }
@Override @Override
public void executeTask() throws Throwable { public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
if (!areDependTasksSucceeded) if (!areDependTasksSucceeded)
return; return;
String content = task.getResult(); String content = task.getResult();
@@ -138,18 +135,4 @@ public class OptiFineVersionList extends InstallerVersionList {
public String getName() { public String getName() {
return "OptiFine - OptiFine Official Site"; return "OptiFine - OptiFine Official Site";
} }
@Override
public List<InstallerVersion> getVersionsImpl(String mcVersion) {
if (versions == null || versionMap == null)
return null;
if (StrUtils.isBlank(mcVersion))
return versions;
List c = versionMap.get(mcVersion);
if (c == null)
return versions;
Collections.sort(c, InstallerVersionComparator.INSTANCE);
return c;
}
} }

View File

@@ -22,12 +22,12 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.util.system.JdkVersion; import org.jackhuang.hellominecraft.util.sys.JdkVersion;
import org.jackhuang.hellominecraft.util.MathUtils; import org.jackhuang.hellominecraft.util.MathUtils;
import org.jackhuang.hellominecraft.util.MessageBox; import org.jackhuang.hellominecraft.util.MessageBox;
import org.jackhuang.hellominecraft.util.system.OS; import org.jackhuang.hellominecraft.util.sys.OS;
import org.jackhuang.hellominecraft.util.system.Platform; import org.jackhuang.hellominecraft.util.sys.Platform;
import org.jackhuang.hellominecraft.util.StrUtils; import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.launcher.core.GameException; import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider; import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
@@ -104,17 +104,17 @@ public abstract class AbstractMinecraftLoader implements IMinecraftLoader {
HMCLog.log("System Platform: " + Platform.getPlatform().getBit()); HMCLog.log("System Platform: " + Platform.getPlatform().getBit());
if (jv != null && jv.getPlatform() == Platform.BIT_32 && Platform.getPlatform() == Platform.BIT_64) if (jv != null && jv.getPlatform() == Platform.BIT_32 && Platform.getPlatform() == Platform.BIT_64)
MessageBox.Show(C.i18n("advice.os64butjdk32")); MessageBox.show(C.i18n("advice.os64butjdk32"));
if (!StrUtils.isBlank(options.getMaxMemory())) { if (!StrUtils.isBlank(options.getMaxMemory())) {
int mem = MathUtils.parseMemory(options.getMaxMemory(), 2147483647); int mem = MathUtils.parseMemory(options.getMaxMemory(), 2147483647);
if (jv != null && jv.getPlatform() == Platform.BIT_32 && mem > 1024) if (jv != null && jv.getPlatform() == Platform.BIT_32 && mem > 1024)
MessageBox.Show(C.i18n("launch.too_big_memory_alloc_64bit")); MessageBox.show(C.i18n("launch.too_big_memory_alloc_64bit"));
else { else {
long a = OS.getTotalPhysicalMemory() / 1024 / 1024; long a = OS.getTotalPhysicalMemory() / 1024 / 1024;
HMCLog.log("System Physical Memory: " + a); HMCLog.log("System Physical Memory: " + a);
if (a > 0 && a < mem) if (a > 0 && a < mem)
MessageBox.Show(C.i18n("launch.too_big_memory_alloc_free_space_too_low", a)); MessageBox.show(C.i18n("launch.too_big_memory_alloc_free_space_too_low", a));
} }
String a = "-Xmx" + options.getMaxMemory(); String a = "-Xmx" + options.getMaxMemory();
if (MathUtils.canParseInt(options.getMaxMemory())) if (MathUtils.canParseInt(options.getMaxMemory()))

View File

@@ -20,14 +20,14 @@ package org.jackhuang.hellominecraft.launcher.core.launch;
import java.io.IOException; import java.io.IOException;
import java.util.HashSet; import java.util.HashSet;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator; import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.auth.LoginInfo; import org.jackhuang.hellominecraft.launcher.core.auth.LoginInfo;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadLibraryJob; import org.jackhuang.hellominecraft.launcher.core.download.DownloadLibraryJob;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.util.tasks.ParallelTask; import org.jackhuang.hellominecraft.util.task.ParallelTask;
import org.jackhuang.hellominecraft.util.tasks.TaskWindow; import org.jackhuang.hellominecraft.util.task.TaskWindow;
import org.jackhuang.hellominecraft.util.system.Compressor; import org.jackhuang.hellominecraft.util.sys.CompressingUtils;
import org.jackhuang.hellominecraft.util.MessageBox; import org.jackhuang.hellominecraft.util.MessageBox;
public class DefaultGameLauncher extends GameLauncher { public class DefaultGameLauncher extends GameLauncher {
@@ -46,13 +46,13 @@ public class DefaultGameLauncher extends GameLauncher {
if (names.contains(s.lib.name)) if (names.contains(s.lib.name))
continue; continue;
names.add(s.lib.name); names.add(s.lib.name);
parallelTask.addDependsTask(new LibraryDownloadTask(s)); parallelTask.addTask(new LibraryDownloadTask(s));
} }
dw.append(parallelTask); dw.append(parallelTask);
boolean flag = true; boolean flag = true;
if (t.size() > 0) if (t.size() > 0)
flag = dw.create(); flag = dw.execute();
if (!flag && MessageBox.Show(C.i18n("launch.not_finished_downloading_libraries"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) if (!flag && MessageBox.show(C.i18n("launch.not_finished_downloading_libraries"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
flag = true; flag = true;
return flag; return flag;
}); });
@@ -61,7 +61,7 @@ public class DefaultGameLauncher extends GameLauncher {
return false; return false;
for (int i = 0; i < value.decompressFiles.length; i++) for (int i = 0; i < value.decompressFiles.length; i++)
try { try {
Compressor.unzip(value.decompressFiles[i], value.getDecompressTo(), value.extractRules[i]::allow, false); CompressingUtils.unzip(value.decompressFiles[i], value.getDecompressTo(), value.extractRules[i]::allow, false);
} catch (IOException ex) { } catch (IOException ex) {
HMCLog.err("Unable to decompress library: " + value.decompressFiles[i] + " to " + value.getDecompressTo(), ex); HMCLog.err("Unable to decompress library: " + value.decompressFiles[i] + " to " + value.getDecompressTo(), ex);
} }

View File

@@ -17,33 +17,32 @@
*/ */
package org.jackhuang.hellominecraft.launcher.core.launch; package org.jackhuang.hellominecraft.launcher.core.launch;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftLoader;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.util.List; import java.util.List;
import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog;
import org.jackhuang.hellominecraft.launcher.api.PluginManager; import org.jackhuang.hellominecraft.launcher.api.PluginManager;
import org.jackhuang.hellominecraft.launcher.core.GameException; import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.auth.AuthenticationException;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator; import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.auth.LoginInfo; import org.jackhuang.hellominecraft.launcher.core.auth.LoginInfo;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider; import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.core.auth.AuthenticationException;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadLibraryJob; import org.jackhuang.hellominecraft.launcher.core.download.DownloadLibraryJob;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftLoader;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.version.DecompressLibraryJob; import org.jackhuang.hellominecraft.launcher.core.version.DecompressLibraryJob;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.system.IOUtils;
import org.jackhuang.hellominecraft.util.system.JavaProcess;
import org.jackhuang.hellominecraft.util.MessageBox;
import org.jackhuang.hellominecraft.util.system.OS;
import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.util.EventHandler; import org.jackhuang.hellominecraft.util.EventHandler;
import org.jackhuang.hellominecraft.util.system.ProcessManager; import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.util.code.Charsets;
import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.util.sys.IOUtils;
import org.jackhuang.hellominecraft.util.sys.JavaProcess;
import org.jackhuang.hellominecraft.util.sys.OS;
import org.jackhuang.hellominecraft.util.sys.ProcessManager;
public class GameLauncher { public class GameLauncher {
@@ -117,7 +116,6 @@ public class GameLauncher {
* Launch the game "as soon as possible". * Launch the game "as soon as possible".
* *
* @param str launch command * @param str launch command
*
* @throws IOException failed creating process * @throws IOException failed creating process
*/ */
public void launch(List<String> str) throws IOException { public void launch(List<String> str) throws IOException {
@@ -138,7 +136,7 @@ public class GameLauncher {
if (options.getLaunchVersion() == null || service.baseDirectory() == null) if (options.getLaunchVersion() == null || service.baseDirectory() == null)
throw new Error("Fucking bug!"); throw new Error("Fucking bug!");
builder.redirectErrorStream(true).directory(service.version().getRunDirectory(options.getLaunchVersion())) builder.redirectErrorStream(true).directory(service.version().getRunDirectory(options.getLaunchVersion()))
.environment().put("APPDATA", service.baseDirectory().getAbsolutePath()); .environment().put("APPDATA", service.baseDirectory().getAbsolutePath());
JavaProcess jp = new JavaProcess(str, builder.start(), PROCESS_MANAGER); JavaProcess jp = new JavaProcess(str, builder.start(), PROCESS_MANAGER);
HMCLog.log("Have started the process"); HMCLog.log("Have started the process");
launchEvent.execute(jp); launchEvent.execute(jp);
@@ -148,13 +146,13 @@ public class GameLauncher {
* According to the name... * According to the name...
* *
* @param launcherName the name of launch bat/sh * @param launcherName the name of launch bat/sh
* @param str launch command * @param str launch command
* *
* @return launcher location * @return launcher location
* *
* @throws java.io.IOException write contents failed. * @throws java.io.IOException write contents failed.
*/ */
public File makeLauncher(String launcherName, List str) throws IOException { public File makeLauncher(String launcherName, List<String> str) throws IOException {
HMCLog.log("Making shell launcher..."); HMCLog.log("Making shell launcher...");
service.version().onLaunch(options.getLaunchVersion()); service.version().onLaunch(options.getLaunchVersion());
boolean isWin = OS.os() == OS.WINDOWS; boolean isWin = OS.os() == OS.WINDOWS;
@@ -162,33 +160,28 @@ public class GameLauncher {
if (!f.exists() && !f.createNewFile()) if (!f.exists() && !f.createNewFile())
HMCLog.warn("Failed to create " + f); HMCLog.warn("Failed to create " + f);
BufferedWriter writer; BufferedWriter writer;
try { try (FileOutputStream fos = FileUtils.openOutputStream(f)) {
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), System.getProperty("sun.jnu.encoding", "UTF-8"))); writer = new BufferedWriter(new OutputStreamWriter(fos, Charsets.toCharset()));
} catch (UnsupportedEncodingException ex) { if (isWin) {
HMCLog.warn("Failed to create writer, will try again.", ex); writer.write("@echo off");
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f)));
}
if (isWin) {
writer.write("@echo off");
writer.newLine();
String appdata = IOUtils.tryGetCanonicalFilePath(service.baseDirectory());
if (appdata != null) {
writer.write("set appdata=" + appdata);
writer.newLine(); writer.newLine();
writer.write("cd /D %appdata%"); String appdata = IOUtils.tryGetCanonicalFilePath(service.baseDirectory());
if (appdata != null) {
writer.write("set appdata=" + appdata);
writer.newLine();
writer.write("cd /D %appdata%");
writer.newLine();
}
}
if (StrUtils.isNotBlank(options.getPrecalledCommand())) {
writer.write(options.getPrecalledCommand());
writer.newLine(); writer.newLine();
} }
writer.write(StrUtils.makeCommand(str));
writer.close();
} }
if (StrUtils.isNotBlank(options.getPrecalledCommand())) { if (!f.setExecutable(true))
writer.write(options.getPrecalledCommand()); throw new IOException(C.i18n("launch.failed_sh_permission"));
writer.newLine();
}
writer.write(StrUtils.makeCommand(str));
writer.close();
if (!f.setExecutable(true)) {
HMCLog.warn("Failed to give launcher permission.");
MessageBox.Show(C.i18n("launch.failed_sh_permission"));
}
HMCLog.log("Command: " + StrUtils.parseParams("", str, " ")); HMCLog.log("Command: " + StrUtils.parseParams("", str, " "));
return f; return f;

View File

@@ -1,7 +1,7 @@
/* /*
* Hello Minecraft!. * Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com> * Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
@@ -15,24 +15,16 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}. * along with this program. If not, see {http://www.gnu.org/licenses/}.
*/ */
package org.jackhuang.hellominecraft.util.tasks.communication; package org.jackhuang.hellominecraft.launcher.core.launch;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
/** /**
* *
* @author huangyuhui * @author huang
* @param <T> the type of result.
*/ */
public class DefaultPreviousResult<T> implements PreviousResult<T> { public interface IAssetProvider {
T a; String provide(MinecraftVersion mv, Boolean allowChecking) throws GameException;
public DefaultPreviousResult(T a) {
this.a = a;
}
@Override
public T getResult() {
return a;
}
} }

View File

@@ -20,7 +20,7 @@ package org.jackhuang.hellominecraft.launcher.core.launch;
import java.io.File; import java.io.File;
import org.jackhuang.hellominecraft.launcher.core.version.GameDirType; import org.jackhuang.hellominecraft.launcher.core.version.GameDirType;
import org.jackhuang.hellominecraft.util.StrUtils; import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.util.system.JdkVersion; import org.jackhuang.hellominecraft.util.sys.JdkVersion;
/** /**
* *

View File

@@ -17,11 +17,9 @@
*/ */
package org.jackhuang.hellominecraft.launcher.core.launch; package org.jackhuang.hellominecraft.launcher.core.launch;
import java.io.File;
import java.net.URL;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadLibraryJob; import org.jackhuang.hellominecraft.launcher.core.download.DownloadLibraryJob;
import org.jackhuang.hellominecraft.util.tasks.download.FileDownloadTask; import org.jackhuang.hellominecraft.util.net.FileDownloadTask;
/** /**
* *
@@ -32,32 +30,10 @@ public class LibraryDownloadTask extends FileDownloadTask {
DownloadLibraryJob job; DownloadLibraryJob job;
public LibraryDownloadTask(DownloadLibraryJob job) { public LibraryDownloadTask(DownloadLibraryJob job) {
super(); super(job.parse().url, job.path);
this.job = job; this.job = job;
} }
@Override
public void executeTask() throws Throwable {
String name = job.lib.name;
if (name.startsWith("net.minecraftforge:forge:")) {
String[] s = name.split(":");
if (s.length == 3)
job.url = "http://files.minecraftforge.net/maven/net/minecraftforge/forge/" + s[2] + "/forge-" + s[2] + "-universal.jar";
}
if (name.startsWith("com.mumfrey:liteloader:")) {
String[] s = name.split(":");
if (s.length == 3 && s[2].length() > 3)
job.url = "http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + s[2].substring(0, s[2].length() - 3) + "/liteloader-" + s[2] + ".jar";
}
download(new URL(job.url), job.path);
}
void download(URL url, File filePath) throws Throwable {
this.url = url;
this.filePath = filePath;
super.executeTask();
}
@Override @Override
public String getInfo() { public String getInfo() {
return C.i18n("download") + ": " + job.lib.name; return C.i18n("download") + ": " + job.lib.name;

View File

@@ -21,16 +21,15 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale;
import org.jackhuang.hellominecraft.util.StrUtils; import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.util.system.IOUtils; import org.jackhuang.hellominecraft.util.sys.IOUtils;
import org.jackhuang.hellominecraft.util.system.OS; import org.jackhuang.hellominecraft.util.sys.OS;
import org.jackhuang.hellominecraft.launcher.core.GameException; import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider; import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.util.func.BiFunction;
/** /**
* *
@@ -48,7 +47,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
ArrayList<MinecraftLibrary> opt = new ArrayList<>(); ArrayList<MinecraftLibrary> opt = new ArrayList<>();
for (MinecraftLibrary l : version.libraries) for (MinecraftLibrary l : version.libraries)
if (l.allow() && !l.isRequiredToUnzip()) { if (l.allow() && !l.isRequiredToUnzip()) {
if (l.name.toLowerCase().contains("optifine")) { if (l.name.toLowerCase(Locale.US).contains("optifine")) {
opt.add(l); opt.add(l);
continue; continue;
} }
@@ -75,7 +74,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
throw new GameException(new NullPointerException("Minecraft Arguments can not be null.")); throw new GameException(new NullPointerException("Minecraft Arguments can not be null."));
String[] splitted = StrUtils.tokenize(version.minecraftArguments); String[] splitted = StrUtils.tokenize(version.minecraftArguments);
String game_assets = assetProvider.apply(version, !options.isNotCheckGame()); String game_assets = assetProvider.provide(version, !options.isNotCheckGame());
for (String t : splitted) { for (String t : splitted) {
t = t.replace("${auth_player_name}", lr.getUserName()); t = t.replace("${auth_player_name}", lr.getUserName());
@@ -114,13 +113,13 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
} }
} }
private final BiFunction<MinecraftVersion, Boolean, String> DEFAULT_ASSET_PROVIDER = (t, allow) -> { private final IAssetProvider DEFAULT_ASSET_PROVIDER = (t, allow) -> {
return new File(service.baseDirectory(), "assets").getAbsolutePath(); return new File(service.baseDirectory(), "assets").getAbsolutePath();
}; };
private BiFunction<MinecraftVersion, Boolean, String> assetProvider = DEFAULT_ASSET_PROVIDER; private IAssetProvider assetProvider = DEFAULT_ASSET_PROVIDER;
public void setAssetProvider(BiFunction<MinecraftVersion, Boolean, String> assetProvider) { public void setAssetProvider(IAssetProvider assetProvider) {
if (assetProvider == null) if (assetProvider == null)
this.assetProvider = DEFAULT_ASSET_PROVIDER; this.assetProvider = DEFAULT_ASSET_PROVIDER;
else else

View File

@@ -18,18 +18,16 @@
package org.jackhuang.hellominecraft.launcher.core.mod; package org.jackhuang.hellominecraft.launcher.core.mod;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftModService; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftModService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.util.code.DigestUtils; import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.util.system.FileUtils;
/** /**
* *
@@ -80,7 +78,7 @@ public class MinecraftModService extends IMinecraftModService {
if (!modCache.containsKey(id)) if (!modCache.containsKey(id))
recacheMods(id); recacheMods(id);
File modsFolder = service.version().getRunDirectory(id, "mods"); File modsFolder = service.version().getRunDirectory(id, "mods");
if (!modsFolder.exists() && !modsFolder.mkdirs()) if (!FileUtils.makeDirectory(modsFolder))
HMCLog.warn("Failed to make directories: " + modsFolder); HMCLog.warn("Failed to make directories: " + modsFolder);
File newf = new File(modsFolder, f.getName()); File newf = new File(modsFolder, f.getName());
FileUtils.copyFile(f, newf); FileUtils.copyFile(f, newf);
@@ -94,24 +92,23 @@ public class MinecraftModService extends IMinecraftModService {
} }
@Override @Override
public void removeMod(String id, Object[] rows) { public boolean removeMod(String id, Object[] rows) {
if (rows.length == 0) if (rows.length == 0)
return; return true;
boolean flag = true;
for (Object r : rows) for (Object r : rows)
if (r instanceof ModInfo) { if (r instanceof ModInfo) {
if (!((ModInfo) r).location.delete()) if (!((ModInfo) r).location.delete()) {
HMCLog.warn("Failed to delete mod" + r); HMCLog.warn("Failed to delete mod" + r);
flag = false;
}
} else if (r instanceof Number) } else if (r instanceof Number)
if (!getMods(id).get(((Number) r).intValue()).location.delete()) if (!getMods(id).get(((Number) r).intValue()).location.delete()) {
HMCLog.warn("Failed to delete mod " + r + ", maybe not a file?"); HMCLog.warn("Failed to delete mod " + r + ", maybe not a file?");
flag = false;
}
recacheMods(id); recacheMods(id);
} return flag;
public String[] checkMd5s(String id) throws IOException {
String[] res = new String[getMods(id).size()];
for (int i = 0; i < res.length; i++)
res[i] = DigestUtils.md5Hex(new FileInputStream(getMods(id).get(i).location));
return res;
} }
} }

View File

@@ -17,20 +17,22 @@
*/ */
package org.jackhuang.hellominecraft.launcher.core.mod; package org.jackhuang.hellominecraft.launcher.core.mod;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException; import com.google.gson.JsonSyntaxException;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.util.List; import java.util.List;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.util.StrUtils; import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.sys.FileUtils;
/** /**
* *
@@ -60,6 +62,8 @@ public class ModInfo implements Comparable<ModInfo> {
public String credits; public String credits;
@SerializedName("authorList") @SerializedName("authorList")
public String[] authorList; public String[] authorList;
@SerializedName("authors")
public String[] authors;
public boolean isActive() { public boolean isActive() {
return !location.getName().endsWith(".disabled"); return !location.getName().endsWith(".disabled");
@@ -87,6 +91,8 @@ public class ModInfo implements Comparable<ModInfo> {
public String getAuthor() { public String getAuthor() {
if (authorList != null && authorList.length > 0) if (authorList != null && authorList.length > 0)
return StrUtils.parseParams("", authorList, ", "); return StrUtils.parseParams("", authorList, ", ");
else if (authors != null && authors.length > 0)
return StrUtils.parseParams("", authors, ", ");
else if (StrUtils.isNotBlank(author)) else if (StrUtils.isNotBlank(author))
return author; return author;
else else
@@ -123,17 +129,30 @@ public class ModInfo implements Comparable<ModInfo> {
return name.endsWith(".zip") || name.endsWith(".jar") || name.endsWith("litemod"); return name.endsWith(".zip") || name.endsWith(".jar") || name.endsWith("litemod");
} }
private static final Type TYPE = new TypeToken<List<ModInfo>>() { private static ModInfo getForgeModInfo(File f, ZipFile jar, ZipEntry entry) throws IOException, JsonSyntaxException {
}.getType();
private static ModInfo getForgeModInfo(File f, ZipFile jar, ZipEntry entry) throws IOException {
ModInfo i = new ModInfo(); ModInfo i = new ModInfo();
i.location = f; i.location = f;
List<ModInfo> m = C.GSON.fromJson(new InputStreamReader(jar.getInputStream(entry), "UTF-8"), TYPE);
InputStreamReader streamReader = new InputStreamReader(jar.getInputStream(entry), "UTF-8");
JsonParser parser = new JsonParser();
JsonElement element = parser.parse(streamReader);
List<ModInfo> m = null;
if (element.isJsonArray())
m = C.GSON.fromJson(element, new TypeToken<List<ModInfo>>() {
}.getType());
else if (element.isJsonObject()) {
JsonObject modInfo = element.getAsJsonObject();
if (modInfo.has("modList") && modInfo.get("modList").isJsonArray())
m = C.GSON.fromJson(modInfo.get("modList"), new TypeToken<List<ModInfo>>() {
}.getType());
}
if (m != null && m.size() > 0) { if (m != null && m.size() > 0) {
i = m.get(0); i = m.get(0);
i.location = f; i.location = f;
} }
return i; return i;
} }

View File

@@ -34,20 +34,21 @@ import java.util.zip.ZipFile;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.GameException; import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftProvider; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftProvider;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.util.func.BiFunction; import org.jackhuang.hellominecraft.util.func.BiFunction;
import org.jackhuang.hellominecraft.util.func.CallbackIO; import org.jackhuang.hellominecraft.util.func.CallbackIO;
import org.jackhuang.hellominecraft.util.system.Compressor; import org.jackhuang.hellominecraft.util.sys.CompressingUtils;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.util.system.ZipEngine; import org.jackhuang.hellominecraft.util.sys.ZipEngine;
import org.jackhuang.hellominecraft.util.tasks.Task; import org.jackhuang.hellominecraft.util.task.Task;
import org.jackhuang.hellominecraft.util.ui.WebPage; import org.jackhuang.hellominecraft.util.net.WebPage;
import org.jackhuang.hellominecraft.util.MinecraftVersionRequest; import org.jackhuang.hellominecraft.util.MinecraftVersionRequest;
import org.jackhuang.hellominecraft.util.tasks.NoShownTaskException; import org.jackhuang.hellominecraft.util.sys.IOUtils;
import org.jackhuang.hellominecraft.util.task.NoShownTaskException;
/** /**
* A mod pack(*.zip) includes these things: * A mod pack(*.zip) includes these things:
@@ -86,21 +87,21 @@ public final class ModpackManager {
Collection<Task> c = new ArrayList<>(); Collection<Task> c = new ArrayList<>();
@Override @Override
public void executeTask() throws Throwable { public void executeTask(boolean areDependTasksSucceeded) throws Throwable {
String id = idFUCK; String id = idFUCK;
String description = C.i18n("modpack.task.install.will"); String description = C.i18n("modpack.task.install.will");
// Read modpack name and description from `modpack.json` // Read modpack name and description from `modpack.json`
try (ZipFile zip = new ZipFile(input)) { try (ZipFile zip = new ZipFile(input)) {
HashMap map = C.GSON.fromJson(new InputStreamReader(zip.getInputStream(zip.getEntry("modpack.json")), "UTF-8"), HashMap.class); HashMap<String, String> map = C.GSON.fromJson(new InputStreamReader(zip.getInputStream(zip.getEntry("modpack.json")), "UTF-8"), HashMap.class);
if (map != null) { if (map != null) {
if (id == null) if (id == null)
if (map.containsKey("name") && map.get("name") instanceof String) if (map.containsKey("name") && map.get("name") instanceof String)
id = (String) map.get("name"); id = map.get("name");
if (id != null) if (id != null)
description += id; description += id;
if (map.containsKey("description") && map.get("description") instanceof String) if (map.containsKey("description") && map.get("description") instanceof String)
description += "\n" + (String) map.get("description"); description += "\n" + map.get("description");
} }
if (id == null) if (id == null)
throw new IllegalStateException("Illegal modpack id!"); throw new IllegalStateException("Illegal modpack id!");
@@ -150,7 +151,7 @@ public final class ModpackManager {
try { try {
final AtomicInteger b = new AtomicInteger(0); final AtomicInteger b = new AtomicInteger(0);
HMCLog.log("Decompressing modpack"); HMCLog.log("Decompressing modpack");
Compressor.unzip(input, versions, t -> { CompressingUtils.unzip(input, versions, t -> {
if (t.equals("minecraft/pack.json")) if (t.equals("minecraft/pack.json"))
b.incrementAndGet(); b.incrementAndGet();
return true; return true;
@@ -186,8 +187,8 @@ public final class ModpackManager {
} }
} finally { } finally {
FileUtils.deleteDirectoryQuietly(oldFile); FileUtils.deleteDirectoryQuietly(oldFile);
if (newFile != null) if (newFile != null && !newFile.renameTo(oldFile))
newFile.renameTo(oldFile); HMCLog.warn("Failed to restore version minecraft");
} }
} }
@@ -244,7 +245,7 @@ public final class ModpackManager {
* *
* @throws IOException if create tmp directory failed * @throws IOException if create tmp directory failed
*/ */
public static void export(File output, IMinecraftProvider provider, String version, List<String> blacklist, Map modpackJson, CallbackIO<ZipEngine> callback) throws IOException, GameException { public static void export(File output, IMinecraftProvider provider, String version, List<String> blacklist, Map<String, String> modpackPreferences, CallbackIO<ZipEngine> callback) throws IOException, GameException {
final ArrayList<String> b = new ArrayList<>(MODPACK_BLACK_LIST); final ArrayList<String> b = new ArrayList<>(MODPACK_BLACK_LIST);
if (blacklist != null) if (blacklist != null)
b.addAll(blacklist); b.addAll(blacklist);
@@ -271,12 +272,11 @@ public final class ModpackManager {
mv.jar = r.version; mv.jar = r.version;
mv.runDir = "version"; mv.runDir = "version";
zip.putTextFile(C.GSON.toJson(mv), "minecraft/pack.json"); zip.putTextFile(C.GSON.toJson(mv), "minecraft/pack.json");
zip.putTextFile(C.GSON.toJson(modpackJson), "modpack.json"); zip.putTextFile(C.GSON.toJson(modpackPreferences), "modpack.json");
if (callback != null) if (callback != null)
callback.call(zip); callback.call(zip);
} finally { } finally {
if (zip != null) IOUtils.closeQuietly(zip);
zip.closeFile();
} }
} }

View File

@@ -19,8 +19,9 @@ package org.jackhuang.hellominecraft.launcher.core.service;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.version.AssetIndexDownloadInfo; import org.jackhuang.hellominecraft.launcher.core.version.AssetIndexDownloadInfo;
import org.jackhuang.hellominecraft.util.tasks.Task; import org.jackhuang.hellominecraft.util.task.Task;
/** /**
* *
@@ -32,7 +33,7 @@ public abstract class IMinecraftAssetService extends IMinecraftBasicService {
super(service); super(service);
} }
public abstract Task downloadAssets(String mcVersion); public abstract Task downloadAssets(String mcVersion) throws GameException;
public abstract File getAssets(); public abstract File getAssets();
@@ -43,7 +44,7 @@ public abstract class IMinecraftAssetService extends IMinecraftBasicService {
* *
* @return Is the action successful? * @return Is the action successful?
*/ */
public abstract boolean refreshAssetsIndex(String a); public abstract boolean refreshAssetsIndex(String a) throws GameException;
public abstract boolean downloadMinecraftAssetsIndexAsync(AssetIndexDownloadInfo assetsId); public abstract boolean downloadMinecraftAssetsIndexAsync(AssetIndexDownloadInfo assetsId);

View File

@@ -22,7 +22,7 @@ import java.util.List;
import org.jackhuang.hellominecraft.launcher.core.GameException; import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadLibraryJob; import org.jackhuang.hellominecraft.launcher.core.download.DownloadLibraryJob;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.util.tasks.Task; import org.jackhuang.hellominecraft.util.task.Task;
/** /**
* *

View File

@@ -19,7 +19,7 @@ package org.jackhuang.hellominecraft.launcher.core.service;
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.Task; import org.jackhuang.hellominecraft.util.task.Task;
/** /**
* *

View File

@@ -37,5 +37,5 @@ public abstract class IMinecraftModService extends IMinecraftBasicService {
public abstract boolean addMod(String id, File f); public abstract boolean addMod(String id, File f);
public abstract void removeMod(String id, Object[] mods); public abstract boolean removeMod(String id, Object[] mods);
} }

View File

@@ -36,7 +36,6 @@ public class Extract implements Cloneable {
} }
@Override @Override
@SuppressWarnings("CloneDeclaresCloneNotSupported")
public Object clone() { public Object clone() {
try { try {
return super.clone(); return super.clone();

View File

@@ -56,7 +56,6 @@ public abstract class IMinecraftLibrary implements Cloneable {
} }
@Override @Override
@SuppressWarnings("CloneDeclaresCloneNotSupported")
public Object clone() { public Object clone() {
try { try {
return super.clone(); return super.clone();

View File

@@ -20,7 +20,7 @@ package org.jackhuang.hellominecraft.launcher.core.version;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
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; import org.jackhuang.hellominecraft.util.sys.IOUtils;
/** /**
* *

View File

@@ -21,8 +21,8 @@ import com.google.gson.annotations.SerializedName;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import org.jackhuang.hellominecraft.util.system.OS; import org.jackhuang.hellominecraft.util.sys.OS;
import org.jackhuang.hellominecraft.util.system.Platform; import org.jackhuang.hellominecraft.util.sys.Platform;
import org.jackhuang.hellominecraft.util.StrUtils; import org.jackhuang.hellominecraft.util.StrUtils;
/** /**
@@ -46,14 +46,6 @@ public class MinecraftLibrary extends IMinecraftLibrary {
super(name); super(name);
} }
public MinecraftLibrary(ArrayList<Rules> rules, String url, Natives natives, String name, Extract extract, LibraryDownloadInfo downloads) {
super(name);
this.rules = rules == null ? null : (ArrayList<Rules>) rules.clone();
this.url = url;
this.natives = natives == null ? null : (Natives) natives.clone();
this.extract = extract == null ? null : (Extract) extract.clone();
}
/** /**
* is the library allowed to load. * is the library allowed to load.
* *
@@ -79,12 +71,12 @@ public class MinecraftLibrary extends IMinecraftLibrary {
private String getNative() { private String getNative() {
switch (OS.os()) { switch (OS.os()) {
case WINDOWS: case WINDOWS:
return formatArch(natives.windows); return formatArch(natives.windows);
case OSX: case OSX:
return formatArch(natives.osx); return formatArch(natives.osx);
default: default:
return formatArch(natives.linux); return formatArch(natives.linux);
} }
} }
@@ -116,6 +108,7 @@ public class MinecraftLibrary extends IMinecraftLibrary {
return extract == null ? new Extract() : extract; return extract == null ? new Extract() : extract;
} }
@Override
public LibraryDownloadInfo getDownloadInfo() { public LibraryDownloadInfo getDownloadInfo() {
if (downloads == null) if (downloads == null)
downloads = new LibrariesDownloadInfo(); downloads = new LibrariesDownloadInfo();
@@ -125,12 +118,15 @@ public class MinecraftLibrary extends IMinecraftLibrary {
downloads.classifiers = new HashMap<>(); downloads.classifiers = new HashMap<>();
if (!downloads.classifiers.containsKey(getNative())) if (!downloads.classifiers.containsKey(getNative()))
downloads.classifiers.put(getNative(), info = new LibraryDownloadInfo()); downloads.classifiers.put(getNative(), info = new LibraryDownloadInfo());
else else {
info = downloads.classifiers.get(getNative()); info = downloads.classifiers.get(getNative());
} else if (downloads.artifact == null) if (info == null) info = new LibraryDownloadInfo();
downloads.artifact = info = new LibraryDownloadInfo(); }
else } else {
if (downloads.artifact == null)
downloads.artifact = new LibraryDownloadInfo();
info = downloads.artifact; info = downloads.artifact;
}
if (StrUtils.isBlank(info.path)) { if (StrUtils.isBlank(info.path)) {
info.path = formatName(); info.path = formatName();
if (info.path == null) if (info.path == null)

View File

@@ -24,13 +24,13 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.launcher.core.GameException; import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftProvider; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftProvider;
import org.jackhuang.hellominecraft.launcher.core.asset.AssetsIndex; import org.jackhuang.hellominecraft.launcher.core.asset.AssetsIndex;
import org.jackhuang.hellominecraft.util.ArrayUtils; import org.jackhuang.hellominecraft.util.ArrayUtils;
import org.jackhuang.hellominecraft.util.Utils;
/** /**
* *
@@ -176,9 +176,27 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
return id.compareTo(o.id); return id.compareTo(o.id);
} }
@Override
public int hashCode() {
int hash = 7;
hash = 53 * hash + Objects.hashCode(this.id);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
return Objects.equals(this.id, ((MinecraftVersion) obj).id);
}
public AssetIndexDownloadInfo getAssetsIndex() { public AssetIndexDownloadInfo getAssetsIndex() {
if (assetIndex == null) if (assetIndex == null)
assetIndex = new AssetIndexDownloadInfo((String) Utils.firstNonNull(assets, AssetsIndex.DEFAULT_ASSET_NAME)); assetIndex = new AssetIndexDownloadInfo(assets == null ? AssetsIndex.DEFAULT_ASSET_NAME : assets);
return assetIndex; return assetIndex;
} }
@@ -194,6 +212,6 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
} }
public Set<IMinecraftLibrary> getLibraries() { public Set<IMinecraftLibrary> getLibraries() {
return libraries == null ? new HashSet() : new HashSet(libraries); return libraries == null ? new HashSet<>() : new HashSet<>(libraries);
} }
} }

View File

@@ -25,14 +25,14 @@ import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.GameException; import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftProvider; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftProvider;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.launcher.core.MCUtils; import org.jackhuang.hellominecraft.launcher.core.MCUtils;
import org.jackhuang.hellominecraft.util.tasks.TaskWindow; import org.jackhuang.hellominecraft.util.task.TaskWindow;
import org.jackhuang.hellominecraft.util.system.IOUtils; import org.jackhuang.hellominecraft.util.sys.IOUtils;
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.func.Consumer; import org.jackhuang.hellominecraft.util.func.Consumer;
@@ -45,7 +45,7 @@ import org.jackhuang.hellominecraft.util.ui.SwingUtils;
*/ */
public class MinecraftVersionManager extends IMinecraftProvider { public class MinecraftVersionManager extends IMinecraftProvider {
final Map<String, MinecraftVersion> versions = new TreeMap(); final Map<String, MinecraftVersion> versions = new TreeMap<>();
/** /**
* *
@@ -100,12 +100,12 @@ public class MinecraftVersionManager extends IMinecraftProvider {
} }
if (ask) { if (ask) {
HMCLog.warn("Found not matched filenames version: " + id + ", json: " + jsons[0].getName()); HMCLog.warn("Found not matched filenames version: " + id + ", json: " + jsons[0].getName());
if (MessageBox.Show(String.format(C.i18n("launcher.versions_json_not_matched"), id, jsons[0].getName()), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) if (MessageBox.show(String.format(C.i18n("launcher.versions_json_not_matched"), id, jsons[0].getName()), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
if (!jsons[0].renameTo(new File(jsons[0].getParent(), id + ".json"))) if (!jsons[0].renameTo(new File(jsons[0].getParent(), id + ".json")))
HMCLog.warn("Failed to rename version json " + jsons[0]); HMCLog.warn("Failed to rename version json " + jsons[0]);
} }
if (!jsonFile.exists()) { if (!jsonFile.exists()) {
if (MessageBox.Show(C.i18n("launcher.versions_json_not_matched_cannot_auto_completion", id), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) if (MessageBox.show(C.i18n("launcher.versions_json_not_matched_cannot_auto_completion", id), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
FileUtils.deleteDirectoryQuietly(dir); FileUtils.deleteDirectoryQuietly(dir);
continue; continue;
} }
@@ -113,16 +113,16 @@ public class MinecraftVersionManager extends IMinecraftProvider {
try { try {
mcVersion = C.GSON.fromJson(FileUtils.read(jsonFile), MinecraftVersion.class); mcVersion = C.GSON.fromJson(FileUtils.read(jsonFile), MinecraftVersion.class);
if (mcVersion == null) if (mcVersion == null)
throw new GameException("Wrong json format, got null."); throw new JsonSyntaxException("Wrong json format, got null.");
} catch (Exception e) { } catch (JsonSyntaxException | IOException e) {
HMCLog.warn("Found wrong format json, try to fix it.", 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) { if (MessageBox.show(C.i18n("launcher.versions_json_not_formatted", id), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
service.download().downloadMinecraftVersionJson(id); service.download().downloadMinecraftVersionJson(id);
try { try {
mcVersion = C.GSON.fromJson(FileUtils.read(jsonFile), MinecraftVersion.class); mcVersion = C.GSON.fromJson(FileUtils.read(jsonFile), MinecraftVersion.class);
if (mcVersion == null) if (mcVersion == null)
throw new GameException("Wrong json format, got null."); throw new JsonSyntaxException("Wrong json format, got null.");
} catch (IOException | GameException | JsonSyntaxException ex) { } catch (IOException | JsonSyntaxException ex) {
HMCLog.warn("Ignoring: " + dir + ", the json of this Minecraft is malformed.", ex); HMCLog.warn("Ignoring: " + dir + ", the json of this Minecraft is malformed.", ex);
continue; continue;
} }
@@ -194,7 +194,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
@Override @Override
public boolean install(String id, Consumer<MinecraftVersion> callback) { public boolean install(String id, Consumer<MinecraftVersion> callback) {
if (!TaskWindow.factory().append(service.download().downloadMinecraft(id)).create()) if (!TaskWindow.factory().append(service.download().downloadMinecraft(id)).execute())
return false; return false;
if (callback != null) { if (callback != null) {
File mvt = new File(versionRoot(id), id + ".json"); File mvt = new File(versionRoot(id), id + ".json");
@@ -256,7 +256,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
@Override @Override
public boolean onLaunch(String id) { public boolean onLaunch(String id) {
File resourcePacks = new File(getRunDirectory(id), "resourcepacks"); File resourcePacks = new File(getRunDirectory(id), "resourcepacks");
if (!resourcePacks.exists() && !resourcePacks.mkdirs()) if (!FileUtils.makeDirectory(resourcePacks))
HMCLog.warn("Failed to make resourcePacks: " + resourcePacks); HMCLog.warn("Failed to make resourcePacks: " + resourcePacks);
return true; return true;
} }
@@ -278,6 +278,5 @@ public class MinecraftVersionManager extends IMinecraftProvider {
@Override @Override
public void initializeMiencraft() { public void initializeMiencraft() {
} }
} }

View File

@@ -33,7 +33,6 @@ public class Natives implements Cloneable {
public String linux; public String linux;
@Override @Override
@SuppressWarnings("CloneDeclaresCloneNotSupported")
protected Object clone() { protected Object clone() {
try { try {
return super.clone(); return super.clone();

View File

@@ -19,7 +19,7 @@ package org.jackhuang.hellominecraft.launcher.core.version;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import org.jackhuang.hellominecraft.util.StrUtils; import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.util.system.OS; import org.jackhuang.hellominecraft.util.sys.OS;
/** /**
* *

View File

@@ -33,14 +33,8 @@ public class Rules {
public Rules() { public Rules() {
} }
public Rules(String action, OSRestriction os) {
this();
this.action = action;
this.os = os;
}
public String action() { public String action() {
return os == null || os != null && os.isCurrentOS() ? action : null; return os == null || os.isCurrentOS() ? action : null;
} }
} }

View File

@@ -33,19 +33,21 @@ import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import javax.net.ssl.X509TrustManager; import javax.net.ssl.X509TrustManager;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.RepaintManager;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException; import javax.swing.UnsupportedLookAndFeelException;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.launcher.api.PluginManager; import org.jackhuang.hellominecraft.launcher.api.PluginManager;
import org.jackhuang.hellominecraft.launcher.core.launch.GameLauncher; import org.jackhuang.hellominecraft.launcher.core.launch.GameLauncher;
import org.jackhuang.hellominecraft.launcher.util.CrashReporter; import org.jackhuang.hellominecraft.launcher.util.CrashReporter;
import org.jackhuang.hellominecraft.util.logging.Configuration; import org.jackhuang.hellominecraft.util.log.Configuration;
import org.jackhuang.hellominecraft.util.logging.appender.ConsoleAppender; import org.jackhuang.hellominecraft.util.log.appender.ConsoleAppender;
import org.jackhuang.hellominecraft.util.logging.layout.DefaultLayout; import org.jackhuang.hellominecraft.util.log.layout.DefaultLayout;
import org.jackhuang.hellominecraft.util.ui.LogWindow; import org.jackhuang.hellominecraft.util.ui.LogWindow;
import org.jackhuang.hellominecraft.launcher.setting.Settings; import org.jackhuang.hellominecraft.launcher.setting.Settings;
import org.jackhuang.hellominecraft.launcher.util.upgrade.IUpgrader; import org.jackhuang.hellominecraft.launcher.util.upgrade.IUpgrader;
import org.jackhuang.hellominecraft.launcher.ui.MainFrame; import org.jackhuang.hellominecraft.launcher.ui.MainFrame;
import org.jackhuang.hellominecraft.util.ui.MyRepaintManager;
import org.jackhuang.hellominecraft.launcher.util.DefaultPlugin; import org.jackhuang.hellominecraft.launcher.util.DefaultPlugin;
import org.jackhuang.hellominecraft.lookandfeel.HelloMinecraftLookAndFeel; import org.jackhuang.hellominecraft.lookandfeel.HelloMinecraftLookAndFeel;
import org.jackhuang.hellominecraft.util.MathUtils; import org.jackhuang.hellominecraft.util.MathUtils;
@@ -75,21 +77,6 @@ public final class Main implements Runnable {
}; };
private static final HostnameVerifier HNV = (hostname, session) -> true; private static final HostnameVerifier HNV = (hostname, session) -> true;
static {
SSLContext sslContext = null;
try {
sslContext = SSLContext.getInstance("TLS");
X509TrustManager[] xtmArray = new X509TrustManager[] { XTM };
sslContext.init(null, xtmArray, new java.security.SecureRandom());
} catch (GeneralSecurityException gse) {
}
if (sslContext != null)
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(HNV);
}
public static final String LAUNCHER_NAME = "Hello Minecraft! Launcher"; public static final String LAUNCHER_NAME = "Hello Minecraft! Launcher";
public static final String LAUNCHER_VERSION = "@HELLO_MINECRAFT_LAUNCHER_VERSION_FOR_GRADLE_REPLACING@"; public static final String LAUNCHER_VERSION = "@HELLO_MINECRAFT_LAUNCHER_VERSION_FOR_GRADLE_REPLACING@";
public static final int MINIMUM_LAUNCHER_VERSION = 16; public static final int MINIMUM_LAUNCHER_VERSION = 16;
@@ -111,7 +98,6 @@ public final class Main implements Runnable {
return "HMCL" + ' ' + LAUNCHER_VERSION; return "HMCL" + ' ' + LAUNCHER_VERSION;
} }
public static final Main INSTANCE = new Main();
private static HelloMinecraftLookAndFeel LOOK_AND_FEEL; private static HelloMinecraftLookAndFeel LOOK_AND_FEEL;
private static final Logger LOGGER = Logger.getLogger(Main.class.getName()); private static final Logger LOGGER = Logger.getLogger(Main.class.getName());
@@ -127,12 +113,22 @@ public final class Main implements Runnable {
System.setProperty("swing.aatext", "true"); System.setProperty("swing.aatext", "true");
System.setProperty("sun.java2d.noddraw", "true"); System.setProperty("sun.java2d.noddraw", "true");
System.setProperty("sun.java2d.dpiaware", "false"); System.setProperty("sun.java2d.dpiaware", "false");
System.setProperty("https.protocols", "SSLv3,TLSv1");
try {
SSLContext c = SSLContext.getInstance("SSL");
c.init(null, new X509TrustManager[] { XTM }, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(c.getSocketFactory());
} catch (GeneralSecurityException ignore) {
}
HttpsURLConnection.setDefaultHostnameVerifier(HNV);
Thread.setDefaultUncaughtExceptionHandler(new CrashReporter(true)); Thread.setDefaultUncaughtExceptionHandler(new CrashReporter(true));
try { try {
File file = new File("hmcl.log"); File file = new File("hmcl.log");
if (!file.exists() && !file.createNewFile()) if (!file.exists() && !file.createNewFile())
HMCLog.warn("Failed to create log file " + file); LOGGER.log(Level.WARNING, "Failed to create log file {0}", file);
Configuration.DEFAULT.appenders.add(new ConsoleAppender("File", new DefaultLayout(), true, new FileOutputStream(file), true)); Configuration.DEFAULT.appenders.add(new ConsoleAppender("File", new DefaultLayout(), true, new FileOutputStream(file), true));
} catch (IOException ex) { } catch (IOException ex) {
LOGGER.log(Level.SEVERE, "Failed to add log appender File because an error occurred while creating or opening hmcl.log", ex); LOGGER.log(Level.SEVERE, "Failed to add log appender File because an error occurred while creating or opening hmcl.log", ex);
@@ -147,17 +143,18 @@ public final class Main implements Runnable {
Locale.setDefault(sl.self); Locale.setDefault(sl.self);
} }
LogWindow.INSTANCE.clean();
LogWindow.INSTANCE.setTerminateGame(GameLauncher.PROCESS_MANAGER::stopAllProcesses);
try { try {
LOOK_AND_FEEL = new HelloMinecraftLookAndFeel(Settings.getInstance().getTheme().settings); LOOK_AND_FEEL = new HelloMinecraftLookAndFeel(Settings.getInstance().getTheme().settings);
UIManager.setLookAndFeel(LOOK_AND_FEEL); UIManager.setLookAndFeel(LOOK_AND_FEEL);
RepaintManager.setCurrentManager(new MyRepaintManager());
} catch (ParseException | UnsupportedLookAndFeelException ex) { } catch (ParseException | UnsupportedLookAndFeelException ex) {
HMCLog.warn("Failed to set look and feel...", ex); HMCLog.warn("Failed to set look and feel...", ex);
} }
LogWindow.INSTANCE.clean();
LogWindow.INSTANCE.setTerminateGame(GameLauncher.PROCESS_MANAGER::stopAllProcesses);
Settings.UPDATE_CHECKER.outdated.register(IUpgrader.NOW_UPGRADER); Settings.UPDATE_CHECKER.outOfDateEvent.register(IUpgrader.NOW_UPGRADER);
Settings.UPDATE_CHECKER.process(false).reg(t -> Main.invokeUpdate()).execute(); Settings.UPDATE_CHECKER.process(false).reg(t -> Main.invokeUpdate()).execute();
if (StrUtils.isNotBlank(Settings.getInstance().getProxyHost()) && StrUtils.isNotBlank(Settings.getInstance().getProxyPort()) && MathUtils.canParseInt(Settings.getInstance().getProxyPort())) { if (StrUtils.isNotBlank(Settings.getInstance().getProxyHost()) && StrUtils.isNotBlank(Settings.getInstance().getProxyPort()) && MathUtils.canParseInt(Settings.getInstance().getProxyPort())) {

View File

@@ -28,8 +28,8 @@ import java.util.UUID;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator; import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
import org.jackhuang.hellominecraft.lookandfeel.Theme; import org.jackhuang.hellominecraft.lookandfeel.Theme;
import org.jackhuang.hellominecraft.util.EventHandler; import org.jackhuang.hellominecraft.util.EventHandler;
import org.jackhuang.hellominecraft.util.system.JdkVersion; import org.jackhuang.hellominecraft.util.sys.JdkVersion;
import org.jackhuang.hellominecraft.util.system.OS; import org.jackhuang.hellominecraft.util.sys.OS;
/** /**
* *
@@ -53,10 +53,10 @@ public final class Config implements Cloneable {
private String proxyPassword; private String proxyPassword;
@SerializedName("enableShadow") @SerializedName("enableShadow")
private boolean enableShadow; private boolean enableShadow;
@SerializedName("enableBlur")
private boolean enableBlur;
@SerializedName("decorated") @SerializedName("decorated")
private boolean decorated; private boolean decorated;
@SerializedName("enableAnimation")
private boolean enableAnimation;
@SerializedName("theme") @SerializedName("theme")
private int theme; private int theme;
@SerializedName("java") @SerializedName("java")
@@ -110,6 +110,15 @@ public final class Config implements Cloneable {
Settings.save(); Settings.save();
} }
public boolean isEnableBlur() {
return enableBlur;
}
public void setEnableBlur(boolean enableBlur) {
this.enableBlur = enableBlur;
Settings.save();
}
public String getLast() { public String getLast() {
if (last == null) if (last == null)
last = Settings.DEFAULT_PROFILE; last = Settings.DEFAULT_PROFILE;
@@ -131,15 +140,6 @@ public final class Config implements Cloneable {
Settings.save(); Settings.save();
} }
public boolean isEnableAnimation() {
return enableAnimation;
}
public void setEnableAnimation(boolean enableAnimation) {
this.enableAnimation = enableAnimation;
Settings.save();
}
public String getClientToken() { public String getClientToken() {
return clientToken; return clientToken;
} }
@@ -194,8 +194,7 @@ public final class Config implements Cloneable {
public Config() { public Config() {
clientToken = UUID.randomUUID().toString(); clientToken = UUID.randomUUID().toString();
logintype = downloadtype = 0; logintype = downloadtype = 0;
enableShadow = false; enableBlur = enableShadow = true;
enableAnimation = true;
theme = 4; theme = 4;
decorated = OS.os() == OS.LINUX; decorated = OS.os() == OS.LINUX;
auth = new HashMap<>(); auth = new HashMap<>();

View File

@@ -24,10 +24,10 @@ import org.jackhuang.hellominecraft.launcher.api.PluginManager;
import org.jackhuang.hellominecraft.launcher.core.MCUtils; import org.jackhuang.hellominecraft.launcher.core.MCUtils;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.util.system.IOUtils; import org.jackhuang.hellominecraft.util.sys.IOUtils;
import org.jackhuang.hellominecraft.util.StrUtils; import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.util.EventHandler; import org.jackhuang.hellominecraft.util.EventHandler;
import org.jackhuang.hellominecraft.util.system.OS; import org.jackhuang.hellominecraft.util.sys.OS;
/** /**
* *

View File

@@ -23,13 +23,13 @@ import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.launcher.Main; import org.jackhuang.hellominecraft.launcher.Main;
import org.jackhuang.hellominecraft.launcher.core.MCUtils; import org.jackhuang.hellominecraft.launcher.core.MCUtils;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType; import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
import org.jackhuang.hellominecraft.util.CollectionUtils; import org.jackhuang.hellominecraft.util.CollectionUtils;
import org.jackhuang.hellominecraft.util.EventHandler; import org.jackhuang.hellominecraft.util.EventHandler;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.util.MessageBox; import org.jackhuang.hellominecraft.util.MessageBox;
import org.jackhuang.hellominecraft.util.UpdateChecker; import org.jackhuang.hellominecraft.util.UpdateChecker;
@@ -126,16 +126,8 @@ public final class Settings {
return SETTINGS.getConfigurations(); return SETTINGS.getConfigurations();
} }
public static void setProfile(Profile ver) {
getProfiles().put(ver.getName(), ver);
}
public static Collection<Profile> getProfilesFiltered() { public static Collection<Profile> getProfilesFiltered() {
return CollectionUtils.map(getProfiles().values(), t -> t != null && t.getName() != null); return CollectionUtils.filter(getProfiles().values(), t -> t != null && t.getName() != null);
}
public static Profile getOneProfile() {
return SETTINGS.getConfigurations().firstEntry().getValue();
} }
public static boolean putProfile(Profile ver) { public static boolean putProfile(Profile ver) {
@@ -151,7 +143,7 @@ public final class Settings {
public static boolean delProfile(String ver) { public static boolean delProfile(String ver) {
if (DEFAULT_PROFILE.equals(ver)) { if (DEFAULT_PROFILE.equals(ver)) {
MessageBox.Show(C.i18n("settings.cannot_remove_default_config")); MessageBox.show(C.i18n("settings.cannot_remove_default_config"));
return false; return false;
} }
boolean notify = false; boolean notify = false;
@@ -163,8 +155,8 @@ public final class Settings {
return flag; return flag;
} }
public static final EventHandler<Profile> profileChangedEvent = new EventHandler(null); public static final EventHandler<Profile> profileChangedEvent = new EventHandler<>(null);
public static final EventHandler<Void> profileLoadingEvent = new EventHandler(null); public static final EventHandler<Void> profileLoadingEvent = new EventHandler<>(null);
static void onProfileChanged() { static void onProfileChanged() {
Profile p = getLastProfile(); Profile p = getLastProfile();

View File

@@ -27,10 +27,10 @@ import org.jackhuang.hellominecraft.launcher.core.version.GameDirType;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.EventHandler; import org.jackhuang.hellominecraft.util.EventHandler;
import org.jackhuang.hellominecraft.util.StrUtils; import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.util.Utils; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.sys.Java;
import org.jackhuang.hellominecraft.util.system.Java; import org.jackhuang.hellominecraft.util.sys.JdkVersion;
import org.jackhuang.hellominecraft.util.system.JdkVersion; import org.jackhuang.hellominecraft.util.sys.OS;
/** /**
* *
@@ -93,27 +93,6 @@ public class VersionSetting {
javaDir = java = minecraftArgs = serverIp = precalledCommand = wrapper = ""; javaDir = java = minecraftArgs = serverIp = precalledCommand = wrapper = "";
} }
public VersionSetting(VersionSetting v) {
this();
if (v == null)
return;
maxMemory = v.maxMemory;
width = v.width;
height = v.height;
java = v.java;
fullscreen = v.fullscreen;
javaArgs = v.javaArgs;
javaDir = v.javaDir;
minecraftArgs = v.minecraftArgs;
permSize = v.permSize;
gameDirType = v.gameDirType;
noJVMArgs = v.noJVMArgs;
launcherVisibility = v.launcherVisibility;
precalledCommand = v.precalledCommand;
wrapper = v.wrapper;
serverIp = v.serverIp;
}
public String getJavaDir() { public String getJavaDir() {
Java j = getJava(); Java j = getJava();
if (j.getHome() == null) if (j.getHome() == null)
@@ -173,13 +152,9 @@ public class VersionSetting {
propertyChanged.execute("javaArgs"); propertyChanged.execute("javaArgs");
} }
public boolean hasJavaArgs() {
return StrUtils.isNotBlank(getJavaArgs().trim());
}
public String getMaxMemory() { public String getMaxMemory() {
if (StrUtils.isBlank(maxMemory)) if (StrUtils.isBlank(maxMemory))
return String.valueOf(Utils.getSuggestedMemorySize()); return String.valueOf(OS.getSuggestedMemorySize());
return maxMemory; return maxMemory;
} }

View File

@@ -1,124 +0,0 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.ui;
import java.awt.AlphaComposite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import org.jackhuang.hellominecraft.launcher.setting.Settings;
/**
*
* @author huangyuhui
*/
public class AnimatedPanel extends JPanel implements Selectable {
private static final int ANIMATION_LENGTH = 10;
public AnimatedPanel() {
timer = new Timer(1, (e) -> {
SwingUtilities.invokeLater(() -> {
AnimatedPanel.this.repaint();
offsetX += 0.15;
if (offsetX >= ANIMATION_LENGTH) {
timer.stop();
AnimatedPanel.this.repaint();
}
});
});
}
double offsetX = ANIMATION_LENGTH;
Timer timer;
boolean animationEnabled = true;
public void animate() {
if (Settings.getInstance().isEnableAnimation() && animationEnabled) {
offsetX = 0;
timer.start();
}
}
@Override
public void paint(Graphics g) {
if (!(g instanceof Graphics2D)) {
super.paint(g);
return;
}
double pgs = 1 - Math.sin(Math.PI / 2 / ANIMATION_LENGTH * offsetX);
if (Math.abs(ANIMATION_LENGTH - offsetX) < 0.1) {
super.paint(g);
return;
}
if (pgs > 1)
pgs = 1;
if (pgs < 0)
pgs = 0;
Graphics2D gg = (Graphics2D) g;
int width = this.getWidth();
int height = this.getHeight();
if (isOpaque()) {
g.setColor(getBackground());
g.fillRect(0, 0, width, height);
}
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = image.createGraphics();
g2d.translate((int) (pgs * 50), 0);
super.paint(g2d);
g2d.dispose();
gg.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, (float) (1 - pgs)));
g.drawImage(image, 0, 0, this);
}
boolean selected = false;
@Override
public boolean isSelected() {
return selected;
}
@Override
public void onSelect() {
if (!selected)
animate();
selected = true;
}
@Override
public void onLeave() {
selected = false;
}
boolean created = false;
@Override
public void onCreate() {
created = true;
}
@Override
public boolean isCreated() {
return created;
}
}

View File

@@ -18,20 +18,19 @@
package org.jackhuang.hellominecraft.launcher.ui; package org.jackhuang.hellominecraft.launcher.ui;
import javax.swing.table.DefaultTableModel; import javax.swing.table.DefaultTableModel;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
import org.jackhuang.hellominecraft.launcher.core.download.MinecraftRemoteVersions; import org.jackhuang.hellominecraft.launcher.core.download.MinecraftRemoteVersions;
import org.jackhuang.hellominecraft.launcher.setting.Settings; import org.jackhuang.hellominecraft.launcher.setting.Settings;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
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.tasks.TaskWindow; import org.jackhuang.hellominecraft.util.task.TaskWindow;
import org.jackhuang.hellominecraft.util.ui.SwingUtils; import org.jackhuang.hellominecraft.util.ui.SwingUtils;
/** /**
* *
* @author huangyuhui * @author huangyuhui
*/ */
public class GameDownloadPanel extends AnimatedPanel { public class GameDownloadPanel extends Page {
GameSettingsPanel gsp; GameSettingsPanel gsp;
@@ -108,19 +107,23 @@ public class GameDownloadPanel extends AnimatedPanel {
public void refreshDownloads() { public void refreshDownloads() {
DefaultTableModel model = SwingUtils.clearDefaultTable(lstDownloads); DefaultTableModel model = SwingUtils.clearDefaultTable(lstDownloads);
model.addRow(new Object[] { C.i18n("message.loading"), "", "" });
MinecraftRemoteVersions.refreshRomoteVersions(Settings.getLastProfile().service().getDownloadType()) MinecraftRemoteVersions.refreshRomoteVersions(Settings.getLastProfile().service().getDownloadType())
.reg((ver) -> model.addRow(new Object[] { ver.id, ver.time, .reg((ver) -> model.addRow(new Object[] { ver.id, ver.time,
StrUtils.equalsOne(ver.type, "old_beta", "old_alpha", "release", "snapshot") ? C.i18n("versions." + ver.type) : ver.type })) StrUtils.equalsOne(ver.type, "old_beta", "old_alpha", "release", "snapshot") ? C.i18n("versions." + ver.type) : ver.type }))
.regDone(lstDownloads::requestFocus).execute(); .regDone(SwingUtils.invokeLater(() -> {
lstDownloads.requestFocus();
model.removeRow(0);
})).execute();
} }
void downloadMinecraft() { void downloadMinecraft() {
if (lstDownloads.getSelectedRow() < 0) { if (lstDownloads.getSelectedRow() < 0) {
MessageBox.Show(C.i18n("gamedownload.not_refreshed")); MessageBox.show(C.i18n("gamedownload.not_refreshed"));
return; return;
} }
String id = (String) lstDownloads.getModel().getValueAt(lstDownloads.getSelectedRow(), 0); String id = (String) lstDownloads.getModel().getValueAt(lstDownloads.getSelectedRow(), 0);
TaskWindow.execute(Settings.getLastProfile().service().download().downloadMinecraft(id)); TaskWindow.factory().execute(Settings.getLastProfile().service().download().downloadMinecraft(id));
} }
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables

View File

@@ -85,9 +85,6 @@
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout"/> <Layout class="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout"/>
<SubComponents> <SubComponents>
<Container class="javax.swing.JPanel" name="pnlSettings"> <Container class="javax.swing.JPanel" name="pnlSettings">
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new AnimatedPanel()"/>
</AuxValues>
<Constraints> <Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription"> <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
<JTabbedPaneConstraints tabName="&lt;settings&gt;"> <JTabbedPaneConstraints tabName="&lt;settings&gt;">
@@ -372,9 +369,6 @@
</SubComponents> </SubComponents>
</Container> </Container>
<Container class="javax.swing.JPanel" name="pnlAdvancedSettings"> <Container class="javax.swing.JPanel" name="pnlAdvancedSettings">
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new AnimatedPanel()"/>
</AuxValues>
<Constraints> <Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription"> <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
<JTabbedPaneConstraints tabName="&lt;advancedsettings&gt;"> <JTabbedPaneConstraints tabName="&lt;advancedsettings&gt;">
@@ -566,9 +560,6 @@
</SubComponents> </SubComponents>
</Container> </Container>
<Container class="javax.swing.JPanel" name="pnlModManagement"> <Container class="javax.swing.JPanel" name="pnlModManagement">
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new AnimatedPanel()"/>
</AuxValues>
<Constraints> <Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription"> <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
<JTabbedPaneConstraints tabName="&lt;mods&gt;"> <JTabbedPaneConstraints tabName="&lt;mods&gt;">
@@ -694,9 +685,6 @@
</SubComponents> </SubComponents>
</Container> </Container>
<Container class="javax.swing.JPanel" name="pnlAutoInstall"> <Container class="javax.swing.JPanel" name="pnlAutoInstall">
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new AnimatedPanel()"/>
</AuxValues>
<Constraints> <Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription"> <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
<JTabbedPaneConstraints tabName="&lt;settings.tabs.installers&gt;"> <JTabbedPaneConstraints tabName="&lt;settings.tabs.installers&gt;">
@@ -788,7 +776,7 @@
<Component id="cboVersions" alignment="3" min="-2" pref="26" max="-2" attributes="0"/> <Component id="cboVersions" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
<Component id="lblVersions" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="lblVersions" alignment="3" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace max="32767" attributes="0"/> <EmptySpace pref="11" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>

View File

@@ -17,9 +17,9 @@
*/ */
package org.jackhuang.hellominecraft.launcher.ui; package org.jackhuang.hellominecraft.launcher.ui;
import java.awt.Color;
import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable; import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.DnDConstants; import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget; import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDragEvent; import java.awt.dnd.DropTargetDragEvent;
@@ -34,7 +34,6 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import javax.swing.DefaultComboBoxModel; import javax.swing.DefaultComboBoxModel;
import javax.swing.JFileChooser;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JPopupMenu; import javax.swing.JPopupMenu;
@@ -42,8 +41,9 @@ import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelEvent;
import javax.swing.table.DefaultTableModel; import javax.swing.table.DefaultTableModel;
import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.launcher.util.LauncherVisibility; import org.jackhuang.hellominecraft.launcher.util.LauncherVisibility;
import org.jackhuang.hellominecraft.launcher.setting.Profile; import org.jackhuang.hellominecraft.launcher.setting.Profile;
import org.jackhuang.hellominecraft.launcher.setting.Settings; import org.jackhuang.hellominecraft.launcher.setting.Settings;
@@ -55,22 +55,24 @@ import org.jackhuang.hellominecraft.launcher.core.version.GameDirType;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.launcher.setting.VersionSetting; import org.jackhuang.hellominecraft.launcher.setting.VersionSetting;
import org.jackhuang.hellominecraft.util.MessageBox; import org.jackhuang.hellominecraft.util.MessageBox;
import org.jackhuang.hellominecraft.util.OverridableSwingWorker; import org.jackhuang.hellominecraft.util.AbstractSwingWorker;
import org.jackhuang.hellominecraft.util.MinecraftVersionRequest; import org.jackhuang.hellominecraft.util.MinecraftVersionRequest;
import org.jackhuang.hellominecraft.util.system.OS; import org.jackhuang.hellominecraft.util.sys.OS;
import org.jackhuang.hellominecraft.util.StrUtils; import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.util.func.Consumer; import org.jackhuang.hellominecraft.util.func.Consumer;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.util.ui.SwingUtils; import org.jackhuang.hellominecraft.util.ui.SwingUtils;
import org.jackhuang.hellominecraft.util.system.Java; import org.jackhuang.hellominecraft.util.sys.Java;
import org.jackhuang.hellominecraft.util.tasks.TaskWindow; import org.jackhuang.hellominecraft.util.task.TaskWindow;
import org.jackhuang.hellominecraft.util.ui.GraphicsUtils;
import org.jackhuang.hellominecraft.util.ui.JSystemFileChooser;
import org.jackhuang.hellominecraft.util.ui.LogWindow; import org.jackhuang.hellominecraft.util.ui.LogWindow;
/** /**
* *
* @author huangyuhui * @author huangyuhui
*/ */
public final class GameSettingsPanel extends AnimatedPanel implements DropTargetListener { public final class GameSettingsPanel extends RepaintPage implements DropTargetListener {
boolean isLoading = false; boolean isLoading = false;
public MinecraftVersionRequest minecraftVersion; public MinecraftVersionRequest minecraftVersion;
@@ -78,19 +80,18 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
final InstallerPanel installerPanels[] = new InstallerPanel[InstallerType.values().length]; final InstallerPanel installerPanels[] = new InstallerPanel[InstallerType.values().length];
/**
* Creates new form GameSettingsPanel
*/
public GameSettingsPanel(MainFrame mf) { public GameSettingsPanel(MainFrame mf) {
mf.actions.put("showGameDownloads", () -> { mf.actions.put("showGameDownloads", () -> {
MainFrame.INSTANCE.selectTab("game"); MainFrame.INSTANCE.selectTab("game");
showGameDownloads(); showGameDownloads();
}); });
setRepainter(this);
} }
void initGui() { void initGui() {
initComponents(); initComponents();
setBackground(Color.white); setBackground(GraphicsUtils.getWebColorWithAlpha("FFFFFF7F"));
setOpaque(true); setOpaque(true);
for (int i = 0; i < InstallerType.values().length; i++) for (int i = 0; i < InstallerType.values().length; i++)
@@ -163,7 +164,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
ppmManage.add(itm); ppmManage.add(itm);
itm = new JMenuItem(C.i18n("versions.manage.remove")); itm = new JMenuItem(C.i18n("versions.manage.remove"));
itm.addActionListener((e) -> { itm.addActionListener((e) -> {
if (mcVersion != null && MessageBox.Show(C.i18n("versions.manage.remove.confirm") + mcVersion, MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) if (mcVersion != null && MessageBox.show(C.i18n("versions.manage.remove.confirm") + mcVersion, MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
if (Settings.getLastProfile().service().version().removeVersionFromDisk(mcVersion)) if (Settings.getLastProfile().service().version().removeVersionFromDisk(mcVersion))
refreshVersions(); refreshVersions();
}); });
@@ -177,7 +178,12 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
itm = new JMenuItem(C.i18n("versions.manage.redownload_assets_index")); itm = new JMenuItem(C.i18n("versions.manage.redownload_assets_index"));
itm.addActionListener((e) -> { itm.addActionListener((e) -> {
if (mcVersion != null) if (mcVersion != null)
Settings.getLastProfile().service().asset().refreshAssetsIndex(mcVersion); try {
Settings.getLastProfile().service().asset().refreshAssetsIndex(mcVersion);
} catch (GameException ex) {
HMCLog.err("Failed to download assets", ex);
MessageBox.showLocalized("assets.failed_download");
}
}); });
ppmManage.add(itm); ppmManage.add(itm);
itm = new JMenuItem(C.i18n("versions.mamage.remove_libraries")); itm = new JMenuItem(C.i18n("versions.mamage.remove_libraries"));
@@ -231,13 +237,15 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
public void stateChanged(ChangeEvent e) { public void stateChanged(ChangeEvent e) {
if (tabVersionEdit.getSelectedComponent() == pnlAutoInstall && !b) { if (tabVersionEdit.getSelectedComponent() == pnlAutoInstall && !b) {
b = true; b = true;
installerPanels[0].refreshVersions(); TaskWindow.factory().execute(installerPanels[0].refreshVersionsTask());
} }
} }
}); });
((NewTabPane) tabVersionEdit).initializing = true; ((NewTabPane) tabVersionEdit).initializing = true;
tabVersionEdit.addTab(C.i18n("settings.tabs.game_download"), pnlGameDownloads); // NOI18N tabVersionEdit.addTab(C.i18n("settings.tabs.game_download"), pnlGameDownloads);
((NewTabPane) tabVersionEdit).initializing = false; ((NewTabPane) tabVersionEdit).initializing = false;
((NewTabPane) tabInstallers).initializing = true; ((NewTabPane) tabInstallers).initializing = true;
for (int i = 0; i < InstallerType.values().length; i++) for (int i = 0; i < InstallerType.values().length; i++)
tabInstallers.addTab(InstallerType.values()[i].getLocalizedName(), installerPanels[i]); tabInstallers.addTab(InstallerType.values()[i].getLocalizedName(), installerPanels[i]);
@@ -255,7 +263,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
tabVersionEdit = new NewTabPane(); tabVersionEdit = new NewTabPane();
((NewTabPane)tabVersionEdit).initializing = true; ((NewTabPane)tabVersionEdit).initializing = true;
pnlSettings = new AnimatedPanel(); pnlSettings = new javax.swing.JPanel();
lblGameDir = new javax.swing.JLabel(); lblGameDir = new javax.swing.JLabel();
txtGameDir = new javax.swing.JTextField(); txtGameDir = new javax.swing.JTextField();
lblDimension = new javax.swing.JLabel(); lblDimension = new javax.swing.JLabel();
@@ -277,7 +285,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
cboJava = new javax.swing.JComboBox(); cboJava = new javax.swing.JComboBox();
btnChoosingGameDir = new javax.swing.JButton(); btnChoosingGameDir = new javax.swing.JButton();
btnCleanGame = new javax.swing.JButton(); btnCleanGame = new javax.swing.JButton();
pnlAdvancedSettings = new AnimatedPanel(); pnlAdvancedSettings = new javax.swing.JPanel();
lblJavaArgs = new javax.swing.JLabel(); lblJavaArgs = new javax.swing.JLabel();
txtJavaArgs = new javax.swing.JTextField(); txtJavaArgs = new javax.swing.JTextField();
txtMinecraftArgs = new javax.swing.JTextField(); txtMinecraftArgs = new javax.swing.JTextField();
@@ -292,14 +300,14 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
lblPrecalledCommand1 = new javax.swing.JLabel(); lblPrecalledCommand1 = new javax.swing.JLabel();
txtWrapperLauncher = new javax.swing.JTextField(); txtWrapperLauncher = new javax.swing.JTextField();
chkDontCheckGame = new javax.swing.JCheckBox(); chkDontCheckGame = new javax.swing.JCheckBox();
pnlModManagement = new AnimatedPanel(); pnlModManagement = new javax.swing.JPanel();
pnlModManagementContent = new javax.swing.JPanel(); pnlModManagementContent = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane(); jScrollPane1 = new javax.swing.JScrollPane();
lstExternalMods = new javax.swing.JTable(); lstExternalMods = new javax.swing.JTable();
btnAddMod = new javax.swing.JButton(); btnAddMod = new javax.swing.JButton();
btnRemoveMod = new javax.swing.JButton(); btnRemoveMod = new javax.swing.JButton();
lblModInfo = new javax.swing.JLabel(); lblModInfo = new javax.swing.JLabel();
pnlAutoInstall = new AnimatedPanel(); pnlAutoInstall = new javax.swing.JPanel();
tabInstallers = new NewTabPane(); tabInstallers = new NewTabPane();
pnlTop = new javax.swing.JPanel(); pnlTop = new javax.swing.JPanel();
pnlSelection = new javax.swing.JPanel(); pnlSelection = new javax.swing.JPanel();
@@ -599,9 +607,6 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
.addGroup(pnlAdvancedSettingsLayout.createSequentialGroup() .addGroup(pnlAdvancedSettingsLayout.createSequentialGroup()
.addGroup(pnlAdvancedSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlAdvancedSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtWrapperLauncher) .addComponent(txtWrapperLauncher)
.addGroup(pnlAdvancedSettingsLayout.createSequentialGroup()
.addComponent(lblPrecalledCommand1)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(pnlAdvancedSettingsLayout.createSequentialGroup() .addGroup(pnlAdvancedSettingsLayout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addComponent(chkNoJVMArgs) .addComponent(chkNoJVMArgs)
@@ -609,6 +614,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
.addComponent(chkDontCheckGame)) .addComponent(chkDontCheckGame))
.addGroup(pnlAdvancedSettingsLayout.createSequentialGroup() .addGroup(pnlAdvancedSettingsLayout.createSequentialGroup()
.addGroup(pnlAdvancedSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlAdvancedSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblPrecalledCommand1)
.addComponent(lblPrecalledCommand) .addComponent(lblPrecalledCommand)
.addComponent(lblServerIP)) .addComponent(lblServerIP))
.addGap(0, 0, Short.MAX_VALUE))) .addGap(0, 0, Short.MAX_VALUE)))
@@ -780,7 +786,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
.addGroup(pnlSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(pnlSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cboVersions, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(cboVersions, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblVersions)) .addComponent(lblVersions))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap(11, Short.MAX_VALUE))
); );
btnModify.setText(C.i18n("settings.manage")); // NOI18N btnModify.setText(C.i18n("settings.manage")); // NOI18N
@@ -946,22 +952,58 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
((NewTabPane)tabVersionEdit).initializing = false; ((NewTabPane)tabVersionEdit).initializing = false;
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
// <editor-fold defaultstate="collapsed" desc="UI Events">
private void cboProfilesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboProfilesItemStateChanged private void btnIncludeMinecraftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIncludeMinecraftActionPerformed
if (!isLoading) JSystemFileChooser fc = new JSystemFileChooser(new File("."));
Settings.getInstance().setLast((String) cboProfiles.getSelectedItem()); fc.setFileSelectionMode(JSystemFileChooser.DIRECTORIES_ONLY);
}//GEN-LAST:event_cboProfilesItemStateChanged if (fc.showOpenDialog(this) == JSystemFileChooser.APPROVE_OPTION) {
File newGameDir = fc.getSelectedFile();
String name = JOptionPane.showInputDialog(C.i18n("setupwindow.give_a_name"));
if (StrUtils.isBlank(name)) {
MessageBox.show(C.i18n("setupwindow.no_empty_name"));
return;
}
Settings.putProfile(new Profile(name).setGameDir(newGameDir.getAbsolutePath()));
MessageBox.show(C.i18n("setupwindow.find_in_configurations"));
loadProfiles();
}
}//GEN-LAST:event_btnIncludeMinecraftActionPerformed
private void btnMakeLaunchScriptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMakeLaunchScriptActionPerformed
MainFrame.INSTANCE.daemon.makeLaunchScript(Settings.getLastProfile());
}//GEN-LAST:event_btnMakeLaunchScriptActionPerformed
private void btnShowLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShowLogActionPerformed
LogWindow.INSTANCE.setVisible(true);
}//GEN-LAST:event_btnShowLogActionPerformed
private void btnTestGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTestGameActionPerformed
LogWindow.INSTANCE.setVisible(true);
MainFrame.INSTANCE.daemon.runGame(Settings.getLastProfile());
}//GEN-LAST:event_btnTestGameActionPerformed
private void btnExploreMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnExploreMouseClicked
ppmExplore.show(evt.getComponent(), evt.getPoint().x, evt.getPoint().y);
}//GEN-LAST:event_btnExploreMouseClicked
private void btnRemoveProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveProfileActionPerformed
if (MessageBox.show(C.i18n("ui.message.sure_remove", Settings.getLastProfile().getName()), MessageBox.YES_NO_OPTION) == MessageBox.NO_OPTION)
return;
Settings.delProfile(Settings.getLastProfile());
}//GEN-LAST:event_btnRemoveProfileActionPerformed
private void btnNewProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewProfileActionPerformed private void btnNewProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewProfileActionPerformed
new NewProfileWindow(null).setVisible(true); new NewProfileWindow(null).setVisible(true);
loadProfiles(); loadProfiles();
}//GEN-LAST:event_btnNewProfileActionPerformed }//GEN-LAST:event_btnNewProfileActionPerformed
private void btnRemoveProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveProfileActionPerformed private void btnRefreshVersionsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshVersionsActionPerformed
if (MessageBox.Show(C.i18n("ui.message.sure_remove", Settings.getLastProfile().getName()), MessageBox.YES_NO_OPTION) == MessageBox.NO_OPTION) refreshVersions();
return; }//GEN-LAST:event_btnRefreshVersionsActionPerformed
Settings.delProfile(Settings.getLastProfile());
}//GEN-LAST:event_btnRemoveProfileActionPerformed private void btnModifyMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnModifyMouseClicked
ppmManage.show(evt.getComponent(), evt.getPoint().x, evt.getPoint().y);
}//GEN-LAST:event_btnModifyMouseClicked
private void cboVersionsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboVersionsItemStateChanged private void cboVersionsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboVersionsItemStateChanged
if (isLoading || evt.getStateChange() != ItemEvent.SELECTED || cboVersions.getSelectedIndex() < 0 || StrUtils.isBlank((String) cboVersions.getSelectedItem())) if (isLoading || evt.getStateChange() != ItemEvent.SELECTED || cboVersions.getSelectedIndex() < 0 || StrUtils.isBlank((String) cboVersions.getSelectedItem()))
@@ -969,50 +1011,98 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
Settings.getLastProfile().setSelectedMinecraftVersion((String) cboVersions.getSelectedItem()); Settings.getLastProfile().setSelectedMinecraftVersion((String) cboVersions.getSelectedItem());
}//GEN-LAST:event_cboVersionsItemStateChanged }//GEN-LAST:event_cboVersionsItemStateChanged
private void btnRefreshVersionsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshVersionsActionPerformed // <editor-fold defaultstate="collapsed" desc="UI Events">
refreshVersions(); private void cboProfilesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboProfilesItemStateChanged
}//GEN-LAST:event_btnRefreshVersionsActionPerformed if (!isLoading)
Settings.getInstance().setLast((String) cboProfiles.getSelectedItem());
}//GEN-LAST:event_cboProfilesItemStateChanged
private void btnExploreMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnExploreMouseClicked private void lblModInfoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblModInfoMouseClicked
ppmExplore.show(evt.getComponent(), evt.getPoint().x, evt.getPoint().y); int idx = lstExternalMods.getSelectedRow();
}//GEN-LAST:event_btnExploreMouseClicked if (idx > 0 && idx < Settings.getLastProfile().service().mod().getMods(Settings.getLastProfile().getSelectedVersion()).size())
SwingUtils.openLink(Settings.getLastProfile().service().mod().getMods(Settings.getLastProfile().getSelectedVersion()).get(idx).url);
}//GEN-LAST:event_lblModInfoMouseClicked
private void btnModifyMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnModifyMouseClicked private void btnRemoveModActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveModActionPerformed
ppmManage.show(evt.getComponent(), evt.getPoint().x, evt.getPoint().y); Settings.getLastProfile().service().mod().removeMod(Settings.getLastProfile().getSelectedVersion(), SwingUtils.getValueBySelectedRow(lstExternalMods, lstExternalMods.getSelectedRows(), 1));
}//GEN-LAST:event_btnModifyMouseClicked reloadMods();
}//GEN-LAST:event_btnRemoveModActionPerformed
private void btnDownloadAllAssetsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadAllAssetsActionPerformed private void btnAddModActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddModActionPerformed
if (mcVersion != null) JSystemFileChooser fc = new JSystemFileChooser();
TaskWindow.execute(Settings.getLastProfile().service().asset().downloadAssets(mcVersion)); fc.setFileSelectionMode(JSystemFileChooser.FILES_ONLY);
}//GEN-LAST:event_btnDownloadAllAssetsActionPerformed fc.setDialogTitle(C.i18n("mods.choose_mod"));
fc.setMultiSelectionEnabled(true);
private void txtGameDirFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtGameDirFocusLost if (fc.showOpenDialog(this) != JSystemFileChooser.APPROVE_OPTION)
Settings.getLastProfile().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; return;
JFileChooser fc = new JFileChooser(); boolean flag = true;
fc.setFileSelectionMode(JFileChooser.FILES_ONLY); for (File f : fc.getSelectedFiles())
fc.setDialogTitle(C.i18n("settings.choose_javapath")); flag &= Settings.getLastProfile().service().mod().addMod(Settings.getLastProfile().getSelectedVersion(), f);
reloadMods();
if (!flag)
MessageBox.show(C.i18n("mods.failed"));
}//GEN-LAST:event_btnAddModActionPerformed
private void lstExternalModsKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_lstExternalModsKeyPressed
if (evt.getKeyCode() == KeyEvent.VK_DELETE)
btnRemoveModActionPerformed(null);
}//GEN-LAST:event_lstExternalModsKeyPressed
private void chkDontCheckGameItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkDontCheckGameItemStateChanged
if (!isLoading)
Settings.getLastProfile().getSelectedVersionSetting().setNotCheckGame(chkDontCheckGame.isSelected());
}//GEN-LAST:event_chkDontCheckGameItemStateChanged
private void txtWrapperLauncherFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtWrapperLauncherFocusLost
Settings.getLastProfile().getSelectedVersionSetting().setWrapper(txtWrapperLauncher.getText());
}//GEN-LAST:event_txtWrapperLauncherFocusLost
private void txtServerIPFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtServerIPFocusLost
Settings.getLastProfile().getSelectedVersionSetting().setServerIp(txtServerIP.getText());
}//GEN-LAST:event_txtServerIPFocusLost
private void txtPrecalledCommandFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPrecalledCommandFocusLost
Settings.getLastProfile().getSelectedVersionSetting().setPrecalledCommand(txtPrecalledCommand.getText());
}//GEN-LAST:event_txtPrecalledCommandFocusLost
private void chkNoJVMArgsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkNoJVMArgsItemStateChanged
if (!isLoading)
Settings.getLastProfile().getSelectedVersionSetting().setNoJVMArgs(chkNoJVMArgs.isSelected());
}//GEN-LAST:event_chkNoJVMArgsItemStateChanged
private void txtPermSizeFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPermSizeFocusLost
Settings.getLastProfile().getSelectedVersionSetting().setPermSize(txtPermSize.getText());
}//GEN-LAST:event_txtPermSizeFocusLost
private void txtMinecraftArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMinecraftArgsFocusLost
Settings.getLastProfile().getSelectedVersionSetting().setMinecraftArgs(txtMinecraftArgs.getText());
}//GEN-LAST:event_txtMinecraftArgsFocusLost
private void txtJavaArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtJavaArgsFocusLost
Settings.getLastProfile().getSelectedVersionSetting().setJavaArgs(txtJavaArgs.getText());
}//GEN-LAST:event_txtJavaArgsFocusLost
private void btnCleanGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCleanGameActionPerformed
Settings.getLastProfile().service().version().cleanFolder();
}//GEN-LAST:event_btnCleanGameActionPerformed
private void btnChoosingGameDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChoosingGameDirActionPerformed
JSystemFileChooser fc = new JSystemFileChooser();
fc.setFileSelectionMode(JSystemFileChooser.DIRECTORIES_ONLY);
fc.setDialogTitle(C.i18n("settings.choose_gamedir"));
fc.setMultiSelectionEnabled(false); fc.setMultiSelectionEnabled(false);
fc.setFileFilter(new FileNameFilter("javaw.exe"));
fc.addChoosableFileFilter(new FileNameFilter("java.exe"));
fc.addChoosableFileFilter(new FileNameFilter("java"));
fc.showOpenDialog(this); fc.showOpenDialog(this);
if (fc.getSelectedFile() == null) if (fc.getSelectedFile() == null)
return; return;
try { try {
String path = fc.getSelectedFile().getCanonicalPath(); String path = fc.getSelectedFile().getCanonicalPath();
txtJavaDir.setText(path); txtGameDir.setText(path);
Settings.getLastProfile().getSelectedVersionSetting().setJavaDir(txtJavaDir.getText()); Settings.getLastProfile().setGameDir(path);
} catch (IOException e) { } catch (IOException e) {
HMCLog.warn("Failed to set java path.", e); HMCLog.warn("Failed to set game dir.", e);
MessageBox.Show(C.i18n("ui.label.failed_set") + e.getMessage()); MessageBox.show(C.i18n("ui.label.failed_set") + e.getMessage());
} }
}//GEN-LAST:event_btnChoosingJavaDirActionPerformed }//GEN-LAST:event_btnChoosingGameDirActionPerformed
private void cboJavaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboJavaItemStateChanged private void cboJavaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboJavaItemStateChanged
if (evt.getStateChange() != ItemEvent.SELECTED || cboJava.getSelectedIndex() < 0 || StrUtils.isBlank((String) cboJava.getSelectedItem())) if (evt.getStateChange() != ItemEvent.SELECTED || cboJava.getSelectedIndex() < 0 || StrUtils.isBlank((String) cboJava.getSelectedItem()))
@@ -1027,87 +1117,28 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
} }
}//GEN-LAST:event_cboJavaItemStateChanged }//GEN-LAST:event_cboJavaItemStateChanged
private void btnAddModActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddModActionPerformed private void btnChoosingJavaDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChoosingJavaDirActionPerformed
JFileChooser fc = new JFileChooser(); if (cboJava.getSelectedIndex() != 1)
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setDialogTitle(C.i18n("mods.choose_mod"));
fc.setMultiSelectionEnabled(true);
if (fc.showOpenDialog(this) != JFileChooser.APPROVE_OPTION)
return; return;
boolean flag = true; JSystemFileChooser fc = new JSystemFileChooser();
for (File f : fc.getSelectedFiles()) fc.setFileSelectionMode(JSystemFileChooser.FILES_ONLY);
flag &= Settings.getLastProfile().service().mod().addMod(Settings.getLastProfile().getSelectedVersion(), f); fc.setDialogTitle(C.i18n("settings.choose_javapath"));
reloadMods();
if (!flag)
MessageBox.Show(C.i18n("mods.failed"));
}//GEN-LAST:event_btnAddModActionPerformed
private void btnRemoveModActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveModActionPerformed
Settings.getLastProfile().service().mod().removeMod(Settings.getLastProfile().getSelectedVersion(), SwingUtils.getValueBySelectedRow(lstExternalMods, lstExternalMods.getSelectedRows(), 1));
reloadMods();
}//GEN-LAST:event_btnRemoveModActionPerformed
private void lstExternalModsKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_lstExternalModsKeyPressed
if (evt.getKeyCode() == KeyEvent.VK_DELETE)
btnRemoveModActionPerformed(null);
}//GEN-LAST:event_lstExternalModsKeyPressed
private void lblModInfoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblModInfoMouseClicked
int idx = lstExternalMods.getSelectedRow();
if (idx > 0 && idx < Settings.getLastProfile().service().mod().getMods(Settings.getLastProfile().getSelectedVersion()).size())
SwingUtils.openLink(Settings.getLastProfile().service().mod().getMods(Settings.getLastProfile().getSelectedVersion()).get(idx).url);
}//GEN-LAST:event_lblModInfoMouseClicked
private void btnChoosingGameDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChoosingGameDirActionPerformed
JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.setDialogTitle(C.i18n("settings.choose_gamedir"));
fc.setMultiSelectionEnabled(false); fc.setMultiSelectionEnabled(false);
fc.setFileFilter(new FileNameFilter("javaw.exe"));
fc.addChoosableFileFilter(new FileNameFilter("java.exe"));
fc.addChoosableFileFilter(new FileNameFilter("java"));
fc.showOpenDialog(this); fc.showOpenDialog(this);
if (fc.getSelectedFile() == null) if (fc.getSelectedFile() == null)
return; return;
try { try {
String path = fc.getSelectedFile().getCanonicalPath(); String path = fc.getSelectedFile().getCanonicalPath();
txtGameDir.setText(path); txtJavaDir.setText(path);
Settings.getLastProfile().setGameDir(path); Settings.getLastProfile().getSelectedVersionSetting().setJavaDir(txtJavaDir.getText());
} catch (IOException e) { } catch (IOException e) {
HMCLog.warn("Failed to set game dir.", e); HMCLog.warn("Failed to set java path.", e);
MessageBox.Show(C.i18n("ui.label.failed_set") + e.getMessage()); MessageBox.show(C.i18n("ui.label.failed_set") + e.getMessage());
} }
}//GEN-LAST:event_btnChoosingGameDirActionPerformed }//GEN-LAST:event_btnChoosingJavaDirActionPerformed
private void btnCleanGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCleanGameActionPerformed
Settings.getLastProfile().service().version().cleanFolder();
}//GEN-LAST:event_btnCleanGameActionPerformed
private void btnTestGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTestGameActionPerformed
LogWindow.INSTANCE.setVisible(true);
MainFrame.INSTANCE.daemon.runGame(Settings.getLastProfile());
}//GEN-LAST:event_btnTestGameActionPerformed
private void btnShowLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShowLogActionPerformed
LogWindow.INSTANCE.setVisible(true);
}//GEN-LAST:event_btnShowLogActionPerformed
private void btnMakeLaunchScriptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMakeLaunchScriptActionPerformed
MainFrame.INSTANCE.daemon.makeLaunchScript(Settings.getLastProfile());
}//GEN-LAST:event_btnMakeLaunchScriptActionPerformed
private void btnIncludeMinecraftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIncludeMinecraftActionPerformed
JFileChooser fc = new JFileChooser(new File("."));
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
File newGameDir = fc.getSelectedFile();
String name = JOptionPane.showInputDialog(C.i18n("setupwindow.give_a_name"));
if (StrUtils.isBlank(name)) {
MessageBox.Show(C.i18n("setupwindow.no_empty_name"));
return;
}
Settings.putProfile(new Profile(name).setGameDir(newGameDir.getAbsolutePath()));
MessageBox.Show(C.i18n("setupwindow.find_in_configurations"));
loadProfiles();
}
}//GEN-LAST:event_btnIncludeMinecraftActionPerformed
private void cboRunDirectoryItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboRunDirectoryItemStateChanged private void cboRunDirectoryItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboRunDirectoryItemStateChanged
if (!isLoading && cboRunDirectory.getSelectedIndex() >= 0) if (!isLoading && cboRunDirectory.getSelectedIndex() >= 0)
@@ -1119,60 +1150,41 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
Settings.getLastProfile().getSelectedVersionSetting().setLauncherVisibility(LauncherVisibility.values()[cboLauncherVisibility.getSelectedIndex()]); Settings.getLastProfile().getSelectedVersionSetting().setLauncherVisibility(LauncherVisibility.values()[cboLauncherVisibility.getSelectedIndex()]);
}//GEN-LAST:event_cboLauncherVisibilityItemStateChanged }//GEN-LAST:event_cboLauncherVisibilityItemStateChanged
private void chkFullscreenItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkFullscreenItemStateChanged private void btnDownloadAllAssetsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadAllAssetsActionPerformed
if (!isLoading) if (mcVersion != null)
Settings.getLastProfile().getSelectedVersionSetting().setFullscreen(chkFullscreen.isSelected()); try {
}//GEN-LAST:event_chkFullscreenItemStateChanged TaskWindow.factory().execute(Settings.getLastProfile().service().asset().downloadAssets(mcVersion));
} catch (GameException ex) {
private void chkNoJVMArgsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkNoJVMArgsItemStateChanged HMCLog.err("Failed to download assets", ex);
if (!isLoading) MessageBox.showLocalized("assets.failed_download");
Settings.getLastProfile().getSelectedVersionSetting().setNoJVMArgs(chkNoJVMArgs.isSelected()); }
}//GEN-LAST:event_chkNoJVMArgsItemStateChanged }//GEN-LAST:event_btnDownloadAllAssetsActionPerformed
private void txtMaxMemoryFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMaxMemoryFocusLost private void txtMaxMemoryFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMaxMemoryFocusLost
Settings.getLastProfile().getSelectedVersionSetting().setMaxMemory(txtMaxMemory.getText()); Settings.getLastProfile().getSelectedVersionSetting().setMaxMemory(txtMaxMemory.getText());
}//GEN-LAST:event_txtMaxMemoryFocusLost }//GEN-LAST:event_txtMaxMemoryFocusLost
private void txtWidthFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtWidthFocusLost private void txtJavaDirFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtJavaDirFocusLost
Settings.getLastProfile().getSelectedVersionSetting().setWidth(txtWidth.getText()); Settings.getLastProfile().getSelectedVersionSetting().setJavaDir(txtJavaDir.getText());
}//GEN-LAST:event_txtWidthFocusLost }//GEN-LAST:event_txtJavaDirFocusLost
private void chkFullscreenItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkFullscreenItemStateChanged
if (!isLoading)
Settings.getLastProfile().getSelectedVersionSetting().setFullscreen(chkFullscreen.isSelected());
}//GEN-LAST:event_chkFullscreenItemStateChanged
private void txtHeightFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtHeightFocusLost private void txtHeightFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtHeightFocusLost
Settings.getLastProfile().getSelectedVersionSetting().setHeight(txtHeight.getText()); Settings.getLastProfile().getSelectedVersionSetting().setHeight(txtHeight.getText());
}//GEN-LAST:event_txtHeightFocusLost }//GEN-LAST:event_txtHeightFocusLost
private void txtJavaDirFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtJavaDirFocusLost private void txtWidthFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtWidthFocusLost
Settings.getLastProfile().getSelectedVersionSetting().setJavaDir(txtJavaDir.getText()); Settings.getLastProfile().getSelectedVersionSetting().setWidth(txtWidth.getText());
}//GEN-LAST:event_txtJavaDirFocusLost }//GEN-LAST:event_txtWidthFocusLost
private void txtJavaArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtJavaArgsFocusLost private void txtGameDirFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtGameDirFocusLost
Settings.getLastProfile().getSelectedVersionSetting().setJavaArgs(txtJavaArgs.getText()); Settings.getLastProfile().setGameDir(txtGameDir.getText());
}//GEN-LAST:event_txtJavaArgsFocusLost loadVersions();
}//GEN-LAST:event_txtGameDirFocusLost
private void txtMinecraftArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMinecraftArgsFocusLost
Settings.getLastProfile().getSelectedVersionSetting().setMinecraftArgs(txtMinecraftArgs.getText());
}//GEN-LAST:event_txtMinecraftArgsFocusLost
private void txtPermSizeFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPermSizeFocusLost
Settings.getLastProfile().getSelectedVersionSetting().setPermSize(txtPermSize.getText());
}//GEN-LAST:event_txtPermSizeFocusLost
private void txtPrecalledCommandFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPrecalledCommandFocusLost
Settings.getLastProfile().getSelectedVersionSetting().setPrecalledCommand(txtPrecalledCommand.getText());
}//GEN-LAST:event_txtPrecalledCommandFocusLost
private void txtServerIPFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtServerIPFocusLost
Settings.getLastProfile().getSelectedVersionSetting().setServerIp(txtServerIP.getText());
}//GEN-LAST:event_txtServerIPFocusLost
private void txtWrapperLauncherFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtWrapperLauncherFocusLost
Settings.getLastProfile().getSelectedVersionSetting().setWrapper(txtWrapperLauncher.getText());
}//GEN-LAST:event_txtWrapperLauncherFocusLost
private void chkDontCheckGameItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkDontCheckGameItemStateChanged
if (!isLoading)
Settings.getLastProfile().getSelectedVersionSetting().setNotCheckGame(chkDontCheckGame.isSelected());
}//GEN-LAST:event_chkDontCheckGameItemStateChanged
// </editor-fold> // </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Load"> // <editor-fold defaultstate="collapsed" desc="Load">
@@ -1224,7 +1236,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
List<File> files = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor); List<File> files = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
for (File file : files) for (File file : files)
Settings.getLastProfile().service().mod().addMod(Settings.getLastProfile().getSelectedVersion(), file); Settings.getLastProfile().service().mod().addMod(Settings.getLastProfile().getSelectedVersion(), file);
} catch (Exception ex) { } catch (UnsupportedFlavorException | IOException ex) {
HMCLog.warn("Failed to drop file.", ex); HMCLog.warn("Failed to drop file.", ex);
} }
} }
@@ -1260,12 +1272,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
return; return;
reloadingMods = true; reloadingMods = true;
DefaultTableModel model = SwingUtils.clearDefaultTable(lstExternalMods); DefaultTableModel model = SwingUtils.clearDefaultTable(lstExternalMods);
new OverridableSwingWorker<List<ModInfo>>() { new OverridableSwingWorkerImpl().reg(t -> {
@Override
protected void work() throws Exception {
publish(Settings.getLastProfile().service().mod().recacheMods(Settings.getLastProfile().getSelectedVersion()));
}
}.reg(t -> {
synchronized (modLock) { synchronized (modLock) {
for (ModInfo x : t) for (ModInfo x : t)
model.addRow(new Object[] { x.isActive(), x, x.version }); model.addRow(new Object[] { x.isActive(), x, x.version });
@@ -1275,6 +1282,14 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
} }
} }
private static class OverridableSwingWorkerImpl extends AbstractSwingWorker<List<ModInfo>> {
@Override
protected void work() throws Exception {
publish(Settings.getLastProfile().service().mod().recacheMods(Settings.getLastProfile().getSelectedVersion()));
}
}
// </editor-fold> // </editor-fold>
void save() { void save() {
VersionSetting vs = Settings.getLastProfile().getSelectedVersionSetting(); VersionSetting vs = Settings.getLastProfile().getSelectedVersionSetting();
@@ -1306,6 +1321,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
Settings.onProfileLoading(); Settings.onProfileLoading();
} }
@Override
public void onLeave() { public void onLeave() {
super.onLeave(); super.onLeave();
save(); save();
@@ -1394,7 +1410,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
private void loadProfiles() { private void loadProfiles() {
isLoading = true; isLoading = true;
DefaultComboBoxModel model = new DefaultComboBoxModel(); DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
for (Profile s : Settings.getProfilesFiltered()) for (Profile s : Settings.getProfilesFiltered())
model.addElement(s.getName()); model.addElement(s.getName());
cboProfiles.setModel(model); cboProfiles.setModel(model);
@@ -1407,7 +1423,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
}; };
void loadVersions() { void loadVersions() {
DefaultComboBoxModel model = new DefaultComboBoxModel(); DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
for (MinecraftVersion each : Settings.getLastProfile().service().version().getVersions()) { for (MinecraftVersion each : Settings.getLastProfile().service().version().getVersions()) {
if (each.hidden) if (each.hidden)
continue; continue;
@@ -1422,7 +1438,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
public void versionChanged(String version) { public void versionChanged(String version) {
isLoading = true; isLoading = true;
DefaultComboBoxModel model = (DefaultComboBoxModel) cboVersions.getModel(); DefaultComboBoxModel<String> model = (DefaultComboBoxModel<String>) cboVersions.getModel();
for (int i = 0; i < model.getSize(); ++i) for (int i = 0; i < model.getSize(); ++i)
if (model.getElementAt(i).equals(version)) { if (model.getElementAt(i).equals(version)) {
model.setSelectedItem(version); model.setSelectedItem(version);
@@ -1446,7 +1462,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
txtGameDir.setText(t.getGameDir()); txtGameDir.setText(t.getGameDir());
isLoading = true; isLoading = true;
DefaultComboBoxModel model = (DefaultComboBoxModel) cboProfiles.getModel(); DefaultComboBoxModel<String> model = (DefaultComboBoxModel<String>) cboProfiles.getModel();
for (int i = 0; i < model.getSize(); ++i) for (int i = 0; i < model.getSize(); ++i)
if (model.getElementAt(i).equals(t.getName())) { if (model.getElementAt(i).equals(t.getName())) {
model.setSelectedItem(t.getName()); model.setSelectedItem(t.getName());

View File

@@ -68,10 +68,6 @@ public class HeaderTab extends JLabel
return this.model.getActionListeners(); return this.model.getActionListeners();
} }
public void removeActionListener(ActionListener listener) {
this.model.removeActionListener(listener);
}
public void setActionCommand(String command) { public void setActionCommand(String command) {
this.model.setActionCommand(command); this.model.setActionCommand(command);
} }

View File

@@ -24,24 +24,25 @@ import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.launcher.setting.Settings; 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.task.TaskRunnable;
import org.jackhuang.hellominecraft.util.tasks.TaskWindow; import org.jackhuang.hellominecraft.util.task.TaskWindow;
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.task.Task;
import org.jackhuang.hellominecraft.util.ui.SwingUtils; import org.jackhuang.hellominecraft.util.ui.SwingUtils;
/** /**
* *
* @author huangyuhui * @author huangyuhui
*/ */
public class InstallerPanel extends AnimatedPanel { public class InstallerPanel extends Page {
GameSettingsPanel gsp; GameSettingsPanel gsp;
/** /**
* Creates new form InstallerPanel * Creates new form InstallerPanel
* *
* @param gsp To get the minecraft version * @param gsp To get the minecraft version
* @param installerType load which installer * @param installerType load which installer
*/ */
public InstallerPanel(GameSettingsPanel gsp, InstallerType installerType) { public InstallerPanel(GameSettingsPanel gsp, InstallerType installerType) {
@@ -113,16 +114,19 @@ public class InstallerPanel extends AnimatedPanel {
}//GEN-LAST:event_btnInstallActionPerformed }//GEN-LAST:event_btnInstallActionPerformed
private void btnRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshActionPerformed private void btnRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshActionPerformed
refreshVersions(); TaskWindow.factory().execute(refreshVersionsTask());
}//GEN-LAST:event_btnRefreshActionPerformed }//GEN-LAST:event_btnRefreshActionPerformed
transient List<InstallerVersionList.InstallerVersion> versions; transient List<InstallerVersionList.InstallerVersion> versions;
transient InstallerVersionList list; InstallerVersionList list;
InstallerType id; InstallerType id;
void refreshVersions() { Task refreshVersionsTask() {
if (TaskWindow.execute(list.refresh(new String[] { gsp.getMinecraftVersionFormatted() }))) Task t = list.refresh(new String[] { gsp.getMinecraftVersionFormatted() });
loadVersions(); if (t != null)
return t.with(new TaskRunnable(this::loadVersions));
else
return null;
} }
public synchronized InstallerVersionList.InstallerVersion getVersion(int idx) { public synchronized InstallerVersionList.InstallerVersion getVersion(int idx) {
@@ -132,11 +136,13 @@ public class InstallerPanel extends AnimatedPanel {
synchronized void downloadSelectedRow() { synchronized void downloadSelectedRow() {
int idx = lstInstallers.getSelectedRow(); int idx = lstInstallers.getSelectedRow();
if (versions == null || idx < 0 || idx >= versions.size()) { if (versions == null || idx < 0 || idx >= versions.size()) {
MessageBox.Show(C.i18n("install.not_refreshed")); MessageBox.show(C.i18n("install.not_refreshed"));
return; return;
} }
TaskWindow.execute(Settings.getLastProfile().service().install().download(Settings.getLastProfile().getSelectedVersion(), getVersion(idx), id), TaskWindow.factory()
new TaskRunnable(this::refreshVersions)); .append(Settings.getLastProfile().service().install().download(Settings.getLastProfile().getSelectedVersion(), getVersion(idx), id))
.append(refreshVersionsTask())
.execute();
} }
public void loadVersions() { public void loadVersions() {
@@ -159,7 +165,7 @@ public class InstallerPanel extends AnimatedPanel {
@Override @Override
public void onSelect() { public void onSelect() {
if (!refreshed) { if (!refreshed) {
refreshVersions(); TaskWindow.factory().execute(refreshVersionsTask());
refreshed = true; refreshed = true;
} }
} }

View File

@@ -19,18 +19,6 @@
<Group type="102" attributes="0"> <Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="chkEnableShadow" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="chkEnableAnimation" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="btnCheckUpdate" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnMCBBS" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="chkDecorated" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<Component id="lblProxy" min="-2" max="-2" attributes="0"/> <Component id="lblProxy" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/> <EmptySpace max="32767" attributes="0"/>
@@ -71,9 +59,20 @@
</Group> </Group>
<Group type="102" attributes="0"> <Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="btnCheckUpdate" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnMCBBS" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="lblAbout" min="-2" max="-2" attributes="0"/> <Component id="lblAbout" min="-2" max="-2" attributes="0"/>
<Component id="lblModpack" alignment="0" min="-2" max="-2" attributes="0"/> <Component id="lblModpack" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lblRestart" alignment="0" min="-2" max="-2" attributes="0"/> <Component id="lblRestart" alignment="0" min="-2" max="-2" attributes="0"/>
<Group type="102" attributes="0">
<Component id="chkEnableShadow" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="chkEnableBlur" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="chkDecorated" alignment="0" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/> <EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group> </Group>
@@ -121,17 +120,18 @@
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0"> <Group type="103" groupAlignment="3" attributes="0">
<Component id="chkEnableShadow" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="chkEnableShadow" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="chkEnableAnimation" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="chkEnableBlur" alignment="3" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="chkDecorated" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="6" max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0"> <Group type="103" groupAlignment="3" attributes="0">
<Component id="btnCheckUpdate" alignment="3" min="-2" pref="26" max="-2" attributes="0"/> <Component id="btnCheckUpdate" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
<Component id="chkDecorated" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnMCBBS" alignment="3" max="32767" attributes="0"/>
<Component id="btnMCBBS" alignment="3" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="lblRestart" min="-2" max="-2" attributes="0"/> <Component id="lblRestart" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="65" max="32767" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="lblModpack" min="-2" max="-2" attributes="0"/> <Component id="lblModpack" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="lblAbout" min="-2" max="-2" attributes="0"/> <Component id="lblAbout" min="-2" max="-2" attributes="0"/>
@@ -157,12 +157,9 @@
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="launcher.about" replaceFormat="C.i18n(&quot;{key}&quot;)"/> <ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="launcher.about" replaceFormat="C.i18n(&quot;{key}&quot;)"/>
</Property> </Property>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor"> <Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="&#x624b;&#x578b;&#x5149;&#x6807;"/> <Color id="&#x9ed8;&#x8ba4;&#x5149;&#x6807;"/>
</Property> </Property>
</Properties> </Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="lblAboutMouseClicked"/>
</Events>
</Component> </Component>
<Component class="javax.swing.JButton" name="btnSelBackgroundPath"> <Component class="javax.swing.JButton" name="btnSelBackgroundPath">
<Properties> <Properties>
@@ -291,16 +288,6 @@
</Property> </Property>
</Properties> </Properties>
</Component> </Component>
<Component class="javax.swing.JCheckBox" name="chkEnableAnimation">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="launcher.enable_animation" replaceFormat="C.i18n(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="chkEnableAnimationItemStateChanged"/>
</Events>
</Component>
<Component class="javax.swing.JCheckBox" name="chkDecorated"> <Component class="javax.swing.JCheckBox" name="chkDecorated">
<Properties> <Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
@@ -357,5 +344,15 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnMCBBSActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnMCBBSActionPerformed"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JCheckBox" name="chkEnableBlur">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="launcher.enable_blur" replaceFormat="C.i18n(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="chkEnableBlurItemStateChanged"/>
</Events>
</Component>
</SubComponents> </SubComponents>
</Form> </Form>

View File

@@ -17,41 +17,44 @@
*/ */
package org.jackhuang.hellominecraft.launcher.ui; package org.jackhuang.hellominecraft.launcher.ui;
import java.awt.Color;
import java.io.IOException; import java.io.IOException;
import javax.swing.DefaultComboBoxModel; import javax.swing.DefaultComboBoxModel;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.filechooser.FileNameExtensionFilter;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.launcher.setting.Settings; import org.jackhuang.hellominecraft.launcher.setting.Settings;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType; import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
import org.jackhuang.hellominecraft.util.system.IOUtils; import org.jackhuang.hellominecraft.util.sys.IOUtils;
import org.jackhuang.hellominecraft.util.MessageBox; import org.jackhuang.hellominecraft.util.MessageBox;
import org.jackhuang.hellominecraft.util.lang.SupportedLocales; import org.jackhuang.hellominecraft.util.lang.SupportedLocales;
import org.jackhuang.hellominecraft.util.ui.GraphicsUtils;
import org.jackhuang.hellominecraft.util.ui.JSystemFileChooser;
import org.jackhuang.hellominecraft.util.ui.SwingUtils; import org.jackhuang.hellominecraft.util.ui.SwingUtils;
/** /**
* *
* @author huangyuhui * @author huangyuhui
*/ */
public class LauncherSettingsPanel extends AnimatedPanel { public class LauncherSettingsPanel extends RepaintPage {
/** /**
* Creates new form LancherSettingsPanel * Creates new form LancherSettingsPanel
*/ */
public LauncherSettingsPanel() { public LauncherSettingsPanel() {
setRepainter(this);
} }
void initGui() { void initGui() {
initComponents(); initComponents();
setBackground(GraphicsUtils.getWebColorWithAlpha("FFFFFF7F"));
setOpaque(true);
DefaultComboBoxModel d = new DefaultComboBoxModel(); DefaultComboBoxModel<String> d = new DefaultComboBoxModel<>();
for (DownloadType type : DownloadType.values()) for (DownloadType type : DownloadType.values())
d.addElement(type.getName()); d.addElement(type.getName());
cboDownloadSource.setModel(d); cboDownloadSource.setModel(d);
d = new DefaultComboBoxModel(); d = new DefaultComboBoxModel<>();
int id = 0; int id = 0;
for (SupportedLocales type : SupportedLocales.values()) { for (SupportedLocales type : SupportedLocales.values()) {
d.addElement(type.showString()); d.addElement(type.showString());
@@ -69,11 +72,8 @@ public class LauncherSettingsPanel extends AnimatedPanel {
cboDownloadSource.setSelectedIndex(Settings.getInstance().getDownloadType()); cboDownloadSource.setSelectedIndex(Settings.getInstance().getDownloadType());
cboTheme.setSelectedIndex(Settings.getInstance().getTheme().ordinal()); cboTheme.setSelectedIndex(Settings.getInstance().getTheme().ordinal());
chkEnableShadow.setSelected(Settings.getInstance().isEnableShadow()); chkEnableShadow.setSelected(Settings.getInstance().isEnableShadow());
chkEnableAnimation.setSelected(Settings.getInstance().isEnableAnimation()); chkEnableBlur.setSelected(Settings.getInstance().isEnableBlur());
chkDecorated.setSelected(Settings.getInstance().isDecorated()); chkDecorated.setSelected(Settings.getInstance().isDecorated());
setBackground(Color.white);
setOpaque(true);
} }
@Override @Override
@@ -110,13 +110,13 @@ public class LauncherSettingsPanel extends AnimatedPanel {
txtProxyUsername = new javax.swing.JTextField(); txtProxyUsername = new javax.swing.JTextField();
txtProxyPassword = new javax.swing.JTextField(); txtProxyPassword = new javax.swing.JTextField();
lblProxyPassword = new javax.swing.JLabel(); lblProxyPassword = new javax.swing.JLabel();
chkEnableAnimation = new javax.swing.JCheckBox();
chkDecorated = new javax.swing.JCheckBox(); chkDecorated = new javax.swing.JCheckBox();
lblModpack = new javax.swing.JLabel(); lblModpack = new javax.swing.JLabel();
cboLang = new javax.swing.JComboBox(); cboLang = new javax.swing.JComboBox();
lblLang = new javax.swing.JLabel(); lblLang = new javax.swing.JLabel();
lblRestart = new javax.swing.JLabel(); lblRestart = new javax.swing.JLabel();
btnMCBBS = new javax.swing.JButton(); btnMCBBS = new javax.swing.JButton();
chkEnableBlur = new javax.swing.JCheckBox();
cboDownloadSource.addItemListener(new java.awt.event.ItemListener() { cboDownloadSource.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) { public void itemStateChanged(java.awt.event.ItemEvent evt) {
@@ -125,12 +125,7 @@ public class LauncherSettingsPanel extends AnimatedPanel {
}); });
lblAbout.setText(C.i18n("launcher.about")); // NOI18N lblAbout.setText(C.i18n("launcher.about")); // NOI18N
lblAbout.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); lblAbout.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
lblAbout.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
lblAboutMouseClicked(evt);
}
});
btnSelBackgroundPath.setText(C.i18n("ui.button.explore")); // NOI18N btnSelBackgroundPath.setText(C.i18n("ui.button.explore")); // NOI18N
btnSelBackgroundPath.addActionListener(new java.awt.event.ActionListener() { btnSelBackgroundPath.addActionListener(new java.awt.event.ActionListener() {
@@ -208,13 +203,6 @@ public class LauncherSettingsPanel extends AnimatedPanel {
lblProxyPassword.setText(C.i18n("proxy.password")); // NOI18N lblProxyPassword.setText(C.i18n("proxy.password")); // NOI18N
chkEnableAnimation.setText(C.i18n("launcher.enable_animation")); // NOI18N
chkEnableAnimation.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
chkEnableAnimationItemStateChanged(evt);
}
});
chkDecorated.setText(C.i18n("launcher.decorated")); // NOI18N chkDecorated.setText(C.i18n("launcher.decorated")); // NOI18N
chkDecorated.addItemListener(new java.awt.event.ItemListener() { chkDecorated.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) { public void itemStateChanged(java.awt.event.ItemEvent evt) {
@@ -249,6 +237,13 @@ public class LauncherSettingsPanel extends AnimatedPanel {
} }
}); });
chkEnableBlur.setText(C.i18n("launcher.enable_blur")); // NOI18N
chkEnableBlur.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
chkEnableBlurItemStateChanged(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout); this.setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(
@@ -256,16 +251,6 @@ public class LauncherSettingsPanel extends AnimatedPanel {
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(chkEnableShadow)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(chkEnableAnimation))
.addGroup(layout.createSequentialGroup()
.addComponent(btnCheckUpdate)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnMCBBS)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(chkDecorated))
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(lblProxy) .addComponent(lblProxy)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
@@ -301,9 +286,18 @@ public class LauncherSettingsPanel extends AnimatedPanel {
.addComponent(cboTheme, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addComponent(cboTheme, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblAbout, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup()
.addComponent(lblModpack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnCheckUpdate)
.addComponent(lblRestart)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnMCBBS))
.addComponent(lblAbout)
.addComponent(lblModpack)
.addComponent(lblRestart)
.addGroup(layout.createSequentialGroup()
.addComponent(chkEnableShadow)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(chkEnableBlur))
.addComponent(chkDecorated))
.addGap(0, 0, Short.MAX_VALUE))) .addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap()) .addContainerGap())
); );
@@ -341,18 +335,19 @@ public class LauncherSettingsPanel extends AnimatedPanel {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(chkEnableShadow) .addComponent(chkEnableShadow)
.addComponent(chkEnableAnimation)) .addComponent(chkEnableBlur))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(chkDecorated)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnCheckUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnCheckUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(chkDecorated) .addComponent(btnMCBBS, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(btnMCBBS))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblRestart) .addComponent(lblRestart)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 65, Short.MAX_VALUE)
.addComponent(lblModpack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblAbout, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lblModpack)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblAbout)
.addContainerGap()) .addContainerGap())
); );
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
@@ -362,8 +357,8 @@ public class LauncherSettingsPanel extends AnimatedPanel {
}//GEN-LAST:event_cboDownloadSourceItemStateChanged }//GEN-LAST:event_cboDownloadSourceItemStateChanged
private void btnSelBackgroundPathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelBackgroundPathActionPerformed private void btnSelBackgroundPathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelBackgroundPathActionPerformed
JFileChooser fc = new JFileChooser(); JSystemFileChooser fc = new JSystemFileChooser();
fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setFileSelectionMode(JSystemFileChooser.FILES_ONLY);
fc.setDialogTitle(C.i18n("launcher.choose_bgpath")); fc.setDialogTitle(C.i18n("launcher.choose_bgpath"));
fc.setMultiSelectionEnabled(false); fc.setMultiSelectionEnabled(false);
fc.setFileFilter(new FileNameExtensionFilter("*.png", "png")); fc.setFileFilter(new FileNameExtensionFilter("*.png", "png"));
@@ -379,7 +374,7 @@ public class LauncherSettingsPanel extends AnimatedPanel {
MainFrame.INSTANCE.loadBackground(); MainFrame.INSTANCE.loadBackground();
} catch (IOException e) { } catch (IOException e) {
HMCLog.warn("Failed to set background path.", e); HMCLog.warn("Failed to set background path.", e);
MessageBox.Show(C.i18n("ui.label.failed_set") + e.getMessage()); MessageBox.show(C.i18n("ui.label.failed_set") + e.getMessage());
} }
}//GEN-LAST:event_btnSelBackgroundPathActionPerformed }//GEN-LAST:event_btnSelBackgroundPathActionPerformed
@@ -413,10 +408,6 @@ public class LauncherSettingsPanel extends AnimatedPanel {
Settings.getInstance().setDecorated(chkDecorated.isSelected()); Settings.getInstance().setDecorated(chkDecorated.isSelected());
}//GEN-LAST:event_chkDecoratedItemStateChanged }//GEN-LAST:event_chkDecoratedItemStateChanged
private void chkEnableAnimationItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkEnableAnimationItemStateChanged
Settings.getInstance().setEnableAnimation(chkEnableAnimation.isSelected());
}//GEN-LAST:event_chkEnableAnimationItemStateChanged
private void txtProxyHostFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtProxyHostFocusLost private void txtProxyHostFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtProxyHostFocusLost
Settings.getInstance().setProxyHost(txtProxyHost.getText()); Settings.getInstance().setProxyHost(txtProxyHost.getText());
}//GEN-LAST:event_txtProxyHostFocusLost }//GEN-LAST:event_txtProxyHostFocusLost
@@ -433,14 +424,14 @@ public class LauncherSettingsPanel extends AnimatedPanel {
Settings.getInstance().setProxyPassword(txtProxyPassword.getText()); Settings.getInstance().setProxyPassword(txtProxyPassword.getText());
}//GEN-LAST:event_txtProxyPasswordFocusLost }//GEN-LAST:event_txtProxyPasswordFocusLost
private void lblAboutMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblAboutMouseClicked
SwingUtils.openLink("http://huangyuhui.duapp.com/link.php?type=sponsor");
}//GEN-LAST:event_lblAboutMouseClicked
private void btnMCBBSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMCBBSActionPerformed private void btnMCBBSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMCBBSActionPerformed
SwingUtils.openLink(C.URL_PUBLISH); SwingUtils.openLink(C.URL_PUBLISH);
}//GEN-LAST:event_btnMCBBSActionPerformed }//GEN-LAST:event_btnMCBBSActionPerformed
private void chkEnableBlurItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkEnableBlurItemStateChanged
Settings.getInstance().setEnableBlur(chkEnableBlur.isSelected());
}//GEN-LAST:event_chkEnableBlurItemStateChanged
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCheckUpdate; private javax.swing.JButton btnCheckUpdate;
private javax.swing.JButton btnMCBBS; private javax.swing.JButton btnMCBBS;
@@ -449,7 +440,7 @@ public class LauncherSettingsPanel extends AnimatedPanel {
private javax.swing.JComboBox cboLang; private javax.swing.JComboBox cboLang;
private javax.swing.JComboBox cboTheme; private javax.swing.JComboBox cboTheme;
private javax.swing.JCheckBox chkDecorated; private javax.swing.JCheckBox chkDecorated;
private javax.swing.JCheckBox chkEnableAnimation; private javax.swing.JCheckBox chkEnableBlur;
private javax.swing.JCheckBox chkEnableShadow; private javax.swing.JCheckBox chkEnableShadow;
private javax.swing.JLabel lblAbout; private javax.swing.JLabel lblAbout;
private javax.swing.JLabel lblBackground; private javax.swing.JLabel lblBackground;

View File

@@ -31,11 +31,11 @@ import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.Event; import org.jackhuang.hellominecraft.util.Event;
import org.jackhuang.hellominecraft.util.MessageBox; import org.jackhuang.hellominecraft.util.MessageBox;
import org.jackhuang.hellominecraft.util.func.Consumer; import org.jackhuang.hellominecraft.util.func.Consumer;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.util.system.JavaProcessMonitor; import org.jackhuang.hellominecraft.util.sys.JavaProcessMonitor;
import org.jackhuang.hellominecraft.util.ui.LogWindow; import org.jackhuang.hellominecraft.util.ui.LogWindow;
import org.jackhuang.hellominecraft.util.ui.WebFrame; import org.jackhuang.hellominecraft.util.net.WebFrame;
/** /**
* *
@@ -110,19 +110,17 @@ public class LaunchingUIDaemon {
String msg = C.i18n("launch.exited_abnormally") + " exit code: " + t; String msg = C.i18n("launch.exited_abnormally") + " exit code: " + t;
if (errorText != null) if (errorText != null)
msg += ", advice: " + MinecraftCrashAdvicer.getAdvice(FileUtils.readQuietly(new File(errorText))); msg += ", advice: " + MinecraftCrashAdvicer.getAdvice(FileUtils.readQuietly(new File(errorText)));
MessageBox.Show(msg);
WebFrame f = new WebFrame(logs); WebFrame f = new WebFrame(logs);
f.setModal(true); f.setModal(true);
f.setTitle("Game output"); f.setTitle(msg);
f.setVisible(true); f.setVisible(true);
checkExit((LauncherVisibility) obj.getTag()); checkExit((LauncherVisibility) obj.getTag());
}); });
jpm.jvmLaunchFailedEvent.register(t -> { jpm.jvmLaunchFailedEvent.register(t -> {
HMCLog.err("Cannot create jvm, exit code: " + t); HMCLog.err("Cannot create jvm, exit code: " + t);
MessageBox.Show(C.i18n("launch.cannot_create_jvm") + " exit code: " + t);
WebFrame f = new WebFrame(jpm.getJavaProcess().getStdOutLines().toArray(new String[0])); WebFrame f = new WebFrame(jpm.getJavaProcess().getStdOutLines().toArray(new String[0]));
f.setModal(true); f.setModal(true);
f.setTitle("Game output"); f.setTitle(C.i18n("launch.cannot_create_jvm") + " exit code: " + t);
f.setVisible(true); f.setVisible(true);
checkExit((LauncherVisibility) obj.getTag()); checkExit((LauncherVisibility) obj.getTag());
}); });
@@ -138,10 +136,6 @@ public class LaunchingUIDaemon {
return true; return true;
}; };
private static void getCrashReport() {
}
private static void checkExit(LauncherVisibility v) { private static void checkExit(LauncherVisibility v) {
if (v != LauncherVisibility.KEEP && !LogWindow.INSTANCE.isVisible()) { if (v != LauncherVisibility.KEEP && !LogWindow.INSTANCE.isVisible()) {
HMCLog.log("Launcher will exit now."); HMCLog.log("Launcher will exit now.");
@@ -154,10 +148,10 @@ public class LaunchingUIDaemon {
try { try {
String s = JOptionPane.showInputDialog(C.i18n("mainwindow.enter_script_name")); String s = JOptionPane.showInputDialog(C.i18n("mainwindow.enter_script_name"));
if (s != null) if (s != null)
MessageBox.Show(C.i18n("mainwindow.make_launch_succeed") + " " + ((GameLauncher) sender).makeLauncher(s, str).getAbsolutePath()); MessageBox.show(C.i18n("mainwindow.make_launch_succeed") + " " + ((GameLauncher) sender).makeLauncher(s, str).getAbsolutePath());
flag = true; flag = true;
} catch (IOException ex) { } catch (IOException ex) {
MessageBox.Show(C.i18n("mainwindow.make_launch_script_failed")); MessageBox.show(C.i18n("mainwindow.make_launch_script_failed"));
HMCLog.err("Failed to create script file.", ex); HMCLog.err("Failed to create script file.", ex);
} }
MainFrame.INSTANCE.closeMessage(); MainFrame.INSTANCE.closeMessage();

View File

@@ -17,6 +17,8 @@
*/ */
package org.jackhuang.hellominecraft.launcher.ui; package org.jackhuang.hellominecraft.launcher.ui;
import org.jackhuang.hellominecraft.util.ui.GaussionPanel;
import org.jackhuang.hellominecraft.util.ui.IRepaint;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.CardLayout; import java.awt.CardLayout;
import java.awt.Color; import java.awt.Color;
@@ -25,7 +27,9 @@ import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.GridLayout; import java.awt.GridLayout;
import java.awt.Rectangle;
import java.awt.Transparency; import java.awt.Transparency;
import java.awt.Window;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
@@ -33,6 +37,8 @@ import java.awt.event.WindowEvent;
import java.awt.event.WindowListener; import java.awt.event.WindowListener;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
@@ -40,35 +46,38 @@ import javax.swing.Box;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog;
import org.jackhuang.hellominecraft.launcher.Main; import org.jackhuang.hellominecraft.launcher.Main;
import org.jackhuang.hellominecraft.launcher.setting.Settings;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator; import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
import org.jackhuang.hellominecraft.util.ui.GraphicsUtils; import org.jackhuang.hellominecraft.launcher.setting.Settings;
import org.jackhuang.hellominecraft.lookandfeel.Theme; import org.jackhuang.hellominecraft.lookandfeel.Theme;
import org.jackhuang.hellominecraft.util.C;
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.DropShadowBorder; import org.jackhuang.hellominecraft.util.log.HMCLog;
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.DropShadowBorder;
import org.jackhuang.hellominecraft.util.ui.GraphicsUtils;
import org.jackhuang.hellominecraft.util.ui.SwingUtils; import org.jackhuang.hellominecraft.util.ui.SwingUtils;
import org.jackhuang.hellominecraft.util.ui.TintablePanel;
/** /**
* *
* @author huangyuhui * @author huangyuhui
*/ */
public final class MainFrame extends DraggableFrame { public final class MainFrame extends DraggableFrame implements IRepaint {
public static final MainFrame INSTANCE = new MainFrame(); public static final MainFrame INSTANCE = new MainFrame();
TintablePanel centralPanel; TintablePanel centralPanel;
JPanel header, infoSwap, realPanel; JPanel header, infoSwap, realPanel;
CardLayout infoLayout; CardLayout infoLayout;
JLabel backgroundLabel, windowTitle; JLabel windowTitle;
GaussionPanel backgroundLabel;
DropShadowBorder border; DropShadowBorder border;
boolean enableShadow; boolean enableShadow;
String defaultTitle; String defaultTitle;
@@ -89,7 +98,7 @@ public final class MainFrame extends DraggableFrame {
setContentSize(834, 542); setContentSize(834, 542);
else else
setContentSize(802, 511); setContentSize(802, 511);
setDefaultCloseOperation(3); setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle(Main.makeTitle()); setTitle(Main.makeTitle());
initComponents(); initComponents();
loadBackground(); loadBackground();
@@ -152,6 +161,7 @@ public final class MainFrame extends DraggableFrame {
} }
private void initComponents() { private void initComponents() {
setLayout(null);
initBorderColor(Settings.getInstance().getTheme()); initBorderColor(Settings.getInstance().getTheme());
realPanel = new JPanel(); realPanel = new JPanel();
@@ -242,14 +252,13 @@ public final class MainFrame extends DraggableFrame {
truePanel.setBounds(0, 0, 800, 480); truePanel.setBounds(0, 0, 800, 480);
centralPanel.setBounds(0, 30, 800, 480); centralPanel.setBounds(0, 30, 800, 480);
setLayout(null);
realPanel.setBounds(1, 0, 800, 511); realPanel.setBounds(1, 0, 800, 511);
add(realPanel); add(realPanel);
} }
private final ActionListener tabListener = e -> MainFrame.this.selectTab(e.getActionCommand()); private transient final ActionListener tabListener = e -> MainFrame.this.selectTab(e.getActionCommand());
private void initializeTab(AnimatedPanel inst, String cmd) { private void initializeTab(Page inst, String cmd) {
HeaderTab tab = new HeaderTab(C.i18n("launcher.title." + cmd)); HeaderTab tab = new HeaderTab(C.i18n("launcher.title." + cmd));
tab.setActionCommand(cmd); tab.setActionCommand(cmd);
tab.setForeground(BasicColors.COLOR_WHITE_TEXT); tab.setForeground(BasicColors.COLOR_WHITE_TEXT);
@@ -263,11 +272,11 @@ public final class MainFrame extends DraggableFrame {
private final List<HeaderTab> tabHeader = new ArrayList<>(); private final List<HeaderTab> tabHeader = new ArrayList<>();
private JPanel tabWrapper[]; private JPanel tabWrapper[];
private final List<AnimatedPanel> tabContent = new ArrayList<>(); private final List<Page> tabContent = new ArrayList<>();
public void selectTab(String tabName) { public void selectTab(String tabName) {
int chosen = -1; int chosen = -1;
AnimatedPanel onCreate = null, onSelect = null; Page onCreate = null, onSelect = null;
for (int i = 0; i < tabHeader.size(); i++) for (int i = 0; i < tabHeader.size(); i++)
if (tabName.equalsIgnoreCase(tabHeader.get(i).getActionCommand())) { if (tabName.equalsIgnoreCase(tabHeader.get(i).getActionCommand())) {
if (!tabContent.get(i).isCreated()) { if (!tabContent.get(i).isCreated()) {
@@ -318,14 +327,15 @@ public final class MainFrame extends DraggableFrame {
public void loadBackground() { public void loadBackground() {
background = SwingUtils.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 GaussionPanel();
backgroundLabel.addAeroObject(backgroundLabel);
backgroundLabel.setBounds(0, 0, 800, 480); backgroundLabel.setBounds(0, 0, 800, 480);
centralPanel.add(backgroundLabel, -1); centralPanel.add(backgroundLabel, -1);
} else }
backgroundLabel.setIcon(background); backgroundLabel.setBackgroundImage(background.getImage());
else } else
HMCLog.warn("No background image here! The background will be empty!"); HMCLog.warn("No background image here! The background will be empty!");
} }
@@ -340,7 +350,7 @@ public final class MainFrame extends DraggableFrame {
isShowedMessage = false; isShowedMessage = false;
reloadColor(Settings.getInstance().getTheme()); reloadColor(Settings.getInstance().getTheme());
windowTitle.setText(defaultTitle); windowTitle.setText(defaultTitle);
windowTitle.setForeground(Settings.UPDATE_CHECKER.OUT_DATED ? Color.red : Color.white); windowTitle.setForeground(Settings.UPDATE_CHECKER.isOutOfDate() ? Color.red : Color.white);
} }
} }
@@ -407,7 +417,7 @@ public final class MainFrame extends DraggableFrame {
int contentWidth = width - off - off; int contentWidth = width - off - off;
int contentHeight = height - off - off; int contentHeight = height - off - off;
BufferedImage contentImage = new BufferedImage(contentWidth, BufferedImage contentImage = new BufferedImage(contentWidth,
contentHeight, Transparency.OPAQUE); contentHeight, Transparency.OPAQUE);
Graphics2D contentG2d = contentImage.createGraphics(); Graphics2D contentG2d = contentImage.createGraphics();
contentG2d.translate(-off, -off); contentG2d.translate(-off, -off);
paintImpl(g); paintImpl(g);
@@ -426,6 +436,25 @@ public final class MainFrame extends DraggableFrame {
} }
} }
@Override
public JComponent getRepaintComponent() {
return null;
}
@Override
public Window getRepaintWindow() {
return this;
}
@Override
public Collection<Rectangle> getRepaintRects() {
int off = MainFrame.INSTANCE.enableShadow ? 16 : 0, yoff = MainFrame.INSTANCE.getInsets().top + off, xoff = MainFrame.INSTANCE.getInsets().left + off;
int width = 800, height = MainFrame.INSTANCE.header.getHeight() + 480 - 1;
return Arrays.asList(new Rectangle(xoff, yoff, xoff, height + yoff + 1),
new Rectangle(xoff + width + 1, yoff, xoff + width + 1, height + yoff + 1),
new Rectangle(xoff, height + yoff + 1, xoff + width + 1, height + yoff + 1));
}
private static class MouseListenerImpl implements MouseListener { private static class MouseListenerImpl implements MouseListener {
public static final MouseListenerImpl INSTANCE = new MouseListenerImpl(); public static final MouseListenerImpl INSTANCE = new MouseListenerImpl();
@@ -454,14 +483,12 @@ public final class MainFrame extends DraggableFrame {
public void failed(String s) { public void failed(String s) {
if (s != null) if (s != null)
MessageBox.Show(s); MessageBox.show(s);
closeMessage(); closeMessage();
} }
LaunchingUIDaemon daemon = new LaunchingUIDaemon(); transient LaunchingUIDaemon daemon = new LaunchingUIDaemon();
transient final HashMap<String, Runnable> actions = new HashMap<>();
final HashMap<String, Runnable> actions = new HashMap<>();
void invokeAction(String name) { void invokeAction(String name) {
if (actions.containsKey(name)) if (actions.containsKey(name))
actions.get(name).run(); actions.get(name).run();

View File

@@ -18,264 +18,287 @@
<Property name="useNullLayout" type="boolean" value="true"/> <Property name="useNullLayout" type="boolean" value="true"/>
</Layout> </Layout>
<SubComponents> <SubComponents>
<Container class="javax.swing.JPanel" name="pnlMore"> <Container class="javax.swing.JPanel" name="pnlRoot">
<Properties> <AuxValues>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor"> <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new org.jackhuang.hellominecraft.launcher.ui.GaussionPanel()"/>
<Color blue="cc" green="cc" red="cc" type="rgb"/> </AuxValues>
</Property>
<Property name="opaque" type="boolean" value="false"/>
</Properties>
<Constraints> <Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="0" y="0" width="190" height="480"/> <AbsoluteConstraints x="0" y="0" width="800" height="480"/>
</Constraint> </Constraint>
</Constraints> </Constraints>
<Layout> <Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
<DimensionLayout dim="0"> <Property name="useNullLayout" type="boolean" value="true"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="pnlPassword" alignment="1" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel10" alignment="1" min="-2" max="-2" attributes="0"/>
<Component id="lblVersion" alignment="1" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="cboProfiles" alignment="0" pref="128" max="32767" attributes="0"/>
<Component id="cboVersions" alignment="0" max="32767" attributes="0"/>
</Group>
</Group>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="lblUserName" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="jLabel7" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="cboLoginMode" max="32767" attributes="0"/>
<Component id="txtPlayerName" max="32767" attributes="0"/>
</Group>
</Group>
<Component id="btnExportModpack" alignment="0" max="32767" attributes="0"/>
<Component id="btnImportModpack" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel10" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="cboProfiles" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="cboVersions" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
<Component id="lblVersion" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel7" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="cboLoginMode" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblUserName" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtPlayerName" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="pnlPassword" min="-2" pref="26" max="-2" attributes="0"/>
<EmptySpace pref="248" max="32767" attributes="0"/>
<Component id="btnImportModpack" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnExportModpack" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout> </Layout>
<SubComponents> <SubComponents>
<Component class="javax.swing.JTextField" name="txtPlayerName"> <Container class="javax.swing.JPanel" name="pnlMore">
<Events>
<EventHandler event="focusGained" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtPlayerNameFocusGained"/>
<EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtPlayerNameFocusLost"/>
<EventHandler event="keyPressed" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="txtPlayerNameKeyPressed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabel7">
<Properties> <Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> <Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="login.type" replaceFormat="C.i18n(&quot;{key}&quot;)"/> <Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property> </Property>
<Property name="opaque" type="boolean" value="false"/>
</Properties> </Properties>
</Component> <AuxValues>
<Component class="javax.swing.JComboBox" name="cboLoginMode"> <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new org.jackhuang.hellominecraft.launcher.ui.RepaintPage()"/>
<Properties> <AuxValue name="JavaCodeGenerator_SerializeTo" type="java.lang.String" value="MainPagePanel_pnlMore"/>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor"> </AuxValues>
<StringArray count="0"/> <Constraints>
</Property> <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
</Properties> <AbsoluteConstraints x="0" y="0" width="190" height="480"/>
<Events> </Constraint>
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="cboLoginModeItemStateChanged"/> </Constraints>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="lblUserName">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="login.username" replaceFormat="C.i18n(&quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel10">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="ui.label.profile" replaceFormat="C.i18n(&quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="cboProfiles">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="0"/>
</Property>
</Properties>
<Events>
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="cboProfilesItemStateChanged"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="lblVersion">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="ui.label.version" replaceFormat="C.i18n(&quot;{key}&quot;)"/>
</Property>
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="ui.label.version" replaceFormat="C.i18n(&quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="cboVersions">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="0"/>
</Property>
</Properties>
<Events>
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="cboVersionsItemStateChanged"/>
</Events>
</Component>
<Container class="javax.swing.JPanel" name="pnlPassword">
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignCardLayout"/> <Layout>
<SubComponents> <DimensionLayout dim="0">
<Container class="javax.swing.JPanel" name="jPanel1"> <Group type="103" groupAlignment="0" attributes="0">
<Constraints> <Group type="102" attributes="0">
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignCardLayout" value="org.netbeans.modules.form.compat2.layouts.DesignCardLayout$CardConstraintsDescription"> <EmptySpace max="-2" attributes="0"/>
<CardConstraints cardName="card2"/> <Group type="103" groupAlignment="0" attributes="0">
</Constraint> <Component id="pnlPassword" alignment="1" max="32767" attributes="0"/>
</Constraints> <Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Layout> <Component id="lblProfile" alignment="1" min="-2" max="-2" attributes="0"/>
<DimensionLayout dim="0"> <Component id="lblVersion" alignment="1" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> </Group>
<Group type="102" alignment="0" attributes="0"> <EmptySpace max="-2" attributes="0"/>
<Component id="jLabel9" min="-2" max="-2" attributes="0"/> <Group type="103" groupAlignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/> <Component id="cboProfiles" alignment="0" max="32767" attributes="0"/>
<Component id="txtPassword" max="32767" attributes="0"/> <Component id="cboVersions" alignment="0" max="32767" attributes="0"/>
</Group>
</Group>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="lblUserName" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lblLogin" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="cboLoginMode" max="32767" attributes="0"/>
<Component id="txtPlayerName" max="32767" attributes="0"/>
</Group>
</Group>
<Component id="btnExportModpack" alignment="0" max="32767" attributes="0"/>
<Component id="btnImportModpack" alignment="0" max="32767" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/>
</Group> </Group>
</DimensionLayout> </Group>
<DimensionLayout dim="1"> </DimensionLayout>
<Group type="103" groupAlignment="0" attributes="0"> <DimensionLayout dim="1">
<Group type="102" alignment="1" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/> <Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="3" attributes="0"> <EmptySpace max="-2" attributes="0"/>
<Component id="jLabel9" alignment="3" min="-2" pref="22" max="-2" attributes="0"/> <Group type="103" groupAlignment="3" attributes="0">
<Component id="txtPassword" alignment="3" min="-2" pref="26" max="-2" attributes="0"/> <Component id="lblProfile" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="cboProfiles" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="cboVersions" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
<Component id="lblVersion" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblLogin" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="cboLoginMode" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblUserName" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtPlayerName" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="pnlPassword" min="-2" pref="26" max="-2" attributes="0"/>
<EmptySpace pref="254" max="32767" attributes="0"/>
<Component id="btnImportModpack" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnExportModpack" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JTextField" name="txtPlayerName">
<Events>
<EventHandler event="focusGained" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtPlayerNameFocusGained"/>
<EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtPlayerNameFocusLost"/>
<EventHandler event="keyPressed" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="txtPlayerNameKeyPressed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="lblLogin">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="login.type" replaceFormat="C.i18n(&quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="cboLoginMode">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="0"/>
</Property>
</Properties>
<Events>
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="cboLoginModeItemStateChanged"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="lblUserName">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="login.username" replaceFormat="C.i18n(&quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblProfile">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="ui.label.profile" replaceFormat="C.i18n(&quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="cboProfiles">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="0"/>
</Property>
</Properties>
<Events>
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="cboProfilesItemStateChanged"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="lblVersion">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="ui.label.version" replaceFormat="C.i18n(&quot;{key}&quot;)"/>
</Property>
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="ui.label.version" replaceFormat="C.i18n(&quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="cboVersions">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="0"/>
</Property>
</Properties>
<Events>
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="cboVersionsItemStateChanged"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new WideComboBox()"/>
</AuxValues>
</Component>
<Container class="javax.swing.JPanel" name="pnlPassword">
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignCardLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="pnlLogIn">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignCardLayout" value="org.netbeans.modules.form.compat2.layouts.DesignCardLayout$CardConstraintsDescription">
<CardConstraints cardName="card2"/>
</Constraint>
</Constraints>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="lblPassword" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="txtPassword" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</Group> </DimensionLayout>
</DimensionLayout> <DimensionLayout dim="1">
</Layout> <Group type="103" groupAlignment="0" attributes="0">
<SubComponents> <Group type="102" alignment="1" attributes="0">
<Component class="javax.swing.JLabel" name="jLabel9"> <EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<Properties> <Group type="103" groupAlignment="3" attributes="0">
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> <Component id="lblPassword" alignment="3" min="-2" pref="22" max="-2" attributes="0"/>
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="ui.label.password" replaceFormat="C.i18n(&quot;{key}&quot;)"/> <Component id="txtPassword" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
</Property> </Group>
</Properties> </Group>
</Component> </Group>
<Component class="javax.swing.JPasswordField" name="txtPassword"> </DimensionLayout>
<Events> </Layout>
<EventHandler event="caretUpdate" listener="javax.swing.event.CaretListener" parameters="javax.swing.event.CaretEvent" handler="txtPasswordCaretUpdate"/> <SubComponents>
<EventHandler event="focusGained" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtPasswordFocusGained"/> <Component class="javax.swing.JLabel" name="lblPassword">
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="txtPasswordActionPerformed"/> <Properties>
<EventHandler event="keyPressed" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="txtPasswordKeyPressed"/> <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
</Events> <ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="ui.label.password" replaceFormat="C.i18n(&quot;{key}&quot;)"/>
</Component> </Property>
</SubComponents> </Properties>
</Container> </Component>
<Container class="javax.swing.JPanel" name="jPanel3"> <Component class="javax.swing.JPasswordField" name="txtPassword">
<Constraints> <Events>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignCardLayout" value="org.netbeans.modules.form.compat2.layouts.DesignCardLayout$CardConstraintsDescription"> <EventHandler event="caretUpdate" listener="javax.swing.event.CaretListener" parameters="javax.swing.event.CaretEvent" handler="txtPasswordCaretUpdate"/>
<CardConstraints cardName="card3"/> <EventHandler event="focusGained" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtPasswordFocusGained"/>
</Constraint> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="txtPasswordActionPerformed"/>
</Constraints> <EventHandler event="keyPressed" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="txtPasswordKeyPressed"/>
</Events>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="pnlLogOut">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignCardLayout" value="org.netbeans.modules.form.compat2.layouts.DesignCardLayout$CardConstraintsDescription">
<CardConstraints cardName="card3"/>
</Constraint>
</Constraints>
<Layout> <Layout>
<DimensionLayout dim="0"> <DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="btnLogout" alignment="0" pref="170" max="32767" attributes="0"/> <Component id="btnLogout" alignment="0" pref="170" max="32767" attributes="0"/>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
<DimensionLayout dim="1"> <DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="btnLogout" alignment="0" max="32767" attributes="0"/> <Component id="btnLogout" alignment="0" max="32767" attributes="0"/>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
</Layout> </Layout>
<SubComponents> <SubComponents>
<Component class="javax.swing.JButton" name="btnLogout"> <Component class="javax.swing.JButton" name="btnLogout">
<Properties> <Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="ui.button.logout" replaceFormat="C.i18n(&quot;{key}&quot;)"/> <ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="ui.button.logout" replaceFormat="C.i18n(&quot;{key}&quot;)"/>
</Property> </Property>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnLogoutActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnLogoutActionPerformed"/>
</Events> </Events>
</Component> </Component>
</SubComponents>
</Container>
</SubComponents> </SubComponents>
</Container> </Container>
<Component class="javax.swing.JButton" name="btnImportModpack">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="modpack.task.install" replaceFormat="C.i18n(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnImportModpackActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnExportModpack">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="modpack.task.save" replaceFormat="C.i18n(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnExportModpackActionPerformed"/>
</Events>
</Component>
</SubComponents> </SubComponents>
</Container> </Container>
<Component class="javax.swing.JButton" name="btnImportModpack">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="modpack.task.install" replaceFormat="C.i18n(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnImportModpackActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnExportModpack">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/lang/I18N.properties" key="modpack.task.save" replaceFormat="C.i18n(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnExportModpackActionPerformed"/>
</Events>
</Component>
</SubComponents> </SubComponents>
</Container> </Container>
</SubComponents> </SubComponents>
</Form> </Form>

View File

@@ -17,13 +17,14 @@
*/ */
package org.jackhuang.hellominecraft.launcher.ui; package org.jackhuang.hellominecraft.launcher.ui;
import org.jackhuang.hellominecraft.util.ui.WideComboBox;
import org.jackhuang.hellominecraft.util.ui.GaussionPanel;
import java.awt.CardLayout; import java.awt.CardLayout;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font; import java.awt.Font;
import java.awt.event.ItemEvent; import java.awt.event.ItemEvent;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import javax.swing.DefaultComboBoxModel; import javax.swing.DefaultComboBoxModel;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.filechooser.FileNameExtensionFilter;
@@ -38,12 +39,13 @@ import org.jackhuang.hellominecraft.launcher.core.mod.ModpackManager;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.ui.modpack.ModpackWizard; import org.jackhuang.hellominecraft.launcher.ui.modpack.ModpackWizard;
import org.jackhuang.hellominecraft.launcher.util.HMCLMinecraftService; import org.jackhuang.hellominecraft.launcher.util.HMCLMinecraftService;
import org.jackhuang.hellominecraft.util.ui.GraphicsUtils;
import org.jackhuang.hellominecraft.util.Event; import org.jackhuang.hellominecraft.util.Event;
import org.jackhuang.hellominecraft.lookandfeel.comp.ConstomButton; import org.jackhuang.hellominecraft.lookandfeel.ConstomButton;
import org.jackhuang.hellominecraft.util.func.Consumer; import org.jackhuang.hellominecraft.util.func.Consumer;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.util.tasks.TaskWindow; import org.jackhuang.hellominecraft.util.task.TaskWindow;
import org.jackhuang.hellominecraft.util.ui.GraphicsUtils;
import org.jackhuang.hellominecraft.util.ui.JSystemFileChooser;
import org.jackhuang.hellominecraft.util.ui.SwingUtils; import org.jackhuang.hellominecraft.util.ui.SwingUtils;
import org.jackhuang.hellominecraft.util.ui.wizard.api.WizardDisplayer; import org.jackhuang.hellominecraft.util.ui.wizard.api.WizardDisplayer;
@@ -51,11 +53,8 @@ import org.jackhuang.hellominecraft.util.ui.wizard.api.WizardDisplayer;
* *
* @author huangyuhui * @author huangyuhui
*/ */
public class MainPagePanel extends AnimatedPanel { public class MainPagePanel extends Page {
/**
* Creates new form MainPagePanel
*/
public MainPagePanel() { public MainPagePanel() {
} }
@@ -76,7 +75,7 @@ public class MainPagePanel extends AnimatedPanel {
btnRun.setFont(newFont); btnRun.setFont(newFont);
btnRun.addActionListener(e -> MainFrame.INSTANCE.daemon.runGame(Settings.getLastProfile())); btnRun.addActionListener(e -> MainFrame.INSTANCE.daemon.runGame(Settings.getLastProfile()));
this.add(pnlButtons); pnlRoot.add(pnlButtons);
pnlButtons.setBounds(0, 0, w, h); pnlButtons.setBounds(0, 0, w, h);
this.setSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT)); this.setSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT));
@@ -93,7 +92,11 @@ public class MainPagePanel extends AnimatedPanel {
prepareAuths(); prepareAuths();
animationEnabled = false; if (Settings.getInstance().isEnableBlur())
((GaussionPanel) pnlRoot).addAeroObject(pnlMore);
((GaussionPanel) pnlRoot).setBackgroundImage(MainFrame.INSTANCE.background.getImage());
((RepaintPage) pnlMore).setRepainter(pnlRoot);
} }
/** /**
@@ -105,26 +108,29 @@ public class MainPagePanel extends AnimatedPanel {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() { private void initComponents() {
pnlMore = new javax.swing.JPanel(); pnlRoot = new GaussionPanel();
pnlMore = new org.jackhuang.hellominecraft.launcher.ui.RepaintPage();
txtPlayerName = new javax.swing.JTextField(); txtPlayerName = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel(); lblLogin = new javax.swing.JLabel();
cboLoginMode = new javax.swing.JComboBox(); cboLoginMode = new javax.swing.JComboBox();
lblUserName = new javax.swing.JLabel(); lblUserName = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel(); lblProfile = new javax.swing.JLabel();
cboProfiles = new javax.swing.JComboBox(); cboProfiles = new javax.swing.JComboBox();
lblVersion = new javax.swing.JLabel(); lblVersion = new javax.swing.JLabel();
cboVersions = new javax.swing.JComboBox(); cboVersions = new WideComboBox();
pnlPassword = new javax.swing.JPanel(); pnlPassword = new javax.swing.JPanel();
jPanel1 = new javax.swing.JPanel(); pnlLogIn = new javax.swing.JPanel();
jLabel9 = new javax.swing.JLabel(); lblPassword = new javax.swing.JLabel();
txtPassword = new javax.swing.JPasswordField(); txtPassword = new javax.swing.JPasswordField();
jPanel3 = new javax.swing.JPanel(); pnlLogOut = new javax.swing.JPanel();
btnLogout = new javax.swing.JButton(); btnLogout = new javax.swing.JButton();
btnImportModpack = new javax.swing.JButton(); btnImportModpack = new javax.swing.JButton();
btnExportModpack = new javax.swing.JButton(); btnExportModpack = new javax.swing.JButton();
setLayout(null); setLayout(null);
pnlRoot.setLayout(null);
pnlMore.setBackground(new java.awt.Color(204, 204, 204)); pnlMore.setBackground(new java.awt.Color(204, 204, 204));
pnlMore.setOpaque(false); pnlMore.setOpaque(false);
@@ -142,7 +148,7 @@ public class MainPagePanel extends AnimatedPanel {
} }
}); });
jLabel7.setText(C.i18n("login.type")); // NOI18N lblLogin.setText(C.i18n("login.type")); // NOI18N
cboLoginMode.addItemListener(new java.awt.event.ItemListener() { cboLoginMode.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) { public void itemStateChanged(java.awt.event.ItemEvent evt) {
@@ -152,7 +158,7 @@ public class MainPagePanel extends AnimatedPanel {
lblUserName.setText(C.i18n("login.username")); // NOI18N lblUserName.setText(C.i18n("login.username")); // NOI18N
jLabel10.setText(C.i18n("ui.label.profile")); // NOI18N lblProfile.setText(C.i18n("ui.label.profile")); // NOI18N
cboProfiles.addItemListener(new java.awt.event.ItemListener() { cboProfiles.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) { public void itemStateChanged(java.awt.event.ItemEvent evt) {
@@ -171,7 +177,7 @@ public class MainPagePanel extends AnimatedPanel {
pnlPassword.setLayout(new java.awt.CardLayout()); pnlPassword.setLayout(new java.awt.CardLayout());
jLabel9.setText(C.i18n("ui.label.password")); // NOI18N lblPassword.setText(C.i18n("ui.label.password")); // NOI18N
txtPassword.addCaretListener(new javax.swing.event.CaretListener() { txtPassword.addCaretListener(new javax.swing.event.CaretListener() {
public void caretUpdate(javax.swing.event.CaretEvent evt) { public void caretUpdate(javax.swing.event.CaretEvent evt) {
@@ -194,25 +200,25 @@ public class MainPagePanel extends AnimatedPanel {
} }
}); });
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); javax.swing.GroupLayout pnlLogInLayout = new javax.swing.GroupLayout(pnlLogIn);
jPanel1.setLayout(jPanel1Layout); pnlLogIn.setLayout(pnlLogInLayout);
jPanel1Layout.setHorizontalGroup( pnlLogInLayout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) pnlLogInLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup() .addGroup(pnlLogInLayout.createSequentialGroup()
.addComponent(jLabel9) .addComponent(lblPassword)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtPassword)) .addComponent(txtPassword))
); );
jPanel1Layout.setVerticalGroup( pnlLogInLayout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) pnlLogInLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlLogInLayout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE) .addGap(0, 0, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(pnlLogInLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lblPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))) .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)))
); );
pnlPassword.add(jPanel1, "card2"); pnlPassword.add(pnlLogIn, "card2");
btnLogout.setText(C.i18n("ui.button.logout")); // NOI18N btnLogout.setText(C.i18n("ui.button.logout")); // NOI18N
btnLogout.addActionListener(new java.awt.event.ActionListener() { btnLogout.addActionListener(new java.awt.event.ActionListener() {
@@ -221,18 +227,18 @@ public class MainPagePanel extends AnimatedPanel {
} }
}); });
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); javax.swing.GroupLayout pnlLogOutLayout = new javax.swing.GroupLayout(pnlLogOut);
jPanel3.setLayout(jPanel3Layout); pnlLogOut.setLayout(pnlLogOutLayout);
jPanel3Layout.setHorizontalGroup( pnlLogOutLayout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) pnlLogOutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnLogout, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE) .addComponent(btnLogout, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
); );
jPanel3Layout.setVerticalGroup( pnlLogOutLayout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) pnlLogOutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnLogout, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnLogout, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
); );
pnlPassword.add(jPanel3, "card3"); pnlPassword.add(pnlLogOut, "card3");
btnImportModpack.setText(C.i18n("modpack.task.install")); // NOI18N btnImportModpack.setText(C.i18n("modpack.task.install")); // NOI18N
btnImportModpack.addActionListener(new java.awt.event.ActionListener() { btnImportModpack.addActionListener(new java.awt.event.ActionListener() {
@@ -258,16 +264,16 @@ public class MainPagePanel extends AnimatedPanel {
.addComponent(pnlPassword, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(pnlPassword, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(pnlMoreLayout.createSequentialGroup() .addGroup(pnlMoreLayout.createSequentialGroup()
.addGroup(pnlMoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlMoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(lblProfile, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lblVersion, javax.swing.GroupLayout.Alignment.TRAILING)) .addComponent(lblVersion, javax.swing.GroupLayout.Alignment.TRAILING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlMoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlMoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cboProfiles, 0, 128, Short.MAX_VALUE) .addComponent(cboProfiles, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cboVersions, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addComponent(cboVersions, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(pnlMoreLayout.createSequentialGroup() .addGroup(pnlMoreLayout.createSequentialGroup()
.addGroup(pnlMoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlMoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblUserName) .addComponent(lblUserName)
.addComponent(jLabel7)) .addComponent(lblLogin))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlMoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlMoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cboLoginMode, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(cboLoginMode, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
@@ -281,7 +287,7 @@ public class MainPagePanel extends AnimatedPanel {
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlMoreLayout.createSequentialGroup() .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlMoreLayout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addGroup(pnlMoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(pnlMoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel10) .addComponent(lblProfile)
.addComponent(cboProfiles, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(cboProfiles, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlMoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(pnlMoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
@@ -289,7 +295,7 @@ public class MainPagePanel extends AnimatedPanel {
.addComponent(lblVersion)) .addComponent(lblVersion))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlMoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(pnlMoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7) .addComponent(lblLogin)
.addComponent(cboLoginMode, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(cboLoginMode, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlMoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(pnlMoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
@@ -297,15 +303,18 @@ public class MainPagePanel extends AnimatedPanel {
.addComponent(txtPlayerName, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(txtPlayerName, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pnlPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(pnlPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 248, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 254, Short.MAX_VALUE)
.addComponent(btnImportModpack) .addComponent(btnImportModpack)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnExportModpack) .addComponent(btnExportModpack)
.addContainerGap()) .addContainerGap())
); );
add(pnlMore); pnlRoot.add(pnlMore);
pnlMore.setBounds(0, 0, 190, 480); pnlMore.setBounds(0, 0, 190, 480);
add(pnlRoot);
pnlRoot.setBounds(0, 0, 800, 480);
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
private void txtPlayerNameFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPlayerNameFocusGained private void txtPlayerNameFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPlayerNameFocusGained
@@ -374,8 +383,8 @@ public class MainPagePanel extends AnimatedPanel {
}//GEN-LAST:event_txtPasswordKeyPressed }//GEN-LAST:event_txtPasswordKeyPressed
private void btnImportModpackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImportModpackActionPerformed private void btnImportModpackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImportModpackActionPerformed
JFileChooser fc = new JFileChooser(); JSystemFileChooser fc = new JSystemFileChooser();
fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setFileSelectionMode(JSystemFileChooser.FILES_ONLY);
fc.setDialogTitle(C.i18n("modpack.choose")); fc.setDialogTitle(C.i18n("modpack.choose"));
fc.setMultiSelectionEnabled(false); fc.setMultiSelectionEnabled(false);
fc.setFileFilter(new FileNameExtensionFilter(C.i18n("modpack"), "zip")); fc.setFileFilter(new FileNameExtensionFilter(C.i18n("modpack"), "zip"));
@@ -383,7 +392,7 @@ public class MainPagePanel extends AnimatedPanel {
if (fc.getSelectedFile() == null) if (fc.getSelectedFile() == null)
return; return;
String suggestedModpackId = JOptionPane.showInputDialog("Please enter your favourite game name", FileUtils.getBaseName(fc.getSelectedFile().getName())); String suggestedModpackId = JOptionPane.showInputDialog("Please enter your favourite game name", FileUtils.getBaseName(fc.getSelectedFile().getName()));
TaskWindow.factory().append(ModpackManager.install(MainFrame.INSTANCE, fc.getSelectedFile(), Settings.getLastProfile().service(), suggestedModpackId)).create(); TaskWindow.factory().append(ModpackManager.install(MainFrame.INSTANCE, fc.getSelectedFile(), Settings.getLastProfile().service(), suggestedModpackId)).execute();
Settings.getLastProfile().service().version().refreshVersions(); Settings.getLastProfile().service().version().refreshVersions();
}//GEN-LAST:event_btnImportModpackActionPerformed }//GEN-LAST:event_btnImportModpackActionPerformed
@@ -398,6 +407,7 @@ public class MainPagePanel extends AnimatedPanel {
}//GEN-LAST:event_txtPasswordCaretUpdate }//GEN-LAST:event_txtPasswordCaretUpdate
// <editor-fold defaultstate="collapsed" desc="Loads"> // <editor-fold defaultstate="collapsed" desc="Loads">
private void prepareAuths() { private void prepareAuths() {
preparingAuth = true; preparingAuth = true;
cboLoginMode.removeAllItems(); cboLoginMode.removeAllItems();
@@ -434,15 +444,16 @@ public class MainPagePanel extends AnimatedPanel {
private javax.swing.JComboBox cboLoginMode; private javax.swing.JComboBox cboLoginMode;
private javax.swing.JComboBox cboProfiles; private javax.swing.JComboBox cboProfiles;
private javax.swing.JComboBox cboVersions; private javax.swing.JComboBox cboVersions;
private javax.swing.JLabel jLabel10; private javax.swing.JLabel lblLogin;
private javax.swing.JLabel jLabel7; private javax.swing.JLabel lblPassword;
private javax.swing.JLabel jLabel9; private javax.swing.JLabel lblProfile;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel3;
private javax.swing.JLabel lblUserName; private javax.swing.JLabel lblUserName;
private javax.swing.JLabel lblVersion; private javax.swing.JLabel lblVersion;
private javax.swing.JPanel pnlLogIn;
private javax.swing.JPanel pnlLogOut;
private javax.swing.JPanel pnlMore; private javax.swing.JPanel pnlMore;
private javax.swing.JPanel pnlPassword; private javax.swing.JPanel pnlPassword;
private javax.swing.JPanel pnlRoot;
private javax.swing.JPasswordField txtPassword; private javax.swing.JPasswordField txtPassword;
private javax.swing.JTextField txtPlayerName; private javax.swing.JTextField txtPlayerName;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
@@ -469,16 +480,14 @@ public class MainPagePanel extends AnimatedPanel {
return true; return true;
}; };
final Runnable onLoadingProfiles = this::loadProfiles; final Runnable onLoadingProfiles = () -> {
private void loadProfiles() {
isLoading = true; isLoading = true;
DefaultComboBoxModel model = new DefaultComboBoxModel(); DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
for (Profile s : Settings.getProfilesFiltered()) for (Profile s : Settings.getProfilesFiltered())
model.addElement(s.getName()); model.addElement(s.getName());
cboProfiles.setModel(model); cboProfiles.setModel(model);
isLoading = false; isLoading = false;
} };
final Consumer<IMinecraftService> onRefreshedVersions = t -> { final Consumer<IMinecraftService> onRefreshedVersions = t -> {
if (Settings.getLastProfile().service() == t) if (Settings.getLastProfile().service() == t)
@@ -495,7 +504,7 @@ public class MainPagePanel extends AnimatedPanel {
if (!showedNoVersion && ((HMCLMinecraftService) Settings.getLastProfile().service()).checkedModpack) { if (!showedNoVersion && ((HMCLMinecraftService) Settings.getLastProfile().service()).checkedModpack) {
showedNoVersion = true; showedNoVersion = true;
SwingUtilities.invokeLater(() -> { 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.invokeAction("showGameDownloads"); MainFrame.INSTANCE.invokeAction("showGameDownloads");
}); });
} }
@@ -516,7 +525,7 @@ public class MainPagePanel extends AnimatedPanel {
void versionChanged(String selectedVersion) { void versionChanged(String selectedVersion) {
isLoading = true; isLoading = true;
DefaultComboBoxModel model = (DefaultComboBoxModel) cboVersions.getModel(); DefaultComboBoxModel<String> model = (DefaultComboBoxModel<String>) cboVersions.getModel();
for (int i = 0; i < model.getSize(); ++i) for (int i = 0; i < model.getSize(); ++i)
if (model.getElementAt(i).equals(selectedVersion)) { if (model.getElementAt(i).equals(selectedVersion)) {
model.setSelectedItem(selectedVersion); model.setSelectedItem(selectedVersion);
@@ -532,7 +541,7 @@ public class MainPagePanel extends AnimatedPanel {
t.launcher().launchingStateChanged.register(launchingStateChanged); t.launcher().launchingStateChanged.register(launchingStateChanged);
isLoading = true; isLoading = true;
DefaultComboBoxModel model = (DefaultComboBoxModel) cboProfiles.getModel(); DefaultComboBoxModel<String> model = (DefaultComboBoxModel<String>) cboProfiles.getModel();
for (int i = 0; i < model.getSize(); ++i) for (int i = 0; i < model.getSize(); ++i)
if (model.getElementAt(i).equals(t.getName())) { if (model.getElementAt(i).equals(t.getName())) {
model.setSelectedItem(t.getName()); model.setSelectedItem(t.getName());

View File

@@ -1,5 +1,5 @@
/* /*
* Hello Minecraft!. * Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com> * Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@@ -15,32 +15,42 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}. * along with this program. If not, see {http://www.gnu.org/licenses/}.
*/ */
package org.jackhuang.hellominecraft.util.tasks; package org.jackhuang.hellominecraft.launcher.ui;
import java.io.File; import javax.swing.JPanel;
import org.jackhuang.hellominecraft.util.system.Compressor;
/** /**
* *
* @author huangyuhui * @author huangyuhui
*/ */
public class DecompressTask extends Task { public class Page extends JPanel implements Selectable {
File src, dest; boolean selected = false;
public DecompressTask(File src, File dest) { @Override
this.src = src; public boolean isSelected() {
this.dest = dest; return selected;
} }
@Override @Override
public void executeTask() throws Throwable { public void onSelect() {
Compressor.unzip(src, dest); selected = true;
} }
@Override @Override
public String getInfo() { public void onLeave() {
return "Decompress: " + src.getAbsolutePath() + " to " + dest.getAbsolutePath(); selected = false;
} }
boolean created = false;
@Override
public void onCreate() {
created = true;
}
@Override
public boolean isCreated() {
return created;
}
} }

View File

@@ -1,7 +1,7 @@
/* /*
* Hello Minecraft!. * Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com> * Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
@@ -15,40 +15,43 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}. * along with this program. If not, see {http://www.gnu.org/licenses/}.
*/ */
package org.jackhuang.hellominecraft.util.tasks.download; package org.jackhuang.hellominecraft.launcher.ui;
import org.jackhuang.hellominecraft.util.Event; import org.jackhuang.hellominecraft.util.ui.IRepaint;
import org.jackhuang.hellominecraft.util.ui.LogWindow; import java.awt.Rectangle;
import java.awt.Window;
import java.util.Arrays;
import java.util.Collection;
import javax.swing.JComponent;
/** /**
* *
* @author huangyuhui * @author huang
*/ */
public class ContentGetAndShowTask extends HTTPGetTask implements Event<String> { public class RepaintPage extends Page implements IRepaint {
public ContentGetAndShowTask(String info, String changeLogUrl) { public RepaintPage() {
super(changeLogUrl); super();
this.info = info; }
JComponent repainter;
@Override
public JComponent getRepaintComponent() {
return repainter;
}
public void setRepainter(JComponent repainter) {
this.repainter = repainter;
} }
@Override @Override
public void executeTask() throws Exception { public Collection<Rectangle> getRepaintRects() {
tdtsl.register(this); return Arrays.asList(this.getBounds());
super.executeTask();
}
String info;
@Override
public String getInfo() {
return info;
} }
@Override @Override
public boolean call(Object sender, String value) { public Window getRepaintWindow() {
LogWindow.INSTANCE.clean(); return null;
LogWindow.INSTANCE.log(value);
LogWindow.INSTANCE.setVisible(true);
return true;
} }
} }

View File

@@ -18,12 +18,14 @@
package org.jackhuang.hellominecraft.launcher.ui.modpack; package org.jackhuang.hellominecraft.launcher.ui.modpack;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.HeadlessException;
import java.io.IOException;
import java.util.Map; import java.util.Map;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
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.WebPage; import org.jackhuang.hellominecraft.util.net.WebPage;
import org.jackhuang.hellominecraft.util.ui.wizard.spi.WizardController; import org.jackhuang.hellominecraft.util.ui.wizard.spi.WizardController;
import org.markdown4j.Markdown4jProcessor; import org.markdown4j.Markdown4jProcessor;
@@ -113,8 +115,8 @@ public class ModpackDescriptionPanel extends javax.swing.JPanel {
msgs[1] = new WebPage(new Markdown4jProcessor().process(txtDescription.getText())); msgs[1] = new WebPage(new Markdown4jProcessor().process(txtDescription.getText()));
((WebPage) msgs[1]).setPreferredSize(new Dimension(800, 350)); ((WebPage) msgs[1]).setPreferredSize(new Dimension(800, 350));
JOptionPane.showOptionDialog(null, msgs, (String) msgs[0], JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); JOptionPane.showOptionDialog(null, msgs, (String) msgs[0], JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
} catch (Exception e) { } catch (HeadlessException | IOException e) {
MessageBox.Show(StrUtils.getStackTrace(e), C.i18n("message.error"), MessageBox.WARNING_MESSAGE); MessageBox.show(StrUtils.getStackTrace(e), C.i18n("message.error"), MessageBox.WARNING_MESSAGE);
} }
}//GEN-LAST:event_jButton1ActionPerformed }//GEN-LAST:event_jButton1ActionPerformed

View File

@@ -26,7 +26,7 @@ import javax.swing.tree.DefaultTreeModel;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.Pair; import org.jackhuang.hellominecraft.util.Pair;
import org.jackhuang.hellominecraft.util.func.BiFunction; import org.jackhuang.hellominecraft.util.func.BiFunction;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.util.ui.checktree.CheckBoxTreeCellRenderer; import org.jackhuang.hellominecraft.util.ui.checktree.CheckBoxTreeCellRenderer;
import org.jackhuang.hellominecraft.util.ui.checktree.CheckBoxTreeNode; import org.jackhuang.hellominecraft.util.ui.checktree.CheckBoxTreeNode;
import org.jackhuang.hellominecraft.util.ui.checktree.CheckBoxTreeNodeSelectionListener; import org.jackhuang.hellominecraft.util.ui.checktree.CheckBoxTreeNodeSelectionListener;

View File

@@ -21,9 +21,9 @@ import java.util.Map;
import java.util.Vector; import java.util.Vector;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.swing.DefaultComboBoxModel; import javax.swing.DefaultComboBoxModel;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.filechooser.FileNameExtensionFilter;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.ui.JSystemFileChooser;
import org.jackhuang.hellominecraft.util.ui.wizard.spi.WizardController; import org.jackhuang.hellominecraft.util.ui.wizard.spi.WizardController;
/** /**
@@ -38,12 +38,12 @@ public class ModpackInitializationPanel extends javax.swing.JPanel {
public static final String KEY_INCLUDING_LAUNCHER = "launcher"; public static final String KEY_INCLUDING_LAUNCHER = "launcher";
private final transient WizardController controller; private final transient WizardController controller;
private final Map wizardData; private final Map<String, Object> wizardData;
/** /**
* Creates new form ModpackInitializationPanel * Creates new form ModpackInitializationPanel
*/ */
public ModpackInitializationPanel(WizardController controller, Map wizardData, Vector<String> versions, String selVersion) { public ModpackInitializationPanel(WizardController controller, Map<String, Object> wizardData, Vector<String> versions, String selVersion) {
initComponents(); initComponents();
this.controller = controller; this.controller = controller;
@@ -172,8 +172,8 @@ public class ModpackInitializationPanel extends javax.swing.JPanel {
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
private void cboModpackLocationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboModpackLocationActionPerformed private void cboModpackLocationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboModpackLocationActionPerformed
JFileChooser fc = new JFileChooser(); JSystemFileChooser fc = new JSystemFileChooser();
fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setFileSelectionMode(JSystemFileChooser.FILES_ONLY);
fc.setDialogTitle(C.i18n("modpack.wizard.step.initialization.save")); fc.setDialogTitle(C.i18n("modpack.wizard.step.initialization.save"));
fc.setMultiSelectionEnabled(false); fc.setMultiSelectionEnabled(false);
fc.setFileFilter(new FileNameExtensionFilter(C.i18n("modpack") + "(*.zip)", "zip")); fc.setFileFilter(new FileNameExtensionFilter(C.i18n("modpack") + "(*.zip)", "zip"));

View File

@@ -19,6 +19,7 @@ package org.jackhuang.hellominecraft.launcher.ui.modpack;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
@@ -38,10 +39,10 @@ import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.Pair; import org.jackhuang.hellominecraft.util.Pair;
import org.jackhuang.hellominecraft.util.StrUtils; import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.util.Utils; import org.jackhuang.hellominecraft.util.Utils;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.util.system.IOUtils; import org.jackhuang.hellominecraft.util.sys.IOUtils;
import org.jackhuang.hellominecraft.util.system.ZipEngine; import org.jackhuang.hellominecraft.util.sys.ZipEngine;
import org.jackhuang.hellominecraft.util.ui.WebPage; import org.jackhuang.hellominecraft.util.net.WebPage;
import org.jackhuang.hellominecraft.util.ui.checktree.CheckBoxTreeNode; import org.jackhuang.hellominecraft.util.ui.checktree.CheckBoxTreeNode;
import org.jackhuang.hellominecraft.util.ui.wizard.spi.DeferredWizardResult; import org.jackhuang.hellominecraft.util.ui.wizard.spi.DeferredWizardResult;
import org.jackhuang.hellominecraft.util.ui.wizard.spi.ResultProgressHandle; import org.jackhuang.hellominecraft.util.ui.wizard.spi.ResultProgressHandle;
@@ -95,7 +96,7 @@ public class ModpackWizard extends WizardBranchController {
if (settings.containsKey(ModpackDescriptionPanel.KEY_MODPACK_DESCRITION)) if (settings.containsKey(ModpackDescriptionPanel.KEY_MODPACK_DESCRITION))
try { try {
map.put("description", new org.markdown4j.Markdown4jProcessor().process((String) settings.get(ModpackDescriptionPanel.KEY_MODPACK_DESCRITION))); map.put("description", new org.markdown4j.Markdown4jProcessor().process((String) settings.get(ModpackDescriptionPanel.KEY_MODPACK_DESCRITION)));
} catch (Exception ex) { } catch (IOException ex) {
progress.failed(C.i18n("modpack.export_error") + ": " + StrUtils.getStackTrace(ex), true); progress.failed(C.i18n("modpack.export_error") + ": " + StrUtils.getStackTrace(ex), true);
} }
try { try {
@@ -113,33 +114,33 @@ public class ModpackWizard extends WizardBranchController {
boolean including = false; boolean including = false;
if ((Boolean) settings.get(ModpackInitializationPanel.KEY_INCLUDING_LAUNCHER)) { if ((Boolean) settings.get(ModpackInitializationPanel.KEY_INCLUDING_LAUNCHER)) {
boolean flag = true; boolean flag = true;
ZipEngine engine = new ZipEngine(loc); try (ZipEngine engine = new ZipEngine(loc)) {
Config s = new Config(); Config s = new Config();
if (!IOUtils.isAbsolutePath(Settings.getInstance().getBgpath())) if (!IOUtils.isAbsolutePath(Settings.getInstance().getBgpath()))
s.setBgpath(Settings.getInstance().getBgpath()); s.setBgpath(Settings.getInstance().getBgpath());
s.setDownloadType(Settings.getInstance().getDownloadType()); s.setDownloadType(Settings.getInstance().getDownloadType());
engine.putTextFile(C.GSON.toJson(s), "hmcl.json"); engine.putTextFile(C.GSON.toJson(s), "hmcl.json");
engine.putFile(modpack, "modpack.zip"); engine.putFile(modpack, "modpack.zip");
File bg = new File("bg"); File bg = new File("bg");
if (bg.isDirectory()) if (bg.isDirectory())
engine.putDirectory(bg); engine.putDirectory(bg);
bg = new File("background.png"); bg = new File("background.png");
if (bg.isFile()) if (bg.isFile())
engine.putFile(bg, "background.png"); engine.putFile(bg, "background.png");
bg = new File("background.jpg"); bg = new File("background.jpg");
if (bg.isFile()) if (bg.isFile())
engine.putFile(bg, "background.jpg"); engine.putFile(bg, "background.jpg");
for (URL u : Utils.getURL()) for (URL u : Utils.getURL())
try { try {
File f = new File(u.toURI()); File f = new File(u.toURI());
if (f.getName().endsWith(".exe") || f.getName().endsWith(".jar")) if (f.getName().endsWith(".exe") || f.getName().endsWith(".jar"))
engine.putFile(f, f.getName()); engine.putFile(f, f.getName());
} catch (Exception e) { } catch (IOException | URISyntaxException e) {
HMCLog.err("Failed to add launcher files.", e); HMCLog.err("Failed to add launcher files.", e);
flag = false; flag = false;
break; break;
} }
engine.closeFile(); }
if (flag) { if (flag) {
including = true; including = true;
if (!modpack.delete()) if (!modpack.delete())

View File

@@ -26,13 +26,13 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import static org.jackhuang.hellominecraft.launcher.Main.LAUNCHER_VERSION; import static org.jackhuang.hellominecraft.launcher.Main.LAUNCHER_VERSION;
import org.jackhuang.hellominecraft.launcher.setting.Settings; import org.jackhuang.hellominecraft.launcher.setting.Settings;
import org.jackhuang.hellominecraft.util.NetUtils; import org.jackhuang.hellominecraft.util.net.NetUtils;
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.system.OS; import org.jackhuang.hellominecraft.util.sys.OS;
import org.jackhuang.hellominecraft.util.ui.LogWindow; import org.jackhuang.hellominecraft.util.ui.LogWindow;
/** /**
@@ -48,6 +48,7 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
put("MessageBox", ""); put("MessageBox", "");
put("AWTError", ""); put("AWTError", "");
put("JFileChooser", "Has your operating system been installed completely or is a ghost system?"); put("JFileChooser", "Has your operating system been installed completely or is a ghost system?");
put("JSystemFileChooser", "Has your operating system been installed completely or is a ghost system?");
put("Jce", "Has your operating system been installed completely or is a ghost system?"); put("Jce", "Has your operating system been installed completely or is a ghost system?");
put("couldn't create component peer", "Fucking computer!"); put("couldn't create component peer", "Fucking computer!");
put("sun.awt.shell.Win32ShellFolder2", "crash.user_fault"); put("sun.awt.shell.Win32ShellFolder2", "crash.user_fault");
@@ -110,8 +111,8 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
System.out.println(text); System.out.println(text);
if (checkThrowable(e) && !System.getProperty("java.vm.name").contains("OpenJDK")) { if (checkThrowable(e) && !System.getProperty("java.vm.name").contains("OpenJDK")) {
SwingUtilities.invokeLater(() -> LogWindow.INSTANCE.showAsCrashWindow(Settings.UPDATE_CHECKER.OUT_DATED)); SwingUtilities.invokeLater(() -> LogWindow.INSTANCE.showAsCrashWindow(Settings.UPDATE_CHECKER.isOutOfDate()));
if (!Settings.UPDATE_CHECKER.OUT_DATED) if (!Settings.UPDATE_CHECKER.isOutOfDate())
reportToServer(text, s); reportToServer(text, s);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
@@ -122,7 +123,7 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
void showMessage(String s) { void showMessage(String s) {
try { try {
MessageBox.Show(s, "ERROR", MessageBox.ERROR_MESSAGE); MessageBox.show(s, "ERROR", MessageBox.ERROR_MESSAGE);
} catch (Throwable e) { } catch (Throwable e) {
LOGGER.log(Level.SEVERE, "ERROR", e); LOGGER.log(Level.SEVERE, "ERROR", e);
} }
@@ -131,7 +132,7 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
private static final HashSet<String> THROWABLE_SET = new HashSet<>(); private static final HashSet<String> THROWABLE_SET = new HashSet<>();
void reportToServer(final String text, String stacktrace) { void reportToServer(final String text, String stacktrace) {
if (THROWABLE_SET.contains(stacktrace)) if (THROWABLE_SET.contains(stacktrace) || stacktrace.contains("Font") || stacktrace.contains("InternalError"))
return; return;
THROWABLE_SET.add(stacktrace); THROWABLE_SET.add(stacktrace);
Thread t = new Thread(() -> { Thread t = new Thread(() -> {

View File

@@ -17,11 +17,11 @@
*/ */
package org.jackhuang.hellominecraft.launcher.util; package org.jackhuang.hellominecraft.launcher.util;
import java.util.ArrayList;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.api.IPlugin; import org.jackhuang.hellominecraft.launcher.api.IPlugin;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator; import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.auth.OfflineAuthenticator; import org.jackhuang.hellominecraft.launcher.core.auth.OfflineAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.auth.SkinmeAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider; import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.core.auth.YggdrasilAuthenticator; import org.jackhuang.hellominecraft.launcher.core.auth.YggdrasilAuthenticator;
import org.jackhuang.hellominecraft.launcher.core.launch.LaunchOptions; import org.jackhuang.hellominecraft.launcher.core.launch.LaunchOptions;
@@ -37,9 +37,7 @@ import org.jackhuang.hellominecraft.util.func.Consumer;
*/ */
public class DefaultPlugin implements IPlugin { public class DefaultPlugin implements IPlugin {
YggdrasilAuthenticator YGGDRASIL_LOGIN = null; ArrayList<IAuthenticator> auths = new ArrayList<>();
OfflineAuthenticator OFFLINE_LOGIN = null;
SkinmeAuthenticator SKINME_LOGIN = null;
@Override @Override
public IMinecraftService provideMinecraftService(Object profile) { public IMinecraftService provideMinecraftService(Object profile) {
@@ -49,20 +47,17 @@ public class DefaultPlugin implements IPlugin {
@Override @Override
public void onRegisterAuthenticators(Consumer<IAuthenticator> apply) { public void onRegisterAuthenticators(Consumer<IAuthenticator> apply) {
String clientToken = Settings.getInstance().getClientToken(); String clientToken = Settings.getInstance().getClientToken();
OFFLINE_LOGIN = new OfflineAuthenticator(clientToken); auths.add(new OfflineAuthenticator(clientToken));
OFFLINE_LOGIN.onLoadSettings(Settings.getInstance().getAuthenticatorConfig(OFFLINE_LOGIN.id())); auths.add(new YggdrasilAuthenticator(clientToken));
YGGDRASIL_LOGIN = new YggdrasilAuthenticator(clientToken);
YGGDRASIL_LOGIN.onLoadSettings(Settings.getInstance().getAuthenticatorConfig(YGGDRASIL_LOGIN.id()));
Runtime.getRuntime().addShutdownHook(new Thread() { Runtime.getRuntime().addShutdownHook(new Thread(() -> {
@Override for (IAuthenticator i : auths)
public void run() { Settings.getInstance().setAuthenticatorConfig(i.id(), i.onSaveSettings());
Settings.getInstance().setAuthenticatorConfig(OFFLINE_LOGIN.id(), OFFLINE_LOGIN.onSaveSettings()); }));
Settings.getInstance().setAuthenticatorConfig(YGGDRASIL_LOGIN.id(), YGGDRASIL_LOGIN.onSaveSettings()); for (IAuthenticator i : auths) {
} i.onLoadSettings(Settings.getInstance().getAuthenticatorConfig(i.id()));
}); apply.accept(i);
apply.accept(OFFLINE_LOGIN); }
apply.accept(YGGDRASIL_LOGIN);
} }
@Override @Override

View File

@@ -19,7 +19,7 @@ package org.jackhuang.hellominecraft.launcher.util;
import java.io.File; import java.io.File;
import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileFilter;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.sys.FileUtils;
/** /**
* *

View File

@@ -31,7 +31,7 @@ import org.jackhuang.hellominecraft.launcher.setting.Settings;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.EventHandler; import org.jackhuang.hellominecraft.util.EventHandler;
import org.jackhuang.hellominecraft.util.func.Consumer; import org.jackhuang.hellominecraft.util.func.Consumer;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
/** /**
* *

View File

@@ -29,22 +29,16 @@ import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.core.download.MinecraftDownloadService; import org.jackhuang.hellominecraft.launcher.core.download.MinecraftDownloadService;
import org.jackhuang.hellominecraft.launcher.core.launch.LaunchOptions; import org.jackhuang.hellominecraft.launcher.core.launch.LaunchOptions;
import org.jackhuang.hellominecraft.launcher.core.launch.MinecraftLoader; import org.jackhuang.hellominecraft.launcher.core.launch.MinecraftLoader;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftAssetService; import org.jackhuang.hellominecraft.launcher.core.service.*;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftDownloadService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftInstallerService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftLoader;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftModService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftProvider;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.mod.MinecraftModService; import org.jackhuang.hellominecraft.launcher.core.mod.MinecraftModService;
import org.jackhuang.hellominecraft.launcher.core.mod.ModpackManager; import org.jackhuang.hellominecraft.launcher.core.mod.ModpackManager;
import org.jackhuang.hellominecraft.launcher.setting.Profile; import org.jackhuang.hellominecraft.launcher.setting.Profile;
import org.jackhuang.hellominecraft.launcher.setting.VersionSetting; import org.jackhuang.hellominecraft.launcher.setting.VersionSetting;
import org.jackhuang.hellominecraft.launcher.ui.MainFrame; import org.jackhuang.hellominecraft.launcher.ui.MainFrame;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.util.tasks.TaskWindow; import org.jackhuang.hellominecraft.util.task.TaskWindow;
/** /**
* *
@@ -60,7 +54,20 @@ public class HMCLMinecraftService extends IMinecraftService {
this.provider = new HMCLGameProvider(this); this.provider = new HMCLGameProvider(this);
provider.initializeMiencraft(); provider.initializeMiencraft();
provider.onRefreshingVersions.register(versionSettings::clear); provider.onRefreshingVersions.register(versionSettings::clear);
provider.onRefreshedVersions.register(this::checkModpack); provider.onRefreshedVersions.register(() -> {
if (!checkingModpack) {
checkingModpack = true;
if (version().getVersionCount() == 0) {
File modpack = new File("modpack.zip");
if (modpack.exists())
SwingUtilities.invokeLater(() -> {
if (TaskWindow.factory().execute(ModpackManager.install(MainFrame.INSTANCE, modpack, this, null)))
version().refreshVersions();
checkedModpack = true;
});
}
}
});
provider.onLoadedVersion.register(this::loadVersionSetting); provider.onLoadedVersion.register(this::loadVersionSetting);
this.mms = new MinecraftModService(this); this.mms = new MinecraftModService(this);
this.mds = new MinecraftDownloadService(this); this.mds = new MinecraftDownloadService(this);
@@ -70,21 +77,6 @@ public class HMCLMinecraftService extends IMinecraftService {
public boolean checkedModpack = false, checkingModpack = false; public boolean checkedModpack = false, checkingModpack = false;
private void checkModpack() {
if (!checkingModpack) {
checkingModpack = true;
if (version().getVersionCount() == 0) {
File modpack = new File("modpack.zip");
if (modpack.exists())
SwingUtilities.invokeLater(() -> {
if (TaskWindow.execute(ModpackManager.install(MainFrame.INSTANCE, modpack, this, null)))
version().refreshVersions();
checkedModpack = true;
});
}
}
}
private void loadVersionSetting(String id) { private void loadVersionSetting(String id) {
if (provider.getVersionById(id) == null) if (provider.getVersionById(id) == null)
return; return;

View File

@@ -43,7 +43,7 @@ public final class MinecraftCrashAdvicer {
return C.i18n("crash.advice.ConcurrentModificationException"); return C.i18n("crash.advice.ConcurrentModificationException");
else if (trace.contains("securityexception")) else if (trace.contains("securityexception"))
return C.i18n("crash.advice.SecurityException"); return C.i18n("crash.advice.SecurityException");
else if (trace.contains("nosuchfieldexception") || trace.contains("nosuchfielderror")) else if (trace.contains("nosuchfieldexception") || trace.contains("nosuchmethodexception") || trace.contains("nosuchfielderror") || trace.contains("nosuchmethoderror"))
return C.i18n("crash.advice.NoSuchFieldError"); return C.i18n("crash.advice.NoSuchFieldError");
else if (trace.contains("outofmemory") || trace.contains("out of memory")) else if (trace.contains("outofmemory") || trace.contains("out of memory"))
return C.i18n("crash.advice.OutOfMemoryError"); return C.i18n("crash.advice.OutOfMemoryError");

View File

@@ -18,8 +18,6 @@
package org.jackhuang.hellominecraft.launcher.util.upgrade; package org.jackhuang.hellominecraft.launcher.util.upgrade;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@@ -37,19 +35,19 @@ import java.util.jar.JarOutputStream;
import java.util.jar.Pack200; import java.util.jar.Pack200;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.MCUtils; import org.jackhuang.hellominecraft.launcher.core.MCUtils;
import org.jackhuang.hellominecraft.util.tasks.Task; import org.jackhuang.hellominecraft.util.task.Task;
import org.jackhuang.hellominecraft.util.tasks.TaskWindow; import org.jackhuang.hellominecraft.util.task.TaskWindow;
import org.jackhuang.hellominecraft.util.tasks.download.FileDownloadTask; import org.jackhuang.hellominecraft.util.net.FileDownloadTask;
import org.jackhuang.hellominecraft.util.ArrayUtils; import org.jackhuang.hellominecraft.util.ArrayUtils;
import org.jackhuang.hellominecraft.util.MessageBox; import org.jackhuang.hellominecraft.util.MessageBox;
import org.jackhuang.hellominecraft.util.UpdateChecker; import org.jackhuang.hellominecraft.util.UpdateChecker;
import org.jackhuang.hellominecraft.util.Utils; import org.jackhuang.hellominecraft.util.Utils;
import org.jackhuang.hellominecraft.util.VersionNumber; import org.jackhuang.hellominecraft.util.VersionNumber;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.util.system.IOUtils; import org.jackhuang.hellominecraft.util.sys.IOUtils;
import org.jackhuang.hellominecraft.util.system.OS; import org.jackhuang.hellominecraft.util.sys.OS;
/** /**
* *
@@ -101,7 +99,7 @@ public class AppDataUpgrader extends IUpgrader {
@Override @Override
public boolean call(Object sender, final VersionNumber number) { public boolean call(Object sender, final VersionNumber number) {
((UpdateChecker) sender).requestDownloadLink().reg(map -> { ((UpdateChecker) sender).requestDownloadLink().reg(map -> {
if (MessageBox.Show(C.i18n("update.newest_version") + number.firstVer + "." + number.secondVer + "." + number.thirdVer + "\n" if (MessageBox.show(C.i18n("update.newest_version") + number.firstVer + "." + number.secondVer + "." + number.thirdVer + "\n"
+ C.i18n("update.should_open_link"), + C.i18n("update.should_open_link"),
MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
if (map != null && map.containsKey("pack")) if (map != null && map.containsKey("pack"))
@@ -109,7 +107,7 @@ public class AppDataUpgrader extends IUpgrader {
String hash = null; String hash = null;
if (map.containsKey("packsha1")) if (map.containsKey("packsha1"))
hash = map.get("packsha1"); hash = map.get("packsha1");
if (TaskWindow.factory().append(new AppDataUpgraderTask(map.get("pack"), number.version, hash)).create()) { if (TaskWindow.factory().append(new AppDataUpgraderTask(map.get("pack"), number.version, hash)).execute()) {
new ProcessBuilder(new String[] { IOUtils.getJavaDir(), "-jar", AppDataUpgraderTask.getSelf(number.version).getAbsolutePath() }).directory(new File(".")).start(); new ProcessBuilder(new String[] { IOUtils.getJavaDir(), "-jar", AppDataUpgraderTask.getSelf(number.version).getAbsolutePath() }).directory(new File(".")).start();
System.exit(0); System.exit(0);
} }
@@ -130,7 +128,7 @@ public class AppDataUpgrader extends IUpgrader {
} catch (URISyntaxException | IOException e) { } catch (URISyntaxException | IOException e) {
HMCLog.warn("Failed to browse uri: " + url, e); HMCLog.warn("Failed to browse uri: " + url, e);
Utils.setClipborad(url); Utils.setClipborad(url);
MessageBox.Show(C.i18n("update.no_browser")); MessageBox.show(C.i18n("update.no_browser"));
} }
} }
}).execute(); }).execute();
@@ -162,10 +160,10 @@ public class AppDataUpgrader extends IUpgrader {
} }
@Override @Override
public void executeTask() throws Exception { public void executeTask(boolean areDependTasksSucceeded) throws Exception {
HashMap<String, String> json = new HashMap<>(); HashMap<String, String> json = new HashMap<>();
File f = getSelf(newestVersion); File f = getSelf(newestVersion);
if (!f.getParentFile().exists() && !f.getParentFile().mkdirs()) if (!FileUtils.makeDirectory(f.getParentFile()))
HMCLog.warn("Failed to make directories: " + f.getParent()); HMCLog.warn("Failed to make directories: " + f.getParent());
for (int i = 0; f.exists(); i++) for (int i = 0; f.exists(); i++)
@@ -173,8 +171,8 @@ public class AppDataUpgrader extends IUpgrader {
if (!f.createNewFile()) if (!f.createNewFile())
HMCLog.warn("Failed to create new file: " + f); HMCLog.warn("Failed to create new file: " + f);
try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(f))) { try (JarOutputStream jos = new JarOutputStream(FileUtils.openOutputStream(f))) {
Pack200.newUnpacker().unpack(new GZIPInputStream(new FileInputStream(tempFile)), jos); Pack200.newUnpacker().unpack(new GZIPInputStream(FileUtils.openInputStream(tempFile)), jos);
} }
json.put("ver", newestVersion); json.put("ver", newestVersion);
json.put("loc", f.getAbsolutePath()); json.put("loc", f.getAbsolutePath());

View File

@@ -19,13 +19,13 @@ package org.jackhuang.hellominecraft.launcher.util.upgrade;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.util.tasks.TaskWindow; import org.jackhuang.hellominecraft.util.task.TaskWindow;
import org.jackhuang.hellominecraft.util.tasks.download.FileDownloadTask; import org.jackhuang.hellominecraft.util.net.FileDownloadTask;
import org.jackhuang.hellominecraft.util.ArrayUtils; import org.jackhuang.hellominecraft.util.ArrayUtils;
import org.jackhuang.hellominecraft.util.VersionNumber; import org.jackhuang.hellominecraft.util.VersionNumber;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.sys.FileUtils;
import org.jackhuang.hellominecraft.util.system.IOUtils; import org.jackhuang.hellominecraft.util.sys.IOUtils;
/** /**
* *
@@ -48,7 +48,7 @@ public class NewFileUpgrader extends IUpgrader {
public boolean call(Object sender, VersionNumber number) { public boolean call(Object sender, VersionNumber number) {
String str = requestDownloadLink(); String str = requestDownloadLink();
File newf = new File(FileUtils.getName(str)); File newf = new File(FileUtils.getName(str));
if (TaskWindow.factory().append(new FileDownloadTask(str, newf)).create()) { if (TaskWindow.factory().append(new FileDownloadTask(str, newf)).execute()) {
try { try {
new ProcessBuilder(new String[] { IOUtils.tryGetCanonicalFilePath(newf), "--removeOldLauncher", IOUtils.getRealPath() }).directory(new File(".")).start(); new ProcessBuilder(new String[] { IOUtils.tryGetCanonicalFilePath(newf), "--removeOldLauncher", IOUtils.getRealPath() }).directory(new File(".")).start();
} catch (IOException ex) { } catch (IOException ex) {

View File

@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. * along with this program.
*/ */
package org.jackhuang.hellominecraft.lookandfeel.comp; package org.jackhuang.hellominecraft.lookandfeel;
import java.awt.Color; import java.awt.Color;
import org.jackhuang.hellominecraft.util.ui.GraphicsUtils; import org.jackhuang.hellominecraft.util.ui.GraphicsUtils;
@@ -28,7 +28,5 @@ public class ConstomButton extends javax.swing.JButton {
prelightFg = GraphicsUtils.getWebColorWithAlpha("FFFFFF7F"), prelightBg = GraphicsUtils.getWebColorWithAlpha("FFFFFF7F"), prelightFg = GraphicsUtils.getWebColorWithAlpha("FFFFFF7F"), prelightBg = GraphicsUtils.getWebColorWithAlpha("FFFFFF7F"),
activeFg = GraphicsUtils.getWebColorWithAlpha("EAEDF83F"), activeBg = GraphicsUtils.getWebColorWithAlpha("EAEDF83F"); activeFg = GraphicsUtils.getWebColorWithAlpha("EAEDF83F"), activeBg = GraphicsUtils.getWebColorWithAlpha("EAEDF83F");
public int drawPercent = 0; public int drawPercent = 0;
public long lastDrawTime = 0;
public int radix = 0; public int radix = 0;
public boolean notDraw = false;
} }

View File

@@ -18,12 +18,13 @@ package org.jackhuang.hellominecraft.lookandfeel;
import java.awt.Color; import java.awt.Color;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.text.ParseException; import java.text.ParseException;
import java.util.Map; import java.util.Map;
import javax.swing.UIDefaults; import javax.swing.UIDefaults;
import javax.swing.plaf.synth.SynthLookAndFeel; import javax.swing.plaf.synth.SynthLookAndFeel;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.util.NetUtils; import org.jackhuang.hellominecraft.util.sys.IOUtils;
/** /**
* *
@@ -37,7 +38,7 @@ public class HelloMinecraftLookAndFeel extends SynthLookAndFeel {
* Creates a new instance of NimbusLookAndFeel * Creates a new instance of NimbusLookAndFeel
* *
* @throws java.text.ParseException error parsing the xml, it must not * @throws java.text.ParseException error parsing the xml, it must not
* happen. * happen.
*/ */
public HelloMinecraftLookAndFeel() throws ParseException { public HelloMinecraftLookAndFeel() throws ParseException {
this(DEFAULT_SETTINGS); this(DEFAULT_SETTINGS);
@@ -45,14 +46,18 @@ public class HelloMinecraftLookAndFeel extends SynthLookAndFeel {
public HelloMinecraftLookAndFeel(Map<String, String> settings) throws ParseException { public HelloMinecraftLookAndFeel(Map<String, String> settings) throws ParseException {
try { try {
String s = NetUtils.getStreamContent(HelloMinecraftLookAndFeel.class.getResourceAsStream("/org/jackhuang/hellominecraft/lookandfeel/synth.xml"), "UTF-8"); try (InputStream is = HelloMinecraftLookAndFeel.class.getResourceAsStream("/org/jackhuang/hellominecraft/lookandfeel/synth.xml")) {
for (String ss : settings.keySet()) String s = IOUtils.toString(is, "UTF-8");
s = s.replace("${" + ss + "}", settings.get(ss)); for (Map.Entry<String, String> ss : settings.entrySet())
load(new ByteArrayInputStream(s.getBytes("UTF-8")), HelloMinecraftLookAndFeel.class); s = s.replace("${" + ss.getKey() + "}", ss.getValue());
load(new ByteArrayInputStream(s.getBytes("UTF-8")), HelloMinecraftLookAndFeel.class);
}
} catch (Throwable ex) { } catch (Throwable ex) {
HMCLog.err("This fucking exception should not happen. Retry backup solution.", ex); HMCLog.err("This fucking exception should not happen. Retry backup solution.", ex);
try { try {
load(HelloMinecraftLookAndFeel.class.getResourceAsStream("/org/jackhuang/hellominecraft/lookandfeel/synth_backup.xml"), HelloMinecraftLookAndFeel.class); try (InputStream is = HelloMinecraftLookAndFeel.class.getResourceAsStream("/org/jackhuang/hellominecraft/lookandfeel/synth_backup.xml")) {
load(is, HelloMinecraftLookAndFeel.class);
}
} catch (Throwable e) { } catch (Throwable e) {
HMCLog.err("User fault", e); HMCLog.err("User fault", e);
} }

Some files were not shown because too many files have changed in this diff Show More