Skip to content

Commit 826eefb

Browse files
committed
[PE Helper/HotInstall/DSC] Remove non-WQL functions
1 parent 32a0ddf commit 826eefb

File tree

2 files changed

+2
-145
lines changed

2 files changed

+2
-145
lines changed
-1.41 KB
Binary file not shown.

Helpers/extps1/PE_Helper/tools/HotInstall/Installer/DSC/DiskSpaceChecker.vb

Lines changed: 2 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -12,86 +12,6 @@ Public Class DiskSpaceChecker
1212
Dim isTestApplicable As Boolean
1313
Dim sourcePath As String = ""
1414

15-
#Region "Non-WQL Drive Information Functions/Methods"
16-
17-
Function GetSystemDrives() As DriveInfo()
18-
Return DriveInfo.GetDrives()
19-
End Function
20-
21-
Function GetSystemBootDrive(FixedDrives As DriveInfo()) As DriveInfo
22-
If FixedDrives Is Nothing Then Return Nothing
23-
For Each FixedDrive As DriveInfo In FixedDrives
24-
If FixedDrive.Name = Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.Windows)) Then
25-
Return FixedDrive
26-
End If
27-
Next
28-
Return Nothing
29-
End Function
30-
31-
Sub ListObtainedDisks(FixedDrives As DriveInfo(), RemovableDrives As DriveInfo())
32-
reportContents &= "List of drives present in the host system:" & CrLf &
33-
"- Fixed drives: " & FixedDrives.Length & CrLf &
34-
"- Removable drives: " & RemovableDrives.Length & CrLf & CrLf
35-
36-
If FixedDrives.Length > 0 Then
37-
reportContents &= "Information about the fixed drives:" & CrLf & CrLf
38-
For Each FixedDrive As DriveInfo In FixedDrives
39-
reportContents &= "- Drive letter: " & FixedDrive.Name & CrLf &
40-
"- Drive type: " & FixedDrive.DriveType.ToString() & CrLf &
41-
"- Drive format: " & FixedDrive.DriveFormat & CrLf &
42-
"- Drive label: " & FixedDrive.VolumeLabel & CrLf &
43-
"- Drive size: " & FixedDrive.TotalSize & " bytes (~" & Converters.BytesToReadableSize(FixedDrive.TotalSize) & ")" & CrLf &
44-
"- Free space: " & FixedDrive.TotalFreeSpace & " bytes (~" & Converters.BytesToReadableSize(FixedDrive.TotalFreeSpace) & ")" & CrLf &
45-
"- Is the system drive? " & If(FixedDrive.Name = Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.Windows)), "Yes", "No") & CrLf & CrLf
46-
Next
47-
End If
48-
49-
If RemovableDrives.Length > 0 Then
50-
reportContents &= "Information about the removable drives:" & CrLf & CrLf
51-
For Each RemovableDrive As DriveInfo In RemovableDrives
52-
reportContents &= "- Drive letter: " & RemovableDrive.Name & CrLf &
53-
"- Drive type: " & RemovableDrive.DriveType.ToString() & CrLf &
54-
"- Drive format: " & RemovableDrive.DriveFormat & CrLf &
55-
"- Drive label: " & RemovableDrive.VolumeLabel & CrLf &
56-
"- Drive size: " & RemovableDrive.TotalSize & " bytes (~" & Converters.BytesToReadableSize(RemovableDrive.TotalSize) & ")" & CrLf &
57-
"- Free space: " & RemovableDrive.TotalFreeSpace & " bytes (~" & Converters.BytesToReadableSize(RemovableDrive.TotalFreeSpace) & ")" & CrLf & CrLf &
58-
"- Is the system drive? " & If(RemovableDrive.Name = Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.Windows)), "Yes", "No") & CrLf & CrLf
59-
Next
60-
End If
61-
62-
If Not FixedDrives.Any() And RemovableDrives.Any() Then
63-
reportContents &= "All drives were detected to be removable" & CrLf & CrLf
64-
End If
65-
End Sub
66-
67-
Sub ListSpaceComparison(ImageNames As List(Of String), ImageSizes As List(Of Long), FixedDrives As DriveInfo())
68-
If ImageNames.Count = 0 Then
69-
Throw New Exception("No names have been passed")
70-
End If
71-
If ImageSizes.Count = 0 Then
72-
Throw New Exception("No sizes have been passed")
73-
End If
74-
If FixedDrives.Length = 0 Then
75-
Throw New Exception("No fixed drives have been passed")
76-
End If
77-
78-
reportContents &= "Comparison of sizes:" & CrLf & CrLf
79-
80-
For Each FixedDrive As DriveInfo In FixedDrives
81-
reportContents &= "- Drive, with label " & Quote & FixedDrive.VolumeLabel & Quote & " (" & FixedDrive.Name & "):" & CrLf
82-
For x = 0 To ImageSizes.Count - 1
83-
If FixedDrive.TotalSize > ImageSizes(x) Then
84-
reportContents &= " - " & Quote & ImageNames(x) & Quote & " (index " & x + 1 & ") can be installed on this drive because there is enough free space." & CrLf
85-
Else
86-
reportContents &= " - " & Quote & ImageNames(x) & Quote & " (index " & x + 1 & ") cannot be installed on this drive because there is not enough free space." & CrLf
87-
End If
88-
Next
89-
Next
90-
reportContents &= CrLf
91-
End Sub
92-
93-
#End Region
94-
9515
#Region "WQL Drive Information Functions/Methods"
9616

