mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-14 22:37:06 -04:00
Fix FileNotFoundException *.hmc when launching.
This commit is contained in:
parent
bee81fd6d9
commit
0df7479e64
1
.gitignore
vendored
1
.gitignore
vendored
@ -18,6 +18,7 @@ hs_err_pid*
|
||||
*.bat
|
||||
*.log
|
||||
.mine*
|
||||
*.json
|
||||
|
||||
HMCLAPI/build/
|
||||
HMCL/build/
|
||||
|
@ -90,7 +90,7 @@ task proguard(type: proguard.gradle.ProGuardTask, dependsOn: jar) {
|
||||
|
||||
configuration 'proguard.pro'
|
||||
}
|
||||
|
||||
/*
|
||||
task makeExecutable(dependsOn: jar) {
|
||||
ext {
|
||||
def re = jar.classifier
|
||||
@ -111,7 +111,7 @@ task makeExecutable(dependsOn: jar) {
|
||||
fos.write(bytes, 0, read);
|
||||
is.close()
|
||||
fos.close()
|
||||
}
|
||||
}*/
|
||||
|
||||
launch4j {
|
||||
launch4jCmd = 'D:\\Develop\\Java\\Launch4j\\launch4j.exe'
|
||||
@ -135,5 +135,5 @@ processResources {
|
||||
}
|
||||
}
|
||||
|
||||
//build.dependsOn proguard
|
||||
build.dependsOn makeExecutable
|
||||
build.dependsOn proguard
|
||||
//build.dependsOn makeExecutable
|
@ -36,6 +36,7 @@ import org.jackhuang.hellominecraft.utils.JdkVersion;
|
||||
import org.jackhuang.hellominecraft.utils.LauncherPrintStream;
|
||||
import org.jackhuang.hellominecraft.utils.MessageBox;
|
||||
import org.jackhuang.hellominecraft.utils.OS;
|
||||
import org.jackhuang.hellominecraft.utils.Platform;
|
||||
import org.jackhuang.hellominecraft.utils.Utils;
|
||||
|
||||
/**
|
||||
@ -105,7 +106,7 @@ public final class Launcher {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!JdkVersion.isJava64Bit() && OS.is64Bit())
|
||||
if (!JdkVersion.isJava64Bit() && OS.getPlatform() == Platform.BIT_32)
|
||||
MessageBox.Show(C.i18n("advice.os64butjdk32"));
|
||||
|
||||
Method minecraftMain;
|
||||
|
@ -26,11 +26,12 @@ import org.jackhuang.hellominecraft.HMCLog;
|
||||
import org.jackhuang.hellominecraft.launcher.Launcher;
|
||||
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
|
||||
import org.jackhuang.hellominecraft.launcher.utils.settings.Profile;
|
||||
import org.jackhuang.hellominecraft.utils.FileUtils;
|
||||
import org.jackhuang.hellominecraft.launcher.utils.settings.Settings;
|
||||
import org.jackhuang.hellominecraft.utils.JdkVersion;
|
||||
import org.jackhuang.hellominecraft.utils.MathUtils;
|
||||
import org.jackhuang.hellominecraft.utils.MessageBox;
|
||||
import org.jackhuang.hellominecraft.utils.OS;
|
||||
import org.jackhuang.hellominecraft.utils.Platform;
|
||||
import org.jackhuang.hellominecraft.utils.StrUtils;
|
||||
import org.jackhuang.hellominecraft.utils.Utils;
|
||||
|
||||
@ -62,24 +63,16 @@ public abstract class IMinecraftLoader {
|
||||
res.addAll(Arrays.asList(v.getWrapperLauncher().split(" ")));
|
||||
|
||||
String str = v.getJavaDir();
|
||||
JdkVersion jv = null;
|
||||
File f = new File(str + ".hmc");
|
||||
try {
|
||||
String s = FileUtils.readFileToString(f);
|
||||
String[] strs = s.split("\n");
|
||||
if (str.length() >= 2)
|
||||
jv = new JdkVersion(strs[0], MathUtils.parseInt(strs[1], -1));
|
||||
else
|
||||
throw new IllegalStateException("The format of file: " + f + " is wrong: " + s);
|
||||
} catch (IOException | IllegalStateException e) {
|
||||
try {
|
||||
JdkVersion jv = new JdkVersion(str);
|
||||
if(Settings.getInstance().getJava().contains(jv))
|
||||
jv = Settings.getInstance().getJava().get(Settings.getInstance().getJava().indexOf(jv));
|
||||
else try {
|
||||
jv = JdkVersion.getJavaVersionFromExecutable(str);
|
||||
jv.write(f);
|
||||
if (!f.exists())
|
||||
HMCLog.warn("Failed to load version from file " + f, e);
|
||||
} catch (Exception ex) {
|
||||
HMCLog.warn("Failed to read JDKVersion.", ex);
|
||||
}
|
||||
Settings.getInstance().getJava().add(jv);
|
||||
Settings.save();
|
||||
} catch (IOException ex) {
|
||||
HMCLog.warn("Failed to get java version", ex);
|
||||
jv = null;
|
||||
}
|
||||
res.add(str);
|
||||
|
||||
@ -95,12 +88,12 @@ public abstract class IMinecraftLoader {
|
||||
res.add("-Xmn128m");
|
||||
}
|
||||
|
||||
if (jv != null && jv.is64Bit == 0 && OS.is64Bit())
|
||||
if (jv != null && jv.platform == Platform.BIT_32 && OS.getPlatform() == Platform.BIT_64)
|
||||
MessageBox.Show(C.i18n("advice.os64butjdk32"));
|
||||
|
||||
if (!StrUtils.isBlank(v.getMaxMemory())) {
|
||||
int mem = MathUtils.parseMemory(v.getMaxMemory(), 2147483647);
|
||||
if (jv != null && jv.is64Bit == 0 && mem > 1024)
|
||||
if (jv != null && jv.platform == Platform.BIT_32 && mem > 1024)
|
||||
MessageBox.Show(C.i18n("launch.too_big_memory_alloc_64bit"));
|
||||
else {
|
||||
long a = OS.getTotalPhysicalMemory() / 1024 / 1024;
|
||||
@ -114,10 +107,10 @@ public abstract class IMinecraftLoader {
|
||||
}
|
||||
|
||||
if (!StrUtils.isBlank(v.getPermSize()) && !v.isNoJVMArgs())
|
||||
if (jv != null && jv.ver != null && (jv.ver.startsWith("1.8") || jv.ver.startsWith("1.9"))); else res.add("-XX:MaxPermSize=" + v.getPermSize() + "m");
|
||||
if (jv != null && jv.ver != null && (jv.ver.startsWith("1.8") || jv.ver.startsWith("1.9")));
|
||||
else res.add("-XX:MaxPermSize=" + v.getPermSize() + "m");
|
||||
|
||||
if (!v.isNoJVMArgs())
|
||||
appendJVMArgs(res);
|
||||
if (!v.isNoJVMArgs()) appendJVMArgs(res);
|
||||
|
||||
HMCLog.log("On making java.library.path.");
|
||||
|
||||
|
@ -14,10 +14,11 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.utils;
|
||||
package org.jackhuang.hellominecraft.launcher.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import org.jackhuang.hellominecraft.utils.FileUtils;
|
||||
|
||||
/**
|
||||
*
|
@ -18,9 +18,12 @@ package org.jackhuang.hellominecraft.launcher.utils.settings;
|
||||
|
||||
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.UUID;
|
||||
import org.jackhuang.hellominecraft.utils.JdkVersion;
|
||||
import org.jackhuang.hellominecraft.utils.OS;
|
||||
|
||||
/**
|
||||
@ -42,6 +45,12 @@ public final class Config {
|
||||
@SerializedName("theme")
|
||||
private int theme;
|
||||
|
||||
private List<JdkVersion> java;
|
||||
|
||||
public List<JdkVersion> getJava() {
|
||||
return java == null ? java = new ArrayList<>() : java;
|
||||
}
|
||||
|
||||
public int getTheme() {
|
||||
return theme;
|
||||
}
|
||||
|
@ -16,6 +16,8 @@
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.launcher.utils.settings;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -25,10 +27,12 @@ import java.util.Objects;
|
||||
import org.jackhuang.hellominecraft.C;
|
||||
import org.jackhuang.hellominecraft.HMCLog;
|
||||
import org.jackhuang.hellominecraft.launcher.Main;
|
||||
import org.jackhuang.hellominecraft.utils.EnumAdapter;
|
||||
import org.jackhuang.hellominecraft.utils.tinystream.CollectionUtils;
|
||||
import org.jackhuang.hellominecraft.utils.FileUtils;
|
||||
import org.jackhuang.hellominecraft.utils.IOUtils;
|
||||
import org.jackhuang.hellominecraft.utils.MessageBox;
|
||||
import org.jackhuang.hellominecraft.utils.Platform;
|
||||
import org.jackhuang.hellominecraft.utils.StrUtils;
|
||||
import org.jackhuang.hellominecraft.utils.UpdateChecker;
|
||||
import org.jackhuang.hellominecraft.utils.VersionNumber;
|
||||
@ -38,7 +42,9 @@ import org.jackhuang.hellominecraft.utils.VersionNumber;
|
||||
* @author hyh
|
||||
*/
|
||||
public final class Settings {
|
||||
|
||||
public static final File settingsFile = new File(IOUtils.currentDir(), "hmcl.json");
|
||||
public static final Gson gson = new GsonBuilder().setPrettyPrinting().registerTypeAdapter(Platform.class, new EnumAdapter<>(Platform.values())).create();
|
||||
|
||||
private static boolean isFirstLoad;
|
||||
private static final Config settings;
|
||||
@ -55,7 +61,7 @@ public final class Settings {
|
||||
static {
|
||||
settings = initSettings();
|
||||
isFirstLoad = StrUtils.isBlank(settings.getUsername());
|
||||
if(!getVersions().containsKey("Default"))
|
||||
if (!getVersions().containsKey("Default"))
|
||||
getVersions().put("Default", new Profile());
|
||||
|
||||
UPDATE_CHECKER = new UpdateChecker(new VersionNumber(Main.firstVer, Main.secondVer, Main.thirdVer),
|
||||
@ -64,14 +70,14 @@ public final class Settings {
|
||||
|
||||
private static Config initSettings() {
|
||||
Config c = new Config();
|
||||
if (settingsFile.exists()) {
|
||||
if (settingsFile.exists())
|
||||
try {
|
||||
String str = FileUtils.readFileToString(settingsFile);
|
||||
if (str == null || str.trim().equals("")) {
|
||||
if (str == null || str.trim().equals(""))
|
||||
HMCLog.log("Settings file is empty, use the default settings.");
|
||||
} else {
|
||||
Config d = C.gsonPrettyPrinting.fromJson(str, Config.class);
|
||||
if(d != null) c = d;
|
||||
else {
|
||||
Config d = gson.fromJson(str, Config.class);
|
||||
if (d != null) c = d;
|
||||
}
|
||||
HMCLog.log("Initialized settings.");
|
||||
} catch (IOException | JsonSyntaxException e) {
|
||||
@ -81,7 +87,7 @@ public final class Settings {
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
else {
|
||||
HMCLog.log("No settings file here, may be first loading.");
|
||||
isFirstLoad = true;
|
||||
}
|
||||
@ -90,7 +96,7 @@ public final class Settings {
|
||||
|
||||
public static void save() {
|
||||
try {
|
||||
FileUtils.write(settingsFile, C.gsonPrettyPrinting.toJson(settings));
|
||||
FileUtils.write(settingsFile, gson.toJson(settings));
|
||||
} catch (IOException ex) {
|
||||
HMCLog.err("Failed to save config", ex);
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import org.jackhuang.hellominecraft.launcher.launch.GameLauncher.DownloadLibrary
|
||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftLoader;
|
||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
||||
import org.jackhuang.hellominecraft.launcher.launch.MinecraftLoader;
|
||||
import org.jackhuang.hellominecraft.utils.BaseLauncherProfile;
|
||||
import org.jackhuang.hellominecraft.launcher.utils.BaseLauncherProfile;
|
||||
import org.jackhuang.hellominecraft.utils.FileUtils;
|
||||
import org.jackhuang.hellominecraft.launcher.utils.MCUtils;
|
||||
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
|
||||
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 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 2 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.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.utils;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
* @param <T> EnumType
|
||||
*/
|
||||
public class EnumAdapter<T extends Enum> implements JsonSerializer<T>, JsonDeserializer<T> {
|
||||
T[] values;
|
||||
|
||||
public EnumAdapter(T[] values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(T src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
return new JsonPrimitive(src.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public T deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
if(json.getAsInt() < values.length)
|
||||
return values[json.getAsInt()];
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -35,11 +35,32 @@ public final class JdkVersion {
|
||||
/**
|
||||
* -1 - unkown 0 - 32Bit 1 - 64Bit
|
||||
*/
|
||||
public int is64Bit;
|
||||
public Platform platform;
|
||||
|
||||
public JdkVersion(String ver, int is64Bit) {
|
||||
public String location;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof JdkVersion)) return false;
|
||||
JdkVersion b = (JdkVersion)obj;
|
||||
return new File(b.location).equals(new File(location));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new File(location).hashCode();
|
||||
}
|
||||
|
||||
public JdkVersion(String location) {
|
||||
File f = new File(location);
|
||||
if(f.exists() && f.isFile()) f = f.getParentFile();
|
||||
this.location = f.getAbsolutePath();
|
||||
}
|
||||
|
||||
public JdkVersion(String location, String ver, Platform platform) {
|
||||
this(location);
|
||||
this.ver = ver;
|
||||
this.is64Bit = is64Bit;
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -146,7 +167,7 @@ public final class JdkVersion {
|
||||
BufferedReader br = null;
|
||||
int lineNumber = 0;
|
||||
String ver = null;
|
||||
int is64Bit = -1;
|
||||
Platform platform = Platform.UNKNOWN;
|
||||
try {
|
||||
br = new BufferedReader(new InputStreamReader(is));
|
||||
String line;
|
||||
@ -162,11 +183,10 @@ public final class JdkVersion {
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (line.contains("64-Bit")) {
|
||||
is64Bit = 1;
|
||||
} else {
|
||||
is64Bit = 0;
|
||||
}
|
||||
if (line.contains("64-Bit"))
|
||||
platform = Platform.BIT_64;
|
||||
else
|
||||
platform = Platform.BIT_32;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -177,12 +197,12 @@ public final class JdkVersion {
|
||||
br.close();
|
||||
}
|
||||
}
|
||||
return new JdkVersion(ver, is64Bit);
|
||||
return new JdkVersion(file, ver, platform);
|
||||
}
|
||||
|
||||
public void write(File f) throws IOException {
|
||||
if (ver != null && is64Bit != -1) {
|
||||
FileUtils.write(f, ver + "\n" + is64Bit);
|
||||
if (ver != null && platform != Platform.UNKNOWN) {
|
||||
FileUtils.write(f, ver + "\n" + platform);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,9 +54,9 @@ public enum OS {
|
||||
return OS.UNKOWN;
|
||||
}
|
||||
|
||||
public static boolean is64Bit() {
|
||||
public static Platform getPlatform() {
|
||||
String arch = System.getProperty("os.arch");
|
||||
return arch.contains("64");
|
||||
return arch.contains("64") ? Platform.BIT_64 : Platform.BIT_32;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 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 2 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.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.utils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public enum Platform {
|
||||
UNKNOWN,
|
||||
BIT_32,
|
||||
BIT_64
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user