-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.ps1
46 lines (39 loc) · 1.79 KB
/
install.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
param (
[Parameter(Mandatory = $false)]
[String]$OldVersion
)
$scriptDir = join-path -Path ${env:ProgramData} -childpath 'EmbroideryOrganize'
$sourceurl = "https://raw.githubusercontent.com/D-Jeffrey/Embroidery-File-Organize/main/"
function Get-FileTo($file) {
$url = $sourceurl + $file
$downloadFile = Join-Path -Path $scriptDir -ChildPath $file
write-host "Downloading ..`n $url to`n $downloadFile" -ForegroundColor Green
$downloadFromGitHub = Invoke-WebRequest -Uri "$url"
$content = $downloadFromGitHub.Content
if ($downloadFromGitHub.Content.Length -gt 0) {
if ($downloadFromGitHub.Content.gettype().Name -eq 'String') {
if ((Compare-Object -ReferenceObject ([System.Text.Encoding]::Unicode.GetBytes(($downloadFromGitHub.Content).substring(0,1))) -DifferenceObject @(255,254)).count -eq 0) {
$content = $downloadFromGitHub.Content.Substring(1)
}
}
Set-Content -Path $downloadFile -Value $content -Force
}
}
function FetchImageFile ([string]$file) {
$source = $sourceurl + $file
$downloadFile = Join-Path -Path $scriptDir -ChildPath $file
write-host "Downloading ..`n $url to`n $downloadFile" -ForegroundColor Green
try {
(New-Object System.Net.WebClient).DownloadFile($source, $downloadFile)
} catch {
Write-Host "`t[!] Failed to download '$source'"
}
}
New-Item -ItemType Directory -Path $scriptDir -ErrorAction SilentlyContinue| out-null
$pushscript = 'EmbroideryCollection-Cleanup.ps1'
Get-FileTo -file $pushscript
$scriptname = Join-Path -Path $scriptDir -ChildPath $pushscript
FetchImageFile -file 'EmbroideryManager.ico'
# for next upgrade
Get-FileTo -file 'install.ps1'
Powershell -NoLogo -ExecutionPolicy Bypass -File $scriptname -setup -OldVersion $OldVersion