9717
Sub ListObtainedDisks(DriveObjects As ManagementObjectCollection)
@@ -183,7 +103,7 @@ Public Class DiskSpaceChecker
183103
End Try
184104
End Sub
185105

186-
Sub GenerateDSCReportUsingWQL()
106+
Sub GenerateDSCReport()
187107
Dim SystemDrives As ManagementObjectCollection = GetResultsFromManagementQuery("SELECT * FROM Win32_LogicalDisk WHERE DriveType = 3") ' DriveType = 3 --> Local Disk
188108
If SystemDrives IsNot Nothing AndAlso SystemDrives.Count > 0 Then
189109
' List the disks with a management query
@@ -226,65 +146,6 @@ Public Class DiskSpaceChecker
226146
End If
227147
End Sub
228148

229-
Sub GenerateDSCReport()
230-
Dim SystemDrives() As DriveInfo = GetSystemDrives()
231-
If SystemDrives.Length > 0 Then
232-
' Only show drives that we have access to (are ready)
233-
SystemDrives = SystemDrives.Where(Function(drive) drive.IsReady).ToArray()
234-
If SystemDrives.Any() Then
235-
Dim FixedDrives() As DriveInfo = SystemDrives.Where(Function(drive) drive.DriveType = DriveType.Fixed).ToArray()
236-
Dim RemovableDrives() As DriveInfo = SystemDrives.Where(Function(drive) drive.DriveType = DriveType.Removable).ToArray()
237-
238-
' Report information about the drives
239-
ListObtainedDisks(FixedDrives, RemovableDrives)
240-
241-
If Not FixedDrives.Any() And RemovableDrives.Any() Then
242-
Throw New Exception("Available drives were found, but they are all removable. This is not well supported..")
243-
End If
244-
245-
' Continue with the fixed drives
246-
If FixedDrives.Any() Then
247-
Dim SystemBootDrive As DriveInfo = GetSystemBootDrive(FixedDrives)
248-
If SystemBootDrive IsNot Nothing Then
249-
' We have grabbed the system boot drive
250-
progressMessage = "Getting size of disc image files..."
251-
BackgroundWorker1.ReportProgress(10)
252-
Dim FolderSize As Long = GetDirectorySize(sourcePath, "")
253-
' Get the free space of the system boot drive, since we'll copy the files there
254-
Dim FreeSpaceOnSystemDrive As Long = SystemBootDrive.TotalFreeSpace
255-
ListFreeSpace(FreeSpaceOnSystemDrive, FolderSize)
256-
' Check if we have enough space
257-
If FreeSpaceOnSystemDrive < FolderSize Then
258-
Throw New Exception("There is not enough space to copy the disc image files to the system drive. Please free up some space and try again.")
259-
End If
260-
' Get information about the installation image and compare the expanded sizes of all indexes with the total space of all fixed drives
261-
progressMessage = "Getting image file information..."
262-
BackgroundWorker1.ReportProgress(40)
263-
Dim imgInfoCollection As DismImageInfoCollection = GetImageInformation(Path.Combine(sourcePath, "sources", "install.wim"))
264-
If imgInfoCollection IsNot Nothing Then
265-
progressMessage = "Getting image names and sizes..."
266-
BackgroundWorker1.ReportProgress(60)
267-
' Grab the image names and expanded sizes
268-
Dim ImageNames As New List(Of String)
269-
Dim ImageSizes As New List(Of Long)
270-
For Each imgInfo As DismImageInfo In imgInfoCollection
271-
ImageNames.Add(imgInfo.ImageName)
272-
ImageSizes.Add(imgInfo.ImageSize)
273-
Next
274-
progressMessage = "Comparing image sizes with free space..."
275-
BackgroundWorker1.ReportProgress(80)
276-
ListSpaceComparison(ImageNames, ImageSizes, FixedDrives)
277-
End If
278-
End If
279-
End If
280-
Else
281-
Throw New Exception("We could not detect available drives in your system.")
282-
End If
283-
Else
284-
Throw New Exception("We could not detect available drives in your system.")
285-
End If
286-
End Sub
287-
288149
Function GetImageInformation(ImagePath As String) As DismImageInfoCollection
289150
Dim imgInfoCollection As DismImageInfoCollection = Nothing
290151
Try
@@ -308,11 +169,7 @@ Public Class DiskSpaceChecker
308169
InitializeReport()
309170
progressMessage = GetValueFromLanguageData("DiskSpaceChecker.DSC_GetSysDrives")
310171
BackgroundWorker1.ReportProgress(5)
311-
Try
312-
GenerateDSCReportUsingWQL() ' Let's make my database teacher happy!
313-
Catch ex As Exception
314-
GenerateDSCReport()
315-
End Try
172+
GenerateDSCReport() ' Let's make my database teacher happy!
316173
End Sub
317174

318175
Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged

0 commit comments

Comments
 (0)