Skip to content

Commit

Permalink
MTE Updater First Release (#56)
Browse files Browse the repository at this point in the history
* Add updater gitignore file

* Add guide version text file

* Create new class for UnzipUtility

* Clean up imports

* Add setup cleanup method

* Add guide file update functionality

* Sort code and add more logging

* Handle exceptions the right way

* Properly close reader instance

* Add some output line separators

* Add updater source file

* Add updater batch script

* Update gitignore file

* Add MWSE updater to startup script

* Add Java check to startup script

* Implement jar file check

* Convert to Gradle project

This way we can auto-manage our dependencies

* Change package names

* Trim trailing space from Main class

* Configure Gradle to compile on Java 8

* Auto-format class code

* Add Shadow gradle plugin

* Replace updater script with Shadow default

* Add custom code to updater script

* Add new line to output print

* Improve website compare display

Enabled richDiff and commit range in display

* Add release number to version file

* Do major framework restructuring

Resolves #46

* Implement 7z archive support

Resolves #49

* Make user input parsing non case-sensitive

* Implement custom logging system

Resolves #50

* Add new logging levels

* Make logging tags tied to enums

* Skip MWSE update if debugging

* Update all logging calls

* Add two more error logs

* Write better user input response

* Fix invalid exception throw

* Fix logging parsing problem

* Fix error logs not printing

* Implement log file printing

Logs can now be printed to a log file.
Errors will automatically print stack trace in log file.

* Create custom LogFile class

* Add exceptions to warning arguments

* Make logger more public

* Update launcher jvm arguments

* Implement application self-update

Resolves #47

* Trim trailing space and minor formatting

* Enable website browsing

* Improve updater logic

Compare links should not be browsed if the local version file is missing.

* Create dedicated execution class

This class will be used to store methods that interact with system processes and the command prompt.

* Improve tmp file cleaning

* Enable downloads tmp registration

* Implement application self-update

Resolves #47

* Add wait option to exec start

* Rename main update method

* Update mwse from application

Move the mwse update command from the launcher into the main app.

* Add some logging and comments

* Reduce number of imports

* Implement runmode definition handling

* Separate self update into a new method

* Make exit calls pause the program

* Improve the logging system

- Logs printed to logfile have a different prefix format for better readability
- Method code has been refactored

* Catch unhandled exceptions

* Fix run mode argument error

* Fix logs being printed in new lines

* Resolve system input stream error

* Kill launcher application properly

* Redirect mwse updater output to logfile

* Catch new exception

* Rewrite uninstaller script

Script stopped working for some reason so it needed to be rewritten

* Fix log formatting problem

File separators were treated as special characters and were getting removed

* Write logger exception safeguards

* Improve execute command methods

* Stop using winp for process managment

* Improve user input handling

Application should no longer crash due to input stream being closed.

* Move updater launcher script to build dir

This will make it easier to test the updater by having the launcher in the ShadowJar compile output directory.

* Relocate version file link to master branch
  • Loading branch information
matshou authored and Tyler799 committed Apr 19, 2019
1 parent 4f5c3bd commit bf7f45e
Show file tree
Hide file tree
Showing 17 changed files with 2,008 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Ignore Eclipse meta files
.metadata
.recommenders

# Ignore Gradle\IDE project-specific directories
.gradle
.settings

# Ignore build output directories
build
bin

# Eclipse Core
.project

# JDT-specific (Eclipse Java Development Tools)
.classpath
60 changes: 60 additions & 0 deletions MTEUpdater/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java Library project to get you started.
* For more details take a look at the Java Libraries chapter in the Gradle
* user guide available at https://docs.gradle.org/5.0/userguide/java_library_plugin.html
*/

plugins {
// Apply the java plugin to add support for Java
id 'java'
// Apply the application plugin to add support for building an application
id 'application'
// Gradle plugin for creating fat/uber JARs with support for package relocation
id 'com.github.johnrengelman.shadow' version '5.0.0'
}

repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
mavenCentral()
}

dependencies {
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:26.0-jre'

// https://mvnrepository.com/artifact/commons-io/commons-io
compile group: 'commons-io', name: 'commons-io', version: '2.6'

// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'

// https://mvnrepository.com/artifact/org.apache.commons/commons-compress
compile group: 'org.apache.commons', name: 'commons-compress', version: '1.18'

// https://mvnrepository.com/artifact/org.tukaani/xz
compile group: 'org.tukaani', name: 'xz', version: '1.8'

// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}

// Define the main class for the application
mainClassName = 'io.mte.updater.Main'

// Change the jar build name
shadowJar {
baseName = 'MTE-Updater'
classifier = null
version = null
}

// Define the main class for the jar manifest
jar {
manifest {
attributes 'Main-Class': 'updater/Main'
}
}
105 changes: 105 additions & 0 deletions MTEUpdater/build/libs/MTE-Updater.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem MTE-Updater startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%..
set JAVA_VERSION=18

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto checkJavaVersion

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:checkJavaVersion
@REM Check if an appropriate version of Java is installed
if not defined JAVA_VERSION goto init

echo Checking your Java version...
PATH %PATH%;%JAVA_HOME%\bin\
for /f tokens^=2-5^ delims^=.-_^" %%j in ('java -fullversion 2^>^&1') do set "jver=%%j%%k"
if %jver% lss %JAVA_VERSION% (
echo.
echo ERROR: Incorrect version of Java ^(%jver:~0,1%.%jver:~-1%^)
echo.
echo You do not have the correct version of Java installed
echo Please install Java SE Runtime Environment 8u202 ^(Java 8^)
echo which you can download from the official Java website
echo.
echo The URL has been copied to your clipboard
echo just paste it into your browser search bar and press enter
echo https://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html| clip

goto fail
)
goto init

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Add default JVM options here. You can also use JAVA_OPTS and MTE_UPDATER_OPTS to pass JVM options to this script.
set APPPATH=MTE-Updater.jar
set "MTE_UPDATER_OPTS=-Dprogram.name=%APPPATH%"

@rem Execute MTEUpdater
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %MTE_UPDATER_OPTS% -jar "%APPPATH%" --launcher %CMD_LINE_ARGS%

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable MTE_UPDATER_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%MTE_UPDATER_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
1 change: 1 addition & 0 deletions MTEUpdater/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.java.home=C:/Program Files/Java/jdk1.8.0_202/
Binary file added MTEUpdater/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions MTEUpdater/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
172 changes: 172 additions & 0 deletions MTEUpdater/gradlew
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#!/usr/bin/env sh

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn () {
echo "$*"
}

die () {
echo
echo "$*"
echo
exit 1
}

# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi

# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option

if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
Loading

0 comments on commit bf7f45e

Please sign in to comment.