Jump to content
LaunchBox Community Forums

TeknoParrot per platform sorting Script using powershell


Recommended Posts

Greetings, 

Sorting through the various platforms that are supported in Teknoparrot can be quite a chore.
I've written a script, that will plow through the games you have setup and sort them by platform so you can just drag and drop them into launchbox. 

known issue: 
- game titles with : in string wil not create folder (WIP) (fixed) - (script updated)
 

# Author klopjero 
#Teknoparrot, game Sorting by platform script for use with launchbox
# The function of this script is to allow the user to scan for games that are set up in teknoparrot, sort them into platformsso that they can be added to Launchbox. 
# import the results using folder names. 
#load assembly fiels for file browser
Add-Type -AssemblyName System.Windows.Forms

#variables
#get teknoparrot location
Add-Type -AssemblyName System.Windows.Forms
$FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
$FolderBrowser.Description = 'Select the folder containing TeknoParrotUI.exe'
$result = $FolderBrowser.ShowDialog((New-Object System.Windows.Forms.Form -Property @{TopMost = $true }))
if ($result -eq [Windows.Forms.DialogResult]::OK){
$FolderBrowser.SelectedPath
} else {
exit
}
$Teknoparrot = $FolderBrowser.SelectedPath
$Teknoparrot
#Check if TeknoparrotUI.exe lives in $Teknoparrot
$found = Test-path $Teknoparrot\TeknoparrotUI.exe
    IF($found = $true) 
        { 
        Write-Host TheBird is alive matey!, plunderin yer games now, ship ahoy!
        $imports = Test-Path "$Teknoparrot\imports"
            IF($imports -eq $false)
                {
                new-item -ItemType Directory "$Teknoparrot\imports"
                } 
        #get your setup games, including platform and full game name
        $TPSetgames = Get-ChildItem $Teknoparrot\gameProfiles\*.xml | select-object -ExpandProperty BaseName
        foreach ($TPSetgame in $TPSetgames)
            {
            $TPSetgame
            [xml]$XML = Get-Content $Teknoparrot\GameProfiles\$TPSetgame.xml
            $gamenameraw = $xml.gameprofile.gamename
            #clean nasty unwanted characters from game name to allow for folder creation
            $gamename = $gamenameraw -replace ":",""
            $json = Get-content $Teknoparrot\descriptions\$TPSetgame.json -raw |ConvertFrom-Json  
            $platform = $json.platform
            $Tp2pt = test-path $Teknoparrot\imports\$platform\
                IF ($Tp2pt -eq $false)
                    { 
                    write-host creating new folder $Teknoparrot\imports\$platform\$gamename\$TPSetgame.xml
                    New-Item -ItemType Directory $Teknoparrot\imports\$platform -force
                    New-Item -itemType Directory $Teknoparrot\imports\$platform\$gamename -Force
                    New-Item -ItemType File $Teknoparrot\imports\$platform\$gamename\$TPSetgame.xml -Force
                    }
                write-host creating new folder $Teknoparrot\imports\$platform\$gamename\$TPSetgame.xml
                New-Item -itemType Directory $Teknoparrot\imports\$platform\$gamename -Force
                New-Item -ItemType File $Teknoparrot\imports\$platform\$gamename\$TPSetgame.xml -force
            }
        #open imports folder.
        Invoke-Item $Teknoparrot\imports
    }

teknoparrotfinder.ps1anyway, hope you find it usefull. any feedback would be nice. 

 

Edited by Klopjero
Link to comment
Share on other sites

  • 1 month later...

I've been updating a bit. Also written a GUI for it. 
image.thumb.png.a420fba709e20bedb164dc14c678cae5.png

When you click "where is teknoParrot button" a browse window will open
image.thumb.png.3cb41627db27e63ab056687c6c88fd26.png
after that you can either Sort by platform or just Sort gun games, when it's done it will out put this folder structure
image.thumb.png.7eea43e88997310dd08ac2d346b0c9ea.png

each sorted game is stored in its seperate folder which will simplify scraping.
image.thumb.png.342eaafc255e34cf1e60f31b4d165b6c.png


I do have an issue though with my XAML. 
it will only find images of my UI if I use absolute paths. and I can't get it to accept relative paths. 
I would really appreciate the help 

MainWindow.xaml

