Fixed username missing

This commit is contained in:
huangyuhui
2016-02-12 13:03:19 +08:00
parent 8f90d56e0f
commit d09607766b
11 changed files with 100 additions and 95 deletions

View File

@@ -26,7 +26,7 @@ if (!hasProperty('mainClass')) {
ext.mainClass = 'org.jackhuang.hellominecraft.launcher.Main' ext.mainClass = 'org.jackhuang.hellominecraft.launcher.Main'
} }
def buildnumber = System.getenv("BUILD_NUMBER") == null ? ".27" : "."+System.getenv("BUILD_NUMBER") def buildnumber = System.getenv("BUILD_NUMBER") == null ? ".10" : "."+System.getenv("BUILD_NUMBER")
String mavenGroupId = 'HMCL' String mavenGroupId = 'HMCL'
String mavenVersion = '2.4.0' + buildnumber String mavenVersion = '2.4.0' + buildnumber

View File

@@ -88,7 +88,7 @@ public abstract class IAuthenticator {
public abstract void logOut(); public abstract void logOut();
public Map onSaveSettings() { public Map onSaveSettings() {
HashMap m = new HashMap(); HashMap<String, String> m = new HashMap<>();
m.put("IAuthenticator_UserName", username); m.put("IAuthenticator_UserName", username);
return m; return m;
} }

View File

@@ -48,7 +48,7 @@ public final class OfflineAuthenticator extends IAuthenticator {
@Override @Override
public Map onSaveSettings() { public Map onSaveSettings() {
Map m = super.onSaveSettings(); Map m = super.onSaveSettings();
m.put("uuidMap", m); m.put("uuidMap", uuidMap);
return m; return m;
} }

View File

@@ -198,16 +198,15 @@ public class MinecraftVersionManager extends IMinecraftProvider {
@Override @Override
public boolean install(String id, Consumer<MinecraftVersion> callback) { public boolean install(String id, Consumer<MinecraftVersion> callback) {
MinecraftVersion v = service.download().downloadMinecraft(id); MinecraftVersion v = service.download().downloadMinecraft(id);
if (v == null)
return false;
if (callback != null) { if (callback != null) {
callback.accept(v); callback.accept(v);
File mvt = new File(versionRoot(id), id + ".json"); File mvt = new File(versionRoot(id), id + ".json");
FileUtils.writeQuietly(mvt, C.GSON.toJson(v)); FileUtils.writeQuietly(mvt, C.GSON.toJson(v));
} }
if (v != null) { refreshVersions();
refreshVersions(); return true;
return true;
}
return false;
} }
@Override @Override

View File

@@ -93,6 +93,8 @@ public final class Config {
} }
public String getLast() { public String getLast() {
if (last == null)
last = Settings.DEFAULT_PROFILE;
return last; return last;
} }

View File

@@ -95,21 +95,29 @@ public final class Settings {
} }
public static Profile getLastProfile() { public static Profile getLastProfile() {
if (!hasProfile(getInstance().getLast()))
getInstance().setLast(DEFAULT_PROFILE);
return getProfile(getInstance().getLast()); return getProfile(getInstance().getLast());
} }
public static Profile getProfile(String name) { public static Profile getProfile(String name) {
Profile p;
if (name == null) if (name == null)
p = getProfiles().get("Default"); name = DEFAULT_PROFILE;
else Profile p = getProfiles().get(name);
p = getProfiles().get(name);
if (p == null) if (p == null)
if (!getProfiles().containsKey(DEFAULT_PROFILE)) if (getProfiles().containsKey(DEFAULT_PROFILE))
p = getProfiles().get(DEFAULT_PROFILE);
else
getProfiles().put(DEFAULT_PROFILE, p = new Profile()); getProfiles().put(DEFAULT_PROFILE, p = new Profile());
return p; return p;
} }
public static boolean hasProfile(String name) {
if (name == null)
name = DEFAULT_PROFILE;
return getProfiles().containsKey(name);
}
public static Map<String, Profile> getProfiles() { public static Map<String, Profile> getProfiles() {
return SETTINGS.getConfigurations(); return SETTINGS.getConfigurations();
} }

View File

@@ -18,6 +18,7 @@
package org.jackhuang.hellominecraft.launcher.ui; package org.jackhuang.hellominecraft.launcher.ui;
import javax.swing.table.DefaultTableModel; import javax.swing.table.DefaultTableModel;
import org.jackhuang.hellominecraft.launcher.setting.Settings;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.MessageBox; import org.jackhuang.hellominecraft.util.MessageBox;
import org.jackhuang.hellominecraft.util.StrUtils; import org.jackhuang.hellominecraft.util.StrUtils;
@@ -104,7 +105,7 @@ public class GameDownloadPanel extends AnimatedPanel {
public void refreshDownloads() { public void refreshDownloads() {
DefaultTableModel model = SwingUtils.clearDefaultTable(lstDownloads); DefaultTableModel model = SwingUtils.clearDefaultTable(lstDownloads);
gsp.getProfile().service().download().getRemoteVersions() Settings.getLastProfile().service().download().getRemoteVersions()
.reg((ver) -> model.addRow(new Object[] { ver.id, ver.time, .reg((ver) -> model.addRow(new Object[] { ver.id, ver.time,
StrUtils.equalsOne(ver.type, "old_beta", "old_alpha", "release", "snapshot") ? C.i18n("versions." + ver.type) : ver.type })) StrUtils.equalsOne(ver.type, "old_beta", "old_alpha", "release", "snapshot") ? C.i18n("versions." + ver.type) : ver.type }))
.regDone(lstDownloads::updateUI).execute(); .regDone(lstDownloads::updateUI).execute();
@@ -120,7 +121,7 @@ public class GameDownloadPanel extends AnimatedPanel {
return; return;
} }
String id = (String) lstDownloads.getModel().getValueAt(lstDownloads.getSelectedRow(), 0); String id = (String) lstDownloads.getModel().getValueAt(lstDownloads.getSelectedRow(), 0);
gsp.getProfile().service().download().downloadMinecraft(id); Settings.getLastProfile().service().download().downloadMinecraft(id);
} }
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
@@ -130,13 +131,13 @@ public class GameDownloadPanel extends AnimatedPanel {
private javax.swing.JTable lstDownloads; private javax.swing.JTable lstDownloads;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
boolean selected = false; boolean refreshedDownloads = false;
@Override @Override
public void onSelected() { public void onSelected() {
super.onSelected(); super.onSelected();
if (!selected) { if (!refreshedDownloads) {
selected = true; refreshedDownloads = true;
refreshDownloads(); refreshDownloads();
} }
} }

View File

@@ -121,7 +121,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
getProfile().service().version().open(mcVersion, a); Settings.getLastProfile().service().version().open(mcVersion, a);
} }
} }
JMenuItem itm; JMenuItem itm;
@@ -152,7 +152,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
if (mcVersion != null) { if (mcVersion != null) {
String newName = JOptionPane.showInputDialog(C.i18n("versions.manage.rename.message"), mcVersion); String newName = JOptionPane.showInputDialog(C.i18n("versions.manage.rename.message"), mcVersion);
if (newName != null) if (newName != null)
if (getProfile().service().version().renameVersion(mcVersion, newName)) if (Settings.getLastProfile().service().version().renameVersion(mcVersion, newName))
refreshVersions(); refreshVersions();
} }
}); });
@@ -160,26 +160,26 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
itm = new JMenuItem(C.i18n("versions.manage.remove")); itm = new JMenuItem(C.i18n("versions.manage.remove"));
itm.addActionListener((e) -> { itm.addActionListener((e) -> {
if (mcVersion != null && MessageBox.Show(C.i18n("versions.manage.remove.confirm") + mcVersion, MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) if (mcVersion != null && MessageBox.Show(C.i18n("versions.manage.remove.confirm") + mcVersion, MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
if (getProfile().service().version().removeVersionFromDisk(mcVersion)) if (Settings.getLastProfile().service().version().removeVersionFromDisk(mcVersion))
refreshVersions(); refreshVersions();
}); });
ppmManage.add(itm); ppmManage.add(itm);
itm = new JMenuItem(C.i18n("versions.manage.redownload_json")); itm = new JMenuItem(C.i18n("versions.manage.redownload_json"));
itm.addActionListener((e) -> { itm.addActionListener((e) -> {
if (mcVersion != null) if (mcVersion != null)
getProfile().service().download().downloadMinecraftVersionJson(mcVersion); Settings.getLastProfile().service().download().downloadMinecraftVersionJson(mcVersion);
}); });
ppmManage.add(itm); ppmManage.add(itm);
itm = new JMenuItem(C.i18n("versions.manage.redownload_assets_index")); itm = new JMenuItem(C.i18n("versions.manage.redownload_assets_index"));
itm.addActionListener((e) -> { itm.addActionListener((e) -> {
if (mcVersion != null) if (mcVersion != null)
getProfile().service().asset().refreshAssetsIndex(mcVersion); Settings.getLastProfile().service().asset().refreshAssetsIndex(mcVersion);
}); });
ppmManage.add(itm); ppmManage.add(itm);
itm = new JMenuItem(C.i18n("versions.mamage.remove_libraries")); itm = new JMenuItem(C.i18n("versions.mamage.remove_libraries"));
itm.addActionListener((e) -> { itm.addActionListener((e) -> {
if (mcVersion != null) if (mcVersion != null)
FileUtils.deleteDirectoryQuietly(new File(getProfile().service().baseDirectory(), "libraries")); FileUtils.deleteDirectoryQuietly(new File(Settings.getLastProfile().service().baseDirectory(), "libraries"));
}); });
ppmManage.add(itm); ppmManage.add(itm);
} }
@@ -192,7 +192,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
} }
lstExternalMods.getSelectionModel().addListSelectionListener(e -> { lstExternalMods.getSelectionModel().addListSelectionListener(e -> {
int row = lstExternalMods.getSelectedRow(); int row = lstExternalMods.getSelectedRow();
List<ModInfo> mods = getProfile().service().mod().getMods(getProfile().getSelectedVersion()); List<ModInfo> mods = Settings.getLastProfile().service().mod().getMods(Settings.getLastProfile().getSelectedVersion());
if (mods != null && 0 <= row && row < mods.size()) { if (mods != null && 0 <= row && row < mods.size()) {
ModInfo m = mods.get(row); ModInfo m = mods.get(row);
boolean hasLink = m.url != null; boolean hasLink = m.url != null;
@@ -212,7 +212,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
((DefaultTableModel) lstExternalMods.getModel()).addTableModelListener(e -> { ((DefaultTableModel) lstExternalMods.getModel()).addTableModelListener(e -> {
if (e.getType() == TableModelEvent.UPDATE && e.getColumn() == 0) { if (e.getType() == TableModelEvent.UPDATE && e.getColumn() == 0) {
int row = lstExternalMods.getSelectedRow(); int row = lstExternalMods.getSelectedRow();
List<ModInfo> mods = getProfile().service().mod().getMods(getProfile().getSelectedVersion()); List<ModInfo> mods = Settings.getLastProfile().service().mod().getMods(Settings.getLastProfile().getSelectedVersion());
if (mods != null && mods.size() > row && row >= 0) if (mods != null && mods.size() > row && row >= 0)
mods.get(row).reverseModState(); mods.get(row).reverseModState();
} }
@@ -947,16 +947,16 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
}//GEN-LAST:event_btnNewProfileActionPerformed }//GEN-LAST:event_btnNewProfileActionPerformed
private void btnRemoveProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveProfileActionPerformed private void btnRemoveProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveProfileActionPerformed
if (MessageBox.Show(C.i18n("ui.message.sure_remove", getProfile().getName()), MessageBox.YES_NO_OPTION) == MessageBox.NO_OPTION) if (MessageBox.Show(C.i18n("ui.message.sure_remove", Settings.getLastProfile().getName()), MessageBox.YES_NO_OPTION) == MessageBox.NO_OPTION)
return; return;
if (Settings.delProfile(getProfile())) if (Settings.delProfile(Settings.getLastProfile()))
loadProfiles(); loadProfiles();
}//GEN-LAST:event_btnRemoveProfileActionPerformed }//GEN-LAST:event_btnRemoveProfileActionPerformed
private void cboVersionsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboVersionsItemStateChanged private void cboVersionsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboVersionsItemStateChanged
if (isLoading || evt.getStateChange() != ItemEvent.SELECTED || cboVersions.getSelectedIndex() < 0 || StrUtils.isBlank((String) cboVersions.getSelectedItem())) if (isLoading || evt.getStateChange() != ItemEvent.SELECTED || cboVersions.getSelectedIndex() < 0 || StrUtils.isBlank((String) cboVersions.getSelectedItem()))
return; return;
getProfile().setSelectedMinecraftVersion((String) cboVersions.getSelectedItem()); Settings.getLastProfile().setSelectedMinecraftVersion((String) cboVersions.getSelectedItem());
}//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
@@ -973,11 +973,11 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
private void btnDownloadAllAssetsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadAllAssetsActionPerformed private void btnDownloadAllAssetsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadAllAssetsActionPerformed
if (mcVersion != null) if (mcVersion != null)
getProfile().service().asset().downloadAssets(mcVersion).run(); Settings.getLastProfile().service().asset().downloadAssets(mcVersion).run();
}//GEN-LAST:event_btnDownloadAllAssetsActionPerformed }//GEN-LAST:event_btnDownloadAllAssetsActionPerformed
private void txtGameDirFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtGameDirFocusLost private void txtGameDirFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtGameDirFocusLost
getProfile().setGameDir(txtGameDir.getText()); Settings.getLastProfile().setGameDir(txtGameDir.getText());
loadVersions(); loadVersions();
}//GEN-LAST:event_txtGameDirFocusLost }//GEN-LAST:event_txtGameDirFocusLost
@@ -997,7 +997,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
try { try {
String path = fc.getSelectedFile().getCanonicalPath(); String path = fc.getSelectedFile().getCanonicalPath();
txtJavaDir.setText(path); txtJavaDir.setText(path);
getProfile().getSelectedVersionSetting().setJavaDir(txtJavaDir.getText()); Settings.getLastProfile().getSelectedVersionSetting().setJavaDir(txtJavaDir.getText());
} catch (IOException e) { } catch (IOException e) {
HMCLog.warn("Failed to set java path.", e); HMCLog.warn("Failed to set java path.", e);
MessageBox.Show(C.i18n("ui.label.failed_set") + e.getMessage()); MessageBox.Show(C.i18n("ui.label.failed_set") + e.getMessage());
@@ -1010,9 +1010,9 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
int idx = cboJava.getSelectedIndex(); int idx = cboJava.getSelectedIndex();
if (idx != -1) { if (idx != -1) {
Java j = Java.JAVA.get(idx); Java j = Java.JAVA.get(idx);
getProfile().getSelectedVersionSetting().setJava(j); Settings.getLastProfile().getSelectedVersionSetting().setJava(j);
txtJavaDir.setEnabled(idx == 1); txtJavaDir.setEnabled(idx == 1);
txtJavaDir.setText(j.getHome() == null ? getProfile().getSelectedVersionSetting().getSettingsJavaDir() : j.getJava()); txtJavaDir.setText(j.getHome() == null ? Settings.getLastProfile().getSelectedVersionSetting().getSettingsJavaDir() : j.getJava());
} }
}//GEN-LAST:event_cboJavaItemStateChanged }//GEN-LAST:event_cboJavaItemStateChanged
@@ -1025,14 +1025,14 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
return; return;
boolean flag = true; boolean flag = true;
for (File f : fc.getSelectedFiles()) for (File f : fc.getSelectedFiles())
flag &= getProfile().service().mod().addMod(getProfile().getSelectedVersion(), f); flag &= Settings.getLastProfile().service().mod().addMod(Settings.getLastProfile().getSelectedVersion(), f);
reloadMods(); reloadMods();
if (!flag) if (!flag)
MessageBox.Show(C.i18n("mods.failed")); MessageBox.Show(C.i18n("mods.failed"));
}//GEN-LAST:event_btnAddModActionPerformed }//GEN-LAST:event_btnAddModActionPerformed
private void btnRemoveModActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveModActionPerformed private void btnRemoveModActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveModActionPerformed
getProfile().service().mod().removeMod(getProfile().getSelectedVersion(), SwingUtils.getValueBySelectedRow(lstExternalMods, lstExternalMods.getSelectedRows(), 1)); Settings.getLastProfile().service().mod().removeMod(Settings.getLastProfile().getSelectedVersion(), SwingUtils.getValueBySelectedRow(lstExternalMods, lstExternalMods.getSelectedRows(), 1));
reloadMods(); reloadMods();
}//GEN-LAST:event_btnRemoveModActionPerformed }//GEN-LAST:event_btnRemoveModActionPerformed
@@ -1043,8 +1043,8 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
private void lblModInfoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblModInfoMouseClicked private void lblModInfoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblModInfoMouseClicked
int idx = lstExternalMods.getSelectedRow(); int idx = lstExternalMods.getSelectedRow();
if (idx > 0 && idx < getProfile().service().mod().getMods(getProfile().getSelectedVersion()).size()) if (idx > 0 && idx < Settings.getLastProfile().service().mod().getMods(Settings.getLastProfile().getSelectedVersion()).size())
SwingUtils.openLink(getProfile().service().mod().getMods(getProfile().getSelectedVersion()).get(idx).url); SwingUtils.openLink(Settings.getLastProfile().service().mod().getMods(Settings.getLastProfile().getSelectedVersion()).get(idx).url);
}//GEN-LAST:event_lblModInfoMouseClicked }//GEN-LAST:event_lblModInfoMouseClicked
private void btnChoosingGameDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChoosingGameDirActionPerformed private void btnChoosingGameDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChoosingGameDirActionPerformed
@@ -1058,7 +1058,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
try { try {
String path = fc.getSelectedFile().getCanonicalPath(); String path = fc.getSelectedFile().getCanonicalPath();
txtGameDir.setText(path); txtGameDir.setText(path);
getProfile().setGameDir(path); Settings.getLastProfile().setGameDir(path);
} catch (IOException e) { } catch (IOException e) {
HMCLog.warn("Failed to set game dir.", e); HMCLog.warn("Failed to set game dir.", e);
MessageBox.Show(C.i18n("ui.label.failed_set") + e.getMessage()); MessageBox.Show(C.i18n("ui.label.failed_set") + e.getMessage());
@@ -1066,12 +1066,12 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
}//GEN-LAST:event_btnChoosingGameDirActionPerformed }//GEN-LAST:event_btnChoosingGameDirActionPerformed
private void btnCleanGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCleanGameActionPerformed private void btnCleanGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCleanGameActionPerformed
getProfile().service().version().cleanFolder(); Settings.getLastProfile().service().version().cleanFolder();
}//GEN-LAST:event_btnCleanGameActionPerformed }//GEN-LAST:event_btnCleanGameActionPerformed
private void btnTestGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTestGameActionPerformed private void btnTestGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTestGameActionPerformed
LogWindow.INSTANCE.setVisible(true); LogWindow.INSTANCE.setVisible(true);
MainFrame.INSTANCE.daemon.runGame(getProfile()); MainFrame.INSTANCE.daemon.runGame(Settings.getLastProfile());
}//GEN-LAST:event_btnTestGameActionPerformed }//GEN-LAST:event_btnTestGameActionPerformed
private void btnShowLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShowLogActionPerformed private void btnShowLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShowLogActionPerformed
@@ -1079,7 +1079,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
}//GEN-LAST:event_btnShowLogActionPerformed }//GEN-LAST:event_btnShowLogActionPerformed
private void btnMakeLaunchScriptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMakeLaunchScriptActionPerformed private void btnMakeLaunchScriptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMakeLaunchScriptActionPerformed
MainFrame.INSTANCE.daemon.makeLaunchScript(getProfile()); MainFrame.INSTANCE.daemon.makeLaunchScript(Settings.getLastProfile());
}//GEN-LAST:event_btnMakeLaunchScriptActionPerformed }//GEN-LAST:event_btnMakeLaunchScriptActionPerformed
private void btnIncludeMinecraftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIncludeMinecraftActionPerformed private void btnIncludeMinecraftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIncludeMinecraftActionPerformed
@@ -1100,80 +1100,72 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
private void cboRunDirectoryItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboRunDirectoryItemStateChanged private void cboRunDirectoryItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboRunDirectoryItemStateChanged
if (!isLoading && cboRunDirectory.getSelectedIndex() >= 0) if (!isLoading && cboRunDirectory.getSelectedIndex() >= 0)
getProfile().getSelectedVersionSetting().setGameDirType(GameDirType.values()[cboRunDirectory.getSelectedIndex()]); Settings.getLastProfile().getSelectedVersionSetting().setGameDirType(GameDirType.values()[cboRunDirectory.getSelectedIndex()]);
}//GEN-LAST:event_cboRunDirectoryItemStateChanged }//GEN-LAST:event_cboRunDirectoryItemStateChanged
private void cboLauncherVisibilityItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboLauncherVisibilityItemStateChanged private void cboLauncherVisibilityItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboLauncherVisibilityItemStateChanged
if (!isLoading && cboLauncherVisibility.getSelectedIndex() >= 0) if (!isLoading && cboLauncherVisibility.getSelectedIndex() >= 0)
getProfile().getSelectedVersionSetting().setLauncherVisibility(LauncherVisibility.values()[cboLauncherVisibility.getSelectedIndex()]); Settings.getLastProfile().getSelectedVersionSetting().setLauncherVisibility(LauncherVisibility.values()[cboLauncherVisibility.getSelectedIndex()]);
}//GEN-LAST:event_cboLauncherVisibilityItemStateChanged }//GEN-LAST:event_cboLauncherVisibilityItemStateChanged
private void chkFullscreenItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkFullscreenItemStateChanged private void chkFullscreenItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkFullscreenItemStateChanged
if (!isLoading) if (!isLoading)
getProfile().getSelectedVersionSetting().setFullscreen(chkFullscreen.isSelected()); Settings.getLastProfile().getSelectedVersionSetting().setFullscreen(chkFullscreen.isSelected());
}//GEN-LAST:event_chkFullscreenItemStateChanged }//GEN-LAST:event_chkFullscreenItemStateChanged
private void chkDebugItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkDebugItemStateChanged private void chkDebugItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkDebugItemStateChanged
if (!isLoading) if (!isLoading)
getProfile().getSelectedVersionSetting().setDebug(chkDebug.isSelected()); Settings.getLastProfile().getSelectedVersionSetting().setDebug(chkDebug.isSelected());
}//GEN-LAST:event_chkDebugItemStateChanged }//GEN-LAST:event_chkDebugItemStateChanged
private void chkCancelWrapperItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkCancelWrapperItemStateChanged private void chkCancelWrapperItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkCancelWrapperItemStateChanged
if (!isLoading) if (!isLoading)
getProfile().getSelectedVersionSetting().setCanceledWrapper(chkCancelWrapper.isSelected()); Settings.getLastProfile().getSelectedVersionSetting().setCanceledWrapper(chkCancelWrapper.isSelected());
}//GEN-LAST:event_chkCancelWrapperItemStateChanged }//GEN-LAST:event_chkCancelWrapperItemStateChanged
private void chkNoJVMArgsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkNoJVMArgsItemStateChanged private void chkNoJVMArgsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkNoJVMArgsItemStateChanged
if (!isLoading) if (!isLoading)
getProfile().getSelectedVersionSetting().setNoJVMArgs(chkNoJVMArgs.isSelected()); Settings.getLastProfile().getSelectedVersionSetting().setNoJVMArgs(chkNoJVMArgs.isSelected());
}//GEN-LAST:event_chkNoJVMArgsItemStateChanged }//GEN-LAST:event_chkNoJVMArgsItemStateChanged
private void txtMaxMemoryFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMaxMemoryFocusLost private void txtMaxMemoryFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMaxMemoryFocusLost
getProfile().getSelectedVersionSetting().setMaxMemory(txtMaxMemory.getText()); Settings.getLastProfile().getSelectedVersionSetting().setMaxMemory(txtMaxMemory.getText());
}//GEN-LAST:event_txtMaxMemoryFocusLost }//GEN-LAST:event_txtMaxMemoryFocusLost
private void txtWidthFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtWidthFocusLost private void txtWidthFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtWidthFocusLost
getProfile().getSelectedVersionSetting().setWidth(txtWidth.getText()); Settings.getLastProfile().getSelectedVersionSetting().setWidth(txtWidth.getText());
}//GEN-LAST:event_txtWidthFocusLost }//GEN-LAST:event_txtWidthFocusLost
private void txtHeightFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtHeightFocusLost private void txtHeightFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtHeightFocusLost
getProfile().getSelectedVersionSetting().setHeight(txtHeight.getText()); Settings.getLastProfile().getSelectedVersionSetting().setHeight(txtHeight.getText());
}//GEN-LAST:event_txtHeightFocusLost }//GEN-LAST:event_txtHeightFocusLost
private void txtJavaDirFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtJavaDirFocusLost private void txtJavaDirFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtJavaDirFocusLost
getProfile().getSelectedVersionSetting().setJavaDir(txtJavaDir.getText()); Settings.getLastProfile().getSelectedVersionSetting().setJavaDir(txtJavaDir.getText());
}//GEN-LAST:event_txtJavaDirFocusLost }//GEN-LAST:event_txtJavaDirFocusLost
private void txtJavaArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtJavaArgsFocusLost private void txtJavaArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtJavaArgsFocusLost
getProfile().getSelectedVersionSetting().setJavaArgs(txtJavaArgs.getText()); Settings.getLastProfile().getSelectedVersionSetting().setJavaArgs(txtJavaArgs.getText());
}//GEN-LAST:event_txtJavaArgsFocusLost }//GEN-LAST:event_txtJavaArgsFocusLost
private void txtMinecraftArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMinecraftArgsFocusLost private void txtMinecraftArgsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMinecraftArgsFocusLost
getProfile().getSelectedVersionSetting().setMinecraftArgs(txtMinecraftArgs.getText()); Settings.getLastProfile().getSelectedVersionSetting().setMinecraftArgs(txtMinecraftArgs.getText());
}//GEN-LAST:event_txtMinecraftArgsFocusLost }//GEN-LAST:event_txtMinecraftArgsFocusLost
private void txtPermSizeFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPermSizeFocusLost private void txtPermSizeFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPermSizeFocusLost
getProfile().getSelectedVersionSetting().setPermSize(txtPermSize.getText()); Settings.getLastProfile().getSelectedVersionSetting().setPermSize(txtPermSize.getText());
}//GEN-LAST:event_txtPermSizeFocusLost }//GEN-LAST:event_txtPermSizeFocusLost
private void txtPrecalledCommandFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPrecalledCommandFocusLost private void txtPrecalledCommandFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPrecalledCommandFocusLost
getProfile().getSelectedVersionSetting().setPrecalledCommand(txtPrecalledCommand.getText()); Settings.getLastProfile().getSelectedVersionSetting().setPrecalledCommand(txtPrecalledCommand.getText());
}//GEN-LAST:event_txtPrecalledCommandFocusLost }//GEN-LAST:event_txtPrecalledCommandFocusLost
private void txtServerIPFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtServerIPFocusLost private void txtServerIPFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtServerIPFocusLost
getProfile().getSelectedVersionSetting().setServerIp(txtServerIP.getText()); Settings.getLastProfile().getSelectedVersionSetting().setServerIp(txtServerIP.getText());
}//GEN-LAST:event_txtServerIPFocusLost }//GEN-LAST:event_txtServerIPFocusLost
// </editor-fold> // </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Load"> // <editor-fold defaultstate="collapsed" desc="Load">
final Profile getProfile() {
return Settings.getProfile((String) cboProfiles.getSelectedItem());
}
final String mcVersion() {
return getProfile().getSelectedVersion();
}
void prepareVersionSetting(VersionSetting profile) { void prepareVersionSetting(VersionSetting profile) {
if (profile == null) if (profile == null)
return; return;
@@ -1206,7 +1198,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
txtMinecraftVersion.setText(""); txtMinecraftVersion.setText("");
if (id == null) if (id == null)
return; return;
minecraftVersion = MinecraftVersionRequest.minecraftVersion(getProfile().service().version().getMinecraftJar(id)); minecraftVersion = MinecraftVersionRequest.minecraftVersion(Settings.getLastProfile().service().version().getMinecraftJar(id));
txtMinecraftVersion.setText(MinecraftVersionRequest.getResponse(minecraftVersion)); txtMinecraftVersion.setText(MinecraftVersionRequest.getResponse(minecraftVersion));
} }
@@ -1224,7 +1216,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
Transferable tr = dtde.getTransferable(); Transferable tr = dtde.getTransferable();
List<File> files = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor); List<File> files = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
for (File file : files) for (File file : files)
getProfile().service().mod().addMod(getProfile().getSelectedVersion(), file); Settings.getLastProfile().service().mod().addMod(Settings.getLastProfile().getSelectedVersion(), file);
} catch (Exception ex) { } catch (Exception ex) {
HMCLog.warn("Failed to drop file.", ex); HMCLog.warn("Failed to drop file.", ex);
} }
@@ -1247,7 +1239,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
} }
void refreshVersions() { void refreshVersions() {
getProfile().service().version().refreshVersions(); Settings.getLastProfile().service().version().refreshVersions();
} }
// </editor-fold> // </editor-fold>
@@ -1264,7 +1256,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
new OverridableSwingWorker<List<ModInfo>>() { new OverridableSwingWorker<List<ModInfo>>() {
@Override @Override
protected void work() throws Exception { protected void work() throws Exception {
publish(getProfile().service().mod().recacheMods(getProfile().getSelectedVersion())); publish(Settings.getLastProfile().service().mod().recacheMods(Settings.getLastProfile().getSelectedVersion()));
} }
}.reg(t -> { }.reg(t -> {
synchronized (modLock) { synchronized (modLock) {
@@ -1278,7 +1270,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
// </editor-fold> // </editor-fold>
void save() { void save() {
VersionSetting vs = getProfile().getSelectedVersionSetting(); VersionSetting vs = Settings.getLastProfile().getSelectedVersionSetting();
if (txtServerIP.hasFocus()) if (txtServerIP.hasFocus())
vs.setServerIp(txtServerIP.getText()); vs.setServerIp(txtServerIP.getText());
if (txtPrecalledCommand.hasFocus()) if (txtPrecalledCommand.hasFocus())
@@ -1398,20 +1390,20 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
} }
final Consumer<IMinecraftService> onRefreshedVersions = t -> { final Consumer<IMinecraftService> onRefreshedVersions = t -> {
if (getProfile().service() == t) if (Settings.getLastProfile().service() == t)
loadVersions(); loadVersions();
}; };
void loadVersions() { void loadVersions() {
DefaultComboBoxModel model = new DefaultComboBoxModel(); DefaultComboBoxModel model = new DefaultComboBoxModel();
for (MinecraftVersion each : getProfile().service().version().getVersions()) { for (MinecraftVersion each : Settings.getLastProfile().service().version().getVersions()) {
if (each.hidden) if (each.hidden)
continue; continue;
model.addElement(each.id); model.addElement(each.id);
} }
cboVersions.setModel(model); cboVersions.setModel(model);
if (getProfile().getSelectedVersion() != null) if (Settings.getLastProfile().getSelectedVersion() != null)
selectedVersionChangedEvent.accept(getProfile().getSelectedVersion()); selectedVersionChangedEvent.accept(Settings.getLastProfile().getSelectedVersion());
} }
final Consumer<String> selectedVersionChangedEvent = this::versionChanged; final Consumer<String> selectedVersionChangedEvent = this::versionChanged;
@@ -1423,7 +1415,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
this.mcVersion = version; this.mcVersion = version;
reloadMods(); reloadMods();
prepareVersionSetting(getProfile().getVersionSetting(version)); prepareVersionSetting(Settings.getLastProfile().getVersionSetting(version));
loadMinecraftVersion(version); loadMinecraftVersion(version);
for (InstallerPanel p : installerPanels) for (InstallerPanel p : installerPanels)
p.loadVersions(); p.loadVersions();

View File

@@ -139,7 +139,7 @@ public class InstallerPanel extends AnimatedPanel {
MessageBox.Show(C.i18n("install.not_refreshed")); MessageBox.Show(C.i18n("install.not_refreshed"));
return; return;
} }
gsp.getProfile().service().install().download(gsp.getProfile().getSelectedVersion(), getVersion(idx), id).after(new TaskRunnable(this::refreshVersions)).run(); Settings.getLastProfile().service().install().download(Settings.getLastProfile().getSelectedVersion(), getVersion(idx), id).after(new TaskRunnable(this::refreshVersions)).run();
} }
public void loadVersions() { public void loadVersions() {

View File

@@ -69,7 +69,7 @@ public class MainPagePanel extends AnimatedPanel {
btnRun.setText(C.i18n("ui.button.run")); btnRun.setText(C.i18n("ui.button.run"));
btnRun.setFont(newFont); btnRun.setFont(newFont);
btnRun.addActionListener(e -> MainFrame.INSTANCE.daemon.runGame(getProfile())); btnRun.addActionListener(e -> MainFrame.INSTANCE.daemon.runGame(Settings.getLastProfile()));
this.add(pnlButtons); this.add(pnlButtons);
pnlButtons.setBounds(0, 0, w, h); pnlButtons.setBounds(0, 0, w, h);
@@ -324,10 +324,10 @@ public class MainPagePanel extends AnimatedPanel {
}//GEN-LAST:event_cboProfilesItemStateChanged }//GEN-LAST:event_cboProfilesItemStateChanged
private void cboVersionsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboVersionsItemStateChanged private void cboVersionsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboVersionsItemStateChanged
if (isLoading || evt.getStateChange() != ItemEvent.SELECTED || cboVersions.getSelectedIndex() < 0 || StrUtils.isBlank((String) cboVersions.getSelectedItem()) || getProfile() == null) if (isLoading || evt.getStateChange() != ItemEvent.SELECTED || cboVersions.getSelectedIndex() < 0 || StrUtils.isBlank((String) cboVersions.getSelectedItem()))
return; return;
String mcv = (String) cboVersions.getSelectedItem(); String mcv = (String) cboVersions.getSelectedItem();
getProfile().setSelectedMinecraftVersion(mcv); Settings.getLastProfile().setSelectedMinecraftVersion(mcv);
}//GEN-LAST:event_cboVersionsItemStateChanged }//GEN-LAST:event_cboVersionsItemStateChanged
private void txtPasswordFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPasswordFocusGained private void txtPasswordFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPasswordFocusGained
@@ -335,7 +335,7 @@ public class MainPagePanel extends AnimatedPanel {
}//GEN-LAST:event_txtPasswordFocusGained }//GEN-LAST:event_txtPasswordFocusGained
private void txtPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPasswordActionPerformed private void txtPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPasswordActionPerformed
MainFrame.INSTANCE.daemon.runGame(getProfile()); MainFrame.INSTANCE.daemon.runGame(Settings.getLastProfile());
}//GEN-LAST:event_txtPasswordActionPerformed }//GEN-LAST:event_txtPasswordActionPerformed
private void btnLogoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLogoutActionPerformed private void btnLogoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLogoutActionPerformed
@@ -355,7 +355,7 @@ public class MainPagePanel extends AnimatedPanel {
IAuthenticator l = Settings.getInstance().getAuthenticator(); IAuthenticator l = Settings.getInstance().getAuthenticator();
l.setUserName(txtPlayerName.getText()); l.setUserName(txtPlayerName.getText());
if (!l.hasPassword()) if (!l.hasPassword())
MainFrame.INSTANCE.daemon.runGame(getProfile()); MainFrame.INSTANCE.daemon.runGame(Settings.getLastProfile());
else if (!l.isLoggedIn()) else if (!l.isLoggedIn())
txtPassword.requestFocus(); txtPassword.requestFocus();
} }
@@ -363,7 +363,7 @@ public class MainPagePanel extends AnimatedPanel {
private void txtPasswordKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPasswordKeyPressed private void txtPasswordKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPasswordKeyPressed
if (evt.getKeyCode() == KeyEvent.VK_ENTER) if (evt.getKeyCode() == KeyEvent.VK_ENTER)
MainFrame.INSTANCE.daemon.runGame(getProfile()); MainFrame.INSTANCE.daemon.runGame(Settings.getLastProfile());
}//GEN-LAST:event_txtPasswordKeyPressed }//GEN-LAST:event_txtPasswordKeyPressed
private void btnImportModpackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImportModpackActionPerformed private void btnImportModpackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImportModpackActionPerformed
@@ -376,14 +376,14 @@ public class MainPagePanel extends AnimatedPanel {
if (fc.getSelectedFile() == null) if (fc.getSelectedFile() == null)
return; return;
String suggestedModpackId = JOptionPane.showInputDialog("Please enter your favourite game name", FileUtils.getBaseName(fc.getSelectedFile().getName())); String suggestedModpackId = JOptionPane.showInputDialog("Please enter your favourite game name", FileUtils.getBaseName(fc.getSelectedFile().getName()));
TaskWindow.factory().append(ModpackManager.install(fc.getSelectedFile(), getProfile().service(), suggestedModpackId)).create(); TaskWindow.factory().append(ModpackManager.install(fc.getSelectedFile(), Settings.getLastProfile().service(), suggestedModpackId)).create();
getProfile().service().version().refreshVersions(); Settings.getLastProfile().service().version().refreshVersions();
}//GEN-LAST:event_btnImportModpackActionPerformed }//GEN-LAST:event_btnImportModpackActionPerformed
private void btnExportModpackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportModpackActionPerformed private void btnExportModpackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportModpackActionPerformed
if (getProfile().service().version().getVersionCount() <= 0) if (Settings.getLastProfile().service().version().getVersionCount() <= 0)
return; return;
WizardDisplayer.showWizard(new ModpackWizard(getProfile().service()).createWizard()); WizardDisplayer.showWizard(new ModpackWizard(Settings.getLastProfile().service()).createWizard());
}//GEN-LAST:event_btnExportModpackActionPerformed }//GEN-LAST:event_btnExportModpackActionPerformed
private void txtPasswordCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_txtPasswordCaretUpdate private void txtPasswordCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_txtPasswordCaretUpdate
@@ -413,10 +413,6 @@ public class MainPagePanel extends AnimatedPanel {
private static final int DEFAULT_WIDTH = 800, DEFAULT_HEIGHT = 480; private static final int DEFAULT_WIDTH = 800, DEFAULT_HEIGHT = 480;
//</editor-fold> //</editor-fold>
public Profile getProfile() {
return Settings.getProfile(Settings.getInstance().getLast());
}
@Override @Override
public void onCreated() { public void onCreated() {
super.onCreated(); super.onCreated();
@@ -475,7 +471,7 @@ public class MainPagePanel extends AnimatedPanel {
} }
final Consumer<IMinecraftService> onRefreshedVersions = t -> { final Consumer<IMinecraftService> onRefreshedVersions = t -> {
if (getProfile().service() == t) if (Settings.getLastProfile().service() == t)
loadVersions(); loadVersions();
}; };
@@ -484,8 +480,8 @@ public class MainPagePanel extends AnimatedPanel {
void loadVersions() { void loadVersions() {
isLoading = true; isLoading = true;
cboVersions.removeAllItems(); cboVersions.removeAllItems();
String selVersion = getProfile().getSelectedVersion(); String selVersion = Settings.getLastProfile().getSelectedVersion();
if (getProfile().service().version().getVersions().isEmpty()) { if (Settings.getLastProfile().service().version().getVersions().isEmpty()) {
if (!showedNoVersion) if (!showedNoVersion)
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
if (MessageBox.Show(C.i18n("mainwindow.no_version"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) if (MessageBox.Show(C.i18n("mainwindow.no_version"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
@@ -493,7 +489,7 @@ public class MainPagePanel extends AnimatedPanel {
showedNoVersion = true; showedNoVersion = true;
}); });
} else { } else {
for (MinecraftVersion mcVersion : getProfile().service().version().getVersions()) { for (MinecraftVersion mcVersion : Settings.getLastProfile().service().version().getVersions()) {
if (mcVersion.hidden) if (mcVersion.hidden)
continue; continue;
cboVersions.addItem(mcVersion.id); cboVersions.addItem(mcVersion.id);

View File

@@ -17,6 +17,7 @@
*/ */
package org.jackhuang.hellominecraft.launcher.util; package org.jackhuang.hellominecraft.launcher.util;
import com.google.gson.JsonSyntaxException;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -39,6 +40,7 @@ import org.jackhuang.hellominecraft.launcher.core.mod.ModpackManager;
import org.jackhuang.hellominecraft.launcher.setting.Profile; import org.jackhuang.hellominecraft.launcher.setting.Profile;
import org.jackhuang.hellominecraft.launcher.setting.VersionSetting; import org.jackhuang.hellominecraft.launcher.setting.VersionSetting;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.logging.HMCLog;
import org.jackhuang.hellominecraft.util.system.FileUtils; import org.jackhuang.hellominecraft.util.system.FileUtils;
import org.jackhuang.hellominecraft.util.tasks.TaskWindow; import org.jackhuang.hellominecraft.util.tasks.TaskWindow;
@@ -88,7 +90,12 @@ public class DefaultMinecraftService extends IMinecraftService {
if (f.exists()) { if (f.exists()) {
String s = FileUtils.readFileToStringQuietly(f); String s = FileUtils.readFileToStringQuietly(f);
if (s != null) if (s != null)
vs = C.GSON.fromJson(s, VersionSetting.class); try {
vs = C.GSON.fromJson(s, VersionSetting.class);
} catch (JsonSyntaxException ex) {
HMCLog.warn("Failed to load version setting: " + id, ex);
vs = null;
}
} }
if (vs == null) if (vs == null)
vs = new VersionSetting(); vs = new VersionSetting();