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

# Stellarium バージョン

$stellarium_version = "25.4"
$stellarium_qt_version = "25.4-qt5"

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

Write-Host "//"
Write-Host "// INTERSTELLAR CONSOLE  Setup Script (ps1)"
Write-Host "// Copyright (C) 2025- Misato Observatory, Wakayama, Japan"
Write-Host "//"
Write-Host ""

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

# Check Windows Version

$winVersion = 0
$winVersion = [System.Environment]::OSVersion.Version.Major

if ( $winVersion -eq 0 ) {
  Write-Host "/////////////////////////////"
  Write-Host "// ERROR: Unexpected error //"
  Write-Host "/////////////////////////////"
  Start-Sleep -Seconds 5
  exit 1
}

Write-Host "Major Version of this Windows is $winVersion"
Write-Host ""

if ( $winVersion -lt 10 ) {
  Write-Host "////////////////////////////////////////////"
  Write-Host "// ERROR: Too OLD Windows!! NOT supported //"
  Write-Host "////////////////////////////////////////////"
  Start-Sleep -Seconds 5
  exit 1
}

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

# Start...

Set-StrictMode -version Latest

Add-Type -AssemblyName System.Windows.Forms

$text = "Is the LANGUAGE setting for this Windows system JAPANESE?"
$caption = "Setup: Select your Language"
$buttonsType = "YesNo"
$iconType = "Information"
$result = [System.Windows.Forms.MessageBox]::Show($text, $caption, $buttonsType, $iconType)

$lang = "en"
if ( $result -eq "Yes" ) {
  $lang = "ja"
}

if ( $lang -eq "ja" ) {
  $text = "Interstellar Consoleでは、Stellariumについて`r`n 1. バージョンは 【 $stellarium_qt_version 】`r`n 2. セットアップで 【 For all users 】 を選択`r`n 3. インストール先はデフォルト`r`nを前提としています。`r`nこれらの条件を満たさない場合は動作しませんのでご注意ください。Interstellar Console のセットアップを開始しますか？"
} else {
  $text = "Please check the following settings for Stellarium：`r`n 1. Version : [ $stellarium_qt_version ] `r`n 2. Selected [ For all users ] when Setup. `r`n 3. The installation location is Default. `r`nPlease note that this software may not function properly if the above conditions are not met. Do you wish to begin setting up 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
}

$currentDirectory = Get-Location

#Write-Host "$PSCommandPath"
#Write-Host "$currentDirectory"

# Using "-Verb runAs" to launch processes with elevated privileges via UAC (User Access Control)
Start-Process -FilePath ".\setup-$stellarium_version.exe" -ArgumentList "$lang" -Verb runAs

