Reset the java directory when javadir is wrong.
This commit is contained in:
@@ -51,7 +51,7 @@ public final class C {
|
||||
try {
|
||||
return String.format(C.I18N.getString(a), format);
|
||||
} catch (Exception e) {
|
||||
HMCLog.warn("Failed to read localization lang: " + a, e);
|
||||
HMCLog.warn("Failed to read localization key: " + a, e);
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.jackhuang.hellominecraft.utils.functions.NonConsumer;
|
||||
import org.jackhuang.hellominecraft.HMCLog;
|
||||
|
||||
/**
|
||||
@@ -32,7 +31,7 @@ import org.jackhuang.hellominecraft.HMCLog;
|
||||
public class TaskList extends Thread {
|
||||
|
||||
List<Task> taskQueue = Collections.synchronizedList(new ArrayList());
|
||||
ArrayList<NonConsumer> allDone = new ArrayList();
|
||||
ArrayList<Runnable> allDone = new ArrayList();
|
||||
ArrayList<DoingDoneListener<Task>> taskListener = new ArrayList();
|
||||
|
||||
int totTask;
|
||||
@@ -46,7 +45,7 @@ public class TaskList extends Thread {
|
||||
taskQueue.clear();
|
||||
}
|
||||
|
||||
public void addAllDoneListener(NonConsumer l) {
|
||||
public void addAllDoneListener(Runnable l) {
|
||||
allDone.add(l);
|
||||
}
|
||||
|
||||
@@ -100,8 +99,7 @@ public class TaskList extends Thread {
|
||||
try {
|
||||
if (this.isInterrupted()) return;
|
||||
Thread.sleep(1);
|
||||
} catch (InterruptedException ex) {
|
||||
HMCLog.warn("Failed to sleep task thread", ex);
|
||||
} catch (InterruptedException ignore) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -148,8 +146,8 @@ public class TaskList extends Thread {
|
||||
for (Task taskQueue1 : taskQueue)
|
||||
executeTask(taskQueue1);
|
||||
if (shouldContinue)
|
||||
for (NonConsumer d : allDone)
|
||||
d.onDone();
|
||||
for (Runnable d : allDone)
|
||||
d.run();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.jackhuang.hellominecraft.tasks;
|
||||
import java.util.ArrayList;
|
||||
import javax.swing.SwingUtilities;
|
||||
import org.jackhuang.hellominecraft.C;
|
||||
import org.jackhuang.hellominecraft.utils.functions.NonConsumer;
|
||||
import org.jackhuang.hellominecraft.HMCLog;
|
||||
import org.jackhuang.hellominecraft.utils.system.MessageBox;
|
||||
import org.jackhuang.hellominecraft.utils.StrUtils;
|
||||
@@ -30,7 +29,7 @@ import org.jackhuang.hellominecraft.utils.SwingUtils;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class TaskWindow extends javax.swing.JDialog
|
||||
implements ProgressProviderListener, NonConsumer, DoingDoneListener<Task> {
|
||||
implements ProgressProviderListener, Runnable, DoingDoneListener<Task> {
|
||||
|
||||
private static final TaskWindow instance = new TaskWindow();
|
||||
|
||||
@@ -202,7 +201,7 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDone() {
|
||||
public void run() {
|
||||
suc = true;
|
||||
this.dispose();
|
||||
HMCLog.log("Tasks are finished.");
|
||||
@@ -259,7 +258,9 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
@Override
|
||||
public void setStatus(Task task, String sta) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
SwingUtils.setValueAt(lstDownload, sta, lstDownload.getRowCount(), 0);
|
||||
int idx = tasks.indexOf(task);
|
||||
if (idx == -1) return;
|
||||
SwingUtils.setValueAt(lstDownload, task.getInfo() + ": " + sta, idx, 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,12 +38,14 @@ import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
||||
public class FileDownloadTask extends Task implements PreviousResult<File>, PreviousResultRegistrar<String> {
|
||||
|
||||
// Max size of download buffer.
|
||||
private static final int MAX_BUFFER_SIZE = 2048;
|
||||
protected static final int MAX_BUFFER_SIZE = 2048;
|
||||
|
||||
private URL url; // download URL
|
||||
private int size; // size of download in bytes
|
||||
private int downloaded; // number of bytes downloaded
|
||||
private final File filePath;
|
||||
protected URL url; // download URL
|
||||
protected int downloaded = 0; // number of bytes downloaded
|
||||
protected File filePath;
|
||||
|
||||
public FileDownloadTask() {
|
||||
}
|
||||
|
||||
public FileDownloadTask(File filePath) {
|
||||
this((URL) null, filePath);
|
||||
@@ -56,8 +58,6 @@ public class FileDownloadTask extends Task implements PreviousResult<File>, Prev
|
||||
// Constructor for Download.
|
||||
public FileDownloadTask(URL url, File filePath) {
|
||||
this.url = url;
|
||||
size = -1;
|
||||
downloaded = 0;
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
@@ -124,10 +124,6 @@ public class FileDownloadTask extends Task implements PreviousResult<File>, Prev
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the size for this download if it hasn't been already set.
|
||||
if (size == -1)
|
||||
size = contentLength;
|
||||
|
||||
filePath.getParentFile().mkdirs();
|
||||
|
||||
File tempFile = new File(filePath.getAbsolutePath() + ".hmd");
|
||||
@@ -135,10 +131,11 @@ public class FileDownloadTask extends Task implements PreviousResult<File>, Prev
|
||||
tempFile.createNewFile();
|
||||
|
||||
// Open file and seek to the end of it.
|
||||
file = new RandomAccessFile(tempFile, "rw");
|
||||
file.seek(downloaded);
|
||||
file = new RandomAccessFile(tempFile, "rwd");
|
||||
|
||||
stream = connection.getInputStream();
|
||||
int lastDownloaded = 0;
|
||||
long lastTime = System.currentTimeMillis();
|
||||
while (true) {
|
||||
// Size buffer according to how much of the file is left to download.
|
||||
if (!shouldContinue) {
|
||||
@@ -158,14 +155,21 @@ public class FileDownloadTask extends Task implements PreviousResult<File>, Prev
|
||||
file.write(buffer, 0, read);
|
||||
downloaded += read;
|
||||
|
||||
if (ppl != null)
|
||||
ppl.setProgress(this, downloaded, size);
|
||||
long now = System.currentTimeMillis();
|
||||
if (ppl != null && (now - lastTime) >= 1000) {
|
||||
ppl.setProgress(this, downloaded, contentLength);
|
||||
ppl.setStatus(this, (downloaded - lastDownloaded) / 1024 + "KB/s");
|
||||
lastDownloaded = downloaded;
|
||||
lastTime = now;
|
||||
}
|
||||
}
|
||||
closeFiles();
|
||||
if (aborted)
|
||||
tempFile.delete();
|
||||
else
|
||||
else {
|
||||
if (filePath.exists()) filePath.delete();
|
||||
tempFile.renameTo(filePath);
|
||||
}
|
||||
if (ppl != null)
|
||||
ppl.onProgressProviderDone(this);
|
||||
return true;
|
||||
@@ -184,6 +188,7 @@ public class FileDownloadTask extends Task implements PreviousResult<File>, Prev
|
||||
|
||||
@Override
|
||||
public boolean abort() {
|
||||
//for (Downloader d : downloaders) d.abort();
|
||||
shouldContinue = false;
|
||||
aborted = true;
|
||||
return true;
|
||||
|
||||
@@ -22,6 +22,10 @@ package org.jackhuang.hellominecraft.tasks.download;
|
||||
*/
|
||||
public class NetException extends RuntimeException {
|
||||
|
||||
public NetException(Exception message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public NetException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.jackhuang.hellominecraft.utils;
|
||||
import java.util.Map;
|
||||
import org.jackhuang.hellominecraft.utils.system.MessageBox;
|
||||
import org.jackhuang.hellominecraft.C;
|
||||
import org.jackhuang.hellominecraft.utils.functions.NonConsumer;
|
||||
import org.jackhuang.hellominecraft.HMCLog;
|
||||
|
||||
/**
|
||||
@@ -30,16 +29,15 @@ public final class UpdateChecker extends Thread {
|
||||
|
||||
public static boolean OUT_DATED = false;
|
||||
public VersionNumber base;
|
||||
public String versionString;
|
||||
public String type;
|
||||
public boolean continueUpdate;
|
||||
public NonConsumer dl;
|
||||
public Map<String, String> download_link;
|
||||
public Runnable dl;
|
||||
public Map<String, String> download_link = null;
|
||||
|
||||
public UpdateChecker(VersionNumber base, String type, boolean continueUpdate, NonConsumer dl) {
|
||||
public UpdateChecker(VersionNumber base, String type, Runnable dl) {
|
||||
super("UpdateChecker");
|
||||
this.base = base;
|
||||
this.type = type;
|
||||
this.continueUpdate = continueUpdate;
|
||||
this.dl = dl;
|
||||
}
|
||||
|
||||
@@ -48,25 +46,16 @@ public final class UpdateChecker extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
String version;
|
||||
try {
|
||||
version = NetUtils.doGet("http://huangyuhui.duapp.com/info.php?type=" + type);
|
||||
versionString = NetUtils.doGet("http://huangyuhui.duapp.com/info.php?type=" + type);
|
||||
} catch (Exception e) {
|
||||
HMCLog.warn("Failed to get update url.", e);
|
||||
return;
|
||||
}
|
||||
value = VersionNumber.check(version);
|
||||
if (!continueUpdate)
|
||||
return;
|
||||
value = VersionNumber.check(versionString);
|
||||
process(false);
|
||||
if (OUT_DATED) {
|
||||
try {
|
||||
download_link = C.gson.fromJson(NetUtils.doGet("http://huangyuhui.duapp.com/update_link.php?type=" + type), Map.class);
|
||||
} catch (Exception e) {
|
||||
HMCLog.warn("Failed to get update link.", e);
|
||||
}
|
||||
dl.onDone();
|
||||
}
|
||||
if (OUT_DATED)
|
||||
dl.run();
|
||||
}
|
||||
|
||||
public void process(boolean showMessage) {
|
||||
@@ -74,14 +63,23 @@ public final class UpdateChecker extends Thread {
|
||||
HMCLog.warn("Failed to check update...");
|
||||
if (showMessage)
|
||||
MessageBox.Show(C.i18n("update.failed"));
|
||||
} else
|
||||
if (VersionNumber.isOlder(base, value)) {
|
||||
OUT_DATED = true;
|
||||
}
|
||||
} else if (VersionNumber.isOlder(base, value))
|
||||
OUT_DATED = true;
|
||||
}
|
||||
|
||||
public VersionNumber getNewVersion() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public synchronized void requestDownloadLink(Runnable finish) {
|
||||
new Thread(() -> {
|
||||
if (download_link == null)
|
||||
try {
|
||||
download_link = C.gson.fromJson(NetUtils.doGet("http://huangyuhui.duapp.com/update_link.php?type=" + type), Map.class);
|
||||
} catch (Exception e) {
|
||||
HMCLog.warn("Failed to get update link.", e);
|
||||
}
|
||||
finish.run();
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,11 +344,13 @@ public class FileUtils {
|
||||
return filename.substring(0, index);
|
||||
}
|
||||
|
||||
public static void writeQuietly(File file, CharSequence data) {
|
||||
public static boolean writeQuietly(File file, CharSequence data) {
|
||||
try {
|
||||
write(file, data);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
HMCLog.warn("Failed to write data to file: " + file, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,23 +38,24 @@ public class JavaProcessMonitor {
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
void start() {
|
||||
public void start() {
|
||||
Event<JavaProcess> event = (sender2, t) -> {
|
||||
processThreadStopped((ProcessThread) sender2, false);
|
||||
return true;
|
||||
};
|
||||
ProcessThread a = new ProcessThread(p, true, true);
|
||||
a.stopEvent.register((sender3, p1) -> {
|
||||
Event<JavaProcess> event2 = (sender3, p1) -> {
|
||||
if (p1.getExitCode() != 0 && p1.getStdErrLines().size() > 0 && StrUtils.containsOne(p1.getStdErrLines(), Arrays.asList("Could not create the Java Virtual Machine.",
|
||||
"Error occurred during initialization of VM",
|
||||
"A fatal exception has occurred. Program will exit."))) MessageBox.Show(C.i18n("launch.cannot_create_jvm"));
|
||||
processThreadStopped((ProcessThread) sender3, false);
|
||||
return true;
|
||||
});
|
||||
};
|
||||
ProcessThread a = new ProcessThread(p, true, true);
|
||||
a.stopEvent.register(event2);
|
||||
a.start();
|
||||
al.add(a);
|
||||
a = new ProcessThread(p, false, true);
|
||||
a.stopEvent.register(event);
|
||||
a.stopEvent.register(event2);
|
||||
a.start();
|
||||
al.add(a);
|
||||
a = new ProcessThread(p, false, false);
|
||||
|
||||
@@ -14,13 +14,33 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.utils.functions;
|
||||
package org.jackhuang.hellominecraft.utils.system;
|
||||
|
||||
import org.jackhuang.hellominecraft.utils.functions.Consumer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public interface NonConsumer {
|
||||
public class ThreadExecutor extends Thread {
|
||||
|
||||
public final Consumer<Throwable> c;
|
||||
public final Runnable r;
|
||||
|
||||
public ThreadExecutor(Consumer<Throwable> c, Runnable r) {
|
||||
super();
|
||||
this.c = c;
|
||||
this.r = r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
r.run();
|
||||
c.accept(null);
|
||||
} catch (Throwable t) {
|
||||
c.accept(t);
|
||||
}
|
||||
}
|
||||
|
||||
void onDone();
|
||||
}
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jackhuang.hellominecraft.views;
|
||||
|
||||
import org.jackhuang.hellominecraft.C;
|
||||
import org.jackhuang.hellominecraft.utils.functions.NonConsumer;
|
||||
import org.jackhuang.hellominecraft.utils.functions.NonFunction;
|
||||
import org.jackhuang.hellominecraft.utils.DoubleOutputStream;
|
||||
import org.jackhuang.hellominecraft.utils.LauncherPrintStream;
|
||||
@@ -33,7 +32,7 @@ public class LogWindow extends javax.swing.JFrame {
|
||||
|
||||
boolean movingEnd;
|
||||
NonFunction<Boolean> listener;
|
||||
NonConsumer terminateGameListener;
|
||||
Runnable terminateGameListener;
|
||||
|
||||
/**
|
||||
* Creates new form LogWindow
|
||||
@@ -226,7 +225,7 @@ public class LogWindow extends javax.swing.JFrame {
|
||||
|
||||
private void btnTerminateGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTerminateGameActionPerformed
|
||||
if (terminateGameListener != null)
|
||||
terminateGameListener.onDone();
|
||||
terminateGameListener.run();
|
||||
}//GEN-LAST:event_btnTerminateGameActionPerformed
|
||||
|
||||
private void btnGitHubActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGitHubActionPerformed
|
||||
@@ -253,7 +252,7 @@ public class LogWindow extends javax.swing.JFrame {
|
||||
this.listener = exit;
|
||||
}
|
||||
|
||||
public void setTerminateGame(NonConsumer l) {
|
||||
public void setTerminateGame(Runnable l) {
|
||||
this.terminateGameListener = l;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ launch.cannot_create_jvm=\u622a\u83b7\u5230\u65e0\u6cd5\u521b\u5efaJava\u865a\u6
|
||||
launch.circular_dependency_versions=\u53d1\u73b0\u6e38\u620f\u7248\u672c\u5faa\u73af\u5f15\u7528\uff0c\u8bf7\u786e\u8ba4\u60a8\u7684\u5ba2\u6237\u7aef\u672a\u88ab\u4fee\u6539\u6216\u4fee\u6539\u5bfc\u81f4\u51fa\u73b0\u6b64\u95ee\u9898\u3002
|
||||
launch.not_finished_downloading_libraries=\u672a\u5b8c\u6210\u6e38\u620f\u4f9d\u8d56\u5e93\u7684\u4e0b\u8f7d\uff0c\u8fd8\u8981\u7ee7\u7eed\u542f\u52a8\u6e38\u620f\u5417\uff1f
|
||||
launch.not_finished_decompressing_natives=\u672a\u80fd\u89e3\u538b\u6e38\u620f\u672c\u5730\u5e93\uff0c\u8fd8\u8981\u7ee7\u7eed\u542f\u52a8\u6e38\u620f\u5417\uff1f
|
||||
launch.wrong_javadir=\u9519\u8bef\u7684Java\u8def\u5f84\uff0c\u5c06\u81ea\u52a8\u91cd\u7f6e\u4e3a\u9ed8\u8ba4Java\u8def\u5f84\u3002
|
||||
|
||||
install.no_version=\u672a\u627e\u5230\u8981\u5b89\u88c5\u7684\u5bf9\u5e94MC\u7248\u672c
|
||||
install.no_version_if_intall=\u672a\u627e\u5230\u8981\u5b89\u88c5\u7684\u5bf9\u5e94MC\u7248\u672c\uff0c\u662f\u5426\u81ea\u52a8\u5b89\u88c5\u9700\u8981\u7684MC\u7248\u672c\uff1f
|
||||
|
||||
@@ -23,6 +23,7 @@ launch.cannot_create_jvm=We find that it cannot create java virutal machine. The
|
||||
launch.circular_dependency_versions=Found circular dependency versions, please check if your client has been modified.
|
||||
launch.not_finished_downloading_libraries=Did not finish downloading libraries, continue launching game?
|
||||
launch.not_finished_decompressing_natives=Did not finish decompressing native libraries, continue launching game?
|
||||
launch.wrong_javadir=Wrong Java Dir, will reset to default Java dir.
|
||||
|
||||
install.no_version=The version is not found.
|
||||
install.no_version_if_intall=The needed version is not found, should install the version automatically?
|
||||
|
||||
@@ -23,6 +23,7 @@ launch.cannot_create_jvm=\u622a\u83b7\u5230\u65e0\u6cd5\u521b\u5efaJava\u865a\u6
|
||||
launch.circular_dependency_versions=\u53d1\u73b0\u6e38\u620f\u7248\u672c\u5faa\u73af\u5f15\u7528\uff0c\u8bf7\u786e\u8ba4\u60a8\u7684\u5ba2\u6237\u7aef\u672a\u88ab\u4fee\u6539\u6216\u4fee\u6539\u5bfc\u81f4\u51fa\u73b0\u6b64\u95ee\u9898\u3002
|
||||
launch.not_finished_downloading_libraries=\u672a\u5b8c\u6210\u6e38\u620f\u4f9d\u8d56\u5e93\u7684\u4e0b\u8f7d\uff0c\u8fd8\u8981\u7ee7\u7eed\u542f\u52a8\u6e38\u620f\u5417\uff1f
|
||||
launch.not_finished_decompressing_natives=\u672a\u80fd\u89e3\u538b\u6e38\u620f\u672c\u5730\u5e93\uff0c\u8fd8\u8981\u7ee7\u7eed\u542f\u52a8\u6e38\u620f\u5417\uff1f
|
||||
launch.wrong_javadir=\u9519\u8bef\u7684Java\u8def\u5f84\uff0c\u5c06\u81ea\u52a8\u91cd\u7f6e\u4e3a\u9ed8\u8ba4Java\u8def\u5f84\u3002
|
||||
|
||||
install.no_version=\u672a\u627e\u5230\u8981\u5b89\u88c5\u7684\u5bf9\u5e94MC\u7248\u672c
|
||||
install.no_version_if_intall=\u672a\u627e\u5230\u8981\u5b89\u88c5\u7684\u5bf9\u5e94MC\u7248\u672c\uff0c\u662f\u5426\u81ea\u52a8\u5b89\u88c5\u9700\u8981\u7684MC\u7248\u672c\uff1f
|
||||
|
||||
@@ -23,6 +23,7 @@ launch.cannot_create_jvm=\u622a\u7372\u5230\u7121\u6cd5\u5275\u5efaJava\u865b\u6
|
||||
launch.circular_dependency_versions=\u767c\u73fe\u904a\u6232\u7248\u672c\u5faa\u74b0\u5f15\u7528\uff0c\u8acb\u78ba\u8a8d\u60a8\u7684\u5ba2\u6236\u7aef\u672a\u88ab\u4fee\u6539\u6216\u4fee\u6539\u5c0e\u81f4\u51fa\u73fe\u6b64\u554f\u984c\u3002
|
||||
launch.not_finished_downloading_libraries=\u672a\u5b8c\u6210\u904a\u6232\u4f9d\u8cf4\u5eab\u7684\u4e0b\u8f09\uff0c\u9084\u8981\u7e7c\u7e8c\u555f\u52d5\u904a\u6232\u55ce\uff1f
|
||||
launch.not_finished_decompressing_natives=\u672a\u80fd\u89e3\u58d3\u904a\u6232\u672c\u5730\u5eab\uff0c\u9084\u8981\u7e7c\u7e8c\u555f\u52d5\u904a\u6232\u55ce\uff1f
|
||||
launch.wrong_javadir=\u932f\u8aa4\u7684Java\u8def\u5f91\uff0c\u5c07\u81ea\u52d5\u91cd\u7f6e\u70ba\u9ed8\u8a8dJava\u8def\u5f91\u3002
|
||||
|
||||
install.no_version=\u672a\u627e\u5230\u8981\u5b89\u88dd\u7684\u5c0d\u61c9MC\u7248\u672c
|
||||
install.no_version_if_intall=\u672a\u627e\u5230\u8981\u5b89\u88dd\u7684\u5c0d\u61c9MC\u7248\u672c\uff0c\u662f\u5426\u81ea\u52a8\u5b89\u88c5\u9700\u8981\u7684MC\u7248\u672c\uff1f
|
||||
|
||||
Reference in New Issue
Block a user