Removed AssetsMojangOldLoader.java
This commit is contained in:
@@ -38,6 +38,7 @@ import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
|||||||
import org.jackhuang.hellominecraft.tasks.TaskWindow;
|
import org.jackhuang.hellominecraft.tasks.TaskWindow;
|
||||||
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
||||||
import org.jackhuang.hellominecraft.utils.MessageBox;
|
import org.jackhuang.hellominecraft.utils.MessageBox;
|
||||||
|
import rx.concurrency.Schedulers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -79,10 +80,10 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
|
|||||||
|
|
||||||
if (!checkAssetsExist())
|
if (!checkAssetsExist())
|
||||||
if (MessageBox.Show(C.i18n("assets.no_assets"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
|
if (MessageBox.Show(C.i18n("assets.no_assets"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
|
||||||
IAssetsHandler.ASSETS_HANDLER.getList(version, provider, (value) -> {
|
IAssetsHandler.ASSETS_HANDLER.getList(version, provider)
|
||||||
if (value != null)
|
.subscribeOn(Schedulers.newThread())
|
||||||
TaskWindow.getInstance().addTask(IAssetsHandler.ASSETS_HANDLER.getDownloadTask(dt.getProvider())).start();
|
.observeOn(Schedulers.eventQueue())
|
||||||
});
|
.subscribe((value) -> TaskWindow.getInstance().addTask(IAssetsHandler.ASSETS_HANDLER.getDownloadTask(dt.getProvider())).start());
|
||||||
|
|
||||||
String game_assets = reconstructAssets().getAbsolutePath();
|
String game_assets = reconstructAssets().getAbsolutePath();
|
||||||
|
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ public final class Profile {
|
|||||||
|
|
||||||
public void setSelectedMinecraftVersion(String selectedMinecraftVersion) {
|
public void setSelectedMinecraftVersion(String selectedMinecraftVersion) {
|
||||||
this.selectedMinecraftVersion = selectedMinecraftVersion;
|
this.selectedMinecraftVersion = selectedMinecraftVersion;
|
||||||
|
Settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getGameDir() {
|
public String getGameDir() {
|
||||||
|
|||||||
@@ -1,102 +0,0 @@
|
|||||||
/*
|
|
||||||
* Hello Minecraft! Launcher.
|
|
||||||
* Copyright (C) 2013 huangyuhui
|
|
||||||
*
|
|
||||||
* 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.launcher.utils.assets;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
|
||||||
import org.jackhuang.hellominecraft.HMCLog;
|
|
||||||
import org.jackhuang.hellominecraft.utils.EventHandler;
|
|
||||||
import org.jackhuang.hellominecraft.utils.MathUtils;
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author huangyuhui
|
|
||||||
*/
|
|
||||||
public class AssetsLoader extends Thread {
|
|
||||||
|
|
||||||
Document doc;
|
|
||||||
Element root;
|
|
||||||
NodeList nodes;
|
|
||||||
public String uri;
|
|
||||||
ArrayList<Contents> al;
|
|
||||||
public final EventHandler<Throwable> failedEvent = new EventHandler<>(this);
|
|
||||||
public final EventHandler<List<Contents>> successEvent = new EventHandler<>(this);
|
|
||||||
|
|
||||||
AssetsLoader(String uri) {
|
|
||||||
this.uri = uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Contents modifyContents(NodeList contents) {
|
|
||||||
Contents ret = new Contents();
|
|
||||||
for (int i = 0; i < contents.getLength(); i++) {
|
|
||||||
Node result = contents.item(i);
|
|
||||||
if (result.getNodeType() == Node.ELEMENT_NODE) {
|
|
||||||
if (result.getNodeName().equalsIgnoreCase("Key"))
|
|
||||||
ret.key = result.getTextContent();
|
|
||||||
if (result.getNodeName().equalsIgnoreCase("ETag"))
|
|
||||||
ret.eTag = result.getTextContent();
|
|
||||||
if (result.getNodeName().equalsIgnoreCase("LastModified"))
|
|
||||||
ret.lastModified = result.getTextContent();
|
|
||||||
if (result.getNodeName().equalsIgnoreCase("Size"))
|
|
||||||
ret.size = MathUtils.parseInt(result.getTextContent(), 0);
|
|
||||||
if (result.getNodeName().equalsIgnoreCase("StorageClass"))
|
|
||||||
ret.storageClass = result.getTextContent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Thread.currentThread().setName("AssetsLoader");
|
|
||||||
al = new ArrayList<>();
|
|
||||||
try {
|
|
||||||
HMCLog.log("AssetsLoader - Download begin.");
|
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
|
||||||
DocumentBuilder db = factory.newDocumentBuilder();
|
|
||||||
doc = db.parse(uri);
|
|
||||||
HMCLog.log("AssetsLoader - Download end and format begin.");
|
|
||||||
root = doc.getDocumentElement();
|
|
||||||
nodes = root.getChildNodes();
|
|
||||||
for (int i = 0; i < nodes.getLength(); i++) {
|
|
||||||
Node result = nodes.item(i);
|
|
||||||
if (result.getNodeType() == Node.ELEMENT_NODE && result.getNodeName().equals("Contents")) {
|
|
||||||
Contents c = modifyContents(result.getChildNodes());
|
|
||||||
if (c.key != null)
|
|
||||||
al.add(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
HMCLog.log("AssetsLoader - Format end.");
|
|
||||||
|
|
||||||
successEvent.execute(al);
|
|
||||||
} catch (ParserConfigurationException | SAXException | IOException e) {
|
|
||||||
HMCLog.warn("AssetsLoader - Failed", e);
|
|
||||||
failedEvent.execute(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -32,8 +32,10 @@ import org.jackhuang.hellominecraft.utils.StrUtils;
|
|||||||
import org.jackhuang.hellominecraft.launcher.utils.MCUtils;
|
import org.jackhuang.hellominecraft.launcher.utils.MCUtils;
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.download.IDownloadProvider;
|
import org.jackhuang.hellominecraft.launcher.utils.download.IDownloadProvider;
|
||||||
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
||||||
import org.jackhuang.hellominecraft.utils.functions.Consumer;
|
|
||||||
import org.jackhuang.hellominecraft.utils.VersionNumber;
|
import org.jackhuang.hellominecraft.utils.VersionNumber;
|
||||||
|
import rx.Observable;
|
||||||
|
import rx.Observer;
|
||||||
|
import rx.subscriptions.Subscriptions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -46,58 +48,62 @@ public class AssetsMojangLoader extends IAssetsHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getList(MinecraftVersion mv, IMinecraftProvider mp, final Consumer<String[]> dl) {
|
public Observable<String[]> getList(MinecraftVersion mv, IMinecraftProvider mp) {
|
||||||
if (mv == null) {
|
return Observable.<String[]>create((Observer<String[]> t1) -> {
|
||||||
dl.accept(null);
|
if (mv == null) {
|
||||||
return;
|
t1.onError(null);
|
||||||
}
|
return Subscriptions.empty();
|
||||||
String assetsId = mv.assets == null ? "legacy" : mv.assets;
|
}
|
||||||
File assets = mp.getAssets();
|
String assetsId = mv.assets == null ? "legacy" : mv.assets;
|
||||||
HMCLog.log("Get index: " + assetsId);
|
File assets = mp.getAssets();
|
||||||
File f = IOUtils.tryGetCanonicalFile(new File(assets, "indexes/" + assetsId + ".json"));
|
HMCLog.log("Get index: " + assetsId);
|
||||||
if (!f.exists() && !MCUtils.downloadMinecraftAssetsIndex(assets, assetsId, Settings.getInstance().getDownloadSource())) {
|
File f = IOUtils.tryGetCanonicalFile(new File(assets, "indexes/" + assetsId + ".json"));
|
||||||
dl.accept(null);
|
if (!f.exists() && !MCUtils.downloadMinecraftAssetsIndex(assets, assetsId, Settings.getInstance().getDownloadSource())) {
|
||||||
return;
|
t1.onError(null);
|
||||||
}
|
return Subscriptions.empty();
|
||||||
|
|
||||||
String result;
|
|
||||||
try {
|
|
||||||
result = FileUtils.readFileToString(f);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
HMCLog.warn("Failed to read index json: " + f, ex);
|
|
||||||
dl.accept(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (StrUtils.isBlank(result)) {
|
|
||||||
HMCLog.err("Index json is empty, please redownload it!");
|
|
||||||
dl.accept(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
AssetsIndex o;
|
|
||||||
try {
|
|
||||||
o = C.gson.fromJson(result, AssetsIndex.class);
|
|
||||||
} catch (Exception e) {
|
|
||||||
HMCLog.err("Failed to parse index json, please redownload it!", e);
|
|
||||||
dl.accept(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
assetsDownloadURLs = new ArrayList<>();
|
|
||||||
assetsLocalNames = new ArrayList<>();
|
|
||||||
ArrayList<String> al = new ArrayList<>();
|
|
||||||
contents = new ArrayList<>();
|
|
||||||
if (o != null && o.getFileMap() != null)
|
|
||||||
for (Map.Entry<String, AssetsObject> e : o.getFileMap().entrySet()) {
|
|
||||||
Contents c = new Contents();
|
|
||||||
c.eTag = e.getValue().getHash();
|
|
||||||
c.key = c.eTag.substring(0, 2) + "/" + e.getValue().getHash();
|
|
||||||
c.size = e.getValue().getSize();
|
|
||||||
contents.add(c);
|
|
||||||
assetsDownloadURLs.add(c.key);
|
|
||||||
assetsLocalNames.add(new File(assets, "objects" + File.separator + c.key.replace("/", File.separator)));
|
|
||||||
al.add(e.getKey());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dl.accept(al.toArray(new String[1]));
|
String result;
|
||||||
|
try {
|
||||||
|
result = FileUtils.readFileToString(f);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
HMCLog.warn("Failed to read index json: " + f, ex);
|
||||||
|
t1.onError(null);
|
||||||
|
return Subscriptions.empty();
|
||||||
|
}
|
||||||
|
if (StrUtils.isBlank(result)) {
|
||||||
|
HMCLog.err("Index json is empty, please redownload it!");
|
||||||
|
t1.onError(null);
|
||||||
|
return Subscriptions.empty();
|
||||||
|
}
|
||||||
|
AssetsIndex o;
|
||||||
|
try {
|
||||||
|
o = C.gson.fromJson(result, AssetsIndex.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
HMCLog.err("Failed to parse index json, please redownload it!", e);
|
||||||
|
t1.onError(null);
|
||||||
|
return Subscriptions.empty();
|
||||||
|
}
|
||||||
|
assetsDownloadURLs = new ArrayList<>();
|
||||||
|
assetsLocalNames = new ArrayList<>();
|
||||||
|
ArrayList<String> al = new ArrayList<>();
|
||||||
|
contents = new ArrayList<>();
|
||||||
|
if (o != null && o.getFileMap() != null)
|
||||||
|
for (Map.Entry<String, AssetsObject> e : o.getFileMap().entrySet()) {
|
||||||
|
Contents c = new Contents();
|
||||||
|
c.eTag = e.getValue().getHash();
|
||||||
|
c.key = c.eTag.substring(0, 2) + "/" + e.getValue().getHash();
|
||||||
|
c.size = e.getValue().getSize();
|
||||||
|
contents.add(c);
|
||||||
|
assetsDownloadURLs.add(c.key);
|
||||||
|
assetsLocalNames.add(new File(assets, "objects" + File.separator + c.key.replace("/", File.separator)));
|
||||||
|
al.add(e.getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
t1.onNext(al.toArray(new String[1]));
|
||||||
|
t1.onCompleted();
|
||||||
|
return Subscriptions.empty();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Hello Minecraft! Launcher.
|
|
||||||
* 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.launcher.utils.assets;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import org.jackhuang.hellominecraft.HMCLog;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.utils.download.IDownloadProvider;
|
|
||||||
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
|
||||||
import org.jackhuang.hellominecraft.utils.VersionNumber;
|
|
||||||
import org.jackhuang.hellominecraft.tasks.Task;
|
|
||||||
import org.jackhuang.hellominecraft.utils.functions.Consumer;
|
|
||||||
import rx.Observable;
|
|
||||||
import rx.util.functions.Func1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author huangyuhui
|
|
||||||
*/
|
|
||||||
public class AssetsMojangOldLoader extends IAssetsHandler {
|
|
||||||
|
|
||||||
private static final String URL = "http://bmclapi.bangbang93.com/resources/";
|
|
||||||
|
|
||||||
public AssetsMojangOldLoader(String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getList(MinecraftVersion mv, IMinecraftProvider mp, final Consumer<String[]> dl) {
|
|
||||||
AssetsLoader al = new AssetsLoader(URL);
|
|
||||||
al.failedEvent.register((sender, e) -> {
|
|
||||||
HMCLog.warn("Failed to get assets list.", e);
|
|
||||||
dl.accept(null);
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
al.successEvent.register((sender, t) -> {
|
|
||||||
assetsDownloadURLs = new ArrayList<>();
|
|
||||||
assetsLocalNames = new ArrayList<>();
|
|
||||||
contents = t;
|
|
||||||
for (Contents c : t) {
|
|
||||||
assetsDownloadURLs.add(c.key);
|
|
||||||
assetsLocalNames.add(new File(mp.getAssets(), c.key.replace("/", File.separator)));
|
|
||||||
}
|
|
||||||
dl.accept(assetsDownloadURLs.toArray(new String[1]));
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
new Thread(al).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVersionAllowed(String formattedVersion) {
|
|
||||||
VersionNumber r = VersionNumber.check(formattedVersion);
|
|
||||||
if (r == null)
|
|
||||||
return false;
|
|
||||||
return VersionNumber.check("1.7.2").compareTo(r) >= 0
|
|
||||||
&& VersionNumber.check("1.6.0").compareTo(r) <= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Task getDownloadTask(IDownloadProvider sourceType) {
|
|
||||||
return new AssetsTask(URL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -34,6 +34,7 @@ import org.jackhuang.hellominecraft.utils.functions.Consumer;
|
|||||||
import org.jackhuang.hellominecraft.utils.code.DigestUtils;
|
import org.jackhuang.hellominecraft.utils.code.DigestUtils;
|
||||||
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
||||||
import org.jackhuang.hellominecraft.utils.NetUtils;
|
import org.jackhuang.hellominecraft.utils.NetUtils;
|
||||||
|
import rx.Observable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assets
|
* Assets
|
||||||
@@ -73,7 +74,7 @@ public abstract class IAssetsHandler {
|
|||||||
* @param mp The Minecraft Provider
|
* @param mp The Minecraft Provider
|
||||||
* @param x finished event
|
* @param x finished event
|
||||||
*/
|
*/
|
||||||
public abstract void getList(MinecraftVersion mv, IMinecraftProvider mp, Consumer<String[]> x);
|
public abstract Observable<String[]> getList(MinecraftVersion mv, IMinecraftProvider mp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will be invoked when the user invoked "Download all assets".
|
* Will be invoked when the user invoked "Download all assets".
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import org.jackhuang.hellominecraft.launcher.settings.Settings;
|
|||||||
import org.jackhuang.hellominecraft.launcher.utils.assets.IAssetsHandler;
|
import org.jackhuang.hellominecraft.launcher.utils.assets.IAssetsHandler;
|
||||||
import org.jackhuang.hellominecraft.tasks.Task;
|
import org.jackhuang.hellominecraft.tasks.Task;
|
||||||
import org.jackhuang.hellominecraft.tasks.TaskWindow;
|
import org.jackhuang.hellominecraft.tasks.TaskWindow;
|
||||||
|
import rx.concurrency.Schedulers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -41,10 +42,10 @@ public class MinecraftService {
|
|||||||
@Override
|
@Override
|
||||||
public void executeTask() throws Throwable {
|
public void executeTask() throws Throwable {
|
||||||
IAssetsHandler type = IAssetsHandler.ASSETS_HANDLER;
|
IAssetsHandler type = IAssetsHandler.ASSETS_HANDLER;
|
||||||
type.getList(profile.getMinecraftProvider().getVersionById(mcVersion), profile.getMinecraftProvider(), (value) -> {
|
type.getList(profile.getMinecraftProvider().getVersionById(mcVersion), profile.getMinecraftProvider())
|
||||||
if (value != null)
|
.subscribeOn(Schedulers.newThread())
|
||||||
TaskWindow.getInstance().addTask(type.getDownloadTask(Settings.getInstance().getDownloadSource().getProvider())).start();
|
.observeOn(Schedulers.eventQueue())
|
||||||
});
|
.subscribe((value) -> TaskWindow.getInstance().addTask(type.getDownloadTask(Settings.getInstance().getDownloadSource().getProvider())).start());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1142,7 +1142,6 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
|||||||
versionChanged(getProfile(), mcv);
|
versionChanged(getProfile(), mcv);
|
||||||
getProfile().setSelectedMinecraftVersion(mcv);
|
getProfile().setSelectedMinecraftVersion(mcv);
|
||||||
cboVersions.setToolTipText(mcv);
|
cboVersions.setToolTipText(mcv);
|
||||||
Settings.save();
|
|
||||||
}//GEN-LAST:event_cboVersionsItemStateChanged
|
}//GEN-LAST:event_cboVersionsItemStateChanged
|
||||||
|
|
||||||
private void btnRefreshVersionsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshVersionsActionPerformed
|
private void btnRefreshVersionsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshVersionsActionPerformed
|
||||||
@@ -1154,12 +1153,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
|||||||
}//GEN-LAST:event_btnRefreshForgeActionPerformed
|
}//GEN-LAST:event_btnRefreshForgeActionPerformed
|
||||||
|
|
||||||
private void btnDownloadForgeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadForgeActionPerformed
|
private void btnDownloadForgeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadForgeActionPerformed
|
||||||
int idx = lstForge.getSelectedRow();
|
forge.downloadSelectedRow();
|
||||||
if (idx == -1) {
|
|
||||||
MessageBox.Show(C.i18n("install.not_refreshed"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
profile.getInstallerService().downloadForge(forge.getVersion(idx)).after(new TaskRunnable(this::refreshVersions)).run();
|
|
||||||
}//GEN-LAST:event_btnDownloadForgeActionPerformed
|
}//GEN-LAST:event_btnDownloadForgeActionPerformed
|
||||||
|
|
||||||
private void btnRefreshOptifineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshOptifineActionPerformed
|
private void btnRefreshOptifineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshOptifineActionPerformed
|
||||||
@@ -1167,21 +1161,11 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
|||||||
}//GEN-LAST:event_btnRefreshOptifineActionPerformed
|
}//GEN-LAST:event_btnRefreshOptifineActionPerformed
|
||||||
|
|
||||||
private void btnDownloadOptifineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadOptifineActionPerformed
|
private void btnDownloadOptifineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadOptifineActionPerformed
|
||||||
int idx = lstOptifine.getSelectedRow();
|
optifine.downloadSelectedRow();
|
||||||
if (idx == -1) {
|
|
||||||
MessageBox.Show(C.i18n("install.not_refreshed"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
profile.getInstallerService().downloadOptifine(optifine.getVersion(idx)).after(new TaskRunnable(this::refreshVersions)).run();
|
|
||||||
}//GEN-LAST:event_btnDownloadOptifineActionPerformed
|
}//GEN-LAST:event_btnDownloadOptifineActionPerformed
|
||||||
|
|
||||||
private void btnInstallLiteLoaderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInstallLiteLoaderActionPerformed
|
private void btnInstallLiteLoaderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInstallLiteLoaderActionPerformed
|
||||||
int idx = lstLiteLoader.getSelectedRow();
|
liteloader.downloadSelectedRow();
|
||||||
if (idx == -1) {
|
|
||||||
MessageBox.Show(C.i18n("install.not_refreshed"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
profile.getInstallerService().downloadLiteLoader(liteloader.getVersion(idx)).after(new TaskRunnable(this::refreshVersions)).run();
|
|
||||||
}//GEN-LAST:event_btnInstallLiteLoaderActionPerformed
|
}//GEN-LAST:event_btnInstallLiteLoaderActionPerformed
|
||||||
|
|
||||||
private void btnRefreshLiteLoaderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshLiteLoaderActionPerformed
|
private void btnRefreshLiteLoaderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshLiteLoaderActionPerformed
|
||||||
@@ -1608,8 +1592,8 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
|||||||
void refreshVersions() {
|
void refreshVersions() {
|
||||||
list = Settings.getInstance().getDownloadSource().getProvider().getInstallerByType(id);
|
list = Settings.getInstance().getDownloadSource().getProvider().getInstallerByType(id);
|
||||||
if (TaskWindow.getInstance().addTask(new TaskRunnableArg1<>(C.i18n("install." + id + ".get_list"), list)
|
if (TaskWindow.getInstance().addTask(new TaskRunnableArg1<>(C.i18n("install." + id + ".get_list"), list)
|
||||||
.registerPreviousResult(new DefaultPreviousResult<>(new String[] {getMinecraftVersionFormatted()})))
|
.registerPreviousResult(new DefaultPreviousResult<>(new String[] {getMinecraftVersionFormatted()})))
|
||||||
.start())
|
.start())
|
||||||
loadVersions();
|
loadVersions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1617,6 +1601,15 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
|||||||
return versions.get(idx);
|
return versions.get(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void downloadSelectedRow() {
|
||||||
|
int idx = jt.getSelectedRow();
|
||||||
|
if (idx == -1) {
|
||||||
|
MessageBox.Show(C.i18n("install.not_refreshed"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
profile.getInstallerService().downloadOptifine(getVersion(idx)).after(new TaskRunnable(this::refreshVersions)).run();
|
||||||
|
}
|
||||||
|
|
||||||
private List<InstallerVersionList.InstallerVersion> loadVersions(InstallerVersionList list, JTable table) {
|
private List<InstallerVersionList.InstallerVersion> loadVersions(InstallerVersionList list, JTable table) {
|
||||||
if (list == null)
|
if (list == null)
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package rx.concurrency;
|
||||||
|
|
||||||
|
import java.awt.EventQueue;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import rx.Subscription;
|
||||||
|
import rx.util.functions.Func0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author huangyuhui
|
||||||
|
*/
|
||||||
|
public class EventQueueScheduler extends AbstractScheduler {
|
||||||
|
private static final EventQueueScheduler INSTANCE = new EventQueueScheduler();
|
||||||
|
|
||||||
|
public static EventQueueScheduler getInstance() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Subscription schedule(Func0<Subscription> action) {
|
||||||
|
final DiscardableAction discardableAction = new DiscardableAction(action);
|
||||||
|
|
||||||
|
EventQueue.invokeLater(discardableAction::call);
|
||||||
|
|
||||||
|
return discardableAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Subscription schedule(Func0<Subscription> action, long dueTime, TimeUnit unit) {
|
||||||
|
return schedule(new SleepingAction(action, this, dueTime, unit));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -62,6 +62,15 @@ public class Schedulers {
|
|||||||
return NewThreadScheduler.getInstance();
|
return NewThreadScheduler.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link Scheduler} that queues work on the EventQueue thread to be executed on the Swing UI Thread.
|
||||||
|
*
|
||||||
|
* @return {@link NewThreadScheduler} instance
|
||||||
|
*/
|
||||||
|
public static Scheduler eventQueue() {
|
||||||
|
return EventQueueScheduler.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Scheduler} that queues work on an {@link Executor}.
|
* {@link Scheduler} that queues work on an {@link Executor}.
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -21,14 +21,7 @@ public class Subscriptions {
|
|||||||
* @return {@link Subscription}
|
* @return {@link Subscription}
|
||||||
*/
|
*/
|
||||||
public static Subscription create(final Action0 unsubscribe) {
|
public static Subscription create(final Action0 unsubscribe) {
|
||||||
return new Subscription() {
|
return unsubscribe::call;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void unsubscribe() {
|
|
||||||
unsubscribe.call();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,21 +31,11 @@ public class Subscriptions {
|
|||||||
*/
|
*/
|
||||||
public static Subscription create(final Object unsubscribe) {
|
public static Subscription create(final Object unsubscribe) {
|
||||||
final FuncN<?> f = Functions.from(unsubscribe);
|
final FuncN<?> f = Functions.from(unsubscribe);
|
||||||
return new Subscription() {
|
return f::call;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void unsubscribe() {
|
|
||||||
f.call();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link Subscription} that does nothing when its unsubscribe method is called.
|
* A {@link Subscription} that does nothing when its unsubscribe method is called.
|
||||||
*/
|
*/
|
||||||
private static Subscription EMPTY = new Subscription() {
|
private static final Subscription EMPTY = () -> { };
|
||||||
public void unsubscribe() {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user