<Window x:Class="System.Windows.Window"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Teknoparrot_Platform_Importer_ui"
        Title="TP Sorting tool" Height="475" Width="815">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Canvas>
            <Canvas.Background>
                <ImageBrush ImageSource="F:\Tools\powershell\TP_GUI\imag1.jpg" Opacity="0.4"/>
            </Canvas.Background>
            <Image Height="100" UseLayoutRounding="False" Source="F:\Tools\powershell\TP_GUI\imag2.png" Canvas.Left="1" Width="799"/>
            <Button Name="Browse" Content="Where is TeknoParrot?" Canvas.Left="10" Canvas.Top="329" Width="780" HorizontalAlignment="Center" VerticalAlignment="Top"/>
            <Button Name="Sort" Content="Sort by platform" Canvas.Left="10" Canvas.Top="354" Width="780" HorizontalAlignment="Center" VerticalAlignment="Top"/>
            <Button Name="Guns" Content="Sort just the gun games" Canvas.Left="10" Canvas.Top="379" Width="780" HorizontalAlignment="Center" VerticalAlignment="Top"/>
            <Button Name="Imports" Content="Go to sorting foler" Canvas.Left="570" Canvas.Top="404" HorizontalAlignment="Left" VerticalAlignment="Center" Width="144"/>
            <Button Name="Exit" Content="Exit" Canvas.Left="718" Canvas.Top="404" HorizontalAlignment="Left" VerticalAlignment="Center" Width="72"/>            
        </Canvas>
    </Grid>
</Window>

and my new Powershell script 

# Author klopjero 
#Teknoparrot, game Sorting by platform script for use with launchbox
# The function of this script is to allow the user to scan for games that are set up in teknoparrot, sort them into platformsso that they can be added to Launchbox. 
# import the results using folder names. 
#load assembly files for file browser
# Load the XAML file
Add-Type -AssemblyName PresentationFramework
$invocation = (Get-Variable MyInvocation).Value
$directorypath = Split-Path $invocation.MyCommand.Path
#$settingspath1 = $directorypath + '\img\imag1.jpg'
#$settingspath2 = $directorypath + '\img\imag2.png' -replace "\","/"
$Teknoparrot = $null  # Initialize the variable in the outer scope

Function Get-teknopparrot 
    {
        #get teknoparrot location
        Add-Type -AssemblyName System.Windows.Forms
        $FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
        $FolderBrowser.Description = 'Select the folder containing TeknoParrotUI.exe'
        $result = $FolderBrowser.ShowDialog((New-Object System.Windows.Forms.Form -Property @{TopMost = $true }))
            if ($result -eq [Windows.Forms.DialogResult]::OK)
            {
            $FolderBrowser.SelectedPath
            } 
        $global:Teknoparrot = $FolderBrowser.SelectedPath
    }
    $global:Teknoparrot = $FolderBrowser.SelectedPath   
Function Sort-Teknoparrot
    {
        #Check if TeknoparrotUI.exe lives in $Teknoparrot
        $found = Test-path $Teknoparrot\TeknoparrotUI.exe
        IF($found = $true) 
            { 
            $imports = Test-Path "$Teknoparrot\imports"
            IF($imports -eq $false)
                {
                new-item -ItemType Directory "$Teknoparrot\imports"
                } 
            #get your setup games, including platform and full game name
            $TPSetgames = Get-ChildItem $Teknoparrot\userprofiles\*.xml | select-object -ExpandProperty BaseName
            foreach ($TPSetgame in $TPSetgames)
                {
                $TPSetgame
                [xml]$XML = Get-Content $Teknoparrot\GameProfiles\$TPSetgame.xml
                $gamenameraw = $xml.gameprofile.gamename
                #clean nasty unwanted characters from game name to allow for folder creation
                $gamename = $gamenameraw -replace ":",""
                $json = Get-content $Teknoparrot\descriptions\$TPSetgame.json -raw |ConvertFrom-Json  
                $platform = $json.platform
                $Tp2pt = test-path $Teknoparrot\imports\$platform\
                    IF ($Tp2pt -eq $false)
                        { 
                        write-host creating new folder $Teknoparrot\imports\$platform\$gamename\$TPSetgame.xml
                        New-Item -ItemType Directory $Teknoparrot\imports\$platform -force
                        New-Item -itemType Directory $Teknoparrot\imports\$platform\$gamename -Force
                        New-Item -ItemType File $Teknoparrot\imports\$platform\$gamename\$TPSetgame.xml -Force
                        }
                write-host creating new folder $Teknoparrot\imports\$platform\$gamename\$TPSetgame.xml
                New-Item -itemType Directory $Teknoparrot\imports\$platform\$gamename -Force
                New-Item -ItemType File $Teknoparrot\imports\$platform\$gamename\$TPSetgame.xml -force
                }
            }
    }        
