Skip to content

Commit

Permalink
Fixed auto-loading when deleting a profile
Browse files Browse the repository at this point in the history
  • Loading branch information
huanghongxun committed Mar 12, 2016
1 parent e7d0624 commit cafcf45
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Profile() {
}

public Profile(String name) {
this(name, IOUtils.currentDir().getPath());
this(name, new File(IOUtils.currentDir(), ".minecraft").getPath());
}

public Profile(String name, String gameDir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public static Config getInstance() {
DownloadType.setSuggestedDownloadType(SETTINGS.getDownloadSource());
if (!getProfiles().containsKey(DEFAULT_PROFILE))
getProfiles().put(DEFAULT_PROFILE, new Profile(DEFAULT_PROFILE));
if (!getProfiles().containsKey(HOME_PROFILE))
getProfiles().put(HOME_PROFILE, new Profile(HOME_PROFILE, MCUtils.getLocation().getPath()));

for (Map.Entry<String, Profile> entry : getProfiles().entrySet()) {
Profile e = entry.getValue();
Expand All @@ -85,8 +83,11 @@ private static Config initSettings() {
} catch (IOException | JsonSyntaxException e) {
HMCLog.warn("Something happened wrongly when load settings.", e);
}
else
else {
HMCLog.log("No settings file here, may be first loading.");
if (!c.getConfigurations().containsKey(HOME_PROFILE))
c.getConfigurations().put(HOME_PROFILE, new Profile(HOME_PROFILE, MCUtils.getLocation().getPath()));
}
return c;
}

Expand Down Expand Up @@ -154,7 +155,13 @@ public static boolean delProfile(String ver) {
MessageBox.Show(C.i18n("settings.cannot_remove_default_config"));
return false;
}
return getProfiles().remove(ver) != null;
boolean notify = false;
if (getLastProfile().getName().equals(ver))
notify = true;
boolean flag = getProfiles().remove(ver) != null;
if (notify && flag)
onProfileChanged();
return flag;
}

public static final EventHandler<Profile> profileChangedEvent = new EventHandler(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,8 +949,7 @@ private void btnNewProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN
private void btnRemoveProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveProfileActionPerformed
if (MessageBox.Show(C.i18n("ui.message.sure_remove", Settings.getLastProfile().getName()), MessageBox.YES_NO_OPTION) == MessageBox.NO_OPTION)
return;
if (Settings.delProfile(Settings.getLastProfile()))
loadProfiles();
Settings.delProfile(Settings.getLastProfile());
}//GEN-LAST:event_btnRemoveProfileActionPerformed

private void cboVersionsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboVersionsItemStateChanged
Expand Down

0 comments on commit cafcf45

Please sign in to comment.