/
MelissaRightFielderObjectWindowsCpp.ps1
239 lines (202 loc) · 7.94 KB
/
MelissaRightFielderObjectWindowsCpp.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
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
# Name: MelissaRightFielderObjectWindowsCpp
# Purpose: Use the MelissaUpdater to make the MelissaRightFielderObjectWindowsCpp code usable
######################### Parameters ##########################
param($rfinput = '""', $dataPath = '', $license = '', [switch]$quiet = $false)
######################### Classes ##########################
class DLLConfig {
[string] $FileName;
[string] $ReleaseVersion;
[string] $OS;
[string] $Compiler;
[string] $Architecture;
[string] $Type;
}
######################### Config ###########################
$RELEASE_VERSION = '2024.Q2'
$ProductName = "RF_DATA"
# Uses the location of the .ps1 file
$CurrentPath = $PSScriptRoot
Set-Location $CurrentPath
$ProjectPath = "$CurrentPath\MelissaRightFielderObjectWindowsCpp"
# Configure the path to vcvarsall.bat if needed
$CmdPath = "C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build\vcvarsall.bat"
$BuildPath = "$ProjectPath\Build"
if (!(Test-Path $BuildPath)) {
New-Item -Path $ProjectPath -Name 'Build' -ItemType "directory"
}
if ([string]::IsNullOrEmpty($dataPath)) {
$DataPath = "$ProjectPath\Data"
}
if (!(Test-Path $DataPath) -and ($DataPath -eq "$ProjectPath\Data")) {
New-Item -Path $ProjectPath -Name 'Data' -ItemType "directory"
}
elseif (!(Test-Path $DataPath) -and ($DataPath -ne "$ProjectPath\Data")) {
Write-Host "`nData file path does not exist. Please check that your file path is correct."
Write-Host "`nAborting program, see above. Press any button to exit.`n"
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") > $null
exit
}
$DLLs = @(
[DLLConfig]@{
FileName = "mdRightFielder.dll";
ReleaseVersion = $RELEASE_VERSION;
OS = "WINDOWS";
Compiler = "DLL";
Architecture = "64BIT";
Type = "BINARY";
},
[DLLConfig]@{
FileName = "mdRightFielderEnums.h";
ReleaseVersion = $RELEASE_VERSION;
OS = "ANY";
Compiler = "C";
Architecture = "ANY";
Type = "INTERFACE";
},
[DLLConfig]@{
FileName = "mdRightFielder.h";
ReleaseVersion = $RELEASE_VERSION;
OS = "ANY";
Compiler = "C";
Architecture = "ANY";
Type = "INTERFACE";
},
[DLLConfig]@{
FileName = "mdRightFielder.lib";
ReleaseVersion = $RELEASE_VERSION;
OS = "WINDOWS";
Compiler = "C";
Architecture = "64BIT";
Type = "INTERFACE";
}
)
######################## Functions #########################
function DownloadDataFiles([string] $license) {
$DataProg = 0
Write-Host "========================== MELISSA UPDATER ========================="
Write-Host "MELISSA UPDATER IS DOWNLOADING DATA FILE(S)..."
.\MelissaUpdater\MelissaUpdater.exe manifest -p $ProductName -r $RELEASE_VERSION -l $license -t $DataPath
if ($? -eq $false) {
Write-Host "`nCannot run Melissa Updater. Please check your license string!"
exit
}
Write-Host "Melissa Updater finished downloading data file(s)!"
}
function DownloadDLLs() {
Write-Host "MELISSA UPDATER IS DOWNLOADING DLL(S)..."
$DLLProg = 0
foreach ($DLL in $DLLs) {
Write-Progress -Activity "Downloading DLL(S)" -Status "$([math]::round($DLLProg / $DLLs.Count * 100, 2))% Complete:" -PercentComplete ($DLLProg / $DLLs.Count * 100)
# Check for quiet mode
if ($quiet) {
if ($DLL.FileName -eq "mdRightFielder.dll")
{
.\MelissaUpdater\MelissaUpdater.exe file --filename $DLL.FileName --release_version $DLL.ReleaseVersion --license $LICENSE --os $DLL.OS --compiler $DLL.Compiler --architecture $DLL.Architecture --type $DLL.Type --target_directory $BuildPath > $null
}
else
{
.\MelissaUpdater\MelissaUpdater.exe file --filename $DLL.FileName --release_version $DLL.ReleaseVersion --license $LICENSE --os $DLL.OS --compiler $DLL.Compiler --architecture $DLL.Architecture --type $DLL.Type --target_directory $ProjectPath > $null
}
if(($?) -eq $False) {
Write-Host "`nCannot run Melissa Updater. Please check your license string!"
Exit
}
}
else {
if ($DLL.FileName -eq "mdRightFielder.dll")
{
.\MelissaUpdater\MelissaUpdater.exe file --filename $DLL.FileName --release_version $DLL.ReleaseVersion --license $LICENSE --os $DLL.OS --compiler $DLL.Compiler --architecture $DLL.Architecture --type $DLL.Type --target_directory $BuildPath
}
else
{
.\MelissaUpdater\MelissaUpdater.exe file --filename $DLL.FileName --release_version $DLL.ReleaseVersion --license $LICENSE --os $DLL.OS --compiler $DLL.Compiler --architecture $DLL.Architecture --type $DLL.Type --target_directory $ProjectPath
}
if(($?) -eq $False) {
Write-Host "`nCannot run Melissa Updater. Please check your license string!"
Exit
}
}
Write-Host "Melissa Updater finished downloading " $DLL.FileName "!"
$DLLProg++
}
}
function CheckDLLs() {
Write-Host "`nDouble checking dll(s) were downloaded."
$FileMissing = $false
if (!(Test-Path ("$BuildPath\mdRightFielder.dll"))) {
Write-Host "mdRightFielder.dll not found."
$FileMissing = $true
}
if (!(Test-Path ("$ProjectPath\mdRightFielderEnums.h"))) {
Write-Host "mdRightFielderEnums.h not found."
$FileMissing = $true
}
if (!(Test-Path ("$ProjectPath\mdRightFielder.h"))) {
Write-Host "mdRightFielder.h not found."
$FileMissing = $true
}
if (!(Test-Path ("$ProjectPath\mdRightFielder.lib"))) {
Write-Host "mdRightFielder.lib not found."
$FileMissing = $true
}
if ($FileMissing) {
Write-Host "`nMissing the above data file(s). Please check that your license string and directory are correct."
return $false
}
else {
return $true
}
}
########################## Main ############################
Write-Host "`n=================== Melissa Right Fielder Object ===================`n [ C++ | Windows | 64BIT ]`n"
# Get license (either from parameters or user input)
if ([string]::IsNullOrEmpty($license)) {
$License = Read-Host "Please enter your license string"
}
# Check for License from Environment Variables
if ([string]::IsNullOrEmpty($License)) {
$License = $env:MD_LICENSE
}
if ([string]::IsNullOrEmpty($License)) {
Write-Host "`nLicense String is invalid!"
exit
}
# Get data file path (either from parameters or user input)
if ($DataPath -eq "$ProjectPath\Data") {
$dataPathInput = Read-Host "Please enter your data files path directory if you have already downloaded the release zip.`nOtherwise, the data files will be downloaded using the Melissa Updater (Enter to skip)"
if (![string]::IsNullOrEmpty($dataPathInput)) {
if (!(Test-Path $dataPathInput)) {
Write-Host "`nData file path does not exist. Please check that your file path is correct."
Write-Host "`nAborting program, see above. Press any button to exit.`n"
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") > $null
exit
}
else {
$DataPath = $dataPathInput
}
}
}
# Use Melissa Updater to download data file(s)
# Download data file(s)
DownloadDataFiles -license $License # Comment out this line if using own release
# Download dll(s)
DownloadDlls -license $License
# Check if dll(s) have been downloaded. Exit script if missing
$DLLsAreDownloaded = CheckDLLs
if (!$DLLsAreDownloaded) {
Write-Host "`nAborting program, see above. Press any button to exit."
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
exit
}
Write-Host "All file(s) have been downloaded/updated!"
# Start program
# Build project
Write-Host "`n=========================== BUILD PROJECT =========================="
cmd.exe /C """$CmdPath"" x86_x64 && Powershell -File BuildProgram.ps1" > $null
# Run project
if ([string]::IsNullOrEmpty($rfinput)) {
& $BuildPath\MelissaRightFielderObjectWindowsCpp.exe --license $License --dataPath $DataPath
}
else {
& $BuildPath\MelissaRightFielderObjectWindowsCpp.exe --license $License --dataPath $DataPath --rfinput $rfinput
}