Fixed NullPointerException when minecraftArguments=null

This commit is contained in:
huangyuhui 2016-05-23 13:09:30 +08:00
parent 75e0fa2def
commit ab1ca18488
12 changed files with 67 additions and 53 deletions

View File

@ -18,7 +18,6 @@
package org.jackhuang.hellominecraft.launcher.core.install.forge; package org.jackhuang.hellominecraft.launcher.core.install.forge;
import org.jackhuang.hellominecraft.launcher.core.install.InstallProfile; import org.jackhuang.hellominecraft.launcher.core.install.InstallProfile;
import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
@ -32,6 +31,7 @@ import org.jackhuang.hellominecraft.util.system.FileUtils;
import org.jackhuang.hellominecraft.util.NetUtils; import org.jackhuang.hellominecraft.util.NetUtils;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftLibrary;
import org.jackhuang.hellominecraft.util.MessageBox; import org.jackhuang.hellominecraft.util.MessageBox;
import org.jackhuang.hellominecraft.util.system.IOUtils;
/** /**
* *
@ -79,10 +79,8 @@ public class ForgeInstaller extends Task {
File file = new File(gameDir, "libraries/" + forge.getDownloadInfo().path); File file = new File(gameDir, "libraries/" + forge.getDownloadInfo().path);
if (file.getParentFile().mkdirs()) if (file.getParentFile().mkdirs())
HMCLog.warn("Failed to make library directory " + file.getParent()); HMCLog.warn("Failed to make library directory " + file.getParent());
try (FileOutputStream fos = new FileOutputStream(file); BufferedOutputStream bos = new BufferedOutputStream(fos)) { try (FileOutputStream fos = new FileOutputStream(file)) {
int c; IOUtils.copyStream(is, fos);
while ((c = is.read()) != -1)
bos.write((byte) c);
} }
mp.version().refreshVersions(); mp.version().refreshVersions();
} }

View File

@ -45,8 +45,12 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
protected void makeSelf(List<String> res) throws GameException { protected void makeSelf(List<String> res) throws GameException {
StringBuilder library = new StringBuilder(""); StringBuilder library = new StringBuilder("");
for (MinecraftLibrary l : version.libraries) for (MinecraftLibrary l : version.libraries)
if (l.allow() && !l.isRequiredToUnzip()) if (l.allow() && !l.isRequiredToUnzip()) {
library.append(l.getFilePath(gameDir).getAbsolutePath()).append(File.pathSeparator); File f = l.getFilePath(gameDir);
if (f == null)
continue;
library.append(f.getAbsolutePath()).append(File.pathSeparator);
}
File f = version.getJar(service.baseDirectory()); File f = version.getJar(service.baseDirectory());
if (!f.exists()) if (!f.exists())
throw new GameException("Minecraft jar does not exists"); throw new GameException("Minecraft jar does not exists");
@ -55,6 +59,8 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
res.add(library.toString().substring(0, library.length() - File.pathSeparator.length())); res.add(library.toString().substring(0, library.length() - File.pathSeparator.length()));
res.add(version.mainClass); res.add(version.mainClass);
if (version.minecraftArguments == null)
throw new GameException(new NullPointerException("Minecraft Arguments can not be null."));
String[] splitted = StrUtils.tokenize(version.minecraftArguments); String[] splitted = StrUtils.tokenize(version.minecraftArguments);
String game_assets = assetProvider.apply(version, !options.isNotCheckGame()); String game_assets = assetProvider.apply(version, !options.isNotCheckGame());

View File

@ -105,7 +105,10 @@ public class MinecraftLibrary extends IMinecraftLibrary {
@Override @Override
public File getFilePath(File gameDir) { public File getFilePath(File gameDir) {
return new File(gameDir, "libraries/" + getDownloadInfo().path); LibraryDownloadInfo info = getDownloadInfo();
if (info == null)
return null;
return new File(gameDir, "libraries/" + info.path);
} }
@Override @Override

View File

@ -63,6 +63,12 @@ task macAppCompressed(type: Zip, dependsOn: createApp) {
from "$buildDir/macApp" from "$buildDir/macApp"
} }
macAppBundle {
mainClassName = mainClass
icon = "src/main/icon.icns"
javaProperties.put("apple.laf.useScreenMenuBar", "true")
}
configure(install.repositories.mavenInstaller) { configure(install.repositories.mavenInstaller) {
pom.project { pom.project {
groupId = mavenGroupId groupId = mavenGroupId

BIN
HMCSM/src/main/icon.icns Executable file

Binary file not shown.

View File

@ -51,21 +51,21 @@ public class DoubleOutputStream extends OutputStream {
} }
@Override @Override
public final void write(byte[] paramArrayOfByte) throws IOException { public final void write(byte[] arr) throws IOException {
if (this.a != null) if (this.a != null)
this.a.write(paramArrayOfByte); this.a.write(arr);
if (this.b != null) if (this.b != null)
this.b.write(paramArrayOfByte); this.b.write(arr);
if (this.c) if (this.c)
flush(); flush();
} }
@Override @Override
public final void write(int paramInt) throws IOException { public final void write(int i) throws IOException {
if (this.a != null) if (this.a != null)
this.a.write(paramInt); this.a.write(i);
if (this.b != null) if (this.b != null)
this.b.write(paramInt); this.b.write(i);
if (this.c) if (this.c)
flush(); flush();
} }

View File

@ -37,13 +37,10 @@ import org.jackhuang.hellominecraft.util.system.IOUtils;
public final class NetUtils { public final class NetUtils {
public static byte[] getBytesFromStream(InputStream is) throws IOException { public static byte[] getBytesFromStream(InputStream is) throws IOException {
ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] arrayOfByte1 = new byte[1024]; IOUtils.copyStream(is, out);
int i;
while ((i = is.read(arrayOfByte1)) >= 0)
localByteArrayOutputStream.write(arrayOfByte1, 0, i);
is.close(); is.close();
return localByteArrayOutputStream.toByteArray(); return out.toByteArray();
} }
public static String getStreamContent(InputStream is) throws IOException { public static String getStreamContent(InputStream is) throws IOException {
@ -83,12 +80,8 @@ public final class NetUtils {
public static String post(URL u, Map<String, String> params) throws IOException { public static String post(URL u, Map<String, String> params) throws IOException {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (params != null) { if (params != null) {
for (Map.Entry<String, String> e : params.entrySet()) { for (Map.Entry<String, String> e : params.entrySet())
sb.append(e.getKey()); sb.append(e.getKey()).append("=").append(e.getValue()).append("&");
sb.append("=");
sb.append(e.getValue());
sb.append("&");
}
sb.deleteCharAt(sb.length() - 1); sb.deleteCharAt(sb.length() - 1);
} }
return post(u, sb.toString()); return post(u, sb.toString());
@ -150,9 +143,9 @@ public final class NetUtils {
public static URL concatenateURL(URL url, String query) { public static URL concatenateURL(URL url, String query) {
try { try {
if ((url.getQuery() != null) && (url.getQuery().length() > 0)) if (url.getQuery() != null && url.getQuery().length() > 0)
return new URL(url.getProtocol(), url.getHost(), url.getPort(), new StringBuilder().append(url.getFile()).append("&").append(query).toString()); return new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile() + "&" + query);
return new URL(url.getProtocol(), url.getHost(), url.getPort(), new StringBuilder().append(url.getFile()).append("?").append(query).toString()); return new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile() + "?" + query);
} catch (MalformedURLException ex) { } catch (MalformedURLException ex) {
throw new IllegalArgumentException("Could not concatenate given URL with GET arguments!", ex); throw new IllegalArgumentException("Could not concatenate given URL with GET arguments!", ex);
} }

View File

@ -109,7 +109,6 @@ public class Compressor {
} }
String pathName;//存相对路径(相对于待压缩的根目录) String pathName;//存相对路径(相对于待压缩的根目录)
byte[] buf = new byte[1024]; byte[] buf = new byte[1024];
int length;
for (File file : files) for (File file : files)
if (file.isDirectory()) { if (file.isDirectory()) {
pathName = file.getPath().substring(basePath.length() + 1) pathName = file.getPath().substring(basePath.length() + 1)
@ -129,8 +128,7 @@ public class Compressor {
try (InputStream is = new FileInputStream(file)) { try (InputStream is = new FileInputStream(file)) {
BufferedInputStream bis = new BufferedInputStream(is); BufferedInputStream bis = new BufferedInputStream(is);
zos.putNextEntry(new ZipEntry(pathName)); zos.putNextEntry(new ZipEntry(pathName));
while ((length = bis.read(buf)) > 0) IOUtils.copyStream(bis, zos, buf);
zos.write(buf, 0, length);
} }
} }
} }
@ -154,6 +152,7 @@ public class Compressor {
* @throws java.io.IOException 解压失败或无法写入 * @throws java.io.IOException 解压失败或无法写入
*/ */
public static void unzip(File zipFileName, File extPlace, Predicate<String> callback, boolean ignoreExistsFile) throws IOException { public static void unzip(File zipFileName, File extPlace, Predicate<String> callback, boolean ignoreExistsFile) throws IOException {
byte[] buf = new byte[1024];
extPlace.mkdirs(); extPlace.mkdirs();
try (ZipInputStream zipFile = new ZipInputStream(new FileInputStream(zipFileName))) { try (ZipInputStream zipFile = new ZipInputStream(new FileInputStream(zipFileName))) {
if (zipFileName.exists()) { if (zipFileName.exists()) {
@ -184,10 +183,8 @@ public class Compressor {
} }
if (ignoreExistsFile && new File(strtemp).exists()) if (ignoreExistsFile && new File(strtemp).exists())
continue; continue;
try (FileOutputStream fos = new FileOutputStream(strtemp); BufferedOutputStream bos = new BufferedOutputStream(fos)) { try (FileOutputStream fos = new FileOutputStream(strtemp)) {
int c; IOUtils.copyStream(zipFile, fos, buf);
while ((c = zipFile.read()) != -1)
bos.write((byte) c);
} }
} }
} }

View File

@ -288,4 +288,14 @@ public class IOUtils {
} }
return lines; return lines;
} }
public static void copyStream(InputStream input, OutputStream output) throws IOException {
copyStream(input, output, new byte[1024]);
}
public static void copyStream(InputStream input, OutputStream output, byte[] buf) throws IOException {
int length;
while ((length = input.read(buf)) != -1)
output.write(buf, 0, length);
}
} }

