Progressbar Downloader und neues System

This commit is contained in:
simonr 2016-10-26 23:58:22 +02:00
parent e96a5a3077
commit 524139acb3
16 changed files with 112 additions and 134 deletions

3
Xerxes
View file

@ -1,3 +0,0 @@
1.10.2
mod2.jar
mod1.jar

Binary file not shown.

BIN
modpack/Minecraft.jar Normal file

Binary file not shown.

BIN
modpack/forge.jar Normal file

Binary file not shown.

BIN
modpack/modpack.zip Normal file

Binary file not shown.

View file

@ -0,0 +1 @@
1.10.2

View file

@ -20,52 +20,17 @@ public class ModpackDownloader {
static int mods = 0; static int mods = 0;
public static String zeile = ""; public static String zeile = "";
public static String version;
public static void main(String[] args) throws MalformedURLException, IOException { public static void main(String[] args) throws MalformedURLException, IOException {
//Modpack-Config Download //Modpack Download
ModpackDownloader2.URL = GUI.URL + zeile + ".zip"; ModpackDownloader1.URL = GUI.URL + zeile + ".zip";
ModpackDownloader2.output = "./modpack/modpack.zip"; ModpackDownloader1.output = "./modpack/modpack.zip";
ModpackDownloader2.main(null); ModpackDownloader1.main(null);
UnZip.modpack = "./modpack/modpack.zip"; UnZip.modpack = "./modpack/modpack.zip";
UnZip.modpack1 = GUI.datei + "/"; UnZip.modpack1 = GUI.datei + "/";
UnZip.main(); UnZip.main();
//Modpack URL Suchen
ModpackDownloader2.URL = GUI.URL + zeile;
ModpackDownloader2.output = "./modpack/modpack.txt";
ModpackDownloader2.main(null);
//Progressbar Modpack durchsuchen
FileReader fr = new FileReader("./modpack/modpack.txt");
BufferedReader br = new BufferedReader(fr);
while ((zeile = br.readLine()) != null) {
mods++;
}
System.out.println("Mods = " + mods);
//Modpack Installieren
FileReader fr1 = new FileReader("./modpack/modpack.txt");
BufferedReader br1 = new BufferedReader(fr1);
version = br1.readLine();
while ((zeile = br1.readLine()) != null) {
ModpackDownloader2.URL = GUI.URL + "mods/" + version + "/" + zeile;
ModpackDownloader2.output = GUI.datei + "/mods/" + zeile;
ModpackDownloader2.main(null);
System.out.println("URL = " + GUI.URL + version + "/" + zeile);
System.out.println("Output = " + GUI.datei + "/mods/" + zeile);
//Progressbar
GUI.zahl = mods;
GUI.datei1 = zeile;
GUI c = new GUI();
c.progressnext();
}
} }
} }

View file

@ -0,0 +1,78 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ModpackDownloader;
import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
public class ModpackDownloader1 {
static String URL;
static String output;
private static JProgressBar jProgressBar;
public static void main(String[] args) {
jProgressBar = new JProgressBar();
jProgressBar.setMaximum(100000);
JFrame frame = new JFrame();
frame.setContentPane(jProgressBar);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.setSize(300, 70);
frame.setVisible(true);
run();
frame.dispose();
}
public static void run() {
try {
URL url = new URL(URL);
HttpURLConnection httpConnection = (HttpURLConnection) (url.openConnection());
long completeFileSize = httpConnection.getContentLength();
java.io.BufferedInputStream in = new java.io.BufferedInputStream(httpConnection.getInputStream());
java.io.FileOutputStream fos = new java.io.FileOutputStream(output);
java.io.BufferedOutputStream bout = new BufferedOutputStream(
fos, 1024);
byte[] data = new byte[1024];
long downloadedFileSize = 0;
int x = 0;
while ((x = in.read(data, 0, 1024)) >= 0) {
downloadedFileSize += x;
// calculate progress
final int currentProgress = (int) ((((double) downloadedFileSize) / ((double) completeFileSize)) * 100000d);
// update progress bar
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
jProgressBar.setValue(currentProgress);
}
});
bout.write(data, 0, x);
}
bout.close();
in.close();
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
}

