Load plugins from jar file
This commit is contained in:
@@ -36,7 +36,6 @@ import org.jackhuang.hmcl.util.task.Task;
|
||||
import org.jackhuang.hmcl.util.task.TaskWindow;
|
||||
import org.jackhuang.hmcl.util.net.FileDownloadTask;
|
||||
import org.jackhuang.hmcl.util.sys.FileUtils;
|
||||
import org.jackhuang.hmcl.util.sys.IOUtils;
|
||||
import org.jackhuang.hmcl.util.task.TaskInfo;
|
||||
|
||||
/**
|
||||
@@ -84,7 +83,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
|
||||
return new TaskInfo("Download Asset Index") {
|
||||
@Override
|
||||
public Collection<Task> getDependTasks() {
|
||||
return Arrays.asList(new FileDownloadTask(assetIndex.getUrl(service.getDownloadType()), IOUtils.tryGetCanonicalFile(assetsIndex), assetIndex.sha1).setTag(assetIndex.getId() + ".json"));
|
||||
return Arrays.asList(new FileDownloadTask(assetIndex.getUrl(service.getDownloadType()), assetsIndex, assetIndex.sha1).setTag(assetIndex.getId() + ".json"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -111,7 +110,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
|
||||
HMCLog.warn("Failed to rename " + assetsIndex + " to " + renamed);
|
||||
}
|
||||
if (TaskWindow.factory()
|
||||
.append(new FileDownloadTask(assetIndex.getUrl(service.getDownloadType()), IOUtils.tryGetCanonicalFile(assetsIndex), assetIndex.sha1).setTag(assetIndex.getId() + ".json"))
|
||||
.append(new FileDownloadTask(assetIndex.getUrl(service.getDownloadType()), assetsIndex, assetIndex.sha1).setTag(assetIndex.getId() + ".json"))
|
||||
.execute()) {
|
||||
if (renamed != null && !renamed.delete())
|
||||
HMCLog.warn("Failed to delete " + renamed + ", maybe you should do it.");
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.jackhuang.hmcl.core.install.optifine.OptiFineInstaller;
|
||||
import org.jackhuang.hmcl.core.install.optifine.vanilla.OptiFineDownloadFormatter;
|
||||
import org.jackhuang.hmcl.util.task.Task;
|
||||
import org.jackhuang.hmcl.util.net.FileDownloadTask;
|
||||
import org.jackhuang.hmcl.util.sys.IOUtils;
|
||||
import org.jackhuang.hmcl.util.task.DeleteFileTask;
|
||||
|
||||
/**
|
||||
@@ -57,7 +56,7 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
|
||||
|
||||
@Override
|
||||
public Task downloadForge(String installId, InstallerVersion v) {
|
||||
File filepath = IOUtils.tryGetCanonicalFile("forge-installer.jar");
|
||||
File filepath = new File("forge-installer.jar");
|
||||
if (v.installer == null)
|
||||
return null;
|
||||
else
|
||||
@@ -68,7 +67,7 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
|
||||
|
||||
@Override
|
||||
public Task downloadOptiFine(String installId, InstallerVersion v) {
|
||||
File filepath = IOUtils.tryGetCanonicalFile("optifine-installer.jar");
|
||||
File filepath = new File("optifine-installer.jar");
|
||||
if (v.installer == null)
|
||||
return null;
|
||||
OptiFineDownloadFormatter task = new OptiFineDownloadFormatter(v.installer);
|
||||
@@ -81,7 +80,7 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
|
||||
public Task downloadLiteLoader(String installId, InstallerVersion v) {
|
||||
if (!(v instanceof LiteLoaderInstallerVersion))
|
||||
throw new Error("Download lite loader but the version is not ll's.");
|
||||
File filepath = IOUtils.tryGetCanonicalFile("liteloader-universal.jar");
|
||||
File filepath = new File("liteloader-universal.jar");
|
||||
FileDownloadTask task = (FileDownloadTask) new FileDownloadTask(v.universal, filepath).setTag("LiteLoader");
|
||||
return task.with(new LiteLoaderInstaller(service, installId, (LiteLoaderInstallerVersion) v).registerPreviousResult(task))
|
||||
.with(new DeleteFileTask(filepath));
|
||||
|
||||
@@ -45,13 +45,12 @@ import org.jackhuang.hmcl.util.StrUtils;
|
||||
import org.jackhuang.hmcl.util.code.Charsets;
|
||||
import org.jackhuang.hmcl.api.HMCLog;
|
||||
import org.jackhuang.hmcl.util.sys.FileUtils;
|
||||
import org.jackhuang.hmcl.util.sys.IOUtils;
|
||||
import org.jackhuang.hmcl.util.sys.JavaProcess;
|
||||
import org.jackhuang.hmcl.util.sys.OS;
|
||||
import org.jackhuang.hmcl.api.auth.IAuthenticator;
|
||||
|
||||
public class GameLauncher {
|
||||
|
||||
|
||||
LaunchOptions options;
|
||||
IMinecraftService service;
|
||||
LoginInfo info;
|
||||
@@ -80,7 +79,7 @@ public class GameLauncher {
|
||||
public UserProfileProvider getLoginResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private Object tag;
|
||||
|
||||
public Object getTag() {
|
||||
@@ -93,6 +92,7 @@ public class GameLauncher {
|
||||
|
||||
/**
|
||||
* Generates the launch command.
|
||||
*
|
||||
* @throws AuthenticationException having trouble logging in.
|
||||
* @throws GameException having trouble completing the game or making lanch command.
|
||||
* @throws RuntimeGameException will be thrown when someone processing login result.
|
||||
@@ -191,13 +191,10 @@ public class GameLauncher {
|
||||
if (isWin) {
|
||||
writer.write("@echo off");
|
||||
writer.newLine();
|
||||
String appdata = IOUtils.tryGetCanonicalFilePath(service.baseDirectory());
|
||||
if (appdata != null) {
|
||||
writer.write("set appdata=" + appdata);
|
||||
writer.newLine();
|
||||
writer.write("cd /D %appdata%");
|
||||
writer.newLine();
|
||||
}
|
||||
writer.write("set appdata=" + service.baseDirectory().getAbsolutePath());
|
||||
writer.newLine();
|
||||
writer.write("cd /D %appdata%");
|
||||
writer.newLine();
|
||||
}
|
||||
if (StrUtils.isNotBlank(options.getPrecalledCommand())) {
|
||||
writer.write(options.getPrecalledCommand());
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import org.jackhuang.hmcl.util.StrUtils;
|
||||
import org.jackhuang.hmcl.api.HMCLog;
|
||||
import org.jackhuang.hmcl.util.sys.IOUtils;
|
||||
import org.jackhuang.hmcl.util.sys.OS;
|
||||
import org.jackhuang.hmcl.core.GameException;
|
||||
import org.jackhuang.hmcl.api.auth.UserProfileProvider;
|
||||
@@ -66,7 +65,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
|
||||
File f = version.getJar(service.baseDirectory());
|
||||
if (!f.exists())
|
||||
throw new GameException("Minecraft jar does not exists");
|
||||
library.append(IOUtils.tryGetCanonicalFilePath(f)).append(File.pathSeparator);
|
||||
library.append(f.getAbsolutePath()).append(File.pathSeparator);
|
||||
res.add("-cp");
|
||||
res.add(library.toString().substring(0, library.length() - File.pathSeparator.length()));
|
||||
res.add(version.mainClass);
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.core.service;
|
||||
|
||||
import java.io.File;
|
||||
import org.jackhuang.hmcl.core.service.IMinecraftService;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public interface IProfile {
|
||||
|
||||
File getGameDir();
|
||||
|
||||
String getName();
|
||||
|
||||
String getSelectedVersion();
|
||||
|
||||
void onSelected();
|
||||
|
||||
IMinecraftService service();
|
||||
|
||||
void setGameDir(File gameDir);
|
||||
|
||||
void setSelectedVersion(String selectedVersion);
|
||||
|
||||
}
|
||||
@@ -39,7 +39,6 @@ import org.jackhuang.hmcl.core.service.IMinecraftService;
|
||||
import org.jackhuang.hmcl.util.sys.FileUtils;
|
||||
import org.jackhuang.hmcl.core.MCUtils;
|
||||
import org.jackhuang.hmcl.util.task.TaskWindow;
|
||||
import org.jackhuang.hmcl.util.sys.IOUtils;
|
||||
import org.jackhuang.hmcl.util.MessageBox;
|
||||
import org.jackhuang.hmcl.util.StrUtils;
|
||||
import org.jackhuang.hmcl.api.func.Consumer;
|
||||
@@ -233,7 +232,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
||||
ArrayList<Extract> extractRules = new ArrayList<>();
|
||||
for (IMinecraftLibrary l : v.libraries)
|
||||
if (l.isRequiredToUnzip() && v.isAllowedToUnpackNatives()) {
|
||||
unzippings.add(IOUtils.tryGetCanonicalFile(getLibraryFile(v, l)));
|
||||
unzippings.add(getLibraryFile(v, l));
|
||||
extractRules.add(l.getDecompressExtractRules());
|
||||
}
|
||||
return new DecompressLibraryJob(unzippings.toArray(new File[unzippings.size()]), extractRules.toArray(new Extract[extractRules.size()]), getDecompressNativesToLocation(v));
|
||||
|
||||
@@ -101,7 +101,7 @@ public final class IOUtils {
|
||||
|
||||
public static String getRealPath() {
|
||||
String realPath = IOUtils.class.getClassLoader().getResource("").getFile();
|
||||
java.io.File file = new java.io.File(realPath);
|
||||
File file = new File(realPath);
|
||||
realPath = file.getAbsolutePath();
|
||||
try {
|
||||
realPath = java.net.URLDecoder.decode(realPath, DEFAULT_CHARSET);
|
||||
@@ -229,34 +229,6 @@ public final class IOUtils {
|
||||
output.write(data.getBytes(encoding));
|
||||
}
|
||||
|
||||
public static String tryGetCanonicalFolderPath(File file) {
|
||||
try {
|
||||
return IOUtils.addSeparator(file.getCanonicalPath());
|
||||
} catch (IOException ignored) {
|
||||
return IOUtils.addSeparator(file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
public static File tryGetCanonicalFile(File file) {
|
||||
try {
|
||||
return file.getCanonicalFile();
|
||||
} catch (IOException ignored) {
|
||||
return file.getAbsoluteFile();
|
||||
}
|
||||
}
|
||||
|
||||
public static File tryGetCanonicalFile(String file) {
|
||||
return tryGetCanonicalFile(new File(file));
|
||||
}
|
||||
|
||||
public static String tryGetCanonicalFilePath(File file) {
|
||||
try {
|
||||
return file.getCanonicalPath();
|
||||
} catch (IOException ignored) {
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
}
|
||||
|
||||
public static URL parseURL(String str) {
|
||||
try {
|
||||
return new URL(str);
|
||||
|
||||
@@ -124,7 +124,7 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
if (img == null)
|
||||
try {
|
||||
img = ImageIO.read(InstructionsPanelImpl.class.getResourceAsStream(
|
||||
"/org/jackhuang/hellominecraft/wizard.jpg"));
|
||||
"/org/jackhuang/hmcl/wizard.jpg"));
|
||||
} catch (IOException ioe) {
|
||||
HMCLog.err("Failed to load wizard.jpg, maybe you fucking modified the launcher", ioe);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user