mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-11 21:06:37 -04:00
Fix mis-encoding in Windows
This commit is contained in:
parent
fdc2570945
commit
cb5391ed28
BIN
HMCL/modpack.zip
BIN
HMCL/modpack.zip
Binary file not shown.
@ -46,7 +46,6 @@ public final class Launcher {
|
||||
static final Logger LOGGER = Logger.getLogger(Launcher.class.getName());
|
||||
|
||||
static String classPath = "";
|
||||
//state String proxyHost = "", proxyPort = "", proxyUsername = "", proxyPassword = "";
|
||||
|
||||
public static void main(String[] args) {
|
||||
LOGGER.log(Level.INFO, "*** {0} ***", Main.makeTitle());
|
||||
@ -61,14 +60,6 @@ public final class Launcher {
|
||||
classPath = classPath.concat(s.substring("-cp=".length()));
|
||||
else if (s.startsWith("-mainClass="))
|
||||
mainClass = s.substring("-mainClass=".length());
|
||||
/*else if (s.startsWith("-proxyHost="))
|
||||
proxyHost = s.substring("-proxyHost=".length());
|
||||
else if (s.startsWith("-proxyPort="))
|
||||
proxyPort = s.substring("-proxyPort=".length());
|
||||
else if (s.startsWith("-proxyUsername="))
|
||||
proxyUsername = s.substring("-proxyUsername=".length());
|
||||
else if (s.startsWith("-proxyPassword="))
|
||||
proxyPassword = s.substring("-proxyPassword=".length());*/
|
||||
else if (s.equals("-debug"))
|
||||
showInfo = true;
|
||||
else
|
||||
@ -106,22 +97,6 @@ public final class Launcher {
|
||||
LOGGER.log(Level.INFO, "Class Path: '{'\n{0}\n'}'", StrUtils.parseParams(" ", tokenized, "\n"));
|
||||
SwingUtilities.invokeLater(() -> LogWindow.INSTANCE.setVisible(true));
|
||||
}
|
||||
/*
|
||||
if (StrUtils.isNotBlank(proxyHost) && StrUtils.isNotBlank(proxyPort) && MathUtils.canParseInt(proxyPort)) {
|
||||
HMCLog.log("Initializing customized proxy");
|
||||
System.setProperty("http.proxyHost", proxyHost);
|
||||
System.setProperty("http.proxyPort", proxyPort);
|
||||
if (StrUtils.isNotBlank(proxyUsername) && StrUtils.isNotBlank(proxyPassword))
|
||||
Authenticator.setDefault(new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(proxyUsername, proxyPassword.toCharArray());
|
||||
}
|
||||
});
|
||||
//PROXY = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(Settings.getInstance().getProxyHost(), Integer.parseInt(Settings.getInstance().getProxyPort())));
|
||||
} else {
|
||||
//PROXY = Proxy.NO_PROXY;
|
||||
}*/
|
||||
|
||||
URL[] urls = new URL[len];
|
||||
|
||||
|
@ -56,11 +56,6 @@ public final class MCUtils {
|
||||
return getWorkingDirectory("minecraft");
|
||||
}
|
||||
|
||||
public static boolean is16Folder(String path) {
|
||||
path = IOUtils.addSeparator(path);
|
||||
return new File(path, "versions").exists();
|
||||
}
|
||||
|
||||
public static String minecraft() {
|
||||
if (OS.os() == OS.OSX)
|
||||
return "minecraft";
|
||||
|
@ -28,7 +28,6 @@ import org.jackhuang.hellominecraft.util.tasks.ParallelTask;
|
||||
import org.jackhuang.hellominecraft.util.tasks.TaskWindow;
|
||||
import org.jackhuang.hellominecraft.util.system.Compressor;
|
||||
import org.jackhuang.hellominecraft.util.MessageBox;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
|
||||
public class DefaultGameLauncher extends GameLauncher {
|
||||
|
||||
@ -56,8 +55,7 @@ public class DefaultGameLauncher extends GameLauncher {
|
||||
return false;
|
||||
for (int i = 0; i < value.decompressFiles.length; i++)
|
||||
try {
|
||||
String[] rules = value.extractRules[i];
|
||||
Compressor.unzip(value.decompressFiles[i], value.getDecompressTo(), t -> !StrUtils.startsWithOne(rules, t), false);
|
||||
Compressor.unzip(value.decompressFiles[i], value.getDecompressTo(), value.extractRules[i]::allow, false);
|
||||
} catch (IOException ex) {
|
||||
HMCLog.err("Unable to decompress library file: " + value.decompressFiles[i] + " to " + value.getDecompressTo(), ex);
|
||||
}
|
||||
|
@ -26,10 +26,10 @@ import java.io.File;
|
||||
public class DecompressLibraryJob {
|
||||
|
||||
public File[] decompressFiles;
|
||||
public String[][] extractRules;
|
||||
public Extract[] extractRules;
|
||||
private File decompressTo;
|
||||
|
||||
public DecompressLibraryJob(File[] decompressFiles, String[][] extractRules, File decompressTo) {
|
||||
public DecompressLibraryJob(File[] decompressFiles, Extract[] extractRules, File decompressTo) {
|
||||
this.decompressFiles = decompressFiles.clone();
|
||||
this.extractRules = extractRules.clone();
|
||||
this.decompressTo = decompressTo;
|
||||
|
@ -17,20 +17,20 @@
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.launcher.core.version;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class Extract implements Cloneable {
|
||||
|
||||
public String[] exclude;
|
||||
public List<String> exclude = new ArrayList<>();
|
||||
|
||||
public Extract(String[] exclude) {
|
||||
this();
|
||||
this.exclude = exclude.clone();
|
||||
}
|
||||
|
||||
public Extract() {
|
||||
public boolean allow(String path) {
|
||||
return !StrUtils.startsWithOne(exclude, path);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,7 +34,7 @@ public abstract class IMinecraftLibrary implements Cloneable {
|
||||
|
||||
public abstract boolean isRequiredToUnzip();
|
||||
|
||||
public abstract String[] getDecompressExtractRules();
|
||||
public abstract Extract getDecompressExtractRules();
|
||||
|
||||
public abstract void init();
|
||||
|
||||
|
@ -48,15 +48,6 @@ public class MinecraftLibrary extends IMinecraftLibrary {
|
||||
this.extract = extract == null ? null : (Extract) extract.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
MinecraftLibrary ml = (MinecraftLibrary) super.clone();
|
||||
ml.extract = (Extract) ml.extract.clone();
|
||||
ml.natives = (Natives) ml.natives.clone();
|
||||
ml.rules = (ArrayList<Rules>) ml.rules.clone();
|
||||
return ml;
|
||||
}
|
||||
|
||||
/**
|
||||
* is the library allowed to load.
|
||||
*
|
||||
@ -64,19 +55,14 @@ public class MinecraftLibrary extends IMinecraftLibrary {
|
||||
*/
|
||||
@Override
|
||||
public boolean allow() {
|
||||
boolean flag = false;
|
||||
if (rules == null || rules.isEmpty())
|
||||
flag = true;
|
||||
else
|
||||
if (rules != null) {
|
||||
String action = "disallow";
|
||||
for (Rules r : rules)
|
||||
if ("disallow".equals(r.getAction())) {
|
||||
if (r.getOS() != null && (StrUtils.isBlank(r.getOS().getName()) || r.getOS().getName().equalsIgnoreCase(OS.os().toString()))) {
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
} else if (r.getOS() == null || (r.getOS() != null && (StrUtils.isBlank(r.getOS().getName()) || r.getOS().getName().equalsIgnoreCase(OS.os().toString()))))
|
||||
flag = true;
|
||||
return flag;
|
||||
if (r.action() != null)
|
||||
action = r.action();
|
||||
return "allow".equals(action);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private String formatArch(String nati) {
|
||||
@ -86,11 +72,11 @@ public class MinecraftLibrary extends IMinecraftLibrary {
|
||||
private String getNative() {
|
||||
switch (OS.os()) {
|
||||
case WINDOWS:
|
||||
return formatArch(natives.getWindows());
|
||||
return formatArch(natives.windows);
|
||||
case OSX:
|
||||
return formatArch(natives.getOsx());
|
||||
return formatArch(natives.osx);
|
||||
default:
|
||||
return formatArch(natives.getLinux());
|
||||
return formatArch(natives.linux);
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,25 +87,16 @@ public class MinecraftLibrary extends IMinecraftLibrary {
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
String str = name;
|
||||
String[] s = str.split(":");
|
||||
str = s[0];
|
||||
str = str.replace('.', File.separatorChar);
|
||||
if (natives == null)
|
||||
str += File.separator + s[1] + File.separator + s[2]
|
||||
+ File.separator + s[1] + '-' + s[2] + ".jar";
|
||||
else {
|
||||
str += File.separator + s[1] + File.separator + s[2]
|
||||
+ File.separator + s[1] + '-' + s[2] + '-';
|
||||
str += getNative();
|
||||
str += ".jar";
|
||||
}
|
||||
formatted = str;
|
||||
String[] s = name.split(":");
|
||||
StringBuilder sb = new StringBuilder(s[0].replace('.', '/')).append('/').append(s[1]).append('/').append(s[2]).append('/').append(s[1]).append('-').append(s[2]);
|
||||
if (natives != null)
|
||||
sb.append('-').append(getNative());
|
||||
formatted = sb.append(".jar").toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getFilePath(File gameDir) {
|
||||
return new File(gameDir, "libraries" + File.separatorChar + formatted);
|
||||
return new File(gameDir, "libraries/" + formatted);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -132,7 +109,7 @@ public class MinecraftLibrary extends IMinecraftLibrary {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getDecompressExtractRules() {
|
||||
return extract == null || extract.exclude == null ? new String[0] : extract.exclude;
|
||||
public Extract getDecompressExtractRules() {
|
||||
return extract == null ? new Extract() : extract;
|
||||
}
|
||||
}
|
||||
|
@ -220,7 +220,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
||||
if (v.libraries == null)
|
||||
throw new GameException("Wrong format: minecraft.json");
|
||||
ArrayList<File> unzippings = new ArrayList<>();
|
||||
ArrayList<String[]> extractRules = new ArrayList<>();
|
||||
ArrayList<Extract> extractRules = new ArrayList<>();
|
||||
for (IMinecraftLibrary l : v.libraries) {
|
||||
l.init();
|
||||
if (l.isRequiredToUnzip() && v.isAllowedToUnpackNatives()) {
|
||||
@ -228,7 +228,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
|
||||
extractRules.add(l.getDecompressExtractRules());
|
||||
}
|
||||
}
|
||||
return new DecompressLibraryJob(unzippings.toArray(new File[unzippings.size()]), extractRules.toArray(new String[extractRules.size()][]), getDecompressNativesToLocation(v));
|
||||
return new DecompressLibraryJob(unzippings.toArray(new File[unzippings.size()]), extractRules.toArray(new Extract[extractRules.size()]), getDecompressNativesToLocation(v));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,31 +23,7 @@ package org.jackhuang.hellominecraft.launcher.core.version;
|
||||
*/
|
||||
public class Natives implements Cloneable {
|
||||
|
||||
private String windows, osx, linux;
|
||||
|
||||
public String getWindows() {
|
||||
return windows;
|
||||
}
|
||||
|
||||
public void setWindows(String windows) {
|
||||
this.windows = windows;
|
||||
}
|
||||
|
||||
public String getOsx() {
|
||||
return osx;
|
||||
}
|
||||
|
||||
public void setOsx(String osx) {
|
||||
this.osx = osx;
|
||||
}
|
||||
|
||||
public String getLinux() {
|
||||
return linux;
|
||||
}
|
||||
|
||||
public void setLinux(String linux) {
|
||||
this.linux = linux;
|
||||
}
|
||||
public String windows, osx, linux;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("CloneDeclaresCloneNotSupported")
|
||||
|
@ -17,11 +17,14 @@
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.launcher.core.version;
|
||||
|
||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||
import org.jackhuang.hellominecraft.util.system.OS;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class OS {
|
||||
public class OSRestriction {
|
||||
|
||||
private String version, name;
|
||||
|
||||
@ -40,4 +43,8 @@ public class OS {
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isCurrentOS() {
|
||||
return StrUtils.isBlank(getName()) || OS.os().name().equalsIgnoreCase(getName());
|
||||
}
|
||||
}
|
@ -24,31 +24,19 @@ package org.jackhuang.hellominecraft.launcher.core.version;
|
||||
public class Rules {
|
||||
|
||||
private String action;
|
||||
private OS os;
|
||||
private OSRestriction os;
|
||||
|
||||
public Rules() {
|
||||
}
|
||||
|
||||
public Rules(String action, OS os) {
|
||||
public Rules(String action, OSRestriction os) {
|
||||
this();
|
||||
this.action = action;
|
||||
this.os = os;
|
||||
}
|
||||
|
||||
public String getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setAction(String action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public OS getOS() {
|
||||
return os;
|
||||
}
|
||||
|
||||
public void setOS(OS os) {
|
||||
this.os = os;
|
||||
public String action() {
|
||||
return os != null && os.isCurrentOS() ? action : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -84,6 +84,15 @@ public final class StrUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean startsWithOne(Collection<String> a, String match) {
|
||||
if (a == null)
|
||||
return false;
|
||||
for (String b : a)
|
||||
if (startsWith(match, b))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean equalsOne(String base, String... a) {
|
||||
for (String s : a)
|
||||
if (base.equals(s))
|
||||
|
@ -48,7 +48,7 @@ public class Localization {
|
||||
|
||||
this.lang = new HashMap<>();
|
||||
try {
|
||||
String[] strings = IOUtils.readFully(is).toString().split("\n");
|
||||
String[] strings = IOUtils.readFully(is).toString("UTF-8").split("\n");
|
||||
for (String s : strings)
|
||||
if (!s.isEmpty() && s.charAt(0) != 35) {
|
||||
int i = s.indexOf("=");
|
||||
|
@ -1,81 +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/}.
|
||||
*/
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'findbugs'
|
||||
|
||||
//sourceCompatibility = '1.7'
|
||||
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
|
||||
|
||||
repositories {
|
||||
mavenCentral();
|
||||
}
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral();
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Adding dependencies here will add the dependencies to each subproject.
|
||||
|
||||
compile 'com.google.code.gson:gson:2.2.4' // Apache License 2.0
|
||||
}
|
||||
|
||||
task sourcesJar(type: Jar, dependsOn: classes, description: 'Creates a jar from the source files.') {
|
||||
classifier = 'sources'
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives jar
|
||||
archives sourcesJar
|
||||
}
|
||||
|
||||
task createFolders(description: 'Creates the source folders if they do not exist.') doLast {
|
||||
sourceSets*.allSource*.srcDirs*.each { File srcDir ->
|
||||
if (!srcDir.isDirectory()) {
|
||||
println "Creating source folder: ${srcDir}"
|
||||
srcDir.mkdirs()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task makeExecutable(dependsOn: jar) << {
|
||||
ext {
|
||||
jar.classifier = ''
|
||||
makeExecutableinjar = jar.archivePath
|
||||
jar.classifier = ''
|
||||
makeExecutableoutjar = jar.archivePath
|
||||
jar.classifier = ''
|
||||
}
|
||||
def loc = new File(project.buildDir, "libs/" + makeExecutableoutjar.getName().substring(0, makeExecutableoutjar.getName().length()-4)+".exe")
|
||||
def fos = new FileOutputStream(loc)
|
||||
def is = new FileInputStream(new File(project.buildDir, '../HMCLauncher.exe'))
|
||||
int read
|
||||
def bytes = new byte[8192]
|
||||
while((read = is.read(bytes)) != -1)
|
||||
fos.write(bytes, 0, read);
|
||||
is.close()
|
||||
is = new FileInputStream(makeExecutableinjar)
|
||||
while((read = is.read(bytes)) != -1)
|
||||
fos.write(bytes, 0, read);
|
||||
is.close()
|
||||
fos.close()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user