Ver Fonte

add 7z sfx build

Tobias Simetsreiter há 4 anos atrás
pai
commit
9e97dedfbe

+ 7 - 0
Makefile

@@ -0,0 +1,7 @@
+
+
+build:
+	mkdir -p dist
+	rm -f dist/WinImager.7z
+	7z a dist/WinImager.7z WinImager
+	cat sfx/7zsd_All_x64.sfx  sfx/sfx_config.txt dist/WinImager.7z > dist/WinImager.exe

+ 54 - 11
WinImager/LibWinImager.psm1

@@ -5,7 +5,8 @@ Function BecomeAdmin($invocation){
     if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))  
     {  
         $arguments = "-ExecutionPolicy Bypass & '" +$invocation.mycommand.definition + "'"
-        Start-Process powershell -Verb runAs -ArgumentList $arguments
+		Hide-Console
+        Start-Process powershell -Wait -Verb runAs -ArgumentList $arguments
         Break
     }
 }
@@ -15,17 +16,17 @@ Function LogFilePath($invocation,$name){
     [System.IO.Path]::Combine($invocation.MyCommand.Definition, "..", "..","log", $logfilename)
 }
 
-Function AskContinue($text)
+Function GuiMessageBox
 {
-    [System.Windows.Forms.MessageBox]::Show($text, 'Continue','YesNo','Info')
-}
-
-Function MessageBox($text)
-{
-    [System.Windows.Forms.MessageBox]::Show($text, 'Continue','YesNo','Info')
+    param(
+        $text,
+        $title = "Continue",
+        $buttons = "YesNo",
+        $level = "Info"
+    )
+    [System.Windows.Forms.MessageBox]::Show($text, $title, $buttons, $level)
 }
 
-
 Function WinDD($inFileName, $outFileName, $bs = 5Mb, $create = $false) {
 
     Write-Output ""
@@ -130,11 +131,16 @@ y
 
 }
 
