// Path: core/client/src/main/java/de/danner_web/studip_client/Starter.java
// public class Starter {
// 
// 	/**
// 	 * Logger dieser Klasse.
// 	 */
// 	// private static Logger logger = LogManager.getLogger(Starter.class);
// 
// 	public static String getClientVersion() {
// 		Properties prop = new Properties();
// 		try {
// 			InputStream resourceAsStream = Starter.class.getResourceAsStream("/version.properties");
// 			prop.load(resourceAsStream);
// 		} catch (IOException e) {
// 			e.printStackTrace();
// 		}
// 		return prop.getProperty("version");
// 	}
// 
// 	public static void onUpdate(SettingsModel settings) {
// 		String oldVersion = settings.getVersion();
// 
// 		File updaterNew = new File("updater_new.jar");
// 		if (updaterNew.exists()) {
// 			try {
// 				Files.copy(updaterNew.toPath(), new File("updater.jar").toPath(), StandardCopyOption.REPLACE_EXISTING);
// 			} catch (IOException e) {
// 				e.printStackTrace();
// 			}
// 			try {
// 				Files.delete(updaterNew.toPath());
// 			} catch (IOException e) {
// 				e.printStackTrace();
// 			}
// 		}
// 
// 		if (VersionUtil.compareVersions(oldVersion, getClientVersion()) < 0) {
// 
// 			/*
// 			 * Add Update for new version here
// 			 * 
// 			 * If you want to update the update.jar you can do this here!
// 			 */
// 			// if (VersionUtil.compareVersions(oldVersion, "0.0.1") < 0) {
// 			// // EXAMPLE database changes from 0.0.1 on: add new Param to the
// 			// // Map of SettingsModel
// 			// }
// 			// if (VersionUtil.compareVersions(oldVersion, "0.1.0") < 0) {
// 			// // EXAMPLE database changes from 0.1.0 on: add new Param to the
// 			// // Map of SettingsModel
// 			// }
// 			// ...
// 			settings.setVersion(getClientVersion());
// 		}
// 	}
// 
// 	/**
// 	 * Entry Method for StudIP Client
// 	 * 
// 	 * @param args
// 	 *            no args are needed.
// 	 */
// 	public static void main(String[] args) {
// 
// 		if (args.length == 1 && "-d".equals(args[0])) {
// 			System.out.println("Delete Preferences from this Application");
// 			Preferences rootPref = Preferences.userNodeForPackage(Starter.class);
// 			try {
// 				rootPref.removeNode();
// 			} catch (BackingStoreException e) {
// 				e.printStackTrace();
// 				System.exit(1);
// 			}
// 			System.exit(0);
// 		}
// 
// 		if (args.length == 1 && "-v".equals(args[0])) {
// 			System.out.println(getClientVersion());
// 			System.exit(0);
// 		}
// 
// 		// Workaround for Bug #JDK-7075600, does not work proper
// 		System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");
// 
// 		// Bootstrap
// 		Model model = new Model();
// 		SettingsModel settings = model.getSettingsModel();
// 
// 		// Update install folder to provide portability
// 		settings.setInstallFolder(System.getProperty("user.dir"));
// 
// 		// Check on every start if the Client got updated, if yes perform some
// 		// changes.
// 		Starter.onUpdate(model.getSettingsModel());
// 
// 		model.getPluginModel().init();
// 		new ViewController(model);
// 	}
// }


import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ProcessBuilder.Redirect;
import java.math.BigInteger;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Enumeration;
import java.util.Observable;
import java.util.Vector;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import java.util.zip.ZipEntry;
import de.danner_web.studip_client.Starter;
package de.danner_web.studip_client.model;



public class UpdateModel extends Observable {

	private int progress = 1;
	private String status = "";

	/**
	 * This Path points to the Location where the Client is installed
	 */
	private Path clientLocation;

	// Names for settings, also in registry/XML file
	private static final String INSTALL_ID = "installID";
	private static final String AUTOUPDATE = "autoUpdate";
	private static final String VERSION = "client_version";

	/**
	 * Info extracted from prefs
	 */
	private String version;
	private String id;
	private boolean autoUpdate;
	private String clientApp = null;

	/**
	 * Temporary Path to download update.jar and extract it
	 */
	private Path tmpDir, extractedPath;

	public UpdateModel() {
		extractPrefs();

		clientLocation = (new File(System.getProperty("user.dir"))).toPath();
		clientApp = clientLocation + File.separator + "StudIP_Client.jar";
	}

