-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
339 lines (289 loc) Β· 11.3 KB
/
Copy pathinstall.ps1
File metadata and controls
339 lines (289 loc) Β· 11.3 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
param(
[string]$SteamPath = "",
[string]$PluginName = "AchievementBackup",
[string]$Repo = "Yuykkk/AchievementBackup",
[string]$Branch = "main",
[switch]$NoRestart
)
$ErrorActionPreference = "Stop"
function Write-ABHeader {
Clear-Host
Write-Host ""
Write-Host " ===============================================" -ForegroundColor Cyan
Write-Host " AchievementBackup - Instalador" -ForegroundColor White
Write-Host " Backups, capturas e saves da Steam" -ForegroundColor DarkGray
Write-Host " ===============================================" -ForegroundColor Cyan
Write-Host ""
}
function Write-ABStep {
param([string]$Text)
Write-Host " > " -NoNewline -ForegroundColor Cyan
Write-Host $Text -ForegroundColor White
}
function Write-ABOk {
param([string]$Text)
Write-Host " OK " -NoNewline -ForegroundColor Green
Write-Host $Text -ForegroundColor DarkGray
}
function Write-ABWarn {
param([string]$Text)
Write-Host " ! " -NoNewline -ForegroundColor Yellow
Write-Host $Text -ForegroundColor Yellow
}
function Test-SteamRoot {
param([string]$Path)
if ([string]::IsNullOrWhiteSpace($Path)) { return $false }
try {
$full = [System.IO.Path]::GetFullPath(($Path -replace "/", "\"))
return Test-Path (Join-Path $full "steam.exe")
} catch {
return $false
}
}
function Test-RealPython {
param([string]$Exe)
if ([string]::IsNullOrWhiteSpace($Exe) -or -not (Test-Path $Exe)) { return $false }
if ($Exe -like "*\WindowsApps\python*.exe") { return $false }
try {
$version = & $Exe -c "import sys; print(sys.version_info[0])" 2>$null
return $LASTEXITCODE -eq 0 -and (($version | Select-Object -First 1) -eq "3")
} catch {
return $false
}
}
function Find-PythonRuntime {
$candidates = New-Object System.Collections.Generic.List[string]
try {
$py = Get-Command py.exe -ErrorAction SilentlyContinue
if ($py) {
$resolved = & $py.Source -3 -c "import sys; print(sys.executable)" 2>$null
if ($LASTEXITCODE -eq 0 -and $resolved -and (Test-RealPython ($resolved | Select-Object -First 1))) {
return $py.Source
}
}
} catch {}
foreach ($cmd in @("python.exe", "python3.exe")) {
try {
$found = Get-Command $cmd -ErrorAction SilentlyContinue
if ($found) { $candidates.Add($found.Source) }
} catch {}
}
foreach ($root in @(
(Join-Path $env:LOCALAPPDATA "Programs\Python"),
(Join-Path $env:ProgramFiles "Python*"),
(Join-Path ${env:ProgramFiles(x86)} "Python*")
)) {
if ([string]::IsNullOrWhiteSpace($root)) { continue }
Get-ChildItem -Path $root -Filter python.exe -Recurse -ErrorAction SilentlyContinue |
ForEach-Object { $candidates.Add($_.FullName) }
}
foreach ($candidate in $candidates | Select-Object -Unique) {
if (Test-RealPython $candidate) { return $candidate }
}
return ""
}
function Ensure-PythonRuntime {
$python = Find-PythonRuntime
if ($python) {
Write-ABOk "Python 3 detectado para o backend."
return
}
Write-ABWarn "Python 3 nao encontrado. O backend do plugin precisa dele para abrir o painel e monitorar a Steam."
$winget = Get-Command winget.exe -ErrorAction SilentlyContinue
if (-not $winget) {
throw "Instale Python 3 e rode o instalador novamente. winget nao esta disponivel para instalar automaticamente."
}
Write-ABStep "Instalando Python 3 pelo winget..."
& $winget.Source install --id Python.Python.3.12 --source winget --accept-package-agreements --accept-source-agreements --silent
if ($LASTEXITCODE -ne 0) {
throw "Falha ao instalar Python pelo winget. Instale Python 3 manualmente e rode o instalador novamente."
}
Start-Sleep -Seconds 2
$python = Find-PythonRuntime
if (-not $python) {
Write-ABWarn "Python foi instalado, mas ainda nao apareceu nesta sessao. A Steam reiniciada deve detecta-lo pelos caminhos comuns."
} else {
Write-ABOk "Python 3 instalado."
}
}
function Find-SteamPath {
$candidates = New-Object System.Collections.Generic.List[string]
if (-not [string]::IsNullOrWhiteSpace($SteamPath)) {
$candidates.Add($SteamPath)
}
foreach ($regPath in @("HKCU:\Software\Valve\Steam", "HKLM:\SOFTWARE\WOW6432Node\Valve\Steam", "HKLM:\SOFTWARE\Valve\Steam")) {
try {
$props = Get-ItemProperty -Path $regPath -ErrorAction Stop
foreach ($name in @("SteamPath", "InstallPath")) {
if ($props.$name) { $candidates.Add($props.$name) }
}
} catch {}
}
try {
$proc = Get-Process steam -ErrorAction SilentlyContinue | Select-Object -First 1
if ($proc -and $proc.Path) {
$candidates.Add((Split-Path -Parent $proc.Path))
}
} catch {}
foreach ($path in @(
"$env:ProgramFiles(x86)\Steam",
"$env:ProgramFiles\Steam",
"C:\Steam",
"D:\steam",
"D:\Steam",
"E:\steam",
"E:\Steam",
"F:\steam",
"F:\Steam"
)) {
if ($path) { $candidates.Add($path) }
}
foreach ($candidate in $candidates | Select-Object -Unique) {
if (Test-SteamRoot $candidate) {
return [System.IO.Path]::GetFullPath(($candidate -replace "/", "\"))
}
}
throw "Nao consegui encontrar a pasta da Steam automaticamente. Rode com -SteamPath `"D:\steam`"."
}
function Restart-Steam {
param([string]$Root)
$steamExe = Join-Path $Root "steam.exe"
if (-not (Test-Path $steamExe)) {
Write-ABWarn "steam.exe nao encontrado em $Root. Instalei o plugin, mas nao consegui abrir a Steam."
return
}
Write-ABStep "Reiniciando a Steam para carregar o plugin..."
Get-Process steam,steamwebhelper,steamerrorreporter -ErrorAction SilentlyContinue |
Stop-Process -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 3
Start-Process -FilePath $steamExe -WorkingDirectory $Root | Out-Null
Start-Sleep -Seconds 3
Write-ABOk "Steam aberta novamente."
}
function Copy-PluginFiles {
param(
[string]$Source,
[string]$Target
)
if (-not (Test-Path (Join-Path $Source "plugin.json"))) {
throw "A pasta baixada nao contem plugin.json: $Source"
}
$items = Get-ChildItem -LiteralPath $Source -Force
if (-not $items -or $items.Count -eq 0) {
throw "A pasta baixada esta vazia: $Source"
}
foreach ($item in $items) {
Copy-Item -LiteralPath $item.FullName -Destination $Target -Recurse -Force
}
if (-not (Test-Path (Join-Path $Target "plugin.json"))) {
throw "Instalacao incompleta: plugin.json nao foi copiado para $Target"
}
}
function Find-PluginsDir {
param([string]$Root)
$modern = Join-Path $Root "millennium\plugins"
$legacy = Join-Path $Root "plugins"
if (Test-Path (Join-Path $Root "millennium")) {
return $modern
}
if (Test-Path $modern) {
return $modern
}
return $legacy
}
function Preserve-PluginData {
param(
[string]$TempRoot,
[string]$Target,
[string]$LegacyTarget,
[string[]]$Names
)
foreach ($name in $Names) {
foreach ($base in @($Target, $LegacyTarget)) {
if ([string]::IsNullOrWhiteSpace($base)) { continue }
$existing = Join-Path $base $name
if (Test-Path $existing) {
$safeBase = (($base -replace "[:\\\/]", "_") -replace "__+", "_")
$saved = Join-Path $TempRoot ("preserve-" + $safeBase + "-" + $name)
Copy-Item -LiteralPath $existing -Destination $saved -Recurse -Force
}
}
}
}
function Restore-PluginData {
param(
[string]$TempRoot,
[string]$Target,
[string[]]$Names
)
foreach ($name in $Names) {
$matches = Get-ChildItem -LiteralPath $TempRoot -Force -ErrorAction SilentlyContinue |
Where-Object { $_.Name -like ("preserve-*-" + $name) } |
Sort-Object LastWriteTime -Descending
foreach ($match in $matches) {
$destination = Join-Path $Target $name
if ($match.PSIsContainer) {
New-Item -ItemType Directory -Force -Path $destination | Out-Null
Get-ChildItem -LiteralPath $match.FullName -Force | ForEach-Object {
Copy-Item -LiteralPath $_.FullName -Destination $destination -Recurse -Force
}
} else {
Copy-Item -LiteralPath $match.FullName -Destination $destination -Force
}
break
}
}
}
Write-ABHeader
$SteamPath = Find-SteamPath
$pluginsDir = Find-PluginsDir -Root $SteamPath
$legacyPluginsDir = Join-Path $SteamPath "plugins"
$target = Join-Path $pluginsDir $PluginName
$legacyTarget = Join-Path $legacyPluginsDir $PluginName
$tmp = Join-Path ([System.IO.Path]::GetTempPath()) ("achievementbackup-install-" + [guid]::NewGuid().ToString("N"))
$zip = Join-Path $tmp "plugin.zip"
$url = "https://github.com/$Repo/archive/refs/heads/$Branch.zip"
Write-ABStep "Steam detectada em:"
Write-Host " $SteamPath" -ForegroundColor DarkGray
Write-ABStep "Plugin sera instalado em:"
Write-Host " $target" -ForegroundColor DarkGray
if ($pluginsDir -ne $legacyPluginsDir) {
Write-ABOk "Millennium novo detectado: usando millennium\plugins."
}
Write-Host ""
Ensure-PythonRuntime
New-Item -ItemType Directory -Force -Path $tmp | Out-Null
New-Item -ItemType Directory -Force -Path $pluginsDir | Out-Null
try {
Write-ABStep "Baixando a versao mais recente do GitHub..."
Invoke-WebRequest -Uri $url -OutFile $zip -UseBasicParsing
Write-ABOk "Download concluido."
Write-ABStep "Extraindo arquivos..."
Expand-Archive -Path $zip -DestinationPath $tmp -Force
$repoRoot = Get-ChildItem -Path $tmp -Directory | Where-Object { $_.Name -like "AchievementBackup-*" } | Select-Object -First 1
if (-not $repoRoot) { throw "Pacote baixado sem pasta AchievementBackup." }
$source = Join-Path $repoRoot.FullName "AchievementBackup"
if (-not (Test-Path $source)) { $source = $repoRoot.FullName }
Write-ABOk "Arquivos extraidos."
Write-ABStep "Preservando configuracoes, backups e logs existentes..."
$preserve = @("profile", "backups", "logs", "cache", "log.txt")
Preserve-PluginData -TempRoot $tmp -Target $target -LegacyTarget $legacyTarget -Names $preserve
Write-ABStep "Instalando o plugin..."
New-Item -ItemType Directory -Force -Path $target | Out-Null
Copy-PluginFiles -Source $source -Target $target
Restore-PluginData -TempRoot $tmp -Target $target -Names $preserve
Write-ABOk "AchievementBackup instalado."
Write-ABOk "Manifest encontrado: $(Join-Path $target "plugin.json")"
if ($NoRestart) {
Write-ABWarn "Instalacao concluida sem reiniciar. Abra/reinicie a Steam manualmente para carregar o plugin."
} else {
Restart-Steam -Root $SteamPath
}
Write-Host ""
Write-Host " ===============================================" -ForegroundColor Cyan
Write-Host " Pronto! AchievementBackup esta instalado." -ForegroundColor Green
Write-Host " ===============================================" -ForegroundColor Cyan
Write-Host ""
} finally {
Remove-Item -LiteralPath $tmp -Recurse -Force -ErrorAction SilentlyContinue
}