added method to start arma 3

This commit is contained in:
Niklas 2020-03-31 00:11:28 +02:00
parent fbfeef1a95
commit 687177f9d2
12 changed files with 292 additions and 136 deletions

View File

@ -338,7 +338,7 @@
</constraints>
<properties>
<editable value="false"/>
<text value="-noInit -noLogs"/>
<text value=""/>
</properties>
</component>
</children>
@ -1784,7 +1784,9 @@
<model>
<item value=""/>
<item value="tbb4malloc_bi"/>
<item value="tbb4malloc_bi_x64"/>
<item value="jemalloc_bi"/>
<item value="jemalloc_bi_x64"/>
<item value="system"/>
</model>
</properties>

View File

@ -201,11 +201,11 @@ public class LauncherGUI implements Observer {
fileChecker.addObserver(this);
syncer.addObserver(this);
if (Parameters.ARMA_PATH.toStringParameter().getConfigValue() == null || Parameters.ARMA_PATH.toStringParameter().getConfigValue().isEmpty()) {
if (Parameters.ARMA_PATH.toParameter().getConfigValue() == null || ((String) Parameters.ARMA_PATH.toParameter().getConfigValue()).isEmpty()) {
final Path installationPath = ArmaUtils.getInstallationPath();
if (installationPath != null) {
Parameters.ARMA_PATH.toStringParameter().save(installationPath.toAbsolutePath().toString());
Parameters.MOD_PATH.toStringParameter().save(Paths.get(
Parameters.ARMA_PATH.toParameter().save(installationPath.toAbsolutePath().toString());
Parameters.MOD_PATH.toParameter().save(Paths.get(
installationPath.toAbsolutePath().toString(), ArmA3Launcher.config.getString("name") + " Mods"
).toAbsolutePath().toString());
techCheck();
@ -250,7 +250,8 @@ public class LauncherGUI implements Observer {
playPresetButton.setMargin(new Insets(10, 10, 10, 10));
serverTable.setModel(new ServerTableModel());
final ServerTableModel serverTableModel = new ServerTableModel();
serverTable.setModel(serverTableModel);
presetList.setModel(new PresetTableModel());
presetList.setCellRenderer(new PresetListRenderer());
@ -301,11 +302,41 @@ public class LauncherGUI implements Observer {
updateTreeScrolPane.getVerticalScrollBar().setUnitIncrement(16);
splitView.setDividerLocation(-1);
ListSelectionModel selectionModel = serverTable.getSelectionModel();
selectionModel.addListSelectionListener(e -> {
if (serverTable.getSelectedRow() == -1) {
playButton.setEnabled(false);
parameterText.setText("");
return;
}
ServerTableModel m = (ServerTableModel) serverTable.getModel();
Server server = m.getServer(serverTable.getSelectedRow());
parameterText.setText(ArmaUtils.getGameParameter(server.getPreset()));
techCheck();
});
playButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (serverTable.getSelectedRow() == -1) {
playButton.setEnabled(false);
parameterText.setText("");
return;
}
ServerTableModel m = (ServerTableModel) serverTable.getModel();
Server server = m.getServer(serverTable.getSelectedRow());
ArmaUtils.start(server.getPreset(), server.getStartparameter().stream().toArray(String[]::new));
}
});
presetList.addListSelectionListener(e -> {
if (!e.getValueIsAdjusting()) {
PresetTableModel m = (PresetTableModel) presetList.getModel();
Object elementAt = m.getElementAt(presetList.getSelectedIndex());
Modset modset = (Modset) elementAt;
if (modset == null) return;
if (modset.getType() == Modset.Type.SERVER || modset.getType() == Modset.Type.PLACEHOLDER) {
renamePresetButton.setEnabled(false);
@ -315,8 +346,34 @@ public class LauncherGUI implements Observer {
removePresetButtom.setEnabled(true);
}
clonePresetButton.setEnabled(modset.getType() != Modset.Type.PLACEHOLDER);
if (modset.getType() == Modset.Type.PLACEHOLDER) {
modList.setModel(new DefaultListModel<String>());
presetNotePane.setVisible(false);
presetList.clearSelection();
}
updateModList(modset);
techCheck();
}
});
playPresetButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (presetList.getSelectedIndex() == -1) {
playPresetButton.setEnabled(false);
parameterText.setText("");
return;
}
PresetTableModel model1 = (PresetTableModel) presetList.getModel();
if (presetList.getSelectedIndex() == -1) return;
Object elementAt = model1.getElementAt(presetList.getSelectedIndex());
Modset selectedModset = (Modset) elementAt;
if(selectedModset.getType() == Modset.Type.PLACEHOLDER) return;
ArmaUtils.start(selectedModset);
}
});
@ -598,10 +655,12 @@ public class LauncherGUI implements Observer {
}
public void techCheck() {
boolean pathSet = Parameters.ARMA_PATH.toStringParameter().getConfigValue() != null && Parameters.ARMA_PATH.toStringParameter().getConfigValue() != null;
boolean pathSet = Parameters.ARMA_PATH.toParameter().getConfigValue() != null && Parameters.ARMA_PATH.toParameter().getConfigValue() != null;
playButton.setEnabled(false);
playPresetButton.setEnabled(false);
if (SteamTimer.arma_running) {
playButton.setEnabled(false);
playPresetButton.setEnabled(false);
syncIntensiveCheckButton.setEnabled(false);
syncFastCheckButton.setEnabled(false);
refreshRepoButton.setEnabled(false);
@ -614,22 +673,20 @@ public class LauncherGUI implements Observer {
} else {
if (SteamTimer.steam_running) {
if (pathSet) {
playButton.setEnabled(true);
playPresetButton.setEnabled(true);
if (serverTable.getSelectedRow() != -1) {
playButton.setEnabled(true);
playButton.setToolTipText(null);
}
playButton.setToolTipText(null);
playPresetButton.setToolTipText(null);
if (presetList.getSelectedIndex() != -1) {
playPresetButton.setEnabled(true);
playPresetButton.setToolTipText(null);
}
} else {
playButton.setEnabled(false);
playPresetButton.setEnabled(false);
playButton.setToolTipText(LangUtils.getInstance().getString("path_not_set"));
playPresetButton.setToolTipText(LangUtils.getInstance().getString("path_not_set"));
}
} else {
playButton.setEnabled(false);
playPresetButton.setEnabled(false);
playButton.setToolTipText(LangUtils.getInstance().getString("steam_not_running"));
playPresetButton.setToolTipText(LangUtils.getInstance().getString("steam_not_running"));
}
@ -673,7 +730,7 @@ public class LauncherGUI implements Observer {
for (int i = 0; i < directories.length; i++) {
try {
readableDirectories[i] = URLDecoder.decode(directories[i], StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
} catch (UnsupportedEncodingException | IllegalArgumentException e) {
readableDirectories[i] = directories[i];
}
}
@ -681,7 +738,7 @@ public class LauncherGUI implements Observer {
((JComboBox<String>) settingsProfileCombo).setModel(new DefaultComboBoxModel<>(readableDirectories));
initFolderChooser(settingsArmaPathText, settingsArmaPathBtn, Parameters.ARMA_PATH.toStringParameter(), new Callback.JFileSelectCallback() {
initFolderChooser(settingsArmaPathText, settingsArmaPathBtn, Parameters.ARMA_PATH.toParameter(), new Callback.JFileSelectCallback() {
@Override
public boolean allowSelection(File path) {
String sPath = path.getAbsolutePath();
@ -702,7 +759,7 @@ public class LauncherGUI implements Observer {
}
});
initFolderChooser(settingsModsPathText, settingsModsPathBtn, Parameters.MOD_PATH.toStringParameter(), new Callback.JFileSelectCallback() {
initFolderChooser(settingsModsPathText, settingsModsPathBtn, Parameters.MOD_PATH.toParameter(), new Callback.JFileSelectCallback() {
@Override
public boolean allowSelection(File path) {
String sPath = path.getAbsolutePath();
@ -721,39 +778,39 @@ public class LauncherGUI implements Observer {
// -------------------------------- COMBO BOXES --------------------------------
initComboBox(settingsLanguageCombo, Parameters.LANGUAGE.toStringParameter());
initComboBox(settingsBehaviorStartCombo, Parameters.BEHAVIOUR_AFTER_START.toStringParameter());
initComboBox(settingsLanguageCombo, Parameters.LANGUAGE.toParameter());
initComboBox(settingsBehaviorStartCombo, Parameters.BEHAVIOUR_AFTER_START.toParameter());
initComboBox(settingsProfileCombo, Parameters.PROFILE.toStringParameter(directories));
initComboBox(settingsExThreadsCombo, Parameters.EXTRA_THREADS.toStringParameter());
initComboBox(settingsMallocCombo, Parameters.MALLOC.toStringParameter());
initComboBox(settingsProfileCombo, Parameters.PROFILE.toParameter(readableDirectories));
initComboBox(settingsExThreadsCombo, Parameters.EXTRA_THREADS.toParameter());
initComboBox(settingsMallocCombo, Parameters.MALLOC.toParameter());
// -------------------------------- CHECK BOXES --------------------------------
initCheckBox(settingsShowParameterBox, Parameters.SHOW_START_PARAMETER.toBooolParameter());
initCheckBox(settingsShowParameterBox, Parameters.SHOW_START_PARAMETER.toParameter());
settingsShowParameterBox.addItemListener(e -> parameterText.setVisible(e.getStateChange() == ItemEvent.SELECTED));
initCheckBox(settingsCheckModsBox, Parameters.CHECK_MODSET.toBooolParameter());
initCheckBox(settingsCheckModsBox, Parameters.CHECK_MODSET.toParameter());
initCheckBox(settingsUseWorkshopBox, Parameters.USE_WORKSHOP.toBooolParameter());
initCheckBox(settingsUseWorkshopBox, Parameters.USE_WORKSHOP.toParameter());
settingsUseWorkshopBox.addItemListener(e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
SwingUtilities.invokeLater(() -> warnBox(LangUtils.getInstance().getString("warning_workshop"), LangUtils.getInstance().getString("warning")));
}
});
initCheckBox(settingsUseSixtyFourBitBox, Parameters.USE_64_BIT_CLIENT.toBooolParameter());
initCheckBox(settingsNoSplashBox, Parameters.NO_SPLASH.toBooolParameter());
initCheckBox(settingsSkipIntroBox, Parameters.SKIP_INTRO.toBooolParameter());
initCheckBox(settingsNoCBBox, Parameters.NO_CB.toBooolParameter());
initCheckBox(settingsNoLogsBox, Parameters.NO_LOGS.toBooolParameter());
initCheckBox(settingsEnableHTBox, Parameters.ENABLE_HT.toBooolParameter());
initCheckBox(settingsHugeoagesBox, Parameters.HUGEPAGES.toBooolParameter());
initCheckBox(settingsNoPauseBox, Parameters.NO_PAUSE.toBooolParameter());
initCheckBox(settingsShowScriptErrorsBox, Parameters.SHOW_SCRIPT_ERRORS.toBooolParameter());
initCheckBox(settingsFilePatchingBox, Parameters.FILE_PATCHING.toBooolParameter());
initCheckBox(settingsCrashDiagBox, Parameters.CRASH_DIAG.toBooolParameter());
initCheckBox(settingsWindowBox, Parameters.WINDOW.toBooolParameter());
initCheckBox(settingsUseSixtyFourBitBox, Parameters.USE_64_BIT_CLIENT.toParameter());
initCheckBox(settingsNoSplashBox, Parameters.NO_SPLASH.toParameter());
initCheckBox(settingsSkipIntroBox, Parameters.SKIP_INTRO.toParameter());
initCheckBox(settingsNoCBBox, Parameters.NO_CB.toParameter());
initCheckBox(settingsNoLogsBox, Parameters.NO_LOGS.toParameter());
initCheckBox(settingsEnableHTBox, Parameters.ENABLE_HT.toParameter());
initCheckBox(settingsHugeoagesBox, Parameters.HUGEPAGES.toParameter());
initCheckBox(settingsNoPauseBox, Parameters.NO_PAUSE.toParameter());
initCheckBox(settingsShowScriptErrorsBox, Parameters.SHOW_SCRIPT_ERRORS.toParameter());
initCheckBox(settingsFilePatchingBox, Parameters.FILE_PATCHING.toParameter());
initCheckBox(settingsCrashDiagBox, Parameters.CRASH_DIAG.toParameter());
initCheckBox(settingsWindowBox, Parameters.WINDOW.toParameter());
// -------------------------------- SPINNER --------------------------------
@ -761,33 +818,33 @@ public class LauncherGUI implements Observer {
OperatingSystemMXBean mxbean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
int memorySize = (int) (mxbean.getTotalPhysicalMemorySize() / 1024);
initSpinner(settingsMaxMemSpinner, Parameters.MAX_MEM.toStringParameter(), -1, memorySize);
initSpinner(settingsMaxVRamSpinner, Parameters.MAX_VRAM.toStringParameter(), -1, 99999);
initSpinner(settingsCpuCountSpinner, Parameters.CPU_COUNT.toStringParameter(), 0, Runtime.getRuntime().availableProcessors());
initSpinner(settingsPosXSpinner, Parameters.POS_X.toStringParameter(), -1, 99999);
initSpinner(settingsPosYSpinner, Parameters.POS_Y.toStringParameter(), -1, 99999);
initSpinner(settingsMaxMemSpinner, Parameters.MAX_MEM.toParameter(), -1, memorySize);
initSpinner(settingsMaxVRamSpinner, Parameters.MAX_VRAM.toParameter(), -1, 99999);
initSpinner(settingsCpuCountSpinner, Parameters.CPU_COUNT.toParameter(), 0, Runtime.getRuntime().availableProcessors());
initSpinner(settingsPosXSpinner, Parameters.POS_X.toParameter(), -1, 99999);
initSpinner(settingsPosYSpinner, Parameters.POS_Y.toParameter(), -1, 99999);
// -------------------------------- -------------------------------- --------------------------------
}
private void initCheckBox(JCheckBox cb, Parameter<Boolean> paraObj) {
cb.setSelected(paraObj.getValue());
private void initCheckBox(JCheckBox cb, Parameter paraObj) {
cb.setSelected((Boolean) paraObj.getValue());
cb.addItemListener(new SettingsHandler.CheckBoxListener(paraObj));
}
private void initComboBox(JComboBox<String> cb, Parameter<String> paraObj) {
private void initComboBox(JComboBox<String> cb, Parameter paraObj) {
cb.setSelectedIndex(paraObj.getIndex());
if (cb.getItemListeners().length == 1) cb.addItemListener(new SettingsHandler.ComboBoxListener(paraObj));
}
private void initFolderChooser(JTextField showText, JButton actionButton, Parameter<String> paraObj, Callback.JFileSelectCallback check) {
showText.setText(paraObj.getValue());
private void initFolderChooser(JTextField showText, JButton actionButton, Parameter paraObj, Callback.JFileSelectCallback check) {
showText.setText((String) paraObj.getValue());
if (actionButton.getActionListeners().length == 0)
actionButton.addActionListener(new SettingsHandler.Fileistener(mainPanel, paraObj, check));
}
public void initSpinner(JSpinner spinner, Parameter<String> paraObj, int min, int max) {
SpinnerNumberModel RAMModel = new SpinnerNumberModel(Integer.parseInt(paraObj.getValue()), min, max, 1);
public void initSpinner(JSpinner spinner, Parameter paraObj, int min, int max) {
SpinnerNumberModel RAMModel = new SpinnerNumberModel(Integer.parseInt((String) paraObj.getValue()), min, max, 1);
spinner.setModel(RAMModel);
JComponent comp = spinner.getEditor();
JFormattedTextField field = (JFormattedTextField) comp.getComponent(0);
@ -844,6 +901,8 @@ public class LauncherGUI implements Observer {
if (modset.getType() == Modset.Type.PLACEHOLDER) return;
int[] select = new int[modset.getMods().size()];
parameterText.setText(ArmaUtils.getGameParameter(modset));
AtomicInteger selectCounter = new AtomicInteger(0);
RepositoryManger.MOD_LIST.stream()
.filter((am) -> am instanceof Mod)
@ -1061,9 +1120,9 @@ public class LauncherGUI implements Observer {
refreshRepoButton.setEnabled(true);
updateRepoTree();
final Parameter<Boolean> checkModsetParameter = Parameters.CHECK_MODSET.toBooolParameter();
if(checkModsetParameter.getValue() != null && checkModsetParameter.getValue()) {
if(!fileChecker.isChecked()) {
final Parameter checkModsetParameter = Parameters.CHECK_MODSET.toParameter();
if (checkModsetParameter.getValue() != null && (boolean) checkModsetParameter.getValue()) {
if (!fileChecker.isChecked()) {
SwingUtilities.invokeLater(() -> fileCheck(false));
Logger.getLogger(getClass().getName()).log(Level.INFO, "Started file check on launch");
}
@ -1130,8 +1189,8 @@ public class LauncherGUI implements Observer {
lastSynclist = null;
} else if (s.equals("syncStopped")) {
final Parameter<Boolean> workshopParameter = Parameters.USE_WORKSHOP.toBooolParameter();
new Thread(() -> fileChecker.check(!(workshopParameter.getValue() != null && workshopParameter.getValue()))).start();
final Parameter workshopParameter = Parameters.USE_WORKSHOP.toParameter();
new Thread(() -> fileChecker.check(!(workshopParameter.getValue() != null && (boolean) workshopParameter.getValue()))).start();
SwingUtilities.invokeLater(() -> {
syncDownloadButton.setEnabled(false);
syncDownloadAbortButton.setEnabled(false);
@ -1142,8 +1201,8 @@ public class LauncherGUI implements Observer {
TaskBarUtils.getInstance().off();
});
} else if (s.equals("syncComplete")) {
final Parameter<Boolean> workshopParameter = Parameters.USE_WORKSHOP.toBooolParameter();
new Thread(() -> fileChecker.check(!(workshopParameter.getValue() != null && workshopParameter.getValue()))).start();
final Parameter workshopParameter = Parameters.USE_WORKSHOP.toParameter();
new Thread(() -> fileChecker.check(!(workshopParameter.getValue() != null && (boolean) workshopParameter.getValue()))).start();
SwingUtilities.invokeLater(() -> {
syncDownloadButton.setEnabled(false);
syncDownloadAbortButton.setEnabled(false);
@ -1234,6 +1293,9 @@ public class LauncherGUI implements Observer {
switch (tab) {
case PLAY:
playPanelButton.setBackground(focusBackgroundColor);
parameterText.setText("");
serverTable.clearSelection();
break;
case UPDATE:
@ -1247,6 +1309,14 @@ public class LauncherGUI implements Observer {
case PRESET:
presetPanelButton.setBackground(focusBackgroundColor);
presetList.clearSelection();
modList.setModel(new DefaultListModel<String>());
presetNotePane.setVisible(false);
clonePresetButton.setEnabled(false);
renamePresetButton.setEnabled(false);
removePresetButtom.setEnabled(false);
break;
case SETTING:
@ -1276,6 +1346,7 @@ public class LauncherGUI implements Observer {
}
tabbedPane1.setSelectedIndex(tab.getIndex());
techCheck();
}
{
@ -1462,7 +1533,7 @@ public class LauncherGUI implements Observer {
panel6.add(playButton, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
parameterText = new JTextField();
parameterText.setEditable(false);
parameterText.setText("-noInit -noLogs");
parameterText.setText("");
panel6.add(parameterText, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
updateTab = new JPanel();
updateTab.setLayout(new GridLayoutManager(2, 2, new Insets(0, 0, 5, 0), -1, -1));
@ -2042,7 +2113,9 @@ public class LauncherGUI implements Observer {
final DefaultComboBoxModel defaultComboBoxModel2 = new DefaultComboBoxModel();
defaultComboBoxModel2.addElement("");
defaultComboBoxModel2.addElement("tbb4malloc_bi");
defaultComboBoxModel2.addElement("tbb4malloc_bi_x64");
defaultComboBoxModel2.addElement("jemalloc_bi");
defaultComboBoxModel2.addElement("jemalloc_bi_x64");
defaultComboBoxModel2.addElement("system");
settingsMallocCombo.setModel(defaultComboBoxModel2);
panel35.add(settingsMallocCombo, new GridConstraints(23, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));

View File

@ -11,23 +11,23 @@ import java.util.logging.Logger;
/**
* Created by gurkengewuerz.de on 24.03.2020.
*/
public class Parameter<T> {
public class Parameter {
private String name;
private ParameterType pType;
private Class<T> persistentClass;
private Class<?> persistentClass;
private String[] values = null;
private String startParameter = "";
public Parameter(String name, ParameterType pType, Class<T> persistentClass) {
public Parameter(String name, ParameterType pType, Class<?> persistentClass) {
this(name, pType, persistentClass, null, "");
}
public Parameter(String name, ParameterType pType, Class<T> persistentClass, String startParameter) {
public Parameter(String name, ParameterType pType, Class<?> persistentClass, String startParameter) {
this(name, pType, persistentClass, null, startParameter);
}
public Parameter(String name, ParameterType pType, Class<T> persistentClass, String[] values, String startParameter) {
public Parameter(String name, ParameterType pType, Class<?> persistentClass, String[] values, String startParameter) {
this.name = name;
this.pType = pType;
this.persistentClass = persistentClass;
@ -45,8 +45,8 @@ public class Parameter<T> {
return "";
}
public void save(T data) {
T def = getDefault();
public void save(Object data) {
Object def = getDefault();
if (data == def || (persistentClass.getTypeName().equals("java.lang.String") && String.valueOf(data).equals(String.valueOf(def)))) {
// remove entry from user config
@ -75,7 +75,7 @@ public class Parameter<T> {
public void save(int index) {
if(values == null) throw new IllegalAccessError("call of save(int index) is only allowed for ComboBoxes");
if(index > values.length - 1) throw new IndexOutOfBoundsException("index " + index + " is out of bound. Max: " + (values.length -1));
save((T) values[index]);
save(values[index]);
}
public String getParameter() {
@ -83,7 +83,7 @@ public class Parameter<T> {
return startParameter;
}
public T getConfigValue() {
public Object getConfigValue() {
// Get User Value else Default else null
Ini.Section section = ArmA3Launcher.user_config.get(getUserConfigSectionName());
if (section != null) {
@ -91,16 +91,16 @@ public class Parameter<T> {
String val = section.get(name);
if (persistentClass.getTypeName().equals("java.lang.Boolean")) {
return (T) (Boolean) Boolean.valueOf(val.toLowerCase());
} else return (T) val;
return Boolean.valueOf(val.toLowerCase());
} else return val;
}
}
return null;
}
public T getValue() {
final T configValue = getConfigValue();
public Object getValue() {
final Object configValue = getConfigValue();
if(configValue != null) return configValue;
return getDefault();
}
@ -114,11 +114,11 @@ public class Parameter<T> {
return -1;
}
public T getDefault() {
public Object getDefault() {
if (persistentClass.getTypeName().equals("java.lang.Boolean")) {
return (T) (Boolean) ArmA3Launcher.config.getBoolean( getUserConfigSectionName() + "." + name);
return ArmA3Launcher.config.getBoolean( getUserConfigSectionName() + "." + name);
} else if (persistentClass.getTypeName().equals("java.lang.String"))
return (T) ArmA3Launcher.config.getString(getUserConfigSectionName()+ "." + name);
return ArmA3Launcher.config.getString(getUserConfigSectionName()+ "." + name);
else return null;
}
@ -126,7 +126,7 @@ public class Parameter<T> {
return startParameter;
}
enum ParameterType {
public enum ParameterType {
ARMA,
CLIENT
}

View File

@ -5,68 +5,70 @@ package de.mc8051.arma3launcher;
*/
public enum Parameters {
LANGUAGE("language", Parameter.ParameterType.CLIENT, "", new String[]{"system", "en_US", "de_DE"}),
BEHAVIOUR_AFTER_START("behaviourAfterStart", Parameter.ParameterType.CLIENT, "", new String[]{"nothing", "minimize", "exit"}),
SHOW_START_PARAMETER("ShowStartParameter", Parameter.ParameterType.CLIENT),
CHECK_MODSET("CheckModset", Parameter.ParameterType.CLIENT),
USE_WORKSHOP("UseWorkshop", Parameter.ParameterType.CLIENT),
ARMA_PATH("armaPath", Parameter.ParameterType.CLIENT),
MOD_PATH("modPath", Parameter.ParameterType.CLIENT),
LANGUAGE("language", Parameter.ParameterType.CLIENT, String.class, "", new String[]{"system", "en_US", "de_DE"}),
BEHAVIOUR_AFTER_START("behaviourAfterStart", Parameter.ParameterType.CLIENT, String.class, "", new String[]{"nothing", "minimize", "exit"}),
SHOW_START_PARAMETER("ShowStartParameter", Parameter.ParameterType.CLIENT, Boolean.class),
CHECK_MODSET("CheckModset", Parameter.ParameterType.CLIENT, Boolean.class),
USE_WORKSHOP("UseWorkshop", Parameter.ParameterType.CLIENT, Boolean.class),
ARMA_PATH("armaPath", Parameter.ParameterType.CLIENT, String.class),
MOD_PATH("modPath", Parameter.ParameterType.CLIENT, String.class),
PROFILE("Profile", Parameter.ParameterType.ARMA, "name"),
USE_64_BIT_CLIENT("Use64BitClient", Parameter.ParameterType.ARMA, "Use64BitClient"),
NO_SPLASH("NoSplash", Parameter.ParameterType.ARMA, "noSplash"),
SKIP_INTRO("SkipIntro", Parameter.ParameterType.ARMA, "skipIntro"),
WORLD("World", Parameter.ParameterType.ARMA, "world"),
MAX_MEM("MaxMem", Parameter.ParameterType.ARMA, "maxMem"),
MAX_VRAM("MaxVRAM", Parameter.ParameterType.ARMA, "maxVRAM"),
NO_CB("NoCB", Parameter.ParameterType.ARMA, "noCB"),
CPU_COUNT("CpuCount", Parameter.ParameterType.ARMA, "cpuCount"),
EXTRA_THREADS("ExThreads", Parameter.ParameterType.ARMA, "exThreads", new String[]{"", "3", "7"}),
MALLOC("Malloc", Parameter.ParameterType.ARMA, "malloc", new String[]{"", "tbb4malloc_bi", "jemalloc_bi", "system"}),
NO_LOGS("NoLogs", Parameter.ParameterType.ARMA, "noLogs"),
ENABLE_HT("EnableHT", Parameter.ParameterType.ARMA, "enableHT"),
HUGEPAGES("Hugepages", Parameter.ParameterType.ARMA, "hugepages"),
NO_PAUSE("NoPause", Parameter.ParameterType.ARMA, "noPause"),
SHOW_SCRIPT_ERRORS("ShowScriptErrors", Parameter.ParameterType.ARMA, "showScriptErrors"),
FILE_PATCHING("FilePatching", Parameter.ParameterType.ARMA, "filePatching"),
INIT("Init", Parameter.ParameterType.ARMA, "init"),
BETA("Beta", Parameter.ParameterType.ARMA, "beta"),
CRASH_DIAG("CrashDiag", Parameter.ParameterType.ARMA, "crashDiag"),
WINDOW("Window", Parameter.ParameterType.ARMA, "window"),
POS_X("PosX", Parameter.ParameterType.ARMA, "posX"),
POS_Y("PosY", Parameter.ParameterType.ARMA, "posY");
PROFILE("Profile", Parameter.ParameterType.ARMA, String.class, "name"),
USE_64_BIT_CLIENT("Use64BitClient", Parameter.ParameterType.ARMA, Boolean.class),
NO_SPLASH("NoSplash", Parameter.ParameterType.ARMA, Boolean.class, "noSplash"),
SKIP_INTRO("SkipIntro", Parameter.ParameterType.ARMA, Boolean.class, "skipIntro"),
WORLD("World", Parameter.ParameterType.ARMA, String.class, "world"),
MAX_MEM("MaxMem", Parameter.ParameterType.ARMA, String.class, "maxMem"),
MAX_VRAM("MaxVRAM", Parameter.ParameterType.ARMA, String.class, "maxVRAM"),
NO_CB("NoCB", Parameter.ParameterType.ARMA, Boolean.class, "noCB"),
CPU_COUNT("CpuCount", Parameter.ParameterType.ARMA, String.class, "cpuCount"),
EXTRA_THREADS("ExThreads", Parameter.ParameterType.ARMA, String.class, "exThreads", new String[]{"", "3", "7"}),
MALLOC("Malloc", Parameter.ParameterType.ARMA, String.class, "malloc", new String[]{"", "tbb4malloc_bi", "tbb4malloc_bi_x64", "jemalloc_bi", "jemalloc_bi_x64", "system"}),
NO_LOGS("NoLogs", Parameter.ParameterType.ARMA, Boolean.class, "noLogs"),
ENABLE_HT("EnableHT", Parameter.ParameterType.ARMA, Boolean.class, "enableHT"),
HUGEPAGES("Hugepages", Parameter.ParameterType.ARMA, Boolean.class, "hugepages"),
NO_PAUSE("NoPause", Parameter.ParameterType.ARMA, Boolean.class, "noPause"),
SHOW_SCRIPT_ERRORS("ShowScriptErrors", Parameter.ParameterType.ARMA, Boolean.class, "showScriptErrors"),
FILE_PATCHING("FilePatching", Parameter.ParameterType.ARMA, Boolean.class, "filePatching"),
INIT("Init", Parameter.ParameterType.ARMA, String.class, "init"),
BETA("Beta", Parameter.ParameterType.ARMA, String.class, "beta"),
CRASH_DIAG("CrashDiag", Parameter.ParameterType.ARMA, Boolean.class, "crashDiag"),
WINDOW("Window", Parameter.ParameterType.ARMA, Boolean.class, "window"),
POS_X("PosX", Parameter.ParameterType.ARMA, String.class, "posX"),
POS_Y("PosY", Parameter.ParameterType.ARMA, String.class, "posY");
private String name;
private Parameter.ParameterType type;
private String[] values;
private String startParameter;
private Class<?> clazz;
Parameters(String name, Parameter.ParameterType type) {
this(name, type, "");
Parameters(String name, Parameter.ParameterType type, Class<?> clazz) {
this(name, type, clazz, "");
}
Parameters(String name, Parameter.ParameterType type, String startParameter) {
this(name, type, startParameter, null);
Parameters(String name, Parameter.ParameterType type, Class<?> clazz, String startParameter) {
this(name, type, clazz, startParameter, null);
}
Parameters(String name, Parameter.ParameterType type, String startParameter, String[] values) {
Parameters(String name, Parameter.ParameterType type, Class<?> clazz, String startParameter, String[] values) {
this.name = name;
this.type = type;
this.startParameter = startParameter;
this. values = values;
this.values = values;
this.clazz = clazz;
}
public Parameter<String> toStringParameter() {
return new Parameter<String>(name, type, String.class, values, startParameter);
public Parameter toParameter() {
return new Parameter(name, type, clazz, values, startParameter);
}
public Parameter<String> toStringParameter(String... values) {
return new Parameter<String>(name, type, String.class, values, startParameter);
public Parameter toParameter(String... values) {
return new Parameter(name, type, clazz, values, startParameter);
}
public Parameter<Boolean> toBooolParameter() {
return new Parameter<>(name, type, Boolean.class);
public Class<?> getClazz() {
return clazz;
}
public String getName() {

View File

@ -18,9 +18,9 @@ import java.io.File;
public class SettingsHandler {
public static class CheckBoxListener implements ItemListener {
private Parameter<Boolean> parameter;
private Parameter parameter;
public CheckBoxListener(Parameter<Boolean> parameter) {
public CheckBoxListener(Parameter parameter) {
this.parameter = parameter;
}
@ -32,9 +32,9 @@ public class SettingsHandler {
public static class ComboBoxListener implements ItemListener {
private Parameter<String> parameter;
private Parameter parameter;
public ComboBoxListener(Parameter<String> parameter) {
public ComboBoxListener(Parameter parameter) {
this.parameter = parameter;
}
@ -50,10 +50,10 @@ public class SettingsHandler {
public static class Fileistener implements ActionListener {
private JPanel parent;
private Parameter<String> parameter;
private Parameter parameter;
private Callback.JFileSelectCallback check;
public Fileistener(JPanel parent, Parameter<String> parameter, Callback.JFileSelectCallback check) {
public Fileistener(JPanel parent, Parameter parameter, Callback.JFileSelectCallback check) {
this.parent = parent;
this.parameter = parameter;
this.check = check;
@ -82,9 +82,9 @@ public class SettingsHandler {
public static class SpinnerListener implements ChangeListener {
private static long lastChange = -1;
private Parameter<String> parameter;
private Parameter parameter;
public SpinnerListener(Parameter<String> parameter) {
public SpinnerListener(Parameter parameter) {
this.parameter = parameter;
}

View File

@ -29,6 +29,7 @@ public class PresetTableModel extends AbstractListModel {
@Override
public Object getElementAt(int index) {
if(index == -1) return null;
return data.get(index);
}
}

View File

@ -39,6 +39,10 @@ public class ServerTableModel extends AbstractTableModel {
return columnNames.length;
}
public Server getServer(int row) {
return data.get(row);
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
if (columnIndex == 0) return data.get(rowIndex).getName();

View File

@ -1,12 +1,16 @@
package de.mc8051.arma3launcher.objects;
import de.mc8051.arma3launcher.ArmA3Launcher;
import de.mc8051.arma3launcher.Parameter;
import de.mc8051.arma3launcher.Parameters;
import org.ini4j.Ini;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
@ -108,8 +112,10 @@ public class Modset implements Comparable {
return type;
}
public void play() {
// TODO: Implement play with this Modset
public List<String> getStartParamter() {
return mods.stream()
.map(m -> new File((String) Parameters.MOD_PATH.toParameter().getValue(), m.getName()).getAbsolutePath())
.collect(Collectors.toList());
}
public Modset clone(String newName, Type newType) {

View File

@ -2,7 +2,9 @@ package de.mc8051.arma3launcher.objects;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* Created by gurkengewuerz.de on 25.03.2020.
@ -28,13 +30,13 @@ public class Server {
}
public Server(JSONObject o) {
if(!o.has("name") || !o.has("password") || !o.has("ipaddress") || !o.has("port") || !o.has("preset")) return;
if (!o.has("name") || !o.has("password") || !o.has("ipaddress") || !o.has("port") || !o.has("preset")) return;
name = o.getString("name");
password = o.getString("password");
ip = o.getString("ipaddress");
port = o.getInt("port");
if(!Modset.MODSET_LIST.containsKey(o.getString("preset"))) return;
if (!Modset.MODSET_LIST.containsKey(o.getString("preset"))) return;
preset = Modset.MODSET_LIST.get(o.getString("preset"));
SERVER_LIST.put(name, this);
@ -59,4 +61,13 @@ public class Server {
public Modset getPreset() {
return preset;
}
public ArrayList<String> getStartparameter() {
ArrayList<String> list = new ArrayList<>();
list.add("-connect=" + ip);
list.add("-port=" + port);
if (password.isEmpty())
list.add("-password=" + ip);
return list;
}
}

View File

@ -98,8 +98,8 @@ public class Syncer implements Observable, SyncListener {
TaskBarUtils.getInstance().normal();
});
final Parameter<Boolean> workshopParameter = Parameters.USE_WORKSHOP.toBooolParameter();
if(workshopParameter.getValue() != null && workshopParameter.getValue()) workshopFiles = WorkshopUtil.workshopFiles();
final Parameter workshopParameter = Parameters.USE_WORKSHOP.toParameter();
if(workshopParameter.getValue() != null && (Boolean) workshopParameter.getValue()) workshopFiles = WorkshopUtil.workshopFiles();
boolean lastPause = false;
while (running) {

View File

@ -18,7 +18,7 @@ public class WorkshopUtil {
public static Map<Path, Long> workshopFiles() {
Map<Path, Long> fileMap = new HashMap<>();
final String armaPath = Parameters.ARMA_PATH.toStringParameter().getValue();
final String armaPath = (String) Parameters.ARMA_PATH.toParameter().getValue();
if(armaPath == null) return fileMap;
final Path workshopPath = Paths.get(armaPath, "!Workshop");

View File

@ -1,5 +1,8 @@
package de.mc8051.arma3launcher.utils;
import de.mc8051.arma3launcher.Parameter;
import de.mc8051.arma3launcher.Parameters;
import de.mc8051.arma3launcher.objects.Modset;
import de.ralleytn.simple.registry.Key;
import de.ralleytn.simple.registry.Registry;
@ -9,8 +12,10 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
/**
* Created by gurkengewuerz.de on 30.03.2020.
@ -31,7 +36,7 @@ public class ArmaUtils {
if (regKey == null) return null;
final Path main = Paths.get(regKey.getValueByName("main").getRawValue());
if(!checkArmaPath(main)) return null;
if (!checkArmaPath(main)) return null;
return main;
}
@ -54,4 +59,56 @@ public class ArmaUtils {
}
return false;
}
public static String getGameParameter(Modset modset) {
StringBuilder sb = new StringBuilder();
List<String> parameters = Arrays.stream(Parameters.values())
.filter(p -> p.getType() == Parameter.ParameterType.ARMA)
.filter(p -> !p.getStartParameter().isEmpty())
.filter(p -> {
if (p.getClazz() == Boolean.class) {
boolean b = (boolean) p.toParameter().getValue();
return b;
}
String paraVal = (String) p.toParameter().getValue();
return !(paraVal == null || paraVal.isEmpty() || paraVal.equals("-1") || paraVal.equals("0"));
})
.map(parameter -> {
final Class<?> clazz = parameter.getClazz();
if (clazz == Boolean.class) {
return "-" + parameter.getStartParameter();
}
return "\"-" + parameter.getStartParameter() + "=" + parameter.toParameter().getValue() + "\"";
})
.collect(Collectors.toList());
sb.append(String.join(" ", parameters)).append(" ");
final List<String> modParameter = modset.getStartParamter();
if (!modParameter.isEmpty())
sb.append("\"-mod=").append(String.join(";", modParameter)).append("\"");
return sb.toString();
}
public static void start(Modset modset) {
start(modset, new String[]{});
}
public static void start(Modset modset, String... additionalParams) {
final Parameter armaPathParameter = Parameters.ARMA_PATH.toParameter();
File arma3battleye = new File((String) armaPathParameter.getValue(), "arma3battleye.exe");
final Parameter use64Bit = Parameters.USE_64_BIT_CLIENT.toParameter();
String gameParameters = getGameParameter(modset);
String additionalParameters = String.join(" ", additionalParams);
String battleEye = "\"" + arma3battleye.getAbsolutePath() + "\" 2 1 1 -exe " + ((Boolean) use64Bit.getValue() ? "arma3_x64.exe" : "arma3.exe");
String command = battleEye + " " + gameParameters + " " + additionalParameters;
Logger.getLogger(ArmaUtils.class.getName()).log(Level.INFO, command);
try {
Runtime.getRuntime().exec(command);
} catch (IOException e) {
Logger.getLogger(ArmaUtils.class.getName()).log(Level.INFO, "Starting failed!", e);
}
}
}