-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultiArchive.ps1
139 lines (123 loc) · 5.23 KB
/
MultiArchive.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
$win_steam =${env:ProgramFiles(x86)}+"\Steam\steamapps\common\Ninja Kiwi Archive\resources"
$win_standalone1=${env:LocalAppData}+"\Programs\Ninja Kiwi Archive\resources"
$win_standalone2=${env:ProgramFiles}+"\Ninja Kiwi\Ninja Kiwi Archive\resources"
$mac_steam=$HOME +"/Library/Application Support/Steam/steamapps/common/Ninja Kiwi Archive/resources"
$mac_standalone="/Applications/Ninja Kiwi Archive.app/Contents/Resources"
$URL_STEAM="https://github.com/GlennnM/NKMultiArchive/releases/download/v1.0/app_steam.zip"
$URL_STANDALONE="https://github.com/GlennnM/NKMultiArchive/releases/download/v1.0/app_standalone.zip"
$SIZE_STEAM = 49746313
$SIZE_STANDALONE = 49746102
$filename="app.asar"
$global:count_=0
function DownloadThenExtract([string]$cache,[string]$zippath,[string]$downloadpath,[int]$FULL_SIZE){
[int]$FULL_MB = $FULL_SIZE / 0.1MB
$FULL_MB_FLOAT = $FULL_MB / 10
$N = (New-Object Net.WebClient)
try {
Set-Location $cache
Write-Host -NoNewline "Downloading $filename ... "
$E = $N.DownloadFileTaskAsync($zippath,$downloadpath)
while (!($E.IsCompleted)) {
Start-Sleep -Seconds 1
if(Test-Path -Path $downloadpath){
$size = (Get-Item -Path $downloadpath).Length
if ($size -eq 0) {
continue
}
[int]$percent = ($size / $FULL_SIZE * 1000)
[int]$mb = $size / 0.1MB
$percent_float = $percent / 10
$mb_float = $mb / 10
#Write-Progress -Activity "Downloading app.asar:" -Status "$percent_float% complete.." -PercentComplete $percent_float
Write-Host -NoNewline "`rDownloading $filename ... $percent_float% ($mb_float MB/$FULL_MB_FLOAT MB) "
}
}
if ($size -lt $FULL_SIZE) {
"`n"
throw
}
Write-Host -NoNewline "`rDownloading $filename complete! "
if(Test-Path -Path $cache'/app.asar'){
Remove-Item $cache'/app.asar'
}
"`nExtracting..."
try {
"Attempting unzip method 1(powershell 5+)..."
Expand-Archive -Path "$cache/install.zip" -DestinationPath "$cache/"
} catch {
try {
"Attempting unzip method 2(.NET)..."
Add-Type -AssemblyName System.IO.Compression.FileSystem
function Unzip
{
param([string]$zipfile,[string]$outpath)
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile,$outpath)
}
Unzip "$cache/install.zip" "$cache/"
} catch {
try {
"Attempting unzip method 3(tar -xvf)"
Start-Process tar -Wait -NoNewWindow -ArgumentList -WorkingDirectory "$cache" @("-xvf","install.zip")
} catch {
if ($IsWindows -or $ENV:OS) {
"Attempting unzip method 4(7zip)"
Start-Process -Wait -FilePath "C:\Program Files\7-Zip\7z.exe" -NoNewWindow -WorkingDirectory "$cache" -ArgumentList @("e","install.zip")
} else {
"Attempting unzip method 4(unzip)"
Start-Process Unzip -Wait -NoNewWindow -WorkingDirectory "$cache" -ArgumentList @("install.zip")
}
}
}
}
Remove-Item "$cache/install.zip"
if (Test-Path -Path $cache'/app.asar') {
$global:count_++
"Mod installation for NK Archive at "+$cache+" probably succeeded!!"
} else {
"Mod installation failed."
}
} catch {
"One or more files failed to download"
} finally {
try {
$N.CancelAsync();
} catch {
}
$N.Dispose();
}
}
"NK MultiArchive Installer by glenn m"
"The following mods will be installed:"
"Ninja Kiwi Multi-Instance Archive"
"Approx data size: 47.4 MB"
"==============================="
$X = Read-Host "Please ensure all Ninja Kiwi Archive windows(INCLUDING THE LAUNCHER!!!) are closed, then press ENTER to begin installation..."
if ($IsWindows -or $ENV:OS) {
if (Test-Path -Path $win_steam) {
"Located windows/steam installation(probably)"
DownloadThenExtract -cache $win_steam -zippath $URL_STEAM -downloadpath $win_steam'/install.zip' -FULL_SIZE $SIZE_STEAM
}
if (Test-Path -Path $win_standalone1) {
"Located windows/standalone installation(probably)"
DownloadThenExtract -cache $win_standalone1 -zippath $URL_STANDALONE -downloadpath $win_standalone1'/install.zip' -FULL_SIZE $SIZE_STANDALONE
}
if (Test-Path -Path $win_standalone2) {
"Located windows/standalone(All Users) installation(probably)"
"If this fails, try running powershell as admin"
"(or, if one of the previous steps succeeded, just use that archive instead)"
try{
DownloadThenExtract -cache $win_standalone2 -zippath $URL_STANDALONE -downloadpath $win_standalone2'/install.zip' -FULL_SIZE $SIZE_STANDALONE
}catch{
}
}
}else{
if(Test-Path -Path $mac_steam){
"Located mac/steam installation(probably)"
DownloadThenExtract -cache $mac_steam -zippath $URL_STEAM -downloadpath $mac_steam'/install.zip' -FULL_SIZE $SIZE_STEAM
}if(Test-Path -Path $mac_standalone){
"Located mac/standalone installation(probably)"
DownloadThenExtract -cache $mac_standalone -zippath $URL_STANDALONE -downloadpath $mac_standalone'/install.zip' -FULL_SIZE $SIZE_STANDALONE
}
}
"Successful installations: "+$global:count_
$X = Read-Host "Press enter to exit..."