finished update checker
This commit is contained in:
parent
b285db0d37
commit
2a96b72a24
10 changed files with 190 additions and 25 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/bin/
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -5,6 +5,13 @@ import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JProgressBar;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JTextArea;
|
||||||
|
|
||||||
public class DownloadLevels {
|
public class DownloadLevels {
|
||||||
|
|
||||||
private ManageFiles data = new ManageFiles();
|
private ManageFiles data = new ManageFiles();
|
||||||
|
@ -12,30 +19,84 @@ public class DownloadLevels {
|
||||||
|
|
||||||
public void download() throws IOException {
|
public void download() throws IOException {
|
||||||
|
|
||||||
String fileURL;
|
|
||||||
|
|
||||||
for(int i = 0; i < data.missingLevels().size(); i++) {
|
JFrame main = new JFrame("Updater");
|
||||||
|
main.setSize(400, 300);
|
||||||
System.out.println("downloading " + data.missingLevels().get(i));
|
main.setLayout(null);
|
||||||
fileURL = "https://raw.githubusercontent.com/All-Rated-Extreme-Demon-List/AREDL/main/data/" + data.missingLevels().get(i) + ".json";
|
main.setResizable(false);
|
||||||
|
main.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||||
try (BufferedInputStream in = new BufferedInputStream(new URL(fileURL).openStream());
|
|
||||||
|
JLabel info = new JLabel("Es werden " + data.missingLevels().size() + " Level heruntergeladen.");
|
||||||
FileOutputStream fileOutputStream = new FileOutputStream("C:\\ExtremeDemonList\\levels\\" + data.missingLevels().get(i) + ".json")) {
|
info.setBounds(80, 1, 500, 30);
|
||||||
|
|
||||||
byte dataBuffer[] = new byte[1024];
|
JTextArea area = new JTextArea();
|
||||||
int bytesRead;
|
area.setEditable(false);
|
||||||
|
area.setLineWrap(true);
|
||||||
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
|
area.setWrapStyleWord(true);
|
||||||
|
|
||||||
fileOutputStream.write(dataBuffer, 0, bytesRead);
|
|
||||||
|
JScrollPane scroll = new JScrollPane(area);
|
||||||
}
|
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||||||
} catch (IOException e) {
|
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||||
// Handle exceptions
|
scroll.setBounds(1, 60, 383, 201);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
JProgressBar bar = new JProgressBar();
|
||||||
}
|
bar.setBounds(1, 29, 382, 30);
|
||||||
|
bar.setMinimum(0);
|
||||||
|
bar.setMaximum(data.missingLevels().size());
|
||||||
|
bar.setStringPainted(true);
|
||||||
|
|
||||||
|
main.add(info);
|
||||||
|
main.add(scroll);
|
||||||
|
main.add(bar);
|
||||||
|
main.setVisible(true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Thread serverThread = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
String fileURL;
|
||||||
|
for(int i = 0; i < data.missingLevels().size(); i++) {
|
||||||
|
|
||||||
|
area.setCaretPosition(area.getDocument().getLength());
|
||||||
|
|
||||||
|
bar.setValue(i + 1);
|
||||||
|
|
||||||
|
area.append(i + 1 + "| " + data.missingLevels().get(i) + " wird heruntergeladen. ");
|
||||||
|
|
||||||
|
System.out.println("downloading " + data.missingLevels().get(i));
|
||||||
|
fileURL = "https://raw.githubusercontent.com/All-Rated-Extreme-Demon-List/AREDL/main/data/" + data.missingLevels().get(i) + ".json";
|
||||||
|
|
||||||
|
try (BufferedInputStream in = new BufferedInputStream(new URL(fileURL).openStream());
|
||||||
|
|
||||||
|
FileOutputStream fileOutputStream = new FileOutputStream("C:\\ExtremeDemonList\\levels\\" + data.missingLevels().get(i) + ".json")) {
|
||||||
|
|
||||||
|
byte dataBuffer[] = new byte[1024];
|
||||||
|
int bytesRead;
|
||||||
|
|
||||||
|
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
|
||||||
|
|
||||||
|
fileOutputStream.write(dataBuffer, 0, bytesRead);
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
// Handle exceptions
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
area.append(" >> ERFOLGREICH \n");
|
||||||
|
}
|
||||||
|
JOptionPane.showMessageDialog(null, "Alle " + data.missingLevels().size() + " Level wurden erfolgreich heruntergeladen.", "Download abgeschlossen", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
main.dispose();
|
||||||
|
|
||||||
|
System.out.println("main gui starten IN DOWNLOADLEVELS NICHT VERGESSEN HIER EINFÜGEN");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
serverThread.start();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,14 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import gui.MissingLevels;
|
||||||
|
|
||||||
public class ManageFiles {
|
public class ManageFiles {
|
||||||
|
|
||||||
private FetchData fetch = new FetchData();
|
private FetchData fetch = new FetchData();
|
||||||
|
private MissingLevels gui = new MissingLevels();
|
||||||
private static ArrayList<String> missinglevels = new ArrayList<String>(); // fehlende noch zu herunterladende level
|
private static ArrayList<String> missinglevels = new ArrayList<String>(); // fehlende noch zu herunterladende level
|
||||||
|
private int missing = 0;
|
||||||
|
|
||||||
|
|
||||||
private void feedMissingLevelsArray(String levelname) { // fehlende level werden missinglevels hinzugefügt
|
private void feedMissingLevelsArray(String levelname) { // fehlende level werden missinglevels hinzugefügt
|
||||||
|
@ -26,9 +30,14 @@ public class ManageFiles {
|
||||||
if(!file.exists()) { // wenn der level lokal nicht vorhanden ist, wird er als fehlend gemeldet.
|
if(!file.exists()) { // wenn der level lokal nicht vorhanden ist, wird er als fehlend gemeldet.
|
||||||
System.out.println(fetch.allLevels().get(i) + " fehlt");
|
System.out.println(fetch.allLevels().get(i) + " fehlt");
|
||||||
feedMissingLevelsArray(fetch.allLevels().get(i));
|
feedMissingLevelsArray(fetch.allLevels().get(i));
|
||||||
|
missing++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(missing > 0) {
|
||||||
|
gui.show(missinglevels, missing);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> missingLevels() { // missinglevels wird zurückgegeben
|
public ArrayList<String> missingLevels() { // missinglevels wird zurückgegeben
|
||||||
|
|
94
src/gui/MissingLevels.java
Normal file
94
src/gui/MissingLevels.java
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
package gui;
|
||||||
|
|
||||||
|
import java.awt.Button;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JTextArea;
|
||||||
|
|
||||||
|
import data.DownloadLevels;
|
||||||
|
|
||||||
|
public class MissingLevels {
|
||||||
|
|
||||||
|
public void show(ArrayList<String> missinglevels, int missing) {
|
||||||
|
|
||||||
|
JFrame main = new JFrame("Liste nicht aktuell");
|
||||||
|
main.setSize(400, 360);
|
||||||
|
main.setLayout(null);
|
||||||
|
main.setResizable(false);
|
||||||
|
main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
|
JLabel missingLevelsLabel = new JLabel("Für die Liste ist ein Update verfügbar.");
|
||||||
|
missingLevelsLabel.setBounds(80, 1, 380, 20);
|
||||||
|
|
||||||
|
JLabel infoLabel = new JLabel("Folgende " + missing + " Level sind nicht vorhanden: ");
|
||||||
|
infoLabel.setBounds(1, 40, 380, 20);
|
||||||
|
|
||||||
|
JLabel separator = new JLabel("____________________________________________________________________________________________________________________");
|
||||||
|
separator.setBounds(0, 260, 500, 30);
|
||||||
|
|
||||||
|
JLabel question = new JLabel("Möchten Sie die Liste aktualisieren?");
|
||||||
|
question.setBounds(90, 255, 500, 30);
|
||||||
|
|
||||||
|
Button yes = new Button("Ja");
|
||||||
|
yes.setBounds(72, 285, 100, 30);
|
||||||
|
|
||||||
|
Button no = new Button("Nein");
|
||||||
|
no.setBounds(200, 285, 100, 30);
|
||||||
|
|
||||||
|
JTextArea area = new JTextArea();
|
||||||
|
area.setEditable(false);
|
||||||
|
area.setLineWrap(true);
|
||||||
|
area.setWrapStyleWord(true);
|
||||||
|
|
||||||
|
JScrollPane scroll = new JScrollPane(area);
|
||||||
|
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||||||
|
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||||
|
scroll.setBounds(1, 60, 383, 201);
|
||||||
|
|
||||||
|
for(int i = 0; i < missinglevels.size(); i++) {
|
||||||
|
area.append(missinglevels.get(i) + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
yes.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
main.dispose();
|
||||||
|
DownloadLevels download = new DownloadLevels();
|
||||||
|
try {
|
||||||
|
download.download();
|
||||||
|
} catch (IOException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
no.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
// haupt gui aufrufen
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
main.add(missingLevelsLabel);
|
||||||
|
main.add(infoLabel);
|
||||||
|
main.add(scroll);
|
||||||
|
main.add(question);
|
||||||
|
main.add(yes);
|
||||||
|
main.add(no);
|
||||||
|
main.add(separator);
|
||||||
|
|
||||||
|
main.setVisible(true);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -20,8 +20,7 @@ public class Main {
|
||||||
ManageFiles manager = new ManageFiles();
|
ManageFiles manager = new ManageFiles();
|
||||||
manager.compareArrays();
|
manager.compareArrays();
|
||||||
|
|
||||||
DownloadLevels download = new DownloadLevels();
|
|
||||||
download.download();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,4 +5,5 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
module ExtremeDemonList {
|
module ExtremeDemonList {
|
||||||
|
requires java.desktop;
|
||||||
}
|
}
|
Loading…
Reference in a new issue