Skip to content

Commit

Permalink
feat: インストールスクリプトの追加 (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
book000 authored Feb 25, 2024
1 parent 1b0f518 commit 9a61e84
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@

## Mod の導入手順

この Mod では、「スクリプトによるインストール」と「マニュアルインストール」を用意しています。
「スクリプトによるインストール」を推奨します。

### スクリプトによるインストール(推奨)

PowerShell を起動し、以下のスクリプトを実行してください。

```powershell
irm https://raw.githubusercontent.com/jaoafa/pat-star-systems/master/installer.ps1 | iex
```

### マニュアルインストール

この Mod は依存 Mod として `System Sharing for Titans & Classic` を使用します。(それ以外の手段で星系を追加する方法がわかりませんでした)

1. [Releases](https://github.com/jaoafa/pat-star-systems/releases) から `pat-star-systems.zip` をダウンロードします。
Expand Down
89 changes: 89 additions & 0 deletions installer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
$prevErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = "Stop"

$owner = "jaoafa"
$repo = "pat-star-systems"
$pat_appdata_path = "$env:LOCALAPPDATA\Uber Entertainment\Planetary Annihilation"
$mods_path = "$pat_appdata_path\mods"
$tag_file_path = "$pat_appdata_path\pat-star-systems.tag"

# Forceフラグがあるかどうかを確認する
$force = $args -contains "-Force"

# Helpフラグがあるかどうかを確認する
$help = $args -contains "-Help"

# Helpフラグがある場合はヘルプを表示して終了する
if ($help) {
Write-Host "jaoafa/pat-star-systems をインストールします。" -ForegroundColor Cyan
Write-Host ""
Write-Host "オプション:"
Write-Host " -Force 既にインストール済みのバージョンを無視して強制的にインストールします。"
Write-Host " -Help このヘルプを表示します。"

$ErrorActionPreference = $prevErrorActionPreference
return
}

# 最新のリリース情報を取得する
$uri = "https://api.github.com/repos/$owner/$repo/releases/latest"
$latestRelease = Invoke-RestMethod -Uri $uri -Method Get
$version = $latestRelease.tag_name
$zipUrl = $latestRelease.assets | Where-Object { $_.name -eq "pat-star-systems.zip" } | Select-Object -ExpandProperty browser_download_url

if ($null -eq $version) {
Write-Host "最新のリリース情報を取得できませんでした。" -ForegroundColor Red

$ErrorActionPreference = $prevErrorActionPreference
return
}

# インストール済みのバージョンを取得する
$installedVersion = "0.0.0"
if (Test-Path $tag_file_path) {
$installedVersion = Get-Content $tag_file_path
}

# インストール済みのバージョンと最新のバージョンを比較する
if ($installedVersion -eq $version -and !$force) {
Write-Host "jaoafa/pat-star-systems $version はインストール済みです。" -ForegroundColor Green

$ErrorActionPreference = $prevErrorActionPreference
return
}

Write-Host "インストール中: jaoafa/pat-star-systems $version" -ForegroundColor Cyan

if ($installedVersion -ne "0.0.0") {
Write-Host "以前のバージョン: $installedVersion" -ForegroundColor Cyan
}

# 一時的なファイルとしてダウンロードする
$zipPath = "$env:TEMP\pat-star-systems-$version.zip"
Invoke-WebRequest -Uri $zipUrl -OutFile $zipPath

if (!(Test-Path $mods_path)) {
New-Item -ItemType Directory -Path $mods_path | Out-Null
}

# 既存のファイルを削除する
Remove-Item -Path "$mods_path\pat-star-systems" -Recurse -Force -ErrorAction SilentlyContinue

# ダウンロードしたファイルを解凍する
Expand-Archive -Path $zipPath -DestinationPath $mods_path -Force
Set-Content -Path $tag_file_path -Value $version

# 一時的なファイルを削除する
Remove-Item -Path $zipPath -Force

Write-Host "jaoafa/pat-star-systems $version をインストールしました。" -ForegroundColor Green

Write-Host ""

Write-Host "この後のインストール手順:" -ForegroundColor Magenta
Write-Host "1. Planetary Annihilation: TITANS にて、コミュニティ MOD から 「System Sharing for Titans & Classic」をインストールしてください。" -ForegroundColor Magenta
Write-Host "2. インストール済 タブから「jao Community PAT Systems」をクリックし、下部「有効」をクリックしてください。" -ForegroundColor Magenta

Write-Host "3. トップページに戻り、星系デザイナー を開き、「jaoafa」タブがあることとそのタブ内に星系があることを確認してください。" -ForegroundColor Magenta

$ErrorActionPreference = $prevErrorActionPreference

0 comments on commit 9a61e84

Please # to comment.