No-Intro Love Pack PowerShell Clean-Up Script

General No-Intro related discussions.
Post Reply
Pr3tty F1y
Posts: 56
Joined: 19 Jul 2014 21:24

No-Intro Love Pack PowerShell Clean-Up Script

Post by Pr3tty F1y »

Prefer to have your dats include homebrew, aftermarket and pirate dumps but sick of clicking so many check boxes and radio buttons?
Just don't have time to keep up downloading individual dats daily, but dealing with all the dats in the Love Pack is too onerous?

Well, if any of that sounds like you, I've created a PowerShell script that will:
  1. Search your current ROM manager's dat directory (and will recurse sub-directories if configured to do so)
  2. Identify the No-Intro dats that you currently have
  3. Then will extract the Love Pack zip that you downloaded and only keep the dats that you are already tracking in your ROM manager
Just download the No-Intro daily Love Pack zip and make sure you click to include Pirate, Homebrew, Aftermarket dumps if you're interested in those sets.

To configure the script, download the attachment and either "right-click -> Edit" it or open the script in your preferred text editor (e.g., Notepad, Notepad++, UltraEdit, etc.).

There are 4 variables that need to be configured at the top of the script:
  1. Set your ROM manager's dat directory
  2. Choose whether or not to recursively search sub-directories in that ROM manger dat directory
  3. Set your download path for the No-Intro Love Pack zip
  4. Choose whether to only retain NEWER versions of dats you already have or keep ALL versions (new + current) of dats you have (in case you want to refresh all of your dats)
After you run the script (right-click -> Run with PowerShell), you can then drag'n drop (at least in CLRMamePro) the extracted No-Intro Love Pack directory and it will only add the dats that you're already tracking and all of the other dats will be eliminated.

To be able to execute as a PowerShell script rename the extension of the attached text file from .txt to .ps1 (the forums, for your safety, won't allow a .ps1 extension as PowerShell scripts can potentially be dangerous if they are coded to be malicious).

I created this script myself and have had no issues with it, but I can't make an guarantees its bug free. If there are any bugs that are experienced, please reply here and I'll try to address them.
You do not have the required permissions to view the files attached to this post.
Pr3tty F1y
Posts: 56
Joined: 19 Jul 2014 21:24

Re: No-Intro Love Pack PowerShell Clean-Up Script

Post by Pr3tty F1y »

New revision attached. Thanks to Pandor for testing.

This version should be MUCH faster as it only extracts out the dats you are already tracking, rather than the previous implementation that extracted the entire zip and deleted out what you didn't need.

Please hit me up with a PM if you run into any issues. And, same as last time, rename the *.txt extension to *.ps1 due to board security not allowing upload of a *.ps1 file.
You do not have the required permissions to view the files attached to this post.
Pandor
Posts: 7
Joined: 29 Apr 2023 08:38

Re: No-Intro Love Pack PowerShell Clean-Up Script

Post by Pandor »

Excellent script that really helps automate the process of updating DAT files. Glad to have been of service in bug reporting and testing.

Now, as i've mentioned in PM, for my use case (RomVault), a additional variable "$ReplaceInPlace = $true" Would make this the ultimate script.

RomVault uses a DAT root folder, where it monitors for its DAT files. To update a DAT, you just remove the old, and replace with the new, and RomVault automagically merges the new entries into its cache (and keeps already verified and unchanged roms as 'known good').

Since the script already keeps a array of current DAT filenames and has filename comparison functionality, I was thinking, of maybe repurposing the unzipping code to instead of just extracting to a subfolder in the $LovePackPath, "If ($ReplaceInPlace)" is set, delete the old DAT, and extract/replace with the new DAT in the $RomManagerDatPath (recursively). This saves another manual step of moving the extracted DAT files to RomVault's DATroot folder.

Something like'... idiotic pseudocode follows:

Code: Select all

when $RomManagerDatPath\snes(old).dat is found, look for snes(new).dat in $LovePackPath\[zip]. if found, remove $RomManagerDatPath\snes(old).dat, and unzip $LovePackPath\[zip]\snes(new).dat to $RomManagerDatPath
This way, one could download the DoM.zip, run the script, and just click renew DAT in RomVault, and be done. This would save a lot of manual labor.
If I find some spare time, I might look into this and maybe try to expand the script, with your permission "Pr3tty F1y". unless you beat me to it. ;)
User avatar
cgar
Posts: 1
Joined: 29 Apr 2023 06:42

Re: No-Intro Love Pack PowerShell Clean-Up Script

Post by cgar »

Pr3tty F1y wrote: 16 Jan 2023 17:13 [...] sick of clicking so many check boxes and radio buttons? [...]
Absolutely!
Pr3tty F1y wrote: 16 Jan 2023 17:13 [...] download the No-Intro daily Love Pack zip and make sure you click [...]
Aww, I wanted zero clicking involved :lol:
Would be great if it also automated the downloading.

Still handy though, thanks.
Pandor
Posts: 7
Joined: 29 Apr 2023 08:38

Re: No-Intro Love Pack PowerShell Clean-Up Script

Post by Pandor »

