Advertisement
zenmaster24

RetroArch - new-playlist.ps1

Jan 30th, 2016
15,600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. .SYNOPSIS
  3.     This script tries to create a playlist (.lpl) file for your ROMs in a given path.
  4.  
  5. .DESCRIPTION
  6.     Providing the RetroArch and ROM paths, this script will scan the ROM path and create a playlist file based on the files found during a recursive scan.
  7.     If it detects a zip file, the script will try and enumerate the first file and append it to the ROM path in the playlist, as below.
  8.    
  9.     Each entry in the playlist file requires six lines:
  10.       1) ROM path - ROM name inside zip needs to be specified and separated with #
  11.       2) Display name
  12.       3) Path to core [or DETECT]
  13.       4) Name of core [or DETECT]
  14.       5) CRC          [or DETECT]
  15.       6) Name of playlist
  16.    
  17.     This script outputs the playlist encoding in ANSI.
  18.    
  19.     Example output-
  20.  
  21.     Nintendo - Super Nintendo Entertainment System.lpl
  22.     D:\games\snes\[Japanese]\Final Fantasy 4.zip#Final Fantasy 4.smc
  23.     Final Fantasy 4
  24.     DETECT
  25.     DETECT
  26.     DETECT
  27.     Nintendo - Super Nintendo Entertainment System.lpl
  28.  
  29. .PARAMETER RetroArchPath
  30.     The path to the RetroArch directory.
  31.  
  32.     Required?                    true
  33.     Position?                    0
  34.     Default value                
  35.     Accept pipeline input?       false
  36.     Accept wildcard characters?  false
  37.  
  38. .PARAMETER ROMPath
  39.     The path to the directory containing the ROM files you wish to scan.
  40.  
  41.     Required?                    true
  42.     Position?                    1
  43.     Default value                
  44.     Accept pipeline input?       false
  45.     Accept wildcard characters?  false
  46.  
  47. .PARAMETER FileExtensions
  48.     An array of file extensions you wish to include in the scan.
  49.     If omitted, all files found are included in the scan.
  50.  
  51.     Required?                    false
  52.     Position?                    2
  53.     Default value                *
  54.     Accept pipeline input?       false
  55.     Accept wildcard characters?  true
  56.  
  57. .INPUTS
  58.     None.
  59.    
  60. .OUTPUTS
  61.     ANSI encoded file in $RetroArchPath\playlists.
  62.  
  63. .EXAMPLE
  64.     .\new-playlist.ps1 -RetroArchPath C:\RetroArch -ROMPath C:\ROMS
  65.    
  66.     Scan C:\ROMS and create the playlist in C:\RetroArch\playlists.
  67.  
  68. .EXAMPLE
  69.     .\new-playlist.ps1 -RetroArchPath C:\RetroArch -ROMPath C:\ROMS -FileExtensions *.zip,*.7z
  70.  
  71.     Scan C:\ROMS and create the playlist in C:\RetroArch\playlists, only including files with an extension of .zip or .7z
  72.  
  73. .EXAMPLE
  74.     .\new-playlist.ps1 -RetroArchPath C:\RetroArch -ROMPath C:\ROMS -FileExtensions *.iso,*.cue
  75.  
  76.     Scan C:\ROMS and create the playlist in C:\RetroArch\playlists, only including files with an extension of .iso or .cue
  77.  
  78. .NOTES
  79.     Created 30/01/2016
  80.     Select-Text function created by Brent Challis and adapted - http://powershell.com/cs/media/p/10883.aspx
  81. #>
  82.  
  83. Param(
  84.     [Parameter(Mandatory=$True)]
  85.     [String]$RetroArchPath=$(Read-Host "RetroArch path"),
  86.     [Parameter(Mandatory=$True)]
  87.     [String]$ROMPath=$(Read-Host "ROM path"),
  88.     [Parameter(Mandatory=$False)]
  89.     [String[]]$FileExtensions="*"
  90. )
  91.  
  92. Function Select-TextItem{
  93.     PARAM  
  94.     (
  95.         [Parameter(Mandatory=$true)]
  96.         $options
  97.     )
  98.      
  99.         Write-Host "`nSystem Selection"
  100.  
  101.         [int]$optionPrefix = 1
  102.        
  103.         # Create menu list
  104.         foreach ($option in $options)
  105.         {
  106.             Write-Host ("{0,3}: {1}" -f $optionPrefix,$option)
  107.            
  108.             $optionPrefix++
  109.         }
  110.        
  111.         Write-Host ("`n{0,3}: {1}" -f 0,"To cancel")
  112.        
  113.         [int]$response = Read-Host "`nEnter Selection"
  114.        
  115.         $val = $null
  116.        
  117.         if ($response -gt 0 -and $response -le $options.Count)
  118.         {
  119.             $val = $options[$response-1]
  120.         } else {
  121.             break
  122.         }
  123.  
  124.         return $val
  125. }
  126.  
  127. Function Get-ZipFile{
  128.     Param(
  129.         [Parameter(Mandatory=$true)]
  130.         [string]$ROMFullFilePath
  131.     )
  132.  
  133.     [Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem')|Out-Null
  134.     $ROMZipFileEntry = ([IO.Compression.ZipFile]::OpenRead($ROMFullFilePath).Entries[0].FullName)
  135.  
  136.     Return $ROMZipFileEntry
  137.  
  138. }
  139.  
  140. $Systems = @(
  141. "3DO",
  142. "Atari - 2600",
  143. "Atari - 7800",
  144. "Atari - Jaguar",
  145. "Atari - Lynx",
  146. "Atari - ST",
  147. "Bandai - WonderSwan Color",
  148. "Bandai - WonderSwan",
  149. "Commodore Amiga",
  150. "DOOM",
  151. "DOS",
  152. "FB Alpha - Arcade Games",
  153. "GCE - Vectrex",
  154. "Magnavox - Odyssey2",
  155. "MAME",
  156. "Microsoft - MSX",
  157. "Microsoft - MSX2",
  158. "NEC - PC Engine - TurboGrafx 16",
  159. "NEC - PC Engine CD - TurboGrafx-CD",
  160. "NEC - PC Engine SuperGrafx",
  161. "NEC - PC-FX",
  162. "Neo Geo",
  163. "Nintendo - Famicom Disk System",
  164. "Nintendo - Game and Watch",
  165. "Nintendo - Game Boy Advance",
  166. "Nintendo - Game Boy Color",
  167. "Nintendo - Game Boy",
  168. "Nintendo - Nintendo 64",
  169. "Nintendo - Nintendo DS Decrypted",
  170. "Nintendo - Nintendo DS",
  171. "Nintendo - Nintendo Entertainment System",
  172. "Nintendo - Satellaview",
  173. "Nintendo - Super Nintendo Entertainment System",
  174. "Nintendo - Virtual Boy",
  175. "Sega - 32X",
  176. "Sega - Game Gear",
  177. "Sega - Master System - Mark III",
  178. "Sega - Mega Drive - Genesis",
  179. "Sega - Mega-CD - Sega CD",
  180. "Sega - Saturn",
  181. "Sega - SG-1000",
  182. "Sinclair - ZX Spectrum +3",
  183. "SNK - Neo Geo Pocket Color",
  184. "SNK - Neo Geo Pocket",
  185. "Sony - PlayStation Portable",
  186. "Sony - PlayStation"
  187. )
  188.  
  189. $val = Select-TextItem $Systems
  190.  
  191. $LPLFileName = "$val.lpl"
  192.  
  193. $LPLFilePath = "$RetroArchPath\playlists"
  194. $LPLPath = "$LPLFilePath\$LPLFileName"
  195.  
  196. Try {
  197.    
  198.     # Required because even if the path doesn't exist, GCI still seem's to exit with $true
  199.     If(Test-Path $ROMPath){
  200.         $ROMS = Get-ChildItem $ROMPath -Recurse -File -Include $FileExtensions
  201.     } else {
  202.         Write-Output "Error - Could not find ROM path $ROMPath"
  203.         exit 1
  204.     }
  205.  
  206.     ForEach($ROM in $ROMS){
  207.        
  208.         $ROMExtension = $ROM.Extension
  209.         $ROMPath = $ROM.FullName
  210.         $ROMName = ($ROM.BaseName).replace(".","")
  211.  
  212.         If($ROMExtension -eq ".zip"){
  213.            
  214.             $ROMZip = Get-ZipFile $ROMPath
  215.             $ROMPath = "$ROMPath#$ROMZip"
  216.  
  217.         }
  218.  
  219. $LPLEntry = @"
  220. $ROMPath
  221. $ROMName
  222. DETECT
  223. DETECT
  224. DETECT
  225. $LPLFileName
  226. "@
  227.  
  228.     $LPLEntry | Out-File -FilePath $LPLPath -Append -Encoding ascii
  229.  
  230.     }
  231.  
  232.     Write-Output "`nGenerated playlist file $LPLPath"
  233.  
  234. }
  235.  
  236. Catch {
  237.     $_.exception
  238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement