Advertisement
mikeisfly

RetroArch Update Script

Sep 6th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2.  
  3. Arthor : Michael Gates
  4. Date : 6 September 2017
  5.  
  6. This script will automate the upgrading of RetroArch. It Requires Winrar to be installed in your c:\program files folder and the name of the upgraded file to be named retroarch.7z
  7.  
  8. Syntax .\"RetroArch Upgrade v2.ps1" c:\arcade\retroarch retroarch.7z
  9.  
  10. If no arguments are given then the default values in the Parameter block will be used. You can change these to fit your needs
  11.  
  12. This script is free to use and I take no responsibility for any damage this may cause to your system or your RetroARch installation. Remember to alway make a back up before using this.
  13.  
  14. Credit goes to:
  15.  
  16. https://adamstech.wordpress.com/2011/05/12/how-to-properly-pause-a-powershell-script/ (I borrowed the pause function)
  17. https://stackoverflow.com/questions/11412617/get-a-folder-path-from-the-explorer-menu-to-a-powershell-variable (Helped me use explorer instead of commandline)
  18. http://www.powershellmagazine.com/2013/06/28/pstip-using-the-system-windows-forms-folderbrowserdialog-class/ (Helped with picking selected path)
  19. http://www.powershellmagazine.com/2013/07/01/pstip-using-the-system-windows-forms-openfiledialog-class/ (Helped with filtering file input)
  20. https://stackoverflow.com/questions/32014711/how-do-you-call-windows-explorer-with-a-file-selected-from-powershell (Helped with selecting the file in file explorer)
  21. #>
  22.  
  23.  
  24. Param #Change value here to set the default value if not specified at command line
  25.     (
  26.         [String]$RetroArchPath = '',
  27.         [String]$RetroArchUpgradeFile = ''
  28.        
  29.                
  30.     )
  31.    
  32. Function Get-Path
  33.         {
  34.             $Path = pwd
  35.             $Path = $Path.path
  36.             Return $Path
  37.         }
  38.  
  39. Function SelectFolder ($RootFolder, $Description)
  40.     {
  41.         Add-Type -AssemblyName System.Windows.Forms
  42.         $FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog -Property @{SelectedPath = $RootFolder}
  43.  
  44.         $FolderBrowser.Description = $Description
  45.        
  46.         [void]$FolderBrowser.ShowDialog()
  47.         Return $FolderBrowser.SelectedPath
  48.     }
  49.    
  50. Function SelectFile ($RootFolder, $Description)
  51.     {
  52.         Add-Type -AssemblyName System.Windows.Forms
  53.         $File = New-Object System.Windows.Forms.OpenFileDialog -Property @{Filter = 'RetroArch Upgrade File (*.7z)|*.7z|All Files (*.*)|*.*'}
  54.         $File.InitialDirectory = $RootFolder
  55.         $File.Title = $Description
  56.         [void]$File.ShowDialog()
  57.         Return $File.FileName
  58.     }
  59.  
  60. Function Pause ($Message1, $Message2)
  61.  
  62.     {
  63.        # If ($psISE)
  64.         #{
  65.             # The "ReadKey" functionality is not supported in Windows PowerShell ISE.
  66.             $Shell = New-Object -ComObject "WScript.Shell"
  67.             $Button = $Shell.Popup($Message1, 0, $Message2, 0)
  68.             Return
  69.         #}
  70.     }
  71.  
  72. #Function Pause ($message)
  73. #   {
  74. #       Write-Host $Message
  75. #       $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
  76. #   }
  77.    
  78. Function Check-Path ($PathString)
  79.     {
  80.         $x = ( !( $PathString[-1] -eq "\" ) )
  81.         IF ( $x ) { $PathString = $PathString + "\" }
  82.         Return $PathString
  83.     }
  84.                
  85. Function Main()
  86.     {
  87.        
  88.         $Assets = "assets", "autoconfig", "config", "filters", "overlays", "saves", "shaders", "states", "system", "cores", "retroarch.cfg", "retroarch.default.cfg", "retroarch-core-options.cfg"
  89.         $RootFolder = Get-Path
  90.  
  91.         If ($RetroArchPath -eq "")
  92.             {
  93.                
  94.                 $RetroArchPath = SelectFolder $RootFolder "Where is your RetroArch Installed?"
  95.                                            
  96.             }
  97.  
  98.         If ($RetroArchUpgradeFile -eq "")
  99.             {
  100.                 $RetroArchUpgradeFile = SelectFile $RootFolder "Select the File that contains your RetroArch Upgrade."
  101.             }
  102.    
  103.         $RetroArchPath = Check-Path $RetroArchPath
  104.        
  105.         If (!(Test-Path TmpUpgrade))
  106.             {
  107.                 New-Item -ItemType Directory TmpUpgrade | Out-Null
  108.             }
  109.         ForEach ($Item in $Assets)
  110.             {
  111.                 $TestCase = $RetroArchPath + $Item
  112.                 If (Test-Path $TestCase)
  113.                     {
  114.                         Copy-Item $TestCase TmpUpgrade -Force
  115.                     }
  116.             }
  117.            
  118.         $WinRAR = '"c:\program files\winrar\winrar.exe"'
  119.         $WinRARTmpDir = '\RetoArchNewTmp'
  120.          
  121.        
  122.         & WinRAR x -y -r $RetroArchUpgradeFile  *.* $RetroArchPath | Out-Null
  123.        
  124.         ForEach ($Item in $Assets)
  125.             {
  126.                 If (Test-Path TmpUpgrade\$Item)
  127.                     {
  128.                         Copy-Item TmpUpgrade\$Item $RetroArchPath -Force
  129.                         Remove-Item TmpUpgrade\$Item -Force -Recurse
  130.                        
  131.                     }
  132.             }
  133.        
  134.         Remove-Item TmpUpgrade
  135.         Pause "Press OK to terminate" "Completed!"
  136.        
  137.     }
  138.    
  139. Main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement