Jump to content
LaunchBox Community Forums

Recommended Posts

Posted

I'm having a difficult time importing my setup teknoparrot games. 

I use my sorting script that sorts the games into folders named after PC Arcade system, so i can add the games to LB by selecting the XML's and dropping them into LB and have it do it's thing. 
This would work for most of my systems, but for some reason LB decides that it will import all the setup games from the [TP folder]\userprofiles folder instead.

which is neat, but not what i want. 

I'm assuming that it has to do with build in logic,
I also assume that the XML files have been parsed by the import as it reads the game name and not the file name.

somehow even if I'm not telling LB what I'm importing by not telling what type of game files I want it to import, or declare a default emulator for it, it will read the XML's and return to the TP\USERPROFILES folder. 

This would be so awesome if it would also give me the option to sort the games into seperate platforms or generate the playlists for those platforms, but right now It frustrates me.

any suggestions ? 
 

Posted (edited)

I thought I found the issue...  I had declared the TP\userprofiles folder as the games folder for the system. but that wasn't it either

 

Edited by Klopjero
I was wrong
Posted (edited)

so what I ended up doing is just import the whole library. close LB. 

wrote a different powershell that would add a custom field to each game that would contain the Arcade system metadata so I could build play lists that way.

 

# TeknoParrot add customField to database
# Author: klop
# Updated: Extended to export LaunchBox Playlist XMLs by platform (from JSON metadata) and enrich the Platform DB with Arcade Platform info using CustomField blocks

# ------------------
# Load TeknoParrot Platform XML
# ------------------
$platformPath = "[path to]/LaunchBox/Data/Platforms/Teknoparrot.xml"
[xml]$platformXml = Get-Content $platformPath
$gameIndex = @{}
foreach ($game in $platformXml.LaunchBox.Game) {
    $gameIndex[$game.Title] = $game
}

# Prepare for appending CustomFields after <Game> entries
$launchBoxNode = $platformXml.SelectSingleNode("/LaunchBox")

# ------------------
# Process each game and read associated JSON metadata
# ------------------
$metadataPath = "[path to tekno parrot]\Metadata" # Path to teknoparrot
$groupedGames = @{}

foreach ($game in $gameIndex.Values) {
    $applicationPath = $game.ApplicationPath
    if (-not $applicationPath) { continue }

    $profileName = [System.IO.Path]::GetFileNameWithoutExtension($applicationPath)
    $jsonFilePath = Join-Path $metadataPath "$profileName.json"

    if (Test-Path $jsonFilePath) {
        try {
            $json = Get-Content $jsonFilePath | ConvertFrom-Json
            $platformName = $json.platform

            # Add custom field as a sibling of <Game> under root
            $customFieldNode = $platformXml.CreateElement("CustomField")
            
            $gameIdNode = $platformXml.CreateElement("GameID")
            $gameIdNode.InnerText = $game.ID
            $customFieldNode.AppendChild($gameIdNode) | Out-Null

            $nameNode = $platformXml.CreateElement("Name")
            $nameNode.InnerText = "Arcade Platform"
            $customFieldNode.AppendChild($nameNode) | Out-Null

            $valueNode = $platformXml.CreateElement("Value")
            $valueNode.InnerText = $platformName
            $customFieldNode.AppendChild($valueNode) | Out-Null

            $launchBoxNode.AppendChild($customFieldNode) | Out-Null

            # Group by platform for playlist creation
            if (-not $groupedGames.ContainsKey($platformName)) {
                $groupedGames[$platformName] = @()
            }
            $groupedGames[$platformName] += $game
        }
        catch {
            Write-Warning "Failed to parse JSON: $jsonFilePath"
        }
    }
    else {
        Write-Warning "Missing JSON for: $profileName"
    }
}

# ------------------
# Save updated Platform DB with ArcadePlatform entries
# ------------------
$platformXml.Save($platformPath)
Write-Host "Updated Teknoparrot.xml with Arcade Platform custom fields."

# ------------------
# Create a LaunchBox Playlist XML for each platform group
# ------------------
foreach ($platformName in $groupedGames.Keys) {
    $playlistGames = $groupedGames[$platformName]
    $playlistId = [guid]::NewGuid().ToString()
    $playlistXml = New-Object xml
    $root = $playlistXml.CreateElement("LaunchBox")
    $playlistXml.AppendChild($root) | Out-Null

    # Playlist metadata
    $playlist = $playlistXml.CreateElement("Playlist")
    $root.AppendChild($playlist) | Out-Null
    $playlist.AppendChild($playlistXml.CreateElement("PlaylistId")).InnerText = $playlistId
    $playlist.AppendChild($playlistXml.CreateElement("Name")).InnerText = $platformName
    $playlist.AppendChild($playlistXml.CreateElement("NestedName")).InnerText = $platformName
    $playlist.AppendChild($playlistXml.CreateElement("IncludeWithPlatforms")).InnerText = "false"
    $playlist.AppendChild($playlistXml.CreateElement("IsAutogenerated")).InnerText = "false"

    # Add games to playlist
    $i = 0
    foreach ($game in $playlistGames) {
        $pg = $playlistXml.CreateElement("PlaylistGame")
        $root.AppendChild($pg) | Out-Null
        $pg.AppendChild($playlistXml.CreateElement("GameId")).InnerText = $game.ID
        $pg.AppendChild($playlistXml.CreateElement("GameTitle")).InnerText = $game.Title
        $pg.AppendChild($playlistXml.CreateElement("GameFileName")).InnerText = [System.IO.Path]::GetFileName($game.ApplicationPath)
        $pg.AppendChild($playlistXml.CreateElement("GamePlatform")).InnerText = "Teknoparrot"
        $pg.AppendChild($playlistXml.CreateElement("ManualOrder")).InnerText = "$i"
        $i++
    }

    # Save
    $safeName = ($platformName -replace '[^a-zA-Z0-9_\- ]', '_')
    $playlistOutputPath = "[path to launchbox]/Playlists/$safeName.xml" #it also generates extra playlistst
    $playlistXml.Save($playlistOutputPath)

    Write-Host "Playlist '$platformName' created at $playlistOutputPath"
}

this is isnt the solution for the helpful unhelpful behavior when your importing Teknoparrot though

Edited by Klopjero

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...