Fix FileNotFoundException *.hmc when launching.

This commit is contained in:
huanghongxun
2015-06-26 18:55:36 +08:00
parent bee81fd6d9
commit 0df7479e64
12 changed files with 175 additions and 65 deletions

View File

@@ -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;
}
}

View File

@@ -35,11 +35,32 @@ public final class JdkVersion {
/**
* -1 - unkown 0 - 32Bit 1 - 64Bit
*/
public int is64Bit;
public Platform platform;
public String location;
public JdkVersion(String ver, int is64Bit) {
@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);
}
}

View File

@@ -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;
}
/**

View File

@@ -16,18 +16,12 @@
*/
package org.jackhuang.hellominecraft.utils;
import java.io.File;
import java.io.IOException;
/**
*
* @author hyh
* @author huangyuhui
*/
public class BaseLauncherProfile {
public static String profile = "{\"selectedProfile\": \"(Default)\",\"profiles\": {\"(Default)\": {\"name\": \"(Default)\"}},\"clientToken\": \"88888888-8888-8888-8888-888888888888\"}";
public static void tryWriteProfile(File gameDir) throws IOException {
File file = new File(gameDir, "launcher_profiles.json");
if(!file.exists())
FileUtils.writeStringToFile(file, profile);
}
public enum Platform {
UNKNOWN,
BIT_32,
BIT_64
}