-
Notifications
You must be signed in to change notification settings - Fork 1
/
Join-FBNeoCRCMatchedToMAMEWithMAMEDatabase.ps1
137 lines (104 loc) · 6.71 KB
/
Join-FBNeoCRCMatchedToMAMEWithMAMEDatabase.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
# Join-FBNeoWithMAMEDatabase.ps1
$strThisScriptVersionNumber = [version]'1.0.20220719.0'
#region License
###############################################################################################
# Copyright 2022 Frank Lesniak
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
# and associated documentation files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or
# substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
###############################################################################################
#endregion License
#region DownloadLocationNotice
# The most up-to-date version of this script can be found on the author's GitHub repository
# at https://github.com/franklesniak/ROMSorter
#endregion DownloadLocationNotice
$actionPreferenceFormerVerbose = $VerbosePreference
$actionPreferenceFormerDebug = $DebugPreference
$strLocalMAMEDatabaseCSV = $null
$boolBackupMAMEDatabaseBeforeOverwrite = $true
$strLocalMAMEDatabaseBackupPrefix = $null
$strLocalMAMEDatabaseBackupSuffix = $null
$strScriptToGenerateCRCMatchedDAT = 'coresponding "Convert-..."'
$strLocalCRCMatchedDATToJoinCSV = $null
$strCRCMatchedDATToJoinDisplayName = 'this CRC-matched DAT'
$actionPreferenceNewVerbose = $VerbosePreference
$actionPreferenceNewDebug = $DebugPreference
#region Inputs
###############################################################################################
# This script requires the current version of MAME's DAT converted to CSV. Optionally, the DAT
# may have already been joined with DATs from other versions of MAME or other emulators. Set
# the following path to point to the corresponding CSV:
$strLocalMAMEDatabaseCSV = Join-Path '.' 'MAME_Database.csv'
# This script will make a backup copy of the previous file before overwriting it with the new
# results. If you don't want to take a backup, uncomment the following line:
# $boolBackupMAMEDatabaseBeforeOverwrite = $false
# Change this if you want to effect the name of the backup file:
$strLocalMAMEDatabaseBackupPrefix = Join-Path '.' 'MAME_Database_Backup_'
$strLocalMAMEDatabaseBackupSuffix = '.csv'
# If the CRC-matched CSV below is missing, the user is prompted to run the following script:
$strScriptToGenerateCRCMatchedDAT = '"Find-MAMEAndFBNeoArcadeMatchUsingCRC"'
# This script also requires a CRC-matched version of the FBNeo Arcade DAT (i.e., the
# one to join to the database), converted to CSV format. CRC matching occurs by
# comparing the ROM file CRCs across the two ROM sets
$strLocalCRCMatchedDATToJoinCSV = Join-Path '.' 'FBNeo_Arcade_DAT_Renamed_and_CRC-Matched_To_MAME_DAT.csv'
# This display name is used in progress output:
$strCRCMatchedDATToJoinDisplayName = "the FBNeo Arcade DAT CRC-matched to MAME's DAT"
# Comment-out the following line if you prefer that the script operate silently.
$actionPreferenceNewVerbose = [System.Management.Automation.ActionPreference]::Continue
# Remove the comment from the following line if you prefer that the script output extra
# debugging information.
# $actionPreferenceNewDebug = [System.Management.Automation.ActionPreference]::Continue
###############################################################################################
#endregion Inputs
$VerbosePreference = $actionPreferenceNewVerbose
$DebugPreference = $actionPreferenceNewDebug
$boolErrorOccurred = $false
$dateTimeStart = Get-Date
if ((Test-Path $strLocalMAMEDatabaseCSV) -ne $true) {
Write-Error ('The input file "' + $strLocalMAMEDatabaseCSV + '" is missing. Please generate it using the "Copy-MAMEDATToMAMEDatabase" script and then re-run this script')
$boolErrorOccurred = $true
}
if ((Test-Path $strLocalCRCMatchedDATToJoinCSV) -ne $true) {
Write-Error ('The input file "' + $strLocalCRCMatchedDATToJoinCSV + '" is missing. Please generate it using the ' + $strScriptToGenerateCRCMatchedDAT + ' script and then re-run this script')
$boolErrorOccurred = $true
}
$VerbosePreference = $actionPreferenceFormerVerbose
$arrModules = @(Get-Module Join-Object -ListAvailable)
$VerbosePreference = $actionPreferenceNewVerbose
if ($arrModules.Count -eq 0) {
Write-Error 'This script requires the module "Join-Object". On PowerShell version 5.0 and newer, it can be instaled using the command "Install-Module Join-Object". Please install it and re-run the script'
$boolErrorOccurred = $true
}
if ($boolErrorOccurred -eq $true) {
break
}
Write-Verbose ('Importing the MAME database...')
$arrMAMEDatabase = @(Import-Csv -Path $strLocalMAMEDatabaseCSV)
Write-Verbose ('Importing ' + $strCRCMatchedDATToJoinDisplayName + '...')
$arrCRCMatchedDATToJoin = @(Import-Csv -Path $strLocalCRCMatchedDATToJoinCSV)
$arrLoadedModules = @(Get-Module Join-Object)
if ($arrLoadedModules.Count -eq 0) {
$VerbosePreference = $actionPreferenceFormerVerbose
Import-Module Join-Object
$VerbosePreference = $actionPreferenceNewVerbose
}
Write-Verbose ('Joining the MAME database with ' + $strCRCMatchedDATToJoinDisplayName + '. This may take a while...')
$arrJoinedData = Join-Object -Left $arrMAMEDatabase -Right $arrCRCMatchedDATToJoin -LeftJoinProperty 'ROMName' -RightJoinProperty 'ROMName' -Type 'AllInBoth' -AddKey 'ROMName' -ExcludeLeftProperties 'ROMName' -ExcludeRightProperties 'ROMName'
if ($boolBackupMAMEDatabaseBeforeOverwrite -eq $true) {
$strBackupFileName = ($strLocalMAMEDatabaseBackupPrefix + ([string]($dateTimeStart.Year) + '-' + [string]($dateTimeStart.Month) + '-' + [string]($dateTimeStart.Day) + '_' + [string]($dateTimeStart.Hour) + [string]($dateTimeStart.Minute) + [string]($dateTimeStart.Second)) + $strLocalMAMEDatabaseBackupSuffix)
Copy-Item -Path $strLocalMAMEDatabaseCSV -Destination $strBackupFileName -Force
}
Write-Verbose ('Exporting results to CSV: ' + $strLocalMAMEDatabaseCSV)
$arrJoinedData | Sort-Object -Property @('ROMName') | Export-Csv -Path $strLocalMAMEDatabaseCSV -NoTypeInformation
Write-Verbose "Done!"
$VerbosePreference = $actionPreferenceFormerVerbose
$DebugPreference = $actionPreferenceFormerDebug