	private void extractPrefs() {
		// Insert default values
		this.autoUpdate = true;
		this.version = "0";
		this.id = "1";

		// Load from prefs if possible
		try {
// Path: core/client/src/main/java/de/danner_web/studip_client/Starter.java
// public class Starter {
// 
// 	/**
// 	 * Logger dieser Klasse.
// 	 */
// 	// private static Logger logger = LogManager.getLogger(Starter.class);
// 
// 	public static String getClientVersion() {
// 		Properties prop = new Properties();
// 		try {
// 			InputStream resourceAsStream = Starter.class.getResourceAsStream("/version.properties");
// 			prop.load(resourceAsStream);
// 		} catch (IOException e) {
// 			e.printStackTrace();
// 		}
// 		return prop.getProperty("version");
// 	}
// 
// 	public static void onUpdate(SettingsModel settings) {
// 		String oldVersion = settings.getVersion();
// 
// 		File updaterNew = new File("updater_new.jar");
// 		if (updaterNew.exists()) {
// 			try {
// 				Files.copy(updaterNew.toPath(), new File("updater.jar").toPath(), StandardCopyOption.REPLACE_EXISTING);
// 			} catch (IOException e) {
// 				e.printStackTrace();
// 			}
// 			try {
// 				Files.delete(updaterNew.toPath());
// 			} catch (IOException e) {
// 				e.printStackTrace();
// 			}
// 		}
// 
// 		if (VersionUtil.compareVersions(oldVersion, getClientVersion()) < 0) {
// 
// 			/*
// 			 * Add Update for new version here
// 			 * 
// 			 * If you want to update the update.jar you can do this here!
// 			 */
// 			// if (VersionUtil.compareVersions(oldVersion, "0.0.1") < 0) {
// 			// // EXAMPLE database changes from 0.0.1 on: add new Param to the
// 			// // Map of SettingsModel
// 			// }
// 			// if (VersionUtil.compareVersions(oldVersion, "0.1.0") < 0) {
// 			// // EXAMPLE database changes from 0.1.0 on: add new Param to the
// 			// // Map of SettingsModel
// 			// }
// 			// ...
// 			settings.setVersion(getClientVersion());
// 		}
// 	}
// 
// 	/**
// 	 * Entry Method for StudIP Client
// 	 * 
// 	 * @param args
// 	 *            no args are needed.
// 	 */
// 	public static void main(String[] args) {
// 
// 		if (args.length == 1 && "-d".equals(args[0])) {
// 			System.out.println("Delete Preferences from this Application");
// 			Preferences rootPref = Preferences.userNodeForPackage(Starter.class);
// 			try {
// 				rootPref.removeNode();
// 			} catch (BackingStoreException e) {
// 				e.printStackTrace();
// 				System.exit(1);
// 			}
// 			System.exit(0);
// 		}
// 
// 		if (args.length == 1 && "-v".equals(args[0])) {
// 			System.out.println(getClientVersion());
// 			System.exit(0);
// 		}
// 
// 		// Workaround for Bug #JDK-7075600, does not work proper
// 		System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");
// 
// 		// Bootstrap
// 		Model model = new Model();
// 		SettingsModel settings = model.getSettingsModel();
// 
// 		// Update install folder to provide portability
// 		settings.setInstallFolder(System.getProperty("user.dir"));
// 
// 		// Check on every start if the Client got updated, if yes perform some
// 		// changes.
// 		Starter.onUpdate(model.getSettingsModel());
// 
// 		model.getPluginModel().init();
// 		new ViewController(model);
// 	}
// }


// Path: core/updater/src/main/java/de/danner_web/studip_client/model/UpdateModel.java
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ProcessBuilder.Redirect;
import java.math.BigInteger;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Enumeration;
import java.util.Observable;
import java.util.Vector;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import java.util.zip.ZipEntry;
import de.danner_web.studip_client.Starter;

package de.danner_web.studip_client.model;



public class UpdateModel extends Observable {

	private int progress = 1;
	private String status = "";

	/**
	 * This Path points to the Location where the Client is installed
	 */
	private Path clientLocation;

	// Names for settings, also in registry/XML file
	private static final String INSTALL_ID = "installID";
	private static final String AUTOUPDATE = "autoUpdate";
	private static final String VERSION = "client_version";

	/**
	 * Info extracted from prefs
	 */
	private String version;
	private String id;
	private boolean autoUpdate;
	private String clientApp = null;

	/**
	 * Temporary Path to download update.jar and extract it
	 */
	private Path tmpDir, extractedPath;

	public UpdateModel() {
		extractPrefs();

		clientLocation = (new File(System.getProperty("user.dir"))).toPath();
		clientApp = clientLocation + File.separator + "StudIP_Client.jar";
	}

	private void extractPrefs() {
		// Insert default values
		this.autoUpdate = true;
		this.version = "0";
		this.id = "1";

		// Load from prefs if possible
		try {
			Preferences rootPref = Preferences.userNodeForPackage(Starter.class);