Supported new version json
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see {http://www.gnu.org/licenses/}.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.util.version;
|
||||
package org.jackhuang.hellominecraft.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -142,7 +142,7 @@ public class MinecraftVersionRequest implements Serializable {
|
||||
int k = i;
|
||||
if (tmp[i + 1] >= (int) 'a' && tmp[i + 1] <= (int) 'z')
|
||||
i++;
|
||||
while (tmp[k] >= 48 && tmp[k] <= 57 || tmp[k] == (int) '.' || tmp[k] == (int) 'w')
|
||||
while (tmp[k] >= 48 && tmp[k] <= 57 || tmp[k] == (int) '-' || tmp[k] == (int) '.' || tmp[k] >= 97 && tmp[k] <= (int) 'z')
|
||||
k--;
|
||||
k++;
|
||||
r.version = new String(tmp, k, i - k + 1);
|
||||
@@ -18,6 +18,7 @@
|
||||
package org.jackhuang.hellominecraft.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.swing.SwingWorker;
|
||||
import org.jackhuang.hellominecraft.util.func.Consumer;
|
||||
@@ -64,4 +65,16 @@ public abstract class OverridableSwingWorker<T> extends SwingWorker<Void, T> {
|
||||
c.accept(t);
|
||||
}
|
||||
|
||||
final List<T> lastChunks = new ArrayList<>();
|
||||
|
||||
protected void send(T... t) {
|
||||
lastChunks.addAll(Arrays.asList(t));
|
||||
publish(t);
|
||||
}
|
||||
|
||||
public List<T> justDo() throws Exception {
|
||||
work();
|
||||
return lastChunks;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,12 +20,14 @@ package org.jackhuang.hellominecraft.util.tasks;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
||||
|
||||
/**
|
||||
@@ -84,7 +86,9 @@ public class TaskList extends Thread {
|
||||
|
||||
}
|
||||
|
||||
static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(64);
|
||||
ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(64);
|
||||
HashMap<Invoker, Future<?>> futures = new HashMap<>();
|
||||
HashSet<Invoker> invokers = new HashSet<>();
|
||||
|
||||
private void processTasks(Collection<? extends Task> c) {
|
||||
if (c == null || c.isEmpty())
|
||||
@@ -95,8 +99,9 @@ public class TaskList extends Thread {
|
||||
t2.setParallelExecuting(true);
|
||||
Invoker thread = new Invoker(t2, runningThread);
|
||||
runningThread.add(thread);
|
||||
invokers.add(thread);
|
||||
if (!EXECUTOR_SERVICE.isTerminated())
|
||||
EXECUTOR_SERVICE.execute(thread);
|
||||
futures.put(thread, EXECUTOR_SERVICE.submit(thread));
|
||||
}
|
||||
while (!runningThread.isEmpty())
|
||||
try {
|
||||
@@ -116,10 +121,10 @@ public class TaskList extends Thread {
|
||||
if (c == null)
|
||||
c = new HashSet<>();
|
||||
HMCLog.log("Executing task: " + t.getInfo());
|
||||
for (DoingDoneListener<Task> d : taskListener)
|
||||
d.onDoing(t, c);
|
||||
for (DoingDoneListener<Task> d : t.getTaskListeners())
|
||||
d.onDoing(t, c);
|
||||
for (DoingDoneListener<Task> d : taskListener)
|
||||
d.onDoing(t, c);
|
||||
processTasks(c);
|
||||
|
||||
boolean flag = true;
|
||||
@@ -134,10 +139,10 @@ public class TaskList extends Thread {
|
||||
Collection<Task> at = t.getAfterTasks();
|
||||
if (at == null)
|
||||
at = new HashSet<>();
|
||||
for (DoingDoneListener<Task> d : taskListener)
|
||||
d.onDone(t, at);
|
||||
for (DoingDoneListener<Task> d : t.getTaskListeners())
|
||||
d.onDone(t, at);
|
||||
for (DoingDoneListener<Task> d : taskListener)
|
||||
d.onDone(t, at);
|
||||
processTasks(at);
|
||||
} else {
|
||||
HMCLog.err("Task failed: " + t.getInfo(), t.getFailReason());
|
||||
@@ -166,7 +171,15 @@ public class TaskList extends Thread {
|
||||
|
||||
public void abort() {
|
||||
shouldContinue = false;
|
||||
EXECUTOR_SERVICE.shutdownNow();
|
||||
final HashSet<Invoker> in = this.invokers;
|
||||
EXECUTOR_SERVICE.shutdown();
|
||||
while (!in.isEmpty())
|
||||
synchronized (in) {
|
||||
Invoker it = in.iterator().next();
|
||||
if (!it.task.abort())
|
||||
futures.get(it).cancel(true);
|
||||
in.remove(it);
|
||||
}
|
||||
this.interrupt();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,9 +34,11 @@ import org.jackhuang.hellominecraft.util.ui.SwingUtils;
|
||||
public class TaskWindow extends javax.swing.JDialog
|
||||
implements ProgressProviderListener, Runnable, DoingDoneListener<Task> {
|
||||
|
||||
private static final TaskWindow INSTANCE = new TaskWindow();
|
||||
private static volatile TaskWindow INSTANCE = null;
|
||||
|
||||
private static TaskWindow instance() {
|
||||
private static synchronized TaskWindow instance() {
|
||||
if (INSTANCE == null)
|
||||
INSTANCE = new TaskWindow();
|
||||
INSTANCE.clean();
|
||||
return INSTANCE;
|
||||
}
|
||||
@@ -82,6 +84,8 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
taskList.addAllDoneListener(this);
|
||||
}
|
||||
|
||||
public static String downloadSource = "";
|
||||
|
||||
public boolean start() {
|
||||
if (isVisible() || taskList == null || taskList.isAlive())
|
||||
return false;
|
||||
@@ -101,7 +105,7 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
MessageBox.Show(C.i18n("taskwindow.no_more_instance"));
|
||||
return false;
|
||||
}
|
||||
setTitle(C.i18n("taskwindow.title") + ": " + C.i18n("download.source"));
|
||||
setTitle(C.i18n("taskwindow.title") + " - " + C.i18n("download.source") + ": " + downloadSource);
|
||||
this.setVisible(true);
|
||||
return this.areTasksFinished();
|
||||
}
|
||||
@@ -296,6 +300,13 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean execute(Task... ts) {
|
||||
TaskWindowFactory f = factory();
|
||||
for (Task t : ts)
|
||||
f.append(t);
|
||||
return f.create();
|
||||
}
|
||||
|
||||
public static class TaskWindowFactory {
|
||||
|
||||
LinkedList<Task> ll = new LinkedList<>();
|
||||
@@ -309,10 +320,10 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
public boolean create() {
|
||||
String stacktrace = StrUtils.getStackTrace(new Throwable());
|
||||
return SwingUtils.invokeAndWait(() -> {
|
||||
synchronized (INSTANCE) {
|
||||
if (INSTANCE.isVisible())
|
||||
final TaskWindow tw = instance();
|
||||
synchronized (tw) {
|
||||
if (tw.isVisible())
|
||||
return false;
|
||||
TaskWindow tw = instance();
|
||||
for (Task t : ll)
|
||||
tw.addTask(t);
|
||||
tw.lastStackTrace = tw.stackTrace;
|
||||
|
||||
@@ -128,6 +128,8 @@ public class FileDownloadTask extends Task implements PreviousResult<File>, Prev
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!shouldContinue)
|
||||
break;
|
||||
try {
|
||||
|
||||
// Open connection to URL.
|
||||
@@ -195,8 +197,6 @@ public class FileDownloadTask extends Task implements PreviousResult<File>, Prev
|
||||
lastTime = now;
|
||||
}
|
||||
}
|
||||
if (downloaded != contentLength)
|
||||
throw new IllegalStateException("Unexptected file size: " + downloaded + ", expected: " + contentLength);
|
||||
closeFiles();
|
||||
if (aborted)
|
||||
tempFile.delete();
|
||||
@@ -205,6 +205,10 @@ public class FileDownloadTask extends Task implements PreviousResult<File>, Prev
|
||||
filePath.delete();
|
||||
tempFile.renameTo(filePath);
|
||||
}
|
||||
if (!shouldContinue)
|
||||
break;
|
||||
if (downloaded != contentLength)
|
||||
throw new IllegalStateException("Unexptected file size: " + downloaded + ", expected: " + contentLength);
|
||||
String hashCode = String.format("%1$040x", new Object[] { new BigInteger(1, digest.digest()) });
|
||||
if (expectedHash != null && !expectedHash.equals(hashCode))
|
||||
throw new IllegalStateException("Unexpected hash code: " + hashCode + ", expected: " + expectedHash);
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Hello Minecraft!.
|
||||
* 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/}.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.util.version;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class MinecraftRemoteLatestVersion {
|
||||
|
||||
public String snapshot, release;
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Hello Minecraft!.
|
||||
* 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/}.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.util.version;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class MinecraftRemoteVersion {
|
||||
|
||||
public String id, time, releaseTime, type;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Hello Minecraft!.
|
||||
* 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/}.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.util.version;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class MinecraftRemoteVersions {
|
||||
|
||||
public ArrayList<MinecraftRemoteVersion> versions;
|
||||
public MinecraftRemoteLatestVersion latest;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user