Browse Source

update to lib

Tobias Simetsreiter 3 years ago
parent
commit
9cb0f84630

+ 29 - 0
WinImager/bin/VBOX_Attach_RAW.ps1

@@ -0,0 +1,29 @@
+
+Import-Module -Name $env:PSLIB
+
+$PSCommandPath
+BecomeAdmin $PSCommandPath
+
+Function Main()
+{
+    if ($null -eq $Lib.VBox.VBOXMANAGE){
+        $Lib.VBox.NotFound
+        Return
+    }
+
+    "Select Disk..."
+    $disk = GuiPhysDev
+    if ((-not $disk.Number -is [int]) -or ($null -eq $disk.Number) -or $disk.Number -lt 0){
+        Write-Output "No Disk Selected"
+    } else {
+        $devicefile = ("$env:temp\VirtualBox_physicaldrive{0}.vmdk" -f $disk.Number)
+        $device = ("\\.\PHYSICALDRIVE{0}" -f $disk.Number)
+        "Creating Physical drive file:"
+        $devicefile
+        $device
+        &$Lib.VBox.VBOXMANAGE internalcommands createrawvmdk -filename $devicefile -rawdisk $device
+        # &$VBOXMANAGE modifymedium disk $devicefile --setlocation $devicefile
+    }
+}
+
+Main

+ 5 - 4
WinImager/bin/VBOX_ImageToVDI.ps1

@@ -3,8 +3,9 @@ $Lib = Import-Module -AsCustomObject -Name $env:PSLIB
 
 Function Main()
 {
-    if ($Lib.VBox.VBOXMANAGE -eq $null){
-        "Virtualbox install Path not found!"
+    $Lib.VBox
+    if ($null -eq $Lib.VBox.VBOXMANAGE){
+        $Lib.VBox.NotFound
         Return
     }
     
@@ -12,7 +13,7 @@ Function Main()
     
     $infilename = $Lib.GuiOpenFileName()
 
-    if (($infilename -eq $null) -or ($infilename -eq "")){
+    if (($null -eq $infilename) -or ($infilename -eq "")){
         "No source file elected"
         Return
     }
@@ -20,7 +21,7 @@ Function Main()
     "Select VDI File..."
     $outfilename = $Lib.GuiSaveFileName("Output Virtualbox Image","Virtualbox Images (*.vdi)| *.vdi", [io.path]::GetDirectoryName($infilename))
 
-    if (($outfilename -eq $null) -or ($outfilename -eq "")){
+    if (($null -eq $outfilename) -or ($outfilename -eq "")){
         "No Target Selected"
         Return
     }

+ 7 - 17
WinImager/bin/VBOX_VDICompact.ps1

@@ -1,38 +1,28 @@
 
-Import-Module -Name $env:PSLIB
+$Lib = Import-Module -AsCustomObject -Name $env:PSLIB
 
 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 {
-        $dialog = @"
-VirtualBox install Path not found!
-
-Is VirtualBox installed?
-"@ 
-        $dialog
-        GuiMessageBox $dialog -Buttons "Ok"
+    if ($Lib.VBox.VBOXMANAGE -eq $null){
+        $Lib.VBox.NotFound
         Return
     }
     
     "Select VDI File..."
 
-    $inname = GuiOpenFileName -Filter "Virtualbox Images (*.vdi)| *.vdi"
+    $inname = $Lib.GuiOpenFileName("Virtualbox Images (*.vdi)| *.vdi")
 
     if (($inname -eq $null) -or ($inname -eq "")){
         "No input file selected"
         Return
     }
 
-    &$VBOXMANAGE modifymedium disk $inname --compact
+    &$Lib.VBox.VBOXMANAGE modifymedium disk $inname --compact
 
     if($LASTEXITCODE -eq 0){
-        GuiMessageBox "Success" -Buttons "Ok"
+        $Lib.GuiMessageBox "Success" -Buttons "Ok"
     } else {
-        GuiMessageBox "Error" -Buttons "Ok"
+        $Lib.GuiMessageBox "Error" -Buttons "Ok"
     }
     Return
 }

+ 8 - 18
WinImager/bin/VBOX_VDIToImage.ps1

@@ -1,28 +1,18 @@
 
-Import-Module -Name $env:PSLIB
+$Lib = Import-Module -AsCustomObject -Name $env:PSLIB
 
 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 {
-        $dialog = @"
-VirtualBox install Path not found!
-
-Is VirtualBox installed?
-"@ 
-        $dialog
-        GuiMessageBox $dialog -Buttons "Ok"
+    if ($null -eq $Lib.VBox.VBOXMANAGE){
+        $Lib.VBox.NotFound
         Return
     }
     
     "Select VDI File..."
 
-    $inname = GuiOpenFileName -Filter "Virtualbox Images (*.vdi)| *.vdi"
+    $inname = $Lib.GuiOpenFileName("Virtualbox Images (*.vdi)| *.vdi")
 
-    if (($inname -eq $null) -or ($inname -eq "")){
+    if (($null -eq $inname) -or ($inname -eq "")){
         "No input file selected"
         Return
     }
@@ -31,7 +21,7 @@ Is VirtualBox installed?
     
     $outname = GuiSaveFileName -InitialDirectory ([io.path]::GetDirectoryName($inname))
 
-    if (($outname -eq $null) -or ($outname -eq "")){
+    if (($null -eq $outname) -or ($outname -eq "")){
         "No output file Selected"
         Return
     }
@@ -41,10 +31,10 @@ Is VirtualBox installed?
         Remove-Item $outname
     }
 
-    &$VBOXMANAGE clonehd $inname  $outname --format RAW
+    &$Lib.VBox.VBOXMANAGE clonehd $inname  $outname --format RAW
 
     if($LASTEXITCODE -eq 0){
-        GuiMessageBox "Success" -Buttons "Ok"
+        $Lib.GuiMessageBox("Success", "Ok")
     } else {
         GuiMessageBox "Error" -Buttons "Ok"
     }

+ 4 - 3
WinImager/lib/vbox.psm1

@@ -1,11 +1,12 @@
 
-if ($env:VBOX_INSTALL_PATH -ne $null){
+$NotFound = "Virtualbox install Path not found!"
+if ($null -ne $env:VBOX_INSTALL_PATH){
     $VBOXMANAGE = $env:VBOX_INSTALL_PATH + "VBoxManage.exe"
-} elseif ($env:VBOX_MSI_INSTALL_PATH -ne $null){
+} elseif ($null -ne $env:VBOX_MSI_INSTALL_PATH){
     $VBOXMANAGE = $env:VBOX_MSI_INSTALL_PATH + "VBoxManage.exe"
 } else {
     $VBOXMANAGE = $null
 }
 
 
-Export-ModuleMember -Function * -Variable VBOXMANAGE
+Export-ModuleMember -Function * -Variable VBOXMANAGE,NotFound