-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathInstallScript.ps1
More file actions
108 lines (90 loc) · 4.44 KB
/
InstallScript.ps1
File metadata and controls
108 lines (90 loc) · 4.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# elevation handled by the calling .bat file to allow script execution policy override
<#
param([switch]$elevated)
function Test-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
if ((Test-Admin) -eq $false) {
if ($elevated) {
# tried to elevate, did not work, aborting
} else {
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
}
exit
}
#>
# registry vars
$iCloneKeyPath = "HKLM:\SOFTWARE\Reallusion\iClone\8.0"
$charCreatorKeyPath = "HKLM:\SOFTWARE\Reallusion\Character Creator\4.0"
$charCreatorFiveKeyPath = "HKLM:\SOFTWARE\Reallusion\Character Creator\5.0"
$valueName = "Install Path"
# path vars
$subFolder = "OpenPlugin"
# script vars
$scriptFolder = $PSScriptRoot
$scriptFolderName = "Blender Pipeline Plugin"
$isGitClone = Test-Path -Path "$scriptFolder\.git"
function Add-Junction($keyPath){
$keyExists = Test-Path -Path $keyPath
if($keyExists){
Write-Host "`n Found $keyPath in the registry."
# check if the entry "Install Path" is present within the key
$entryExists = Get-ItemProperty -Path $keyPath -Name $valueName -ErrorAction SilentlyContinue
if ($entryExists){
$entryValue = Get-ItemPropertyValue -Path $keyPath -Name $valueName
# check if subfolder is present under the install path
$subFolderExists = Test-Path -Path "$entryValue\$subFolder"
if($subFolderExists){
Write-Host "`n $subFolder folder exists (in $entryValue)."
}else{
Write-Host "`n Creating $subFolder folder in $entryValue."
New-Item -Path "$entryValue\$subFolder" -ItemType Directory
}
# is this a Git Clone? Install as junction, otherwise install as full copy
if ($isGitClone){
Write-Host "`n Installing Git Clone Plugin as junction link."
}else{
Write-Host "`n Installing Plugin Files directly."
}
# create a directory junction to the folder containing this script
$junctionPath = "$entryValue\$subFolder\$scriptFolderName"
$junctionExists = Test-Path -Path $junctionPath
if($junctionExists){
Write-Host "`n Folder link $junctionPath already exists."
cmd /c rmdir /s /q $junctionPath
Write-Host "`n Folder link $junctionPath deleted."
}
$junctionExists = Test-Path -Path $junctionPath
if(!$junctionExists){
if ($isGitClone){
cmd /c mklink /J "$junctionPath" "$scriptFolder" | Out-Null
Write-Host "`n Folder link $junctionPath has been created."
}else{
Copy-Item -Path "$scriptFolder" -Destination "$junctionPath" -Recurse
Write-Host "`n Folder $junctionPath has been copied."
}
}
}else{
Write-Host "`n Cannot find $valueName in the registry key... skipping."
}
}else{
Write-Host "`n Cannot find $keyPath in the registry... skipping."
}
}
if ($isGitClone){
Write-Host "`n************************************************************************"
Write-Host "`n This script will create links that allow iClone/Character Creator`n to use the plugin contained in this folder - Please ensure that this`n folder stays in its current location (or the links will break).`n`n [If you need to move the folder then run the Uninstall.bat file before`n re-running the Install.bat file.]"
Write-Host "`n************************************************************************`n"
}else{
Write-Host "`n************************************************************************"
Write-Host "`n This script will install the files that allow iClone/Character Creator`n to use the plugin contained in this folder."
Write-Host "`n************************************************************************`n"
}
$keyPaths = @($iCloneKeyPath, $charCreatorKeyPath, $charCreatorFiveKeyPath)
foreach ($entry in $keyPaths){
Write-Host "`n`n Processing $entry ..."
Add-Junction($entry)
}
Write-Host "`n`n Process Complete - Press any key to exit...`n"
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")