forked from schmurtzm/Onion-Desktop-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Onion_Config_01_Emulators.ps1
526 lines (410 loc) · 20.1 KB
/
Onion_Config_01_Emulators.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
# Onion Emulators and Apps Manager
param (
[Parameter(Mandatory = $false)]
[string]$Target
)
$SdCard_Version = ""
$SdCardState = ""
$ScriptPath = $MyInvocation.MyCommand.Path
$ScriptDirectory = Split-Path $ScriptPath -Parent
Set-Location -Path $ScriptDirectory
[Environment]::CurrentDirectory = Get-Location
# $Target = "h:"
if (-not $Target) {
. "$PSScriptRoot\Disk_selector.ps1"
if ($selectedTag -ne "") {
$selectedTagSplitted = $selectedTag.Split(",")
$Drive_Number = $($selectedTagSplitted[0])
$Drive_Letter = $($selectedTagSplitted[1])
$Target = "$Drive_Letter`:"
Write-Host "Selected Tag: $selectedTag"
Write-Host "Disk Number: $Drive_Number"
Write-Host "Disk Letter: $Drive_Letter"
}
else {
return
}
}
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName Microsoft.VisualBasic
# Variables globales
$global:rowCountWithoutColor = 0
$global:rowCountGreen = 0
$global:rowCountOrange = 0
# Function to create and populate the table
function FillTable {
param (
[System.Windows.Forms.DataGridView]$dataGridView,
[string]$PackType
)
$PacksrootPath = "$Target\App\PackageManager\data\$PackType\"
# App\PackageManager\data\Emu\Atari - 2600 (Stella 2014)\Emu
# App\PackageManager\data\$PackType\$PackName\$PackContent
$PacksNames = Get-ChildItem -Path $PacksrootPath -Directory
foreach ($PacksName in $PacksNames) {
# exple : for each in "App\PackageManager\data\Emu"
$PackContents = Get-ChildItem -Path (Join-Path -Path $PacksName.FullName -ChildPath $PackType) -Directory
foreach ($PackContent in $PackContents) {
# exple : for each in "App\PackageManager\data\Emu\Atari - 2600 (Stella 2014)\Emu"
Write-Output "Parent Directory: $PacksName.Name, Sub Directory: $PackContent.Name"
$row = New-Object System.Windows.Forms.DataGridViewRow
$cell1 = New-Object System.Windows.Forms.DataGridViewTextBoxCell
$cell2 = New-Object System.Windows.Forms.DataGridViewTextBoxCell
$cell3 = New-Object System.Windows.Forms.DataGridViewTextBoxCell
$cell4 = New-Object System.Windows.Forms.DataGridViewTextBoxCell
$cell1.Value = $PacksName.Name
$cell2.Value = $PackType
$cell3.Value = $PackContent.Name
$cell4.Value = ""
$row.Cells.AddRange($cell1, $cell2, $cell3)
$PackRomDirectory = Join-Path -Path $PacksName.FullName -ChildPath "Roms"
if (Test-Path $PackRomDirectory -PathType Container) {
$romSubDirectories = Get-ChildItem -Path $PackRomDirectory -Directory
$row.Cells.Add($cell4)
$dataGridView.Rows.Add($row)
foreach ($romSubDirectory in $romSubDirectories) {
$cell4.Value = $romSubDirectory.name
}
if (Test-Path "$Target\$PackType\$PackContent" -PathType Container) {
Write-Output "$Target\$PackType\$PackContent"
$row.DefaultCellStyle.BackColor = "Green"
$global:rowCountGreen++
}
else {
$GamesNumber = 0
if (Test-Path "$Target\Roms\$romSubDirectory" -PathType Container) {
$games = Get-ChildItem -Path "$Target\Roms\$romSubDirectory"
$GamesNumber = $games.Count
}
if ($GamesNumber -gt 0) {
Write-Output "Roms: $romSubDirectory, Here!!!!"
$row.DefaultCellStyle.BackColor = "Orange"
$global:rowCountOrange++
}
else {
$global:rowCountWithoutColor++
}
}
}
else {
if ( $PackContent.Name -ne "romscripts") {
# no roms folder, it can be an app
if (Test-Path "$Target\$PackType\$PackContent" -PathType Container) {
Write-Output "$Target\$PackType\$PackContent"
$row.DefaultCellStyle.BackColor = "Green"
$global:rowCountGreen++
}
else {
$global:rowCountWithoutColor++
}
$row.Cells.Add($cell4)
$dataGridView.Rows.Add($row)
}
}
}
}
$labelRowCount.Text = "Items not installed: $rowCountWithoutColor`nItems installed: $rowCountGreen`nItem not installed but roms are here: $rowCountOrange"
$filter = $textBoxFilter.Text.Trim()
foreach ($row in $dataGridView.Rows) {
$row.Visible = $row.Cells[0].Value -like "*$filter*" -or
$row.Cells[1].Value -like "*$filter*" -or
$row.Cells[2].Value -like "*$filter*" -or
$row.Cells[3].Value -like "*$filter*"
}
}
function Get-SubDirectories {
param (
[string]$PackType
)
$rootPath = "$Target\App\PackageManager\data\$PackType\"
$directories = Get-ChildItem -Path $rootPath -Directory
foreach ($directory in $directories) {
$PackContent = Get-ChildItem -Path (Join-Path -Path $directory.FullName -ChildPath $PackType) -Directory
foreach ($subDirectory in $PackContent) {
$subDirectoryName = $subDirectory.Name
$PacksName.Name = $directory.Name
Write-Output "Parent Directory: $PacksName.Name, Sub Directory: $subDirectoryName"
}
}
}
# Function to handle Rom Folder column cell click event
$DataGrid_CellDoubleClick = {
param(
[System.Object]$sender,
[System.Windows.Forms.DataGridViewCellEventArgs]$e
)
$rowIndex = $e.RowIndex
$columnIndex = $e.ColumnIndex
$SelName = $dataGridView.Rows[$rowIndex].Cells[0].Value
$SelType = $dataGridView.Rows[$rowIndex].Cells[1].Value
$SelEmuFolder = $dataGridView.Rows[$rowIndex].Cells[2].Value
$SelRomFolder = $dataGridView.Rows[$rowIndex].Cells[3].Value
if ($columnIndex -eq 2) {
# to handle "Emu Folder" column cell click event
$emuFolderPath = "$Target\$SelType\$SelEmuFolder"
if (Test-Path $emuFolderPath -PathType Container) {
Invoke-Item -Path $emuFolderPath
}
else {
[Microsoft.VisualBasic.Interaction]::MsgBox("Emu folder not found: $emuFolderPath", [Microsoft.VisualBasic.MsgBoxStyle]::OkOnly, "Error")
}
}
if ($columnIndex -eq 3) {
# to handle "Rom Folder" column cell click event
$RomFolderPath = "$Target\Roms\$SelRomFolder"
if (Test-Path $RomFolderPath -PathType Container) {
Invoke-Item -Path $RomFolderPath
}
else {
[Microsoft.VisualBasic.Interaction]::MsgBox("Rom folder not found: $RomFolderPath", [Microsoft.VisualBasic.MsgBoxStyle]::OkOnly, "Error")
}
}
$cellValue = $dataGridView.Rows[$rowIndex].Cells[$columnIndex].Value
write-output "********************* $SelName $SelType $SelEmuFolder"
#[System.Windows.Forms.MessageBox]::Show("Position : ($rowIndex, $columnIndex)`nContenu : $cellValue `n$SelName `n$SelType `n$SelEmuFolder")
if ($columnIndex -eq 0) {
# to handle "Emu Folder" column cell click event
$message = "Copy content of `$Target\App\PackageManager\data\$SelType\$SelName` to the root of $Target"
$result = [Microsoft.VisualBasic.Interaction]::MsgBox($message, [Microsoft.VisualBasic.MsgBoxStyle]::YesNo, "Confirmation")
if ($result -eq [Microsoft.VisualBasic.MsgBoxResult]::Yes) {
$sourcePath = "$Target\App\PackageManager\data\$SelType\$SelName\*"
$destinationPath = "$Target\"
Copy-Item -Path $sourcePath -Destination $destinationPath -Recurse -Force
}
& $RefreshItems
}
}
# Function to handle "pouet" button click event
$InstallButton_Click = {
$selectedRows = $dataGridView.SelectedRows
if ($selectedRows.Count -eq 0) {
Write-Host "No rows selected."
[Microsoft.VisualBasic.Interaction]::MsgBox("Use the row selector at the left to select one or multiple rows firt.`n(Press control for multiple selection)`nThen click install button again.", [Microsoft.VisualBasic.MsgBoxStyle]::OkOnly, "Information")
}
else {
$message = "Are you sure you want to install these items? :`n"
foreach ($row in $selectedRows) {
$folderValue = $row.Cells[0].Value
$message += "`n$folderValue "
Write-Host "Selected Row: $folderValue, $sourceValue, $emuFolderValue, $romFolderValue"
}
$result = [Microsoft.VisualBasic.Interaction]::MsgBox($message, [Microsoft.VisualBasic.MsgBoxStyle]::YesNo, "Confirmation")
if ($result -eq [Microsoft.VisualBasic.MsgBoxResult]::Yes) {
foreach ($row in $selectedRows) {
$folderValue = $row.Cells[0].Value
$sourceValue = $row.Cells[1].Value
$emuFolderValue = $row.Cells[2].Value
$romFolderValue = $row.Cells[3].Value
$sourcePath = "$Target\App\PackageManager\data\$sourceValue\$folderValue\*"
$destinationPath = "$Target\"
Copy-Item -Path $sourcePath -Destination $destinationPath -Recurse -Force
Write-Host "******************** copying `"$sourcePath`" content to :`n$destinationPath"
}
& $RefreshItems
}
}
}
# Function to handle "pouet" button click event
$AutoInstallButton_Click = {
$message = "Are you sure you want to install these items? :`n"
foreach ($row in $dataGridView.Rows) {
if ($row.DefaultCellStyle.BackColor -eq "Orange") {
$folderValue = $row.Cells[0].Value
$message += "`n$folderValue "
Write-Host "Selected Row: $folderValue, $sourceValue, $emuFolderValue, $romFolderValue"
}
}
$result = [Microsoft.VisualBasic.Interaction]::MsgBox($message, [Microsoft.VisualBasic.MsgBoxStyle]::YesNo, "Confirmation")
if ($result -eq [Microsoft.VisualBasic.MsgBoxResult]::Yes) {
foreach ($row in $dataGridView.Rows) {
if ($row.DefaultCellStyle.BackColor -eq "Orange") {
$folderValue = $row.Cells[0].Value
$sourceValue = $row.Cells[1].Value
$emuFolderValue = $row.Cells[2].Value
$romFolderValue = $row.Cells[3].Value
$sourcePath = "$Target\App\PackageManager\data\$sourceValue\$folderValue\*"
$destinationPath = "$Target\"
Copy-Item -Path $sourcePath -Destination $destinationPath -Recurse -Force
Write-Host "******************** copying `"$sourcePath`" content to :`n$destinationPath"
}
}
& $RefreshItems
}
}
$UninstallButton_Click = {
$selectedRows = $dataGridView.SelectedRows
if ($selectedRows.Count -eq 0) {
Write-Host "No rows selected."
[Microsoft.VisualBasic.Interaction]::MsgBox("Use the row selector at the left to select one or multiple rows firt.`n(Press control for multiple selection)`nThen click uninstall button again.", [Microsoft.VisualBasic.MsgBoxStyle]::OkOnly, "Information")
}
else {
$message = "Are you sure you want to uninstall these items? :`n"
foreach ($row in $selectedRows) {
$folderValue = $row.Cells[0].Value
$message += "`n$folderValue "
Write-Host "Selected Row: $folderValue, $sourceValue, $emuFolderValue, $romFolderValue"
}
if (($sourceValue -eq "Emu") -or ($sourceValue -eq "RApp")) {
$message += "`n`n(Your roms will not be deleted)"
}
$result = [Microsoft.VisualBasic.Interaction]::MsgBox($message, [Microsoft.VisualBasic.MsgBoxStyle]::YesNo, "Confirmation")
if ($result -eq [Microsoft.VisualBasic.MsgBoxResult]::Yes) {
foreach ($row in $selectedRows) {
$folderValue = $row.Cells[0].Value
$sourceValue = $row.Cells[1].Value
$emuFolderValue = $row.Cells[2].Value
$romFolderValue = $row.Cells[3].Value
$sourcePath = "$Target\$sourceValue\$emuFolderValue"
Remove-Item -Path $sourcePath -Recurse -Force
Write-Host "******************** Removing `"$sourcePath`""
}
& $RefreshItems
}
}
}
$HelpButton_Click = {
& ".\tools\res\Onion_Emulators_Manager_help.png"
}
$RefreshItems = {
$global:rowCountWithoutColor = 0
$global:rowCountGreen = 0
$global:rowCountOrange = 0
$dataGridView.Rows.Clear()
$selectedSource = $dropDown.SelectedItem.ToString()
Write-Host "Selected source : $selectedSource"
switch ($selectedSource) {
"All" {
FillTable -dataGridView $dataGridView -PackType "Emu"
FillTable -dataGridView $dataGridView -PackType "RApp"
FillTable -dataGridView $dataGridView -PackType "App"
}
"Emu" {
FillTable -dataGridView $dataGridView -PackType "Emu"
}
"RApp" {
FillTable -dataGridView $dataGridView -PackType "RApp"
}
"App" {
FillTable -dataGridView $dataGridView -PackType "App"
}
}
}
# Create the form and controls
$form = New-Object System.Windows.Forms.Form
$form.Text = "Onion Emulators Manager"
$form.Size = New-Object System.Drawing.Size(615, 800)
$form.StartPosition = "CenterScreen"
$iconPath = Join-Path -Path $PSScriptRoot -ChildPath "tools\res\onion.ico"
$icon = New-Object System.Drawing.Icon($iconPath)
$form.Icon = $icon
$dropDown = New-Object System.Windows.Forms.ComboBox
$dropDown.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$dropDown.Items.AddRange(@("All", "Emu", "RApp", "App"))
$dropDown.SelectedIndex = 0
$dropDown.add_SelectedIndexChanged($RefreshItems)
$labelRowCount = New-Object System.Windows.Forms.Label
$labelRowCount.Text = "Rows without color: 0, Rows in green: 0, Rows in orange: 0"
$labelRowCount.AutoSize = $true
$labelRowCount.Anchor = [System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Right
$dataGridView = New-Object System.Windows.Forms.DataGridView
$dataGridView.Dock = [System.Windows.Forms.DockStyle]::Fill
# $dataGridView.Size = New-Object System.Drawing.Size(580, 200)
# $dataGridView.RowHeadersVisible = $false
$dataGridView.RowHeadersWidth = 22
$dataGridView.AllowUserToAddRows = $false
$dataGridView.AllowUserToResizeRows = $false
$dataGridView.ReadOnly = $true
$dataGridView.AutoSizeColumnsMode = [System.Windows.Forms.DataGridViewAutoSizeColumnsMode]::AllCells # Automatically resize columns based on content
$dataGridView.Add_CellDoubleClick($DataGrid_CellDoubleClick) # Attach event handlers
$folderColumn = New-Object System.Windows.Forms.DataGridViewColumn
$folderColumn.HeaderText = "Folder"
$folderColumn.Name = "Folder"
$folderColumn.SortMode = [System.Windows.Forms.DataGridViewColumnSortMode]::Automatic
# $folderColumn.ReadOnly = $true
$dataGridView.Columns.Add($folderColumn)
$sourceColumn = New-Object System.Windows.Forms.DataGridViewColumn
$sourceColumn.HeaderText = "Source"
$sourceColumn.Name = "Source"
$sourceColumn.ReadOnly = $true
$dataGridView.Columns.Add($sourceColumn)
$EmufolderColumn = New-Object System.Windows.Forms.DataGridViewColumn
$EmufolderColumn.HeaderText = "Emu folder"
$EmufolderColumn.Name = "EmuFolder"
$EmufolderColumn.ReadOnly = $true
$dataGridView.Columns.Add($EmufolderColumn)
$romfolderColumn = New-Object System.Windows.Forms.DataGridViewColumn
$romfolderColumn.HeaderText = "Rom folder"
$romfolderColumn.Name = "RomFolder"
$romfolderColumn.ReadOnly = $true
$dataGridView.Columns.Add($romfolderColumn)
# Cr�ation du bouton "InstallButton"
$InstallButton = New-Object System.Windows.Forms.Button
$InstallButton.Text = "Install"
$InstallButton.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Right
$InstallButton.add_Click($InstallButton_Click)
$AutoInstallButton = New-Object System.Windows.Forms.Button
$AutoInstallButton.Text = "Auto-Install"
$AutoInstallButton.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Right
$AutoInstallButton.add_Click($AutoInstallButton_Click)
$checkBox = New-Object System.Windows.Forms.CheckBox
$checkBox.Text = "Include experts"
# $checkBox.Location = New-Object System.Drawing.Point($currentX, $currentY)
$AutoInstallButton.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Right
$checkBox.AutoSize = $true
$UninstallButton = New-Object System.Windows.Forms.Button
$UninstallButton.Text = "Uninstall"
$UninstallButton.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Right
$UninstallButton.add_Click($UninstallButton_Click)
$HelpButton = New-Object System.Windows.Forms.Button
$HelpButton.Text = "Help"
$HelpButton.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Left
$HelpButton.add_Click($HelpButton_Click)
# Add TextBox for filtering
$textBoxFilter = New-Object System.Windows.Forms.TextBox
$textBoxFilter.Anchor = [System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Left
# Attach event handler for filtering
$textBoxFilter.add_TextChanged({
$filter = $textBoxFilter.Text.Trim()
foreach ($row in $dataGridView.Rows) {
$row.Visible = $row.Cells[0].Value -like "*$filter*" -or
$row.Cells[1].Value -like "*$filter*" -or
$row.Cells[2].Value -like "*$filter*" -or
$row.Cells[3].Value -like "*$filter*"
}
})
$tooltip = New-Object System.Windows.Forms.ToolTip
$tooltip.SetToolTip($InstallButton, "This will install all the selected rows.`nUse the row selector at the left to select one or multiple rows firt.`n(Press control for multiple selection)`nThen click install button.")
$tooltip.SetToolTip($AutoInstallButton, "This will install all the emulators where roms are already present (orange lines).")
$tooltip.SetToolTip($UninstallButton, "This will uninstall all the selected rows.`nUse the row selector at the left to select one or multiple rows firt.`n(Press control for multiple selection)`nThen click uninstall button.")
$tooltip.SetToolTip($HelpButton, "This will display the help of Onion Emulator Manager.")
$tooltip.SetToolTip($dropDown, "Select the type of items here.")
$tooltip.SetToolTip($textBoxFilter, "This is a filter field for all the elements of the table below.")
$dataGridViewContainer = New-Object System.Windows.Forms.Panel
$dataGridViewContainer.Dock = [System.Windows.Forms.DockStyle]::Fill
$dataGridViewContainer.Dock = 'Fill'
$tableLayoutPanel = New-Object System.Windows.Forms.TableLayoutPanel
$tableLayoutPanel.Dock = [System.Windows.Forms.DockStyle]::Fill
$dataGridViewContainer.Controls.Add($dataGridView)
# $tableLayoutPanel.Controls.Add($dataGridView,3)
$tableLayoutPanel.Controls.Add($textBoxFilter, 0, 1)
$tableLayoutPanel.Controls.Add($dropDown, 0, 0)
$tableLayoutPanel.Controls.Add($labelRowCount, 1, 0)
# $tableLayoutPanel.Controls.Add($dataGridViewContainer, 0, 3)
$tableLayoutPanel.Controls.Add($InstallButton, 2, 0)
$tableLayoutPanel.Controls.Add($AutoInstallButton, 2, 1)
# $tableLayoutPanel.Controls.Add($checkBox, 0, 2)
$tableLayoutPanel.Controls.Add($UninstallButton, 2, 2)
$tableLayoutPanel.Controls.Add($HelpButton, 0, 2)
# $form.Controls.Add($InstallButton)
# $form.Controls.Add($UninstallButton)
# $dataGridViewContainer.ColumnSpan = $tableLayoutPanel.ColumnCount
$tableLayoutPanel.Controls.Add($dataGridView)
$tableLayoutPanel.SetColumnSpan($dataGridView, 3)
$tableLayoutPanel.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle
$form.Controls.Add($tableLayoutPanel)
# Initial population
# FillTable -dataGridView $dataGridView -PackType "Emu"
# FillTable -dataGridView $dataGridView -PackType "RApp"
# FillTable -dataGridView $dataGridView -PackType "App"
& $RefreshItems
[void]$form.ShowDialog()