Created
May 29, 2022 02:47
-
-
Save joyrider3774/fa88b95ba7bac96b4744e488b603a880 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$repourl = "https://arduboy.ried.cl/repo.json" | |
$romsdir = "./arduboy/roms" | |
$mediadir = "./arduboy/screenshots" | |
#emulation station destkop editon gamelist | |
$gameslist = "./arduboy/gamelist.xml" | |
if (!(Test-Path -Path $romsdir)) | |
{ | |
New-Item -ItemType Directory $romsdir | |
} | |
if (!(Test-Path -Path $mediadir)) | |
{ | |
New-Item -ItemType Directory $mediadir | |
} | |
$xmlObjectsettings = New-Object System.Xml.XmlWriterSettings | |
#Indent: Gets or sets a value indicating whether to indent elements. | |
$xmlObjectsettings.Indent = $true | |
$xmlObjectsettings.IndentChars = " " | |
$XmlFilePath = $gameslist | |
$XmlObjectWriter = [System.XML.XmlWriter]::Create($XmlFilePath, $xmlObjectsettings) | |
$XmlObjectWriter.WriteStartDocument() | |
$XmlObjectWriter.WriteStartElement("gameList") | |
$json = Invoke-RestMethod -Uri $repourl | |
foreach ($item in $json.items) | |
{ | |
if ($item.binaries) | |
{ | |
try { | |
$XmlObjectWriter.WriteStartElement("game") | |
$XmlObjectWriter.WriteElementString("path", "./" + $item.title + ".hex") | |
$XmlObjectWriter.WriteElementString("name", $item.title) | |
$XmlObjectWriter.WriteElementString("desc", $item.description) | |
$XmlObjectWriter.WriteElementString("developer", $item.author) | |
try { | |
$XmlObjectWriter.WriteElementString("releasedate", ([DateTime]$item.date).ToUniversalTime().toString("yyyMMddT000000")) | |
} | |
catch{} | |
$XmlObjectWriter.WriteElementString("genre", $item.genre) | |
$XmlObjectWriter.WriteEndElement() #game | |
Invoke-WebRequest -Uri $item.binaries[0].filename -OutFile ((Join-Path $romsdir $item.title) + ".hex") | |
if ($item.banner -and (!($items.banner -eq ""))) | |
{ | |
$req = [System.Net.HttpWebRequest]::Create($item.banner) | |
$req.Method = "HEAD" | |
$response = $req.GetResponse() | |
$fUri = $response.ResponseUri | |
$ext = [System.IO.Path]::GetExtension($fUri.LocalPath) | |
$response.Close() | |
if($ext -eq "") | |
{ | |
$ext = ".png" | |
} | |
Invoke-WebRequest -Uri $item.banner -OutFile ((Join-Path $mediadir $item.title) + $ext.ToLower()) | |
} | |
} | |
catch | |
{} | |
} | |
} | |
$XmlObjectWriter.WriteEndElement() #gameslist | |
$XmlObjectWriter.WriteEndDocument() | |
$XmlObjectWriter.Flush() | |
$XmlObjectWriter.Close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment