diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/bin/data/DownloadLevels.class b/bin/data/DownloadLevels.class index 6d09a47..11e69df 100644 Binary files a/bin/data/DownloadLevels.class and b/bin/data/DownloadLevels.class differ diff --git a/bin/data/ManageFiles.class b/bin/data/ManageFiles.class index fcc7ce5..161a997 100644 Binary files a/bin/data/ManageFiles.class and b/bin/data/ManageFiles.class differ diff --git a/bin/main/Main.class b/bin/main/Main.class index bfc1924..913bbed 100644 Binary files a/bin/main/Main.class and b/bin/main/Main.class differ diff --git a/bin/module-info.class b/bin/module-info.class index 3ec61ff..86e5590 100644 Binary files a/bin/module-info.class and b/bin/module-info.class differ diff --git a/src/data/DownloadLevels.java b/src/data/DownloadLevels.java index 63b9759..7021908 100644 --- a/src/data/DownloadLevels.java +++ b/src/data/DownloadLevels.java @@ -5,6 +5,13 @@ import java.io.FileOutputStream; import java.io.IOException; 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 { private ManageFiles data = new ManageFiles(); @@ -12,30 +19,84 @@ public class DownloadLevels { public void download() throws IOException { - String fileURL; - for(int i = 0; i < data.missingLevels().size(); i++) { - - 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(); - } - } + JFrame main = new JFrame("Updater"); + main.setSize(400, 300); + main.setLayout(null); + main.setResizable(false); + main.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + + JLabel info = new JLabel("Es werden " + data.missingLevels().size() + " Level heruntergeladen."); + info.setBounds(80, 1, 500, 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); + + 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(); + + } } diff --git a/src/data/ManageFiles.java b/src/data/ManageFiles.java index 3e430fe..16ec12e 100644 --- a/src/data/ManageFiles.java +++ b/src/data/ManageFiles.java @@ -4,10 +4,14 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import gui.MissingLevels; + public class ManageFiles { private FetchData fetch = new FetchData(); + private MissingLevels gui = new MissingLevels(); private static ArrayList missinglevels = new ArrayList(); // fehlende noch zu herunterladende level + private int missing = 0; 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. System.out.println(fetch.allLevels().get(i) + " fehlt"); feedMissingLevelsArray(fetch.allLevels().get(i)); + missing++; } } + if(missing > 0) { + gui.show(missinglevels, missing); + } + } public ArrayList missingLevels() { // missinglevels wird zurückgegeben diff --git a/src/gui/MissingLevels.java b/src/gui/MissingLevels.java new file mode 100644 index 0000000..fa512b0 --- /dev/null +++ b/src/gui/MissingLevels.java @@ -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 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); + + + } + +} diff --git a/src/main/Main.java b/src/main/Main.java index 48b327c..fc82d4b 100644 --- a/src/main/Main.java +++ b/src/main/Main.java @@ -20,8 +20,7 @@ public class Main { ManageFiles manager = new ManageFiles(); manager.compareArrays(); - DownloadLevels download = new DownloadLevels(); - download.download(); + } diff --git a/src/module-info.java b/src/module-info.java index 8b64736..6588caa 100644 --- a/src/module-info.java +++ b/src/module-info.java @@ -5,4 +5,5 @@ * */ module ExtremeDemonList { + requires java.desktop; } \ No newline at end of file