View file

@ -1,44 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ModpackDownloader;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
/**
*
* @author simonr
*/
public class ModpackDownloader2 {
static String URL;
static String output;
public static void main(String[] args) throws MalformedURLException, IOException {
final URL url = new URL(URL);
final URLConnection conn = url.openConnection();
try (InputStream is = new BufferedInputStream(conn.getInputStream())) {
final OutputStream os;
os = new BufferedOutputStream(new FileOutputStream(output));
byte[] chunk = new byte[1024];
int chunkSize;
while ((chunkSize = is.read(chunk)) != -1) {
os.write(chunk, 0, chunkSize);
}
os.flush(); // Necessary for Java < 6
os.close();
}
}
}

View file

@ -8,7 +8,9 @@ package ModpackDownloader;
import forgemodpackbuilder.GUI; import forgemodpackbuilder.GUI;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URL; import java.net.URL;
@ -18,8 +20,6 @@ import java.net.URLConnection;
* *
* @author simonr * @author simonr
*/ */
public class downloader1 { public class downloader1 {
public static void main(String[] args) throws Throwable { public static void main(String[] args) throws Throwable {
@ -31,6 +31,7 @@ public class downloader1 {
String total = ""; String total = "";
String version = ""; String version = "";
String version1 = "";
if (GUI.version.equals("1.10.2")) { if (GUI.version.equals("1.10.2")) {
version = forge10; version = forge10;
@ -46,16 +47,22 @@ public class downloader1 {
} }
if (GUI.version.equals("Modpacks")) { if (GUI.version.equals("Modpacks")) {
if (ModpackDownloader.version.equals("1.10.2")) { FileReader fr = new FileReader("./modpack/modpack/version.txt");
BufferedReader br = new BufferedReader(fr);
version1 = br.readLine();
br.close();
if (version1.equals("1.10.2")) {
version = forge10; version = forge10;
} }
if (ModpackDownloader.version.equals("1.9.4")) { if (version1.equals("1.9.4")) {
version = forge9; version = forge9;
} }
if (ModpackDownloader.version.equals("1.8.9")) { if (version1.equals("1.8.9")) {
version = forge8; version = forge8;
} }
if (ModpackDownloader.version.equals("1.7.10")) { if (version1.equals("1.7.10")) {
version = forge7; version = forge7;
} }
} }

View file

@ -16,19 +16,12 @@ import java.io.IOException;
*/ */
public class Modpacktxt { public class Modpacktxt {
static String name;
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
FileWriter fw = new FileWriter(name); FileWriter fw = new FileWriter("./modpack/modpack/version.txt");
BufferedWriter bw = new BufferedWriter(fw); BufferedWriter bw = new BufferedWriter(fw);
bw.write(GUI.version); bw.write(GUI.version);
bw.newLine();
for (int i = 0; i < GUI.mods1.size(); i++) {
bw.write(GUI.mods1.get(i).substring( GUI.mods1.get(i).lastIndexOf( "/" ) + 1 ));
bw.newLine();
}
bw.close(); bw.close();
} }

View file

@ -16,7 +16,6 @@ import net.lingala.zip4j.util.*;
public class Zip { public class Zip {
String modpack = ""; String modpack = "";
static String datum = "";
void archiveDir(String path) { void archiveDir(String path) {
try { try {
@ -25,7 +24,7 @@ public class Zip {
ZipFile zipFile = new ZipFile(modpack + ".zip"); ZipFile zipFile = new ZipFile(modpack + ".zip");
// Folder to add // Folder to add
String folderToAdd = "./modpack/modpack/config"; String folderToAdd = "./modpack/modpack";
// Initiate Zip Parameters which define various properties such // Initiate Zip Parameters which define various properties such
// as compression method, etc. // as compression method, etc.
@ -38,7 +37,7 @@ public class Zip {
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL); parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
// Set the root folder // Set the root folder
//parameters.setIncludeRootFolder(false); parameters.setIncludeRootFolder(false);
// Add folder to the zip file // Add folder to the zip file
zipFile.addFolder(folderToAdd, parameters); zipFile.addFolder(folderToAdd, parameters);

View file

@ -77,19 +77,20 @@ public class frage extends javax.swing.JFrame {
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
try {
// TODO add your handling code here: // TODO add your handling code here:
String name = jTextField1.getText(); String name = jTextField1.getText();
System.out.println(name); System.out.println(name);
Modpacktxt.main(null);
Zip a = new Zip(); Zip a = new Zip();
a.modpack = name; a.modpack = name;
a.archiveDir(null); a.archiveDir(null);
Modpacktxt.name = name; this.dispose();
try {
Modpacktxt.main(null);
} catch (IOException ex) { } catch (IOException ex) {
Logger.getLogger(frage.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(frage.class.getName()).log(Level.SEVERE, null, ex);
} }
this.dispose();
}//GEN-LAST:event_jButton1ActionPerformed }//GEN-LAST:event_jButton1ActionPerformed

View file

@ -27,7 +27,6 @@
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="jProgressBar1" max="32767" attributes="0"/>
<Group type="102" attributes="0"> <Group type="102" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/> <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="4" max="-2" attributes="0"/> <EmptySpace min="-2" pref="4" max="-2" attributes="0"/>
@ -94,11 +93,9 @@
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0"> <Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="jScrollPane1" pref="478" max="32767" attributes="0"/> <Component id="jScrollPane1" pref="504" max="32767" attributes="0"/>
<Component id="jScrollPane3" max="32767" attributes="0"/> <Component id="jScrollPane3" max="32767" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="jProgressBar1" min="-2" max="-2" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
@ -241,8 +238,6 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jTextField1ActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jTextField1ActionPerformed"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JProgressBar" name="jProgressBar1">
</Component>
<Component class="javax.swing.JButton" name="jButton7"> <Component class="javax.swing.JButton" name="jButton7">
<Properties> <Properties>
<Property name="text" type="java.lang.String" value="Server-URL"/> <Property name="text" type="java.lang.String" value="Server-URL"/>

View file

@ -70,7 +70,6 @@ public class GUI extends javax.swing.JFrame {
jButton6 = new javax.swing.JButton(); jButton6 = new javax.swing.JButton();
jButton8 = new javax.swing.JButton(); jButton8 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField(); jTextField1 = new javax.swing.JTextField();
jProgressBar1 = new javax.swing.JProgressBar();
jButton7 = new javax.swing.JButton(); jButton7 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
@ -167,7 +166,6 @@ public class GUI extends javax.swing.JFrame {
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jProgressBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(jLabel1) .addComponent(jLabel1)
.addGap(4, 4, 4) .addGap(4, 4, 4)
@ -222,10 +220,8 @@ public class GUI extends javax.swing.JFrame {
.addComponent(jButton3))) .addComponent(jButton3)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 478, Short.MAX_VALUE) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 504, Short.MAX_VALUE)
.addComponent(jScrollPane3)) .addComponent(jScrollPane3)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
); );
pack(); pack();
@ -397,15 +393,6 @@ public class GUI extends javax.swing.JFrame {
System.out.println(URL); System.out.println(URL);
}//GEN-LAST:event_jButton7ActionPerformed }//GEN-LAST:event_jButton7ActionPerformed
public void progressnext() {
jProgressBar1.setMaximum(zahl);
jProgressBar1.setValue(jProgressBar1.getValue() + 1);
jProgressBar1.setStringPainted(true);
jProgressBar1.setString(datei);
}
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1; private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2; private javax.swing.JButton jButton2;
@ -420,7 +407,6 @@ public class GUI extends javax.swing.JFrame {
private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel2;
private javax.swing.JList<String> jList1; private javax.swing.JList<String> jList1;
private javax.swing.JList<String> jList2; private javax.swing.JList<String> jList2;
private javax.swing.JProgressBar jProgressBar1;
private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane3; private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField1;