Function gun-teknoparrot
    {   
    #$Teknoparrot = $FolderBrowser.SelectedPath
    #Check if TeknoparrotUI.exe lives in $Teknoparrot
    $found = Test-path $Teknoparrot\TeknoparrotUI.exe
        IF($found = $true) 
           { 
           $imports = Test-Path "$Teknoparrot\imports"
                IF($imports -eq $false)
                   {
                    new-item -ItemType Directory "$Teknoparrot\imports"
                    } 
                #get your setup games, including platform and full game name
                $TPSetgames = Get-ChildItem $Teknoparrot\UserProfiles\*.xml | select-object -ExpandProperty BaseName
                foreach ($TPSetgame in $TPSetgames)
                    {
                    $TPSetgame
                    [xml]$XML = Get-Content $Teknoparrot\GameProfiles\$TPSetgame.xml
                    $gamenameraw = $xml.gameprofile.gamename
                    $GameGenre = $xml.gameprofile.GameGenre
                    #clean nasty unwanted characters from game name to allow for folder creation
                    $gamename = $gamenameraw -replace ":",""
                    $json = Get-content $Teknoparrot\descriptions\$TPSetgame.json -raw |ConvertFrom-Json  
                    $platform = $json.platform
                    $Tp2pt = test-path $Teknoparrot\imports\$platform\
                        IF ($GameGenre -eq "shooter")
                           {
                            write-host creating new folder $Teknoparrot\imports\GunGames\$gamename
                            New-Item -itemType Directory $Teknoparrot\imports\GunGames\$gamename -Force
                            New-Item -ItemType File $Teknoparrot\imports\GunGames\$gamename\$TPSetgame.xml -Force
                           }
                    }
                
            }
    }
Function import-teknoparrot
    {
    #open imports folder.
    Invoke-Item $Teknoparrot\imports
    }
    
    $XAMLPath = Join-Path -Path $PSScriptRoot -ChildPath "mainwindow.xaml"  # Assuming the XAML file is in the same directory as the script

    [xml]$xaml = Get-Content $XAMLPath
    
    # Add WPF and WindowsBase assemblies
    Add-Type -AssemblyName PresentationCore, PresentationFramework
    
    # Create a XAML reader
    $reader = (New-Object System.Xml.XmlNodeReader $xaml)
    
    # Load the XAML
    $mainWindow = [Windows.Markup.XamlReader]::Load($reader)
    
    # Define variables for the buttons in the XAML
    $BrowseButton = $mainWindow.FindName("Browse")
    $SortButton = $mainWindow.FindName("Sort")
    $GunsButton = $mainWindow.FindName("Guns")
    $ImportsButton = $mainWindow.FindName("Imports")
    $ExitButton = $mainWindow.FindName("Exit")
    
    # Function to handle button actions
    
    Function Handle-BrowseButtonClick {
        # Add your code to handle the Browse button click event here
        Get-teknopparrot
    }
    
    Function Handle-SortButtonClick {
        # Add your code to handle the Sort button click event here
        Sort-Teknoparrot
    }
    
    Function Handle-GunsButtonClick {
        # Add your code to handle the Guns button click event here
        gun-teknoparrot
    }
    
    Function Handle-ImportsButtonClick {
        # Add your code to handle the Imports button click event here
        import-teknoparrot
    }
    
    Function Handle-ExitButtonClick {
        # Add your code to handle the Exit button click event here
        $mainWindow.Close()
    }
    
    # Wire up button click events
    $BrowseButton.Add_Click({ Handle-BrowseButtonClick })
    $SortButton.Add_Click({ Handle-SortButtonClick })
    $GunsButton.Add_Click({ Handle-GunsButtonClick })
    $ImportsButton.Add_Click({ Handle-ImportsButtonClick })
    $ExitButton.Add_Click({ Handle-ExitButtonClick })
    
    # Show the window
    $mainWindow.ShowDialog()
    

    
    
    

 

  • Like 1
Link to comment
Share on other sites

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...