Advertisement
metalx1000

Get and Play SNES

Jul 6th, 2014
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. Gets and Runs Super Nintendo ROMS
  3. PowerShell -ExecutionPolicy Bypass .\play_snes.ps1
  4. #>
  5. function Main(){
  6.     Add-Type -AssemblyName presentationCore
  7.     $mediaPlayer = New-Object system.windows.media.mediaplayer
  8.     $music = "http://www.florian-rappl.de/html5/projects/SuperMario/audio/menu.mp3"
  9.     $mediaPlayer.open($music)
  10.     $mediaPlayer.Play()
  11.    
  12.     $folder = "snes"
  13.     $storageDir = "$pwd"
  14.     $file = "snes.zip"
  15.     $url = "https://dl.dropbox.com/s/cxsa8h7qdh26yo9/snes.zip"
  16.     #$roms_url = "https://dl.dropbox.com/s/cxsa8h7qdh26yo9/snes.zip"
  17.     $roms_url = "https://dl.dropbox.com/s/4r2c86chb1yc8ja/snes_roms.zip"
  18.     $roms_zip = "snes_roms.zip"
  19.  
  20.     cls
  21.     Write-Output "Welcome!!!"
  22.     Start-Sleep -seconds 2
  23.    
  24.     function DownloadFile($url, $targetFile)
  25.    
  26.     {
  27.    
  28.        $uri = New-Object "System.Uri" "$url"
  29.    
  30.        $request = [System.Net.HttpWebRequest]::Create($uri)
  31.    
  32.        $request.set_Timeout(15000) #15 second timeout
  33.    
  34.        $response = $request.GetResponse()
  35.    
  36.        $totalLength = [System.Math]::Floor($response.get_ContentLength()/1024)
  37.    
  38.        $responseStream = $response.GetResponseStream()
  39.    
  40.        $targetStream = New-Object -TypeName System.IO.FileStream -ArgumentList $targetFile, Create
  41.    
  42.        $buffer = new-object byte[] 10KB
  43.    
  44.        $count = $responseStream.Read($buffer,0,$buffer.length)
  45.    
  46.        $downloadedBytes = $count
  47.    
  48.        while ($count -gt 0)
  49.    
  50.        {
  51.    
  52.            $targetStream.Write($buffer, 0, $count)
  53.    
  54.            $count = $responseStream.Read($buffer,0,$buffer.length)
  55.    
  56.            $downloadedBytes = $downloadedBytes + $count
  57.    
  58.            Write-Progress -activity "Downloading file '$($url.split('/') | Select -Last 1)'" -status "Downloaded ($([System.Math]::Floor($downloadedBytes/1024))K of $($totalLength)K): " -PercentComplete ((([System.Math]::Floor($downloadedBytes/1024)) / $totalLength)  * 100)
  59.    
  60.        }
  61.    
  62.        #Write-Progress -activity "Finished downloading file '$($url.split('/') | Select -Last 1)'"
  63.    
  64.        $targetStream.Flush()
  65.    
  66.        $targetStream.Close()
  67.    
  68.        $targetStream.Dispose()
  69.    
  70.        $responseStream.Dispose()
  71.    
  72.     }
  73.    
  74.    
  75.     if(!(Test-Path -Path $folder )){
  76.         Write-Output "Downloading Emulator for Windows..."
  77.         Start-Sleep -seconds 2
  78.    
  79.         DownloadFile $url $file
  80.    
  81.         Write-Output "Unzipping Emulator for Windows"
  82.         Start-Sleep -seconds 2
  83.        
  84.         $shell = new-object -com shell.application
  85.         $zip = $shell.NameSpace("$file")
  86.    
  87.         foreach($item in $zip.items())
  88.         {
  89.             $shell.Namespace("$storageDir\").copyhere($item)
  90.         }
  91.         Remove-Item $file -Force -Recurse
  92.     }else{
  93.         Write-Output "Emulator Already Installed";
  94.         Start-Sleep -seconds 2
  95.     }
  96.    
  97.    
  98.  
  99.  
  100.     $rom = "roms\Super Mario World (U) [!].smc"
  101.    
  102.     $mediaPlayer.Stop()
  103.    
  104.     $get_roms = Read-Host 'Emulator is ready. Would you like to get roms? (y/N)'
  105.    
  106.     if(($get_roms -eq "Y" )){
  107.         cls
  108.         Write-Output "Player some Mario World While I download a bunch of ROMS"
  109.         Write-Output "By 'a bunch', I mean all of them."
  110.         Start-Sleep -seconds 2
  111.    
  112.         #cd $pwd\$folder
  113.         cmd /c start $pwd\$folder\zsnesw.exe $pwd\$folder\$rom
  114.  
  115.         DownloadFile $roms_url $roms_zip
  116.         $zip = $shell.NameSpace("$roms_zip")
  117.        
  118.        
  119.         foreach($item in $zip.items())
  120.         {
  121.                 $shell.Namespace("$pwd\$folder\").copyhere($item)
  122.         }
  123.         write-output "Removing $roms_zip"
  124.         Remove-Item $roms_zip -Force -Recurse
  125.      
  126.     }else{
  127.         #cd $pwd\$folder
  128.         cmd /c start $pwd\$folder\zsnesw.exe $rom        
  129.     }
  130.    
  131.    
  132.     $del = Read-Host 'Do you want to remove the emulator and roms? (y/N)'
  133.    
  134.     if(($del -eq "Y" )){
  135.         Write-Output "Removing Emulator and ROMS"
  136.         Remove-Item $folder -Force -Recurse
  137.     }
  138.    
  139.     write-output "Thank you for playing"
  140. }
  141.  
  142. Main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement