-
Notifications
You must be signed in to change notification settings - Fork 5
/
pack.ps1
81 lines (67 loc) · 2.37 KB
/
pack.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
Set-location (Join-Path $PSScriptRoot "\distribution")
function Use-SrcPath {
Param (
[String] $fileName
)
return Join-Path $PSScriptRoot "otomad_helper" | Join-Path -ChildPath $fileName
}
function Add-ToZip {
Param (
[String] $zipFile,
[String] $file
)
$writeTime = $lastWriteTime = (Get-Item $zipFile).LastWriteTime
& "C:\Program Files\WinRAR\WinRAR" a -afzip $zipFile $file
while ($writeTime -eq $lastWriteTime) {
Start-Sleep -Milliseconds 100
$lastWriteTime = (Get-Item $zipFile).LastWriteTime
}
}
function Update-ToReplaceTextFileOnce {
Param (
[String] $file,
[String[]] $sourceTexts,
[String[]] $targetTexts
)
$content = Get-Content -Path $file -Encoding UTF8 -Raw
for ($i = 0; $i -lt $sourceTexts.Length; $i++) {
$content = [Regex]::New($sourceTexts[$i]).Replace($content, $targetTexts[$i], 1)
}
# Set-Content -Path $file -Value $content -Encoding UTF8
$utf8NoBomEncoding = New-Object Text.UTF8Encoding $False
[IO.File]::WriteAllLines((Join-Path $pwd $file), $content, $utf8NoBomEncoding)
}
function Update-UndefinedSymbols {
Param (
[String] $file,
[String[]] $undefinedSymbols
)
if ($undefinedSymbols.Length -ne 0) {
$sourceTexts = $undefinedSymbols | ForEach-Object { "#define " + $_ }
$targetTexts = $undefinedSymbols | ForEach-Object { "// #define " + $_ }
Update-ToReplaceTextFileOnce $file $sourceTexts $targetTexts
}
}
$infos = @{
VegasVersions = 22;
UndefinedSymbols = @();
}, @{
VegasVersions = 16..21 -join "";
UndefinedSymbols = @("VER_GEQ_22");
}, @{
VegasVersions = 14..15 -join "";
UndefinedSymbols = @("VER_GEQ_22", "VER_GEQ_16");
}, @{
VegasVersions = 13;
UndefinedSymbols = @("VER_GEQ_22", "VER_GEQ_16", "VER_GEQ_14");
}
$version = [Regex]::New("(?<=VERSION-)[\d\.]+").Match((Get-Content -Path '..\README.md' -Encoding UTF8)).Value
Remove-Item "*.*"
for ($i = 0; $i -lt $infos.Count; $i++) {
$info = $infos[$i]
Copy-Item (Use-SrcPath "release_package_template.zip"), (Use-SrcPath "Otomad Helper.cs") -Destination "."
Update-UndefinedSymbols "Otomad Helper.cs" $info.UndefinedSymbols
Add-ToZip "release_package_template.zip" "Otomad Helper.cs"
Rename-Item -Path "release_package_template.zip" -NewName ([String]$i + "_otomad_helper_v" + $version + "_vegas" + [string]$info.VegasVersions + ".zip")
Remove-Item "Otomad Helper.cs"
}