|
|
@@ -1,5 +1,5 @@
|
|
|
|
|
|
-[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
|
|
|
+Add-Type -AssemblyName "System.Windows.Forms"
|
|
|
|
|
|
Function BecomeAdmin($invocation){
|
|
|
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
|
|
|
@@ -21,33 +21,46 @@ Function MessageBox($text)
|
|
|
}
|
|
|
|
|
|
|
|
|
-Function WinDD($inFileName, $outFileName, $blocksize = 5Mb) {
|
|
|
+Function WinDD($inFileName, $outFileName, $bs = 5Mb, $create = $false) {
|
|
|
|
|
|
Write-Output ""
|
|
|
Write-Output "" "Copy $inFileName to $outFileName with blocksize: $blocksize...."
|
|
|
- $block = [System.Byte[]]::CreateInstance([System.Byte], $blocksize)
|
|
|
+
|
|
|
+ $blocksize = $bs
|
|
|
+ $block = [System.Byte[]]::CreateInstance([System.Byte], $bs)
|
|
|
|
|
|
try{
|
|
|
$inFile = [System.IO.File]::Open($inFileName, [System.IO.FileMode]::Open)
|
|
|
- $outFile = [System.IO.File]::Open($outFileName, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Write)
|
|
|
+
|
|
|
+ if ($inFile.Length -eq $null){
|
|
|
+
|
|
|
+ $inFileLength = (get-disk |
|
|
|
+ Where { ("\\.\PHYSICALDRIVE{0}" -f $_.Number) -eq $inFileName }).Size
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ $inFileLength = $inFile.Length
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($create){
|
|
|
+ $filemode = [System.IO.FileMode]::OpenOrCreate
|
|
|
+ } else {
|
|
|
+ $filemode = [System.IO.FileMode]::Open
|
|
|
+ }
|
|
|
+
|
|
|
+ $outFile = [System.IO.File]::Open($outFileName, $filemode, [System.IO.FileAccess]::Write)
|
|
|
$outFile.Seek(0,0) | Out-Null
|
|
|
$inFile.Seek(0,0) | Out-Null
|
|
|
|
|
|
- $max = [math]::Round($inFile.Length/1Mb)
|
|
|
+ $max = [math]::Round($inFileLength/1Mb)
|
|
|
$starttime = [System.DateTime]::Now
|
|
|
- while ($outFile.Position -lt $inFile.Length){
|
|
|
-
|
|
|
- $remains = ($inFile.Length - $outFile.Position)
|
|
|
-
|
|
|
- if($remains -lt $blocksize){
|
|
|
- $blocksize = $remains
|
|
|
- $block = [System.Byte[]]::CreateInstance([System.Byte], $blocksize)
|
|
|
- }
|
|
|
+ while ($blocksize -gt 0){
|
|
|
|
|
|
- $inFile.Read( $block, 0, $blocksize) | Out-Null
|
|
|
+ $blocksize = $inFile.Read( $block, 0, $bs)
|
|
|
$outFile.Write( $block , 0, $blocksize) | Out-Null
|
|
|
|
|
|
- $percent = [math]::Min(100,[math]::Round(100 * $outFile.Position / $inFile.Length, 1))
|
|
|
+ $percent = [math]::Min(100,[math]::Round(100 * $outFile.Position / $inFileLength, 1))
|
|
|
$done = [math]::Round($outFile.Position/1Mb)
|
|
|
$speed = [math]::Round($done / ([System.DateTime]::Now - $startTime).TotalSeconds, 2)
|
|
|
$status = "{0,5}% {1,6}/{2} Mb {3} Mbps " -f ($percent,$done,$max,$speed)
|
|
|
@@ -69,7 +82,6 @@ Function WinDD($inFileName, $outFileName, $blocksize = 5Mb) {
|
|
|
try {
|
|
|
$outFile.Close()
|
|
|
} catch {
|
|
|
- $_.Exception
|
|
|
}
|
|
|
if ($ex -ne $null){throw $ex}
|
|
|
}
|
|
|
@@ -113,7 +125,17 @@ y
|
|
|
|
|
|
}
|
|
|
|
|
|
-Function GuiFileName($initialDirectory = "C:\", $title = "Select File")
|
|
|
+Function GuiSaveFileName($initialDirectory = "C:\", $title = "Save Image File")
|
|
|
+{
|
|
|
+ $SaveFileDialog = New-Object System.Windows.Forms.SaveFileDialog
|
|
|
+ $SaveFileDialog.initialDirectory = $initialDirectory
|
|
|
+ $SaveFileDialog.filter = "Images (*.img;*.afp;*.usb;*.iso)| *.img;*.afp;*.usb;*.iso|All files (*.*)| *.*"
|
|
|
+ $SaveFileDialog.Title = $title
|
|
|
+ $SaveFileDialog.ShowDialog() | Out-Null
|
|
|
+ $SaveFileDialog.filename
|
|
|
+}
|
|
|
+
|
|
|
+Function GuiOpenFileName($initialDirectory = "C:\", $title = "Select Image File")
|
|
|
{
|
|
|
|
|
|
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
|
|
|
@@ -122,7 +144,7 @@ Function GuiFileName($initialDirectory = "C:\", $title = "Select File")
|
|
|
$OpenFileDialog.Title = $title
|
|
|
$OpenFileDialog.ShowDialog() | Out-Null
|
|
|
$OpenFileDialog.filename
|
|
|
-} #end function Get-FileName
|
|
|
+}
|
|
|
|
|
|
Function GuiPhysDev()
|
|
|
{
|