Clean up again

This commit is contained in:
huangyuhui
2017-01-27 22:41:34 +08:00
parent 809d7378e2
commit 972c4758b1
120 changed files with 353 additions and 1725 deletions

View File

@@ -27,13 +27,6 @@ public class PluginManager {
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) {
try {
IPlugin p = (IPlugin) cls.newInstance();

View File

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

View File

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

View File

@@ -28,15 +28,6 @@ public class 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() {
return key;
}

View File

@@ -31,6 +31,7 @@ import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.util.tasks.Task;
import org.jackhuang.hellominecraft.util.tasks.download.FileDownloadTask;
import org.jackhuang.hellominecraft.util.code.DigestUtils;
import org.jackhuang.hellominecraft.util.system.FileUtils;
import org.jackhuang.hellominecraft.util.system.IOUtils;
import org.jackhuang.hellominecraft.util.tasks.TaskInfo;
@@ -113,8 +114,8 @@ public abstract class IAssetsHandler {
boolean need = true;
try {
if (location.exists()) {
FileInputStream fis = new FileInputStream(location);
String sha = DigestUtils.sha1Hex(IOUtils.readFully(fis).toByteArray());
FileInputStream fis = FileUtils.openInputStream(location);
String sha = DigestUtils.sha1Hex(IOUtils.toByteArray(fis));
IOUtils.closeQuietly(fis);
if (contents.get(i).geteTag().equals(sha)) {
++hasDownloaded;

View File

@@ -57,7 +57,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
public Task downloadAssets(final MinecraftVersion mv) throws GameException {
if (mv == null)
return null;
return IAssetsHandler.ASSETS_HANDLER.getList(mv.resolve(service.version()), 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
@@ -155,7 +155,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
if (index == null)
return false;
for (Map.Entry entry : index.getFileMap().entrySet())
for (Map.Entry<String, AssetsObject> entry : index.getFileMap().entrySet())
if (!new File(getAssets(), "objects/" + ((AssetsObject) entry.getValue()).getHash().substring(0, 2) + "/" + ((AssetsObject) entry.getValue()).getHash()).exists())
return false;
return true;
@@ -185,7 +185,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
int cnt = 0;
HMCLog.log("Reconstructing virtual assets folder at " + virtualRoot);
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 original = new File(assetsDir, "objects/" + ((AssetsObject) entry.getValue()).getHash().substring(0, 2) + "/" + ((AssetsObject) entry.getValue()).getHash());
if (original.exists()) {

View File

@@ -87,13 +87,13 @@ public abstract class IAuthenticator {
public abstract void logOut();
public Map onSaveSettings() {
public Map<?, ?> onSaveSettings() {
HashMap<String, String> m = new HashMap<>();
m.put("IAuthenticator_UserName", username);
return m;
}
public void onLoadSettings(Map m) {
public void onLoadSettings(Map<?, ?> m) {
if (m == null)
return;
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 {
Map<String, String> uuidMap = new HashMap<>();
Map uuidMap = new HashMap<>();
public OfflineAuthenticator(String clientToken) {
super(clientToken);
@@ -42,7 +42,7 @@ public final class OfflineAuthenticator extends IAuthenticator {
return;
Object o = m.get("uuidMap");
if (o != null && o instanceof Map)
uuidMap = (Map<String, String>) o;
uuidMap = (Map<?, ?>) o;
}
@Override
@@ -57,8 +57,8 @@ public final class OfflineAuthenticator extends IAuthenticator {
if (StrUtils.isBlank(info.username))
throw new AuthenticationException(C.i18n("login.no_Player007"));
String uuid = getUUIDFromUserName(info.username);
if (uuidMap != null && uuidMap.containsKey(uuid))
uuid = uuidMap.get(info.username);
if (uuidMap != null && uuidMap.containsKey(info.username) && uuidMap.get(info.username) instanceof String)
uuid = (String) uuidMap.get(info.username);
else {
if (uuidMap == null)
uuidMap = new HashMap<>();
@@ -69,7 +69,8 @@ public final class OfflineAuthenticator extends IAuthenticator {
.setSession(uuid)
.setUserId(uuid)
.setAccessToken(uuid)
.setUserType("Legacy");
.setUserType("Legacy")
.setClientIdentifier(clientToken);
}
public static String getUUIDFromUserName(String str) {

View File

@@ -86,7 +86,8 @@ public final class YggdrasilAuthenticator extends IAuthenticator {
.setUserProperties(new GsonBuilder().registerTypeAdapter(PropertyMap.class, new PropertyMap.LegacySerializer()).create().toJson(ua.getUserProperties()))
.setUserPropertyMap(new GsonBuilder().registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create().toJson(ua.getUserProperties()))
.setAccessToken(ua.getAuthenticatedToken())
.setSession(ua.getAuthenticatedToken());
.setSession(ua.getAuthenticatedToken())
.setClientIdentifier(clientToken);
}
@Override

View File

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

View File

@@ -17,12 +17,18 @@
*/
package org.jackhuang.hellominecraft.launcher.core.download;
import com.google.gson.annotations.SerializedName;
/**
*
* @author huangyuhui
*/
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;
import com.google.gson.annotations.SerializedName;
/**
*
* @author huangyuhui
*/
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;
public String getUrl(DownloadType type) {

View File

@@ -19,9 +19,12 @@ package org.jackhuang.hellominecraft.launcher.core.install;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.util.tasks.Task;
/**
@@ -29,6 +32,9 @@ import org.jackhuang.hellominecraft.util.tasks.Task;
* @author huangyuhui
*/
public abstract class InstallerVersionList {
public Map<String, List<InstallerVersion>> versionMap;
public List<InstallerVersion> versions;
/**
* Refresh installer versions list from the downloaded content.
@@ -53,7 +59,17 @@ public abstract class InstallerVersionList {
*
* @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.

View File

@@ -62,8 +62,8 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
return null;
else
return new FileDownloadTask(service.getDownloadType().getProvider().getParsedDownloadURL(v.installer), filepath).setTag("forge")
.after(new ForgeInstaller(service, filepath))
.after(new DeleteFileTask(filepath));
.with(new ForgeInstaller(service, filepath))
.with(new DeleteFileTask(filepath));
}
@Override
@@ -72,9 +72,9 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
if (v.installer == null)
return null;
OptiFineDownloadFormatter task = new OptiFineDownloadFormatter(v.installer);
return task.after(new FileDownloadTask(filepath).registerPreviousResult(task).setTag("optifine"))
.after(new OptiFineInstaller(service, installId, v, filepath))
.after(new DeleteFileTask(filepath));
return task.with(new FileDownloadTask(filepath).registerPreviousResult(task).setTag("optifine"))
.with(new OptiFineInstaller(service, installId, v, filepath))
.with(new DeleteFileTask(filepath));
}
@Override
@@ -83,7 +83,7 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
throw new Error("Download lite loader but the version is not ll's.");
File filepath = IOUtils.tryGetCanonicalFile("liteloader-universal.jar");
FileDownloadTask task = (FileDownloadTask) new FileDownloadTask(v.universal, filepath).setTag("LiteLoader");
return task.after(new LiteLoaderInstaller(service, installId, (LiteLoaderVersionList.LiteLoaderInstallerVersion) v).registerPreviousResult(task))
.after(new DeleteFileTask(filepath));
return task.with(new LiteLoaderInstaller(service, installId, (LiteLoaderVersionList.LiteLoaderInstallerVersion) v).registerPreviousResult(task))
.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.CompressingUtils;
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)
CompressingUtils.unzip(new File(src1), file);
CompressingUtils.zip(file.getAbsolutePath(), dest.getAbsolutePath());
FileUtils.deleteDirectory(file);
}
}

View File

@@ -81,7 +81,7 @@ public class ForgeInstaller extends Task {
File file = new File(gameDir, "libraries/" + forge.getDownloadInfo().path);
if (file.getParentFile().mkdirs())
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);
}
mp.version().refreshVersions();

View File

@@ -1,38 +0,0 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.launcher.core.install.forge;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.jackhuang.hellominecraft.launcher.core.install.PackMinecraftInstaller;
/**
*
* @author huangyuhui
*/
public class ForgeOldInstaller {
public static void install(String destMinecraftJar, String srcMinecraftJar, String forgeUniversal) throws IOException {
ArrayList<String> al = new ArrayList<>();
al.add(srcMinecraftJar);
al.add(forgeUniversal);
new PackMinecraftInstaller(al, new File(destMinecraftJar)).install();
}
}

View File

@@ -47,19 +47,6 @@ public class 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() {
return profileName;
}

View File

@@ -76,16 +76,4 @@ public class MinecraftForgeVersion {
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,7 +22,6 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
@@ -48,8 +47,6 @@ public class MinecraftForgeVersionList extends InstallerVersionList {
}
public MinecraftForgeVersionRoot root;
public Map<String, List<InstallerVersion>> versionMap;
public List<InstallerVersion> versions;
@Override
public Task refresh(String[] needed) {
@@ -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
public String getName() {
return "Forge - MinecraftForge Offical Site";

View File

@@ -63,7 +63,7 @@ public class LiteLoaderInstaller extends Task implements PreviousResultRegistrar
MinecraftVersion mv = (MinecraftVersion) service.version().getVersionById(installId).clone();
mv.inheritsFrom = mv.id;
mv.jar = mv.jar == null ? mv.id : mv.jar;
mv.libraries = new ArrayList(Arrays.asList(version.libraries));
mv.libraries = new ArrayList<>(Arrays.asList(version.libraries));
MinecraftLibrary ml = new MinecraftLibrary("com.mumfrey:liteloader:" + version.selfVersion);
//ml.url = "http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + version.mcVersion + "/liteloader-" + version.selfVersion + ".jar";
@@ -92,7 +92,7 @@ public class LiteLoaderInstaller extends Task implements PreviousResultRegistrar
ArrayList<PreviousResult<File>> pre = new ArrayList<>();
@Override
public Task registerPreviousResult(PreviousResult pr) {
public Task registerPreviousResult(PreviousResult<File> pr) {
pre.add(pr);
return this;
}

View File

@@ -22,13 +22,11 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
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.InstallerVersion;
import org.jackhuang.hellominecraft.launcher.core.install.InstallerVersionNewerComparator;
import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.util.tasks.Task;
@@ -50,8 +48,6 @@ public class LiteLoaderVersionList extends InstallerVersionList {
}
public LiteLoaderVersionsRoot root;
public Map<String, List<InstallerVersion>> versionMap;
public List<InstallerVersion> versions;
@Override
public Task refresh(String[] needed) {
@@ -102,19 +98,6 @@ 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
public String getName() {
return "LiteLoader - LiteLoader Official Site(By: Mumfrey)";

View File

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

View File

@@ -42,10 +42,6 @@ public class OptiFineInstaller extends Task implements PreviousResultRegistrar<F
public InstallerVersionList.InstallerVersion version;
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) {
this.service = service;
this.installId = installId;
@@ -90,10 +86,10 @@ public class OptiFineInstaller extends Task implements PreviousResultRegistrar<F
return "OptiFine Installer";
}
ArrayList<PreviousResult<File>> pre = new ArrayList();
ArrayList<PreviousResult<File>> pre = new ArrayList<>();
@Override
public Task registerPreviousResult(PreviousResult pr) {
public Task registerPreviousResult(PreviousResult<File> pr) {
pre.add(pr);
return this;
}

View File

@@ -25,7 +25,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jackhuang.hellominecraft.util.C;
@@ -52,8 +51,6 @@ public class OptiFineBMCLVersionList extends InstallerVersionList {
}
public ArrayList<OptiFineVersion> root;
public Map<String, List<InstallerVersion>> versionMap;
public List<InstallerVersion> versions;
private static final Type TYPE = new TypeToken<ArrayList<OptiFineVersion>>() {
}.getType();
@@ -101,19 +98,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
public String getName() {
return "OptiFine - BMCLAPI(By: bangbang93)";

View File

@@ -25,7 +25,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.xml.parsers.DocumentBuilder;
@@ -59,9 +58,7 @@ public class OptiFineVersionList extends InstallerVersionList {
return instance;
}
public ArrayList<OptiFineVersion> root = new ArrayList();
public Map<String, List<InstallerVersion>> versionMap;
public List<InstallerVersion> versions;
public ArrayList<OptiFineVersion> root = new ArrayList<>();
@Override
public Task refresh(String[] sss) {
@@ -138,18 +135,4 @@ public class OptiFineVersionList extends InstallerVersionList {
public String getName() {
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,8 +22,6 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.List;
import org.jackhuang.hellominecraft.launcher.api.PluginManager;
import org.jackhuang.hellominecraft.launcher.core.GameException;
@@ -38,6 +36,7 @@ import org.jackhuang.hellominecraft.launcher.core.version.DecompressLibraryJob;
import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.EventHandler;
import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.util.code.Charsets;
import org.jackhuang.hellominecraft.util.logging.HMCLog;
import org.jackhuang.hellominecraft.util.system.FileUtils;
import org.jackhuang.hellominecraft.util.system.IOUtils;
@@ -153,7 +152,7 @@ public class GameLauncher {
*
* @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...");
service.version().onLaunch(options.getLaunchVersion());
boolean isWin = OS.os() == OS.WINDOWS;
@@ -161,13 +160,8 @@ public class GameLauncher {
if (!f.exists() && !f.createNewFile())
HMCLog.warn("Failed to create " + f);
BufferedWriter writer;
try (FileOutputStream fos = new FileOutputStream(f)) {
try {
writer = new BufferedWriter(new OutputStreamWriter(fos, System.getProperty("sun.jnu.encoding", "UTF-8")));
} catch (UnsupportedEncodingException ex) {
HMCLog.warn("Failed to create writer, will try again.", ex);
writer = new BufferedWriter(new OutputStreamWriter(fos, Charset.defaultCharset()));
}
try (FileOutputStream fos = FileUtils.openOutputStream(f)) {
writer = new BufferedWriter(new OutputStreamWriter(fos, Charsets.toCharset()));
if (isWin) {
writer.write("@echo off");
writer.newLine();

View File

@@ -18,7 +18,6 @@
package org.jackhuang.hellominecraft.launcher.core.mod;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
@@ -28,7 +27,6 @@ import java.util.Map;
import org.jackhuang.hellominecraft.util.logging.HMCLog;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftModService;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.util.code.DigestUtils;
import org.jackhuang.hellominecraft.util.system.FileUtils;
/**
@@ -113,11 +111,4 @@ public class MinecraftModService extends IMinecraftModService {
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

@@ -93,15 +93,15 @@ public final class ModpackManager {
// Read modpack name and description from `modpack.json`
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 (id == null)
if (map.containsKey("name") && map.get("name") instanceof String)
id = (String) map.get("name");
id = map.get("name");
if (id != null)
description += id;
if (map.containsKey("description") && map.get("description") instanceof String)
description += "\n" + (String) map.get("description");
description += "\n" + map.get("description");
}
if (id == null)
throw new IllegalStateException("Illegal modpack id!");
@@ -245,7 +245,7 @@ public final class ModpackManager {
*
* @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);
if (blacklist != null)
b.addAll(blacklist);
@@ -272,7 +272,7 @@ public final class ModpackManager {
mv.jar = r.version;
mv.runDir = "version";
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)
callback.call(zip);
} finally {

View File

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

View File

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

View File

@@ -46,14 +46,6 @@ public class MinecraftLibrary extends IMinecraftLibrary {
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.
*

View File

@@ -31,7 +31,6 @@ import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftProvider;
import org.jackhuang.hellominecraft.launcher.core.asset.AssetsIndex;
import org.jackhuang.hellominecraft.util.ArrayUtils;
import org.jackhuang.hellominecraft.util.Utils;
/**
*
@@ -213,6 +212,6 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
}
public Set<IMinecraftLibrary> getLibraries() {
return libraries == null ? new HashSet() : new HashSet(libraries);
return libraries == null ? new HashSet<>() : new HashSet<>(libraries);
}
}

View File

@@ -45,7 +45,7 @@ import org.jackhuang.hellominecraft.util.ui.SwingUtils;
*/
public class MinecraftVersionManager extends IMinecraftProvider {
final Map<String, MinecraftVersion> versions = new TreeMap();
final Map<String, MinecraftVersion> versions = new TreeMap<>();
/**
*

View File

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

View File

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

View File

@@ -98,7 +98,6 @@ public final class Main implements Runnable {
return "HMCL" + ' ' + LAUNCHER_VERSION;
}
public static final Main INSTANCE = new Main();
private static HelloMinecraftLookAndFeel LOOK_AND_FEEL;
private static final Logger LOGGER = Logger.getLogger(Main.class.getName());

View File

@@ -126,18 +126,10 @@ public final class Settings {
return SETTINGS.getConfigurations();
}
public static void setProfile(Profile ver) {
getProfiles().put(ver.getName(), ver);
}
public static Collection<Profile> getProfilesFiltered() {
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) {
if (ver == null || ver.getName() == null || getProfiles().containsKey(ver.getName()))
return false;
@@ -163,8 +155,8 @@ public final class Settings {
return flag;
}
public static final EventHandler<Profile> profileChangedEvent = new EventHandler(null);
public static final EventHandler<Void> profileLoadingEvent = new EventHandler(null);
public static final EventHandler<Profile> profileChangedEvent = new EventHandler<>(null);
public static final EventHandler<Void> profileLoadingEvent = new EventHandler<>(null);
static void onProfileChanged() {
Profile p = getLastProfile();

View File

@@ -93,27 +93,6 @@ public class VersionSetting {
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() {
Java j = getJava();
if (j.getHome() == null)
@@ -173,10 +152,6 @@ public class VersionSetting {
propertyChanged.execute("javaArgs");
}
public boolean hasJavaArgs() {
return StrUtils.isNotBlank(getJavaArgs().trim());
}
public String getMaxMemory() {
if (StrUtils.isBlank(maxMemory))
return String.valueOf(OS.getSuggestedMemorySize());

View File

@@ -1410,7 +1410,7 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi
private void loadProfiles() {
isLoading = true;
DefaultComboBoxModel model = new DefaultComboBoxModel();
DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
for (Profile s : Settings.getProfilesFiltered())
model.addElement(s.getName());
cboProfiles.setModel(model);
@@ -1423,7 +1423,7 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi
};
void loadVersions() {
DefaultComboBoxModel model = new DefaultComboBoxModel();
DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
for (MinecraftVersion each : Settings.getLastProfile().service().version().getVersions()) {
if (each.hidden)
continue;
@@ -1438,7 +1438,7 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi
public void versionChanged(String version) {
isLoading = true;
DefaultComboBoxModel model = (DefaultComboBoxModel) cboVersions.getModel();
DefaultComboBoxModel<String> model = (DefaultComboBoxModel<String>) cboVersions.getModel();
for (int i = 0; i < model.getSize(); ++i)
if (model.getElementAt(i).equals(version)) {
model.setSelectedItem(version);
@@ -1462,7 +1462,7 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi
txtGameDir.setText(t.getGameDir());
isLoading = true;
DefaultComboBoxModel model = (DefaultComboBoxModel) cboProfiles.getModel();
DefaultComboBoxModel<String> model = (DefaultComboBoxModel<String>) cboProfiles.getModel();
for (int i = 0; i < model.getSize(); ++i)
if (model.getElementAt(i).equals(t.getName())) {
model.setSelectedItem(t.getName());

View File

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

View File

@@ -124,7 +124,7 @@ public class InstallerPanel extends Page {
Task refreshVersionsTask() {
Task t = list.refresh(new String[] { gsp.getMinecraftVersionFormatted() });
if (t != null)
return t.after(new TaskRunnable(this::loadVersions));
return t.with(new TaskRunnable(this::loadVersions));
else
return null;
}

View File

@@ -49,12 +49,12 @@ public class LauncherSettingsPanel extends RepaintPage {
setBackground(GraphicsUtils.getWebColorWithAlpha("FFFFFF7F"));
setOpaque(true);
DefaultComboBoxModel d = new DefaultComboBoxModel();
DefaultComboBoxModel<String> d = new DefaultComboBoxModel<>();
for (DownloadType type : DownloadType.values())
d.addElement(type.getName());
cboDownloadSource.setModel(d);
d = new DefaultComboBoxModel();
d = new DefaultComboBoxModel<>();
int id = 0;
for (SupportedLocales type : SupportedLocales.values()) {
d.addElement(type.showString());

View File

@@ -38,7 +38,7 @@ import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.ui.modpack.ModpackWizard;
import org.jackhuang.hellominecraft.launcher.util.HMCLMinecraftService;
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.system.FileUtils;
import org.jackhuang.hellominecraft.util.tasks.TaskWindow;
@@ -473,7 +473,7 @@ public class MainPagePanel extends GaussionPage {
final Runnable onLoadingProfiles = () -> {
isLoading = true;
DefaultComboBoxModel model = new DefaultComboBoxModel();
DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
for (Profile s : Settings.getProfilesFiltered())
model.addElement(s.getName());
cboProfiles.setModel(model);
@@ -516,7 +516,7 @@ public class MainPagePanel extends GaussionPage {
void versionChanged(String selectedVersion) {
isLoading = true;
DefaultComboBoxModel model = (DefaultComboBoxModel) cboVersions.getModel();
DefaultComboBoxModel<String> model = (DefaultComboBoxModel<String>) cboVersions.getModel();
for (int i = 0; i < model.getSize(); ++i)
if (model.getElementAt(i).equals(selectedVersion)) {
model.setSelectedItem(selectedVersion);
@@ -532,7 +532,7 @@ public class MainPagePanel extends GaussionPage {
t.launcher().launchingStateChanged.register(launchingStateChanged);
isLoading = true;
DefaultComboBoxModel model = (DefaultComboBoxModel) cboProfiles.getModel();
DefaultComboBoxModel<String> model = (DefaultComboBoxModel<String>) cboProfiles.getModel();
for (int i = 0; i < model.getSize(); ++i)
if (model.getElementAt(i).equals(t.getName())) {
model.setSelectedItem(t.getName());

View File

@@ -24,7 +24,7 @@ import javax.swing.JComboBox;
* Make the popup menu of combo boxes wider.
* @author huangyuhui
*/
public class WideComboBox extends JComboBox {
public class WideComboBox<E> extends JComboBox<E> {
public WideComboBox() {
}

View File

@@ -38,12 +38,12 @@ public class ModpackInitializationPanel extends javax.swing.JPanel {
public static final String KEY_INCLUDING_LAUNCHER = "launcher";
private final transient WizardController controller;
private final Map wizardData;
private final Map<String, Object> wizardData;
/**
* 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();
this.controller = controller;

View File

@@ -1,62 +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.util;
import java.io.File;
import java.util.ArrayList;
/**
*
* @author huangyuhui
*/
public class ModpackUpdater {
private ModpackInfo info;
public ModpackUpdater(File baseFolder, ModpackInfo info) {
this.info = info;
}
void update() {
}
public ModpackInfo getInfo() {
return info;
}
public void setInfo(ModpackInfo info) {
this.info = info;
}
public static class ModpackInfo {
ArrayList<ModpackFolder> folders;
ArrayList<ModpackFile> files;
public static class ModpackFolder {
String ext, name;
}
public static class ModpackFile {
String hash, loc;
}
}
}

View File

@@ -18,8 +18,6 @@
package org.jackhuang.hellominecraft.launcher.util.upgrade;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -173,8 +171,8 @@ public class AppDataUpgrader extends IUpgrader {
if (!f.createNewFile())
HMCLog.warn("Failed to create new file: " + f);
try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(f))) {
Pack200.newUnpacker().unpack(new GZIPInputStream(new FileInputStream(tempFile)), jos);
try (JarOutputStream jos = new JarOutputStream(FileUtils.openOutputStream(f))) {
Pack200.newUnpacker().unpack(new GZIPInputStream(FileUtils.openInputStream(tempFile)), jos);
}
json.put("ver", newestVersion);
json.put("loc", f.getAbsolutePath());