-
Notifications
You must be signed in to change notification settings - Fork 3
/
handle_deps.ps1
148 lines (128 loc) · 4.32 KB
/
handle_deps.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<#
This script is a simple helper to handle all operation with the needed product dependent DLLs.
#>
Param (
[parameter(Mandatory = $false, HelpMessage = 'The operation mode to use.')]
[ValidateNotNullOrEmpty()]
[ValidateSet('collect','clean', IgnoreCase = $true)]
[string] $OpMode = 'clean',
[parameter(Mandatory = $false, HelpMessage = 'The source directory to use.')]
[ValidateNotNullOrEmpty()]
[string] $SrcDir
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$targetDir = $PSScriptRoot
$depFiles = @(
'Newtonsoft.Json.dll',
'NLog.dll',
'QBM.AppServer.Client.dll',
'QBM.AppServer.Interface.dll',
'QBM.AppServer.JobProvider.Plugin.dll',
'QER.AppServer.Plugin.dll',
'QER.Customizer.dll',
'QER.DB.Plugin.dll',
'QER.Interfaces.dll',
'ServiceStack.Client.dll',
'ServiceStack.Common.dll',
'ServiceStack.dll',
'ServiceStack.Interfaces.dll',
'ServiceStack.Text.dll',
'System.Memory.dll',
'System.Numerics.Vectors.dll',
'System.Runtime.CompilerServices.Unsafe.dll',
'VI.Base.dll',
'VI.DB.dll'
)
$fallbackMarkerFiles = @(
'NLog',
'ServiceStack.Client',
'ServiceStack',
'ServiceStack.Interfaces',
'ServiceStack.Text',
'System.Memory',
'System.Numerics.Vectors',
'System.Runtime.CompilerServices.Unsafe',
'Newtonsoft.Json'
)
function CollectDeps {
param (
[parameter(Mandatory = $true, HelpMessage = 'The source directory to use.')]
[string] $SrcDir,
[parameter(Mandatory = $true, HelpMessage = 'The target directory to use.')]
[string] $TargetDir
)
Write-Output 'Start collection operation'
Write-Output "[+] Source directory: $SrcDir"
Write-Output "[+] Target directory: $TargetDir"
Write-Output 'Getting file list...'
$excludes = @(
'database'
'MDK'
'autorun'
'projects'
'documentation'
)
$excludesRegex = $excludes -join '|'
$allFiles = Get-ChildItem -Recurse -File -Path $SrcDir | Where-Object {
$_.DirectoryName -notmatch $excludesRegex
}
Write-Output 'Copying files...'
$failed = $False
$depFiles | ForEach-Object {
$searchFile = $_
$file = $allFiles | Where-Object { $_.Name -EQ $searchFile } | Select-Object -First 1
if ( $file ) {
$exists = Test-Path $file.FullName
}
if ( $exists ) {
Copy-Item -Path $file.FullName -Destination $TargetDir -Recurse
Write-Output "[+] File or folder '$searchFile' copied successfully"
} else {
Write-Output "[!] File or folder '$searchFile' not found in (sub)folder '${SrcDir}'"
$failed = $True
}
}
Write-Output 'Creating fallback marker files...'
$markerDir = Join-Path "$TargetDir" 'fallback'
if ( -Not (Test-Path "$markerDir") ) {
New-Item -Path "$markerDir" -ItemType Directory > $null
}
$fallbackMarkerFiles | ForEach-Object {
$marker = Join-Path $markerDir "$_.use_default"
Write-Output "[+] Create fallback marker for $_"
Write-Output 'Use default' > $marker
}
if ( $failed ){
Write-Output ''
Write-Output 'WARNING: Found some errors. Thats means some files may not be copied'
exit 1
} else {
Write-Output ''
Write-Output '--> All files successfully copied <--'
}
}
function Cleanup {
param (
[parameter(Mandatory = $true, HelpMessage = 'The target directory to clean.')]
[string] $TargetDir
)
Write-Output 'Start cleanup operation'
Write-Output "[+] Directory to clean: $TargetDir"
$depFiles | ForEach-Object {
$searchFile = $_
if ( Test-Path "$searchFile" ) {
Remove-Item -Path "$searchFile"
Write-Output "[+] File or folder '$searchFile' removed"
}
}
$markerDir = Join-Path "$TargetDir" 'fallback'
if ( Test-Path "$markerDir" ) {
Remove-Item -Path "$markerDir" -Recurse -Force
}
}
switch ($OpMode.ToLowerInvariant()) {
'collect' {CollectDeps -SrcDir "${SrcDir}" -TargetDir "${TargetDir}"; break}
'clean' {Cleanup -TargetDir "${TargetDir}"; break}
default {CollectDeps; break}
}