Parcourir la source

Seperate FixCHS script

Tobias Simetsreiter il y a 4 ans
Parent
commit
fff2c62b02
4 fichiers modifiés avec 65 ajouts et 7 suppressions
  1. 46 0
      WinImager/FixCHS.ps1
  2. 12 4
      WinImager/LibWinImager.psm1
  3. 6 3
      WinImager/WinImager.ps1
  4. 1 0
      WinImager/log/.gitignore

+ 46 - 0
WinImager/FixCHS.ps1

@@ -0,0 +1,46 @@
+
+$libpath = [System.IO.Path]::Combine($MyInvocation.MyCommand.Definition, "..", "LibWinImager.psm1")
+$logfilename = "FixCHS_"+([System.DateTime]::Now).ToFileTime()+".log"
+$logpath = [System.IO.Path]::Combine($MyInvocation.MyCommand.Definition, "..", "log", $logfilename)
+Import-Module -Name $libpath
+
+BecomeAdmin $MyInvocation
+
+Function Main()
+{
+
+    $ErrorActionPreference = "Stop"
+
+    $disk = GuiPhysDev
+    $disknum = $disk.Number
+    $diskname = $disk.FriendlyName
+    $diskserial = $disk.SerialNumber
+
+    if ((-not $disknum -is [int]) -or $disknum -eq $null -or $disknum -lt 0){
+        Write-Output "No Disk Selected"
+    } else {
+
+        $dialog = @"
+Rewrite CHS on Disk:
+
+"${diskname} ${diskserial}" 
+
+Would you like to contine?
+"@ 
+        $dialog
+        $continue = AskContinue $dialog
+
+
+        if ($continue -eq "Yes"){
+
+            FixCHS $disknum
+        }
+    }
+}
+
+try{
+    Main | Tee-Object -FilePath $logpath
+} catch {
+    Write-Error $_.Exception | Tee-Object -FilePath $logpath -Append
+    pause
+}

+ 12 - 4
WinImager/LibWinImager.psm1

@@ -15,6 +15,12 @@ Function AskContinue($text)
     [System.Windows.Forms.MessageBox]::Show($text, 'Continue','YesNo','Info')
 }
 
+Function MessageBox($text)
+{
+    [System.Windows.Forms.MessageBox]::Show($text, 'Continue','YesNo','Info')
+}
+
+
 Function WinDD($inFileName, $outFileName, $blocksize = 5Mb) {
 
     Write-Output ""
@@ -130,11 +136,11 @@ Function GuiPhysDev()
 Function GuiSelectDisk($disks){
     $labels = ($disks | foreach {$_ | GuiDiskLabel}) 
 	$dia = GuiSelectDialog $labels
-    $result = $dia.ShowDialog()
+    $result = $dia.form.ShowDialog()
 
     if ($result -eq [System.Windows.Forms.DialogResult]::OK)
     {
-        $x = $dia.Tag.SelectedIndex
+        $x = $dia.listbox.SelectedIndex
         $disks[$x]
     }
 }
@@ -180,10 +186,12 @@ Function GuiSelectDialog($items){
     }
 
     $form.Controls.Add($listBox)
-    $form.Tag = $listBox
 
     $form.Topmost = $true
-    $form
+    [PSCustomObject]@{ 
+        form = $form
+        listbox = $listBox
+    }
 }
 
 Function GuiDiskLabel(){

+ 6 - 3
WinImager/WinImager.ps1

@@ -1,5 +1,7 @@
 
 $libpath = [System.IO.Path]::Combine($MyInvocation.MyCommand.Definition, "..", "LibWinImager.psm1")
+$logfilename = "WinImager_"+([System.DateTime]::Now).ToFileTime()+".log"
+$logpath = [System.IO.Path]::Combine($MyInvocation.MyCommand.Definition, "..", "log", $logfilename)
 Import-Module -Name $libpath
 
 BecomeAdmin $MyInvocation
@@ -37,6 +39,7 @@ to Drive:
 
 Would you like to contine?
 "@ 
+			$dialog
             $continue = AskContinue $dialog
 
 
@@ -44,7 +47,6 @@ Would you like to contine?
 
                 Reset-Disk $disknum
                 WinDD $filename ("\\.\PHYSICALDRIVE{0}" -f $disknum)
-                FixCHS $disknum
             }
         }
 
@@ -55,6 +57,7 @@ Write image
 
 to another Drive?
 "@
+		$dialog
         $continue = AskContinue $dialog
 
     }
@@ -62,8 +65,8 @@ to another Drive?
 }
 
 try{
-    Main 
+    Main | Tee-Object -FilePath $logpath
 } catch {
-    Write-Error $_.Exception
+    Write-Error $_.Exception | Tee-Object -FilePath $logpath -Append
     pause
 }

+ 1 - 0
WinImager/log/.gitignore

@@ -0,0 +1 @@
+*