Skip to content

Commit f19bfa1

Browse files
koder95koder95
authored andcommitted
Pierwsze kroki ku zbudowaniu systemu samoaktualizacji programu.
1 parent c656178 commit f19bfa1

File tree

7 files changed

+132
-2
lines changed

7 files changed

+132
-2
lines changed

eMetrykant.iml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" version="4">
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
33
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
44
<output url="file://$MODULE_DIR$/target/classes" />
55
<output-test url="file://$MODULE_DIR$/target/test-classes" />
@@ -11,5 +11,11 @@
1111
<orderEntry type="inheritedJdk" />
1212
<orderEntry type="sourceFolder" forTests="false" />
1313
<orderEntry type="library" name="Maven: org.controlsfx:controlsfx:8.40.16" level="project" />
14+
<orderEntry type="library" name="Maven: org.kohsuke:github-api:1.119" level="project" />
15+
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.9" level="project" />
16+
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.10.2" level="project" />
17+
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.10.2" level="project" />
18+
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.10.2" level="project" />
19+
<orderEntry type="library" name="Maven: commons-io:commons-io:2.4" level="project" />
1420
</component>
1521
</module>

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
<artifactId>controlsfx</artifactId>
4141
<version>8.40.16</version>
4242
</dependency>
43+
<dependency>
44+
<groupId>org.kohsuke</groupId>
45+
<artifactId>github-api</artifactId>
46+
<version>1.119</version>
47+
</dependency>
4348
</dependencies>
4449

4550
<distributionManagement>

src/main/java/pl/koder95/eme/Version.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,6 @@ public static Version parse(Class klasa) {
290290
* @return wersja tego programu
291291
*/
292292
public static Version get() {
293-
return parse("0.4.0");
293+
return parse("0.5.0");
294294
}
295295
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package pl.koder95.eme.au;
2+
3+
import javafx.concurrent.Service;
4+
5+
public class AutoUpdateService extends Service<Object> {
6+
@Override
7+
protected AutoUpdateTask createTask() {
8+
return null;
9+
}
10+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package pl.koder95.eme.au;
2+
3+
import javafx.application.Platform;
4+
import javafx.concurrent.Task;
5+
import pl.koder95.eme.Main;
6+
7+
import java.io.File;
8+
import java.io.IOException;
9+
import java.net.URISyntaxException;
10+
11+
public class AutoUpdateTask extends Task<Object> {
12+
@Override
13+
protected Object call() throws Exception {
14+
return null;
15+
}
16+
17+
private static void restart() {
18+
Platform.exit();
19+
try {
20+
final String javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
21+
File self = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI());
22+
ProcessBuilder builder = new ProcessBuilder();
23+
builder.command(javaBin, "-jar", self.getName());
24+
builder.start();
25+
} catch (IOException | URISyntaxException e) {
26+
e.printStackTrace();
27+
}
28+
System.exit(0);
29+
}
30+
31+
private static void generateUpdateScript() {}
32+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package pl.koder95.eme.au;
2+
3+
import org.kohsuke.github.*;
4+
5+
import java.io.IOException;
6+
import java.net.HttpURLConnection;
7+
8+
public class GitHubRepositoryController {
9+
10+
private GitHub createNewConnection() throws IOException {
11+
return new GitHubBuilder().withRateLimitHandler(new RateLimitHandler() {
12+
@Override
13+
public void onError(IOException e, HttpURLConnection uc) {
14+
e.printStackTrace();
15+
System.out.println(uc);
16+
}
17+
}).withOAuthToken("5c3210fa72227686dbaf630c6e192e68e7fae89c").build();
18+
}
19+
20+
private GitHub connection = null;
21+
22+
GitHub getConnection() {
23+
while(connection == null) {
24+
try {
25+
connection = createNewConnection();
26+
} catch (IOException e) {
27+
e.printStackTrace();
28+
}
29+
}
30+
return connection;
31+
}
32+
33+
final String username;
34+
final String repositoryName;
35+
36+
public GitHubRepositoryController(String username, String repositoryName) {
37+
this.username = username;
38+
this.repositoryName = repositoryName;
39+
}
40+
41+
private GHUser user = null;
42+
43+
private void selectUser() throws IOException {
44+
GitHub connection = getConnection();
45+
if (connection.isOffline()) {
46+
this.connection = null;
47+
selectUser();
48+
}
49+
else {
50+
user = connection.getUser(username);
51+
}
52+
}
53+
54+
private GHRepository repo = null;
55+
56+
private void selectRepository() throws IOException {
57+
if (user == null) throw new IllegalStateException("User is not selected.");
58+
else repo = user.getRepository(repositoryName);
59+
}
60+
61+
public void init() {
62+
try {
63+
selectUser();
64+
selectRepository();
65+
} catch (IOException e) {
66+
throw new ExceptionInInitializerError(e);
67+
}
68+
}
69+
70+
public GHRepository getRepository() {
71+
return repo;
72+
}
73+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Paczka zawiera klasy odpowiedzialne za pobieranie i wprowadzanie aktualizacji.
3+
*/
4+
package pl.koder95.eme.au;

0 commit comments

Comments
 (0)