JAL-3830 improved bash scripts. Added powershell script. Needs testing
[jalview.git] / utils / getdown / jalviewc.ps1
diff --git a/utils/getdown/jalviewc.ps1 b/utils/getdown/jalviewc.ps1
new file mode 100644 (file)
index 0000000..ff4d6d8
--- /dev/null
@@ -0,0 +1,28 @@
+# save first parameter
+$ARGS = $args
+$ARG1 = $args[0]
+# parent dir of this script (should be the getdown app dir)
+$DIR = Split-Path $MyInvocation.MyCommand.Path -Parent
+
+# insert an "-open" parameter to Jalview's ARGS if ARG1 is non-zero-length, and not "open" or starts with a "-"
+if ( $ARG1.length -gt 0 -and (-not $ARG1.StartsWith("-")) -and $ARG1 -ne "open" ) {
+  $ARGS = "-open " + $ARGS
+}
+
+$APPDIR = $DIR
+$JAVA = "${APPDIR}/jre/bin/java.exe"
+$GETDOWNTXT = "${APPDIR}/getdown.txt"
+
+if (-not (Test-Path -Path "${GETDOWNTXT}")) {
+  throw "Cannot find getdown.txt"
+}
+
+if (-not (Test-Path -Path "${JAVA}")) {
+  Write-Host "Cannot find bundled java.exe. Using system and hoping for the best!"
+  $JAVA = "java.exe"
+}
+
+$CLASSPATH = (Select-String -Path "${GETDOWNTXT}" -AllMatches -Pattern "code\s*=\s*(.*)$" | foreach { "$DIR/$($_.Matches.Groups[1].Value)" }) -join ":"
+
+Invoke-Expression -Command "${JAVA} -cp ${CLASSPATH} jalview.bin.Launcher $ARGS"
+