Mordax

Software Developer

View My GitHub Profile

Delving into Windows Powershell

During the duration of my open source releases, I found myself going back to Flashpoint and curating for fun.

Freearcade (as I mentioned in my previous post) is a site that mainly has Java applet games and those games tend to have a lot of assets.

Deciding to curate another Java applet game, I realized that it wasn’t only Wiz3 with a bunch of assets but this game as well.

Flashpoint comes with autocurator scripts (which I didn’t know at the time)but I decided to make my own using Windows PowerShell. I’ve been wanting to learn Powershell scripting after enjoying bash, and decided that as a struggling Windows developer, I should get to know the tools on this platform. So this dilemma was a good excuse.

So this is my first PowerShell script.

Issue:

Doing HTTP GET requests on multiple Flashpoint redirector 404s.



Flashpoint redirector opens with the launcher - it’s a modified Apache server that pretends to be the website the game is located on. It shows the assets it’s grabbing within the folder directory on your computer.

You can copy all 404 URLs by hitting Tools -> Copy All 404 Not Found URLs. It’s tedious to go to each URL and download files one by one.

Solution:

Make a PowerShell Script to automate it.

The Script URL

Get-Assets.ps1

<# A useful powershell script to download files off of URLs #>

# $output = whatever folder location you want the script to save the files to. 
$output = "..\..\Flashpoint Core 2.3\Games\Flash\htdocs\ww2.freearcade.com\Jetslalom.jav\"
$client = new-object System.Net.WebClient
while($select -ne 0){
    Write-Host "Select from the following options:
                        0. Exit script
                        1. Grab asset from one URL
                        2. Grab multiple assets from multiple URLs"
    $select = Read-Host -Prompt "Enter your selection"
    switch($select){
        1{
            $url = Read-Host -Prompt "Enter URL (with http included)"
            $file = Split-Path $url -Leaf
            $client.DownloadFile($url, $output + $file)
        }
        2{
            $txt = Read-Host -Prompt "Enter location of input file with the 404 URLS (if in same directory, it's .\ syntax"
            foreach($line in Get-Content $txt){
                $filename = Split-Path $line -leaf
                $client.DownloadFile($line, $output + $filename)
            }
        }
    }

    # Line 29 is optional, it's to make sure the game is reset to run the new assets
    Stop-Process -name "appletviewer" -ErrorAction SilentlyContinue
}
Write-Host "Thanks for using my tool!"

<# TODO: Allow users to specify output location - most likely manually for now
 - Maybe talk to redirector to grab 404 urls
 - Dynamically add missing folders #>

Rest of the code with some TODOs.

This script I passed on to the Discord and was happy to see that some people had cloned it on Github (through the analytics). It’s optimized for Freearcade.com java applets but I hope to expand it to become better.