-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
85 lines (76 loc) · 3.44 KB
/
Copy pathsetup.ps1
File metadata and controls
85 lines (76 loc) · 3.44 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
# Requires -RunAsAdministrator
# ============================================================
# Dynamic Refresh - Setup Script
# (version without changing ExecutionPolicy)
# ============================================================
try {
# 1. Create install folder
$ProgramFilesPath = ${env:ProgramFiles}
$installPath = "$ProgramFilesPath\QRes"
Write-Host "Creating folder at $installPath..."
New-Item -ItemType Directory -Path $installPath -Force | Out-Null
Start-Sleep -Seconds 1
# 2. Download repo zip
$tempZip = "$env:TEMP\dynamic-refresh.zip"
$repoUrl = "https://github.com/protocol-8/dynamic-refresh/archive/refs/heads/main.zip"
Write-Host "Downloading repository from $repoUrl ..."
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri $repoUrl -OutFile $tempZip -UseBasicParsing -ErrorAction Stop
if (!(Test-Path $tempZip)) {
throw "Download failed — check internet connection or repo URL."
}
Start-Sleep -Seconds 1
# 3. Extract repo
$tempExtract = "$env:TEMP\dynamic-refresh"
Write-Host "Extracting archive to $tempExtract ..."
if (Test-Path $tempExtract) { Remove-Item $tempExtract -Recurse -Force -ErrorAction SilentlyContinue }
Expand-Archive -Path $tempZip -DestinationPath $tempExtract -Force
Start-Sleep -Seconds 1
# 4. Move files to install folder
$repoMain = Join-Path $tempExtract "dynamic-refresh-main"
if (-not (Test-Path $repoMain)) {
throw "Expected folder $repoMain not found. Extraction may have failed."
}
Write-Host "Copying files to $installPath ..."
Copy-Item -Path "$repoMain\*" -Destination $installPath -Recurse -Force
Start-Sleep -Seconds 1
# 5. Import Task Scheduler XML
$taskName = "dynamic-refresh"
$taskXml = Join-Path $installPath "taskschd.xml"
if (-not (Test-Path $taskXml)) {
throw "Task XML not found at $taskXml. Aborting."
}
Write-Host "Registering scheduled task '$taskName' ..."
Start-Sleep -Seconds 1
if (Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue) {
Write-Host "Existing task found. Removing old task ..."
Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue
}
$xmlText = Get-Content -Path $taskXml -Raw
$TaskUser = "$env:UserDomain\$env:UserName"
$xmlText = $xmlText -replace '\{\{ProgramFilesPath\}\}', $ProgramFilesPath
Register-ScheduledTask -Xml $xmlText -TaskName $taskName -User $TaskUser -Force
Start-Sleep -Seconds 1
# 6. Clean up temp files
Write-Host "Cleaning up temporary files..."
Remove-Item $tempZip -Force -ErrorAction SilentlyContinue
Remove-Item $tempExtract -Recurse -Force -ErrorAction SilentlyContinue
$InstalledScript = Join-Path $installPath "setup.ps1"
if (Test-Path $InstalledScript) {
Remove-Item $InstalledScript -Force
}
Start-Sleep -Seconds 1
Write-Host "------------------------------------------------------------------"
Write-Host ""
Write-Host "Setup complete!"
Write-Host "Files installed at: $installPath"
Write-Host "Scheduled task: '$taskName'"
Write-Host "Note: This script did NOT change ExecutionPolicy. qres.vbs runs PowerShell with -ExecutionPolicy Bypass."
Write-Host "Completed at: $(Get-Date -Format 'HH:mm:ss')"
}
catch {
Write-Host ""
Write-Host "Installation failed:"
Write-Host $_.Exception.Message
exit 1
}