-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.ps1
121 lines (93 loc) · 3.77 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
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
# Author : Emanuele Messina
# Description : Installer for the cura post processing scripts.
# Doc: https://github.com/emanuelemessina/CuraPostProcessingScripts
# License: https://github.com/emanuelemessina/CuraPostProcessingScripts/LICENSE
param (
[string]$CuraVersion
)
##################################################################################
function Write-Red {
param (
[string]$Message
)
Write-Host $Message -ForegroundColor Red
}
function IsAdmin {
$currentIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal($currentIdentity)
return $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function CopyPythonScripts {
param (
[string]$DestinationFolder
)
$scriptsPath = Join-Path $PSScriptRoot "scripts"
$pythonFiles = Get-ChildItem $scriptsPath -Filter "*.py" -File
if ($pythonFiles.Count -eq 0) {
Write-Host "No .py files found in the 'scripts' folder."
exit
}
Write-Host "Copying scripts from $scriptsPath to $DestinationFolder..."
foreach ($file in $pythonFiles) {
try {
Copy-Item $file.FullName -Destination $DestinationFolder -ErrorAction Stop
}
catch {
Write-Red "Error: $_"
exit
}
Write-Host "Copied $($file.Name)"
}
}
function GetCuraInstallationPath {
param (
[string]$SpecificVersion
)
$curaEntries = Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
"HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
"HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall",
"HKCU:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" -ErrorAction SilentlyContinue |
Get-ItemProperty |
Where-Object { $_.DisplayName -like "Ultimaker Cura*" } |
Select-Object DisplayName, UninstallString
if ($curaEntries.Count -eq 0) {
Write-Red "Cura is not installed on this machine."
exit
}
if (-Not [string]::IsNullOrWhiteSpace($SpecificVersion)) {
Write-Host "Requested Cura version $SpecificVersion"
$specificVersionEntry = $curaEntries | Where-Object { $_.DisplayName -match "Ultimaker Cura $SpecificVersion" }
if ($specificVersionEntry) {
$installPath = $specificVersionEntry.UninstallString -replace "(.*\\)(.*unins.*?$)", '$1'
Write-Host "Found at $installPath"
return $installPath.TrimEnd('\')
}
else {
Write-Red "Cura version '$SpecificVersion' is not found."
exit
}
}
Write-Host "Searching for highest Cura version..."
$sortedCuraEntries = $curaEntries | Sort-Object { [Version]($_.DisplayName -replace "Ultimaker Cura ") } -Descending
$highestVersionEntry = $sortedCuraEntries[0]
$installPath = $highestVersionEntry.UninstallString -replace "(.*\\)(.*unins.*?$)", '$1'
Write-Host "Found highest at $installPath"
return $installPath.TrimEnd('\')
}
##################################################################################
# Check if the script is running with admin privileges
if (-Not (IsAdmin)) {
Write-Red "Run this script with admin privileges"
Pause
exit
}
# Main script execution
$DestinationFolder = GetCuraInstallationPath -SpecificVersion $CuraVersion
$DestinationFolder = Join-Path $DestinationFolder "share\cura\plugins\PostProcessingPlugin\scripts"
if ( (Test-Path $DestinationFolder) ) {
CopyPythonScripts -DestinationFolder $DestinationFolder
} else {
Write-Red "The specified destination folder does not exist."
}
##################################################################################
Pause