From 3e24dcf0bfecb26b048f88bcabbf82f5724bc3c3 Mon Sep 17 00:00:00 2001 From: Blank517 Date: Mon, 20 May 2019 02:09:19 +0200 Subject: [PATCH 1/2] Fix miiShop_Install.ps1 Fixed "Get-ChildItem: Access to the path is denied." Users are now forced to choose a directory Code cleanup --- miiShop_Install.ps1 | 70 ++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/miiShop_Install.ps1 b/miiShop_Install.ps1 index f01754e..1475857 100644 --- a/miiShop_Install.ps1 +++ b/miiShop_Install.ps1 @@ -5,15 +5,15 @@ function get-latestmiiShop ([String] $question,[String] $installType) Write-Output $question # Download Engarak/MiiShop release from github $repo = "Engarak/MiiShop" - if($installType.ToUpper() -eq 'UPGRADE') - { - $file = "miiShop_upgrade-0_2_x-0_2_7.zip" - $uoriDir = Get-Folder -displayMesage 'Where are the .cia files located?' + If ($installType.ToUpper() -eq 'UPGRADE') + { + $file = "miiShop_upgrade-0_2_x-0_2_7.zip" + $uoriDir = Get-Folder -displayMesage $question } - else + Else { $file = "miiShop_install-0_2_7.zip" - $uoriDir = Get-Folder -displayMesage 'Where is the miiShop.ps1 file located?' + $uoriDir = Get-Folder -displayMesage $question } $releases = "https://api.github.com/repos/$repo/releases" @@ -35,16 +35,10 @@ function get-latestmiiShop ([String] $question,[String] $installType) Expand-Archive -path $zip -DestinationPath $uoriDir -Force # Cleaning up target dir - Remove-Item $name -Recurse -Force -ErrorAction SilentlyContinue - - # Moving from temp dir to target dir - Write-Output 'Upgrading/installing...' - $folder = $zip.Replace('.zip','') - Get-ChildItem -Path $folder -Recurse | Move-Item -Destination $uoriDir -Force + Remove-Item $name -Recurse -Force -ErrorAction SilentlyContinue # Removing temp files Remove-Item $zip -Force - Remove-Item $folder -Recurse -Force $filePath="$uoriDir\start.bat" cd $uoriDir #$file = Get-ChildItem "$uoriDir\database\settings.csv" #for future upgrades force the settings file to get updated to force a rebuild @@ -56,22 +50,40 @@ function get-latestmiiShop ([String] $question,[String] $installType) Function Get-Folder ([string]$displayMesage) { - $initialDirectory=$env:HOMEDRIVE - [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")|Out-Null + Add-Type -AssemblyName System.Windows.Forms | Out-Null + + $initialDirectory = $env:HOMEDRIVE $foldername = New-Object System.Windows.Forms.FolderBrowserDialog $foldername.Description = $displayMesage $foldername.rootfolder = "MyComputer" - if($foldername.ShowDialog() -eq "OK") + $ButtonType = [System.Windows.Forms.MessageBoxButtons]::RetryCancel + $MessageIcon = [System.Windows.Forms.MessageBoxIcon]::Error + $MessageBody = "You must select a folder" + $MessageTitle = "Error" + + Do { - $folder += $foldername.SelectedPath - } - return $folder + If($foldername.ShowDialog() -eq "OK") + { + $folder += $foldername.SelectedPath + return $folder + } + Else + { + $result = [System.Windows.Forms.MessageBox]::Show($MessageBody, $MessageTitle, $ButtonType, $MessageIcon) + + If ($result -eq "Cancel") + { + Exit 1 + } + } + } While (True) } #get a start date, formatted for files $dateFormat = 'M-d-y-hh_mm_ss' -$date=(get-date).ToString($dateFormat) +$date = (get-date).ToString($dateFormat) #Start Transcript logging for what the window says Start-Transcript -Path ('{0}\logs\MiiShopInstall_{1}.log' -f $PSScriptRoot, $date) @@ -87,15 +99,15 @@ $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no) $result = $host.ui.PromptForChoice($title, $message, $Options, 0) Switch ($result) - { - 0 { - get-latestmiiShop -question 'Where is the miiShop.ps1 file located?' - } - 1 { - get-latestmiiShop -question 'Where are your 3DS games (.cia files) located?' - } - - } +{ + 0 { + get-latestmiiShop -question 'Where is the miiShop.ps1 file located?' + } + + 1 { + get-latestmiiShop -question 'Where are your 3DS games (.cia files) located?' + } +} Stop-Transcript # SIG # Begin signature block From 26cd368766074be7ddb9690c4c2e1ac8c1e2783c Mon Sep 17 00:00:00 2001 From: Blank517 Date: Mon, 20 May 2019 08:40:37 +0200 Subject: [PATCH 2/2] Minor improvements Replaced double quotes with single quotes where string formatting is not needed. Code cleanup. --- miiShop_Install.ps1 | 46 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/miiShop_Install.ps1 b/miiShop_Install.ps1 index 1475857..b27c00b 100644 --- a/miiShop_Install.ps1 +++ b/miiShop_Install.ps1 @@ -4,15 +4,15 @@ function get-latestmiiShop ([String] $question,[String] $installType) { Write-Output $question # Download Engarak/MiiShop release from github - $repo = "Engarak/MiiShop" + $repo = 'Engarak/MiiShop' If ($installType.ToUpper() -eq 'UPGRADE') { - $file = "miiShop_upgrade-0_2_x-0_2_7.zip" + $file = 'miiShop_upgrade-0_2_x-0_2_7.zip' $uoriDir = Get-Folder -displayMesage $question } Else { - $file = "miiShop_install-0_2_7.zip" + $file = 'miiShop_install-0_2_7.zip' $uoriDir = Get-Folder -displayMesage $question } @@ -28,10 +28,9 @@ function get-latestmiiShop ([String] $question,[String] $installType) Write-Output 'Dowloading latest release' - [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 Invoke-WebRequest $download -Out $zip - Write-Output 'Extracting release files' + Write-Output 'Upgrading/Installing...' Expand-Archive -path $zip -DestinationPath $uoriDir -Force # Cleaning up target dir @@ -39,12 +38,14 @@ function get-latestmiiShop ([String] $question,[String] $installType) # Removing temp files Remove-Item $zip -Force - $filePath="$uoriDir\start.bat" - cd $uoriDir + #$file = Get-ChildItem "$uoriDir\database\settings.csv" #for future upgrades force the settings file to get updated to force a rebuild #$file.LastWriteTime = Get-Date - Write-Output 'Upgrade/install completed, launching miiShop' + Write-Output 'Upgrade/Install completed, launching miiShop' + $filePath = "$uoriDir\start.bat" + Stop-Transcript + Invoke-Expression $filePath } @@ -55,30 +56,29 @@ Function Get-Folder ([string]$displayMesage) $initialDirectory = $env:HOMEDRIVE $foldername = New-Object System.Windows.Forms.FolderBrowserDialog $foldername.Description = $displayMesage - $foldername.rootfolder = "MyComputer" + $foldername.rootfolder = 'MyComputer' $ButtonType = [System.Windows.Forms.MessageBoxButtons]::RetryCancel $MessageIcon = [System.Windows.Forms.MessageBoxIcon]::Error - $MessageBody = "You must select a folder" - $MessageTitle = "Error" + $MessageBody = 'You must select a folder' + $MessageTitle = 'Error' Do { - If($foldername.ShowDialog() -eq "OK") + If($foldername.ShowDialog() -eq 'OK') { - $folder += $foldername.SelectedPath - return $folder + return $foldername.SelectedPath } Else { $result = [System.Windows.Forms.MessageBox]::Show($MessageBody, $MessageTitle, $ButtonType, $MessageIcon) - If ($result -eq "Cancel") + If ($result -eq 'Cancel') { Exit 1 } } - } While (True) + } While ($true) } #get a start date, formatted for files @@ -86,13 +86,13 @@ $dateFormat = 'M-d-y-hh_mm_ss' $date = (get-date).ToString($dateFormat) #Start Transcript logging for what the window says -Start-Transcript -Path ('{0}\logs\MiiShopInstall_{1}.log' -f $PSScriptRoot, $date) +Start-Transcript -Path ('{0}\logs\MiiShopInstall_{1}.log' -f $PSScriptRoot, $date) -$title = "Install or Upgrade" -$message = "Is this an Install or Upgrade?" +$title = 'Install or Upgrade' +$message = 'Is this an Install or Upgrade?' -$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Upgrade", "Upgrade" -$no = New-Object System.Management.Automation.Host.ChoiceDescription "&Install", "Install" +$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Upgrade", 'Upgrade' +$no = New-Object System.Management.Automation.Host.ChoiceDescription "&Install", 'Install' $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no) @@ -100,11 +100,11 @@ $result = $host.ui.PromptForChoice($title, $message, $Options, 0) Switch ($result) { - 0 { + 0 { get-latestmiiShop -question 'Where is the miiShop.ps1 file located?' } - 1 { + 1 { get-latestmiiShop -question 'Where are your 3DS games (.cia files) located?' } }