mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-08-03 19:36:53 -04:00
Fixed swing syncing bugs
This commit is contained in:
parent
a436e10d93
commit
52c43bde06
@ -18,6 +18,7 @@
|
||||
package org.jackhuang.hellominecraft.launcher.launch;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.swing.SwingUtilities;
|
||||
import org.jackhuang.hellominecraft.C;
|
||||
import org.jackhuang.hellominecraft.HMCLog;
|
||||
import org.jackhuang.hellominecraft.launcher.launch.GameLauncher.DownloadLibraryJob;
|
||||
@ -30,6 +31,8 @@ import org.jackhuang.hellominecraft.utils.system.Compressor;
|
||||
import org.jackhuang.hellominecraft.utils.MessageBox;
|
||||
|
||||
public class DefaultGameLauncher extends GameLauncher {
|
||||
|
||||
private boolean fuckingFlag;
|
||||
|
||||
public DefaultGameLauncher(Profile version, LoginInfo info, IAuthenticator lg) {
|
||||
super(version, info, lg);
|
||||
@ -43,12 +46,23 @@ public class DefaultGameLauncher extends GameLauncher {
|
||||
for (DownloadLibraryJob s : t)
|
||||
parallelTask.addDependsTask(new LibraryDownloadTask(s));
|
||||
dw.addTask(parallelTask);
|
||||
boolean flag = true;
|
||||
if (t.size() > 0)
|
||||
flag = dw.start();
|
||||
if (!flag && MessageBox.Show(C.i18n("launch.not_finished_downloading_libraries"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
|
||||
flag = true;
|
||||
return flag;
|
||||
Runnable r = () -> {
|
||||
boolean flag = true;
|
||||
if (t.size() > 0)
|
||||
flag = dw.start();
|
||||
if (!flag && MessageBox.Show(C.i18n("launch.not_finished_downloading_libraries"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
|
||||
flag = true;
|
||||
synchronized(DefaultGameLauncher.this) {
|
||||
fuckingFlag = flag;
|
||||
}
|
||||
};
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(r);
|
||||
} catch (Exception e) {
|
||||
HMCLog.err("InvokeAndWait failed.", e);
|
||||
r.run();
|
||||
}
|
||||
return fuckingFlag;
|
||||
});
|
||||
decompressNativesEvent.register((sender, value) -> {
|
||||
if (value == null)
|
||||
|
@ -22,6 +22,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.swing.SwingUtilities;
|
||||
import org.jackhuang.hellominecraft.C;
|
||||
import org.jackhuang.hellominecraft.HMCLog;
|
||||
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
|
||||
@ -37,7 +38,6 @@ import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
|
||||
import org.jackhuang.hellominecraft.tasks.TaskWindow;
|
||||
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
||||
import org.jackhuang.hellominecraft.utils.MessageBox;
|
||||
import rx.concurrency.Schedulers;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -74,11 +74,19 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
|
||||
String[] splitted = org.jackhuang.hellominecraft.utils.StrUtils.tokenize(arg);
|
||||
|
||||
if (!checkAssetsExist())
|
||||
if (MessageBox.Show(C.i18n("assets.no_assets"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
|
||||
IAssetsHandler.ASSETS_HANDLER.getList(version, provider)
|
||||
.subscribeOn(Schedulers.newThread())
|
||||
.observeOn(Schedulers.eventQueue())
|
||||
.subscribe((value) -> TaskWindow.getInstance().addTask(IAssetsHandler.ASSETS_HANDLER.getDownloadTask(dt.getProvider())).start());
|
||||
if (MessageBox.Show(C.i18n("assets.no_assets"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
|
||||
IAssetsHandler.ASSETS_HANDLER.getList(version, provider).subscribe(a -> {
|
||||
});
|
||||
Runnable r = ()
|
||||
-> TaskWindow.getInstance().addTask(IAssetsHandler.ASSETS_HANDLER.getDownloadTask(provider.profile.getDownloadType().getProvider())).start();
|
||||
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(r);
|
||||
} catch (Exception e) {
|
||||
HMCLog.err("Failed invokeAndWait", e);
|
||||
r.run();
|
||||
}
|
||||
}
|
||||
|
||||
String game_assets = reconstructAssets().getAbsolutePath();
|
||||
|
||||
|
@ -54,7 +54,7 @@ public class ModInfo implements Comparable<ModInfo> {
|
||||
if (f.renameTo(newf))
|
||||
location = newf;
|
||||
}
|
||||
|
||||
|
||||
public void showURL() {
|
||||
if (url != null)
|
||||
Utils.openLink(url);
|
||||
@ -100,7 +100,28 @@ public class ModInfo implements Comparable<ModInfo> {
|
||||
boolean disabled = name.endsWith(".disabled");
|
||||
if (disabled)
|
||||
name = name.substring(0, name.length() - ".disabled".length());
|
||||
return name.endsWith(".zip") || name.endsWith(".jar");
|
||||
return name.endsWith(".zip") || name.endsWith(".jar") || name.endsWith("litemod");
|
||||
}
|
||||
|
||||
private static ModInfo getForgeModInfo(File f, ZipFile jar, ZipEntry entry) throws IOException {
|
||||
ModInfo i = new ModInfo();
|
||||
i.location = f;
|
||||
List<ModInfo> m = C.gson.fromJson(new InputStreamReader(jar.getInputStream(entry)),
|
||||
new TypeToken<List<ModInfo>>() {
|
||||
}.getType());
|
||||
if (m != null && m.size() > 0) {
|
||||
i = m.get(0);
|
||||
i.location = f;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
private static ModInfo getLiteLoaderModInfo(File f, ZipFile jar, ZipEntry entry) throws IOException {
|
||||
ModInfo m = C.gson.fromJson(new InputStreamReader(jar.getInputStream(entry)),
|
||||
ModInfo.class);
|
||||
if (m == null) m = new ModInfo();
|
||||
m.location = f;
|
||||
return m;
|
||||
}
|
||||
|
||||
public static ModInfo readModInfo(File f) {
|
||||
@ -109,19 +130,12 @@ public class ModInfo implements Comparable<ModInfo> {
|
||||
try {
|
||||
try (ZipFile jar = new ZipFile(f)) {
|
||||
ZipEntry entry = jar.getEntry("mcmod.info");
|
||||
if (entry == null)
|
||||
entry = jar.getEntry("litemod.json");
|
||||
if (entry == null)
|
||||
return i;
|
||||
else {
|
||||
List<ModInfo> m = C.gson.fromJson(new InputStreamReader(jar.getInputStream(entry)),
|
||||
new TypeToken<List<ModInfo>>() {
|
||||
}.getType());
|
||||
if (m != null && m.size() > 0) {
|
||||
i = m.get(0);
|
||||
i.location = f;
|
||||
}
|
||||
}
|
||||
if (entry != null)
|
||||
return getForgeModInfo(f, jar, entry);
|
||||
entry = jar.getEntry("litemod.json");
|
||||
if (entry != null)
|
||||
return getLiteLoaderModInfo(f, jar, entry);
|
||||
return i;
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
HMCLog.warn("File " + f + " is not a jar.", ex);
|
||||
|
@ -49,9 +49,9 @@ public class MinecraftForgeVersionList extends InstallerVersionList {
|
||||
|
||||
@Override
|
||||
public void refreshList(String[] needed) throws Exception {
|
||||
String s = NetUtils.get(Settings.getInstance().getDownloadSource().getProvider().getParsedLibraryDownloadURL(C.URL_FORGE_LIST));
|
||||
if (root != null)
|
||||
return;
|
||||
String s = NetUtils.get(Settings.getInstance().getDownloadSource().getProvider().getParsedLibraryDownloadURL(C.URL_FORGE_LIST));
|
||||
|
||||
root = C.gson.fromJson(s, MinecraftForgeVersionRoot.class);
|
||||
|
||||
|
@ -185,7 +185,13 @@ public final class GameSettingsPanel extends javax.swing.JPanel implements DropT
|
||||
boolean hasLink = m.url != null;
|
||||
String text = "<html>" + (hasLink ? "<a href=\"" + m.url + "\">" : "") + m.getName() + (hasLink ? "</a>" : "");
|
||||
text += " by " + m.getAuthor();
|
||||
text += "<br>" + (m.description == null ? "No mcmod.info found" : SwingUtils.getParsedJPanelText(lblModInfo, m.description));
|
||||
String description = "No mod description found";
|
||||
if (m.description != null) {
|
||||
description = "";
|
||||
for (String desc : m.description.split("\n"))
|
||||
description += SwingUtils.getParsedJPanelText(lblModInfo, desc) + "<br/>";
|
||||
}
|
||||
text += "<br>" + description;
|
||||
lblModInfo.setText(text);
|
||||
lblModInfo.setCursor(new java.awt.Cursor(hasLink ? java.awt.Cursor.HAND_CURSOR : java.awt.Cursor.DEFAULT_CURSOR));
|
||||
}
|
||||
@ -208,7 +214,7 @@ public final class GameSettingsPanel extends javax.swing.JPanel implements DropT
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if (tabVersionEdit.getSelectedComponent() == pnlGameDownloads && !a) {
|
||||
a = true;
|
||||
refreshDownloads(Settings.getInstance().getDownloadSource());
|
||||
refreshDownloads();
|
||||
} else if (tabVersionEdit.getSelectedComponent() == pnlAutoInstall && !b) {
|
||||
b = true;
|
||||
forge.refreshVersions();
|
||||
@ -1172,12 +1178,12 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
||||
}//GEN-LAST:event_btnRefreshLiteLoaderActionPerformed
|
||||
|
||||
private void btnDownloadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadActionPerformed
|
||||
downloadMinecraft(Settings.getInstance().getDownloadSource());
|
||||
downloadMinecraft();
|
||||
refreshVersions();
|
||||
}//GEN-LAST:event_btnDownloadActionPerformed
|
||||
|
||||
private void btnRefreshGameDownloadsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshGameDownloadsActionPerformed
|
||||
refreshDownloads(Settings.getInstance().getDownloadSource());
|
||||
refreshDownloads();
|
||||
}//GEN-LAST:event_btnRefreshGameDownloadsActionPerformed
|
||||
|
||||
private void btnExploreMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnExploreMouseClicked
|
||||
@ -1487,7 +1493,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
||||
|
||||
//</editor-fold>
|
||||
// <editor-fold defaultstate="collapsed" desc="Game Download">
|
||||
public void refreshDownloads(final DownloadType provider) {
|
||||
public void refreshDownloads() {
|
||||
DefaultTableModel model = (DefaultTableModel) lstDownloads.getModel();
|
||||
while (model.getRowCount() > 0)
|
||||
model.removeRow(0);
|
||||
@ -1501,12 +1507,8 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
|
||||
}, lstDownloads::updateUI);
|
||||
}
|
||||
|
||||
void downloadMinecraft(DownloadType index) {
|
||||
if (profile == null)
|
||||
return;
|
||||
if (lstDownloads.getSelectedRow() < 0)
|
||||
refreshDownloads(Settings.getInstance().getDownloadSource());
|
||||
if (lstDownloads.getSelectedRow() < 0) {
|
||||
void downloadMinecraft() {
|
||||
if (profile == null || lstDownloads.getSelectedRow() < 0) {
|
||||
MessageBox.Show(C.i18n("gamedownload.not_refreshed"));
|
||||
return;
|
||||
}
|
||||
|
@ -386,7 +386,7 @@ public class MainPagePanel extends javax.swing.JPanel {
|
||||
}
|
||||
final IAuthenticator l = IAuthenticator.LOGINS.get(index);
|
||||
final LoginInfo li = new LoginInfo(Settings.getInstance().getUsername(), l.isLoggedIn() || l.isHidePasswordBox() ? null : new String(txtPassword.getPassword()));
|
||||
Thread t = new Thread() {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("Game Launcher");
|
||||
@ -405,8 +405,7 @@ public class MainPagePanel extends javax.swing.JPanel {
|
||||
listener.accept(gl);
|
||||
gl.makeLaunchCommand();
|
||||
}
|
||||
};
|
||||
t.start();
|
||||
}.start();
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
|
@ -219,8 +219,8 @@ implements ProgressProviderListener, Runnable, DoingDoneListener<Task> {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
SwingUtilities.invokeLater(this::dispose);
|
||||
suc = true;
|
||||
this.dispose();
|
||||
HMCLog.log("Tasks are finished.");
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ public final class CollectionUtils {
|
||||
|
||||
public static <T> ArrayList<T> map(Collection<T> coll, Predicate<T> p) {
|
||||
ArrayList<T> newColl = new ArrayList<>();
|
||||
Observable.from(coll).filter(p).subscribe(newColl::add);
|
||||
Observable.from(coll).filter(t -> p.apply(t)).subscribe(t -> newColl.add(t));
|
||||
return newColl;
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ public class SwingUtils {
|
||||
char[] chars = longString.toCharArray();
|
||||
FontMetrics fontMetrics = jLabel1.getFontMetrics(jLabel1.getFont());
|
||||
for (int beginIndex = 0, limit = 1;; limit++) {
|
||||
if (beginIndex + limit >= chars.length)
|
||||
if (beginIndex + limit > chars.length)
|
||||
break;
|
||||
if (fontMetrics.charsWidth(chars, beginIndex, limit) < jLabel1.getWidth()) {
|
||||
if (beginIndex + limit < chars.length)
|
||||
|
Loading…
x
Reference in New Issue
Block a user