View File

@ -121,11 +121,9 @@ public class ZipEngine {
} }
public void putStream(InputStream is, String pathName) throws IOException { public void putStream(InputStream is, String pathName) throws IOException {
int length;
try (BufferedInputStream bis = new BufferedInputStream(is)) { try (BufferedInputStream bis = new BufferedInputStream(is)) {
put(new ZipEntry(pathName)); put(new ZipEntry(pathName));
while ((length = bis.read(buf)) > 0) IOUtils.copyStream(bis, zos, buf);
zos.write(buf, 0, length);
} }
} }

View File

@ -62,12 +62,12 @@ public class HTTPGetTask extends TaskInfo implements PreviousResult<String> {
URLConnection conn = new URL(url).openConnection(); URLConnection conn = new URL(url).openConnection();
InputStream is = conn.getInputStream(); InputStream is = conn.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i; byte[] buf = new byte[1024];
int size = conn.getContentLength(), read = 0; int size = conn.getContentLength(), read = 0, len;
long lastTime = System.currentTimeMillis(); long lastTime = System.currentTimeMillis();
while ((i = is.read()) != -1) { while ((len = is.read(buf)) != -1) {
baos.write(i); baos.write(buf, 0, len);
++read; read += len;
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
if (ppl != null && (now - lastTime) >= 1000) { if (ppl != null && (now - lastTime) >= 1000) {
ppl.setProgress(this, read, size); ppl.setProgress(this, read, size);

View File

@ -18,6 +18,7 @@
package org.jackhuang.hellominecraft.util.ui; package org.jackhuang.hellominecraft.util.ui;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Objects;
import java.util.Timer; import java.util.Timer;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import org.jackhuang.hellominecraft.util.logging.Level; import org.jackhuang.hellominecraft.util.logging.Level;
@ -34,24 +35,26 @@ public class LogWindowOutputStream extends OutputStream {
private final Level sas; private final Level sas;
public LogWindowOutputStream(LogWindow logWindow, Level l) { public LogWindowOutputStream(LogWindow logWindow, Level l) {
Objects.nonNull(logWindow);
Objects.nonNull(l);
txt = logWindow; txt = logWindow;
this.sas = l; sas = l;
} }
@Override @Override
public final void write(byte[] paramArrayOfByte) { public final void write(byte[] arr) {
write(paramArrayOfByte, 0, paramArrayOfByte.length); write(arr, 0, arr.length);
} }
@Override @Override
public final void write(byte[] paramArrayOfByte, int off, int len) { public final void write(byte[] arr, int off, int len) {
append(new String(paramArrayOfByte, off, len)); append(new String(arr, off, len));
} }
private void append(final String newString) { private void append(final String str) {
try { try {
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
txt.log(newString, Level.guessLevel(newString, sas)); txt.log(str, Level.guessLevel(str, sas));
}); });
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
@ -59,8 +62,8 @@ public class LogWindowOutputStream extends OutputStream {
} }
@Override @Override
public final void write(int paramInt) { public final void write(int i) {
append(new String(new byte[] { (byte) paramInt })); append(new String(new byte[] { (byte) i }));
} }
public static void dispose() { public static void dispose() {