allow tasks being hidden in task window
This commit is contained in:
@@ -46,7 +46,7 @@ def buildnumber = System.getenv("TRAVIS_BUILD_NUMBER")
|
|||||||
if (buildnumber == null)
|
if (buildnumber == null)
|
||||||
buildnumber = System.getenv("BUILD_NUMBER")
|
buildnumber = System.getenv("BUILD_NUMBER")
|
||||||
if (buildnumber == null)
|
if (buildnumber == null)
|
||||||
buildnumber = "0"
|
buildnumber = "1"
|
||||||
|
|
||||||
def versionroot = System.getenv("VERSION_ROOT")
|
def versionroot = System.getenv("VERSION_ROOT")
|
||||||
if (versionroot == null)
|
if (versionroot == null)
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ public abstract class IAssetsHandler {
|
|||||||
try {
|
try {
|
||||||
if (location.exists()) {
|
if (location.exists()) {
|
||||||
FileInputStream fis = new FileInputStream(location);
|
FileInputStream fis = new FileInputStream(location);
|
||||||
String sha = DigestUtils.sha1Hex(IOUtils.getBytesFromStream(fis));
|
String sha = DigestUtils.sha1Hex(IOUtils.readFully(fis).toByteArray());
|
||||||
IOUtils.closeQuietly(fis);
|
IOUtils.closeQuietly(fis);
|
||||||
if (contents.get(i).geteTag().equals(sha)) {
|
if (contents.get(i).geteTag().equals(sha)) {
|
||||||
++hasDownloaded;
|
++hasDownloaded;
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ import javax.swing.JOptionPane;
|
|||||||
import org.jackhuang.hellominecraft.util.C;
|
import org.jackhuang.hellominecraft.util.C;
|
||||||
import org.jackhuang.hellominecraft.util.ArrayUtils;
|
import org.jackhuang.hellominecraft.util.ArrayUtils;
|
||||||
import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.GameProfile;
|
import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.GameProfile;
|
||||||
|
import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.UUIDTypeAdapter;
|
||||||
import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.PropertyMap;
|
import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.PropertyMap;
|
||||||
import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.YggdrasilAuthentication;
|
import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.YggdrasilAuthentication;
|
||||||
import org.jackhuang.hellominecraft.launcher.core.auth.yggdrasil.UUIDTypeAdapter;
|
|
||||||
import org.jackhuang.hellominecraft.util.ui.SwingUtils;
|
import org.jackhuang.hellominecraft.util.ui.SwingUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ public class YggdrasilAuthentication {
|
|||||||
|
|
||||||
private void loggedIn(URL url, Object input) throws AuthenticationException {
|
private void loggedIn(URL url, Object input) throws AuthenticationException {
|
||||||
try {
|
try {
|
||||||
String jsonResult = input == null ? NetUtils.get(url) : NetUtils.post(url, GSON.toJson(input), "application/json", proxy);
|
String jsonResult = input == null ? NetUtils.get(url, proxy) : NetUtils.post(url, GSON.toJson(input), "application/json", proxy);
|
||||||
Response response = (Response) GSON.fromJson(jsonResult, Response.class);
|
Response response = (Response) GSON.fromJson(jsonResult, Response.class);
|
||||||
|
|
||||||
if (response == null)
|
if (response == null)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import com.google.gson.annotations.SerializedName;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import org.jackhuang.hellominecraft.util.C;
|
import org.jackhuang.hellominecraft.util.C;
|
||||||
import org.jackhuang.hellominecraft.util.NetUtils;
|
import org.jackhuang.hellominecraft.util.NetUtils;
|
||||||
import org.jackhuang.hellominecraft.util.OverridableSwingWorker;
|
import org.jackhuang.hellominecraft.util.AbstractSwingWorker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -55,7 +55,7 @@ public class MinecraftRemoteVersions {
|
|||||||
return new RemoteVersionsTask(type);
|
return new RemoteVersionsTask(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class RemoteVersionsTask extends OverridableSwingWorker<MinecraftRemoteVersion> {
|
public static class RemoteVersionsTask extends AbstractSwingWorker<MinecraftRemoteVersion> {
|
||||||
|
|
||||||
DownloadType type;
|
DownloadType type;
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
|||||||
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
|
import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService;
|
||||||
import org.jackhuang.hellominecraft.util.tasks.Task;
|
import org.jackhuang.hellominecraft.util.tasks.Task;
|
||||||
import org.jackhuang.hellominecraft.util.system.FileUtils;
|
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.launcher.core.version.MinecraftLibrary;
|
||||||
import org.jackhuang.hellominecraft.util.MessageBox;
|
import org.jackhuang.hellominecraft.util.MessageBox;
|
||||||
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
||||||
@@ -55,7 +54,7 @@ public class ForgeInstaller extends Task {
|
|||||||
|
|
||||||
try (ZipFile zipFile = new ZipFile(forgeInstaller)) {
|
try (ZipFile zipFile = new ZipFile(forgeInstaller)) {
|
||||||
ZipEntry entry = zipFile.getEntry("install_profile.json");
|
ZipEntry entry = zipFile.getEntry("install_profile.json");
|
||||||
String content = IOUtils.getStreamContent(zipFile.getInputStream(entry));
|
String content = IOUtils.toString(zipFile.getInputStream(entry));
|
||||||
InstallProfile profile = C.GSON.fromJson(content, InstallProfile.class);
|
InstallProfile profile = C.GSON.fromJson(content, InstallProfile.class);
|
||||||
File from = new File(gameDir, "versions" + File.separator + profile.install.getMinecraft());
|
File from = new File(gameDir, "versions" + File.separator + profile.install.getMinecraft());
|
||||||
if (!from.exists())
|
if (!from.exists())
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ import org.jackhuang.hellominecraft.util.system.ZipEngine;
|
|||||||
import org.jackhuang.hellominecraft.util.tasks.Task;
|
import org.jackhuang.hellominecraft.util.tasks.Task;
|
||||||
import org.jackhuang.hellominecraft.util.ui.WebPage;
|
import org.jackhuang.hellominecraft.util.ui.WebPage;
|
||||||
import org.jackhuang.hellominecraft.util.MinecraftVersionRequest;
|
import org.jackhuang.hellominecraft.util.MinecraftVersionRequest;
|
||||||
|
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
||||||
import org.jackhuang.hellominecraft.util.tasks.NoShownTaskException;
|
import org.jackhuang.hellominecraft.util.tasks.NoShownTaskException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -275,8 +276,7 @@ public final class ModpackManager {
|
|||||||
if (callback != null)
|
if (callback != null)
|
||||||
callback.call(zip);
|
callback.call(zip);
|
||||||
} finally {
|
} finally {
|
||||||
if (zip != null)
|
IOUtils.closeQuietly(zip);
|
||||||
zip.closeFile();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ public final class Main implements Runnable {
|
|||||||
HMCLog.warn("Failed to set look and feel...", ex);
|
HMCLog.warn("Failed to set look and feel...", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings.UPDATE_CHECKER.outdated.register(IUpgrader.NOW_UPGRADER);
|
Settings.UPDATE_CHECKER.outOfDateEvent.register(IUpgrader.NOW_UPGRADER);
|
||||||
Settings.UPDATE_CHECKER.process(false).reg(t -> Main.invokeUpdate()).execute();
|
Settings.UPDATE_CHECKER.process(false).reg(t -> Main.invokeUpdate()).execute();
|
||||||
|
|
||||||
if (StrUtils.isNotBlank(Settings.getInstance().getProxyHost()) && StrUtils.isNotBlank(Settings.getInstance().getProxyPort()) && MathUtils.canParseInt(Settings.getInstance().getProxyPort())) {
|
if (StrUtils.isNotBlank(Settings.getInstance().getProxyHost()) && StrUtils.isNotBlank(Settings.getInstance().getProxyPort()) && MathUtils.canParseInt(Settings.getInstance().getProxyPort())) {
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ public final class Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<Profile> getProfilesFiltered() {
|
public static Collection<Profile> getProfilesFiltered() {
|
||||||
return CollectionUtils.map(getProfiles().values(), t -> t != null && t.getName() != null);
|
return CollectionUtils.filter(getProfiles().values(), t -> t != null && t.getName() != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Profile getOneProfile() {
|
public static Profile getOneProfile() {
|
||||||
|
|||||||
@@ -107,10 +107,14 @@ public class GameDownloadPanel extends Page {
|
|||||||
|
|
||||||
public void refreshDownloads() {
|
public void refreshDownloads() {
|
||||||
DefaultTableModel model = SwingUtils.clearDefaultTable(lstDownloads);
|
DefaultTableModel model = SwingUtils.clearDefaultTable(lstDownloads);
|
||||||
|
model.addRow(new Object[] { C.i18n("message.loading"), "", "" });
|
||||||
MinecraftRemoteVersions.refreshRomoteVersions(Settings.getLastProfile().service().getDownloadType())
|
MinecraftRemoteVersions.refreshRomoteVersions(Settings.getLastProfile().service().getDownloadType())
|
||||||
.reg((ver) -> model.addRow(new Object[] { ver.id, ver.time,
|
.reg((ver) -> model.addRow(new Object[] { ver.id, ver.time,
|
||||||
StrUtils.equalsOne(ver.type, "old_beta", "old_alpha", "release", "snapshot") ? C.i18n("versions." + ver.type) : ver.type }))
|
StrUtils.equalsOne(ver.type, "old_beta", "old_alpha", "release", "snapshot") ? C.i18n("versions." + ver.type) : ver.type }))
|
||||||
.regDone(lstDownloads::requestFocus).execute();
|
.regDone(() -> {
|
||||||
|
lstDownloads.requestFocus();
|
||||||
|
model.removeRow(0);
|
||||||
|
}).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
void downloadMinecraft() {
|
void downloadMinecraft() {
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ import org.jackhuang.hellominecraft.launcher.core.version.GameDirType;
|
|||||||
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
|
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion;
|
||||||
import org.jackhuang.hellominecraft.launcher.setting.VersionSetting;
|
import org.jackhuang.hellominecraft.launcher.setting.VersionSetting;
|
||||||
import org.jackhuang.hellominecraft.util.MessageBox;
|
import org.jackhuang.hellominecraft.util.MessageBox;
|
||||||
import org.jackhuang.hellominecraft.util.OverridableSwingWorker;
|
import org.jackhuang.hellominecraft.util.AbstractSwingWorker;
|
||||||
import org.jackhuang.hellominecraft.util.MinecraftVersionRequest;
|
import org.jackhuang.hellominecraft.util.MinecraftVersionRequest;
|
||||||
import org.jackhuang.hellominecraft.util.system.OS;
|
import org.jackhuang.hellominecraft.util.system.OS;
|
||||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||||
@@ -1276,7 +1276,7 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class OverridableSwingWorkerImpl extends OverridableSwingWorker<List<ModInfo>> {
|
private static class OverridableSwingWorkerImpl extends AbstractSwingWorker<List<ModInfo>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void work() throws Exception {
|
protected void work() throws Exception {
|
||||||
|
|||||||
@@ -348,7 +348,7 @@ public final class MainFrame extends DraggableFrame implements IRepaint {
|
|||||||
isShowedMessage = false;
|
isShowedMessage = false;
|
||||||
reloadColor(Settings.getInstance().getTheme());
|
reloadColor(Settings.getInstance().getTheme());
|
||||||
windowTitle.setText(defaultTitle);
|
windowTitle.setText(defaultTitle);
|
||||||
windowTitle.setForeground(Settings.UPDATE_CHECKER.OUT_DATED ? Color.red : Color.white);
|
windowTitle.setForeground(Settings.UPDATE_CHECKER.isOutOfDate() ? Color.red : Color.white);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -114,33 +114,33 @@ public class ModpackWizard extends WizardBranchController {
|
|||||||
boolean including = false;
|
boolean including = false;
|
||||||
if ((Boolean) settings.get(ModpackInitializationPanel.KEY_INCLUDING_LAUNCHER)) {
|
if ((Boolean) settings.get(ModpackInitializationPanel.KEY_INCLUDING_LAUNCHER)) {
|
||||||
boolean flag = true;
|
boolean flag = true;
|
||||||
ZipEngine engine = new ZipEngine(loc);
|
try (ZipEngine engine = new ZipEngine(loc)) {
|
||||||
Config s = new Config();
|
Config s = new Config();
|
||||||
if (!IOUtils.isAbsolutePath(Settings.getInstance().getBgpath()))
|
if (!IOUtils.isAbsolutePath(Settings.getInstance().getBgpath()))
|
||||||
s.setBgpath(Settings.getInstance().getBgpath());
|
s.setBgpath(Settings.getInstance().getBgpath());
|
||||||
s.setDownloadType(Settings.getInstance().getDownloadType());
|
s.setDownloadType(Settings.getInstance().getDownloadType());
|
||||||
engine.putTextFile(C.GSON.toJson(s), "hmcl.json");
|
engine.putTextFile(C.GSON.toJson(s), "hmcl.json");
|
||||||
engine.putFile(modpack, "modpack.zip");
|
engine.putFile(modpack, "modpack.zip");
|
||||||
File bg = new File("bg");
|
File bg = new File("bg");
|
||||||
if (bg.isDirectory())
|
if (bg.isDirectory())
|
||||||
engine.putDirectory(bg);
|
engine.putDirectory(bg);
|
||||||
bg = new File("background.png");
|
bg = new File("background.png");
|
||||||
if (bg.isFile())
|
if (bg.isFile())
|
||||||
engine.putFile(bg, "background.png");
|
engine.putFile(bg, "background.png");
|
||||||
bg = new File("background.jpg");
|
bg = new File("background.jpg");
|
||||||
if (bg.isFile())
|
if (bg.isFile())
|
||||||
engine.putFile(bg, "background.jpg");
|
engine.putFile(bg, "background.jpg");
|
||||||
for (URL u : Utils.getURL())
|
for (URL u : Utils.getURL())
|
||||||
try {
|
try {
|
||||||
File f = new File(u.toURI());
|
File f = new File(u.toURI());
|
||||||
if (f.getName().endsWith(".exe") || f.getName().endsWith(".jar"))
|
if (f.getName().endsWith(".exe") || f.getName().endsWith(".jar"))
|
||||||
engine.putFile(f, f.getName());
|
engine.putFile(f, f.getName());
|
||||||
} catch (IOException | URISyntaxException e) {
|
} catch (IOException | URISyntaxException e) {
|
||||||
HMCLog.err("Failed to add launcher files.", e);
|
HMCLog.err("Failed to add launcher files.", e);
|
||||||
flag = false;
|
flag = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
engine.closeFile();
|
}
|
||||||
if (flag) {
|
if (flag) {
|
||||||
including = true;
|
including = true;
|
||||||
if (!modpack.delete())
|
if (!modpack.delete())
|
||||||
|
|||||||
@@ -111,8 +111,8 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
|
|||||||
System.out.println(text);
|
System.out.println(text);
|
||||||
|
|
||||||
if (checkThrowable(e) && !System.getProperty("java.vm.name").contains("OpenJDK")) {
|
if (checkThrowable(e) && !System.getProperty("java.vm.name").contains("OpenJDK")) {
|
||||||
SwingUtilities.invokeLater(() -> LogWindow.INSTANCE.showAsCrashWindow(Settings.UPDATE_CHECKER.OUT_DATED));
|
SwingUtilities.invokeLater(() -> LogWindow.INSTANCE.showAsCrashWindow(Settings.UPDATE_CHECKER.isOutOfDate()));
|
||||||
if (!Settings.UPDATE_CHECKER.OUT_DATED)
|
if (!Settings.UPDATE_CHECKER.isOutOfDate())
|
||||||
reportToServer(text, s);
|
reportToServer(text, s);
|
||||||
}
|
}
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class HelloMinecraftLookAndFeel extends SynthLookAndFeel {
|
|||||||
public HelloMinecraftLookAndFeel(Map<String, String> settings) throws ParseException {
|
public HelloMinecraftLookAndFeel(Map<String, String> settings) throws ParseException {
|
||||||
try {
|
try {
|
||||||
try (InputStream is = HelloMinecraftLookAndFeel.class.getResourceAsStream("/org/jackhuang/hellominecraft/lookandfeel/synth.xml")) {
|
try (InputStream is = HelloMinecraftLookAndFeel.class.getResourceAsStream("/org/jackhuang/hellominecraft/lookandfeel/synth.xml")) {
|
||||||
String s = IOUtils.getStreamContent(is, "UTF-8");
|
String s = IOUtils.toString(is, "UTF-8");
|
||||||
for (Map.Entry<String, String> ss : settings.entrySet())
|
for (Map.Entry<String, String> ss : settings.entrySet())
|
||||||
s = s.replace("${" + ss.getKey() + "}", ss.getValue());
|
s = s.replace("${" + ss.getKey() + "}", ss.getValue());
|
||||||
load(new ByteArrayInputStream(s.getBytes("UTF-8")), HelloMinecraftLookAndFeel.class);
|
load(new ByteArrayInputStream(s.getBytes("UTF-8")), HelloMinecraftLookAndFeel.class);
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public class ForgeInstaller {
|
|||||||
|
|
||||||
ZipFile zipFile = new ZipFile(forgeInstaller);
|
ZipFile zipFile = new ZipFile(forgeInstaller);
|
||||||
ZipEntry entry = zipFile.getEntry("install_profile.json");
|
ZipEntry entry = zipFile.getEntry("install_profile.json");
|
||||||
String content = IOUtils.getStreamContent(zipFile.getInputStream(entry));
|
String content = IOUtils.toString(zipFile.getInputStream(entry));
|
||||||
InstallProfile profile = gson.fromJson(content, InstallProfile.class);
|
InstallProfile profile = gson.fromJson(content, InstallProfile.class);
|
||||||
|
|
||||||
HMCLog.log("Extracting cauldron server pack..." + profile.install.filePath);
|
HMCLog.log("Extracting cauldron server pack..." + profile.install.filePath);
|
||||||
@@ -122,7 +122,7 @@ public class ForgeInstaller {
|
|||||||
File packFile = new File(gameDir, "libraries" + File.separator + library.formatted + ".pack.xz");
|
File packFile = new File(gameDir, "libraries" + File.separator + library.formatted + ".pack.xz");
|
||||||
if (packFile.exists() && packFile.isFile())
|
if (packFile.exists() && packFile.isFile())
|
||||||
try {
|
try {
|
||||||
unpackLibrary(lib.getParentFile(), IOUtils.getBytesFromStream(FileUtils.openInputStream(packFile)));
|
unpackLibrary(lib.getParentFile(), IOUtils.readFully(FileUtils.openInputStream(packFile)).toByteArray());
|
||||||
if (!checksumValid(lib, Arrays.asList(library.checksums)))
|
if (!checksumValid(lib, Arrays.asList(library.checksums)))
|
||||||
badLibs.add(library.name);
|
badLibs.add(library.name);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -165,7 +165,7 @@ public class ForgeInstaller {
|
|||||||
|
|
||||||
private static boolean checksumValid(File libPath, List<String> checksums) {
|
private static boolean checksumValid(File libPath, List<String> checksums) {
|
||||||
try {
|
try {
|
||||||
byte[] fileData = IOUtils.getBytesFromStream(FileUtils.openInputStream(libPath));
|
byte[] fileData = IOUtils.readFully(FileUtils.openInputStream(libPath)).toByteArray();
|
||||||
boolean valid = (checksums == null) || (checksums.isEmpty()) || (checksums.contains(DigestUtils.sha1Hex(fileData)));
|
boolean valid = (checksums == null) || (checksums.isEmpty()) || (checksums.contains(DigestUtils.sha1Hex(fileData)));
|
||||||
if ((!valid) && (libPath.getName().endsWith(".jar")))
|
if ((!valid) && (libPath.getName().endsWith(".jar")))
|
||||||
valid = validateJar(libPath, fileData, checksums);
|
valid = validateJar(libPath, fileData, checksums);
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
||||||
|
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -65,12 +66,7 @@ public class ServerProperties {
|
|||||||
HMCLog.warn("Failed to get property in server.properties", ex);
|
HMCLog.warn("Failed to get property in server.properties", ex);
|
||||||
return "";
|
return "";
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
IOUtils.closeQuietly(is);
|
||||||
if (is != null)
|
|
||||||
is.close();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
HMCLog.warn("Failed to close InputStream for server.properties", ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,12 +94,7 @@ public class ServerProperties {
|
|||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
HMCLog.warn("Failed to set property in server.properties", ex);
|
HMCLog.warn("Failed to set property in server.properties", ex);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
IOUtils.closeQuietly(is);
|
||||||
if (is != null)
|
|
||||||
is.close();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
HMCLog.warn("Failed to close OutputStream for server.properties", ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import java.util.logging.Logger;
|
|||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
import org.jackhuang.hellominecraft.util.C;
|
import org.jackhuang.hellominecraft.util.C;
|
||||||
|
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断mod类型
|
* 判断mod类型
|
||||||
@@ -68,14 +69,7 @@ public class ModType {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
IOUtils.closeQuietly(zipFile);
|
||||||
if (zipFile != null)
|
|
||||||
zipFile.close();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
Logger.getLogger(ModType.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (isModLoader)
|
if (isModLoader)
|
||||||
return MODLOADER_MOD;
|
return MODLOADER_MOD;
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import java.util.StringTokenizer;
|
|||||||
import com.sun.management.OperatingSystemMXBean;
|
import com.sun.management.OperatingSystemMXBean;
|
||||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||||
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
||||||
|
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -39,7 +40,7 @@ public class MonitorServiceImpl implements IMonitorService {
|
|||||||
private static final int CPUTIME = 30;
|
private static final int CPUTIME = 30;
|
||||||
private static final int PERCENT = 100;
|
private static final int PERCENT = 100;
|
||||||
private static final int FAULTLENGTH = 10;
|
private static final int FAULTLENGTH = 10;
|
||||||
private static final String linuxVersion = null;
|
private static final String LINUX_VERSION = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得当前的监控对象.
|
* 获得当前的监控对象.
|
||||||
@@ -77,7 +78,7 @@ public class MonitorServiceImpl implements IMonitorService {
|
|||||||
else if (osName.toLowerCase().startsWith("mac"))
|
else if (osName.toLowerCase().startsWith("mac"))
|
||||||
cpuRatio = this.getCpuRatioForMac();
|
cpuRatio = this.getCpuRatioForMac();
|
||||||
else
|
else
|
||||||
cpuRatio = this.getCpuRatioForLinux();
|
cpuRatio = getCpuRatioForLinux();
|
||||||
// 构造返回对象
|
// 构造返回对象
|
||||||
MonitorInfoBean infoBean = new MonitorInfoBean();
|
MonitorInfoBean infoBean = new MonitorInfoBean();
|
||||||
infoBean.setFreeMemory(freeMemory);
|
infoBean.setFreeMemory(freeMemory);
|
||||||
@@ -100,20 +101,22 @@ public class MonitorServiceImpl implements IMonitorService {
|
|||||||
String command = "cat /proc/stat";
|
String command = "cat /proc/stat";
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
pro1 = r.exec(command);
|
pro1 = r.exec(command);
|
||||||
BufferedReader in1 = new BufferedReader(new InputStreamReader(pro1.getInputStream()));
|
String line;
|
||||||
String line = null;
|
long idleCpuTime1, totalCpuTime1; //分别为系统启动后空闲的CPU时间和总的CPU时间
|
||||||
long idleCpuTime1 = 0, totalCpuTime1 = 0; //分别为系统启动后空闲的CPU时间和总的CPU时间
|
try (BufferedReader in1 = new BufferedReader(new InputStreamReader(pro1.getInputStream()))) {
|
||||||
while ((line = in1.readLine()) != null)
|
idleCpuTime1 = 0;
|
||||||
if (line.startsWith("cpu")) {
|
totalCpuTime1 = 0; //分别为系统启动后空闲的CPU时间和总的CPU时间
|
||||||
line = line.trim();
|
while ((line = in1.readLine()) != null)
|
||||||
String[] temp = line.split("\\s+");
|
if (line.startsWith("cpu")) {
|
||||||
idleCpuTime1 = Long.parseLong(temp[4]);
|
line = line.trim();
|
||||||
for (String s : temp)
|
String[] temp = line.split("\\s+");
|
||||||
if (!s.equals("cpu"))
|
idleCpuTime1 = Long.parseLong(temp[4]);
|
||||||
totalCpuTime1 += Long.parseLong(s);
|
for (String s : temp)
|
||||||
break;
|
if (!s.equals("cpu"))
|
||||||
}
|
totalCpuTime1 += Long.parseLong(s);
|
||||||
in1.close();
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
pro1.destroy();
|
pro1.destroy();
|
||||||
try {
|
try {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
@@ -123,21 +126,21 @@ public class MonitorServiceImpl implements IMonitorService {
|
|||||||
//第二次采集CPU时间
|
//第二次采集CPU时间
|
||||||
long endTime = System.currentTimeMillis();
|
long endTime = System.currentTimeMillis();
|
||||||
pro2 = r.exec(command);
|
pro2 = r.exec(command);
|
||||||
BufferedReader in2 = new BufferedReader(new InputStreamReader(pro2.getInputStream()));
|
try (BufferedReader in2 = new BufferedReader(new InputStreamReader(pro2.getInputStream()))) {
|
||||||
long idleCpuTime2 = 0, totalCpuTime2 = 0; //分别为系统启动后空闲的CPU时间和总的CPU时间
|
long idleCpuTime2 = 0, totalCpuTime2 = 0; //分别为系统启动后空闲的CPU时间和总的CPU时间
|
||||||
while ((line = in2.readLine()) != null)
|
while ((line = in2.readLine()) != null)
|
||||||
if (line.startsWith("cpu")) {
|
if (line.startsWith("cpu")) {
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
String[] temp = line.split("\\s+");
|
String[] temp = line.split("\\s+");
|
||||||
idleCpuTime2 = Long.parseLong(temp[4]);
|
idleCpuTime2 = Long.parseLong(temp[4]);
|
||||||
for (String s : temp)
|
for (String s : temp)
|
||||||
if (!s.equals("cpu"))
|
if (!s.equals("cpu"))
|
||||||
totalCpuTime2 += Long.parseLong(s);
|
totalCpuTime2 += Long.parseLong(s);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (idleCpuTime1 != 0 && totalCpuTime1 != 0 && idleCpuTime2 != 0 && totalCpuTime2 != 0)
|
if (idleCpuTime1 != 0 && totalCpuTime1 != 0 && idleCpuTime2 != 0 && totalCpuTime2 != 0)
|
||||||
cpuUsage = 1 - (float) (idleCpuTime2 - idleCpuTime1) / (float) (totalCpuTime2 - totalCpuTime1);
|
cpuUsage = 1 - (float) (idleCpuTime2 - idleCpuTime1) / (float) (totalCpuTime2 - totalCpuTime1);
|
||||||
in2.close();
|
}
|
||||||
pro2.destroy();
|
pro2.destroy();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
HMCLog.err("Failed to catch sysout", e);
|
HMCLog.err("Failed to catch sysout", e);
|
||||||
@@ -174,21 +177,9 @@ public class MonitorServiceImpl implements IMonitorService {
|
|||||||
System.out.println(ioe.getMessage());
|
System.out.println(ioe.getMessage());
|
||||||
return 1;
|
return 1;
|
||||||
} finally {
|
} finally {
|
||||||
freeResource(is, isr, brStat);
|
IOUtils.closeQuietly(is);
|
||||||
}
|
IOUtils.closeQuietly(isr);
|
||||||
}
|
IOUtils.closeQuietly(brStat);
|
||||||
|
|
||||||
private static void freeResource(InputStream is, InputStreamReader isr,
|
|
||||||
BufferedReader br) {
|
|
||||||
try {
|
|
||||||
if (is != null)
|
|
||||||
is.close();
|
|
||||||
if (isr != null)
|
|
||||||
isr.close();
|
|
||||||
if (br != null)
|
|
||||||
br.close();
|
|
||||||
} catch (IOException ioe) {
|
|
||||||
System.out.println(ioe.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,6 +209,14 @@ public class MonitorServiceImpl implements IMonitorService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String substring(String src, int start_idx, int end_idx) {
|
||||||
|
byte[] b = src.getBytes();
|
||||||
|
String tgt = "";
|
||||||
|
for (int i = start_idx; i <= end_idx; i++)
|
||||||
|
tgt += (char) b[i];
|
||||||
|
return tgt;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 读取CPU信息.
|
* 读取CPU信息.
|
||||||
*
|
*
|
||||||
@@ -250,12 +249,12 @@ public class MonitorServiceImpl implements IMonitorService {
|
|||||||
continue;
|
continue;
|
||||||
// 字段出现顺序:Caption,CommandLine,KernelModeTime,ReadOperationCount,
|
// 字段出现顺序:Caption,CommandLine,KernelModeTime,ReadOperationCount,
|
||||||
// ThreadCount,UserModeTime,WriteOperation
|
// ThreadCount,UserModeTime,WriteOperation
|
||||||
String caption = StrUtils.substring(line, capidx, cmdidx - 1).trim();
|
String caption = substring(line, capidx, cmdidx - 1).trim();
|
||||||
String cmd = StrUtils.substring(line, cmdidx, kmtidx - 1).trim();
|
String cmd = substring(line, cmdidx, kmtidx - 1).trim();
|
||||||
if (cmd.contains("wmic.exe"))
|
if (cmd.contains("wmic.exe"))
|
||||||
continue;
|
continue;
|
||||||
String s1 = StrUtils.substring(line, kmtidx, rocidx - 1).trim();
|
String s1 = substring(line, kmtidx, rocidx - 1).trim();
|
||||||
String s2 = StrUtils.substring(line, umtidx, wocidx - 1).trim();
|
String s2 = substring(line, umtidx, wocidx - 1).trim();
|
||||||
if (caption.equals("System Idle Process") || caption.equals("System")) {
|
if (caption.equals("System Idle Process") || caption.equals("System")) {
|
||||||
if (s1.length() > 0)
|
if (s1.length() > 0)
|
||||||
idletime += Long.parseLong(s1);
|
idletime += Long.parseLong(s1);
|
||||||
@@ -274,11 +273,7 @@ public class MonitorServiceImpl implements IMonitorService {
|
|||||||
} catch (IOException | NumberFormatException ex) {
|
} catch (IOException | NumberFormatException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
IOUtils.closeQuietly(proc.getInputStream());
|
||||||
proc.getInputStream().close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import org.jackhuang.hellominecraft.util.func.Consumer;
|
|||||||
*
|
*
|
||||||
* @author huangyuhui
|
* @author huangyuhui
|
||||||
*/
|
*/
|
||||||
public abstract class OverridableSwingWorker<T> extends SwingWorker<Void, T> {
|
public abstract class AbstractSwingWorker<T> extends SwingWorker<Void, T> {
|
||||||
|
|
||||||
List<Consumer<T>> processListeners = new ArrayList<>();
|
List<Consumer<T>> processListeners = new ArrayList<>();
|
||||||
List<Runnable> doneListeners = new ArrayList<>();
|
List<Runnable> doneListeners = new ArrayList<>();
|
||||||
@@ -47,13 +47,13 @@ public abstract class OverridableSwingWorker<T> extends SwingWorker<Void, T> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OverridableSwingWorker reg(Consumer<T> c) {
|
public AbstractSwingWorker reg(Consumer<T> c) {
|
||||||
Objects.requireNonNull(c);
|
Objects.requireNonNull(c);
|
||||||
processListeners.add(c);
|
processListeners.add(c);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OverridableSwingWorker regDone(Runnable c) {
|
public AbstractSwingWorker regDone(Runnable c) {
|
||||||
Objects.requireNonNull(c);
|
Objects.requireNonNull(c);
|
||||||
doneListeners.add(c);
|
doneListeners.add(c);
|
||||||
return this;
|
return this;
|
||||||
@@ -31,7 +31,7 @@ public final class CollectionUtils {
|
|||||||
private CollectionUtils() {
|
private CollectionUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> ArrayList<T> map(Collection<T> coll, Predicate<T> p) {
|
public static <T> ArrayList<T> filter(Collection<T> coll, Predicate<T> p) {
|
||||||
ArrayList<T> newColl = new ArrayList<>();
|
ArrayList<T> newColl = new ArrayList<>();
|
||||||
for (T t : coll)
|
for (T t : coll)
|
||||||
if (p.apply(t))
|
if (p.apply(t))
|
||||||
|
|||||||
@@ -26,47 +26,47 @@ import java.io.OutputStream;
|
|||||||
*/
|
*/
|
||||||
public class DoubleOutputStream extends OutputStream {
|
public class DoubleOutputStream extends OutputStream {
|
||||||
|
|
||||||
private OutputStream a = null;
|
private OutputStream os1 = null;
|
||||||
private OutputStream b = null;
|
private OutputStream os2 = null;
|
||||||
private boolean c = true;
|
private boolean autoFlush = true;
|
||||||
|
|
||||||
public DoubleOutputStream(OutputStream paramOutputStream1, OutputStream paramOutputStream2) {
|
public DoubleOutputStream(OutputStream os1, OutputStream os2) {
|
||||||
this(paramOutputStream1, paramOutputStream2, true);
|
this(os1, os2, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DoubleOutputStream(OutputStream paramOutputStream1, OutputStream paramOutputStream2, boolean paramBoolean) {
|
private DoubleOutputStream(OutputStream os1, OutputStream os2, boolean autoFlush) {
|
||||||
this.a = paramOutputStream1;
|
this.os1 = os1;
|
||||||
this.b = paramOutputStream2;
|
this.os2 = os2;
|
||||||
this.c = true;
|
this.autoFlush = autoFlush;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void write(byte[] arr, int off, int len) throws IOException {
|
public final void write(byte[] arr, int off, int len) throws IOException {
|
||||||
if (this.a != null)
|
if (this.os1 != null)
|
||||||
this.a.write(arr, off, len);
|
this.os1.write(arr, off, len);
|
||||||
if (this.b != null)
|
if (this.os2 != null)
|
||||||
this.b.write(arr, off, len);
|
this.os2.write(arr, off, len);
|
||||||
if (this.c)
|
if (this.autoFlush)
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void write(byte[] arr) throws IOException {
|
public final void write(byte[] arr) throws IOException {
|
||||||
if (this.a != null)
|
if (this.os1 != null)
|
||||||
this.a.write(arr);
|
this.os1.write(arr);
|
||||||
if (this.b != null)
|
if (this.os2 != null)
|
||||||
this.b.write(arr);
|
this.os2.write(arr);
|
||||||
if (this.c)
|
if (this.autoFlush)
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void write(int i) throws IOException {
|
public final void write(int i) throws IOException {
|
||||||
if (this.a != null)
|
if (this.os1 != null)
|
||||||
this.a.write(i);
|
this.os1.write(i);
|
||||||
if (this.b != null)
|
if (this.os2 != null)
|
||||||
this.b.write(i);
|
this.os2.write(i);
|
||||||
if (this.c)
|
if (this.autoFlush)
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,17 +74,17 @@ public class DoubleOutputStream extends OutputStream {
|
|||||||
public final void close() throws IOException {
|
public final void close() throws IOException {
|
||||||
flush();
|
flush();
|
||||||
|
|
||||||
if (this.a != null)
|
if (this.os1 != null)
|
||||||
this.a.close();
|
this.os1.close();
|
||||||
if (this.b != null)
|
if (this.os2 != null)
|
||||||
this.b.close();
|
this.os2.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void flush() throws IOException {
|
public final void flush() throws IOException {
|
||||||
if (this.a != null)
|
if (this.os1 != null)
|
||||||
this.a.flush();
|
this.os1.flush();
|
||||||
if (this.b != null)
|
if (this.os2 != null)
|
||||||
this.b.flush();
|
this.os2.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,13 +49,13 @@ public interface IUpdateChecker {
|
|||||||
*
|
*
|
||||||
* @return the process observable.
|
* @return the process observable.
|
||||||
*/
|
*/
|
||||||
OverridableSwingWorker<VersionNumber> process(boolean showMessage);
|
AbstractSwingWorker<VersionNumber> process(boolean showMessage);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the download links.
|
* Get the download links.
|
||||||
*
|
*
|
||||||
* @return a JSON, which contains the server response.
|
* @return a JSON, which contains the server response.
|
||||||
*/
|
*/
|
||||||
OverridableSwingWorker<Map<String, String>> requestDownloadLink();
|
AbstractSwingWorker<Map<String, String>> requestDownloadLink();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public class MinecraftVersionRequest implements Serializable {
|
|||||||
|
|
||||||
private static MinecraftVersionRequest getVersionOfOldMinecraft(ZipFile file, ZipEntry entry) throws IOException {
|
private static MinecraftVersionRequest getVersionOfOldMinecraft(ZipFile file, ZipEntry entry) throws IOException {
|
||||||
MinecraftVersionRequest r = new MinecraftVersionRequest();
|
MinecraftVersionRequest r = new MinecraftVersionRequest();
|
||||||
byte[] tmp = IOUtils.getBytesFromStream(file.getInputStream(entry));
|
byte[] tmp = IOUtils.readFully(file.getInputStream(entry)).toByteArray();
|
||||||
|
|
||||||
byte[] bytes = "Minecraft Minecraft ".getBytes("ASCII");
|
byte[] bytes = "Minecraft Minecraft ".getBytes("ASCII");
|
||||||
int j = ArrayUtils.matchArray(tmp, bytes);
|
int j = ArrayUtils.matchArray(tmp, bytes);
|
||||||
@@ -92,7 +92,7 @@ public class MinecraftVersionRequest implements Serializable {
|
|||||||
|
|
||||||
private static MinecraftVersionRequest getVersionOfNewMinecraft(ZipFile file, ZipEntry entry) throws IOException {
|
private static MinecraftVersionRequest getVersionOfNewMinecraft(ZipFile file, ZipEntry entry) throws IOException {
|
||||||
MinecraftVersionRequest r = new MinecraftVersionRequest();
|
MinecraftVersionRequest r = new MinecraftVersionRequest();
|
||||||
byte[] tmp = IOUtils.getBytesFromStream(file.getInputStream(entry));
|
byte[] tmp = IOUtils.readFully(file.getInputStream(entry)).toByteArray();
|
||||||
|
|
||||||
byte[] str = "-server.txt".getBytes("ASCII");
|
byte[] str = "-server.txt".getBytes("ASCII");
|
||||||
int j = ArrayUtils.matchArray(tmp, str);
|
int j = ArrayUtils.matchArray(tmp, str);
|
||||||
@@ -175,12 +175,7 @@ public class MinecraftVersionRequest implements Serializable {
|
|||||||
r.type = MinecraftVersionRequest.INVALID_JAR;
|
r.type = MinecraftVersionRequest.INVALID_JAR;
|
||||||
return r;
|
return r;
|
||||||
} finally {
|
} finally {
|
||||||
if (f != null)
|
IOUtils.closeQuietly(f);
|
||||||
try {
|
|
||||||
f.close();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
HMCLog.warn("Failed to close zip file", ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import java.net.MalformedURLException;
|
|||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import org.jackhuang.hellominecraft.util.code.Charsets;
|
||||||
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
import org.jackhuang.hellominecraft.util.system.IOUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,8 +38,18 @@ public final class NetUtils {
|
|||||||
private NetUtils() {
|
private NetUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static HttpURLConnection createConnection(URL url, Proxy proxy) throws IOException {
|
||||||
|
HttpURLConnection con = (HttpURLConnection) url.openConnection(proxy);
|
||||||
|
con.setDoOutput(true);
|
||||||
|
con.setDoInput(true);
|
||||||
|
con.setUseCaches(false);
|
||||||
|
con.setConnectTimeout(15000);
|
||||||
|
con.setReadTimeout(15000);
|
||||||
|
return con;
|
||||||
|
}
|
||||||
|
|
||||||
public static String get(String url, String encoding) throws IOException {
|
public static String get(String url, String encoding) throws IOException {
|
||||||
return IOUtils.getStreamContent(new URL(url).openConnection().getInputStream());
|
return IOUtils.toString(new URL(url).openConnection().getInputStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String get(String url) throws IOException {
|
public static String get(String url) throws IOException {
|
||||||
@@ -50,7 +61,7 @@ public final class NetUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String get(URL url, Proxy proxy) throws IOException {
|
public static String get(URL url, Proxy proxy) throws IOException {
|
||||||
return IOUtils.getStreamContent(url.openConnection(proxy).getInputStream());
|
return readData(createConnection(url, proxy));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String post(URL u, Map<String, String> params) throws IOException {
|
public static String post(URL u, Map<String, String> params) throws IOException {
|
||||||
@@ -72,17 +83,13 @@ public final class NetUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String post(URL u, String post, String contentType, Proxy proxy) throws IOException {
|
public static String post(URL u, String post, String contentType, Proxy proxy) throws IOException {
|
||||||
HttpURLConnection con = (HttpURLConnection) u.openConnection(proxy);
|
byte[] bytes = post.getBytes(Charsets.UTF_8);
|
||||||
|
|
||||||
|
HttpURLConnection con = createConnection(u, proxy);
|
||||||
con.setRequestMethod("POST");
|
con.setRequestMethod("POST");
|
||||||
con.setDoOutput(true);
|
con.setDoOutput(true);
|
||||||
con.setDoInput(true);
|
|
||||||
con.setUseCaches(false);
|
|
||||||
con.setConnectTimeout(30000);
|
|
||||||
con.setReadTimeout(30000);
|
|
||||||
con.setRequestProperty("Content-Type", contentType + "; charset=utf-8");
|
con.setRequestProperty("Content-Type", contentType + "; charset=utf-8");
|
||||||
byte[] bytes = post.getBytes(IOUtils.DEFAULT_CHARSET);
|
|
||||||
con.setRequestProperty("Content-Length", "" + bytes.length);
|
con.setRequestProperty("Content-Length", "" + bytes.length);
|
||||||
con.connect();
|
|
||||||
OutputStream os = null;
|
OutputStream os = null;
|
||||||
try {
|
try {
|
||||||
os = con.getOutputStream();
|
os = con.getOutputStream();
|
||||||
@@ -90,20 +97,23 @@ public final class NetUtils {
|
|||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(os);
|
IOUtils.closeQuietly(os);
|
||||||
}
|
}
|
||||||
|
return readData(con);
|
||||||
|
}
|
||||||
|
|
||||||
String result;
|
private static String readData(HttpURLConnection con) throws IOException {
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
try {
|
try {
|
||||||
is = con.getInputStream();
|
is = con.getInputStream();
|
||||||
result = IOUtils.getStreamContent(is);
|
return IOUtils.toString(is, Charsets.UTF_8);
|
||||||
} catch (IOException ex) {
|
} catch (IOException e) {
|
||||||
IOUtils.closeQuietly(is);
|
IOUtils.closeQuietly(is);
|
||||||
is = con.getErrorStream();
|
is = con.getErrorStream();
|
||||||
result = IOUtils.getStreamContent(is);
|
if (is != null)
|
||||||
|
return IOUtils.toString(is, Charsets.UTF_8);
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
IOUtils.closeQuietly(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
con.disconnect();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static URL constantURL(String url) {
|
public static URL constantURL(String url) {
|
||||||
@@ -117,9 +127,7 @@ 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)
|
return new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile() + (url.getQuery() != null && url.getQuery().length() > 0 ? '&' : '?') + query);
|
||||||
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) {
|
} 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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,14 +37,6 @@ public final class StrUtils {
|
|||||||
private StrUtils() {
|
private StrUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String substring(String src, int start_idx, int end_idx) {
|
|
||||||
byte[] b = src.getBytes();
|
|
||||||
String tgt = "";
|
|
||||||
for (int i = start_idx; i <= end_idx; i++)
|
|
||||||
tgt += (char) b[i];
|
|
||||||
return tgt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String makeCommand(List<String> cmd) {
|
public static String makeCommand(List<String> cmd) {
|
||||||
StringBuilder cmdbuf = new StringBuilder(120);
|
StringBuilder cmdbuf = new StringBuilder(120);
|
||||||
for (int i = 0; i < cmd.size(); i++) {
|
for (int i = 0; i < cmd.size(); i++) {
|
||||||
@@ -189,7 +181,7 @@ public final class StrUtils {
|
|||||||
|
|
||||||
public static boolean equals(String base, String to) {
|
public static boolean equals(String base, String to) {
|
||||||
if (base == null)
|
if (base == null)
|
||||||
return (to == null);
|
return to == null;
|
||||||
else
|
else
|
||||||
return base.equals(to);
|
return base.equals(to);
|
||||||
}
|
}
|
||||||
@@ -220,15 +212,6 @@ public final class StrUtils {
|
|||||||
return (String[]) localArrayList.toArray(new String[localArrayList.size()]);
|
return (String[]) localArrayList.toArray(new String[localArrayList.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String trimExtension(String filename) {
|
|
||||||
if ((filename != null) && (filename.length() > 0)) {
|
|
||||||
int i = filename.lastIndexOf('.');
|
|
||||||
if ((i > -1) && (i < (filename.length())))
|
|
||||||
return filename.substring(0, i);
|
|
||||||
}
|
|
||||||
return filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isBlank(String s) {
|
public static boolean isBlank(String s) {
|
||||||
return s == null || s.trim().length() <= 0;
|
return s == null || s.trim().length() <= 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public final class UpdateChecker implements IUpdateChecker {
|
public final class UpdateChecker implements IUpdateChecker {
|
||||||
|
|
||||||
public boolean OUT_DATED = false;
|
private volatile boolean outOfDate = false;
|
||||||
public VersionNumber base;
|
public VersionNumber base;
|
||||||
public String versionString;
|
public String versionString;
|
||||||
public String type;
|
public String type;
|
||||||
@@ -41,9 +41,13 @@ public final class UpdateChecker implements IUpdateChecker {
|
|||||||
|
|
||||||
VersionNumber value;
|
VersionNumber value;
|
||||||
|
|
||||||
|
public boolean isOutOfDate() {
|
||||||
|
return outOfDate;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OverridableSwingWorker<VersionNumber> process(final boolean showMessage) {
|
public AbstractSwingWorker<VersionNumber> process(final boolean showMessage) {
|
||||||
return new OverridableSwingWorker() {
|
return new AbstractSwingWorker() {
|
||||||
@Override
|
@Override
|
||||||
protected void work() throws Exception {
|
protected void work() throws Exception {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
@@ -56,8 +60,8 @@ public final class UpdateChecker implements IUpdateChecker {
|
|||||||
if (showMessage)
|
if (showMessage)
|
||||||
MessageBox.show(C.i18n("update.failed"));
|
MessageBox.show(C.i18n("update.failed"));
|
||||||
} else if (VersionNumber.isOlder(base, value))
|
} else if (VersionNumber.isOlder(base, value))
|
||||||
OUT_DATED = true;
|
outOfDate = true;
|
||||||
if (OUT_DATED)
|
if (outOfDate)
|
||||||
publish(value);
|
publish(value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -69,8 +73,8 @@ public final class UpdateChecker implements IUpdateChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized OverridableSwingWorker<Map<String, String>> requestDownloadLink() {
|
public synchronized AbstractSwingWorker<Map<String, String>> requestDownloadLink() {
|
||||||
return new OverridableSwingWorker() {
|
return new AbstractSwingWorker() {
|
||||||
@Override
|
@Override
|
||||||
protected void work() throws Exception {
|
protected void work() throws Exception {
|
||||||
if (download_link == null)
|
if (download_link == null)
|
||||||
@@ -84,11 +88,11 @@ public final class UpdateChecker implements IUpdateChecker {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public final EventHandler<VersionNumber> outdated = new EventHandler<>(this);
|
public final EventHandler<VersionNumber> outOfDateEvent = new EventHandler<>(this);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void checkOutdate() {
|
public void checkOutdate() {
|
||||||
if (OUT_DATED)
|
if (outOfDate)
|
||||||
outdated.execute(getNewVersion());
|
outOfDateEvent.execute(getNewVersion());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,12 +37,16 @@ public final class Localization {
|
|||||||
|
|
||||||
private final Map<String, String> lang;
|
private final Map<String, String> lang;
|
||||||
|
|
||||||
|
private static InputStream getStream(String id) {
|
||||||
|
return Localization.class.getResourceAsStream(String.format(ROOT_LOCATION, id));
|
||||||
|
}
|
||||||
|
|
||||||
private Localization(Locale locale) {
|
private Localization(Locale locale) {
|
||||||
InputStream is = Localization.class.getResourceAsStream(String.format(ROOT_LOCATION, "_" + locale.getLanguage() + "_" + locale.getCountry()));
|
InputStream is = getStream("_" + locale.getLanguage() + "_" + locale.getCountry());
|
||||||
if (is == null)
|
if (is == null)
|
||||||
is = Localization.class.getResourceAsStream(String.format(ROOT_LOCATION, "_" + locale.getLanguage()));
|
is = getStream("_" + locale.getLanguage());
|
||||||
if (is == null)
|
if (is == null)
|
||||||
is = Localization.class.getResourceAsStream(String.format(ROOT_LOCATION, ""));
|
is = getStream("");
|
||||||
if (is == null)
|
if (is == null)
|
||||||
throw new RuntimeException("LANG FILE MISSING");
|
throw new RuntimeException("LANG FILE MISSING");
|
||||||
|
|
||||||
|
|||||||
@@ -195,12 +195,12 @@ public final class FileUtils {
|
|||||||
|
|
||||||
public static String read(File file)
|
public static String read(File file)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
return IOUtils.getStreamContent(IOUtils.openInputStream(file));
|
return IOUtils.toString(IOUtils.openInputStream(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String readQuietly(File file) {
|
public static String readQuietly(File file) {
|
||||||
try {
|
try {
|
||||||
return IOUtils.getStreamContent(IOUtils.openInputStream(file));
|
return IOUtils.toString(IOUtils.openInputStream(file));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
HMCLog.err("Failed to read file: " + file, ex);
|
HMCLog.err("Failed to read file: " + file, ex);
|
||||||
return null;
|
return null;
|
||||||
@@ -209,12 +209,12 @@ public final class FileUtils {
|
|||||||
|
|
||||||
public static String read(File file, String charset)
|
public static String read(File file, String charset)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
return IOUtils.getStreamContent(IOUtils.openInputStream(file), charset);
|
return IOUtils.toString(IOUtils.openInputStream(file), charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String readIgnoreFileNotFound(File file) throws IOException {
|
public static String readIgnoreFileNotFound(File file) throws IOException {
|
||||||
try {
|
try {
|
||||||
return IOUtils.getStreamContent(IOUtils.openInputStream(file));
|
return IOUtils.toString(IOUtils.openInputStream(file));
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (FileNotFoundException ex) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -263,14 +263,6 @@ public final class FileUtils {
|
|||||||
return Math.max(lastUnixPos, lastWindowsPos);
|
return Math.max(lastUnixPos, lastWindowsPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int indexOfExtension(String filename) {
|
|
||||||
if (filename == null)
|
|
||||||
return -1;
|
|
||||||
int extensionPos = filename.lastIndexOf(46);
|
|
||||||
int lastSeparator = indexOfLastSeparator(filename);
|
|
||||||
return lastSeparator > extensionPos ? -1 : extensionPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getName(String filename) {
|
public static String getName(String filename) {
|
||||||
if (filename == null)
|
if (filename == null)
|
||||||
return null;
|
return null;
|
||||||
@@ -289,6 +281,14 @@ public final class FileUtils {
|
|||||||
return removeExtension(getName(filename));
|
return removeExtension(getName(filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int indexOfExtension(String filename) {
|
||||||
|
if (filename == null)
|
||||||
|
return -1;
|
||||||
|
int extensionPos = filename.lastIndexOf(46);
|
||||||
|
int lastSeparator = indexOfLastSeparator(filename);
|
||||||
|
return lastSeparator > extensionPos ? -1 : extensionPos;
|
||||||
|
}
|
||||||
|
|
||||||
public static String getExtension(String filename) {
|
public static String getExtension(String filename) {
|
||||||
if (filename == null)
|
if (filename == null)
|
||||||
return null;
|
return null;
|
||||||
@@ -333,7 +333,6 @@ public final class FileUtils {
|
|||||||
try {
|
try {
|
||||||
out = openOutputStream(file, append);
|
out = openOutputStream(file, append);
|
||||||
IOUtils.write(data, out, encoding);
|
IOUtils.write(data, out, encoding);
|
||||||
out.close();
|
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(out);
|
IOUtils.closeQuietly(out);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -203,6 +203,22 @@ public final class IOUtils {
|
|||||||
return entryBuffer;
|
return entryBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte[] toByteArray(InputStream stream) throws IOException {
|
||||||
|
return readFully(stream).toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String toString(InputStream is) throws IOException {
|
||||||
|
return readFully(is).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String toString(InputStream is, String charset) throws IOException {
|
||||||
|
return readFully(is).toString(charset);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String toString(InputStream is, Charset charset) throws IOException {
|
||||||
|
return readFully(is).toString(charset.name());
|
||||||
|
}
|
||||||
|
|
||||||
public static void closeQuietly(Closeable closeable) {
|
public static void closeQuietly(Closeable closeable) {
|
||||||
try {
|
try {
|
||||||
if (closeable != null)
|
if (closeable != null)
|
||||||
@@ -302,31 +318,6 @@ public final class IOUtils {
|
|||||||
output.write(buf, 0, length);
|
output.write(buf, 0, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] getBytesFromStream(InputStream is) throws IOException {
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
||||||
IOUtils.copyStream(is, out);
|
|
||||||
is.close();
|
|
||||||
return out.toByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getStreamContent(InputStream is) throws IOException {
|
|
||||||
return getStreamContent(is, DEFAULT_CHARSET);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getStreamContent(InputStream is, String encoding)
|
|
||||||
throws IOException {
|
|
||||||
if (is == null)
|
|
||||||
return null;
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
try (InputStreamReader br = new InputStreamReader(is, encoding)) {
|
|
||||||
int len;
|
|
||||||
char[] buf = new char[16384];
|
|
||||||
while ((len = br.read(buf)) != -1)
|
|
||||||
sb.append(buf, 0, len);
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final String DEFAULT_CHARSET = "UTF-8";
|
public static final String DEFAULT_CHARSET = "UTF-8";
|
||||||
|
|
||||||
public static PrintStream createPrintStream(OutputStream out, Charset charset) {
|
public static PrintStream createPrintStream(OutputStream out, Charset charset) {
|
||||||
|
|||||||
@@ -78,9 +78,8 @@ public class JavaProcessMonitor {
|
|||||||
al.add(a);
|
al.add(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
void processThreadStopped(ProcessThread t, boolean forceTermintate) {
|
void processThreadStopped(ProcessThread t1, boolean forceTermintate) {
|
||||||
al.remove(t);
|
CollectionUtils.removeIf(al, t -> t == t1 || !t.isAlive());
|
||||||
al.removeAll(CollectionUtils.map(al, t1 -> !t1.isAlive()));
|
|
||||||
if (al.isEmpty() || forceTermintate) {
|
if (al.isEmpty() || forceTermintate) {
|
||||||
for (Thread a : al)
|
for (Thread a : al)
|
||||||
a.interrupt();
|
a.interrupt();
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hellominecraft.util.system;
|
package org.jackhuang.hellominecraft.util.system;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
@@ -46,35 +47,29 @@ public class ProcessThread extends Thread {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
setName("ProcessMonitor");
|
setName("ProcessMonitor");
|
||||||
InputStreamReader br = null;
|
BufferedReader br = null;
|
||||||
try {
|
try {
|
||||||
InputStream in = p.getRawProcess().getInputStream();
|
InputStream in = p.getRawProcess().getInputStream();
|
||||||
try {
|
try {
|
||||||
br = new InputStreamReader(in, System.getProperty("sun.jnu.encoding", "UTF-8"));
|
br = new BufferedReader(new InputStreamReader(in, System.getProperty("sun.jnu.encoding", "UTF-8")));
|
||||||
} catch (UnsupportedEncodingException ex) {
|
} catch (UnsupportedEncodingException ex) {
|
||||||
HMCLog.warn("Unsupported encoding: " + System.getProperty("sun.jnu.encoding", "UTF-8"), ex);
|
HMCLog.warn("Unsupported encoding: " + System.getProperty("sun.jnu.encoding", "UTF-8"), ex);
|
||||||
br = new InputStreamReader(in);
|
br = new BufferedReader(new InputStreamReader(in));
|
||||||
}
|
}
|
||||||
|
|
||||||
int ch;
|
int ch;
|
||||||
String line = "";
|
String line = "";
|
||||||
while (p.isRunning())
|
while (p.isRunning())
|
||||||
while ((ch = br.read()) != -1)
|
while ((line = br.readLine()) != null) {
|
||||||
if (ch == '\n') {
|
|
||||||
printlnEvent.execute(line);
|
|
||||||
System.out.println("Minecraft: " + line);
|
|
||||||
p.getStdOutLines().add(line);
|
|
||||||
line = "";
|
|
||||||
} else
|
|
||||||
line += (char) ch;
|
|
||||||
while ((ch = br.read()) != -1)
|
|
||||||
if (ch == '\n') {
|
|
||||||
printlnEvent.execute(line);
|
printlnEvent.execute(line);
|
||||||
System.out.println("Minecraft: " + line);
|
System.out.println("Minecraft: " + line);
|
||||||
p.getStdOutLines().add(line);
|
p.getStdOutLines().add(line);
|
||||||
line = "";
|
}
|
||||||
} else
|
while ((line = br.readLine()) != null) {
|
||||||
line += (char) ch;
|
printlnEvent.execute(line);
|
||||||
|
System.out.println("Minecraft: " + line);
|
||||||
|
p.getStdOutLines().add(line);
|
||||||
|
}
|
||||||
stopEvent.execute(p);
|
stopEvent.execute(p);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
HMCLog.err("An error occured when reading process stdout/stderr.", e);
|
HMCLog.err("An error occured when reading process stdout/stderr.", e);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package org.jackhuang.hellominecraft.util.system;
|
|||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.Closeable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@@ -34,7 +35,7 @@ import org.jackhuang.hellominecraft.util.func.BiFunction;
|
|||||||
*
|
*
|
||||||
* @author huangyuhui
|
* @author huangyuhui
|
||||||
*/
|
*/
|
||||||
public class ZipEngine {
|
public class ZipEngine implements Closeable {
|
||||||
|
|
||||||
byte[] buf = new byte[1024];
|
byte[] buf = new byte[1024];
|
||||||
ZipOutputStream zos;
|
ZipOutputStream zos;
|
||||||
@@ -44,7 +45,8 @@ public class ZipEngine {
|
|||||||
zos = new ZipOutputStream(new BufferedOutputStream(os));
|
zos = new ZipOutputStream(new BufferedOutputStream(os));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeFile() throws IOException {
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
zos.closeEntry();
|
zos.closeEntry();
|
||||||
zos.close();
|
zos.close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ public class DoubleTask extends TaskInfo {
|
|||||||
super(info);
|
super(info);
|
||||||
this.a = a;
|
this.a = a;
|
||||||
this.b = b;
|
this.b = b;
|
||||||
|
hidden = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ public class ParallelTask extends Task {
|
|||||||
|
|
||||||
Collection<Task> dependsTask = new HashSet<>();
|
Collection<Task> dependsTask = new HashSet<>();
|
||||||
|
|
||||||
|
public ParallelTask() {
|
||||||
|
hidden = true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executeTask(boolean areDependTasksSucceeded) {
|
public void executeTask(boolean areDependTasksSucceeded) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,12 @@ public abstract class Task {
|
|||||||
return aborted;
|
return aborted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean hidden = false;
|
||||||
|
|
||||||
|
public boolean isHidden() {
|
||||||
|
return hidden;
|
||||||
|
}
|
||||||
|
|
||||||
public Throwable getFailReason() {
|
public Throwable getFailReason() {
|
||||||
return failReason;
|
return failReason;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ public class TaskWindow extends javax.swing.JDialog
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDoing(Task task, Collection<Task> taskCollection) {
|
public void onDoing(Task task, Collection<Task> taskCollection) {
|
||||||
if (task == null)
|
if (task == null || task.isHidden())
|
||||||
return;
|
return;
|
||||||
task.setProgressProviderListener(this);
|
task.setProgressProviderListener(this);
|
||||||
|
|
||||||
@@ -238,8 +238,10 @@ public class TaskWindow extends javax.swing.JDialog
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDone(Task task, Collection<Task> taskCollection) {
|
public void onDone(Task task, Collection<Task> taskCollection) {
|
||||||
|
if (task == null || task.isHidden())
|
||||||
|
return;
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
if (taskList == null || task == null)
|
if (taskList == null)
|
||||||
return;
|
return;
|
||||||
pgsTotal.setMaximum(taskList.taskCount());
|
pgsTotal.setMaximum(taskList.taskCount());
|
||||||
pgsTotal.setValue(pgsTotal.getValue() + 1);
|
pgsTotal.setValue(pgsTotal.getValue() + 1);
|
||||||
@@ -254,8 +256,10 @@ public class TaskWindow extends javax.swing.JDialog
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailed(Task task) {
|
public void onFailed(Task task) {
|
||||||
|
if (task == null || task.isHidden())
|
||||||
|
return;
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
if (taskList == null || task == null)
|
if (taskList == null)
|
||||||
return;
|
return;
|
||||||
String msg = null;
|
String msg = null;
|
||||||
if (task.getFailReason() != null && !(task.getFailReason() instanceof NoShownTaskException))
|
if (task.getFailReason() != null && !(task.getFailReason() instanceof NoShownTaskException))
|
||||||
@@ -283,13 +287,14 @@ public class TaskWindow extends javax.swing.JDialog
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setStatus(Task task, String sta) {
|
public void setStatus(Task task, String sta) {
|
||||||
|
if (task == null || task.isHidden())
|
||||||
|
return;
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
if (taskList == null || task == null)
|
if (taskList == null)
|
||||||
return;
|
return;
|
||||||
int idx = tasks.indexOf(task);
|
int idx = tasks.indexOf(task);
|
||||||
if (idx == -1)
|
if (idx != -1)
|
||||||
return;
|
SwingUtils.setValueAt(lstDownload, task.getInfo() + ": " + sta, idx, 0);
|
||||||
SwingUtils.setValueAt(lstDownload, task.getInfo() + ": " + sta, idx, 0);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,23 +92,10 @@ public class FileDownloadTask extends Task implements PreviousResult<File>, Prev
|
|||||||
boolean shouldContinue = true;
|
boolean shouldContinue = true;
|
||||||
|
|
||||||
private void closeFiles() {
|
private void closeFiles() {
|
||||||
// Close file.
|
IOUtils.closeQuietly(file);
|
||||||
if (file != null)
|
file = null;
|
||||||
try {
|
IOUtils.closeQuietly(stream);
|
||||||
file.close();
|
stream = null;
|
||||||
file = null;
|
|
||||||
} catch (IOException e) {
|
|
||||||
HMCLog.warn("Failed to close file", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close connection to server.
|
|
||||||
if (stream != null)
|
|
||||||
try {
|
|
||||||
stream.close();
|
|
||||||
stream = null;
|
|
||||||
} catch (IOException e) {
|
|
||||||
HMCLog.warn("Failed to close stream", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download file.
|
// Download file.
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ message.error=错误
|
|||||||
message.cannot_open_explorer=无法打开文件管理器:
|
message.cannot_open_explorer=无法打开文件管理器:
|
||||||
message.cancelled=已取消
|
message.cancelled=已取消
|
||||||
message.info=提示
|
message.info=提示
|
||||||
|
message.loading=加载中...
|
||||||
|
|
||||||
folder.game=游戏文件夹
|
folder.game=游戏文件夹
|
||||||
folder.mod=MOD文件夹
|
folder.mod=MOD文件夹
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ message.error=\u9519\u8bef
|
|||||||
message.cannot_open_explorer=\u65e0\u6cd5\u6253\u5f00\u6587\u4ef6\u7ba1\u7406\u5668:
|
message.cannot_open_explorer=\u65e0\u6cd5\u6253\u5f00\u6587\u4ef6\u7ba1\u7406\u5668:
|
||||||
message.cancelled=\u5df2\u53d6\u6d88
|
message.cancelled=\u5df2\u53d6\u6d88
|
||||||
message.info=\u63d0\u793a
|
message.info=\u63d0\u793a
|
||||||
|
message.loading=\u52a0\u8f7d\u4e2d...
|
||||||
|
|
||||||
folder.game=\u6e38\u620f\u6587\u4ef6\u5939
|
folder.game=\u6e38\u620f\u6587\u4ef6\u5939
|
||||||
folder.mod=MOD\u6587\u4ef6\u5939
|
folder.mod=MOD\u6587\u4ef6\u5939
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ message.error=Error
|
|||||||
message.cannot_open_explorer=Cannot open explorer:
|
message.cannot_open_explorer=Cannot open explorer:
|
||||||
message.cancelled=Cancelled
|
message.cancelled=Cancelled
|
||||||
message.info=Info
|
message.info=Info
|
||||||
|
message.loading=Loading...
|
||||||
|
|
||||||
folder.game=Game Dir
|
folder.game=Game Dir
|
||||||
folder.mod=Mod
|
folder.mod=Mod
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ message.error=Error
|
|||||||
message.cannot_open_explorer=Cannot open explorer:
|
message.cannot_open_explorer=Cannot open explorer:
|
||||||
message.cancelled=Cancelled
|
message.cancelled=Cancelled
|
||||||
message.info=Info
|
message.info=Info
|
||||||
|
message.loading=Loading...
|
||||||
|
|
||||||
folder.game=Game Dir
|
folder.game=Game Dir
|
||||||
folder.mod=Mod
|
folder.mod=Mod
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ message.error=錯誤
|
|||||||
message.cannot_open_explorer=無法打開資料管理器:
|
message.cannot_open_explorer=無法打開資料管理器:
|
||||||
message.cancelled=已取消
|
message.cancelled=已取消
|
||||||
message.info=提示
|
message.info=提示
|
||||||
|
message.loading=加載中...
|
||||||
|
|
||||||
folder.game=遊戲資料夾
|
folder.game=遊戲資料夾
|
||||||
folder.mod=MOD資料夾
|
folder.mod=MOD資料夾
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ message.error=\u932f\u8aa4
|
|||||||
message.cannot_open_explorer=\u7121\u6cd5\u6253\u958b\u8cc7\u6599\u7ba1\u7406\u5668:
|
message.cannot_open_explorer=\u7121\u6cd5\u6253\u958b\u8cc7\u6599\u7ba1\u7406\u5668:
|
||||||
message.cancelled=\u5df2\u53d6\u6d88
|
message.cancelled=\u5df2\u53d6\u6d88
|
||||||
message.info=\u63d0\u793a
|
message.info=\u63d0\u793a
|
||||||
|
message.loading=\u52a0\u8f09\u4e2d...
|
||||||
|
|
||||||
folder.game=\u904a\u6232\u8cc7\u6599\u593e
|
folder.game=\u904a\u6232\u8cc7\u6599\u593e
|
||||||
folder.mod=MOD\u8cc7\u6599\u593e
|
folder.mod=MOD\u8cc7\u6599\u593e
|
||||||
|
|||||||
Reference in New Issue
Block a user