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