JAL-3830 improved bash scripts. Added powershell script. Needs testing
[jalview.git] / utils / getdown / jalviewc.ps1
1 # save first parameter
2 $ARGS = $args
3 $ARG1 = $args[0]
4 # parent dir of this script (should be the getdown app dir)
5 $DIR = Split-Path $MyInvocation.MyCommand.Path -Parent
6
7 # insert an "-open" parameter to Jalview's ARGS if ARG1 is non-zero-length, and not "open" or starts with a "-"
8 if ( $ARG1.length -gt 0 -and (-not $ARG1.StartsWith("-")) -and $ARG1 -ne "open" ) {
9   $ARGS = "-open " + $ARGS
10 }
11
12 $APPDIR = $DIR
13 $JAVA = "${APPDIR}/jre/bin/java.exe"
14 $GETDOWNTXT = "${APPDIR}/getdown.txt"
15
16 if (-not (Test-Path -Path "${GETDOWNTXT}")) {
17   throw "Cannot find getdown.txt"
18 }
19
20 if (-not (Test-Path -Path "${JAVA}")) {
21   Write-Host "Cannot find bundled java.exe. Using system and hoping for the best!"
22   $JAVA = "java.exe"
23 }
24
25 $CLASSPATH = (Select-String -Path "${GETDOWNTXT}" -AllMatches -Pattern "code\s*=\s*(.*)$" | foreach { "$DIR/$($_.Matches.Groups[1].Value)" }) -join ":"
26
27 Invoke-Expression -Command "${JAVA} -cp ${CLASSPATH} jalview.bin.Launcher $ARGS"
28