-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBuild-FB2KComponent.ps1
144 lines (115 loc) · 3.85 KB
/
Build-FB2KComponent.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
<#
.SYNOPSIS
Builds the foobar2000 component package.
.DESCRIPTION
This script will be executed unconditionally during the Post-build step. It copies all the necessary files to an output directory and creates the zip archive.
.EXAMPLE
C:\PS> .\Build-FB2KComponent.ps1
.OUTPUTS
foo_midi.fb2k-component
#>
[CmdletBinding()]
param
(
[parameter(Mandatory, HelpMessage='Target Name')]
[string] $TargetName,
[parameter(Mandatory, HelpMessage='Target File Name')]
[string] $TargetFileName,
[parameter(Mandatory, HelpMessage='Platform')]
[string] $Platform,
[parameter(Mandatory, HelpMessage='OutputPath')]
[string] $OutputPath
)
#Requires -Version 7.2
Set-StrictMode -Version Latest;
Set-PSDebug -Strict; # Equivalent of VBA "Option Explicit".
$ErrorActionPreference = 'Stop';
$PSStyle.OutputRendering = [System.Management.Automation.OutputRendering]::PlainText;
# Note: The working directory is the solution directory.
function Install-Component
{
if (Test-Path -Path "../bin")
{
# Install the 64-bit component if there is one.
if (Test-Path -Path $PackagePath64)
{
Write-Host "Installing component in foobar2000 64-bit...";
$ProfilePath = "../bin/profile/user-components-x64/$TargetName";
if (!(Test-Path -Path $ProfilePath))
{
Write-Host "Creating output directory `"$ProfilePath`"...";
$null = New-Item -Path '../bin/profile/user-components-x64/' -Name "$TargetName" -ItemType 'directory';
}
Copy-Item "$PackagePath64/*" -Destination $ProfilePath -Force;
}
}
if (Test-Path -Path "../bin/x86")
{
# Install the 32-bit component if there is one.
if (Test-Path -Path $PackagePath86)
{
Write-Host "Installing component in foobar2000 32-bit...";
$ProfilePath = "../bin/x86/profile/user-components/$TargetName";
if (!(Test-Path -Path $ProfilePath))
{
Write-Host "Creating output directory `"$ProfilePath`"...";
$null = New-Item -Path '../bin/x86/profile/user-components/' -Name "$TargetName" -ItemType 'directory';
}
Copy-Item "$PackagePath86/*" -Exclude "x64" -Destination $ProfilePath -Force;
}
}
}
Write-Host "Building package `"$TargetName`" for platform `"$Platform`"...";
if ($Platform -eq 'Win32')
{
$Platform = 'x86';
}
$PackagePath64 = "../out/$TargetName/x64";
$PackagePath86 = "../out/$TargetName";
$Files = @(
$TargetFileName,
"avcodec-58.dll",
"avformat-58.dll",
"avutil-56.dll",
"swresample-3.dll",
"libmpg123-0.dll"
);
if ($Platform -eq 'x64')
{
if (!(Test-Path -Path $PackagePath64))
{
Write-Host "Creating output directory `"$PackagePath64`"...";
$null = New-Item -Path '../out/' -Name "$TargetName/x64" -ItemType 'directory';
}
if (Test-Path -Path "$OutputPath/$TargetFileName")
{
$Files | ForEach-Object {
Write-Host "Copying $_ to `"$PackagePath86`"...";
Copy-Item "$OutputPath/$_" -Destination "$PackagePath64";
}
}
Install-Component;
}
elseif ($Platform -eq 'x86')
{
if (!(Test-Path -Path $PackagePath86))
{
Write-Host "Creating output directory `"$PackagePath86`"...";
$null = New-Item -Path '../out/' -Name "$TargetName" -ItemType 'directory';
}
if (Test-Path -Path "$OutputPath/$TargetFileName")
{
$Files | ForEach-Object {
Write-Host "Copying $_ to `"$PackagePath86`"...";
Copy-Item "$OutputPath/$_" -Destination "$PackagePath86";
}
}
Install-Component;
}
else
{
Write-Host "Unknown platform: $Platform";
exit;
}
Compress-Archive -Force -Path ../out/$TargetName/* -DestinationPath ../out/$TargetName.fb2k-component;
Write-Host "Done.";