Skip to content

Instantly share code, notes, and snippets.

@GhostTypes
Created July 6, 2024 18:22
Show Gist options
  • Select an option

  • Save GhostTypes/f4a8fdeb4c71f8d62557d9cbef68c009 to your computer and use it in GitHub Desktop.

Select an option

Save GhostTypes/f4a8fdeb4c71f8d62557d9cbef68c009 to your computer and use it in GitHub Desktop.
Windows script to set up a micro sd for R4i-SDHC flashcarts. Installs YSMenu. Will update for more eventually, and have it auto download the multi-cart update zip.
$sdRoot = Read-Host -Prompt "Enter flashcart microsd drive letter (e.g., E:)"
$workDir = Get-Location
$cfRoot = Join-Path "$workDir" -ChildPath "RetroGameFan Multi Cart Update v7.06"
Write-Host $cfRoot
$r4iRoot = Join-Path "$cfRoot" -ChildPath "R4i-SDHC YSMenu"
$skinsRoot = Join-Path "$cfRoot" -ChildPath "YSMenu Skins"
$ttMenu = Join-Path "$r4iroot" -ChildPath "TTMenu"
$r4iDat = Join-Path "$r4iroot" -ChildPath "R4.dat"
$ttMenuDat = Join-Path "$r4iroot" -ChildPath "TTMenu.dat"
$ysMenu = Join-Path "$r4iroot" -ChildPath "YSMenu.nds"
function CheckPath {
param (
[Parameter(Mandatory=$true)]
[string]$path
)
if (-Not (Test-Path -Path $path -PathType Container)) { return $false }
return $true
}
function CheckFilePath {
param (
[Parameter(Mandatory=$true)]
[string]$path
)
if (-Not (Test-Path -Path $path -PathType Leaf)) { return $false }
return $true
}
function CheckDeps {
if (-Not (CheckPath -$cfRoot)) {
Write-Error "Missing RetroGameFan Multi Cart Update 7.06 folder"
exit
}
if (-Not (CheckPath -$r4iRoot)) {
Write-Error "RGF Multi Cart Update folder corrupt - missing R4i-SDHC YSMenu folder"
exit
}
if (-Not (CheckPath -$cfRoot)) {
Write-Error "RGF Multi Cart Update folder corrupt - Missing YSMenu Skins folder"
exit
}
}
function MakeGamesFolder {
param (
[Parameter(Mandatory=$true)]
[string]$sdRoot
)
$root = Join-Path -Path "$sdRoot" -ChildPath "Games"
if (Test-Path $root -PathType Container) {
return # games folder already exists
}
$ndsR = Join-Path -Path "$root" -ChildPath "nds"
$gbaR = Join-Path -Path "$root" -ChildPath "gba"
$gbcR = Join-Path -Path "$root" -ChildPath "gbc"
$gbR = Join-Path -Path "$root" -ChildPath "gb"
$nesR = Join-Path -Path "$root" -ChildPath "nes"
# idk what else would be 'necessary'
MakeDir -path $ndsR
MakeDir -path $gbaR
MakeDir -path $gbcR
MakeDir -path $gbR
MakeDir -path $nesR
}
function MakeDir {
param (
[Parameter(Mandatory=$true)]
[string]$path
)
New-Item -ItemType Directory $path
}
function CopyTheme {
param (
[Parameter(Mandatory=$true)]
[string]$themeName
)
$themeRoot = Join-Path "$skinsRoot" -ChildPath "$themeName"
if (-Not (Test-Path -Path $themeRoot -PathType Container)) {
Write-Error "Theme name $themeName not found at: $SourcePath"
return
}
$dest = Join-Path "$sdRoot" "TTMenu"
CopyFile -Source $themeRoot -Dest $dest
}
function CopyFolder {
param (
[Parameter(Mandatory=$true)]
[string]$Source,
[Parameter(Mandatory=$true)]
[string]$Dest
)
if (-Not (Test-Path -Path $Source -PathType Container)) {
Write-Error "Source path does not exist or is not a folder: $SourcePath"
return
}
if (-Not (Test-Path -Path $Dest -PathType Container)) {
New-Item -ItemType Directory -Path $Dest
}
try {
Copy-Item -Path $SourcePath\* -Destination $Dest -Recurse -Force
} catch {
Write-Error "Unable to copy folder from $Source to $Dest"
Write-Error "An error occurred: $_"
}
}
function CopyFile {
param (
[Parameter(Mandatory=$true)]
[string]$Source,
[Parameter(Mandatory=$true)]
[string]$Dest
)
if (-Not (Test-Path -Path $Source -PathType Leaf)) {
Write-Error "Source file does not exist: $Source"
return
}
$dest = Split-Path -Parent $Dest
if (-Not (Test-Path -Path $destinationDir -PathType Container)) {
Write-Host "Destination directory does not exist. Creating: $dest"
New-Item -ItemType Directory -Path $dest
}
try {
Copy-Item -Path $Source -Destination $Dest -Force
} catch {
Write-Error "Unable to copy item from $Source to $Dest"
Write-Error "An error occurred: $_"
}
}
function HasCurrentInstall {
$check1 = Join-Path "$sdRoot" -ChildPath "R4.dat"
$check2 = Join-Path "$sdRoot" -ChildPath "TTMenu.dat"
if (CheckFilePath -path $check1) {
return $true
}
if (CheckFilePath -path $check2) {
return $true
}
return $false
}
if (HasCurrentInstall) {
Write-Warning "Existing kernel/firmware detected on the microSD"
Write-Info "Please format your microSD card before running this script"
exit
}
#CheckDeps # make sure we have the required files
Write-Host "Installing YSMenu..."
CopyFolder -Source $ttMenu -Dest $sdRoot # copy YSMenu files
CopyFile -Source $ttMenuDat -Dest $sdRoot # copy TTMenu.dat
CopyFile -Source $r4iDat -Dest $sdRoot # copy R4.dat
CopyFile -Source $ysMenu -Dest $sdRoot # copy YSMenu.nds
Write-Host "Finalizing YSMenu install..."
MakeGamesFolder -sdRoot $sdRoot # create games folder
CopyTheme -themeName "Plain" # install the Plain theme
Write-Host "Done!"
Pause > nul
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment