No-Intro Love Pack PowerShell Clean-Up Script

General No-Intro related discussions.
Post Reply
Pr3tty F1y
Posts: 60
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.

*********************************************************************************************************************************
2024-08-08 UPDATE:
- Script has been updated to include support for "Aftermarket" dats
- Script now notifies you if you have older revisions of dats (i.e., if you have two dats from the same system but different timestamps, it will flag the older timestamp so you can manually remove the old dat)

*********************************************************************************************************************************
2024-08-14 EXPERIMENTAL UPDATE:
- Script now has the option to merge Aftermarket and Standard dats into a single dat (i.e., reverting to the same way they were handled prior to the split of separate Aftermarket and Standard dats).
- So why would this be better? Well, if you don't mind more files in a single ROM directory, less dats are easier to manage. Also, if you manually are downloading individual dats and checking [X] Machine Life Span and [X] Aftermarket, the DoM will produce a zipped dat file named like the standard dat, so this new option in the script essentially makes the Love Pack data compatible with individually downloaded dats.
*********************************************************************************************************************************
2024-10-31 UPDATE:
- Prior changes to merge aftermarket + standard dats into a single dat remain. It's probably no longer experimental. It's been working well for me for months at this point
- Apparently the No-Intro Love Pack zips have been updated to include dats that are numbered with a # rather than using a yyyy-MM-dd format. This update will now only look for dats with dates in the name and no longer crash out when a dat is found with no date in the name
You do not have the required permissions to view the files attached to this post.
Last edited by Pr3tty F1y on 31 Oct 2024 21:39, edited 3 times in total.
Pr3tty F1y
Posts: 60
Joined: 19 Jul 2014 21:24

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

Post by Pr3tty F1y »

See original post for new versions
Last edited by Pr3tty F1y on 08 Aug 2024 23:31, edited 1 time in total.
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 backtracking the arrays, but its rather complex). I decided I needed a simple way to search and replace the DAT files generated by his script in my 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. I added a functions to find the latest "No-Intro Love Pack" created by Pr3tty F1y's code in the current directory.
So what this script does is check the files in the source folder ("No-Intro Love Pack") that is extracted by Pr3tty F1y's script and compares those to the destination folder (DATroot). It deletes any older DAT file in the destination, and moves the new DAT file there. This supports 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/visually debug the script.

file: replace_DATs.ps1

Code: Select all

# Specify  destination folder
$destinationFolder = "F:\EMU\managers\RomVault\ROMVault\DatRoot"


# Find the latest folder named "No-Intro Love Pack"
$latestDate = $null
$latestFolder = $null

# Iterate through each folder in the current directory
Get-ChildItem -Path $PWD -Directory | ForEach-Object {
    $folderName = $_.Name
    # Check if the folder name matches the pattern "No-Intro Love Pack (yyyy-mm-dd)"
    if ($folderName -match "^No-Intro Love Pack \((\d{4}-\d{2}-\d{2})\)$") {
        $folderDate = [datetime]::ParseExact($matches[1], 'yyyy-MM-dd', $null)
        # Check if this folder's date is later than the current latest date
        if (-not $latestDate -or $folderDate -gt $latestDate) {
            $latestDate = $folderDate
            $latestFolder = $_
        }
    }
}
# Check if a valid folder is found
if ($latestFolder) {
    $sourceFolder = $latestFolder.FullName
} else {
    Write-Host "Error: No valid source folder found."
 # Pause to keep the PowerShell window open
Write-Host "Press any key to exit..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
exit
}

# Define colors for output using ConsoleColor enumeration
$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
}

# 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

    # 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]
        Write-ColorText "Matching destination file: $($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


        # 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")

So now I can run No-Intro Love Pack Clean-Up.ps1 to extract all the latest DAT files, and after that run my replace_DATs.ps1 to automagically move all new DAT files to their corresponding location in my DATroot, removing any older DAT files. No more manual labor. YaY. :lol:
Pr3tty F1y
Posts: 60
Joined: 19 Jul 2014 21:24

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

Post by Pr3tty F1y »

New revision added in main post. Any/all modifications are the script are fine by me. It's not programmed very well :lol:
Pr3tty F1y
Posts: 60
Joined: 19 Jul 2014 21:24

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

Post by Pr3tty F1y »

New revision in main post to add ability to merge separate aftermarket and standard dats from the Love Pack.
User avatar
against03
Posts: 26
Joined: 30 Dec 2015 17:37

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

Post by against03 »

Hi, i use use romvault and get this error. What should i do?

2024-10-14_173420.jpg
2024-10-14_173229.jpg

greets
You do not have the required permissions to view the files attached to this post.
Pr3tty F1y
Posts: 60
Joined: 19 Jul 2014 21:24

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

Post by Pr3tty F1y »

against03 wrote: 14 Oct 2024 16:35 Hi, i use use romvault and get this error. What should i do?


2024-10-14_173420.jpg

2024-10-14_173229.jpg


greets
I only use CLRMamePro, but this is what my dat dir looks like with the various No-Intro dats:
Image

And this is where I have that corresponding directory setup in the *.ps1 file:
Image

From the error, I'm guessing it just isn't finding any of the No-Intro dats. Now, if RomVault does something weird like converting No-Intro dats into it's own storage format/database file/etc. - then this script may not work. But it should pick up on the *.dat files as long as you have it pointed to the directory that holds those files.
Last edited by Pr3tty F1y on 17 Oct 2024 00:10, edited 1 time in total.
Pr3tty F1y
Posts: 60
Joined: 19 Jul 2014 21:24

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

Post by Pr3tty F1y »

New revision in main post to deal with dats that are numbered with # and don't have a yyyy-MM-dd date in the filename.
Post Reply