-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstall-ScreenshotTool.ps1
102 lines (79 loc) · 3.39 KB
/
Install-ScreenshotTool.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
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
function Expand-ZIPFile($file, $destination) {
$shell = new-object -com shell.application
$zip = $shell.NameSpace($file)
foreach ($item in $zip.items()) {
$shell.Namespace($destination).copyhere($item)
}
}
$path = $env:LocalAppData + "\Niklas_Mollenhauer\"
$apikey = Read-Host("Bitte API Key eingeben oder mit Enter bestätigen um den Inhalt der Zwischenablage zu nutzen")
if ($apikey -and $apikey -eq "") {
$apikey = Get-Clipboard
}
$pluginPath = $env:AppData + "\HolzShots\Plugin\"
$ShortcutPath = ($env:AppData + "\Microsoft\Windows\Start Menu\Programs\Startup\HolzShots.lnk")
#Stop Holzshots
Get-Process -Name "HolzShots" | Stop-Process -Confirm:$false -Force
#Prepare Directorys
Write-Host("Erstelle HolzShots Programm Ordner")
Remove-Item ($env:LocalAppData + "\HolzShots") -recurse
$HZPath = (New-Item -ItemType Directory -Force -Path ($env:LocalAppData + "\HolzShots")).FullName
$HolzShotsBinPath = $HZPath + "\Holzshots.exe"
Write-Host("Erstelle HolzShots Plugin Ordner")
Remove-Item $pluginPath -recurse
New-Item -ItemType Directory -Force -Path $pluginPath
Write-Host("Erstelle HolzShots Settings Ordner")
Remove-Item $path -recurse
New-Item -ItemType Directory -Force -Path $path
#Download Holzshots
Write-Host("Lade HolzShots herunter..")
$url = "https://github.com/Nightwire/Screenshot-Client/raw/master/HolzShots.zip"
$output = "$HZPath\HolzShots.zip"
Invoke-WebRequest -Uri $url -OutFile $output
#Unzip Holzshots
Write-Host("Entpacke HolzShots..")
Expand-ZIPFile -File $output -Destination $HZPath
#Delete Zip
Write-Host("Lösche HolzShots Archiv..")
Remove-Item -Force $output
#Add Holzshots to autostart
Write-Host("Füge Holzshots zum Autostart hinzu..")
If (Test-Path $ShortcutPath) {
Remove-Item $ShortcutPath
}
$wshshell = New-Object -comObject WScript.Shell
$link = $wshshell.CreateShortcut($ShortcutPath)
$link.targetpath = $HolzShotsBinPath
$link.save()
#Copy CustomPost Plugin
Write-Host("Kopiere Custom Post Plugin..")
Copy-Item -Force ($HZPath + "\CustomPostUpload.dll") -Destination ($pluginPath + "\CustomPostUpload.dll")
#Start Holzshots once, wait a few seconds and kill it right away
Write-Host("Starte HolzShots, um entsprechenden Config Pfad zu erkennen.")
$Process = [Diagnostics.Process]::Start($HolzShotsBinPath)
$id = $Process.Id
Write-Host("Warte 10 Sekunden..")
Start-Sleep -Seconds 10
try {
Stop-Process -Id $id -ErrorAction stop
Write-Host "Erfolgreich Holzshots mit der ID: $id gestoppt."
}
catch {
Write-Host "FEHLER: Bitte Holzshots manuell neustarten."
}
#Add Config
Get-ChildItem $path | ForEach-Object {
Remove-Item $_.FullName -recurse
$ConfigFolder = New-Item -ItemType directory -Path ($_.FullName + "\" + "0.9.8.12")
$configPath = $ConfigFolder.FullName + "\user.config"
Write-Host("Lade HolzShots Config herunter..")
$url = "https://github.com/Nightwire/Screenshot-Client/raw/master/user.config"
Invoke-WebRequest -Uri $url -OutFile $configPath
(Get-Content $configPath) |
Foreach-Object { $_ -replace 'INSERTAPIKEYHERE', $apikey } |
Out-File $configPath -Encoding utf8
Write-Host("HolzShots Config erfolgreich unter $configPath gespeichert")
}
Write-Host("Installation erfolgreich, starte Holzshots.")
[Diagnostics.Process]::Start($HolzShotsBinPath)