mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-03-01 17:25:53 +08:00
Now can choose Java Installation in Windows
This commit is contained in:
parent
4a167253db
commit
95598df273
@ -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
@ -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);
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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": {
|
||||
|
@ -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>
|
||||
|
@ -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;
|
||||
|
@ -16,6 +16,7 @@
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.utils.system;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
@ -23,6 +24,7 @@ import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
@ -33,6 +35,7 @@ import java.net.SocketException;
|
||||
import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.jackhuang.hellominecraft.HMCLog;
|
||||
|
||||
/**
|
||||
@ -164,7 +167,11 @@ public class IOUtils {
|
||||
}
|
||||
|
||||
public static String getJavaDir() {
|
||||
String path = System.getProperty("java.home") + File.separatorChar + "bin" + File.separatorChar;
|
||||
return getJavaDir(System.getProperty("java.home"));
|
||||
}
|
||||
|
||||
public static String getJavaDir(String home) {
|
||||
String path = home + File.separatorChar + "bin" + File.separatorChar;
|
||||
path = addSeparator(path);
|
||||
if (OS.os() == OS.WINDOWS && new File(path + "javaw.exe").isFile())
|
||||
return path + "javaw.exe";
|
||||
@ -237,7 +244,7 @@ public class IOUtils {
|
||||
public static String tryGetCanonicalFolderPath(File file) {
|
||||
try {
|
||||
return IOUtils.addSeparator(file.getCanonicalPath());
|
||||
} catch (IOException ex) {
|
||||
} catch (IOException ignored) {
|
||||
return IOUtils.addSeparator(file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
@ -245,7 +252,7 @@ public class IOUtils {
|
||||
public static File tryGetCanonicalFile(File file) {
|
||||
try {
|
||||
return file.getCanonicalFile();
|
||||
} catch (IOException ex) {
|
||||
} catch (IOException ignored) {
|
||||
return file.getAbsoluteFile();
|
||||
}
|
||||
}
|
||||
@ -257,7 +264,7 @@ public class IOUtils {
|
||||
public static String tryGetCanonicalFilePath(File file) {
|
||||
try {
|
||||
return file.getCanonicalPath();
|
||||
} catch (IOException ex) {
|
||||
} catch (IOException ignored) {
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
}
|
||||
@ -270,4 +277,30 @@ public class IOUtils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> readProcessByInputStream(String[] cmd) throws IOException, InterruptedException {
|
||||
JavaProcess jp = new JavaProcess(cmd, new ProcessBuilder(cmd).start(), null);
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(jp.getRawProcess().getInputStream()))) {
|
||||
jp.getRawProcess().waitFor();
|
||||
String line;
|
||||
while((line = br.readLine()) != null) {
|
||||
lines.add(line);
|
||||
}
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
public static List<String> readProcessByErrorStream(String[] cmd) throws IOException, InterruptedException {
|
||||
JavaProcess jp = new JavaProcess(cmd, new ProcessBuilder(cmd).start(), null);
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(jp.getRawProcess().getErrorStream()))) {
|
||||
jp.getRawProcess().waitFor();
|
||||
String line;
|
||||
while((line = br.readLine()) != null) {
|
||||
lines.add(line);
|
||||
}
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.utils.system;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.jackhuang.hellominecraft.HMCLog;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class Java {
|
||||
String name, home;
|
||||
|
||||
public Java(String name, String home) {
|
||||
this.name = name;
|
||||
this.home = home;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getHome() {
|
||||
return home;
|
||||
}
|
||||
|
||||
public String getJava() {
|
||||
return IOUtils.getJavaDir(getHome());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof Java) {
|
||||
Java j = (Java) obj;
|
||||
return (j.getName() == null && this.getName() == null) || ((Java) obj).getName().equals(this.getName());
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
|
||||
public static List<Java> queryAllJavaHomeInWindowsByReg() {
|
||||
try {
|
||||
List<Java> ans = new ArrayList<>();
|
||||
List<String> javas = queryRegSubFolders("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment");
|
||||
for (String java : javas) {
|
||||
int s = 0;
|
||||
for (char c : java.toCharArray())
|
||||
if (c == '.') s++;
|
||||
if (s <= 1) continue;
|
||||
String javahome = queryRegValue(java, "JavaHome");
|
||||
if (javahome != null)
|
||||
ans.add(new Java(java.substring("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\".length()), javahome));
|
||||
}
|
||||
return ans;
|
||||
} catch (IOException | InterruptedException ex) {
|
||||
HMCLog.err("Faield to query java", ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> queryRegSubFolders(String location) throws IOException, InterruptedException {
|
||||
String[] cmd = new String[]{"cmd", "/c", "reg", "query", location};
|
||||
List<String> l = IOUtils.readProcessByInputStream(cmd);
|
||||
List<String> ans = new ArrayList<>();
|
||||
for (String line : l)
|
||||
if (line.startsWith(location) && !line.equals(location))
|
||||
ans.add(line);
|
||||
return ans;
|
||||
}
|
||||
|
||||
private static String queryRegValue(String location, String name) throws IOException, InterruptedException {
|
||||
String[] cmd = new String[]{"cmd", "/c", "reg", "query", location, "/v", name};
|
||||
List<String> l = IOUtils.readProcessByInputStream(cmd);
|
||||
if (l.size() < 3) return null;
|
||||
// 18 = 4 spaces + [name.length()] + 4 spaces + "REG_SZ".length()=6 characters + 4 spaces
|
||||
return l.get(2).substring(18 + name.length());
|
||||
}
|
||||
|
||||
}
|
@ -16,11 +16,8 @@
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.utils.system;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jackhuang.hellominecraft.HMCLog;
|
||||
@ -154,21 +151,14 @@ public final class JdkVersion {
|
||||
return jdkBit.contains("64");
|
||||
}
|
||||
|
||||
static Pattern p = Pattern.compile("java version \"[1-9]*\\.[1-9]*\\.[0-9]*(.*?)\"");
|
||||
private static final Pattern p = Pattern.compile("java version \"[1-9]*\\.[1-9]*\\.[0-9]*(.*?)\"");
|
||||
|
||||
public static JdkVersion getJavaVersionFromExecutable(String file) throws IOException {
|
||||
String[] str = new String[]{file, "-version"};
|
||||
ProcessBuilder pb = new ProcessBuilder(str);
|
||||
JavaProcess jp = new JavaProcess(str, pb.start(), null);
|
||||
InputStream is = jp.getRawProcess().getErrorStream();
|
||||
BufferedReader br = null;
|
||||
String ver = null;
|
||||
Platform platform = Platform.BIT_32;
|
||||
String ver = null;
|
||||
try {
|
||||
br = new BufferedReader(new InputStreamReader(is));
|
||||
String line;
|
||||
jp.getRawProcess().waitFor();
|
||||
while ((line = br.readLine()) != null) {
|
||||
for(String line : IOUtils.readProcessByErrorStream(str)) {
|
||||
Matcher m = p.matcher(line);
|
||||
if (m.find()) {
|
||||
ver = m.group();
|
||||
@ -179,9 +169,6 @@ public final class JdkVersion {
|
||||
}
|
||||
} catch (InterruptedException | IOException e) {
|
||||
HMCLog.warn("Failed to get java version", e);
|
||||
} finally {
|
||||
if (br != null)
|
||||
br.close();
|
||||
}
|
||||
return new JdkVersion(file, ver, platform);
|
||||
}
|
||||
|
@ -73,6 +73,7 @@ login.not_email=\u7528\u6237\u540d\u5fc5\u987b\u662f\u90ae\u7bb1
|
||||
login.type=\u767b\u5f55
|
||||
login.username=\u540d\u5b57
|
||||
login.account=\u90ae\u7bb1
|
||||
login.no_valid_character=\u65e0\u6709\u6548\u7684\u89d2\u8272\uff0c\u81ea\u884c\u5230skinme.cc\u767b\u9646\u5e76\u521b\u5efa\u89d2\u8272
|
||||
|
||||
proxy.username=\u8d26\u6237
|
||||
proxy.password=\u5bc6\u7801
|
||||
@ -192,6 +193,8 @@ settings.fullscreen=\u5168\u5c4f
|
||||
settings.update_version=\u66f4\u65b0\u7248\u672c\u6587\u4ef6
|
||||
settings.physical_memory=\u7269\u7406\u5185\u5b58\u5927\u5c0f
|
||||
settings.choose_javapath=\u9009\u62e9Java\u8def\u5f84
|
||||
settings.default=\u9ed8\u8ba4
|
||||
settings.custom=\u81ea\u5b9a\u4e49
|
||||
|
||||
settings.failed_load=\u8bbe\u7f6e\u6587\u4ef6\u52a0\u8f7d\u5931\u8d25\uff0c\u53ef\u80fd\u662f\u5347\u7ea7\u4e86\u542f\u52a8\u5668\u6216\u88ab\u4eba\u5de5\u4fee\u6539\u9020\u6210\u9519\u8bef\uff0c\u662f\u5426\u6e05\u9664\uff1f
|
||||
|
||||
|
@ -73,6 +73,7 @@ login.not_email=The username must be a e-mail.
|
||||
login.type=Login
|
||||
login.username=Name
|
||||
login.account=Email
|
||||
login.no_valid_character=No Valid Character, please visit skinme.cc and create your own character.
|
||||
|
||||
login.failed.connect_authentication_server=Cannot connect the authentication server. Check your network.
|
||||
|
||||
@ -187,6 +188,8 @@ settings.fullscreen=Fullscreen
|
||||
settings.update_version=Update version json.
|
||||
settings.physical_memory=Physical Memory Size
|
||||
settings.choose_javapath=Choose Java Directory.
|
||||
settings.default=Default
|
||||
settings.custom=Custom
|
||||
|
||||
settings.failed_load=Failed to load settings file. Remove it?
|
||||
|
||||
|
@ -73,6 +73,7 @@ login.not_email=\u7528\u6237\u540d\u5fc5\u987b\u662f\u90ae\u7bb1
|
||||
login.type=\u767b\u5f55
|
||||
login.username=\u540d\u5b57
|
||||
login.account=\u90ae\u7bb1
|
||||
login.no_valid_character=\u65e0\u6709\u6548\u7684\u89d2\u8272\uff0c\u81ea\u884c\u5230skinme.cc\u767b\u9646\u5e76\u521b\u5efa\u89d2\u8272
|
||||
|
||||
login.failed.connect_authentication_server=\u65e0\u6cd5\u8fde\u63a5\u8ba4\u8bc1\u670d\u52a1\u5668,\u53ef\u80fd\u662f\u7f51\u7edc\u95ee\u9898
|
||||
|
||||
@ -187,6 +188,8 @@ settings.fullscreen=\u5168\u5c4f
|
||||
settings.update_version=\u66f4\u65b0\u7248\u672c\u6587\u4ef6
|
||||
settings.physical_memory=\u7269\u7406\u5185\u5b58\u5927\u5c0f
|
||||
settings.choose_javapath=\u9009\u62e9Java\u8def\u5f84
|
||||
settings.default=\u9ed8\u8ba4
|
||||
settings.custom=\u81ea\u5b9a\u4e49
|
||||
|
||||
settings.failed_load=\u8bbe\u7f6e\u6587\u4ef6\u52a0\u8f7d\u5931\u8d25\uff0c\u53ef\u80fd\u662f\u5347\u7ea7\u4e86\u542f\u52a8\u5668\u6216\u88ab\u4eba\u5de5\u4fee\u6539\u9020\u6210\u9519\u8bef\uff0c\u662f\u5426\u6e05\u9664\uff1f
|
||||
|
||||
|
@ -73,6 +73,7 @@ login.not_email=\u7528\u6236\u540d\u5fc5\u9808\u662f\u90f5\u7bb1
|
||||
login.type=\u767b\u9304
|
||||
login.username=\u540d\u5b57
|
||||
login.account=\u90ae\u7bb1
|
||||
login.no_valid_character=\u7121\u6709\u6548\u7684\u89d2\u8272\uff0c\u81ea\u884c\u5230skinme.cc\u767b\u9678\u4e26\u5275\u5efa\u89d2\u8272
|
||||
|
||||
login.failed.connect_authentication_server=\u7121\u6cd5\u9023\u63a5\u8a8d\u8b49\u670d\u52d9\u5668,\u53ef\u80fd\u662f\u7db2\u7d61\u554f\u984c
|
||||
|
||||
@ -187,6 +188,8 @@ settings.fullscreen=\u5168\u5c4f
|
||||
settings.update_version=\u66f4\u65b0\u7248\u672c\u6587\u4ef6
|
||||
settings.physical_memory=\u7269\u7406\u5185\u5b58\u5927\u5c0f
|
||||
settings.choose_javapath=\u9009\u62e9Java\u8def\u5f84
|
||||
settings.default=\u9ed8\u8a8d
|
||||
settings.custom=\u81ea\u5b9a\u7fa9
|
||||
|
||||
settings.failed_load=\u8a2d\u5b9a\u6587\u4ef6\u52a0\u8f09\u5931\u6557\uff0c\u53ef\u80fd\u662f\u5347\u7d1a\u4e86\u555f\u52d5\u5668\u6216\u88ab\u4eba\u5de5\u4fee\u6539\u9020\u6210\u932f\u8aa4\uff0c\u662f\u5426\u6e05\u9664\uff1f
|
||||
|
||||
|
@ -15,13 +15,16 @@
|
||||
* along with this program.
|
||||
*/
|
||||
apply plugin: 'launch4j'
|
||||
apply plugin: 'me.tatarka.retrolambda'
|
||||
|
||||
if (!hasProperty('mainClass')) {
|
||||
ext.mainClass = 'org.jackhuang.hellominecraft.svrmgr.Main'
|
||||
}
|
||||
|
||||
def buildnumber = System.getenv("BUILD_NUMBER") == null ? "" : "."+System.getenv("BUILD_NUMBER")
|
||||
|
||||
String mavenGroupId = 'HMCSM'
|
||||
String mavenVersion = '0.8.6'
|
||||
String mavenVersion = '0.8.6' + buildnumber
|
||||
String bundleName = "Hello Minecraft! Server Manager"
|
||||
|
||||
group = mavenGroupId
|
||||
@ -35,6 +38,7 @@ buildscript {
|
||||
dependencies {
|
||||
classpath 'net.sf.proguard:proguard-gradle:4.10'
|
||||
classpath 'edu.sc.seis.gradle:launch4j:1.0.6'
|
||||
classpath 'me.tatarka:gradle-retrolambda:3.1.0'
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -47,6 +51,10 @@ configure(install.repositories.mavenInstaller) {
|
||||
}
|
||||
}
|
||||
|
||||
retrolambda {
|
||||
javaVersion = JavaVersion.VERSION_1_7
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(":HMCLAPI")
|
||||
compile project(":MetroLookAndFeel")
|
||||
@ -79,6 +87,7 @@ task proguard(type: proguard.gradle.ProGuardTask, dependsOn: jar) {
|
||||
|
||||
configuration 'proguard.pro'
|
||||
}
|
||||
|
||||
processResources {
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
exclude 'icon.icns'
|
||||
|
Loading…
Reference in New Issue
Block a user