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 $APPDIR = If ( ( Split-Path -Path $DIR -Leaf ) -eq "bin" ) { Split-Path -Path $DIR -Parent } Else { $DIR }
61 $JAVAEXE = If ( $myIsWindows ) { "java.exe" } Else { "java" }
62 $JAVA = Join-Path -Path $APPDIR -ChildPath ( "jre/" + $( If ( $myIsMacOS ) { "Contents/Home/" } Else { "" } ) + "bin/${JAVAEXE}" )
63 $GETDOWNTXT = Join-Path -Path $APPDIR -ChildPath "getdown.txt"
65 # look for getdown.txt -- needed to create classpath
66 if ( -not ( Test-Path -Path "${GETDOWNTXT}" ) ) {
67 throw "Cannot find ${GETDOWNTXT}"
70 # look for bundled JRE. Might not be there if unix installer used in which case just invoke "java"
71 if ( -not ( Test-Path -Path "${JAVA}" ) ) {
72 Write-Host "Cannot find bundled ${JAVAEXE}. Using system ${JAVAEXE} and hoping for the best!"
76 $CLASSPATH = ( Select-String -Path "${GETDOWNTXT}" -AllMatches -Pattern "code\s*=\s*(.*)$" | foreach { Join-Path -Path $APPDIR -ChildPath $($_.Matches.Groups[1].Value ) } ) -join $( If ( $myIsWindows ) { ";" } Else { ":" } )
79 $CONSOLEWIDTH = $Host.UI.RawUI.WindowSize.Width
81 # quote the args and the command (in case of spaces) with escape chars (`) and precede with & to indicate command not string
82 if ( $myArgs.count -eq 0 ) {
83 Invoke-Expression -Command "& `"${JAVA}`" `"-DCONSOLEWIDTH=${CONSOLEWIDTH}`" `"-Dgetdownappdir=${APPDIR}`" -cp `"${CLASSPATH}`" jalview.bin.Launcher"
85 $myArgsString = '"' + $($myArgs -join '" "') + '"'
86 Invoke-Expression -Command "& `"${JAVA}`" `"-DCONSOLEWIDTH=${CONSOLEWIDTH}`" `"-Dgetdownappdir=${APPDIR}`" -cp `"${CLASSPATH}`" jalview.bin.Launcher ${myArgsString}"