3 # save args and first parameter
4 $myArgs = $args.Clone()
7 # setup for powershell version < 6.0
8 [bool] $myIsWindows = 0
10 if ( $IsWindows -eq $null ) {
11 # for powershell version < 6.0 let's assume Windows
15 $myIsWindows = $IsWindows
19 # parent dir of this actual script (which should be the getdown appdir/bin). Follow all symlinks. Like GNU readlink -f
24 $max = 100 # just in case we end up in a loop
26 $file = Get-Item -Path $Link
28 While ( $c -lt $max -and "${file}" -ne "${prevfile}" -and -not $found ) {
30 [string] $target = ( $file ).Target
31 If ( $target -eq $null -or ( $file ).LinkType -ne "SymbolicLink" ) {
35 If ( $( Split-Path -Path $target -IsAbsolute ) ) {
36 $file = Get-Item -Path $target
38 # symbolic link is relative: combine previous link parent dir with the link target and resolve
39 $file = Get-Item -Path ( Join-Path -Path ( Split-Path -Path $prevfile -Parent ) -ChildPath $target -Resolve )
45 throw "Could not determine path to actual file $( Split-Path -Path $Link -Leaf )"
50 # Avert problem with unix version of powershell and tell user the reason (Windows must always have .ps1 extension)
51 if ( $MyInvocation.MyCommand.Path -eq $null ) {
52 throw "Script or link to script must have extension .ps1"
56 $CMDPATH = ( Get-Item $MyInvocation.MyCommand.Path )
57 $SCRIPTPATH = Readlink-f -Link $CMDPATH
58 $DIR = Split-Path -Path $SCRIPTPATH -Parent
60 # set the "-open" parameter if myArg1 is non-zero-length, and not "open" or starts with a "-"
62 if ( $myArg1.length -gt 0 -and ( -not $myArg1.StartsWith("-") ) -and $myArg1 -cne "open" ) {
66 $APPDIR = If ( ( Split-Path -Path $DIR -Leaf ) -eq "bin" ) { Split-Path -Path $DIR -Parent } Else { $DIR }
67 $JAVAEXE = If ( $myIsWindows ) { "java.exe" } Else { "java" }
68 $JAVA = Join-Path -Path $APPDIR -ChildPath ( "jre/" + $( If ( $myIsMacOS ) { "Contents/Home/" } Else { "" } ) + "bin/${JAVAEXE}" )
69 $GETDOWNTXT = Join-Path -Path $APPDIR -ChildPath "getdown.txt"
71 # look for getdown.txt -- needed to create classpath
72 if ( -not ( Test-Path -Path "${GETDOWNTXT}" ) ) {
73 throw "Cannot find ${GETDOWNTXT}"
76 # look for bundled JRE. Might not be there if unix installer used in which case just invoke "java"
77 if ( -not ( Test-Path -Path "${JAVA}" ) ) {
78 Write-Host "Cannot find bundled ${JAVAEXE}. Using system ${JAVAEXE} and hoping for the best!"
82 $CLASSPATH = ( Select-String -Path "${GETDOWNTXT}" -AllMatches -Pattern "code\s*=\s*(.*)$" | foreach { Join-Path -Path $APPDIR -ChildPath $($_.Matches.Groups[1].Value ) } ) -join $( If ( $myIsWindows ) { ";" } Else { ":" } )
84 # quote the args and the command (in case of spaces) with escape chars (`) and precede with & to indicate command not string
85 $myArgsString = '"' + $($myArgs -join '" "') + '"'
86 Invoke-Expression -Command "& `"${JAVA}`" -cp `"${CLASSPATH}`" jalview.bin.Launcher ${OPEN} ${myArgsString}"