# Step 1 - Download and unzip the ZIP file into a temporary folder
$zipUrl = "https://github.com/iSharingan/CTRPF-AR-CHEAT-CODES/archive/refs/heads/
master.zip"
$tempFolder = [System.IO.Path]::Combine($env:TEMP, "CTRPF-AR-CHEAT-CODES")
$zipPath = [System.IO.Path]::Combine($tempFolder, "master.zip")
# Create temporary folder
if (-not (Test-Path $tempFolder)) {
    New-Item -Path $tempFolder -ItemType Directory | Out-Null
}
# Download the ZIP file
Invoke-WebRequest -Uri $zipUrl -OutFile $zipPath
# Unzip the file into the temporary folder
Expand-Archive -Path $zipPath -DestinationPath $tempFolder -Force
# Step 2 - Access the "Cheats" folder
$cheatsFolder = [System.IO.Path]::Combine($tempFolder, "CTRPF-AR-CHEAT-CODES-
master", "Cheats")
if (-not (Test-Path $cheatsFolder)) {
    Write-Host "Error: Cheats folder not found." -ForegroundColor Red
    Exit
}
# Step 3 - Search for .txt files in the "Cheats" folder and subfolders
$txtFiles = Get-ChildItem -Path $cheatsFolder -Recurse -Filter *.txt
if (-not $txtFiles) {
    Write-Host "No .txt files were found in the Cheats folder." -ForegroundColor
Red
    Exit
}
# Step 4 - Ask the user which emulator they use to select the destination folder
$emulator = Read-Host "Choose fork:Old Citra,Lime3DS or PabloMK7's Citra."
$destinationFolder = ""
switch ($emulator.ToLower()) {
    "lime3ds" {
        $destinationFolder = "$env:USERPROFILE\AppData\Roaming\Lime3DS\cheats"
    }
    "pablomk7's citra" {
        $destinationFolder = "$env:USERPROFILE\AppData\Roaming\Citra\cheats"
    }
      "old citra" {
        $destinationFolder = "$env:USERPROFILE\AppData\Roaming\Citra\cheats"
    }
    default {
        Write-Host "Invalid emulator. Please choose 'Lime3DS' or 'PabloMK7's
Citra'" -ForegroundColor Red
        Exit
    }
}
# Check if the destination folder exists, and if not, create it
if (-not (Test-Path $destinationFolder)) {
    New-Item -Path $destinationFolder -ItemType Directory | Out-Null
}
# Confirm with the user if they want to proceed with the copy
$continueCopy = Read-Host "Do you want to continue copying the files (YES/NO)?"
if ($continueCopy.ToUpper() -eq "YES") {
    Write-Host "Start copying .txt files to the destination folder:
$destinationFolder" -ForegroundColor Yellow
    # Start copying .txt files to the destination folder
    foreach ($file in $txtFiles) {
        Copy-Item -Path $file.FullName -Destination $destinationFolder -Force
    }
    # Delete the temporary folder after completing the copy
    Remove-Item -Path $tempFolder -Recurse -Force
    # Inform the user that the copy is complete
    Write-Host "Copy completed. Press OK." -ForegroundColor Green
} else {
    Write-Host "The copy was cancelled. Press OK" -ForegroundColor Red
    # Delete the temporary folder even if the copy is canceled
    Remove-Item -Path $tempFolder -Recurse -Force
}