Since Pr3tty F1y was rather silent about modifying his script, and i couldn't be bothered analyzing his script and the way it creates its arrays (I tried, but its rather complex). I decided I needed a simple way to search and replace the DAT files generated by his script in me favorite manager's (ROMVAULT) DAT-root folder. So here it is if anyone in interested. you need to set the "$sourceFolder" manually to whatever "Pr3tty F1y"'s script created for now. I might build in automation to search for the lates date.
So what this script does is check the files in the source folder and compares to the destination folder, and deletes any older DAT file in the destination, and moves the new DAT file there. it support subfolders.

Mind you, the script is verry noisy (verbose), but that was because i'm not a coder by trade, and my coding/scripting experience is limited. So most of this came from chatGPT, and I wanted to make sure I could easily debug the script.

file: replace_DATs.ps1

Code: Select all

# Specify the source and destination folders
$sourceFolder = "F:\EMU\managers\No-Intro Love Pack (2024-04-13)"
$destinationFolder = "F:\EMU\managers\RomVault\ROMVault\DatRoot"

# Define colors for output using ConsoleColor enumeration
$colorSourceFolder = [System.ConsoleColor]::DarkCyan
$colorDestinationFolder = [System.ConsoleColor]::DarkMagenta
$colorVerboseMessage = [System.ConsoleColor]::DarkYellow
$colorDestinationFile = [System.ConsoleColor]::DarkGreen
$colorExistingFile = [System.ConsoleColor]::DarkRed
$colorCompletionMessage = [System.ConsoleColor]::Yellow

# Function to output colored text
function Write-ColorText {
    param(
        [string]$text,
        [System.ConsoleColor]$color
    )
    Write-Host $text -ForegroundColor $color
}

Write-ColorText "Source folder: $sourceFolder" -color $colorSourceFolder
Write-ColorText "Destination folder: $destinationFolder" -color $colorDestinationFolder

# Get all files in the source folder
Write-ColorText "Getting files from source folder..." -color $colorVerboseMessage
$sourceFiles = Get-ChildItem -Path $sourceFolder -Filter "*.dat" -File -Recurse
Write-ColorText "Found $($sourceFiles.Count) files in source folder." -color $colorVerboseMessage

# Initialize a variable to track if any files were moved
$filesMoved = $false

# Iterate over each file in the source folder
foreach ($sourceFile in $sourceFiles) {
    # Extract the base name of the source file (filename without extension and date information)
    $sourceBaseName = $sourceFile.BaseName -replace '\(\d{8}-\d{6}\)$'
    
    Write-ColorText "Processing source file: $($sourceFile.FullName)" -color $colorVerboseMessage

    # Output verbose message indicating the base name being searched for
    Write-ColorText "Searching for matching files for base name: $sourceBaseName" -color $colorVerboseMessage

    # Search for matching files in the destination folder and its subdirectories based on the base name
    Write-ColorText "Searching for matching files in destination folder..." -color $colorVerboseMessage
    $matchingDestinationFiles = Get-ChildItem -Path $destinationFolder -Filter "$sourceBaseName(*).dat" -File -Recurse -ErrorAction SilentlyContinue

    # If matching files are found in the destination folder
    if ($matchingDestinationFiles.Count -gt 0) {
        # Output verbose message indicating matching files found
        Write-ColorText "Matching files found for base name: $sourceBaseName" -color $colorVerboseMessage
        
        # Get the first matching destination file
        $destinationFile = $matchingDestinationFiles[0]

        # Extract the base name of the destination file
        $destinationBaseName = $destinationFile.BaseName
        Write-ColorText "Matching destination file found: $($destinationFile.FullName)" -color $colorDestinationFile

        # Extract the subdirectory structure from the destination file path
        $relativeDirectoryPath = $destinationFile.Directory.FullName.Replace($destinationFolder, '')

        # Construct the destination directory path for the source file
        $destinationDirectory = Join-Path -Path $destinationFolder -ChildPath $relativeDirectoryPath
        Write-ColorText "Destination directory for source file: $destinationDirectory" -color $colorDestinationFolder

        # Create the destination directory if it doesn't exist
        if (-not (Test-Path -Path $destinationDirectory -PathType Container)) {
            Write-ColorText "Creating destination directory: $destinationDirectory" -color $colorVerboseMessage
            New-Item -Path $destinationDirectory -ItemType Directory | Out-Null
        }

        # Remove the existing destination file
        Write-ColorText "Removing existing destination file: $($destinationFile.FullName)" -color $colorExistingFile
        Remove-Item -Path $destinationFile.FullName -Force
        Write-ColorText "Existing destination file removed." -color $colorExistingFile

        # Move the source file to the destination directory
        Write-ColorText "Moving source file $($sourceFile.FullName) to destination directory: $destinationDirectory" -color $colorVerboseMessage
        Move-Item -Path $sourceFile.FullName -Destination $destinationDirectory -Force
        Write-ColorText "File moved to: $destinationDirectory" -color $colorDestinationFolder

        # Set flag to indicate files were moved
        $filesMoved = $true
    }
}

# Output completion message
if ($filesMoved) {
    Write-ColorText "Replacement process completed." -color $colorCompletionMessage
} else {
    Write-ColorText "No files were moved." -color $colorCompletionMessage
}

# Pause to keep the PowerShell window open
Write-Host "Press any key to exit..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Post Reply