Now can choose Java Installation in Windows

This commit is contained in:
huanghongxun
2015-08-04 15:13:04 +08:00
parent 4a167253db
commit 95598df273
15 changed files with 887 additions and 625 deletions

View File

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

File diff suppressed because it is too large Load Diff

View File

@@ -25,6 +25,7 @@ import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.utils.Utils;
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersionManager;
import org.jackhuang.hellominecraft.utils.system.Java;
import org.jackhuang.hellominecraft.utils.system.OS;
/**
@@ -34,7 +35,7 @@ import org.jackhuang.hellominecraft.utils.system.OS;
public final class Profile {
private String name, selectedMinecraftVersion = "", javaArgs, minecraftArgs, maxMemory, permSize, width, height, userProperties;
private String gameDir, javaDir, wrapperLauncher, serverIp;
private String gameDir, javaDir, wrapperLauncher, serverIp, java;
private boolean fullscreen, debug, noJVMArgs, canceledWrapper;
/**
@@ -60,7 +61,8 @@ public final class Profile {
this.name = name;
gameDir = MCUtils.getInitGameDir().getPath();
debug = fullscreen = canceledWrapper = false;
javaDir = IOUtils.getJavaDir();
javaDir = "";
java = "Default";
launcherVisibility = gameDirType = 0;
minecraftArgs = serverIp = "";
}
@@ -73,6 +75,7 @@ public final class Profile {
maxMemory = v.maxMemory;
width = v.width;
height = v.height;
java = v.java;
fullscreen = v.fullscreen;
javaArgs = v.javaArgs;
javaDir = v.javaDir;
@@ -129,8 +132,12 @@ public final class Profile {
}
public String getJavaDir() {
if (StrUtils.isBlank(javaDir))
javaDir = IOUtils.getJavaDir();
Java j = getJava();
if (j.getHome() == null) return javaDir;
else return j.getJava();
}
public String getSettingsJavaDir() {
return javaDir;
}
@@ -143,6 +150,29 @@ public final class Profile {
Settings.save();
}
public Java getJava() {
return Settings.JAVA.get(getJavaIndexInAllJavas());
}
public int getJavaIndexInAllJavas() {
if(StrUtils.isBlank(java) && StrUtils.isNotBlank(javaDir)) {
java = "Custom";
}
int idx = Settings.JAVA.indexOf(new Java(java, null));
if (idx == -1) {
java = "Default";
idx = 0;
}
return idx;
}
public void setJava(Java java) {
int idx = Settings.JAVA.indexOf(java);
if (idx == -1) return;
this.java = java.getName();
Settings.save();
}
public File getFolder(String folder) {
return new File(getGameDir(), folder);
}

View File

@@ -19,7 +19,10 @@ package org.jackhuang.hellominecraft.launcher.settings;
import com.google.gson.JsonSyntaxException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.jackhuang.hellominecraft.C;
@@ -32,6 +35,8 @@ import org.jackhuang.hellominecraft.utils.system.MessageBox;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.utils.UpdateChecker;
import org.jackhuang.hellominecraft.utils.VersionNumber;
import org.jackhuang.hellominecraft.utils.system.Java;
import org.jackhuang.hellominecraft.utils.system.OS;
/**
*
@@ -42,11 +47,11 @@ public final class Settings {
public static final String DEFAULT_PROFILE = "Default";
public static final File settingsFile = new File(IOUtils.currentDir(), "hmcl.json");
//public static final Gson gson = new GsonBuilder().setPrettyPrinting().registerTypeAdapter(Platform.class, new EnumAdapter<>(Platform.values())).create();
private static boolean isFirstLoad;
private static final Config settings;
public static final UpdateChecker UPDATE_CHECKER;
public static final List<Java> JAVA;
public static Config getInstance() {
return settings;
@@ -66,6 +71,13 @@ public final class Settings {
UPDATE_CHECKER = new UpdateChecker(new VersionNumber(Main.firstVer, Main.secondVer, Main.thirdVer),
"hmcl", settings.isCheckUpdate(), () -> Main.invokeUpdate());
List<Java> temp = new ArrayList<>();
temp.add(new Java("Default", System.getProperty("java.home")));
temp.add(new Java("Custom", null));
if (OS.os() == OS.WINDOWS)
temp.addAll(Java.queryAllJavaHomeInWindowsByReg());
JAVA = Collections.unmodifiableList(temp);
}
private static Config initSettings() {

View File

@@ -64,6 +64,9 @@ public final class SkinmeAuthenticator extends IAuthenticator {
if (null != sl[0]) switch (sl[0]) {
case "0":
req.setSuccess(false);
if(sl[1].contains("No Valid Character")) {
sl[1] = C.i18n("login.no_valid_character");
}
req.setErrorReason(sl[1]);
break;
case "1": {

View File

@@ -312,7 +312,11 @@
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="txtMaxMemory" max="32767" attributes="0"/>
<Component id="txtJavaDir" max="32767" attributes="0"/>
<Group type="102" attributes="0">
<Component id="cboJava" min="-2" pref="100" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="txtJavaDir" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
@@ -339,7 +343,8 @@
<Group type="103" groupAlignment="3" attributes="0">
<Component id="txtJavaDir" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
<Component id="jLabel11" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnChoosingJavaDir" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnChoosingJavaDir" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
<Component id="cboJava" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
@@ -506,6 +511,16 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnChoosingJavaDirActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JComboBox" name="cboJava">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="0"/>
</Property>
</Properties>
<Events>
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="cboJavaItemStateChanged"/>
</Events>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel2">
@@ -585,7 +600,7 @@
<Component id="jLabel31" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="txtServerIP" min="-2" pref="26" max="-2" attributes="0"/>
<EmptySpace pref="85" max="32767" attributes="0"/>
<EmptySpace pref="86" max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="chkDebug" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="chkNoJVMArgs" alignment="3" min="-2" max="-2" attributes="0"/>
@@ -745,7 +760,7 @@
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane11" pref="291" max="32767" attributes="0"/>
<Component id="jScrollPane11" pref="292" max="32767" attributes="0"/>
<Group type="102" attributes="0">
<Component id="btnDownloadForge" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
@@ -830,7 +845,7 @@
<Component id="btnDownloadOptifine" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnRefreshOptifine" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="239" max="32767" attributes="0"/>
<EmptySpace min="0" pref="240" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@@ -905,7 +920,7 @@
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane12" pref="291" max="32767" attributes="0"/>
<Component id="jScrollPane12" pref="292" max="32767" attributes="0"/>
<Group type="102" attributes="0">
<Component id="btnInstallLiteLoader" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
@@ -996,7 +1011,7 @@
<EmptySpace max="32767" attributes="0"/>
<Component id="btnDownload" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="jScrollPane2" pref="320" max="32767" attributes="0"/>
<Component id="jScrollPane2" pref="321" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>

View File

@@ -32,8 +32,6 @@ import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
@@ -65,6 +63,7 @@ import org.jackhuang.hellominecraft.version.MinecraftVersionRequest;
import org.jackhuang.hellominecraft.utils.system.OS;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.utils.SwingUtils;
import org.jackhuang.hellominecraft.utils.system.Java;
import org.jackhuang.hellominecraft.version.MinecraftRemoteVersion;
import org.jackhuang.hellominecraft.version.MinecraftRemoteVersions;
import org.jackhuang.hellominecraft.views.Selector;
@@ -161,6 +160,13 @@ public class GameSettingsPanel extends javax.swing.JPanel {
});
ppmManage.add(itm);
//</editor-fold>
for (Java j : Settings.JAVA) {
String name = j.getName();
if (name.equals("Default")) name = C.i18n("settings.default");
if (name.equals("Custom")) name = C.i18n("settings.custom");
cboJava.addItem(name);
}
}
/**
@@ -205,6 +211,7 @@ public class GameSettingsPanel extends javax.swing.JPanel {
jLabel12 = new javax.swing.JLabel();
cboGameDirType = new javax.swing.JComboBox();
btnChoosingJavaDir = new javax.swing.JButton();
cboJava = new javax.swing.JComboBox();
jPanel2 = new javax.swing.JPanel();
chkDebug = new javax.swing.JCheckBox();
jLabel26 = new javax.swing.JLabel();
@@ -470,6 +477,12 @@ public class GameSettingsPanel extends javax.swing.JPanel {
}
});
cboJava.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
cboJavaItemStateChanged(evt);
}
});
javax.swing.GroupLayout jPanel22Layout = new javax.swing.GroupLayout(jPanel22);
jPanel22.setLayout(jPanel22Layout);
jPanel22Layout.setHorizontalGroup(
@@ -504,7 +517,10 @@ public class GameSettingsPanel extends javax.swing.JPanel {
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel22Layout.createSequentialGroup()
.addGroup(jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtMaxMemory)
.addComponent(txtJavaDir))
.addGroup(jPanel22Layout.createSequentialGroup()
.addComponent(cboJava, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtJavaDir)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnChoosingJavaDir, javax.swing.GroupLayout.Alignment.TRAILING)
@@ -522,7 +538,8 @@ public class GameSettingsPanel extends javax.swing.JPanel {
.addGroup(jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtJavaDir, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel11)
.addComponent(btnChoosingJavaDir))
.addComponent(btnChoosingJavaDir, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cboJava, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblMaxMemory)
@@ -667,7 +684,7 @@ public class GameSettingsPanel extends javax.swing.JPanel {
.addComponent(jLabel31)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtServerIP, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 85, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 86, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(chkDebug)
.addComponent(chkNoJVMArgs)
@@ -710,7 +727,7 @@ public class GameSettingsPanel extends javax.swing.JPanel {
);
jPanel16Layout.setVerticalGroup(
jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane11, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
.addComponent(jScrollPane11, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
.addGroup(jPanel16Layout.createSequentialGroup()
.addComponent(btnDownloadForge)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
@@ -758,7 +775,7 @@ btnRefreshOptifine.addActionListener(new java.awt.event.ActionListener() {
.addComponent(btnDownloadOptifine)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnRefreshOptifine)
.addGap(0, 239, Short.MAX_VALUE))
.addGap(0, 240, Short.MAX_VALUE))
);
tabInstallers.addTab("OptiFine", pnlOptifine);
@@ -796,7 +813,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane12, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
.addComponent(jScrollPane12, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
.addGroup(jPanel3Layout.createSequentialGroup()
.addComponent(btnInstallLiteLoader)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
@@ -856,7 +873,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
.addComponent(btnRefreshGameDownloads)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnDownload))
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE)
);
tabVersionEdit.addTab(bundle.getString("settings.tabs.game_download"), pnlGameDownloads); // NOI18N
@@ -877,7 +894,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
.addContainerGap()
.addComponent(btnIncludeMinecraft)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(tabVersionEdit, javax.swing.GroupLayout.DEFAULT_SIZE, 684, Short.MAX_VALUE)
.addComponent(tabVersionEdit)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -1124,6 +1141,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
}//GEN-LAST:event_txtGameDirFocusLost
private void btnChoosingJavaDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChoosingJavaDirActionPerformed
if (cboJava.getSelectedIndex() != 1) return;
JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setDialogTitle(C.i18n("settings.choose_javapath"));
@@ -1144,6 +1162,18 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
}
}//GEN-LAST:event_btnChoosingJavaDirActionPerformed
private void cboJavaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboJavaItemStateChanged
if (isLoading || evt.getStateChange() != ItemEvent.SELECTED || cboJava.getSelectedIndex() < 0 || StrUtils.isBlank((String) cboJava.getSelectedItem()) || getProfile() == null)
return;
int idx = cboJava.getSelectedIndex();
if (idx != -1) {
Java j = Settings.JAVA.get(idx);
profile.setJava(j);
txtJavaDir.setEnabled(idx == 1);
txtJavaDir.setText(j.getHome() == null ? profile.getSettingsJavaDir() : j.getJava());
}
}//GEN-LAST:event_cboJavaItemStateChanged
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Load">
private void loadProfiles() {
@@ -1187,7 +1217,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
txtGameDir.setText(profile.getGameDir());
txtJavaArgs.setText(profile.getJavaArgs());
txtMinecraftArgs.setText(profile.getMinecraftArgs());
txtJavaDir.setText(profile.getJavaDir());
txtJavaDir.setText(profile.getSettingsJavaDir());
txtWrapperLauncher.setText(profile.getWrapperLauncher());
txtServerIP.setText(profile.getServerIp());
chkDebug.setSelected(profile.isDebug());
@@ -1197,6 +1227,11 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
cboLauncherVisibility.setSelectedIndex(profile.getLauncherVisibility().ordinal());
cboGameDirType.setSelectedIndex(profile.getGameDirType().ordinal());
isLoading = true;
cboJava.setSelectedIndex(profile.getJavaIndexInAllJavas());
isLoading = false;
cboJavaItemStateChanged(new ItemEvent(cboJava, 0, cboJava.getSelectedItem(), ItemEvent.SELECTED));
loadVersions();
loadMinecraftVersion();
}
@@ -1416,6 +1451,7 @@ btnRefreshLiteLoader.addActionListener(new java.awt.event.ActionListener() {
private javax.swing.JButton btnRefreshVersions;
private javax.swing.JButton btnRemoveProfile;
private javax.swing.JComboBox cboGameDirType;
private javax.swing.JComboBox cboJava;
private javax.swing.JComboBox cboLauncherVisibility;
private javax.swing.JComboBox cboProfiles;
private javax.swing.JComboBox cboVersions;