Compare commits

...
7 Commits
27 ... 33
24 changed files with 228 additions and 199 deletions

No files matched your search

@@ -32,6 +32,7 @@ import org.jackhuang.hellominecraft.util.system.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.tasks.TaskInfo;
@@ -47,8 +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) {
if (mv == null) Utils.requireNonNull(mv);
throw new IllegalArgumentException("AssetsMojangLoader: null argument: MinecraftVersion");
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);
@@ -30,6 +30,7 @@ import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
import org.jackhuang.hellominecraft.launcher.core.version.AssetIndexDownloadInfo; import org.jackhuang.hellominecraft.launcher.core.version.AssetIndexDownloadInfo;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
import org.jackhuang.hellominecraft.util.MessageBox; import org.jackhuang.hellominecraft.util.MessageBox;
import org.jackhuang.hellominecraft.util.Utils;
import org.jackhuang.hellominecraft.util.func.Function; import org.jackhuang.hellominecraft.util.func.Function;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.logging.HMCLog;
import org.jackhuang.hellominecraft.util.tasks.Task; import org.jackhuang.hellominecraft.util.tasks.Task;
@@ -55,6 +56,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
} }
public Task downloadAssets(final MinecraftVersion mv) { public Task downloadAssets(final MinecraftVersion mv) {
Utils.requireNonNull(mv);
return new TaskInfo("Download Assets") { return new TaskInfo("Download Assets") {
Collection<Task> afters = new HashSet<>(); Collection<Task> afters = new HashSet<>();
@@ -57,7 +57,7 @@ public class BMCLAPIDownloadProvider extends IDownloadProvider {
@Override @Override
public String getVersionsListDownloadURL() { public String getVersionsListDownloadURL() {
return "http://bmclapi2.bangbang93.com/versions/versions.json"; return "http://bmclapi2.bangbang93.com/mc/game/version_manifest.json";
} }
@Override @Override
@@ -66,13 +66,17 @@ public class BMCLAPIDownloadProvider extends IDownloadProvider {
} }
@Override @Override
public String getParsedLibraryDownloadURL(String str) { public String getParsedDownloadURL(String str) {
return str == null ? null : str.replace("http://files.minecraftforge.net/maven", "http://bmclapi2.bangbang93.com/maven"); return str == null ? null
: str.replace("https://launchermeta.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("http://files.minecraftforge.net/maven", "http://bmclapi2.bangbang93.com/maven");
} }
@Override @Override
public boolean isAllowedToUseSelfURL() { public boolean isAllowedToUseSelfURL() {
return false; return true;
} }
} }
@@ -24,7 +24,7 @@ package org.jackhuang.hellominecraft.launcher.core.download;
public class CurseDownloadProvider extends MojangDownloadProvider { public class CurseDownloadProvider extends MojangDownloadProvider {
@Override @Override
public String getParsedLibraryDownloadURL(String str) { public String getParsedDownloadURL(String str) {
return str == null ? null : str.replace("http://files.minecraftforge.net/maven", "http://ftb.cursecdn.com/FTB2/maven/"); return str == null ? null : str.replace("http://files.minecraftforge.net/maven", "http://ftb.cursecdn.com/FTB2/maven/");
} }
@@ -55,7 +55,15 @@ public abstract class IDownloadProvider {
public abstract String getAssetsDownloadURL(); public abstract String getAssetsDownloadURL();
public abstract String getParsedLibraryDownloadURL(String str); /**
* For example, minecraft.json/assetIndex/url or
* minecraft.json/downloads/client/url
*
* @param str baseURL
*
* @return parsedURL
*/
public abstract String getParsedDownloadURL(String str);
public abstract boolean isAllowedToUseSelfURL(); public abstract boolean isAllowedToUseSelfURL();
} }
@@ -21,6 +21,7 @@ import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftDownloadServ
import com.google.gson.JsonSyntaxException; import com.google.gson.JsonSyntaxException;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@@ -31,11 +32,9 @@ 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.TaskWindow;
import org.jackhuang.hellominecraft.util.tasks.download.FileDownloadTask; import org.jackhuang.hellominecraft.util.tasks.download.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.system.FileUtils;
import org.jackhuang.hellominecraft.util.tasks.DoingDoneListener;
import org.jackhuang.hellominecraft.util.tasks.Task; import org.jackhuang.hellominecraft.util.tasks.Task;
import org.jackhuang.hellominecraft.util.tasks.TaskInfo; import org.jackhuang.hellominecraft.util.tasks.TaskInfo;
@@ -55,74 +54,46 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
if (mv == null) if (mv == null)
return downloadLibraries; return downloadLibraries;
MinecraftVersion v = mv.resolve(service.version()); MinecraftVersion v = mv.resolve(service.version());
if (v.libraries != null) for (IMinecraftLibrary l : v.getLibraries())
for (IMinecraftLibrary l : v.libraries) if (l != null && l.allow()) {
if (l.allow()) { File ff = l.getFilePath(service.baseDirectory());
File ff = l.getFilePath(service.baseDirectory()); if (!ff.exists()) {
if (!ff.exists()) { String libURL = l.getDownloadInfo().getUrl(service.getDownloadType());
String libURL = service.getDownloadType().getProvider().getParsedLibraryDownloadURL(l.getDownloadInfo().getUrl(service.getDownloadType())); if (libURL != null)
if (libURL != null) downloadLibraries.add(new DownloadLibraryJob(l, libURL, ff));
downloadLibraries.add(new DownloadLibraryJob(l, libURL, ff));
}
} }
}
return downloadLibraries; return downloadLibraries;
} }
@Override @Override
public Task downloadMinecraft(String id) { public Task downloadMinecraft(String id) {
return new TaskInfo("Download Minecraft") { return new TaskInfo("Download Minecraft") {
@Override
public Collection<Task> getDependTasks() {
return Arrays.asList(downloadMinecraftVersionJson(id));
}
@Override @Override
public void executeTask() throws Throwable { public void executeTask() throws Throwable {
List<MinecraftRemoteVersion> versions = MinecraftRemoteVersions.getRemoteVersions(service.getDownloadType()).justDo();
MinecraftRemoteVersion currentVersion = null;
for (MinecraftRemoteVersion v : versions)
if (id.equals(v.id)) {
currentVersion = v;
break;
}
if (currentVersion == null)
throw new RuntimeException("Cannot find version: " + id + " in remote repository.");
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"); if (!areDependTasksSucceeded) {
FileUtils.deleteDirectory(vpath);
throw new RuntimeException("Cannot continue because of download failing.");
}
File mvj = new File(vpath, id + ".jar"); File mvj = new File(vpath, id + ".jar");
if (!vpath.exists() && !vpath.mkdirs())
HMCLog.warn("Failed to make directories: " + vpath);
if (mvt.exists() && !mvt.delete())
HMCLog.warn("Failed to delete " + mvt);
if (mvj.exists() && !mvj.delete()) if (mvj.exists() && !mvj.delete())
HMCLog.warn("Failed to delete " + mvj); HMCLog.warn("Failed to delete " + mvj);
try {
MinecraftVersion mv = C.GSON.fromJson(FileUtils.readFileToStringQuietly(new File(vpath, id + ".json")), MinecraftVersion.class);
if (mv == null)
throw new JsonSyntaxException("incorrect version");
Task t = new FileDownloadTask(jsonURL, mvt).setTag(id + ".json"); afters.add(downloadMinecraftJar(mv, mvj));
t.addTaskListener(new DoingDoneListener<Task>() { } catch (JsonSyntaxException ex) {
@Override HMCLog.err("Failed to parse minecraft version json.", ex);
public void onDone(Task k, Collection<Task> taskCollection) { FileUtils.deleteDirectory(vpath);
MinecraftVersion mv; }
try {
mv = C.GSON.fromJson(FileUtils.readFileToStringQuietly(mvt), MinecraftVersion.class);
if (mv == null)
throw new JsonSyntaxException("incorrect version");
} catch (JsonSyntaxException ex) {
HMCLog.err("Failed to parse minecraft version json.", ex);
onFailed(k);
return;
}
GameDownloadInfo i = mv.getClientDownloadInfo();
taskCollection.add(new FileDownloadTask(i.getUrl(service.getDownloadType()), mvj, i.sha1)
.setFailedCallbackReturnsNewURL(new DownloadTypeSwitcher(id + "/" + id + ".jar")).setTag(id + ".jar"));
}
@Override
public void onDoing(Task k, Collection<Task> taskCollection) {
}
@Override
public void onFailed(Task k) {
FileUtils.deleteDirectoryQuietly(vpath);
}
});
afters.add(t);
} }
Collection<Task> afters = new HashSet<>(); Collection<Task> afters = new HashSet<>();
@@ -134,34 +105,6 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
}; };
} }
@Override
public boolean downloadMinecraftJar(String id) {
String vurl = service.getDownloadType().getProvider().getVersionsDownloadURL() + id + "/";
File vpath = new File(service.baseDirectory(), "versions/" + id);
File mvv = new File(vpath, id + ".jar"), moved = null;
if (mvv.exists()) {
moved = new File(vpath, id + "-renamed.jar");
if (!mvv.renameTo(moved))
HMCLog.warn("Failed to rename " + mvv + " to " + moved);
}
File mvt = new File(vpath, id + ".jar");
if (!vpath.exists() && !vpath.mkdirs())
HMCLog.warn("Failed to make version folder " + vpath);
if (TaskWindow.factory()
.append(new FileDownloadTask(vurl + id + ".jar", mvt).setFailedCallbackReturnsNewURL(new DownloadTypeSwitcher(id + "/" + id + ".jar")).setTag(id + ".jar"))
.create()) {
if (moved != null && moved.exists() && !moved.delete())
HMCLog.warn("Failed to delete " + moved);
return true;
} else {
if (mvt.exists() && !mvt.delete())
HMCLog.warn("Failed to delete game jar " + mvt);
if (moved != null && moved.exists() && !moved.renameTo(mvt))
HMCLog.warn("Failed to rename " + moved + " to " + mvt);
return false;
}
}
private static class DownloadTypeSwitcher implements Function<Integer, String> { private static class DownloadTypeSwitcher implements Function<Integer, String> {
String suffix; String suffix;
@@ -178,37 +121,43 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
} }
@Override @Override
public Task downloadMinecraftJarTo(MinecraftVersion mv, File mvt) { public Task downloadMinecraftJar(MinecraftVersion mv, File mvj) {
String jar = mv.jar == null ? mv.id : mv.jar;
GameDownloadInfo i = mv.getClientDownloadInfo(); GameDownloadInfo i = mv.getClientDownloadInfo();
return new FileDownloadTask(i.getUrl(service.getDownloadType(), true), mvt, i.sha1).setTag(jar + ".jar"); return new FileDownloadTask(i.getUrl(service.getDownloadType()), mvj, i.sha1)
.setFailedCallbackReturnsNewURL(new DownloadTypeSwitcher(mv.id + "/" + mv.id + ".jar")).setTag(mv.id + ".jar");
} }
@Override @Override
public boolean downloadMinecraftVersionJson(String id) { public Task downloadMinecraftVersionJson(String id) {
String vurl = service.getDownloadType().getProvider().getVersionsDownloadURL() + id + "/"; return new TaskInfo("Download Minecraft Json") {
File vpath = new File(service.baseDirectory(), "versions/" + id); @Override
File mvv = new File(vpath, id + ".json"), moved = null; public void executeTask() throws Throwable {
if (mvv.exists()) { List<MinecraftRemoteVersion> versions = MinecraftRemoteVersions.getRemoteVersions(service.getDownloadType()).justDo();
moved = new File(vpath, id + "-renamed.json"); MinecraftRemoteVersion currentVersion = null;
if (!mvv.renameTo(moved)) for (MinecraftRemoteVersion v : versions)
HMCLog.warn("Failed to rename " + mvv + " to " + moved); if (id.equals(v.id)) {
} currentVersion = v;
File mvt = new File(vpath, id + ".json"); break;
if (!vpath.exists() && !vpath.mkdirs()) }
HMCLog.warn("Failed to make version folder " + vpath); if (currentVersion == null)
if (TaskWindow.factory() throw new RuntimeException("Cannot find version: " + id + " in remote repository.");
.append(new FileDownloadTask(vurl + id + ".json", mvt).setTag(id + ".json")) String jsonURL = currentVersion.getUrl(service.getDownloadType());
.create()) { File vpath = new File(service.baseDirectory(), "versions/" + id);
if (moved != null && moved.exists() && !moved.delete()) File mvt = new File(vpath, id + ".json");
HMCLog.warn("Failed to delete " + moved); if (!vpath.exists() && !vpath.mkdirs())
return true; HMCLog.warn("Failed to make directories: " + vpath);
} else { if (mvt.exists() && !mvt.delete())
if (mvt.exists() && !mvt.delete()) HMCLog.warn("Failed to delete " + mvt);
HMCLog.warn("Failed to delete minecraft version json" + mvt);
if (moved != null && moved.exists() && !moved.renameTo(mvt)) afters.add(new FileDownloadTask(jsonURL, mvt).setTag(id + ".json"));
HMCLog.warn("Failed to rename " + moved + " to " + mvt); }
return false;
} Collection<Task> afters = new HashSet<>();
@Override
public Collection<Task> getAfterTasks() {
return afters;
}
};
} }
} }
@@ -73,7 +73,7 @@ public class MojangDownloadProvider extends IDownloadProvider {
} }
@Override @Override
public String getParsedLibraryDownloadURL(String str) { public String getParsedDownloadURL(String str) {
if (str == null) if (str == null)
return null; return null;
else if (str.contains("scala-swing") || str.contains("scala-xml") || str.contains("scala-parser-combinators")) else if (str.contains("scala-swing") || str.contains("scala-xml") || str.contains("scala-parser-combinators"))
@@ -86,5 +86,4 @@ public class MojangDownloadProvider extends IDownloadProvider {
else else
return str; return str;
} }
} }
@@ -49,7 +49,7 @@ public class RapidDataDownloadProvider extends MojangDownloadProvider {
} }
@Override @Override
public String getParsedLibraryDownloadURL(String str) { public String getParsedDownloadURL(String str) {
return str == null ? null : str.replace("http://files.minecraftforge.net/maven", "http://mirrors.rapiddata.org/forge/maven"); return str == null ? null : str.replace("http://files.minecraftforge.net/maven", "http://mirrors.rapiddata.org/forge/maven");
} }
@@ -64,7 +64,7 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "forge-installer.jar"); File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "forge-installer.jar");
if (v.installer != null) if (v.installer != null)
TaskWindow.factory() TaskWindow.factory()
.append(new FileDownloadTask(service.getDownloadType().getProvider().getParsedLibraryDownloadURL(v.installer), filepath).setTag("forge")) .append(new FileDownloadTask(service.getDownloadType().getProvider().getParsedDownloadURL(v.installer), filepath).setTag("forge"))
.append(new ForgeInstaller(service, filepath)) .append(new ForgeInstaller(service, filepath))
.create(); .create();
} }
@@ -51,7 +51,7 @@ public class MinecraftForgeVersionList extends InstallerVersionList {
public void refreshList(String[] needed) throws Exception { public void refreshList(String[] needed) throws Exception {
if (root != null) if (root != null)
return; return;
String s = NetUtils.get(DownloadType.getSuggestedDownloadType().getProvider().getParsedLibraryDownloadURL(C.URL_FORGE_LIST)); String s = NetUtils.get(DownloadType.getSuggestedDownloadType().getProvider().getParsedDownloadURL(C.URL_FORGE_LIST));
root = C.GSON.fromJson(s, MinecraftForgeVersionRoot.class); root = C.GSON.fromJson(s, MinecraftForgeVersionRoot.class);
@@ -70,7 +70,7 @@ public class MinecraftForgeVersionList extends InstallerVersionList {
if (!StrUtils.isBlank(v.branch)) if (!StrUtils.isBlank(v.branch))
ver = ver + "-" + v.branch; ver = ver + "-" + v.branch;
String filename = root.artifact + "-" + ver + "-" + f[1] + "." + f[0]; String filename = root.artifact + "-" + ver + "-" + f[1] + "." + f[0];
String url = DownloadType.getSuggestedDownloadType().getProvider().getParsedLibraryDownloadURL(root.webpath + ver + "/" + filename); String url = DownloadType.getSuggestedDownloadType().getProvider().getParsedDownloadURL(root.webpath + ver + "/" + filename);
switch (f[1]) { switch (f[1]) {
case "installer": case "installer":
iv.installer = url; iv.installer = url;
@@ -31,6 +31,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
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.logging.HMCLog;
@@ -46,6 +47,7 @@ import org.jackhuang.hellominecraft.util.system.ZipEngine;
import org.jackhuang.hellominecraft.util.tasks.Task; import org.jackhuang.hellominecraft.util.tasks.Task;
import org.jackhuang.hellominecraft.util.ui.WebPage; import org.jackhuang.hellominecraft.util.ui.WebPage;
import org.jackhuang.hellominecraft.util.MinecraftVersionRequest; import org.jackhuang.hellominecraft.util.MinecraftVersionRequest;
import org.jackhuang.hellominecraft.util.tasks.NoShownTaskException;
/** /**
* A mod pack(*.zip) includes these things: * A mod pack(*.zip) includes these things:
@@ -79,7 +81,7 @@ public final class ModpackManager {
* @return The installing Task, may take long time, please consider * @return The installing Task, may take long time, please consider
* TaskWindow. * TaskWindow.
*/ */
public static Task install(final File input, final IMinecraftService service, final String idFUCK) { public static Task install(JFrame parFrame, final File input, final IMinecraftService service, final String idFUCK) {
return new Task() { return new Task() {
Collection<Task> c = new ArrayList<>(); Collection<Task> c = new ArrayList<>();
@@ -109,9 +111,9 @@ public final class ModpackManager {
msgs[0] = C.i18n("modpack.task.install"); msgs[0] = C.i18n("modpack.task.install");
msgs[1] = new WebPage(description); msgs[1] = new WebPage(description);
((WebPage) msgs[1]).setPreferredSize(new Dimension(800, 350)); ((WebPage) msgs[1]).setPreferredSize(new Dimension(800, 350));
int result = JOptionPane.showOptionDialog(null, msgs, (String) msgs[0], JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); int result = JOptionPane.showOptionDialog(parFrame, msgs, (String) msgs[0], JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
if (result == JOptionPane.NO_OPTION) if (result == JOptionPane.NO_OPTION)
return; throw new NoShownTaskException("Operation was canceled by user.");
File versions = new File(service.baseDirectory(), "versions"); File versions = new File(service.baseDirectory(), "versions");
@@ -166,7 +168,7 @@ public final class ModpackManager {
if (mv.jar == null) if (mv.jar == null)
throw new FileNotFoundException(C.i18n("modpack.incorrect_format.no_jar")); throw new FileNotFoundException(C.i18n("modpack.incorrect_format.no_jar"));
c.add(service.download().downloadMinecraftJarTo(mv, new File(nowFile, id + ".jar"))); c.add(service.download().downloadMinecraftJar(mv, new File(nowFile, id + ".jar")));
mv.jar = null; mv.jar = null;
FileUtils.writeStringToFile(json, C.GSON.toJson(mv)); FileUtils.writeStringToFile(json, C.GSON.toJson(mv));
if (!json.renameTo(new File(nowFile, id + ".json"))) if (!json.renameTo(new File(nowFile, id + ".json")))
@@ -22,9 +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.OverridableSwingWorker;
import org.jackhuang.hellominecraft.util.tasks.Task; import org.jackhuang.hellominecraft.util.tasks.Task;
import org.jackhuang.hellominecraft.launcher.core.download.MinecraftRemoteVersion;
/** /**
* *
@@ -38,11 +36,9 @@ public abstract class IMinecraftDownloadService extends IMinecraftBasicService {
public abstract Task downloadMinecraft(String id); public abstract Task downloadMinecraft(String id);
public abstract boolean downloadMinecraftJar(String id); public abstract Task downloadMinecraftJar(MinecraftVersion mv, File f);
public abstract Task downloadMinecraftJarTo(MinecraftVersion mv, File f); public abstract Task downloadMinecraftVersionJson(String id);
public abstract boolean downloadMinecraftVersionJson(String id);
/** /**
* Get the libraries that need to download. * Get the libraries that need to download.
@@ -36,11 +36,8 @@ public class AssetIndexDownloadInfo extends GameDownloadInfo {
} }
@Override @Override
public String getUrl(DownloadType dt, boolean allowSelf) { public String getCustomizedURL(DownloadType dt) {
if (url != null && dt.getProvider().isAllowedToUseSelfURL()) return dt.getProvider().getIndexesDownloadURL() + id + ".json";
return url;
else
return dt.getProvider().getIndexesDownloadURL() + id + ".json";
} }
public String getId() { public String getId() {
@@ -55,9 +55,13 @@ public class GameDownloadInfo implements Cloneable {
*/ */
public String getUrl(DownloadType dt, boolean allowSelf) { public String getUrl(DownloadType dt, boolean allowSelf) {
if (url != null && allowSelf) if (url != null && allowSelf)
return url; return dt.getProvider().getParsedDownloadURL(url);
else else
return dt.getProvider().getVersionsDownloadURL() + id + "/" + id + ".jar"; return getCustomizedURL(dt);
}
protected String getCustomizedURL(DownloadType dt) {
return dt.getProvider().getVersionsDownloadURL() + id + "/" + id + ".jar";
} }
@Override @Override
@@ -168,4 +168,8 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
i.id = id; i.id = id;
return i; return i;
} }
public Set<IMinecraftLibrary> getLibraries() {
return libraries == null ? new HashSet() : new HashSet(libraries);
}
} }
@@ -46,8 +46,12 @@ public final class Profile {
} }
public Profile(String name) { public Profile(String name) {
this(name, new File(IOUtils.currentDir(), ".minecraft").getPath());
}
public Profile(String name, String gameDir) {
this.name = name; this.name = name;
gameDir = MCUtils.getInitGameDir().getPath(); this.gameDir = gameDir;
} }
public Profile(String name, Profile v) { public Profile(String name, Profile v) {
@@ -25,6 +25,7 @@ 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.logging.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.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;
@@ -40,6 +41,7 @@ import org.jackhuang.hellominecraft.util.UpdateChecker;
public final class Settings { public final class Settings {
public static final String DEFAULT_PROFILE = "Default"; public static final String DEFAULT_PROFILE = "Default";
public static final String HOME_PROFILE = "Home";
public static final File SETTINGS_FILE = new File(IOUtils.currentDir(), "hmcl.json"); public static final File SETTINGS_FILE = new File(IOUtils.currentDir(), "hmcl.json");
@@ -55,7 +57,7 @@ public final class Settings {
SETTINGS.downloadTypeChangedEvent.register(DownloadType::setSuggestedDownloadType); SETTINGS.downloadTypeChangedEvent.register(DownloadType::setSuggestedDownloadType);
DownloadType.setSuggestedDownloadType(SETTINGS.getDownloadSource()); DownloadType.setSuggestedDownloadType(SETTINGS.getDownloadSource());
if (!getProfiles().containsKey(DEFAULT_PROFILE)) if (!getProfiles().containsKey(DEFAULT_PROFILE))
getProfiles().put(DEFAULT_PROFILE, new Profile()); getProfiles().put(DEFAULT_PROFILE, new Profile(DEFAULT_PROFILE));
for (Map.Entry<String, Profile> entry : getProfiles().entrySet()) { for (Map.Entry<String, Profile> entry : getProfiles().entrySet()) {
Profile e = entry.getValue(); Profile e = entry.getValue();
@@ -81,8 +83,11 @@ public final class Settings {
} catch (IOException | JsonSyntaxException e) { } catch (IOException | JsonSyntaxException e) {
HMCLog.warn("Something happened wrongly when load settings.", e); HMCLog.warn("Something happened wrongly when load settings.", e);
} }
else else {
HMCLog.log("No settings file here, may be first loading."); HMCLog.log("No settings file here, may be first loading.");
if (!c.getConfigurations().containsKey(HOME_PROFILE))
c.getConfigurations().put(HOME_PROFILE, new Profile(HOME_PROFILE, MCUtils.getLocation().getPath()));
}
return c; return c;
} }
@@ -150,7 +155,13 @@ public final class Settings {
MessageBox.Show(C.i18n("settings.cannot_remove_default_config")); MessageBox.Show(C.i18n("settings.cannot_remove_default_config"));
return false; return false;
} }
return getProfiles().remove(ver) != null; boolean notify = false;
if (getLastProfile().getName().equals(ver))
notify = true;
boolean flag = getProfiles().remove(ver) != null;
if (notify && flag)
onProfileChanged();
return flag;
} }
public static final EventHandler<Profile> profileChangedEvent = new EventHandler(null); public static final EventHandler<Profile> profileChangedEvent = new EventHandler(null);
@@ -388,43 +388,40 @@
<Layout> <Layout>
<DimensionLayout dim="0"> <DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="103" alignment="0" groupAlignment="0" attributes="0"> <Group type="102" attributes="0">
<Group type="102" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0"> <Component id="txtWrapperLauncher" alignment="0" max="32767" attributes="0"/>
<Component id="txtWrapperLauncher" alignment="0" max="32767" attributes="0"/> <Group type="102" alignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0"> <Component id="lblPrecalledCommand1" min="-2" max="-2" attributes="0"/>
<Component id="lblPrecalledCommand1" min="-2" max="-2" attributes="0"/> <EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/>
</Group> </Group>
<Component id="txtPrecalledCommand" alignment="0" max="32767" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="txtServerIP" alignment="0" max="32767" attributes="0"/> </Group>
<Group type="102" attributes="0"> <Component id="txtPrecalledCommand" alignment="0" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Component id="txtServerIP" alignment="0" max="32767" attributes="0"/>
<Component id="lblPrecalledCommand" alignment="0" min="-2" max="-2" attributes="0"/> <Group type="102" alignment="1" attributes="0">
<Component id="lblServerIP" alignment="0" min="-2" max="-2" attributes="0"/> <Group type="103" groupAlignment="0" attributes="0">
</Group> <Component id="lblMinecraftArgs" alignment="0" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="716" max="32767" attributes="0"/> <Component id="lblPermSize" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lblJavaArgs" alignment="0" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<Group type="102" alignment="1" attributes="0"> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="lblMinecraftArgs" alignment="0" min="-2" max="-2" attributes="0"/> <Component id="txtJavaArgs" pref="664" max="32767" attributes="0"/>
<Component id="lblPermSize" alignment="0" min="-2" max="-2" attributes="0"/> <Component id="txtMinecraftArgs" max="32767" attributes="0"/>
<Component id="lblJavaArgs" alignment="0" min="-2" max="-2" attributes="0"/> <Component id="txtPermSize" alignment="1" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="txtJavaArgs" max="32767" attributes="0"/>
<Component id="txtMinecraftArgs" max="32767" attributes="0"/>
<Component id="txtPermSize" alignment="1" max="32767" attributes="0"/>
</Group>
</Group> </Group>
</Group> </Group>
<Group type="102" alignment="0" attributes="0"> <Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/> <Group type="103" groupAlignment="0" attributes="0">
<Component id="chkNoJVMArgs" min="-2" max="-2" attributes="0"/> <Component id="lblPrecalledCommand" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lblServerIP" alignment="0" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="chkNoJVMArgs" 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>
</Group> </Group>
@@ -949,8 +949,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
private void btnRemoveProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveProfileActionPerformed 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) if (MessageBox.Show(C.i18n("ui.message.sure_remove", Settings.getLastProfile().getName()), MessageBox.YES_NO_OPTION) == MessageBox.NO_OPTION)
return; return;
if (Settings.delProfile(Settings.getLastProfile())) Settings.delProfile(Settings.getLastProfile());
loadProfiles();
}//GEN-LAST:event_btnRemoveProfileActionPerformed }//GEN-LAST:event_btnRemoveProfileActionPerformed
private void cboVersionsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboVersionsItemStateChanged private void cboVersionsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboVersionsItemStateChanged
@@ -1376,10 +1375,12 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
final Runnable onLoadingProfiles = this::loadProfiles; final Runnable onLoadingProfiles = this::loadProfiles;
private void loadProfiles() { private void loadProfiles() {
isLoading = true;
DefaultComboBoxModel model = new DefaultComboBoxModel(); DefaultComboBoxModel 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;
} }
final Consumer<IMinecraftService> onRefreshedVersions = t -> { final Consumer<IMinecraftService> onRefreshedVersions = t -> {
@@ -1425,12 +1426,15 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
t.selectedVersionChangedEvent.register(selectedVersionChangedEvent); t.selectedVersionChangedEvent.register(selectedVersionChangedEvent);
txtGameDir.setText(t.getGameDir()); txtGameDir.setText(t.getGameDir());
isLoading = true;
DefaultComboBoxModel model = (DefaultComboBoxModel) cboProfiles.getModel(); DefaultComboBoxModel model = (DefaultComboBoxModel) 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());
break; break;
} }
isLoading = false;
}; };
//</editor-fold> //</editor-fold>
} }
@@ -37,6 +37,7 @@ import org.jackhuang.hellominecraft.launcher.setting.Settings;
import org.jackhuang.hellominecraft.launcher.core.mod.ModpackManager; 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.util.ui.GraphicsUtils; 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.comp.ConstomButton;
@@ -382,7 +383,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(fc.getSelectedFile(), Settings.getLastProfile().service(), suggestedModpackId)).create(); TaskWindow.factory().append(ModpackManager.install(MainFrame.INSTANCE, fc.getSelectedFile(), Settings.getLastProfile().service(), suggestedModpackId)).create();
Settings.getLastProfile().service().version().refreshVersions(); Settings.getLastProfile().service().version().refreshVersions();
}//GEN-LAST:event_btnImportModpackActionPerformed }//GEN-LAST:event_btnImportModpackActionPerformed
@@ -471,10 +472,12 @@ public class MainPagePanel extends AnimatedPanel {
final Runnable onLoadingProfiles = this::loadProfiles; final Runnable onLoadingProfiles = this::loadProfiles;
private void loadProfiles() { private void loadProfiles() {
isLoading = true;
DefaultComboBoxModel model = new DefaultComboBoxModel(); DefaultComboBoxModel 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;
} }
final Consumer<IMinecraftService> onRefreshedVersions = t -> { final Consumer<IMinecraftService> onRefreshedVersions = t -> {
@@ -489,7 +492,7 @@ public class MainPagePanel extends AnimatedPanel {
cboVersions.removeAllItems(); cboVersions.removeAllItems();
String selVersion = Settings.getLastProfile().getSelectedVersion(); String selVersion = Settings.getLastProfile().getSelectedVersion();
if (Settings.getLastProfile().service().version().getVersions().isEmpty()) { if (Settings.getLastProfile().service().version().getVersions().isEmpty()) {
if (!showedNoVersion) { 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)
@@ -528,11 +531,13 @@ public class MainPagePanel extends AnimatedPanel {
t.selectedVersionChangedEvent.register(versionChanged); t.selectedVersionChangedEvent.register(versionChanged);
t.launcher().launchingStateChanged.register(launchingStateChanged); t.launcher().launchingStateChanged.register(launchingStateChanged);
isLoading = true;
DefaultComboBoxModel model = (DefaultComboBoxModel) cboProfiles.getModel(); DefaultComboBoxModel model = (DefaultComboBoxModel) 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());
break; break;
} }
isLoading = false;
}; };
} }
@@ -21,6 +21,7 @@ import com.google.gson.JsonSyntaxException;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.swing.SwingUtilities;
import org.jackhuang.hellominecraft.launcher.core.GameException; import org.jackhuang.hellominecraft.launcher.core.GameException;
import org.jackhuang.hellominecraft.launcher.core.install.MinecraftInstallerService; import org.jackhuang.hellominecraft.launcher.core.install.MinecraftInstallerService;
import org.jackhuang.hellominecraft.launcher.core.asset.MinecraftAssetService; import org.jackhuang.hellominecraft.launcher.core.asset.MinecraftAssetService;
@@ -39,6 +40,7 @@ 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.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog; import org.jackhuang.hellominecraft.util.logging.HMCLog;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.system.FileUtils;
@@ -66,18 +68,19 @@ public class HMCLMinecraftService extends IMinecraftService {
this.mis = new MinecraftInstallerService(this); this.mis = new MinecraftInstallerService(this);
} }
public boolean checkedModpack = false, checkingModpack = false;
private void checkModpack() { private void checkModpack() {
int show = 0; if (!checkingModpack) {
for (StackTraceElement e : Thread.currentThread().getStackTrace()) checkingModpack = true;
if ("checkModpack".equals(e.getMethodName())) if (version().getVersionCount() == 0) {
++show; File modpack = new File("modpack.zip");
if (show > 2) if (modpack.exists())
return; SwingUtilities.invokeLater(() -> {
if (version().getVersionCount() == 0) { if (TaskWindow.execute(ModpackManager.install(MainFrame.INSTANCE, modpack, this, null)))
File modpack = new File("modpack.zip"); version().refreshVersions();
if (modpack.exists()) { checkedModpack = true;
TaskWindow.factory().append(ModpackManager.install(modpack, this, null)).create(); });
version().refreshVersions();
} }
} }
} }
@@ -93,6 +93,7 @@ public class ZipEngine {
if (file.isDirectory()) { if (file.isDirectory()) {
pathName = file.getPath().substring(basePath.length() + 1) pathName = file.getPath().substring(basePath.length() + 1)
+ "/"; + "/";
pathName = pathName.replace('\\', '/');
if (pathNameCallback != null) if (pathNameCallback != null)
pathName = pathNameCallback.apply(pathName, true); pathName = pathNameCallback.apply(pathName, true);
if (pathName == null) if (pathName == null)
@@ -100,9 +101,10 @@ public class ZipEngine {
zos.putNextEntry(new ZipEntry(pathName)); zos.putNextEntry(new ZipEntry(pathName));
putDirectoryImpl(file, basePath, pathNameCallback); putDirectoryImpl(file, basePath, pathNameCallback);
} else { } else {
if (".DS_Store".equals(file.getName())) // For mac computers. if (".DS_Store".equals(file.getName())) // For Mac computers.
continue; continue;
pathName = file.getPath().substring(basePath.length() + 1); pathName = file.getPath().substring(basePath.length() + 1);
pathName = pathName.replace('\\', '/');
if (pathNameCallback != null) if (pathNameCallback != null)
pathName = pathNameCallback.apply(pathName, false); pathName = pathNameCallback.apply(pathName, false);
if (pathName == null) if (pathName == null)
@@ -0,0 +1,29 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.util.tasks;
/**
*
* @author huangyuhui
*/
public class NoShownTaskException extends RuntimeException {
public NoShownTaskException(String msg) {
super(msg);
}
}
@@ -225,9 +225,11 @@ public class TaskWindow extends javax.swing.JDialog
@Override @Override
public void run() { public void run() {
SwingUtilities.invokeLater(this::dispose); SwingUtilities.invokeLater(() -> {
suc = true; dispose();
HMCLog.log("Tasks are finished."); suc = true;
HMCLog.log("Tasks are finished.");
});
} }
@Override @Override
@@ -271,7 +273,14 @@ public class TaskWindow extends javax.swing.JDialog
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
if (taskList == null || task == null) if (taskList == null || task == null)
return; return;
failReasons.add(task.getInfo() + ": " + (null == task.getFailReason() ? "No exception" : (StrUtils.isBlank(task.getFailReason().getLocalizedMessage()) ? task.getFailReason().getClass().getSimpleName() : task.getFailReason().getLocalizedMessage()))); String msg = null;
if (task.getFailReason() != null && !(task.getFailReason() instanceof NoShownTaskException))
if (StrUtils.isBlank(task.getFailReason().getLocalizedMessage()))
msg = task.getFailReason().getClass().getSimpleName();
else
msg = task.getFailReason().getLocalizedMessage();
if (msg != null)
failReasons.add(task.getInfo() + ": " + msg);
pgsTotal.setMaximum(taskList.taskCount()); pgsTotal.setMaximum(taskList.taskCount());
pgsTotal.setValue(pgsTotal.getValue() + 1); pgsTotal.setValue(pgsTotal.getValue() + 1);
int idx = tasks.indexOf(task); int idx = tasks.indexOf(task);