Fixed Issue #1 & Added proxy support

This commit is contained in:
huanghongxun
2015-06-24 13:45:00 +08:00
parent 7bfe7c3432
commit e5621d1a58
30 changed files with 623 additions and 578 deletions

View File

@@ -34,6 +34,7 @@ public final class C {
public static final String URL_PUBLISH = "http://www.mcbbs.net/thread-142335-1-1.html";
public static final String URL_TIEBA = "http://tieba.baidu.com/f?kw=hellominecraftlauncher";
public static final String URL_GITHUB = "https://github.com/huanghongxun/HMCL/issues";
public static final String URL_MINECRAFTFORUM = "http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-tools/1265720-hello-minecraft-launcher-1-9-3-mc-1-7-4-auto";
public static final String FILE_MINECRAFT_VERSIONS = "versions";

View File

@@ -41,8 +41,9 @@ public class Compressor {
/**
* 功能:把 sourceDir 目录下的所有文件进行 zip 格式的压缩,保存为指定 zip 文件
*
* @param sourceDir
* @param zipFile
* @param sourceDir 源文件夹
* @param zipFile 压缩生成的zip文件路径。
* @throws java.io.IOException 压缩失败或无法读取
*/
public static void zip(File sourceDir, File zipFile) throws IOException {
FileOutputStream os;
@@ -65,7 +66,7 @@ public class Compressor {
*
* @param source zip文件路径
* @param basePath 待压缩文件根目录
* @param zos
* @param zos zip文件的os
*/
private static void zipFile(File source, String basePath,
ZipOutputStream zos) throws IOException {
@@ -115,6 +116,7 @@ public class Compressor {
* @param zipFileName zip文件路径
* @param extPlace 待压缩文件根目录
* @param without 带前缀的不解压
* @throws java.io.IOException 解压失败或无法写入
*/
public static void unzip(File zipFileName, File extPlace, String[] without) throws IOException {
extPlace.mkdirs();
@@ -164,6 +166,7 @@ public class Compressor {
*
* @param destFile zip1
* @param srcFile zip2
* @throws java.io.IOException 无法写入或读取
*/
public static void merge(File destFile, File srcFile) throws IOException {
try (ZipOutputStream os = new ZipOutputStream(new FileOutputStream(destFile))) {

View File

@@ -42,12 +42,16 @@ public class Stream<T> {
protected Stream() {
}
protected static <T> Stream<T> of(List<T> a) {
protected static <T> Stream<T> noneCopyOf(List<T> a) {
Stream<T> b = new Stream<>();
b.internal = a;
return b;
}
protected static <T> Stream<T> of(Collection<T> a) {
return new Stream<>(a);
}
public Stream<T> forEach(Consumer<? super T> p) {
for (T t : internal) p.accept(t);
return this;
@@ -88,15 +92,25 @@ public class Stream<T> {
}
public boolean anyMatch(Predicate<? super T> p) {
return map(t -> p.apply(t)).reduce(false, (accumulator, _item) -> accumulator | _item);
return map(t -> p.apply(t)).<Boolean>reduce(false, (a, b) -> a | b);
}
public boolean allMatch(Predicate<? super T> p) {
return map(t -> p.apply(t)).reduce(true, (accumulator, _item) -> accumulator & _item);
return map(t -> p.apply(t)).<Boolean>reduce(true, (a, b) -> a & b);
}
public T findFirst() {
return internal.isEmpty() ? null : internal.get(0);
}
public Stream<T> skip(int c) {
internal = internal.subList(c+1, internal.size());
return this;
}
public Stream<T> limit(int c) {
internal = internal.subList(0, c);
return this;
}
}

View File

@@ -37,6 +37,8 @@
<Component id="btnMCBBS" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnMCF" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnGitHub" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="btnTerminateGame" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
@@ -46,7 +48,7 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="btnClose" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="lblCrash" alignment="0" pref="639" max="32767" attributes="0"/>
<Component id="lblCrash" alignment="0" pref="674" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
@@ -68,6 +70,7 @@
<Component id="btnTieBa" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnMCF" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnTerminateGame" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnGitHub" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
@@ -164,5 +167,13 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnTerminateGameActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnGitHub">
<Properties>
<Property name="text" type="java.lang.String" value="GitHub"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnGitHubActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>

View File

@@ -73,6 +73,7 @@ public class LogWindow extends javax.swing.JFrame {
btnTieBa = new javax.swing.JButton();
btnMCF = new javax.swing.JButton();
btnTerminateGame = new javax.swing.JButton();
btnGitHub = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Log");
@@ -139,6 +140,13 @@ public class LogWindow extends javax.swing.JFrame {
}
});
btnGitHub.setText("GitHub");
btnGitHub.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnGitHubActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
@@ -153,6 +161,8 @@ public class LogWindow extends javax.swing.JFrame {
.addComponent(btnMCBBS)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnMCF)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnGitHub)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnTerminateGame)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
@@ -161,7 +171,7 @@ public class LogWindow extends javax.swing.JFrame {
.addComponent(btnClear)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnClose))
.addComponent(lblCrash, javax.swing.GroupLayout.DEFAULT_SIZE, 639, Short.MAX_VALUE))
.addComponent(lblCrash, javax.swing.GroupLayout.DEFAULT_SIZE, 674, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
@@ -179,7 +189,8 @@ public class LogWindow extends javax.swing.JFrame {
.addComponent(btnMCBBS)
.addComponent(btnTieBa)
.addComponent(btnMCF)
.addComponent(btnTerminateGame))
.addComponent(btnTerminateGame)
.addComponent(btnGitHub))
.addContainerGap())
);
@@ -219,6 +230,10 @@ public class LogWindow extends javax.swing.JFrame {
terminateGameListener.onDone();
}//GEN-LAST:event_btnTerminateGameActionPerformed
private void btnGitHubActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGitHubActionPerformed
Utils.openLink(C.URL_GITHUB);
}//GEN-LAST:event_btnGitHubActionPerformed
public void log(String status) {
String text = txtLog.getText();
text += status + System.getProperty("line.separator");
@@ -286,6 +301,7 @@ public class LogWindow extends javax.swing.JFrame {
private javax.swing.JButton btnClear;
private javax.swing.JButton btnClose;
private javax.swing.JButton btnCopy;
private javax.swing.JButton btnGitHub;
private javax.swing.JButton btnMCBBS;
private javax.swing.JButton btnMCF;
private javax.swing.JButton btnTerminateGame;