

if ( Test-Path Variable:DESTDIR ) {

  $flag_dialog = "No"

} else {

  $flag_dialog = "Yes"

  ################################################################

  Set-StrictMode -version Latest

  Add-Type -AssemblyName System.Windows.Forms

  ################################################################

  Write-Host "//"
  Write-Host "// INTERSTELLAR CONSOLE  Shortcut creation script (ps1)"
  Write-Host "// Copyright (C) 2025- Misato Observatory, Wakayama, Japan"
  Write-Host "//"
  Write-Host ""

  ################################################################

  $STELDIR     = "C:\Program Files\Stellarium"
  $SSCDIR      = "$STELDIR\scripts"

  $DESTDIR = "$SSCDIR\interstellar-console"
  Write-Host "DESTDIR: $DESTDIR"

}


if ( Test-Path -Path "$DESTDIR" ) {
  if ( !(Test-Path -Path "$DESTDIR" -PathType Container) ) {
    Write-Host "//////////////////////////////////////////////////////////"
    Write-Host "// ERROR: Stellarium or ISC is not installed correctly. //"
    Write-Host "//////////////////////////////////////////////////////////"
    Start-Sleep -Seconds 5
    exit 1
  }
} else {
  Write-Host "//////////////////////////////////////////////////////////"
  Write-Host "// ERROR: Stellarium or ISC is not installed correctly. //"
  Write-Host "//////////////////////////////////////////////////////////"
  Start-Sleep -Seconds 5
  exit 1
}


if ( $flag_dialog -eq "Yes" ) {

  $text = "Do you want to create a shortcut on your desktop to launch Interstellar Console?"
  $caption = "Setup: Interstellar Console"
  $buttonsType = "YesNo"
  $iconType = "Information"

  $result = [System.Windows.Forms.MessageBox]::Show($text, $caption, $buttonsType, $iconType)

  if ( $result -eq "No" ) {
    exit
  }

}


################################################################

Write-Host "Creating a shortcut on the desktop..."

$work_dir       = "$DESTDIR"

# params
$link_from_file = "$DESTDIR\isc_navigator.exe"
$link_name      = "isc_navigator.lnk"
# create shortcut
$link_to = [System.Environment]::GetFolderPath("Desktop") + "\" + $link_name
$wso = New-Object -ComObject WScript.Shell
$shortcut = $wso.CreateShortcut($link_to)
$shortcut.TargetPath = $link_from_file
$shortcut.WorkingDirectory = $work_dir
$shortcut.Save()

# params
$link_from_file = "$DESTDIR\isc_dome.exe"
$link_name      = "isc_dome.lnk"
# create shortcut
$link_to = [System.Environment]::GetFolderPath("Desktop") + "\" + $link_name
$wso = New-Object -ComObject WScript.Shell
$shortcut = $wso.CreateShortcut($link_to)
$shortcut.TargetPath = $link_from_file
$shortcut.WorkingDirectory = $work_dir
$shortcut.Save()

# params
$link_from_file = "$DESTDIR\isc_gui.exe"
$link_name      = "isc_gui.lnk"
# create shortcut
$link_to = [System.Environment]::GetFolderPath("Desktop") + "\" + $link_name
$wso = New-Object -ComObject WScript.Shell
$shortcut = $wso.CreateShortcut($link_to)
$shortcut.TargetPath = $link_from_file
$shortcut.WorkingDirectory = $work_dir
$shortcut.Save()


################################################################

if ( $flag_dialog -eq "Yes" ) {

  Write-Host "Shortcut creation complete!"

  $text = "Shortcut creation complete!"
  $caption = "Finished Setup"
  $buttonsType = "OK"
  $iconType = "Information"

  $result = [System.Windows.Forms.MessageBox]::Show($text, $caption, $buttonsType, $iconType)

  Start-Sleep -Seconds 1

}

