

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 ショートカット作成スクリプト (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 または ISC が正しくインストールされていません //"
    Write-Host "/////////////////////////////////////////////////////////////////////"
    Start-Sleep -Seconds 5
    exit 1
  }
} else {
  Write-Host "/////////////////////////////////////////////////////////////////////"
  Write-Host "// ERROR: Stellarium または ISC が正しくインストールされていません //"
  Write-Host "/////////////////////////////////////////////////////////////////////"
  Start-Sleep -Seconds 5
  exit 1
}


if ( $flag_dialog -eq "Yes" ) {

  $text = "デスクトップに Interstellar Console 起動用`r`nショートカットを作成しますか？"
  $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 "デスクトップにショートカットを作成中..."

$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 "完了しました！"

  $text = "ショートカット作成が完了しました！"
  $caption = "Finished Setup"
  $buttonsType = "OK"
  $iconType = "Information"

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

  Start-Sleep -Seconds 1

}

