Try to fix some problems

This commit is contained in:
huanghongxun
2015-12-10 14:06:56 +08:00
parent 52c43bde06
commit e91d4c5477
20 changed files with 1920 additions and 1264 deletions

View File

@@ -32,8 +32,6 @@ 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);
register();
@@ -46,23 +44,12 @@ public class DefaultGameLauncher extends GameLauncher {
for (DownloadLibraryJob s : t)
parallelTask.addDependsTask(new LibraryDownloadTask(s));
dw.addTask(parallelTask);
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;
return flag;
});
decompressNativesEvent.register((sender, value) -> {
if (value == null)

View File

@@ -85,7 +85,6 @@ public abstract class IMinecraftProvider {
*
* @see org.jackhuang.hellominecraft.launcher.launch.IMinecraftLoader
* @param p player informations, including username & auth_token
* @param type where to download
*
* @return what you want
*

View File

@@ -77,15 +77,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
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();
}
TaskWindow.getInstance().addTask(IAssetsHandler.ASSETS_HANDLER.getDownloadTask(provider.profile.getDownloadType().getProvider())).start();
}
String game_assets = reconstructAssets().getAbsolutePath();

View File

@@ -120,8 +120,11 @@ public final class Config {
}
public TreeMap<String, Profile> getConfigurations() {
if (configurations == null)
if (configurations == null) {
configurations = new TreeMap<>();
Profile profile = new Profile();
configurations.put(profile.getName(), profile);
}
return configurations;
}
@@ -147,9 +150,6 @@ public final class Config {
clientToken = UUID.randomUUID().toString();
username = "";
logintype = downloadtype = 0;
configurations = new TreeMap<>();
Profile profile = new Profile();
configurations.put(profile.getName(), profile);
enableShadow = false;
theme = 0;
}

View File

@@ -119,6 +119,7 @@ public final class Settings {
}
public static Profile getProfile(String name) {
if (name == null) return getProfiles().get("Default");
return getProfiles().get(name);
}

View File

@@ -62,7 +62,7 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
t.printStackTrace();
}
return false;
} else if (s.contains("java.lang.NoClassDefFoundError") || s.contains("java.lang.IncompatibleClassChangeError") || s.contains("java.lang.ClassFormatError")) {
} else if (s.contains("java.lang.NoClassDefFoundError") || s.contains("java.lang.VerifyError") || s.contains("java.lang.NoSuchMethodError") || s.contains("java.lang.IncompatibleClassChangeError") || s.contains("java.lang.ClassFormatError")) {
System.out.println(C.i18n("crash.NoClassDefFound"));
try {
MessageBox.Show(C.i18n("crash.NoClassDefFound"));
@@ -98,7 +98,7 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
else
System.out.println(text);
if (checkThrowable(e)) {
if (checkThrowable(e) && !System.getProperty("java.vm.name").contains("OpenJDK")) {
SwingUtilities.invokeLater(() -> LogWindow.INSTANCE.showAsCrashWindow(UpdateChecker.OUT_DATED));
if (!UpdateChecker.OUT_DATED)
reportToServer(text, s);

View File

@@ -33,7 +33,6 @@ import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
import org.jackhuang.hellominecraft.utils.VersionNumber;
import rx.Observable;
import rx.Observer;
import rx.subscriptions.Subscriptions;
/**
*
@@ -47,10 +46,10 @@ public class AssetsMojangLoader extends IAssetsHandler {
@Override
public Observable<String[]> getList(MinecraftVersion mv, IMinecraftProvider mp) {
return Observable.<String[]>create((Observer<String[]> t1) -> {
return Observable.<String[]>createWithEmptySubscription((Observer<String[]> t1) -> {
if (mv == null) {
t1.onError(null);
return Subscriptions.empty();
return;
}
String assetsId = mv.assets == null ? "legacy" : mv.assets;
File assets = mp.getAssetService().getAssets();
@@ -58,7 +57,7 @@ public class AssetsMojangLoader extends IAssetsHandler {
File f = IOUtils.tryGetCanonicalFile(new File(assets, "indexes/" + assetsId + ".json"));
if (!f.exists() && !mp.getAssetService().downloadMinecraftAssetsIndex(assetsId)) {
t1.onError(null);
return Subscriptions.empty();
return;
}
String result;
@@ -67,12 +66,12 @@ public class AssetsMojangLoader extends IAssetsHandler {
} catch (IOException ex) {
HMCLog.warn("Failed to read index json: " + f, ex);
t1.onError(null);
return Subscriptions.empty();
return;
}
if (StrUtils.isBlank(result)) {
HMCLog.err("Index json is empty, please redownload it!");
t1.onError(null);
return Subscriptions.empty();
return;
}
AssetsIndex o;
try {
@@ -80,7 +79,7 @@ public class AssetsMojangLoader extends IAssetsHandler {
} catch (Exception e) {
HMCLog.err("Failed to parse index json, please redownload it!", e);
t1.onError(null);
return Subscriptions.empty();
return;
}
assetsDownloadURLs = new ArrayList<>();
assetsLocalNames = new ArrayList<>();
@@ -100,7 +99,6 @@ public class AssetsMojangLoader extends IAssetsHandler {
t1.onNext(al.toArray(new String[1]));
t1.onCompleted();
return Subscriptions.empty();
});
}

View File

@@ -207,7 +207,9 @@ public final class MinecraftVersionManager extends IMinecraftProvider {
@Override
public GameLauncher.DecompressLibraryJob getDecompressLibraries() {
MinecraftVersion v = profile.getSelectedMinecraftVersion().resolve(this);
MinecraftVersion v = getSelectedMinecraftVersion();
if (v == null) return null;
v = v.resolve(this);
if (v.libraries == null)
return null;
ArrayList<File> unzippings = new ArrayList<>();

View File

@@ -38,7 +38,6 @@ import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.TableModelEvent;
@@ -48,7 +47,6 @@ import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.settings.LauncherVisibility;
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList;
import org.jackhuang.hellominecraft.launcher.utils.installers.InstallerVersionList.InstallerVersion;
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
import org.jackhuang.hellominecraft.launcher.settings.Profile;
import org.jackhuang.hellominecraft.launcher.settings.Settings;
import org.jackhuang.hellominecraft.launcher.utils.FileNameFilter;
@@ -67,6 +65,7 @@ import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.utils.SwingUtils;
import org.jackhuang.hellominecraft.utils.system.Java;
import org.jackhuang.hellominecraft.views.LogWindow;
import rx.Observable;
import rx.concurrency.Schedulers;
/**
@@ -75,6 +74,11 @@ import rx.concurrency.Schedulers;
*/
public final class GameSettingsPanel extends javax.swing.JPanel implements DropTargetListener {
boolean isLoading = false;
public MinecraftVersionRequest minecraftVersion;
InstallerHelper forge, optifine, liteloader;
String mcVersion;
/**
* Creates new form GameSettingsPanel
*/
@@ -179,7 +183,7 @@ public final class GameSettingsPanel extends javax.swing.JPanel implements DropT
}
lstExternalMods.getSelectionModel().addListSelectionListener(e -> {
int row = lstExternalMods.getSelectedRow();
List<ModInfo> mods = profile.getMinecraftProvider().getModService().getMods();
List<ModInfo> mods = getProfile().getMinecraftProvider().getModService().getMods();
if (mods != null && 0 <= row && row < mods.size()) {
ModInfo m = mods.get(row);
boolean hasLink = m.url != null;
@@ -199,7 +203,7 @@ public final class GameSettingsPanel extends javax.swing.JPanel implements DropT
((DefaultTableModel) lstExternalMods.getModel()).addTableModelListener(e -> {
if (e.getType() == TableModelEvent.UPDATE && e.getColumn() == 0) {
int row = lstExternalMods.getSelectedRow();
List<ModInfo> mods = profile.getMinecraftProvider().getModService().getMods();
List<ModInfo> mods = getProfile().getMinecraftProvider().getModService().getMods();
if (mods != null && mods.size() > row && row >= 0)
mods.get(row).reverseModState();
}
@@ -1110,12 +1114,9 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
private void cboProfilesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboProfilesItemStateChanged
if (isLoading)
return;
profile = getProfile();
if (profile == null)
return;
if (profile.getMinecraftProvider().getVersionCount() <= 0)
versionChanged(profile, null);
prepare(profile);
if (getProfile().getMinecraftProvider().getVersionCount() <= 0)
versionChanged(null);
prepare(getProfile());
}//GEN-LAST:event_cboProfilesItemStateChanged
private void btnNewProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewProfileActionPerformed
@@ -1125,18 +1126,15 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
}//GEN-LAST:event_btnNewProfileActionPerformed
private void btnRemoveProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveProfileActionPerformed
if (profile == null)
if (getProfile() == null)
return;
if (MessageBox.Show(C.i18n("ui.message.sure_remove", profile.getName()), MessageBox.YES_NO_OPTION) == MessageBox.NO_OPTION)
if (MessageBox.Show(C.i18n("ui.message.sure_remove", getProfile().getName()), MessageBox.YES_NO_OPTION) == MessageBox.NO_OPTION)
return;
if (Settings.delProfile(profile)) {
cboProfiles.removeItem(profile.getName());
profile = Settings.getOneProfile();
if (profile != null) {
prepare(profile);
if (Settings.delProfile(getProfile())) {
cboProfiles.removeItem(getProfile().getName());
prepare(getProfile());
loadVersions();
}
}
}//GEN-LAST:event_btnRemoveProfileActionPerformed
private void cboVersionsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboVersionsItemStateChanged
@@ -1144,7 +1142,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
return;
String mcv = (String) cboVersions.getSelectedItem();
loadMinecraftVersion(mcv);
versionChanged(getProfile(), mcv);
versionChanged(mcv);
getProfile().setSelectedMinecraftVersion(mcv);
cboVersions.setToolTipText(mcv);
}//GEN-LAST:event_cboVersionsItemStateChanged
@@ -1212,76 +1210,76 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
}//GEN-LAST:event_btnModifyMouseClicked
private void txtJavaArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtJavaArgsFocusLost
profile.setJavaArgs(txtJavaArgs.getText());
getProfile().setJavaArgs(txtJavaArgs.getText());
}//GEN-LAST:event_txtJavaArgsFocusLost
private void txtMinecraftArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMinecraftArgsFocusLost
profile.setMinecraftArgs(txtMinecraftArgs.getText());
getProfile().setMinecraftArgs(txtMinecraftArgs.getText());
}//GEN-LAST:event_txtMinecraftArgsFocusLost
private void txtPermSizeFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPermSizeFocusLost
profile.setPermSize(txtPermSize.getText());
getProfile().setPermSize(txtPermSize.getText());
}//GEN-LAST:event_txtPermSizeFocusLost
private void chkDebugFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkDebugFocusLost
profile.setDebug(chkDebug.isSelected());
getProfile().setDebug(chkDebug.isSelected());
}//GEN-LAST:event_chkDebugFocusLost
private void chkNoJVMArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkNoJVMArgsFocusLost
profile.setNoJVMArgs(chkNoJVMArgs.isSelected());
getProfile().setNoJVMArgs(chkNoJVMArgs.isSelected());
}//GEN-LAST:event_chkNoJVMArgsFocusLost
private void chkCancelWrapperFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkCancelWrapperFocusLost
profile.setCanceledWrapper(chkCancelWrapper.isSelected());
getProfile().setCanceledWrapper(chkCancelWrapper.isSelected());
}//GEN-LAST:event_chkCancelWrapperFocusLost
private void txtPrecalledCommandFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPrecalledCommandFocusLost
profile.setPrecalledCommand(txtPrecalledCommand.getText());
getProfile().setPrecalledCommand(txtPrecalledCommand.getText());
}//GEN-LAST:event_txtPrecalledCommandFocusLost
private void txtServerIPFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtServerIPFocusLost
profile.setServerIp(txtServerIP.getText());
getProfile().setServerIp(txtServerIP.getText());
}//GEN-LAST:event_txtServerIPFocusLost
private void cboGameDirTypeFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cboGameDirTypeFocusLost
if (cboGameDirType.getSelectedIndex() >= 0)
profile.setGameDirType(GameDirType.values()[cboGameDirType.getSelectedIndex()]);
getProfile().setGameDirType(GameDirType.values()[cboGameDirType.getSelectedIndex()]);
}//GEN-LAST:event_cboGameDirTypeFocusLost
private void cboLauncherVisibilityFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cboLauncherVisibilityFocusLost
if (cboLauncherVisibility.getSelectedIndex() >= 0)
profile.setLauncherVisibility(LauncherVisibility.values()[cboLauncherVisibility.getSelectedIndex()]);
getProfile().setLauncherVisibility(LauncherVisibility.values()[cboLauncherVisibility.getSelectedIndex()]);
}//GEN-LAST:event_cboLauncherVisibilityFocusLost
private void btnDownloadAllAssetsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadAllAssetsActionPerformed
if (mcVersion != null && profile != null)
profile.getMinecraftProvider().getAssetService().downloadAssets(mcVersion).run();
if (mcVersion != null && getProfile() != null)
getProfile().getMinecraftProvider().getAssetService().downloadAssets(mcVersion).run();
}//GEN-LAST:event_btnDownloadAllAssetsActionPerformed
private void txtMaxMemoryFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMaxMemoryFocusLost
profile.setMaxMemory(txtMaxMemory.getText());
getProfile().setMaxMemory(txtMaxMemory.getText());
}//GEN-LAST:event_txtMaxMemoryFocusLost
private void txtJavaDirFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtJavaDirFocusLost
profile.setJavaDir(txtJavaDir.getText());
getProfile().setJavaDir(txtJavaDir.getText());
}//GEN-LAST:event_txtJavaDirFocusLost
private void chkFullscreenFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkFullscreenFocusLost
profile.setFullscreen(chkFullscreen.isSelected());
getProfile().setFullscreen(chkFullscreen.isSelected());
}//GEN-LAST:event_chkFullscreenFocusLost
private void txtHeightFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtHeightFocusLost
profile.setHeight(txtHeight.getText());
getProfile().setHeight(txtHeight.getText());
}//GEN-LAST:event_txtHeightFocusLost
private void txtWidthFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtWidthFocusLost
profile.setWidth(txtWidth.getText());
getProfile().setWidth(txtWidth.getText());
}//GEN-LAST:event_txtWidthFocusLost
private void txtGameDirFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtGameDirFocusLost
if (profile == null)
if (getProfile() == null)
return;
profile.setGameDir(txtGameDir.getText());
getProfile().setGameDir(txtGameDir.getText());
loadVersions();
}//GEN-LAST:event_txtGameDirFocusLost
@@ -1301,7 +1299,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
try {
String path = fc.getSelectedFile().getCanonicalPath();
txtJavaDir.setText(path);
profile.setJavaDir(txtJavaDir.getText());
getProfile().setJavaDir(txtJavaDir.getText());
} catch (IOException e) {
HMCLog.warn("Failed to set java path.", e);
MessageBox.Show(C.i18n("ui.label.failed_set") + e.getMessage());
@@ -1314,9 +1312,9 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
int idx = cboJava.getSelectedIndex();
if (idx != -1) {
Java j = Settings.JAVA.get(idx);
profile.setJava(j);
getProfile().setJava(j);
txtJavaDir.setEnabled(idx == 1);
txtJavaDir.setText(j.getHome() == null ? profile.getSettingsJavaDir() : j.getJava());
txtJavaDir.setText(j.getHome() == null ? getProfile().getSettingsJavaDir() : j.getJava());
}
}//GEN-LAST:event_cboJavaItemStateChanged
@@ -1329,14 +1327,14 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
return;
boolean flag = false;
for (File f : fc.getSelectedFiles())
flag |= !profile.getMinecraftProvider().getModService().addMod(f);
flag |= !getProfile().getMinecraftProvider().getModService().addMod(f);
reloadMods();
if (flag)
MessageBox.Show(C.I18N.getString("mods.failed"));
}//GEN-LAST:event_btnAddModActionPerformed
private void btnRemoveModActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveModActionPerformed
profile.getMinecraftProvider().getModService().removeMod(lstExternalMods.getSelectedRows());
getProfile().getMinecraftProvider().getModService().removeMod(lstExternalMods.getSelectedRows());
reloadMods();
}//GEN-LAST:event_btnRemoveModActionPerformed
@@ -1347,8 +1345,8 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
private void lblModInfoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblModInfoMouseClicked
int idx = lstExternalMods.getSelectedRow();
if (idx > 0 && idx < profile.getMinecraftProvider().getModService().getMods().size())
profile.getMinecraftProvider().getModService().getMods().get(idx).showURL();
if (idx > 0 && idx < getProfile().getMinecraftProvider().getModService().getMods().size())
getProfile().getMinecraftProvider().getModService().getMods().get(idx).showURL();
}//GEN-LAST:event_lblModInfoMouseClicked
private void btnChoosingGameDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChoosingGameDirActionPerformed
@@ -1362,7 +1360,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
try {
String path = fc.getSelectedFile().getCanonicalPath();
txtGameDir.setText(path);
profile.setGameDir(path);
getProfile().setGameDir(path);
} catch (IOException e) {
HMCLog.warn("Failed to set game dir.", e);
MessageBox.Show(C.i18n("ui.label.failed_set") + e.getMessage());
@@ -1378,7 +1376,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
}//GEN-LAST:event_btnShowLogActionPerformed
private void btnCleanGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCleanGameActionPerformed
profile.getMinecraftProvider().cleanFolder();
getProfile().getMinecraftProvider().cleanFolder();
}//GEN-LAST:event_btnCleanGameActionPerformed
// </editor-fold>
@@ -1404,10 +1402,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
isLoading = false;
if (index < cboProfiles.getItemCount()) {
cboProfiles.setSelectedIndex(index);
profile = selectedProfile;
if (profile == null)
profile = firstProfile;
prepare(profile);
prepare(getProfile());
loadVersions();
}
}
@@ -1416,7 +1411,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
if (cboProfiles.getSelectedIndex() >= 0)
return Settings.getProfile(cboProfiles.getSelectedItem().toString());
else
return null;
return Settings.getProfile(null);
}
void prepare(Profile profile) {
@@ -1449,14 +1444,14 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
}
void loadVersions() {
if (profile == null)
if (getProfile() == null)
return;
isLoading = true;
cboVersions.removeAllItems();
int index = 0, i = 0;
MinecraftVersion selVersion = profile.getSelectedMinecraftVersion();
MinecraftVersion selVersion = getProfile().getSelectedMinecraftVersion();
String selectedMC = selVersion == null ? null : selVersion.id;
for (MinecraftVersion each : profile.getMinecraftProvider().getVersions()) {
for (MinecraftVersion each : getProfile().getMinecraftProvider().getVersions()) {
cboVersions.addItem(each.id);
if (each.id.equals(selectedMC))
index = i;
@@ -1470,15 +1465,16 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
}
void loadMinecraftVersion() {
loadMinecraftVersion(profile.getSelectedMinecraftVersion());
loadMinecraftVersion(getProfile().getSelectedMinecraftVersion());
}
void loadMinecraftVersion(String v) {
loadMinecraftVersion(profile.getMinecraftProvider().getVersionById(v));
loadMinecraftVersion(getProfile().getMinecraftProvider().getVersionById(v));
}
/**
* Anaylze the jar of selected minecraft version of current profile to get
* Anaylze the jar of selected minecraft version of current getProfile() to
* get
* the version.
*
* @param v
@@ -1487,17 +1483,15 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
txtMinecraftVersion.setText("");
if (v == null)
return;
minecraftVersion = MinecraftVersionRequest.minecraftVersion(v.getJar(profile.getGameDirFile()));
minecraftVersion = MinecraftVersionRequest.minecraftVersion(v.getJar(getProfile().getGameDirFile()));
txtMinecraftVersion.setText(MinecraftVersionRequest.getResponse(minecraftVersion));
}
//</editor-fold>
// <editor-fold defaultstate="collapsed" desc="Game Download">
public void refreshDownloads() {
DefaultTableModel model = (DefaultTableModel) lstDownloads.getModel();
while (model.getRowCount() > 0)
model.removeRow(0);
profile.getMinecraftProvider().getDownloadService().getRemoteVersions()
DefaultTableModel model = SwingUtils.clearDefaultTable(lstDownloads);
getProfile().getMinecraftProvider().getDownloadService().getRemoteVersions()
.observeOn(Schedulers.eventQueue()).subscribeOn(Schedulers.newThread())
.subscribe((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}),
@@ -1508,12 +1502,12 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
}
void downloadMinecraft() {
if (profile == null || lstDownloads.getSelectedRow() < 0) {
if (getProfile() == null || lstDownloads.getSelectedRow() < 0) {
MessageBox.Show(C.i18n("gamedownload.not_refreshed"));
return;
}
String id = (String) lstDownloads.getModel().getValueAt(lstDownloads.getSelectedRow(), 0);
profile.getMinecraftProvider().getDownloadService().downloadMinecraft(id);
getProfile().getMinecraftProvider().getDownloadService().downloadMinecraft(id);
}
// </editor-fold>
@@ -1530,7 +1524,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
Transferable tr = dtde.getTransferable();
List<File> files = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
for (File file : files)
profile.getMinecraftProvider().getModService().addMod(file);
getProfile().getMinecraftProvider().getModService().addMod(file);
} catch (Exception ex) {
HMCLog.warn("Failed to drop file.", ex);
}
@@ -1586,7 +1580,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
MessageBox.Show(C.i18n("install.not_refreshed"));
return;
}
profile.getInstallerService().download(getVersion(idx), id).after(new TaskRunnable(this::refreshVersions)).run();
getProfile().getInstallerService().download(getVersion(idx), id).after(new TaskRunnable(this::refreshVersions)).run();
}
private List<InstallerVersionList.InstallerVersion> loadVersions(InstallerVersionList list, JTable table) {
@@ -1615,36 +1609,21 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
loadVersions();
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Variables">
boolean isLoading = false;
Profile profile;
public MinecraftVersionRequest minecraftVersion;
InstallerHelper forge, optifine, liteloader;
String mcVersion;
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Mods">
private final Object lockMod = new Object();
private void reloadMods() {
new Thread(() -> {
synchronized (lockMod) {
profile.getMinecraftProvider().getModService().recacheMods();
SwingUtilities.invokeLater(() -> {
synchronized (lockMod) {
SwingUtils.clearDefaultTable(lstExternalMods);
DefaultTableModel model = (DefaultTableModel) lstExternalMods.getModel();
for (ModInfo info : profile.getMinecraftProvider().getModService().getMods())
model.addRow(new Object[] {info.isActive(), info.getFileName(), info.version});
}
});
}
}).start();
DefaultTableModel model = SwingUtils.clearDefaultTable(lstExternalMods);
Observable.<List<ModInfo>>createWithEmptySubscription(
t -> t.onNext(getProfile().getMinecraftProvider().getModService().recacheMods()))
.subscribeOn(Schedulers.newThread()).observeOn(Schedulers.eventQueue())
.flatMap(t -> Observable.from(t))
.subscribe(t -> model.addRow(new Object[] {t.isActive(), t.getFileName(), t.version}));
}
// </editor-fold>
public void versionChanged(Profile profile, String version) {
public void versionChanged(String version) {
this.mcVersion = version;
forge.loadVersions();
optifine.loadVersions();
@@ -1655,12 +1634,12 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
public void onSelected() {
loadProfiles();
if (profile == null)
if (getProfile() == null)
return;
if (profile.getMinecraftProvider().getVersionCount() <= 0)
versionChanged(profile, null);
if (getProfile().getMinecraftProvider().getVersionCount() <= 0)
versionChanged(null);
else
versionChanged(getProfile(), (String) cboVersions.getSelectedItem());
versionChanged((String) cboVersions.getSelectedItem());
}
public void showGameDownloads() {

View File

@@ -293,7 +293,7 @@ public final class MainFrame extends DraggableFrame {
backgroundLabel.setIcon(background);
centralPanel.add(backgroundLabel, -1);
} else
HMCLog.warn("No Background Image, the background will be white!");
HMCLog.warn("No Background Image, the background will be empty!");
}
public JPanel getTitleBar() {

View File

@@ -25,7 +25,7 @@ import org.jackhuang.hellominecraft.logging.logger.Logger;
*/
public class HMCLog {
public static Logger logger = new Logger("HMC");
public static Logger logger = new Logger("Hello Minecraft!");
public static void log(String message) {
logger.info(message);

View File

@@ -17,6 +17,7 @@
*/
package org.jackhuang.hellominecraft.tasks;
import java.awt.EventQueue;
import java.util.ArrayList;
import java.util.LinkedList;
import javax.swing.SwingUtilities;
@@ -33,11 +34,11 @@ import org.jackhuang.hellominecraft.utils.SwingUtils;
public class TaskWindow extends javax.swing.JDialog
implements ProgressProviderListener, Runnable, DoingDoneListener<Task> {
private static final TaskWindow instance = new TaskWindow();
private static final TaskWindow INSTANCE = new TaskWindow();
private static TaskWindow inst() {
instance.clean();
return instance;
INSTANCE.clean();
return INSTANCE;
}
public static TaskWindowFactory getInstance() {
@@ -200,12 +201,13 @@ implements ProgressProviderListener, Runnable, DoingDoneListener<Task> {
private javax.swing.JScrollPane srlDownload;
// End of variables declaration//GEN-END:variables
ArrayList<Task> tasks = new ArrayList<>();
ArrayList<Integer> progresses = new ArrayList<>();
final ArrayList<Task> tasks = new ArrayList<>();
final ArrayList<Integer> progresses = new ArrayList<>();
@Override
public void setProgress(Task task, int progress, int max) {
SwingUtilities.invokeLater(() -> {
if (task == null) return;
int idx = tasks.indexOf(task);
if (idx == -1)
return;
@@ -229,7 +231,7 @@ implements ProgressProviderListener, Runnable, DoingDoneListener<Task> {
task.setProgressProviderListener(this);
SwingUtilities.invokeLater(() -> {
if (taskList == null)
if (taskList == null || task == null)
return;
tasks.add(task);
progresses.add(0);
@@ -245,7 +247,7 @@ implements ProgressProviderListener, Runnable, DoingDoneListener<Task> {
@Override
public void onDone(Task task) {
SwingUtilities.invokeLater(() -> {
if (taskList == null)
if (taskList == null || task == null)
return;
pgsTotal.setMaximum(taskList.taskCount());
pgsTotal.setValue(pgsTotal.getValue() + 1);
@@ -261,7 +263,7 @@ implements ProgressProviderListener, Runnable, DoingDoneListener<Task> {
@Override
public void onFailed(Task task) {
SwingUtilities.invokeLater(() -> {
if (taskList == null)
if (taskList == null || task == null)
return;
failReasons.add(task.getInfo() + ": " + (null == task.getFailReason() ? "No exception" : (StrUtils.isBlank(task.getFailReason().getLocalizedMessage()) ? task.getFailReason().getClass().getSimpleName() : task.getFailReason().getLocalizedMessage())));
pgsTotal.setMaximum(taskList.taskCount());
@@ -283,7 +285,7 @@ implements ProgressProviderListener, Runnable, DoingDoneListener<Task> {
@Override
public void setStatus(Task task, String sta) {
SwingUtilities.invokeLater(() -> {
if (taskList == null)
if (taskList == null || task == null)
return;
int idx = tasks.indexOf(task);
if (idx == -1)
@@ -295,6 +297,7 @@ implements ProgressProviderListener, Runnable, DoingDoneListener<Task> {
public static class TaskWindowFactory {
LinkedList<Task> ll = new LinkedList<>();
boolean flag;
public TaskWindowFactory addTask(Task t) {
ll.add(t);
@@ -302,14 +305,28 @@ implements ProgressProviderListener, Runnable, DoingDoneListener<Task> {
}
public boolean start() {
synchronized (instance) {
if (instance.isVisible())
return false;
Runnable r = () -> {
synchronized (INSTANCE) {
if (INSTANCE.isVisible()) {
flag = false;
return;
}
TaskWindow tw = inst();
for (Task t : ll)
tw.addTask(t);
return tw.start();
}
flag = tw.start();
}
};
if (EventQueue.isDispatchThread())
r.run();
else
try {
EventQueue.invokeAndWait(r);
} catch (Exception e) {
HMCLog.err("Failed to invokeAndWait, the UI will work abnormally.", e);
r.run();
}
return flag;
}
}
}

View File

@@ -30,7 +30,6 @@ import java.util.Map;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.utils.system.IOUtils;
import rx.Observable;
import rx.subscriptions.Subscriptions;
/**
*
@@ -160,13 +159,12 @@ public final class NetUtils {
}
public static Observable<String> getRx(String url) {
return Observable.create(t1 -> {
return Observable.createWithEmptySubscription(t1 -> {
try {
t1.onNext(get(url));
} catch(Exception e) {
t1.onError(e);
}
return Subscriptions.empty();
});
}
}

View File

@@ -131,12 +131,15 @@ public class SwingUtils {
* Clear the JTable
*
* @param table JTable with DefaultTableModel.
*
* @return To make the code succinct
*/
public static void clearDefaultTable(JTable table) {
public static DefaultTableModel clearDefaultTable(JTable table) {
DefaultTableModel model = (DefaultTableModel) table.getModel();
while (model.getRowCount() > 0)
model.removeRow(0);
table.updateUI();
return model;
}
public static void appendLast(JTable table, Object... elements) {

View File

@@ -93,9 +93,10 @@ public final class Utils {
return new ImageIcon(i.getImage().getScaledInstance(x, y, Image.SCALE_SMOOTH));
}
public static ImageIcon searchBackgroundImage(ImageIcon background, String bgpath, int width, int height) {
public static ImageIcon searchBackgroundImage(ImageIcon init, String bgpath, int width, int height) {
Random r = new Random();
boolean loaded = false;
ImageIcon background = init;
// bgpath
if (StrUtils.isNotBlank(bgpath) && !loaded) {
@@ -142,6 +143,7 @@ public final class Utils {
}
}
if (background == null) return init;
return background;
}

File diff suppressed because it is too large Load Diff

View File

@@ -240,7 +240,7 @@ mainwindow.enter_script_name=\u8f93\u5165\u8981\u751f\u6210\u811a\u672c\u7684\u6
mainwindow.make_launch_succeed=\u542f\u52a8\u811a\u672c\u5df2\u751f\u6210\u5b8c\u6bd5:
mainwindow.no_version=\u672a\u627e\u5230\u4efb\u4f55\u7248\u672c\uff0c\u662f\u5426\u8fdb\u5165\u6e38\u620f\u4e0b\u8f7d\uff1f
launcher.about=<html>\u9ed8\u8ba4\u80cc\u666f\u56fe\u6765\u81eaLiberty Dome\u670d\u52a1\u5668\u3002<br/>\u5173\u4e8e\u4f5c\u8005\uff1a<br/>\n\u767e\u5ea6ID\uff1ahuanghongxun20<br/>\nmcbbs\uff1ahuanghongxun<br/>\n\u90ae\u7bb1\uff1ahuanghongxun2008@126.com<br/>\nMinecraft Forum ID: klkl6523<br/>\n\u6b22\u8fce\u63d0\u4ea4Bug\u54e6<br/>\nCopyright (c) 2013-2015 huangyuhui.<br/>\u514d\u8d23\u58f0\u660e\uff1aMinecraft\u8f6f\u4ef6\u7248\u6743\u5f52Mojang AB\u6240\u6709\uff0c\u6e38\u620f\u7531\u4e8e\u8bef\u64cd\u4f5c\u672c\u542f\u52a8\u5668\u800c\u4e22\u5931\u6570\u636e\u7684\u6982\u4e0d\u8d1f\u8d23\u3002<br/>\u672c\u542f\u52a8\u5668\u5728GPLv2\u534f\u8bae\u4e0b\u5f00\u6e90:http://github.com/huanghongxun/HMCL/</html>
launcher.about=<html>\u9ed8\u8ba4\u80cc\u666f\u56fe\u6765\u81eaLiberty Dome\u670d\u52a1\u5668\u3002<br/>\u5173\u4e8e\u4f5c\u8005\uff1a<br/>\n\u767e\u5ea6ID\uff1ahuanghongxun20<br/>\nmcbbs\uff1ahuanghongxun<br/>\n\u90ae\u7bb1\uff1ahuanghongxun2008@126.com<br/>\nMinecraft Forum ID: klkl6523<br/>\n\u6b22\u8fce\u63d0\u4ea4Bug\u54e6<br/>\nCopyright (c) 2013-2015 huangyuhui.<br/>\u514d\u8d23\u58f0\u660e\uff1aMinecraft\u8f6f\u4ef6\u7248\u6743\u5f52Mojang AB\u6240\u6709\uff0c\u6e38\u620f\u7531\u4e8e\u8bef\u64cd\u4f5c\u672c\u542f\u52a8\u5668\u800c\u4e22\u5931\u6570\u636e\u7684\u6982\u4e0d\u8d1f\u8d23\u3002<br/>\u672c\u542f\u52a8\u5668\u5728GPLv3\u534f\u8bae\u4e0b\u5f00\u6e90:http://github.com/huanghongxun/HMCL/<br/>\u672c\u8f6f\u4ef6\u4f7f\u7528\u4e86\u57fa\u4e8eApache License 2.0\u7684RxJava\u548cGson\u9879\u76ee\uff0c\u611f\u8c22\u8d21\u732e\u8005\u3002</html>
launcher.download_source=\u4e0b\u8f7d\u6e90
launcher.background_location=\u80cc\u666f\u5730\u5740
launcher.exit_failed=\u5f3a\u5236\u9000\u51fa\u5931\u8d25\uff0c\u53ef\u80fd\u662fForge 1.7.10\u53ca\u66f4\u9ad8\u7248\u672c\u5bfc\u81f4\u7684\uff0c\u65e0\u6cd5\u89e3\u51b3\u3002

View File

@@ -240,7 +240,7 @@ mainwindow.enter_script_name=Enter the script name.
mainwindow.make_launch_succeed=Finished script creation.
mainwindow.no_version=No version found. Switch to Game Downloads Tab?
launcher.about=<html>About Author<br/>\nEmail\uff1ahuanghongxun2008@126.com<br/>\nMinecraft Forum ID: klkl6523<br/>\nCopyright (c) 2013 huangyuhui<br/>Opened source under GPL v2 licence:http://github.com/huanghongxun/HMCL/</html>
launcher.about=<html>About Author<br/>\nEmail\uff1ahuanghongxun2008@126.com<br/>\nMinecraft Forum ID: klkl6523<br/>\nCopyright (c) 2013 huangyuhui<br/>Opened source under GPL v3 license:http://github.com/huanghongxun/HMCL/<br/>This software used project RxJava and Gson which is under Apache License 2.0, thanks contributors.</html>
launcher.download_source=Download Source
launcher.background_location=Background Location
launcher.exit_failed=Failed to shutdown.

View File

@@ -240,7 +240,7 @@ mainwindow.enter_script_name=\u8f38\u5165\u8981\u751f\u6210\u8173\u672c\u7684\u6
mainwindow.make_launch_succeed=\u555f\u52d5\u8173\u672c\u5df2\u751f\u6210\u5b8c\u7562:
mainwindow.no_version=\u672a\u627e\u5230\u4efb\u4f55\u7248\u672c\uff0c\u662f\u5426\u9032\u5165\u904a\u6232\u4e0b\u8f09\uff1f
launcher.about=<html>\u9ed8\u8a8d\u80cc\u666f\u5716\u4f86\u81eaLiberty Dome\u670d\u52d9\u5668\u3002 <br/>\u95dc\u65bc\u4f5c\u8005\uff1a<br/>\n\u767e\u5ea6ID\uff1ahuanghongxun20<br/>\nmcbbs\uff1ahuanghongxun<br/>\n\u90f5\u7bb1\uff1ahuanghongxun2008@126.com<br/>\nMinecraft Forum ID: klkl6523<br />\n\u6b61\u8fce\u63d0\u4ea4Bug\u54e6<br/>\nCopyright (c) 2013-2015 huangyuhui.<br/>\u514d\u8cac\u8072\u660e\uff1aMinecraft\u8edf\u4ef6\u7248\u6b0a\u6b78Mojang AB\u6240\u6709\uff0c\u904a\u6232\u7531\u65bc\u8aa4\u64cd\u4f5c\u672c\u555f\u52d5\u5668\u800c\u4e1f\u5931\u6578\u64da\u7684\u6982\u4e0d\u8ca0\u8cac\u3002 <br/>\u672c\u555f\u52d5\u5668\u5728GPLv2\u5354\u8b70\u4e0b\u958b\u6e90:http://github.com/huanghongxun/HMCL/</html>
launcher.about=<html>\u9ed8\u8a8d\u80cc\u666f\u5716\u4f86\u81eaLiberty Dome\u670d\u52d9\u5668\u3002 <br/>\u95dc\u65bc\u4f5c\u8005\uff1a<br/>\n\u767e\u5ea6ID\uff1ahuanghongxun20<br/>\nmcbbs\uff1ahuanghongxun<br/>\n\u90f5\u7bb1\uff1ahuanghongxun2008@126.com<br/>\nMinecraft Forum ID: klkl6523<br />\n\u6b61\u8fce\u63d0\u4ea4Bug\u54e6<br/>\nCopyright (c) 2013-2015 huangyuhui.<br/>\u514d\u8cac\u8072\u660e\uff1aMinecraft\u8edf\u4ef6\u7248\u6b0a\u6b78Mojang AB\u6240\u6709\uff0c\u904a\u6232\u7531\u65bc\u8aa4\u64cd\u4f5c\u672c\u555f\u52d5\u5668\u800c\u4e1f\u5931\u6578\u64da\u7684\u6982\u4e0d\u8ca0\u8cac\u3002 <br/>\u672c\u555f\u52d5\u5668\u5728GPLv3\u5354\u8b70\u4e0b\u958b\u6e90:http://github.com/huanghongxun/HMCL/<br/>\u672c\u8edf\u4ef6\u4f7f\u7528\u4e86\u57fa\u65bcApache License 2.0\u7684RxJava\u548cGson\u9805\u76ee\uff0c\u611f\u8b1d\u8ca2\u737b\u8005\u3002</html>
launcher.download_source=\u4e0b\u8f09\u6e90
launcher.background_location=\u80cc\u666f\u5730\u5740
launcher.exit_failed=\u5f37\u5236\u9000\u51fa\u5931\u6557\uff0c\u53ef\u80fd\u662fForge 1.7.10\u53ca\u66f4\u9ad8\u7248\u672c\u5c0e\u81f4\u7684\uff0c\u7121\u6cd5\u89e3\u6c7a\u3002

View File

@@ -237,7 +237,7 @@ mainwindow.enter_script_name=\u8f93\u5165\u8981\u751f\u6210\u811a\u672c\u7684\u6
mainwindow.make_launch_succeed=\u542f\u52a8\u811a\u672c\u5df2\u751f\u6210\u5b8c\u6bd5:
mainwindow.no_version=\u672a\u627e\u5230\u4efb\u4f55\u7248\u672c\uff0c\u662f\u5426\u8fdb\u5165\u6e38\u620f\u4e0b\u8f7d\uff1f
launcher.about=<html>\u9ed8\u8ba4\u80cc\u666f\u56fe\u6765\u81eaLiberty Dome\u670d\u52a1\u5668\u3002<br/>\u5173\u4e8e\u4f5c\u8005\uff1a<br/>\n\u767e\u5ea6ID\uff1ahuanghongxun20<br/>\nmcbbs\uff1ahuanghongxun<br/>\n\u90ae\u7bb1\uff1ahuanghongxun2008@126.com<br/>\nMinecraft Forum ID: klkl6523<br/>\n\u6b22\u8fce\u63d0\u4ea4Bug\u54e6<br/>\nCopyright (c) 2013-2015 huangyuhui.<br/>\u514d\u8d23\u58f0\u660e\uff1aMinecraft\u8f6f\u4ef6\u7248\u6743\u5f52Mojang AB\u6240\u6709\uff0c\u6e38\u620f\u7531\u4e8e\u8bef\u64cd\u4f5c\u672c\u542f\u52a8\u5668\u800c\u4e22\u5931\u6570\u636e\u7684\u6982\u4e0d\u8d1f\u8d23\u3002<br/>\u672c\u542f\u52a8\u5668\u5728GPLv2\u534f\u8bae\u4e0b\u5f00\u6e90:http://github.com/huanghongxun/HMCL/</html>
launcher.about=<html>\u9ed8\u8ba4\u80cc\u666f\u56fe\u6765\u81eaLiberty Dome\u670d\u52a1\u5668\u3002<br/>\u5173\u4e8e\u4f5c\u8005\uff1a<br/>\n\u767e\u5ea6ID\uff1ahuanghongxun20<br/>\nmcbbs\uff1ahuanghongxun<br/>\n\u90ae\u7bb1\uff1ahuanghongxun2008@126.com<br/>\nMinecraft Forum ID: klkl6523<br/>\n\u6b22\u8fce\u63d0\u4ea4Bug\u54e6<br/>\nCopyright (c) 2013-2015 huangyuhui.<br/>\u514d\u8d23\u58f0\u660e\uff1aMinecraft\u8f6f\u4ef6\u7248\u6743\u5f52Mojang AB\u6240\u6709\uff0c\u6e38\u620f\u7531\u4e8e\u8bef\u64cd\u4f5c\u672c\u542f\u52a8\u5668\u800c\u4e22\u5931\u6570\u636e\u7684\u6982\u4e0d\u8d1f\u8d23\u3002<br/>\u672c\u542f\u52a8\u5668\u5728GPLv3\u534f\u8bae\u4e0b\u5f00\u6e90:http://github.com/huanghongxun/HMCL/<br/>\u672c\u8f6f\u4ef6\u4f7f\u7528\u4e86\u57fa\u4e8eApache License 2.0\u7684RxJava\u548cGson\u9879\u76ee\uff0c\u611f\u8c22\u8d21\u732e\u8005\u3002</html>
launcher.download_source=\u4e0b\u8f7d\u6e90
launcher.background_location=\u80cc\u666f\u5730\u5740
launcher.exit_failed=\u5f3a\u5236\u9000\u51fa\u5931\u8d25\uff0c\u53ef\u80fd\u662fForge 1.7.10\u53ca\u66f4\u9ad8\u7248\u672c\u5bfc\u81f4\u7684\uff0c\u65e0\u6cd5\u89e3\u51b3\u3002