mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-03-07 17:36:52 +08:00
Fixed forge not downloading from BMCL
This commit is contained in:
parent
0bda79c0d5
commit
c67caafdb4
@ -153,6 +153,8 @@ public class LaunchingUIDaemon {
|
||||
case DecompressingNatives:
|
||||
message = "launch.state.decompressing_natives";
|
||||
break;
|
||||
case Done:
|
||||
return;
|
||||
}
|
||||
MainFrame.INSTANCE.showMessage(C.i18n(message));
|
||||
};
|
||||
|
@ -1,40 +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.hmcl.api.event.launch;
|
||||
|
||||
import org.jackhuang.hmcl.api.game.DecompressLibraryJob;
|
||||
import org.jackhuang.hmcl.api.event.ResultedSimpleEvent;
|
||||
|
||||
/**
|
||||
* This event gets fired when we are launching a game and going to decompress natives.
|
||||
* <br>
|
||||
* This event is {@link org.jackhuang.hmcl.api.event.ResultedEvent}
|
||||
* If this event is failed, the launching process will be terminated.
|
||||
* <br>
|
||||
* This event is fired on the {@link org.jackhuang.hmcl.api.HMCLApi#EVENT_BUS}
|
||||
* @param source {@link org.jackhuang.hmcl.core.launch.GameLauncher}
|
||||
* @param DecompressLibraryJob libraries to be decompressed
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class DecompressLibrariesEvent extends ResultedSimpleEvent<DecompressLibraryJob> {
|
||||
|
||||
public DecompressLibrariesEvent(Object source, DecompressLibraryJob value) {
|
||||
super(source, value);
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +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.hmcl.api.event.launch;
|
||||
|
||||
import java.util.List;
|
||||
import org.jackhuang.hmcl.api.event.ResultedSimpleEvent;
|
||||
|
||||
/**
|
||||
* This event gets fired when we are launching a game and there are some libraries to be downloaded.
|
||||
* <br>
|
||||
* This event is {@link org.jackhuang.hmcl.api.event.ResultedEvent}
|
||||
* If this event is failed, the launching process will be terminated.
|
||||
* <br>
|
||||
* This event is fired on the {@link org.jackhuang.hmcl.api.HMCLApi#EVENT_BUS}
|
||||
* @param source {@link org.jackhuang.hmcl.core.launch.GameLauncher}
|
||||
* Passed value List<DownloadLibraryJob>: libraries to be downloaded.
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class DownloadLibrariesEvent extends ResultedSimpleEvent<List<DownloadLibraryJob>> {
|
||||
|
||||
public DownloadLibrariesEvent(Object sender, List<DownloadLibraryJob> lists) {
|
||||
super(sender, lists);
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
* 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.hmcl.api.event.launch;
|
||||
package org.jackhuang.hmcl.core.download;
|
||||
|
||||
import java.io.File;
|
||||
import org.jackhuang.hmcl.api.game.IMinecraftLibrary;
|
||||
@ -36,17 +36,17 @@ public class DownloadLibraryJob {
|
||||
path = p;
|
||||
}
|
||||
|
||||
public DownloadLibraryJob parse() {
|
||||
public DownloadLibraryJob parse(DownloadType type) {
|
||||
String name = lib.getName();
|
||||
if (name.startsWith("net.minecraftforge:forge:")) {
|
||||
if (name.startsWith("net.minecraftforge:forge:") && url == null) {
|
||||
String[] s = name.split(":");
|
||||
if (s.length == 3)
|
||||
url = "http://files.minecraftforge.net/maven/net/minecraftforge/forge/" + s[2] + "/forge-" + s[2] + "-universal.jar";
|
||||
url = type.getProvider().getParsedDownloadURL("http://files.minecraftforge.net/maven/net/minecraftforge/forge/" + s[2] + "/forge-" + s[2] + "-universal.jar");
|
||||
}
|
||||
if (name.startsWith("com.mumfrey:liteloader:")) {
|
||||
if (name.startsWith("com.mumfrey:liteloader:") && url == null) {
|
||||
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";
|
||||
url = type.getProvider().getParsedDownloadURL("http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + s[2].substring(0, s[2].length() - 3) + "/liteloader-" + s[2] + ".jar");
|
||||
}
|
||||
return this;
|
||||
}
|
@ -17,7 +17,6 @@
|
||||
*/
|
||||
package org.jackhuang.hmcl.core.download;
|
||||
|
||||
import org.jackhuang.hmcl.api.event.launch.DownloadLibraryJob;
|
||||
import org.jackhuang.hmcl.core.service.IMinecraftDownloadService;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import java.io.File;
|
||||
|
@ -21,11 +21,7 @@ import org.jackhuang.hmcl.api.game.LaunchOptions;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import org.jackhuang.hmcl.api.HMCLApi;
|
||||
import org.jackhuang.hmcl.api.event.ResultedSimpleEvent;
|
||||
import org.jackhuang.hmcl.api.event.launch.DecompressLibrariesEvent;
|
||||
import org.jackhuang.hmcl.api.event.launch.DownloadLibrariesEvent;
|
||||
import org.jackhuang.hmcl.api.event.launch.DownloadLibraryJob;
|
||||
import org.jackhuang.hmcl.core.download.DownloadLibraryJob;
|
||||
import org.jackhuang.hmcl.api.auth.LoginInfo;
|
||||
import org.jackhuang.hmcl.core.service.IMinecraftService;
|
||||
import org.jackhuang.hmcl.util.C;
|
||||
@ -35,47 +31,45 @@ import org.jackhuang.hmcl.util.sys.CompressingUtils;
|
||||
import org.jackhuang.hmcl.util.task.ParallelTask;
|
||||
import org.jackhuang.hmcl.util.task.TaskWindow;
|
||||
import org.jackhuang.hmcl.api.auth.IAuthenticator;
|
||||
|
||||
import org.jackhuang.hmcl.api.game.DecompressLibraryJob;
|
||||
|
||||
public class DefaultGameLauncher extends GameLauncher {
|
||||
|
||||
public DefaultGameLauncher(LaunchOptions options, IMinecraftService service, LoginInfo info, IAuthenticator lg) {
|
||||
super(options, service, info, lg);
|
||||
register();
|
||||
}
|
||||
|
||||
private void register() {
|
||||
HMCLApi.EVENT_BUS.channel(DownloadLibrariesEvent.class).register(t -> {
|
||||
ResultedSimpleEvent<List<DownloadLibraryJob>> event = (ResultedSimpleEvent) t;
|
||||
final TaskWindow.TaskWindowFactory dw = TaskWindow.factory();
|
||||
ParallelTask parallelTask = new ParallelTask();
|
||||
HashSet<String> names = new HashSet<>();
|
||||
for (DownloadLibraryJob s : t.getValue()) {
|
||||
if (names.contains(s.lib.getName()))
|
||||
continue;
|
||||
names.add(s.lib.getName());
|
||||
parallelTask.addTask(new LibraryDownloadTask(s));
|
||||
@Override
|
||||
public boolean downloadLibraries(List<DownloadLibraryJob> jobs) {
|
||||
final TaskWindow.TaskWindowFactory dw = TaskWindow.factory();
|
||||
ParallelTask parallelTask = new ParallelTask();
|
||||
HashSet<String> names = new HashSet<>();
|
||||
for (DownloadLibraryJob s : jobs) {
|
||||
if (names.contains(s.lib.getName()))
|
||||
continue;
|
||||
names.add(s.lib.getName());
|
||||
parallelTask.addTask(new LibraryDownloadTask(s, service.getDownloadType()));
|
||||
}
|
||||
dw.append(parallelTask);
|
||||
boolean flag = true;
|
||||
if (jobs.size() > 0)
|
||||
flag = dw.execute();
|
||||
if (!flag && MessageBox.show(C.i18n("launch.not_finished_downloading_libraries"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
|
||||
flag = true;
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean decompressLibraries(DecompressLibraryJob job) {
|
||||
if (job == null)
|
||||
return false;
|
||||
for (int i = 0; i < job.decompressFiles.length; i++)
|
||||
try {
|
||||
CompressingUtils.unzip(job.decompressFiles[i], job.getDecompressTo(), job.extractRules[i]::allow, false);
|
||||
} catch (IOException ex) {
|
||||
HMCLog.err("Unable to decompress library: " + job.decompressFiles[i] + " to " + job.getDecompressTo(), ex);
|
||||
}
|
||||
dw.append(parallelTask);
|
||||
boolean flag = true;
|
||||
if (t.getValue().size() > 0)
|
||||
flag = dw.execute();
|
||||
if (!flag && MessageBox.show(C.i18n("launch.not_finished_downloading_libraries"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
|
||||
flag = true;
|
||||
t.setResult(flag);
|
||||
});
|
||||
HMCLApi.EVENT_BUS.channel(DecompressLibrariesEvent.class).register(t -> {
|
||||
if (t.getValue() == null) {
|
||||
t.setResult(false);
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < t.getValue().decompressFiles.length; i++)
|
||||
try {
|
||||
CompressingUtils.unzip(t.getValue().decompressFiles[i], t.getValue().getDecompressTo(), t.getValue().extractRules[i]::allow, false);
|
||||
} catch (IOException ex) {
|
||||
HMCLog.err("Unable to decompress library: " + t.getValue().decompressFiles[i] + " to " + t.getValue().getDecompressTo(), ex);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,9 +25,7 @@ import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.List;
|
||||
import org.jackhuang.hmcl.api.HMCLApi;
|
||||
import org.jackhuang.hmcl.api.event.launch.DecompressLibrariesEvent;
|
||||
import org.jackhuang.hmcl.api.game.DecompressLibraryJob;
|
||||
import org.jackhuang.hmcl.api.event.launch.DownloadLibrariesEvent;
|
||||
import org.jackhuang.hmcl.api.event.launch.LaunchEvent;
|
||||
import org.jackhuang.hmcl.api.event.launch.LaunchSucceededEvent;
|
||||
import org.jackhuang.hmcl.api.event.launch.LaunchingState;
|
||||
@ -49,8 +47,9 @@ import org.jackhuang.hmcl.util.sys.FileUtils;
|
||||
import org.jackhuang.hmcl.util.sys.JavaProcess;
|
||||
import org.jackhuang.hmcl.util.sys.OS;
|
||||
import org.jackhuang.hmcl.api.auth.IAuthenticator;
|
||||
import org.jackhuang.hmcl.core.download.DownloadLibraryJob;
|
||||
|
||||
public class GameLauncher {
|
||||
public abstract class GameLauncher {
|
||||
|
||||
LaunchOptions options;
|
||||
IMinecraftService service;
|
||||
@ -128,18 +127,22 @@ public class GameLauncher {
|
||||
if (!options.isNotCheckGame()) {
|
||||
HMCLog.log("Detecting libraries...");
|
||||
HMCLApi.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(this, LaunchingState.DownloadingLibraries));
|
||||
if (!HMCLApi.EVENT_BUS.fireChannelResulted(new DownloadLibrariesEvent(this, service.download().getDownloadLibraries(loader.getMinecraftVersion()))))
|
||||
if (!downloadLibraries(service.download().getDownloadLibraries(loader.getMinecraftVersion())))
|
||||
throw new GameException("Failed to download libraries");
|
||||
}
|
||||
|
||||
HMCLog.log("Unpacking natives...");
|
||||
HMCLApi.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(this, LaunchingState.DecompressingNatives));
|
||||
DecompressLibraryJob job = service.version().getDecompressLibraries(loader.getMinecraftVersion());
|
||||
if (!HMCLApi.EVENT_BUS.fireChannelResulted(new DecompressLibrariesEvent(this, job)))
|
||||
if (!decompressLibraries(job))
|
||||
throw new GameException("Failed to decompress natives");
|
||||
|
||||
HMCLApi.EVENT_BUS.fireChannel(new LaunchSucceededEvent(this, loader.makeLaunchingCommand()));
|
||||
}
|
||||
|
||||
public abstract boolean downloadLibraries(List<DownloadLibraryJob> jobs);
|
||||
|
||||
public abstract boolean decompressLibraries(DecompressLibraryJob job);
|
||||
|
||||
/**
|
||||
* Launch the game "as soon as possible".
|
||||
|
@ -18,7 +18,8 @@
|
||||
package org.jackhuang.hmcl.core.launch;
|
||||
|
||||
import org.jackhuang.hmcl.util.C;
|
||||
import org.jackhuang.hmcl.api.event.launch.DownloadLibraryJob;
|
||||
import org.jackhuang.hmcl.core.download.DownloadLibraryJob;
|
||||
import org.jackhuang.hmcl.core.download.DownloadType;
|
||||
import org.jackhuang.hmcl.util.net.FileDownloadTask;
|
||||
|
||||
/**
|
||||
@ -29,8 +30,8 @@ public class LibraryDownloadTask extends FileDownloadTask {
|
||||
|
||||
DownloadLibraryJob job;
|
||||
|
||||
public LibraryDownloadTask(DownloadLibraryJob job) {
|
||||
super(job.parse().url, job.path);
|
||||
public LibraryDownloadTask(DownloadLibraryJob job, DownloadType downloadType) {
|
||||
super(job.parse(downloadType).url, job.path);
|
||||
this.job = job;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ package org.jackhuang.hmcl.core.service;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import org.jackhuang.hmcl.core.GameException;
|
||||
import org.jackhuang.hmcl.api.event.launch.DownloadLibraryJob;
|
||||
import org.jackhuang.hmcl.core.download.DownloadLibraryJob;
|
||||
import org.jackhuang.hmcl.core.version.MinecraftVersion;
|
||||
import org.jackhuang.hmcl.util.task.Task;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user