Fixed #66
This commit is contained in:
@@ -20,7 +20,6 @@ package org.jackhuang.hellominecraft.launcher.core;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import org.jackhuang.hellominecraft.util.system.FileUtils;
|
||||
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
||||
import org.jackhuang.hellominecraft.util.system.OS;
|
||||
|
||||
/**
|
||||
@@ -63,14 +62,11 @@ public final class MCUtils {
|
||||
}
|
||||
|
||||
public static File getInitGameDir() {
|
||||
File gameDir = IOUtils.currentDir();
|
||||
if (gameDir.exists()) {
|
||||
gameDir = new File(gameDir, MCUtils.minecraft());
|
||||
if (!gameDir.exists()) {
|
||||
File newFile = MCUtils.getLocation();
|
||||
if (newFile.exists())
|
||||
gameDir = newFile;
|
||||
}
|
||||
File gameDir = new File(MCUtils.minecraft());
|
||||
if (!gameDir.exists()) {
|
||||
File newFile = MCUtils.getLocation();
|
||||
if (newFile.exists())
|
||||
gameDir = newFile;
|
||||
}
|
||||
return gameDir;
|
||||
}
|
||||
@@ -80,6 +76,6 @@ public final class MCUtils {
|
||||
public static void tryWriteProfile(File gameDir) throws IOException {
|
||||
File file = new File(gameDir, "launcher_profiles.json");
|
||||
if (!file.exists())
|
||||
FileUtils.writeStringToFile(file, PROFILE);
|
||||
FileUtils.write(file, PROFILE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class AssetsMojangLoader extends IAssetsHandler {
|
||||
public void executeTask() throws Throwable {
|
||||
if (!areDependTasksSucceeded)
|
||||
throw new IllegalStateException("Failed to get asset index");
|
||||
String result = FileUtils.readFileToString(f);
|
||||
String result = FileUtils.read(f);
|
||||
if (StrUtils.isBlank(result))
|
||||
throw new IllegalStateException("Index json is empty, please redownload it!");
|
||||
AssetsIndex o = C.GSON.fromJson(result, AssetsIndex.class);
|
||||
|
||||
@@ -133,7 +133,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
|
||||
File objectsDir = new File(assetsDir, "objects");
|
||||
File indexFile = new File(indexDir, assetVersion + ".json");
|
||||
try {
|
||||
AssetsIndex index = (AssetsIndex) C.GSON.fromJson(FileUtils.readFileToString(indexFile, "UTF-8"), AssetsIndex.class);
|
||||
AssetsIndex index = (AssetsIndex) C.GSON.fromJson(FileUtils.read(indexFile, "UTF-8"), AssetsIndex.class);
|
||||
|
||||
String hash = ((AssetsObject) index.getFileMap().get(name)).getHash();
|
||||
return new File(objectsDir, hash.substring(0, 2) + "/" + hash);
|
||||
@@ -152,7 +152,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
|
||||
return false;
|
||||
|
||||
try {
|
||||
String assetIndexContent = FileUtils.readFileToString(indexFile, "UTF-8");
|
||||
String assetIndexContent = FileUtils.read(indexFile, "UTF-8");
|
||||
AssetsIndex index = (AssetsIndex) C.GSON.fromJson(assetIndexContent, AssetsIndex.class);
|
||||
|
||||
if (index == null)
|
||||
@@ -180,7 +180,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
|
||||
}
|
||||
|
||||
try {
|
||||
String assetIndexContent = FileUtils.readFileToString(indexFile, "UTF-8");
|
||||
String assetIndexContent = FileUtils.read(indexFile, "UTF-8");
|
||||
AssetsIndex index = (AssetsIndex) C.GSON.fromJson(assetIndexContent, AssetsIndex.class);
|
||||
|
||||
if (index == null)
|
||||
@@ -195,7 +195,7 @@ public class MinecraftAssetService extends IMinecraftAssetService {
|
||||
if (original.exists()) {
|
||||
cnt++;
|
||||
if (!target.isFile())
|
||||
FileUtils.copyFile(original, target, false);
|
||||
FileUtils.copyFile(original, target);
|
||||
}
|
||||
}
|
||||
// If the scale new format existent file is lower then 0.1, use the old format.
|
||||
|
||||
@@ -85,7 +85,7 @@ public class MinecraftDownloadService extends IMinecraftDownloadService {
|
||||
if (mvj.exists() && !mvj.delete())
|
||||
HMCLog.warn("Failed to delete " + mvj);
|
||||
try {
|
||||
MinecraftVersion mv = C.GSON.fromJson(FileUtils.readFileToStringQuietly(new File(vpath, id + ".json")), MinecraftVersion.class);
|
||||
MinecraftVersion mv = C.GSON.fromJson(FileUtils.readQuietly(new File(vpath, id + ".json")), MinecraftVersion.class);
|
||||
if (mv == null)
|
||||
throw new JsonSyntaxException("incorrect version");
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
|
||||
|
||||
@Override
|
||||
public Task downloadForge(String installId, InstallerVersion v) {
|
||||
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "forge-installer.jar");
|
||||
File filepath = IOUtils.tryGetCanonicalFile("forge-installer.jar");
|
||||
if (v.installer == null)
|
||||
return null;
|
||||
else
|
||||
@@ -68,7 +68,7 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
|
||||
|
||||
@Override
|
||||
public Task downloadOptiFine(String installId, InstallerVersion v) {
|
||||
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "optifine-installer.jar");
|
||||
File filepath = IOUtils.tryGetCanonicalFile("optifine-installer.jar");
|
||||
if (v.installer == null)
|
||||
return null;
|
||||
OptiFineDownloadFormatter task = new OptiFineDownloadFormatter(v.installer);
|
||||
@@ -79,7 +79,7 @@ public final class MinecraftInstallerService extends IMinecraftInstallerService
|
||||
|
||||
@Override
|
||||
public Task downloadLiteLoader(String installId, InstallerVersion v) {
|
||||
File filepath = IOUtils.tryGetCanonicalFile(IOUtils.currentDirWithSeparator() + "liteloader-universal.jar");
|
||||
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));
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.ArrayList;
|
||||
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
||||
import org.jackhuang.hellominecraft.util.system.Compressor;
|
||||
import org.jackhuang.hellominecraft.util.system.FileUtils;
|
||||
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -40,7 +39,7 @@ public class PackMinecraftInstaller {
|
||||
}
|
||||
|
||||
public void install() throws IOException {
|
||||
File file = new File(IOUtils.currentDir(), "HMCL-MERGE-TEMP");
|
||||
File file = new File("HMCL-MERGE-TEMP");
|
||||
if (!file.exists() && !file.mkdirs())
|
||||
HMCLog.warn("Failed to make directories: " + file);
|
||||
for (String src1 : src)
|
||||
|
||||
@@ -79,7 +79,7 @@ public class OptiFineInstaller extends Task implements PreviousResultRegistrar<F
|
||||
if (!loc.exists() && loc.mkdirs())
|
||||
HMCLog.warn("Failed to make directories: " + loc);
|
||||
File json = new File(loc, mv.id + ".json");
|
||||
FileUtils.writeStringToFile(json, C.GSON.toJson(mv, MinecraftVersion.class));
|
||||
FileUtils.write(json, C.GSON.toJson(mv, MinecraftVersion.class));
|
||||
|
||||
service.version().refreshVersions();
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.jackhuang.hellominecraft.util.MessageBox;
|
||||
import org.jackhuang.hellominecraft.util.system.OS;
|
||||
import org.jackhuang.hellominecraft.util.system.Platform;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
import org.jackhuang.hellominecraft.util.Utils;
|
||||
import org.jackhuang.hellominecraft.launcher.core.GameException;
|
||||
import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider;
|
||||
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
|
||||
|
||||
@@ -121,7 +121,7 @@ public class GameLauncher {
|
||||
* @throws IOException failed creating process
|
||||
*/
|
||||
public void launch(List str) throws IOException {
|
||||
if (!service.version().onLaunch())
|
||||
if (!service.version().onLaunch(options.getLaunchVersion()))
|
||||
return;
|
||||
if (StrUtils.isNotBlank(options.getPrecalledCommand())) {
|
||||
Process p = Runtime.getRuntime().exec(options.getPrecalledCommand());
|
||||
@@ -155,7 +155,7 @@ public class GameLauncher {
|
||||
*/
|
||||
public File makeLauncher(String launcherName, List str) throws IOException {
|
||||
HMCLog.log("Making shell launcher...");
|
||||
service.version().onLaunch();
|
||||
service.version().onLaunch(options.getLaunchVersion());
|
||||
boolean isWin = OS.os() == OS.WINDOWS;
|
||||
File f = new File(launcherName + (isWin ? ".bat" : ".sh"));
|
||||
if (!f.exists() && !f.createNewFile())
|
||||
|
||||
@@ -164,13 +164,13 @@ public final class ModpackManager {
|
||||
HMCLog.warn("Failed to rename incorrect json " + oldFile + " to " + nowFile);
|
||||
|
||||
File json = new File(nowFile, "pack.json");
|
||||
MinecraftVersion mv = C.GSON.fromJson(FileUtils.readFileToString(json), MinecraftVersion.class);
|
||||
MinecraftVersion mv = C.GSON.fromJson(FileUtils.read(json), MinecraftVersion.class);
|
||||
if (mv.jar == null)
|
||||
throw new FileNotFoundException(C.i18n("modpack.incorrect_format.no_jar"));
|
||||
|
||||
c.add(service.download().downloadMinecraftJar(mv, new File(nowFile, id + ".jar")));
|
||||
mv.jar = null;
|
||||
FileUtils.writeStringToFile(json, C.GSON.toJson(mv));
|
||||
FileUtils.write(json, C.GSON.toJson(mv));
|
||||
if (!json.renameTo(new File(nowFile, id + ".json")))
|
||||
HMCLog.warn("Failed to rename pack.json to new id");
|
||||
|
||||
|
||||
@@ -72,13 +72,6 @@ public abstract class IMinecraftProvider {
|
||||
*/
|
||||
public abstract boolean install(String version, Consumer<MinecraftVersion> callback);
|
||||
|
||||
/**
|
||||
* Returns the thing like ".minecraft/resourcepacks".
|
||||
*
|
||||
* @return the thing
|
||||
*/
|
||||
public abstract File getResourcePacks();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param v should be resolved
|
||||
@@ -164,7 +157,7 @@ public abstract class IMinecraftProvider {
|
||||
*
|
||||
* @return if false, will break the launch process.
|
||||
*/
|
||||
public abstract boolean onLaunch();
|
||||
public abstract boolean onLaunch(String id);
|
||||
|
||||
public File baseDirectory() {
|
||||
return service.baseDirectory();
|
||||
|
||||
@@ -111,7 +111,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
||||
}
|
||||
MinecraftVersion mcVersion;
|
||||
try {
|
||||
mcVersion = C.GSON.fromJson(FileUtils.readFileToString(jsonFile), MinecraftVersion.class);
|
||||
mcVersion = C.GSON.fromJson(FileUtils.read(jsonFile), MinecraftVersion.class);
|
||||
if (mcVersion == null)
|
||||
throw new GameException("Wrong json format, got null.");
|
||||
} catch (Exception e) {
|
||||
@@ -119,7 +119,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
||||
if (MessageBox.Show(C.i18n("launcher.versions_json_not_formatted", id), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
|
||||
service.download().downloadMinecraftVersionJson(id);
|
||||
try {
|
||||
mcVersion = C.GSON.fromJson(FileUtils.readFileToString(jsonFile), MinecraftVersion.class);
|
||||
mcVersion = C.GSON.fromJson(FileUtils.read(jsonFile), MinecraftVersion.class);
|
||||
if (mcVersion == null)
|
||||
throw new GameException("Wrong json format, got null.");
|
||||
} catch (IOException | GameException | JsonSyntaxException ex) {
|
||||
@@ -164,7 +164,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
||||
public boolean renameVersion(String from, String to) {
|
||||
try {
|
||||
File fromJson = new File(versionRoot(from), from + ".json");
|
||||
MinecraftVersion mcVersion = C.GSON.fromJson(FileUtils.readFileToString(fromJson), MinecraftVersion.class);
|
||||
MinecraftVersion mcVersion = C.GSON.fromJson(FileUtils.read(fromJson), MinecraftVersion.class);
|
||||
mcVersion.id = to;
|
||||
FileUtils.writeQuietly(fromJson, C.GSON.toJson(mcVersion));
|
||||
File toDir = versionRoot(to);
|
||||
@@ -198,7 +198,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
||||
return false;
|
||||
if (callback != null) {
|
||||
File mvt = new File(versionRoot(id), id + ".json");
|
||||
MinecraftVersion v = C.GSON.fromJson(FileUtils.readFileToStringQuietly(mvt), MinecraftVersion.class);
|
||||
MinecraftVersion v = C.GSON.fromJson(FileUtils.readQuietly(mvt), MinecraftVersion.class);
|
||||
if (v == null)
|
||||
return false;
|
||||
callback.accept(v);
|
||||
@@ -254,13 +254,8 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getResourcePacks() {
|
||||
return new File(service.baseDirectory(), "resourcepacks");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLaunch() {
|
||||
File resourcePacks = getResourcePacks();
|
||||
public boolean onLaunch(String id) {
|
||||
File resourcePacks = new File(getRunDirectory(id), "resourcepacks");
|
||||
if (!resourcePacks.exists() && !resourcePacks.mkdirs())
|
||||
HMCLog.warn("Failed to make resourcePacks: " + resourcePacks);
|
||||
return true;
|
||||
|
||||
@@ -46,7 +46,7 @@ public final class Profile {
|
||||
}
|
||||
|
||||
public Profile(String name) {
|
||||
this(name, new File(IOUtils.currentDir(), ".minecraft").getPath());
|
||||
this(name, new File(".minecraft").getPath());
|
||||
}
|
||||
|
||||
public Profile(String name, String gameDir) {
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
|
||||
import org.jackhuang.hellominecraft.util.CollectionUtils;
|
||||
import org.jackhuang.hellominecraft.util.EventHandler;
|
||||
import org.jackhuang.hellominecraft.util.system.FileUtils;
|
||||
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
||||
import org.jackhuang.hellominecraft.util.MessageBox;
|
||||
import org.jackhuang.hellominecraft.util.UpdateChecker;
|
||||
|
||||
@@ -43,7 +42,7 @@ public final class Settings {
|
||||
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("hmcl.json");
|
||||
|
||||
private static final Config SETTINGS;
|
||||
public static final UpdateChecker UPDATE_CHECKER = new UpdateChecker(Main.getVersionNumber(), "hmcl");
|
||||
@@ -71,7 +70,7 @@ public final class Settings {
|
||||
Config c = new Config();
|
||||
if (SETTINGS_FILE.exists())
|
||||
try {
|
||||
String str = FileUtils.readFileToString(SETTINGS_FILE);
|
||||
String str = FileUtils.read(SETTINGS_FILE);
|
||||
if (str == null || str.trim().equals(""))
|
||||
HMCLog.log("Settings file is empty, use the default settings.");
|
||||
else {
|
||||
|
||||
@@ -406,10 +406,6 @@
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="txtWrapperLauncher" alignment="0" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="lblPrecalledCommand1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="chkNoJVMArgs" min="-2" max="-2" attributes="0"/>
|
||||
@@ -418,6 +414,7 @@
|
||||
</Group>
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="lblPrecalledCommand1" alignment="0" 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>
|
||||
|
||||
@@ -61,7 +61,6 @@ import org.jackhuang.hellominecraft.util.system.OS;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
import org.jackhuang.hellominecraft.util.func.Consumer;
|
||||
import org.jackhuang.hellominecraft.util.system.FileUtils;
|
||||
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
||||
import org.jackhuang.hellominecraft.util.ui.SwingUtils;
|
||||
import org.jackhuang.hellominecraft.util.system.Java;
|
||||
import org.jackhuang.hellominecraft.util.tasks.TaskWindow;
|
||||
@@ -1095,7 +1094,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
||||
}//GEN-LAST:event_btnMakeLaunchScriptActionPerformed
|
||||
|
||||
private void btnIncludeMinecraftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIncludeMinecraftActionPerformed
|
||||
JFileChooser fc = new JFileChooser(IOUtils.currentDir());
|
||||
JFileChooser fc = new JFileChooser(new File("."));
|
||||
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
||||
File newGameDir = fc.getSelectedFile();
|
||||
|
||||
@@ -109,7 +109,7 @@ public class LaunchingUIDaemon {
|
||||
}
|
||||
String msg = C.i18n("launch.exited_abnormally") + " exit code: " + t;
|
||||
if (errorText != null)
|
||||
msg += ", advice: " + MinecraftCrashAdvicer.getAdvice(FileUtils.readFileToStringQuietly(new File(errorText)));
|
||||
msg += ", advice: " + MinecraftCrashAdvicer.getAdvice(FileUtils.readQuietly(new File(errorText)));
|
||||
MessageBox.Show(msg);
|
||||
WebFrame f = new WebFrame(logs);
|
||||
f.setModal(true);
|
||||
|
||||
@@ -91,7 +91,7 @@ public class HMCLMinecraftService extends IMinecraftService {
|
||||
VersionSetting vs = null;
|
||||
File f = new File(provider.versionRoot(id), "hmclversion.cfg");
|
||||
if (f.exists()) {
|
||||
String s = FileUtils.readFileToStringQuietly(f);
|
||||
String s = FileUtils.readQuietly(f);
|
||||
if (s != null)
|
||||
try {
|
||||
vs = C.GSON.fromJson(s, VersionSetting.class);
|
||||
|
||||
@@ -81,7 +81,7 @@ public class AppDataUpgrader extends IUpgrader {
|
||||
try {
|
||||
File f = AppDataUpgraderTask.HMCL_VER_FILE;
|
||||
if (f.exists()) {
|
||||
Map<String, String> m = C.GSON.fromJson(FileUtils.readFileToString(f), Map.class);
|
||||
Map<String, String> m = C.GSON.fromJson(FileUtils.read(f), Map.class);
|
||||
String s = m.get("ver");
|
||||
if (s != null && VersionNumber.check(s).compareTo(nowVersion) > 0) {
|
||||
String j = m.get("loc");
|
||||
@@ -179,7 +179,7 @@ public class AppDataUpgrader extends IUpgrader {
|
||||
json.put("ver", newestVersion);
|
||||
json.put("loc", f.getAbsolutePath());
|
||||
String result = C.GSON.toJson(json);
|
||||
FileUtils.writeStringToFile(HMCL_VER_FILE, result);
|
||||
FileUtils.write(HMCL_VER_FILE, result);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user