This repository has been archived by the owner on May 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrunestar-launcher.ps1
68 lines (55 loc) · 2.56 KB
/
runestar-launcher.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#Requires -Version 2.0
Set-StrictMode -Version 2.0
function Expand-Zip($Path, $DestinationPath) {
if (Get-Command Expand-Archive -ErrorAction SilentlyContinue) {
Expand-Archive -Verbose -Force -Path $Path -DestinationPath $DestinationPath
} else {
New-Item -ItemType Directory -Path $DestinationPath -Force -Verbose | Out-Null
$shell = New-Object -COM Shell.Application
$target = $shell.NameSpace((Resolve-Path $DestinationPath).Path)
$zip = $shell.NameSpace((Resolve-Path $Path).Path)
$target.CopyHere($zip.Items(), 16)
}
}
function Download-File($Uri, $OutFile) {
if (Get-Command Invoke-WebRequest -ErrorAction SilentlyContinue) {
Invoke-WebRequest -TimeoutSec 5 -Verbose -Uri $Uri -OutFile $OutFile
} else {
New-Item -ItemType File -Path $OutFile -Verbose | Out-Null
(New-Object System.Net.WebClient).DownloadFile($Uri, $OutFile)
}
}
trap { Write-Error -ErrorRecord $_ -ErrorAction Continue ; exit 1 }
$Host.ui.RawUI.WindowTitle = "Launching RuneStar"
$ProgressPreference = 'SilentlyContinue'
$ErrorActionPreference = 'Stop'
[Net.ServicePointManager]::SecurityProtocol = [Enum]::ToObject([Net.SecurityProtocolType], 3072) # TLS 1.2
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
$java_version = 11
$arch = if ($Env:PROCESSOR_ARCHITECTURE -eq 'AMD64' -or $Env:PROCESSOR_ARCHITEW6432 -eq 'AMD64') { 'x64' } else { 'x32' }
$jre_dir = Join-Path $PSScriptRoot jre-$java_version-windows-$arch
if (!(Test-Path $jre_dir)) {
$temp_dir = Join-Path $PSScriptRoot temp
New-Item -ItemType Directory -Path $temp_dir -Force -Verbose | Out-Null
$temp_jdk_archive = Join-Path $temp_dir jdk-$java_version-windows-$arch.zip
if (!(Test-Path $temp_jdk_archive)) {
Download-File -Uri "https://api.adoptopenjdk.net/v2/binary/releases/openjdk$($java_version)?openjdk_impl=hotspot&release=latest&type=jdk&heap_size=normal&os=windows&arch=$arch" -OutFile $temp_jdk_archive
}
$temp_jdk_dir = Join-Path $temp_dir jdk-$java_version-windows-$arch
Expand-Zip -Path $temp_jdk_archive -DestinationPath $temp_jdk_dir
$temp_jdk_home = Join-Path $temp_jdk_dir * -Resolve
& "$temp_jdk_home\bin\jlink" `
--verbose `
--no-header-files `
--no-man-pages `
--strip-debug `
--compress=2 `
--module-path "$temp_jdk_home\jmods" `
--add-modules "java.desktop,java.management,java.naming,java.sql,java.net.http" `
--output "$jre_dir"
if ($LastExitCode) { exit $LastExitCode }
Remove-Item $temp_dir -Recurse
}
$jar = Join-Path $PSScriptRoot runestar-launcher.jar
& "$jre_dir\bin\java" -jar "$jar"
exit $LastExitCode