|
1 |
| -$MSG="$emudeckFolder/logs/msg.log" |
2 |
| - |
3 |
| - |
4 | 1 | function generateGameLists {
|
5 |
| - Move-Item -Path "$storagePath/retrolibrary/assets/alekfull/carousel-icons" -Destination "$storagePath/retrolibrary/assets/default/carousel-icons" -Force |
6 |
| - generate_pythonEnv *> $null |
| 2 | + # Invoca la función generate_pythonEnv y redirige la salida a null |
| 3 | + generate_pythonEnv | Out-Null |
7 | 4 |
|
8 |
| - $accountfolder = Get-ChildItem "$HOME/.steam/steam/userdata" | Sort-Object LastWriteTime -Descending | Select-Object -First 1 |
9 |
| - $dest_folder = "$accountfolder/config/grid/retrolibrary/artwork/" |
| 5 | + # Obtiene la carpeta de usuario de Steam más reciente |
| 6 | + $accountFolder = Get-ChildItem "$steamInstallPath/userdata" -Directory | Sort-Object LastWriteTime -Descending | Select-Object -First 1 |
| 7 | + $destFolder = "$steamInstallPath/userdata$accountFolder/config/grid/retrolibrary/artwork" |
| 8 | + Write-Output "Starting to build database" | Set-Content -Path $MSG |
10 | 9 |
|
11 |
| - "Starting to build database" | Out-File -FilePath "$MSG" |
12 |
| - New-Item -ItemType Directory -Path "$storagePath/retrolibrary/artwork" -Force |
13 |
| - New-Item -ItemType Directory -Path "$storagePath/retrolibrary/cache" -Force |
14 |
| - New-Item -ItemType Directory -Path "$accountfolder/config/grid/retrolibrary/" -Force |
| 10 | + # Crea los directorios necesarios |
| 11 | + New-Item -ItemType Directory -Force -Path "$storagePath/retrolibrary/artwork" |
| 12 | + New-Item -ItemType Directory -Force -Path "$storagePath/retrolibrary/cache" |
| 13 | + New-Item -ItemType Directory -Force -Path "$accountFolder/config/grid/retrolibrary" |
15 | 14 |
|
| 15 | + # Elimina archivos vacíos en el directorio de artwork |
16 | 16 | Get-ChildItem "$storagePath/retrolibrary/artwork" -File | Where-Object { $_.Length -eq 0 } | Remove-Item -Force
|
17 | 17 |
|
18 |
| - New-Item -ItemType SymbolicLink -Path "$accountfolder/config/grid/retrolibrary/artwork" -Target "$storagePath/retrolibrary/artwork" -Force |
19 |
| - New-Item -ItemType SymbolicLink -Path "$accountfolder/config/grid/retrolibrary/cache" -Target "$storagePath/retrolibrary/cache" -Force |
| 18 | + # Crea junctions |
| 19 | + mkdir "$accountFolder/config/grid/retrolibrary" -ErrorAction SilentlyContinue |
| 20 | + $simLinkPath = "$steamInstallPath/userdata/$accountFolder/config/grid/retrolibrary/artwork" |
| 21 | + $emuSavePath = "$storagePath/retrolibrary/artwork" |
| 22 | + createSaveLink $simLinkPath $emuSavePath |
| 23 | + |
| 24 | + $simLinkPath = "$steamInstallPath/userdata/$accountFolder/config/grid/retrolibrary/cache" |
| 25 | + $emuSavePath = "$storagePath\retrolibrary\cache" |
| 26 | + createSaveLink $simLinkPath $emuSavePath |
20 | 27 |
|
| 28 | + # Llama a las funciones de descarga |
21 | 29 | generateGameLists_downloadAchievements
|
22 | 30 | generateGameLists_downloadData
|
23 | 31 | generateGameLists_downloadAssets
|
24 | 32 |
|
25 |
| - robocopy "$emudeckBackend/roms/" "$storagePath/retrolibrary/artwork" /E /XD roms txt |
| 33 | + # Sincroniza archivos usando RoboCopy |
| 34 | + robocopy "$emudeckBackend/roms/" "$storagePath/retrolibrary/artwork" /MIR /XD roms txt /SL |
| 35 | + |
| 36 | + # Configura las rutas de Pegasus |
26 | 37 | pegasus_setPaths
|
| 38 | + |
| 39 | + Write-Output "Database built" | Set-Content -Path $MSG |
| 40 | + |
| 41 | + # Ejecuta el script de Python |
27 | 42 | python "$emudeckBackend/tools/retro-library/generate_game_lists.py" "$romsPath"
|
28 |
| - generateGameLists_artwork *> $null & |
| 43 | + |
| 44 | + # Llama a la función para manejar artwork en segundo plano |
| 45 | + Start-Job { generateGameLists_artwork } | Out-Null |
29 | 46 | }
|
30 | 47 |
|
31 | 48 | function generateGameListsJson {
|
32 |
| - generate_pythonEnv *> $null |
33 |
| - "Adding Games" | Out-File -FilePath "$MSG" |
34 |
| - "Games Added" | Out-File -FilePath "$MSG" |
| 49 | + # Invoca la función generate_pythonEnv y redirige la salida a null |
| 50 | + generate_pythonEnv | Out-Null |
| 51 | + |
| 52 | + # Escribe mensajes en el archivo de mensaje |
| 53 | + Write-Output "Adding Games" | Set-Content -Path $MSG |
| 54 | + Write-Output "Games Added" | Set-Content -Path $MSG |
| 55 | + |
| 56 | + # Muestra el contenido del archivo JSON |
35 | 57 | Get-Content "$storagePath/retrolibrary/cache/roms_games.json"
|
36 | 58 | }
|
37 | 59 |
|
38 | 60 | function generateGameLists_artwork {
|
39 |
| - generate_pythonEnv *> $null |
40 |
| - "Searching for missing artwork" | Out-File -FilePath "$MSG" |
| 61 | + # Invoca la función generate_pythonEnv y redirige la salida a null |
| 62 | + generate_pythonEnv | Out-Null |
| 63 | + |
| 64 | + # Escribe mensaje inicial en el archivo de mensaje |
| 65 | + Write-Output "Searching for missing artwork" | Set-Content -Path $MSG |
| 66 | + |
| 67 | + # Ejecuta los scripts de Python para buscar y descargar artwork |
41 | 68 | python "$emudeckBackend/tools/retro-library/missing_artwork_platforms.py" "$romsPath" "$storagePath/retrolibrary/artwork"
|
42 | 69 | python "$emudeckBackend/tools/retro-library/download_art_platforms.py" "$storagePath/retrolibrary/artwork"
|
43 |
| - python "$emudeckBackend/tools/retro-library/missing_artwork_nohash.py" "$romsPath" "$storagePath/retrolibrary/artwork" |
44 |
| - python "$emudeckBackend/tools/retro-library/download_art_nohash.py" "$storagePath/retrolibrary/artwork" & |
45 |
| - "Artwork finished. Restart if you see this message" | Out-File -FilePath "$MSG" |
| 70 | + |
| 71 | + # Ejecuta los scripts de Python adicionales en segundo plano |
| 72 | + Start-Job { |
| 73 | + python "$emudeckBackend/tools/retro-library/missing_artwork_nohash.py" "$romsPath" "$storagePath/retrolibrary/artwork" |
| 74 | + python "$emudeckBackend/tools/retro-library/download_art_nohash.py" "$storagePath/retrolibrary/artwork" |
| 75 | + } |
| 76 | + |
| 77 | + # Escribe mensaje final en el archivo de mensaje |
| 78 | + Write-Output "Artwork finished. Restart if you see this message" | Set-Content -Path $MSG |
46 | 79 | }
|
47 | 80 |
|
48 |
| -function saveImage { |
49 |
| - param( |
50 |
| - [string]$url, [string]$name, [string]$system |
51 |
| - ) |
| 81 | +function saveImage($url, $name, $system){ |
| 82 | + |
| 83 | + # Obtiene la carpeta de usuario de Steam más reciente |
| 84 | + $accountFolder = Get-ChildItem "$steamInstallPath/userdata" -Directory | Sort-Object LastWriteTime -Descending | Select-Object -First 1 |
| 85 | +$accountFolder = $accountFolder.FullName |
| 86 | + |
| 87 | + # Define las rutas de destino |
| 88 | + $destFolder = "$storagePath/retrolibrary/artwork/$system/media/box2dfront/" |
| 89 | + $destPath = "$destFolder/$name.jpg" |
52 | 90 |
|
53 |
| - $accountfolder = Get-ChildItem "$HOME/.steam/steam/userdata" | Sort-Object LastWriteTime -Descending | Select-Object -First 1 |
54 |
| - $dest_folder = "$storagePath/retrolibrary/artwork/$system/media/box2dfront/" |
55 |
| - $dest_path = "$dest_folder/$name.jpg" |
56 |
| - Invoke-WebRequest -Uri $url -OutFile $dest_path |
| 91 | + # Crea el directorio si no existe |
| 92 | + if (-not (Test-Path -Path $destFolder)) { |
| 93 | + New-Item -ItemType Directory -Force -Path $destFolder | Out-Null |
| 94 | + } |
| 95 | + |
| 96 | + # Descarga la imagen desde la URL |
| 97 | + Invoke-WebRequest -Uri $url -OutFile $destPath -UseBasicParsing -Quiet |
57 | 98 | }
|
58 | 99 |
|
59 |
| -function addGameListsArtwork { |
60 |
| - param( |
61 |
| - [string]$file, [string]$appID, [string]$platform |
62 |
| - ) |
| 100 | +function addGameListsArtwork($file, $appID, $platform){ |
63 | 101 |
|
64 |
| - $accountfolder = Get-ChildItem "$HOME/.steam/steam/userdata" | Sort-Object LastWriteTime -Descending | Select-Object -First 1 |
| 102 | + # Obtiene la carpeta de usuario de Steam más reciente |
| 103 | + $accountFolder = Get-ChildItem "$steamInstallPath/userdata" -Directory | Sort-Object LastWriteTime -Descending | Select-Object -First 1 |
| 104 | + $accountFolder = $accountFolder.FullName |
| 105 | + # Define las rutas de origen y destino |
65 | 106 | $vertical = "$storagePath/retrolibrary/artwork/$platform/media/box2dfront/$file.jpg"
|
66 |
| - $destination_vertical = "$accountfolder/config/grid/${appID}p.png" |
67 |
| - $destination_hero = "$accountfolder/config/grid/${appID}_hero.png" |
68 |
| - $destination_grid = "$accountfolder/config/grid/${appID}.png" |
| 107 | + $grid = $vertical |
| 108 | + $destinationVertical = "$accountFolder/config/grid/${appID}p.png" |
| 109 | + $destinationHero = "$accountFolder/config/grid/${appID}_hero.png" |
| 110 | + $destinationGrid = "$accountFolder/config/grid/${appID}.png" |
| 111 | + |
| 112 | + # Elimina los archivos existentes en los destinos |
| 113 | + Remove-Item -Path $destinationVertical -Force -ErrorAction SilentlyContinue |
| 114 | + Remove-Item -Path $destinationHero -Force -ErrorAction SilentlyContinue |
| 115 | + Remove-Item -Path $destinationGrid -Force -ErrorAction SilentlyContinue |
| 116 | + |
| 117 | + # Crea enlaces simbólicos (junctions) |
| 118 | + createSaveLink $destinationVertical $vertical |
| 119 | + createSaveLink $destinationHero $grid |
| 120 | + createSaveLink $destinationGrid $grid |
69 | 121 |
|
70 |
| - Remove-Item -Path $destination_vertical -Force -ErrorAction SilentlyContinue |
71 |
| - Remove-Item -Path $destination_hero -Force -ErrorAction SilentlyContinue |
72 |
| - Remove-Item -Path $destination_grid -Force -ErrorAction SilentlyContinue |
| 122 | +} |
| 123 | + |
| 124 | +function generateGameLists_getPercentage { |
| 125 | + # Invoca la función generate_pythonEnv y redirige la salida a null |
| 126 | + generate_pythonEnv | Out-Null |
| 127 | + |
| 128 | + # Obtiene la carpeta de usuario de Steam más reciente |
| 129 | + $accountFolder = Get-ChildItem "$steamInstallPath/userdata" -Directory | Sort-Object LastWriteTime -Descending | Select-Object -First 1 |
| 130 | + $accountFolder = $accountFolder.FullName |
| 131 | + # Define las rutas necesarias |
| 132 | + $destFolder = "$storagePath/retrolibrary/artwork/" |
| 133 | + $jsonFile = "$storagePath/retrolibrary/cache/roms_games.json" |
| 134 | + $jsonFileArtwork = "$storagePath/retrolibrary/cache/missing_artwork_no_hash.json" |
| 135 | + |
| 136 | + # Ejecuta el script de Python para generar datos de artworks faltantes |
| 137 | + python "$emudeckBackend/tools/retro-library/missing_artwork_nohash.py" "$romsPath" "$destFolder" | Out-Null |
| 138 | + |
| 139 | + # Cargar y procesar los datos de JSON |
| 140 | + if (-Not (Test-Path $jsonFile) -or -Not (Test-Path $jsonFileArtwork)) { |
| 141 | + Write-Output "Required JSON files are missing." |
| 142 | + return |
| 143 | + } |
| 144 | + |
| 145 | + # Leer el contenido de los archivos JSON |
| 146 | + $games = (Get-Content $jsonFile | ConvertFrom-Json | ForEach-Object { $_.games } | Measure-Object).Count |
| 147 | + $artworkMissing = (Get-Content $jsonFileArtwork | ConvertFrom-Json | ForEach-Object { $_.games } | Measure-Object).Count |
| 148 | + |
| 149 | + if ($games -eq 0 -or -Not $games) { |
| 150 | + Write-Output "No games found in the JSON file." |
| 151 | + return |
| 152 | + } |
| 153 | + |
| 154 | + # Calcular juegos procesados y el porcentaje |
| 155 | + $parsedGames = $games - $artworkMissing |
| 156 | + $percentage = [math]::Floor((100 * $parsedGames) / $games) |
| 157 | + |
| 158 | + # Mostrar el resultado |
| 159 | + Write-Output "$parsedGames / $games ($percentage%)" |
| 160 | +} |
73 | 161 |
|
74 |
| - New-Item -ItemType SymbolicLink -Path $destination_vertical -Target $vertical -Force |
75 |
| - New-Item -ItemType SymbolicLink -Path $destination_hero -Target $vertical -Force |
76 |
| - New-Item -ItemType SymbolicLink -Path $destination_grid -Target $vertical -Force |
| 162 | +function generateGameLists_downloadAchievements { |
| 163 | + # Define la carpeta de logros |
| 164 | + $folder = "$storagePath/retrolibrary/achievements" |
| 165 | + $accountFolder = Get-ChildItem "$steamInstallPath/userdata" -Directory | Sort-Object LastWriteTime -Descending | Select-Object -First 1 |
| 166 | + $accountFolder = $accountFolder.FullName |
| 167 | + $destFolder = "$accountFolder/config/grid/retrolibrary/achievements" |
| 168 | + |
| 169 | + # Comprueba si la carpeta existe, si no, la crea y descarga los datos |
| 170 | + if (-not (Test-Path -Path $folder)) { |
| 171 | + Write-Output "Downloading Retroachievements Data" | Set-Content -Path $MSG |
| 172 | + New-Item -ItemType Directory -Force -Path $folder | Out-Null |
| 173 | + createSaveLink $destFolder $folder |
| 174 | + download "https://artwork.emudeck.com/achievements/achievements.zip" "achievements.zip" |
| 175 | + moveFromTo "$temp/achievements" "$storagePath\retrolibrary\achievements" |
| 176 | + Write-Output "Retroachievements Data Downloaded" | Set-Content -Path $MSG |
| 177 | + } |
77 | 178 | }
|
78 | 179 |
|
79 |
| -Set-Alias generateGameLists generateGameLists |
80 |
| -Set-Alias generateGameListsJson generateGameListsJson |
81 |
| -Set-Alias generateGameLists_artwork generateGameLists_artwork |
82 |
| -Set-Alias saveImage saveImage |
83 |
| -Set-Alias addGameListsArtwork addGameListsArtwork |
| 180 | +function generateGameLists_downloadData { |
| 181 | + # Define la carpeta de datos |
| 182 | + $folder = "$storagePath/retrolibrary/data" |
| 183 | + $accountFolder = Get-ChildItem "$steamInstallPath/userdata" -Directory | Sort-Object LastWriteTime -Descending | Select-Object -First 1 |
| 184 | + $accountFolder = $accountFolder.FullName |
| 185 | + $destFolder = "$accountFolder/config/grid/retrolibrary/data" |
| 186 | + |
| 187 | + # Crea la carpeta y descarga los datos si no existe |
| 188 | + if (-not (Test-Path -Path $folder)) { |
| 189 | + Write-Output "Downloading Metadata" | Set-Content -Path $MSG |
| 190 | + New-Item -ItemType Directory -Force -Path $folder | Out-Null |
| 191 | + createSaveLink $destFolder $folder |
| 192 | + download "https://artwork.emudeck.com/data/data.zip" "data.zip" |
| 193 | + moveFromTo "$temp/data" "$storagePath\retrolibrary\data" |
| 194 | + Write-Output "Metadata Downloaded" | Set-Content -Path $MSG |
| 195 | + } |
| 196 | +} |
| 197 | + |
| 198 | +function generateGameLists_downloadAssets { |
| 199 | + $accountFolder = Get-ChildItem -Path "$env:USERPROFILE\AppData\Local\Steam\userdata" -Directory | Sort-Object LastWriteTime -Descending | Select-Object -First 1 |
| 200 | + $folder = "$storagePath\retrolibrary\assets" |
| 201 | + $destFolder = "$($accountFolder.FullName)\config\grid\retrolibrary\assets" |
| 202 | + |
| 203 | + $folderDefault = "$storagePath\retrolibrary\assets\default" |
| 204 | + $folderBezels = "$storagePath\retrolibrary\assets\bezels" |
| 205 | + $folderWii = "$storagePath\retrolibrary\assets\wii" |
| 206 | + |
| 207 | + New-Item -ItemType Directory -Force -Path $folder | Out-Null |
| 208 | + New-Item -ItemType SymbolicLink -Path $destFolder -Target $folder -Force | Out-Null |
| 209 | + |
| 210 | + if (-not (Test-Path -Path $folderDefault)) { |
| 211 | + Write-Output "Downloading Assets" | Set-Content -Path $MSG |
| 212 | + New-Item -ItemType Directory -Force -Path $folder | Out-Null |
| 213 | + createSaveLink $destFolder $folder |
| 214 | + download "https://artwork.emudeck.com/assets/default.zip" "default.zip" |
| 215 | + moveFromTo "$temp/default" "$storagePath\retrolibrary\assets" |
| 216 | + Write-Output "Assets Downloaded" | Set-Content -Path $MSG |
| 217 | + } |
| 218 | + |
| 219 | + if (-not (Test-Path -Path $folderBezels)) { |
| 220 | + Write-Output "Downloading Bezels" | Set-Content -Path $MSG |
| 221 | + New-Item -ItemType Directory -Force -Path $folder | Out-Null |
| 222 | + createSaveLink $destFolder $folder |
| 223 | + download "https://artwork.emudeck.com/assets/bezels.zip" "bezels.zip" |
| 224 | + moveFromTo "$temp/bezels" "$storagePath\retrolibrary\assets" |
| 225 | + Write-Output "Bezels Downloaded" | Set-Content -Path $MSG |
| 226 | + } |
| 227 | + |
| 228 | + if (-not (Test-Path -Path $folderWii)) { |
| 229 | + Write-Output "Downloading Wii Assets" | Set-Content -Path $MSG |
| 230 | + New-Item -ItemType Directory -Force -Path $folder | Out-Null |
| 231 | + createSaveLink $destFolder $folder |
| 232 | + download "https://artwork.emudeck.com/assets/wii.zip" "wii.zip" |
| 233 | + moveFromTo "$temp/wii" "$storagePath\retrolibrary\assets" |
| 234 | + Write-Output "Wii Assets Downloaded" | Set-Content -Path $MSG |
| 235 | + } |
| 236 | + |
| 237 | + |
| 238 | + Invoke-WebRequest -Uri "https://artwork.emudeck.com/assets/default/backgrounds/store.jpg" -OutFile "$folder\default\backgrounds\store.jpg" |
| 239 | + Invoke-WebRequest -Uri "https://artwork.emudeck.com/assets/default/carousel-icons/store.jpg" -OutFile "$folder\default\carousel-icons\store.jpg" |
| 240 | + Invoke-WebRequest -Uri "https://artwork.emudeck.com/assets/default/logo/store.png" -OutFile "$folder\default\logo\store.png" |
| 241 | +} |
0 commit comments