created modules and added patcher

This commit is contained in:
Niklas 2020-03-29 23:37:39 +02:00
parent beb80b8597
commit c4fbe48055
60 changed files with 399 additions and 111 deletions

2
.gitignore vendored
View File

@ -3,3 +3,5 @@
out/
META-INF/
target/
gui/target/
patcher/target/

129
gui/pom.xml Normal file
View File

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.mc8051</groupId>
<artifactId>arma3launcher</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>gui</artifactId>
<version>0.1.1000</version>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>com.formdev</groupId>
<artifactId>flatlaf</artifactId>
<version>0.28</version>
</dependency>
<dependency>
<groupId>com.github.RalleYTN</groupId>
<artifactId>SimpleRegistry</artifactId>
<version>java8-7949ac7f06-1</version>
</dependency>
<dependency>
<groupId>org.ini4j</groupId>
<artifactId>ini4j</artifactId>
<version>0.5.4</version>
</dependency>
<dependency>
<groupId>com.github.Gurkengewuerz</groupId>
<artifactId>zsyncer</artifactId>
<version>1de0d3f651</version>
</dependency>
<dependency>
<groupId>com.jgoodies</groupId>
<artifactId>jgoodies-forms</artifactId>
<version>1.9.0</version>
</dependency>
<dependency>
<groupId>com.intellij</groupId>
<artifactId>forms_rt</artifactId>
<version>7.0.3</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/project.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources/icons</directory>
<filtering>false</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>12</source>
<target>12</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<finalName>${parent.artifactId}-${project.artifactId}</finalName>
<descriptorRefs>
<descriptorRef>
jar-with-dependencies
</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>${project.groupId}.${parent.artifactId}.ArmA3Launcher</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>assamble</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,5 +1,6 @@
package de.mc8051.arma3launcher;
import com.sun.management.OperatingSystemMXBean;
import de.mc8051.arma3launcher.interfaces.Observer;
import de.mc8051.arma3launcher.model.JCheckBoxTree;
import de.mc8051.arma3launcher.model.ModListRenderer;
@ -737,7 +738,7 @@ public class LauncherGUI implements Observer {
// -------------------------------- SPINNER --------------------------------
com.sun.management.OperatingSystemMXBean mxbean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
OperatingSystemMXBean mxbean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
int memorySize = (int) (mxbean.getTotalPhysicalMemorySize() / 1024);
initSpinner(settingsMaxMemSpinner, "MaxMem", Parameter.ParameterType.ARMA, -1, memorySize);

View File

Before

Width:  |  Height:  |  Size: 536 B

After

Width:  |  Height:  |  Size: 536 B

View File

Before

Width:  |  Height:  |  Size: 476 B

After

Width:  |  Height:  |  Size: 476 B

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

Before

Width:  |  Height:  |  Size: 511 B

After

Width:  |  Height:  |  Size: 511 B

View File

Before

Width:  |  Height:  |  Size: 237 B

After

Width:  |  Height:  |  Size: 237 B

View File

Before

Width:  |  Height:  |  Size: 566 B

After

Width:  |  Height:  |  Size: 566 B

View File

Before

Width:  |  Height:  |  Size: 912 B

After

Width:  |  Height:  |  Size: 912 B

View File

@ -0,0 +1,197 @@
/*
* MIT License
*
* Copyright (c) 2020-2020 Niklas Schütrumpf (Gurkengewuerz)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package de.mc8051.arma3launcher;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.List;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.Flow;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Created by gurkengewuerz.de on 29.03.2020.
*/
public class Arma3LauncherPatcher {
public static void main(String[] args) {
if (args.length != 2) {
Logger.getLogger(Arma3LauncherPatcher.class.getName()).log(Level.SEVERE, "<url> <old_programm>");
return;
}
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ignored) {
}
JFrame frame = new JFrame("Auto Patcher");
Patcher patcher = new Patcher();
frame.setContentPane(patcher.mainpanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setMinimumSize(new Dimension(500, 100));
frame.setResizable(false);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
frame.dispose();
}
});
frame.pack();
frame.setIconImage(createIcon());
frame.setLocationRelativeTo(null);
frame.setVisible(true);
HttpClient client = HttpClient.newHttpClient();
try {
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI(args[0]))
.GET()
.build();
File f = new File(args[1]);
String fileName = Paths.get(f.getPath()).getFileName().toString();
String fileExt = "";
if (fileName.indexOf(".") > 0) {
fileExt = fileName.substring(fileName.lastIndexOf(".") + 1);
fileName = fileName.substring(0, fileName.lastIndexOf("."));
}
Path tempFile = Files.createTempFile(fileName, fileExt);
HttpResponse<Path> response = client.send(request, responseInfo -> {
HttpResponse.BodyHandler<Path> bodyHandler = HttpResponse.BodyHandlers.ofFile(tempFile);
final String s = responseInfo.headers().firstValue("content-length").get();
long contentSize = Long.parseLong(s);
return new DownloadObserver(bodyHandler.apply(responseInfo), contentSize, patcher.progressBar1);
});
if (response.statusCode() != 200)
throw new IllegalStateException("Download file is invalid. Got response code " + response.statusCode());
Files.copy(tempFile, f.toPath(), StandardCopyOption.REPLACE_EXISTING);
run(f.getAbsolutePath());
JOptionPane.showMessageDialog(
frame,
"Launcher has been successfully updated.",
"Update", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
} catch (IOException | URISyntaxException | InterruptedException | IllegalStateException e) {
Logger.getLogger(Arma3LauncherPatcher.class.getName()).log(Level.SEVERE, null, e);
JOptionPane.showMessageDialog(
null,
"An error occured.\n" + e.getMessage() + "\nUpdate process aborded.",
"Update failed", JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
}
public static void run(String path) {
try {
Runtime.getRuntime().exec("\"" + System.getProperty("java.home") + File.separator + "bin" + File.separator + "java\" -jar \"" + path + "\"");
} catch (IOException ignored) {
}
}
static BufferedImage createIcon() {
try {
return ImageIO.read(Arma3LauncherPatcher.class.getResourceAsStream("/icons/logo_32.png"));
} catch (IOException e) {
Logger.getLogger(Arma3LauncherPatcher.class.getName()).log(Level.SEVERE, null, e);
return null;
}
}
private static class DownloadObserver implements HttpResponse.BodySubscriber<Path> {
private int counter = 0;
private long total = 0L;
private long contentSize = 0L;
private HttpResponse.BodySubscriber<Path> subscriber;
private JProgressBar progressBar;
public DownloadObserver(HttpResponse.BodySubscriber<Path> subscriber, long contentSize, JProgressBar progressBar) {
this.subscriber = subscriber;
this.contentSize = contentSize;
this.progressBar = progressBar;
}
@Override
public void onSubscribe(Flow.Subscription subscription) {
subscriber.onSubscribe(subscription);
}
@Override
public void onNext(List<ByteBuffer> item) {
item.forEach((size) -> {
total += size.remaining();
});
int progress = (int) (((double) total / (double) contentSize) * 100);
SwingUtilities.invokeLater(() -> progressBar.setValue(progress));
counter++;
subscriber.onNext(item);
}
@Override
public void onError(Throwable throwable) {
subscriber.onError(throwable);
}
@Override
public void onComplete() {
subscriber.onComplete();
}
@Override
public CompletionStage<Path> getBody() {
return subscriber.getBody();
}
}
}

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="de.mc8051.arma3launcher.Patcher">
<grid id="27dc6" binding="mainpanel" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<xy x="20" y="20" width="691" height="270"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="2ca5" class="javax.swing.JProgressBar" binding="progressBar1" default-binding="true">
<constraints border-constraint="Center"/>
<properties>
<minimumSize width="10" height="4"/>
<string value=""/>
<value value="0"/>
</properties>
</component>
<component id="87955" class="javax.swing.JLabel">
<constraints border-constraint="North"/>
<properties>
<font size="16" style="1"/>
<text value="Launcher Updater"/>
</properties>
</component>
</children>
</grid>
</form>

View File

@ -0,0 +1,35 @@
/*
* MIT License
*
* Copyright (c) 2020-2020 Niklas Schütrumpf (Gurkengewuerz)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package de.mc8051.arma3launcher;
import javax.swing.*;
/**
* Created by gurkengewuerz.de on 29.03.2020.
*/
public class Patcher {
public JPanel mainpanel;
public JProgressBar progressBar1;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

115
pom.xml
View File

@ -6,114 +6,11 @@
<groupId>de.mc8051</groupId>
<artifactId>arma3launcher</artifactId>
<version>0.1.1000</version>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>com.formdev</groupId>
<artifactId>flatlaf</artifactId>
<version>0.28</version>
</dependency>
<dependency>
<groupId>com.github.RalleYTN</groupId>
<artifactId>SimpleRegistry</artifactId>
<version>java8-7949ac7f06-1</version>
</dependency>
<dependency>
<groupId>org.ini4j</groupId>
<artifactId>ini4j</artifactId>
<version>0.5.4</version>
</dependency>
<dependency>
<groupId>com.github.Gurkengewuerz</groupId>
<artifactId>zsyncer</artifactId>
<version>1de0d3f651</version>
</dependency>
<dependency>
<groupId>com.jgoodies</groupId>
<artifactId>jgoodies-forms</artifactId>
<version>1.9.0</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/project.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources/icons</directory>
<filtering>false</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>12</source>
<target>12</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<finalName>${project.artifactId}</finalName>
<descriptorRefs>
<descriptorRef>
jar-with-dependencies
</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>${project.groupId}.${project.artifactId}.ArmA3Launcher</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>assamble</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
<modules>
<module>gui</module>
<module>patcher</module>
</modules>
</project>