-Function GuiSaveFileName($initialDirectory = "C:\", $title = "Save Image File")
+Function GuiSaveFileName
 {  
+    param(
+        $initialDirectory = "C:\",
+        $title = "Save Image File",
+        $filter = "Images (*.img;*.afp;*.usb;*.iso)| *.img;*.afp;*.usb;*.iso"
+    )
     $SaveFileDialog = New-Object System.Windows.Forms.SaveFileDialog
     $SaveFileDialog.initialDirectory = $initialDirectory
-    $SaveFileDialog.filter = "Images (*.img;*.afp;*.usb;*.iso)| *.img;*.afp;*.usb;*.iso|All files (*.*)| *.*"
+    $SaveFileDialog.filter = $filter + "|All files (*.*)| *.*"
     $SaveFileDialog.Title = $title
     $SaveFileDialog.ShowDialog() | Out-Null
     $SaveFileDialog.filename
@@ -242,4 +248,41 @@ Function GuiDiskLabel(){
 	("{0,-3} {1,-4} {2,-22} {3,-20} {4,8} GB" -f $number,$bustype,$name,$serial,$size)
 }
 
+# .Net methods for hiding/showing the console in the background
+Add-Type -Name Window -Namespace Console -MemberDefinition '
+[DllImport("Kernel32.dll")]
+public static extern IntPtr GetConsoleWindow();
+
+[DllImport("user32.dll")]
+public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);
+'
+
+function Show-Console
+{
+    $consolePtr = [Console.Window]::GetConsoleWindow()
+
+    # Hide = 0,
+    # ShowNormal = 1,
+    # ShowMinimized = 2,
+    # ShowMaximized = 3,
+    # Maximize = 3,
+    # ShowNormalNoActivate = 4,
+    # Show = 5,
+    # Minimize = 6,
+    # ShowMinNoActivate = 7,
+    # ShowNoActivate = 8,
+    # Restore = 9,
+    # ShowDefault = 10,
+    # ForceMinimized = 11
+
+    [Console.Window]::ShowWindow($consolePtr, 4)
+}
+
+function Hide-Console
+{
+    $consolePtr = [Console.Window]::GetConsoleWindow()
+    #0 hide
+    [Console.Window]::ShowWindow($consolePtr, 0)
+}
+
 Export-ModuleMember -Function *

+ 3 - 1
WinImager/WinImager.ps1

@@ -2,7 +2,9 @@
 $libpath = [System.IO.Path]::Combine($MyInvocation.MyCommand.Definition, "..", "LibWinImager.psm1")
 Import-Module -Name $libpath
 
-$items = Get-ChildItem "bin"
+BecomeAdmin $MyInvocation
+
+$items = Get-ChildItem ([System.IO.Path]::Combine($MyInvocation.MyCommand.Definition, "..","bin"))
 $items
 ""
 $dia = GuiSelectDialog ($items|foreach {$_.Name}) -Title "Select Command" -Label "Select Command"

+ 1 - 1
WinImager/bin/DiskToImage.ps1

@@ -40,7 +40,7 @@ to File:
 Would you like to contine?
 "@ 
         $dialog
-        $continue = AskContinue $dialog
+        $continue = GuiMessageBox $dialog
 
 
         if ($continue -eq "Yes"){

+ 1 - 1
WinImager/bin/FixCHS.ps1

@@ -31,7 +31,7 @@ Rewrite CHS on Disk:
 Would you like to contine?
 "@ 
         $dialog
-        $continue = AskContinue $dialog
+        $continue = GuiMessageBox $dialog
 
 
         if ($continue -eq "Yes"){

+ 1 - 1
WinImager/bin/ImageToDisk.ps1

@@ -46,7 +46,7 @@ to Drive:
 Would you like to contine?
 "@ 
 			$dialog
-            $continue = AskContinue $dialog
+            $continue = GuiMessageBox $dialog
 
 
             if ($continue -eq "Yes"){

+ 53 - 0
WinImager/bin/ImageToVDI.ps1

@@ -0,0 +1,53 @@
+
+$libpath = [System.IO.Path]::Combine($MyInvocation.MyCommand.Definition, "..", "..", "LibWinImager.psm1")
+
+Import-Module -Name $libpath
+
+$logpath = LogFilePath $MyInvocation "ImageToVDI"
+
+Function Main()
+{
+    if ($env:VBOX_INSTALL_PATH -ne $null){
+        $VBOXMANAGE = $env:VBOX_INSTALL_PATH + "VBoxManage.exe"
+    } elseif ($env:VBOX_MSI_INSTALL_PATH -ne $null){
+        $VBOXMANAGE = $env:VBOX_MSI_INSTALL_PATH + "VBoxManage.exe"
+    } else {
+        "Virtualbox install Path not found!"
+        Break
+    }
+    
+    "Select Image File..."
+    
+    $filename = GuiOpenFileName
+
+    if (($filename -eq $null) -or ($filename -eq "")){
+        "No Image Selected"
+        Break
+    }
+
+    "Select VDI File..."
+    $vdiname = GuiSaveFileName -filter "Virtualbox Images (*.vdi)| *.vdi"
+
+    if (($vdiname -eq $null) -or ($vdiname -eq "")){
+        "No Target Selected"
+        Break
+    }
+
+    if (Test-Path $vdiname -PathType Leaf) {
+        Remove-Item $vdiname
+    }
+
+    &$VBOXMANAGE convertfromraw $filename $vdiname --format VDI
+    GuiMessageBox "OK" -Buttons "Ok"
+    pause
+    Break
+}
+
+Main
+
+try{
+    Main | Tee-Object -FilePath $logpath
+} catch {
+    Write-Error $_.Exception | Tee-Object -FilePath $logpath -Append
+    pause
+}

BIN
WinImager/mingw/fdisk.exe


BIN
WinImager/mingw/sfdisk.exe


BIN
sfx/7zsd_All_x64.sfx


+ 4 - 0
sfx/sfx_config.txt

@@ -0,0 +1,4 @@
+;!@Install@!UTF-8!
+Title="WinImager"
+RunProgram="powershell.exe -ExecutionPolicy Bypass %%T\WinImager\WinImager.ps1"
+;!@InstallEnd@!