Compare commits

...
6 Commits
56 ... 61
Author SHA1 Message Date
huangyuhui b36c194f67 Merge branch 'master' of https://github.com/huanghongxun/HMCL 2016-05-28 23:19:21 +08:00
huangyuhui 7c7b6e0fd9 Fixed #73 2016-05-28 23:17:49 +08:00
huanghongxun 01b77f1f5f Merge pull request #71 from Cat7373/master
Windows 启动脚本中允许跨分区 cd
2016-05-23 19:28:18 +08:00
Cat73 840a0ad840 Windows 启动脚本中允许跨分区 cd
修复跨分区的情况下一些文件如 logs 仍然生成在脚本所在目录,而不是 .minecraft 目录
2016-05-23 13:25:58 +08:00
huangyuhui ab1ca18488 Fixed NullPointerException when minecraftArguments=null 2016-05-23 13:09:30 +08:00
huangyuhui 75e0fa2def Fixed mainClass of macAppBundle 2016-05-16 18:10:30 +08:00
18 changed files with 118 additions and 57 deletions

No files matched your search

+6
View File
@@ -83,6 +83,12 @@ task macAppCompressed(type: Zip, dependsOn: createApp) {
from "$buildDir/macApp"
}
macAppBundle {
mainClassName = mainClass
icon = "src/main/icon.icns"
javaProperties.put("apple.laf.useScreenMenuBar", "true")
}
sourceSets {
main {
java {
@@ -148,7 +148,7 @@ public class YggdrasilAuthentication {
if (StrUtils.isNotBlank(response.error)) {
HMCLog.err("Failed to log in, the auth server returned an error: " + response.error + ", message: " + response.errorMessage + ", cause: " + response.cause);
if (response.errorMessage.contains("Invalid token"))
if (response.errorMessage != null && response.errorMessage.contains("Invalid token"))
response.errorMessage = C.i18n("login.invalid_token");
throw new AuthenticationException("Request error: " + response.errorMessage);
}
@@ -18,7 +18,6 @@
package org.jackhuang.hellominecraft.launcher.core.install.forge;
import org.jackhuang.hellominecraft.launcher.core.install.InstallProfile;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
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.launcher.core.version.MinecraftLibrary;
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);
if (file.getParentFile().mkdirs())
HMCLog.warn("Failed to make library directory " + file.getParent());
try (FileOutputStream fos = new FileOutputStream(file); BufferedOutputStream bos = new BufferedOutputStream(fos)) {
int c;
while ((c = is.read()) != -1)
bos.write((byte) c);
try (FileOutputStream fos = new FileOutputStream(file)) {
IOUtils.copyStream(is, fos);
}
mp.version().refreshVersions();
}
@@ -175,7 +175,7 @@ public class GameLauncher {
if (appdata != null) {
writer.write("set appdata=" + appdata);
writer.newLine();
writer.write("cd %appdata%");
writer.write("cd /D %appdata%");
writer.newLine();
}
}
@@ -19,6 +19,7 @@ package org.jackhuang.hellominecraft.launcher.core.launch;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.util.logging.HMCLog;
@@ -44,9 +45,24 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
@Override
protected void makeSelf(List<String> res) throws GameException {
StringBuilder library = new StringBuilder("");
ArrayList<MinecraftLibrary> opt = new ArrayList<>();
for (MinecraftLibrary l : version.libraries)
if (l.allow() && !l.isRequiredToUnzip())
library.append(l.getFilePath(gameDir).getAbsolutePath()).append(File.pathSeparator);
if (l.allow() && !l.isRequiredToUnzip()) {
if (l.name.toLowerCase().contains("optifine")) {
opt.add(l);
continue;
}
File f = l.getFilePath(gameDir);
if (f == null)
continue;
library.append(f.getAbsolutePath()).append(File.pathSeparator);
}
for (MinecraftLibrary l : opt) {
File f = l.getFilePath(gameDir);
if (f == null)
continue;
library.append(f.getAbsolutePath()).append(File.pathSeparator);
}
File f = version.getJar(service.baseDirectory());
if (!f.exists())
throw new GameException("Minecraft jar does not exists");
@@ -55,6 +71,8 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
res.add(library.toString().substring(0, library.length() - File.pathSeparator.length()));
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 game_assets = assetProvider.apply(version, !options.isNotCheckGame());
@@ -105,7 +105,10 @@ public class MinecraftLibrary extends IMinecraftLibrary {
@Override
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
@@ -145,7 +145,7 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
this.assets != null ? this.assets : parent.assets,
this.jar != null ? this.jar : parent.jar,
null, this.runDir, parent.minimumLauncherVersion,
this.libraries != null ? ArrayUtils.merge(parent.libraries, this.libraries) : parent.libraries, this.hidden,
this.libraries != null ? ArrayUtils.merge(this.libraries, parent.libraries) : parent.libraries, this.hidden,
this.downloads != null ? this.downloads : parent.downloads,
this.assetIndex != null ? this.assetIndex : parent.assetIndex);
@@ -26,6 +26,8 @@
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="btnCheckUpdate" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnMCBBS" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="chkDecorated" min="-2" max="-2" attributes="0"/>
</Group>
@@ -125,6 +127,7 @@
<Group type="103" groupAlignment="3" attributes="0">
<Component id="btnCheckUpdate" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
<Component id="chkDecorated" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnMCBBS" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="lblRestart" min="-2" max="-2" attributes="0"/>
@@ -345,5 +348,14 @@
</Property>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="btnMCBBS">
<Properties>
<Property name="text" type="java.lang.String" value="MCBBS"/>
<Property name="toolTipText" type="java.lang.String" value=""/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnMCBBSActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>
@@ -116,6 +116,7 @@ public class LauncherSettingsPanel extends AnimatedPanel {
cboLang = new javax.swing.JComboBox();
lblLang = new javax.swing.JLabel();
lblRestart = new javax.swing.JLabel();
btnMCBBS = new javax.swing.JButton();
cboDownloadSource.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
@@ -240,6 +241,14 @@ public class LauncherSettingsPanel extends AnimatedPanel {
lblRestart.setText(C.i18n("launcher.restart")); // NOI18N
btnMCBBS.setText("MCBBS");
btnMCBBS.setToolTipText("");
btnMCBBS.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnMCBBSActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
@@ -253,6 +262,8 @@ public class LauncherSettingsPanel extends AnimatedPanel {
.addComponent(chkEnableAnimation))
.addGroup(layout.createSequentialGroup()
.addComponent(btnCheckUpdate)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnMCBBS)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(chkDecorated))
.addGroup(layout.createSequentialGroup()
@@ -334,7 +345,8 @@ public class LauncherSettingsPanel extends AnimatedPanel {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnCheckUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(chkDecorated))
.addComponent(chkDecorated)
.addComponent(btnMCBBS))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblRestart)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 65, Short.MAX_VALUE)
@@ -425,8 +437,13 @@ public class LauncherSettingsPanel extends AnimatedPanel {
SwingUtils.openLink("http://huangyuhui.duapp.com/link.php?type=sponsor");
}//GEN-LAST:event_lblAboutMouseClicked
private void btnMCBBSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMCBBSActionPerformed
SwingUtils.openLink(C.URL_PUBLISH);
}//GEN-LAST:event_btnMCBBSActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCheckUpdate;
private javax.swing.JButton btnMCBBS;
private javax.swing.JButton btnSelBackgroundPath;
private javax.swing.JComboBox cboDownloadSource;
private javax.swing.JComboBox cboLang;
+6
View File
@@ -63,6 +63,12 @@ task macAppCompressed(type: Zip, dependsOn: createApp) {
from "$buildDir/macApp"
}
macAppBundle {
mainClassName = mainClass
icon = "src/main/icon.icns"
javaProperties.put("apple.laf.useScreenMenuBar", "true")
}
configure(install.repositories.mavenInstaller) {
pom.project {
groupId = mavenGroupId
BIN
View File
Binary file not shown.
@@ -51,21 +51,21 @@ public class DoubleOutputStream extends OutputStream {
}
@Override
public final void write(byte[] paramArrayOfByte) throws IOException {
public final void write(byte[] arr) throws IOException {
if (this.a != null)
this.a.write(paramArrayOfByte);
this.a.write(arr);
if (this.b != null)
this.b.write(paramArrayOfByte);
this.b.write(arr);
if (this.c)
flush();
}
@Override
public final void write(int paramInt) throws IOException {
public final void write(int i) throws IOException {
if (this.a != null)
this.a.write(paramInt);
this.a.write(i);
if (this.b != null)
this.b.write(paramInt);
this.b.write(i);
if (this.c)
flush();
}
@@ -37,13 +37,10 @@ import org.jackhuang.hellominecraft.util.system.IOUtils;
public final class NetUtils {
public static byte[] getBytesFromStream(InputStream is) throws IOException {
ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
byte[] arrayOfByte1 = new byte[1024];
int i;
while ((i = is.read(arrayOfByte1)) >= 0)
localByteArrayOutputStream.write(arrayOfByte1, 0, i);
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copyStream(is, out);
is.close();
return localByteArrayOutputStream.toByteArray();
return out.toByteArray();
}
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 {
StringBuilder sb = new StringBuilder();
if (params != null) {
for (Map.Entry<String, String> e : params.entrySet()) {
sb.append(e.getKey());
sb.append("=");
sb.append(e.getValue());
sb.append("&");
}
for (Map.Entry<String, String> e : params.entrySet())
sb.append(e.getKey()).append("=").append(e.getValue()).append("&");
sb.deleteCharAt(sb.length() - 1);
}
return post(u, sb.toString());
@@ -150,9 +143,9 @@ public final class NetUtils {
public static URL concatenateURL(URL url, String query) {
try {
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(), new StringBuilder().append(url.getFile()).append("?").append(query).toString());
if (url.getQuery() != null && url.getQuery().length() > 0)
return new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile() + "&" + query);
return new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile() + "?" + query);
} catch (MalformedURLException ex) {
throw new IllegalArgumentException("Could not concatenate given URL with GET arguments!", ex);
}
@@ -109,7 +109,6 @@ public class Compressor {
}
String pathName;//存相对路径(相对于待压缩的根目录)
byte[] buf = new byte[1024];
int length;
for (File file : files)
if (file.isDirectory()) {
pathName = file.getPath().substring(basePath.length() + 1)
@@ -129,8 +128,7 @@ public class Compressor {
try (InputStream is = new FileInputStream(file)) {
BufferedInputStream bis = new BufferedInputStream(is);
zos.putNextEntry(new ZipEntry(pathName));
while ((length = bis.read(buf)) > 0)
zos.write(buf, 0, length);
IOUtils.copyStream(bis, zos, buf);
}
}
}
@@ -154,6 +152,7 @@ public class Compressor {
* @throws java.io.IOException 解压失败或无法写入
*/
public static void unzip(File zipFileName, File extPlace, Predicate<String> callback, boolean ignoreExistsFile) throws IOException {
byte[] buf = new byte[1024];
extPlace.mkdirs();
try (ZipInputStream zipFile = new ZipInputStream(new FileInputStream(zipFileName))) {
if (zipFileName.exists()) {
@@ -184,10 +183,8 @@ public class Compressor {
}
if (ignoreExistsFile && new File(strtemp).exists())
continue;
try (FileOutputStream fos = new FileOutputStream(strtemp); BufferedOutputStream bos = new BufferedOutputStream(fos)) {
int c;
while ((c = zipFile.read()) != -1)
bos.write((byte) c);
try (FileOutputStream fos = new FileOutputStream(strtemp)) {
IOUtils.copyStream(zipFile, fos, buf);
}
}
}
@@ -288,4 +288,14 @@ public class IOUtils {
}
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);
}
}
@@ -121,11 +121,9 @@ public class ZipEngine {
}
public void putStream(InputStream is, String pathName) throws IOException {
int length;
try (BufferedInputStream bis = new BufferedInputStream(is)) {
put(new ZipEntry(pathName));
while ((length = bis.read(buf)) > 0)
zos.write(buf, 0, length);
IOUtils.copyStream(bis, zos, buf);
}
}
@@ -62,12 +62,12 @@ public class HTTPGetTask extends TaskInfo implements PreviousResult<String> {
URLConnection conn = new URL(url).openConnection();
InputStream is = conn.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i;
int size = conn.getContentLength(), read = 0;
byte[] buf = new byte[1024];
int size = conn.getContentLength(), read = 0, len;
long lastTime = System.currentTimeMillis();
while ((i = is.read()) != -1) {
baos.write(i);
++read;
while ((len = is.read(buf)) != -1) {
baos.write(buf, 0, len);
read += len;
long now = System.currentTimeMillis();
if (ppl != null && (now - lastTime) >= 1000) {
ppl.setProgress(this, read, size);
@@ -18,6 +18,7 @@
package org.jackhuang.hellominecraft.util.ui;
import java.io.OutputStream;
import java.util.Objects;
import java.util.Timer;
import javax.swing.SwingUtilities;
import org.jackhuang.hellominecraft.util.logging.Level;
@@ -34,24 +35,26 @@ public class LogWindowOutputStream extends OutputStream {
private final Level sas;
public LogWindowOutputStream(LogWindow logWindow, Level l) {
Objects.nonNull(logWindow);
Objects.nonNull(l);
txt = logWindow;
this.sas = l;
sas = l;
}
@Override
public final void write(byte[] paramArrayOfByte) {
write(paramArrayOfByte, 0, paramArrayOfByte.length);
public final void write(byte[] arr) {
write(arr, 0, arr.length);
}
@Override
public final void write(byte[] paramArrayOfByte, int off, int len) {
append(new String(paramArrayOfByte, off, len));
public final void write(byte[] arr, int off, int len) {
append(new String(arr, off, len));
}
private void append(final String newString) {
private void append(final String str) {
try {
SwingUtilities.invokeLater(() -> {
txt.log(newString, Level.guessLevel(newString, sas));
txt.log(str, Level.guessLevel(str, sas));
});
} catch (Throwable e) {
e.printStackTrace();
@@ -59,8 +62,8 @@ public class LogWindowOutputStream extends OutputStream {
}
@Override
public final void write(int paramInt) {
append(new String(new byte[] { (byte) paramInt }));
public final void write(int i) {
append(new String(new byte[] { (byte) i }));
}
public static void dispose() {