-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemove_Controllers.ps1
More file actions
262 lines (237 loc) · 14.6 KB
/
Copy pathRemove_Controllers.ps1
File metadata and controls
262 lines (237 loc) · 14.6 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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# Define input and output file paths
param (
[string]$inputFilePath
)
# Hungry Pumkin does not want Binary DMX files
$firstLine = Get-Content -Path $inputFilePath -TotalCount 1
if ($firstLine -match "binary") {
$pumkin = @"
%%%%%%%%%%%%%%@@:@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# : ::::: ::: : @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@%%%%%%%%%%%%%@@:@@@@@@@@@@@@@@@@@@@@@@@@@@: =*####+. .:::. :=*##%%%%%%*= .@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@%%%%%%%%%%%%%@@:@@@@@@@@@@@@@@@@@@@@@- .%%%%%%%%%%%%%%%%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. @@@@@@
@%%@ #############%%%%%%%%%%%%%%%%%%%%%%% @@ @ .@@ %%%%%%%%%%%%*@#+ @ +%@@*%%%%%%%%%%%%%%%%%%%%%%%%%## %@@@@@@
@%%*##############%%%%%%%%%%%%%%%%%%%%%%=@@@* =@@@.%%%%%%%%%%%.@:: ==@@=%%%%%%%%%%%%%%%%%%%%%%%%#%#% @@@@@@
@%@:#############%%%%%%%%%%%%%%%%%%%%%%%%%:@ =:@:%%%%%%%%%%%%%%%:: :.% %%%%%%%%%%%%%%%%%%%%%%%%%%#%##+ @.-@@
@@*##############%%%%%%%%%%%%%%%%%%%%%%%%%%% :* := *%%%%%%%%%%%%%%%%%%%%%%+--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%### %@@%%
% ###############%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%######%.--
@ ################%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%=%%%%%%%%%%%%%%%%%%%%%%% .%%%%%%%%%%%%%%%%%%%%%%.%%%%%%%%%#####% ---
@ #*##############%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*%%%%%%%%%%%%%%%%%%%%%%%*%-#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%######## :::
@ ##*#####- .*#####%%%%%%%#%%%%%%%%%%%%%%%%%%%%%%%%%%*.:==::%%%%%%%%%%#.%%%%%%%%%%%%%%%%%%%%%%%%%%%+%%%%%%%%#%###### :
@ #*#### ..:: #####%%%%%%%:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%##%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%.%%%%%% . +###### @ :
@ #**#* ::::: ######%%%%%%:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*%%%%%%%% ::::: ##### @ :
@@ #*# :::::: =#####%%%%%%%%%:+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%* :::::. ###-@@ :
@@=:*# :::::. ######%#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% .:::::. ### @@ :
@@@ *# .:::::: #######%#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%+ .::::::::::::::-----:+%%%%%%%%%%%%%%%%%%%%%%%%% :::::: ### @@@@@
@@@@ .:::::::.#######%%%%%%%%%%%%%%%%%%%%%%%%%%%* ...:::::::::::::::::------:. %*%%%%%%%%%%%%%%%%%%%#.::::::: # #@@@@@
@@@@ .::::::::::#########%%%%%%%%%%%%%%%%%%%%%=%%%%%%%%%* .::::::::::::::.#%%%%%%%.%%%%%%%%%%%%%%%%%%% ::::::::: +@@@@@@
@@@+ :::::::::: =#########%#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#+===+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#:.:::::::::: %@@@@@
@@@ :::::::::: = +########%#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%=.:*%%%#+=%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%- :::::::::: %@@@@
"@
Write-Host $pumkin
Write-Host "`n NO!"
Start-Sleep -Milliseconds 600
$message1 = "`n I DON'T WANT THAT!`n"
Write-Host -NoNewline " "
foreach ($char in $message1.ToCharArray()) {
Write-Host -NoNewline $char
Start-Sleep -Milliseconds 125 }
Write-Host ""
Write-Host -NoNewline " ."
Start-Sleep -Milliseconds 600
for ($i = 2; $i -le 4; $i++) {
Write-Host -NoNewline "."
Start-Sleep -Milliseconds 600 }
Start-Sleep -Milliseconds 300
$message2 = "`n GIVE ME THE KEYVALUES...`n"
Write-Host -NoNewline "`n "
foreach ($char in $message2.ToCharArray()) {
Write-Host -NoNewline $char
Start-Sleep -Milliseconds 125 }
Write-Host ""
exit
}
# Get the file name without extension and the extension separately
$filenameWithoutExtension = [System.IO.Path]::GetFileNameWithoutExtension($inputFilePath)
$fileExtension = [System.IO.Path]::GetExtension($inputFilePath)
# Define the output file path with "_stripped" appended before the extension
$outputFilePath = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName($inputFilePath), $filenameWithoutExtension + "_stripped" + $fileExtension)
# Check if input file exists
if (!(Test-Path -Path $inputFilePath)) {
Write-Output "File not found: $inputFilePath"
exit
}
# Open file streams for reading and writing
$inputStream = [System.IO.StreamReader]::new($inputFilePath)
$outputStream = [System.IO.StreamWriter]::new($outputFilePath)
# Initialize state variables
$insideTargetArray = $false
$insideTargetBlock = $false
$bracketLevel = 0
# Variables to capture name information and counters
$currentName = ""
$currentDominator = ""
$currentSuppressed = ""
$flexControllerCount = 0
$dominatorRuleCount = 0
$separatorPrinted = $false # Flag to control single separator printing
# Timer for inactivity messages
$lastMessageTime = [datetime]::Now
$inactivityCheckEnabled = $true
$iterationCounter = 0 # Counter for loop iterations
$checkFrequency = 100 # Perform inactivity check only once every 100 iterations for performance
# Initial output acknowledging the file being worked on
Write-Host "-------------------------------------------------------------------------------------------------------------"
Write-Host "Processing file: $inputFilePath"
Write-Host "-------------------------------------------------------------------------------------------------------------"
# Function to handle final cleanup and reporting
function Finalize-Script {
param (
[int]$FlexControllerCount,
[int]$DominatorRuleCount,
[string]$OutputFilePath,
[System.IO.StreamReader]$InputStream,
[System.IO.StreamWriter]$OutputStream
)
# Close file streams
if ($InputStream) { $InputStream.Close() }
if ($OutputStream) { $OutputStream.Close() }
# Reporting logic
if ($FlexControllerCount -eq 0 -and $DominatorRuleCount -eq 0) {
Write-Host "Nothing found to remove!"
Write-Host "Either this DMX file was already stripped or you somehow snuck a Binary DMX file past the Pumkin??..."
} else {
Write-Host "-------------------------------------------------------------------------------------------------------------"
Write-Host "Removal complete. Output saved to $( [System.IO.Path]::GetFileName($OutputFilePath) )"
Write-Host "-------------------------------------------------------------------------------------------------------------"
Write-Output "Total flex controllers removed: $FlexControllerCount"
Write-Output "Total dominator rules removed: $DominatorRuleCount"
Write-Host "-------------------------------------------------------------------------------------------------------------"
}
# Exit the script
exit
}
while (($line = $inputStream.ReadLine()) -ne $null) {
# Increment the iteration counter
$iterationCounter++
# Break the loop and finish when no activity has been detected for 2 seconds
if ($inactivityCheckEnabled -and $iterationCounter % $checkFrequency -eq 0) {
if (([datetime]::Now - $lastMessageTime).TotalSeconds -ge 2) {
# Write the current line to ensure no data is skipped
$outputStream.WriteLine($line)
# Align stream position and read all remaining lines in bulk
$remainingLines = $inputStream.ReadToEnd()
# Validate and clean up remaining lines
if ($remainingLines -ne "") {
$remainingLines = $remainingLines.TrimStart("`n", "`r").TrimEnd("`n", "`r") # Remove extra newlines
$outputStream.Write($remainingLines)
}
# Finalize and exit
Finalize-Script -FlexControllerCount $flexControllerCount -DominatorRuleCount $dominatorRuleCount -OutputFilePath $outputFilePath -InputStream $inputStream -OutputStream $outputStream
}
}
# Detect start of the target arrays ("controls" or "dominators") containing element_array
if ($line -match '"controls" "element_array"') {
$insideTargetArray = "controls"
$outputStream.WriteLine($line) # Write the array header line
$outputStream.WriteLine(" [") # Write the opening bracket for the array with double indentation
$lastMessageTime = [datetime]::Now # Reset timer because significant work is happening
$inactivityCheckEnabled = $true # Re-enable inactivity checks
continue
} elseif ($line -match '"dominators" "element_array"') {
$insideTargetArray = "dominators"
$outputStream.WriteLine($line) # Write the array header line
$outputStream.WriteLine(" [") # Write the opening bracket for the array with double indentation
$lastMessageTime = [datetime]::Now # Reset timer because significant work is happening
$inactivityCheckEnabled = $true # Re-enable inactivity checks
continue
}
# If inside the target array, check for start and end of blocks to remove
if ($insideTargetArray) {
# Detect start of a block to remove
if ($line -match '"DmeCombinationInputControl"') {
$insideTargetBlock = "DmeCombinationInputControl"
$bracketLevel = 0 # Reset bracket level for nested tracking
$lastMessageTime = [datetime]::Now # Reset timer because significant work is happening
$inactivityCheckEnabled = $true # Re-enable inactivity checks
continue
} elseif ($line -match '"DmeCombinationDominationRule"') {
# Print separator if it hasn't been printed after flex controllers
if (-not $separatorPrinted -and $flexControllerCount -gt 0) {
Write-Host "-------------------------------------------------------------------------------------------------------------"
$separatorPrinted = $true # Ensure this only prints once
}
$insideTargetBlock = "DmeCombinationDominationRule"
$bracketLevel = 0 # Reset bracket level for nested tracking
$lastMessageTime = [datetime]::Now # Reset timer because significant work is happening
$inactivityCheckEnabled = $true # Re-enable inactivity checks
continue
}
# Track nested brackets within the target block to identify its end
if ($insideTargetBlock) {
# Capture "name" values for reporting
if ($insideTargetBlock -eq "DmeCombinationInputControl" -and $line -match '"name" "string" "(.*)"') {
$currentName = $matches[1]
$flexControllerCount++
Write-Output "Removing flex controller: $currentName"
$lastMessageTime = [datetime]::Now # Reset timer because significant work is happening
$inactivityCheckEnabled = $true # Re-enable inactivity checks
} elseif ($insideTargetBlock -eq "DmeCombinationDominationRule") {
# Capture "name" or "dominators" and "suppressed" values for DmeCombinationDominationRule
if ($line -match '"name" "string" "(.*)"') {
$currentName = $matches[1]
}
# Capture each item in "dominators" or "suppressed" array until closing bracket
elseif ($line -match '"dominators" "string_array"') {
$currentDominator = $inputStream.ReadLine().Trim(" []`"").Trim()
while (($arrayLine = $inputStream.ReadLine().Trim()) -notmatch '^\]') {
$currentDominator += $arrayLine.Trim(" ", "`"").Trim() + ", "
}
$currentDominator = $currentDominator.TrimEnd(", ") # Remove trailing comma
} elseif ($line -match '"suppressed" "string_array"') {
$currentSuppressed = $inputStream.ReadLine().Trim(" []`"").Trim()
while (($arrayLine = $inputStream.ReadLine().Trim()) -notmatch '^\]') {
$currentSuppressed += $arrayLine.Trim(" ", "`"").Trim() + ", "
}
$currentSuppressed = $currentSuppressed.TrimEnd(", ") # Remove trailing comma
$dominatorRuleCount++
Write-Output "Removing dominator rule: $currentDominator suppressing $currentSuppressed"
$lastMessageTime = [datetime]::Now # Reset timer because significant work is happening
$inactivityCheckEnabled = $true # Re-enable inactivity checks
}
}
# Update bracket level for nested structures
if ($line -match '^\s*\{') { $bracketLevel++ }
if ($line -match '^\s*\}') { $bracketLevel-- }
# Exit block when reaching the matching closing bracket
if ($bracketLevel -eq 0) {
# Reset block-specific variables
$insideTargetBlock = $false
$currentName = ""
$currentDominator = ""
$currentSuppressed = ""
}
continue # Skip lines inside the target block
}
# Detect the end of the target array and write the closing bracket only once
if ($line -match '^\s*\]') {
$outputStream.WriteLine(" ]") # Write only the closing bracket for an empty array with double indentation
$insideTargetArray = $false # Exit the array
$lastMessageTime = [datetime]::Now # Reset timer because significant work is happening
$inactivityCheckEnabled = $true # Re-enable inactivity checks
}
continue
}
# Write lines outside of the target arrays
$outputStream.WriteLine($line)
}
# Fallback to finalize in case inactivity check is skipped
Finalize-Script -FlexControllerCount $flexControllerCount -DominatorRuleCount $dominatorRuleCount -OutputFilePath $outputFilePath -InputStream $inputStream -OutputStream $outputStream