diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..aa047c8 --- /dev/null +++ b/.classpath @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/.project b/.project new file mode 100644 index 0000000..c2ef516 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + UpLauncher + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..ec1937b --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/src/fr/tyrolium/maxime/update/LauncherUpdate.java b/src/fr/tyrolium/maxime/update/LauncherUpdate.java new file mode 100644 index 0000000..499282f --- /dev/null +++ b/src/fr/tyrolium/maxime/update/LauncherUpdate.java @@ -0,0 +1,94 @@ +package fr.tyrolium.maxime.update; + +import fr.theshark34.openlauncherlib.bootstrap.Bootstrap; +import fr.theshark34.openlauncherlib.bootstrap.LauncherClasspath; +import fr.theshark34.openlauncherlib.bootstrap.LauncherInfos; +import fr.theshark34.openlauncherlib.util.ErrorUtil; +import fr.theshark34.openlauncherlib.util.GameDir; +import fr.theshark34.openlauncherlib.util.SplashScreen; +import fr.theshark34.supdate.BarAPI; +import fr.theshark34.supdate.SUpdate; +import fr.theshark34.swinger.colored.SColoredBar; + +import static fr.theshark34.swinger.Swinger.*; + +import java.io.File; +import java.io.IOException; + +public class LauncherUpdate { + + private static SplashScreen splash; + private static SColoredBar bar; + private static Thread barThread; + + private static final LauncherInfos TY_B_INFOS = new LauncherInfos("Tyrolium", "fr.tyrolium.maxime.launcher.LauncherFrame"); + private static final File TY_DIR = GameDir.createGameDir("TyroliumLauncher"); + private static final LauncherClasspath TY_B_CP = new LauncherClasspath(new File(TY_DIR, "Launcher/launcher.jar"), new File(TY_DIR, "Launcher/Libs/")); + + private static ErrorUtil errorUtil = new ErrorUtil(new File(TY_DIR, ("Launcher/crashes"))); + + public static void main(String[] args) { + + setResourcePath("/fr/tyrolium/maxime/update/ressources"); + displaySplash(); + try { + doUpdate(); + } catch (Exception e) { + errorUtil.catchError(e, "Impossible de mettre a jour le launcher !"); + barThread.interrupt(); + } + try { + launchLauncher(); + } catch (IOException e) { + errorUtil.catchError(e, "Impossible de lancer le launcher !"); + barThread.interrupt(); + } + } + + private static void displaySplash() { + + splash = new SplashScreen("Tyrolium", getResource("splash.png")); + + bar = new SColoredBar(getTransparentWhite(100), getTransparentWhite(175)); + bar.setBounds(0, 490, 350, 20); + splash.add(bar); + + splash.setBackground(TRANSPARENT); + splash.getContentPane().setBackground(TRANSPARENT); + splash.setVisible(true); + } + + private static void doUpdate() throws Exception{ + + SUpdate su = new SUpdate("http://tyrolium.fr/s-update-launch", new File(TY_DIR, "Launcher")); + + barThread = new Thread() { + @Override + public void run() { + while(!this.isInterrupted()) { + bar.setValue((int) (BarAPI.getNumberOfTotalDownloadedBytes() / 1000)); + bar.setMaximum((int) (BarAPI.getNumberOfTotalBytesToDownload() / 1000)); + } + } + }; + barThread.start(); + + su.start(); + barThread.interrupt(); + + } + + private static void launchLauncher() throws IOException{ + Bootstrap bootstrap = new Bootstrap(TY_B_CP, TY_B_INFOS); + Process p = bootstrap.launch(); + + splash.setVisible(false); + + try { + p.waitFor(); + } catch (InterruptedException e) { + } + System.exit(0); + } + +} \ No newline at end of file diff --git a/src/fr/tyrolium/maxime/update/ressources/splash.png b/src/fr/tyrolium/maxime/update/ressources/splash.png new file mode 100644 index 0000000..3804b7f Binary files /dev/null and b/src/fr/tyrolium/maxime/update/ressources/splash.png differ