-
Notifications
You must be signed in to change notification settings - Fork 4
/
CopyAddinFiles.ps1
60 lines (43 loc) · 1.62 KB
/
CopyAddinFiles.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
param($SolutionDir, $TargetDir, $ConfigurationName)
if ($ConfigurationName -Match "Release")
{
exit
}
$jsonPath = Join-Path -Path $SolutionDir -ChildPath "BuildConfig.json"
if (!(Test-Path $jsonPath))
{
exit
}
$config = Get-Content -Raw -Path $jsonPath | ConvertFrom-Json
$baseDir = $config.InstallDirectory
$baseDir = $baseDir -replace "/", "\"
$baseDir = $baseDir -replace "%APPDATA%", $env:APPDATA
$baseDir = $baseDir -replace "%PROGRAMDATA%", $env:ProgramData
$baseDir = $baseDir -replace "%LOCALAPPDATA%", $env:LOCALAPPDATA
#$versionInstallDir = Join-Path -Path $baseDir -ChildPath $ConfigurationName
#echo $versionInstallDir
#$addinDir = Join-Path -Path $versionInstallDir -ChildPath "Addin"
#echo $addinDir
if (!(Test-Path $baseDir))
{
New-Item -ItemType Directory -Path $baseDir -Force
}
try
{
Copy-Item $TargetDir -Destination $baseDir -Container -Recurse -Force -ErrorAction Stop
}
catch
{
#If the copy fails, then it is likely because the DLL is currently in use by Revit
#So, we want to copy the files to a new directory that will be scanned for by the GenericCommand class
$dirName = [System.IO.Path]::GetFileName($TargetDir)
$installDir = Join-Path -Path $baseDir -ChildPath $dirName
$updatedAssembliesDir = Join-Path $installDir -ChildPath "UpdatedAssemblies"
if (!(Test-Path $updatedAssembliesDir))
{
New-Item -ItemType Directory -Path $updatedAssembliesDir -Force
}
$timestamp = Get-Date -Format yyyyMMddHHmmss
$timestampDir = Join-Path -Path $updatedAssembliesDir -ChildPath $timestamp
Copy-Item $TargetDir -Destination $timestampDir -Container -Recurse -Force
}