-
Notifications
You must be signed in to change notification settings - Fork 0
/
doublon.ps1
219 lines (190 loc) · 8.36 KB
/
doublon.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
<#
.SYNOPSIS
This script is intended to detect duplicate roms based on the name used by the gamelist.xml files of recalbox
.DESCRIPTION
This script will check in each subfolder of the roms folder, the file gamelist.xml in order to look for duplicates of the same game based on its name.
Duplicates roms are displayed on terminal and coule be store in log file.
.PARAMETER source
Define the source folder for your roms folder
By default : \\recalbox\share\roms
.PARAMETER destination
Define in which folder the log file will be written
By default : . (in the same folder as the script).
.PARAMETER systeme
Define which systeme will be check (base of the system folder in recalbox inside the rom folder), by default this script will check all systems.
By default : all
.PARAMETER log
Define if you want a log file, put csv for a csv file, txt for a txt file, other value will not create log file
By default : n
.EXAMPLE
.\Doublon.ps1
Launch the script to check all system, Duplicate roms will be display on terminal
-------------------------- EXEMPLE 2 --------------------------
.\Doublon.ps1 -source ""\\recalbox\share\roms" -destination "c:\recalbox\result" -systeme "snes" -log csv
Launch the script to check duplicate snes rom, the result file will be put in c:\recalbox\result\Duplicate_roms_recalbox.csv
.INPUTS
.OUTPUTS
This script will generate a text file which all duplicate roms found.
.NOTES
NOM: Doublon.ps1
AUTEUR: Choum
HISTORIQUE VERSION:
1.2 09.09.2017
Fix duplicate name on screen and in log
better display on screen
Add Csv log file
1.1 02.09.2017
add path of the duplicate roms
1.0 31.08.2017
Version Initiale
.LINK
#>
[CmdletBinding()]
# Define script argument
Param(
[Parameter(Mandatory=$False,HelpMessage="Path to the roms folder of recalbox")]
[ValidateScript({Test-Path $_ -PathType Container})]
[string]$Source = "\\recalbox\share\roms",
[Parameter(Mandatory=$False,HelpMessage="Path to the folder where you want your log file is argument -log is set to y, by default current folder of powershell temrinal")]
[ValidateScript({Test-Path $_ -PathType Container})]
[string]$Destination= ".",
[Parameter(Mandatory=$False,HelpMessage="Define which system you want to check (base on roms folder), all by default")]
[Object]$systeme = "all",
[Parameter(Mandatory=$False,HelpMessage="if txt, create a txt log file call duplicate, if csv create a csv file, default value n")]
[Object]$log = "n"
)
if ($log -eq "txt")
{
$result = "$Destination\Duplicate_roms_recalbox.txt"
New-Item $result -force > $null
}
elseif ($log -eq "csv")
{
$result = "$Destination\Duplicate_roms_recalbox.csv"
New-Item $result -force > $null
}
$Gamelist = ""
function add-Rom
{
param([string]$Game,[string]$Path,[string]$systeme)
$d=New-Object PSObject
$d | Add-Member -Name Nom -MemberType NoteProperty -Value $Game
$d | Add-Member -Name Chemin -MemberType NoteProperty -Value $Path
$d | Add-Member -Name Systeme -MemberType NoteProperty -Value $systeme
return $d
}
function Get-Duplicate ($systeme)
# Return an array with all duplicate roms, path & system, also return nb of duplicate roms found.
{
$roms = @()
$liste = @()
$rompath = @()
$compteurDoublon = 0
$compteurA = 0
try {
$Gamelist = (Select-Xml $source\$systeme\gamelist.xml -XPath "//name" | forEach-object {$_.node.InnerXML})
$path = (Select-Xml $source\$systeme\gamelist.xml -XPath "//path" | forEach-object {$_.node.InnerXML})
$path = $path.replace('&', '&')
$Gamelist = $Gamelist.replace('&', '&')
}
catch
{
Write-Host "no gamelist $systeme"
if ($log -eq "txt"){"$source\$systeme\gamelist.xml not present or not readable" | Out-File -Append $result}
$Gamelist = ""
$compteurDoublon = "N/A"
}
if ($gamelist -ne "")
{
foreach ($lines in $Gamelist)
{
$lines = $lines -replace "\[([^\[]*)\]",""
$compteurB = 0
foreach ($x in $roms)
{
if ($lines -eq $x)
{
$test = $path[$compteurA].Replace('(',"\(")
$test = $test.Replace(')',"\)")
if ($liste | Where-Object { $liste.Chemin -match $test} )
{}
else
{
$liste += add-Rom -Game $lines -Path $path[$compteurA] -systeme $systeme
}
$test = $rompath[$compteurB].Replace('(',"\(")
$test = $test.Replace(')',"\)")
if ($liste | Where-Object { $liste.Chemin -match $test })
{}
else
{
$liste += add-Rom -Game $lines -Path $rompath[$compteurB] -systeme $systeme
}
$compteurDoublon = $compteurDoublon +1
}
$compteurB = $compteurB +1
}
$rompath += $path[$compteurA]
$roms += $lines
$compteurA = $compteurA +1
}
if ($compteurDoublon > 0) # Fix when no gamelist (to not return a 0)
{$liste = $liste | Sort-Object Nom}
}
return ($liste,$compteurDoublon)
}
# main
if ($systeme -eq "all")
{
$csv = @()
$c = Get-ChildItem $source | Where-Object {$_.PSIsContainer} | Select-object $_.name
foreach ($systeme in $c)
{
Write-Host "######### SEARCH $systeme #########"
if ($log -eq "txt"){"######### SEARCH $systeme #########" | Out-File -Append $result}
($liste, $NbDuplicate) = Get-Duplicate($systeme)
Write-Host "Duplicate roms found in $systeme : $NbDuplicate"
if ($log -eq "txt"){ "Duplicate roms found in $systeme : $NbDuplicate" | Out-File -Append $result }
Write-Host ($liste | Format-Table | Out-String)
write-Host "######### END $systeme #########"
write-Host ""
write-Host ""
if ($log -eq "txt")
{
$unik = $liste | Group-Object -Property Nom | Select-Object -ExpandProperty name #Recover unique game name
foreach($x in $unik)
{
"$x" | out-file -append $result
$liste | Where-Object {$_.Nom -match "$x"} | Select-Object Chemin | Format-Table -hidetableheaders | out-file -append $result # DIsplay all path for unique game
}
"######### END $systeme #########" | Out-File -Append $result
"" | Out-File -Append $result
"" | Out-File -Append $result
}
elseif ($log -eq "csv")
{$csv = $csv + $liste}
}
if ($log -eq "csv")
{$csv | Export-csv $result -noType -Encoding 'utf8'}
}
else
{
Write-Host "######### SEARCH $systeme #########"
($liste, $NbDuplicate) = Get-Duplicate($systeme)
$unik = $liste | Group-Object -Property Nom | Select-Object -ExpandProperty name #Recover unique game name
Write-Host "Duplicate roms found in $systeme : $NbDuplicate"
Write-Host ($liste | Format-Table | Out-String)
write-Host "######### END $systeme #########"
if ($log -eq "txt")
{
foreach($x in $unik)
{
"$x" | out-file -append $result
$liste | Where-Object {$_.Nom -match "$x"} | Select-Object Chemin | Format-Table -hidetableheaders | out-file -append $result # DIsplay all path for unique game
}
}
if ($log -eq "csv")
{
$liste | Export-csv $result -noType -Encoding 'utf8'
}
}