Skip to content

Commit ce8af46

Browse files
Added drive letters to physical disks page.
1 parent e34d7f3 commit ce8af46

6 files changed

Lines changed: 98 additions & 31 deletions

File tree

TimVer/Configuration/UserSettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ public partial class UserSettings : ConfigManager<UserSettings>
102102
[ObservableProperty]
103103
private bool _showDiskType = true;
104104

105+
/// <summary>
106+
/// Show the Drive Letters column on the Physical Drives page.
107+
/// </summary>
108+
[ObservableProperty]
109+
private bool _showDriveLetters = true;
110+
105111
/// <summary>
106112
/// Show Exit in the navigation menu.
107113
/// </summary>

TimVer/Helpers/DiskDriveHelpers.cs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ public static List<PhysicalDrives> GetPhysicalDriveInfo()
212212

213213
pDisk.BusType = results["BusType"];
214214
pDisk.DiskType = results["DiskType"];
215+
pDisk.DriveLetters = results["Letters"];
215216
pDisk.FriendlyName = results["FriendlyName"];
216217
pDisk.Health = results["HealthStatus"];
217218
pDisk.Index = index;
@@ -258,7 +259,7 @@ private static List<uint> GetDriveIndicies()
258259
List<uint> indexes = [];
259260
indexes.AddRange(cimSession.QueryInstances(scope, "WQL", query)
260261
.Select(drive => (uint)drive.CimInstanceProperties["Index"]?.Value!)
261-
.OrderBy(i => i));
262+
.Order());
262263
return indexes;
263264
}
264265
#endregion Get list of drive indexes
@@ -272,7 +273,7 @@ private static List<uint> GetDriveIndicies()
272273
private static Dictionary<string, string> GetWin32DiskDrive(uint index)
273274
{
274275
const string scope = @"\\.\root\CIMV2";
275-
string query = $"SELECT InterfaceType, MediaType, Model, Name, Status, Partitions, Size FROM Win32_DiskDrive WHERE Index = {index}";
276+
string query = $"SELECT InterfaceType, MediaType, Model, Name, Status, Partitions, Size, DeviceID FROM Win32_DiskDrive WHERE Index = {index}";
276277

277278
try
278279
{
@@ -290,7 +291,8 @@ private static Dictionary<string, string> GetWin32DiskDrive(uint index)
290291
["Status"] = CimStringProperty(drive, "Status"),
291292
["Size"] = Math.Round(Convert.ToDouble(drive.CimInstanceProperties["Size"]
292293
.Value, CultureInfo.InvariantCulture) / Math.Pow(gbPref, 3), 2)
293-
.ToString(CultureInfo.InvariantCulture)
294+
.ToString(CultureInfo.InvariantCulture),
295+
["Letters"] = GetDriveLetters(CimStringProperty(drive,"DeviceID"))
294296
}).FirstOrDefault()!;
295297
}
296298
catch (Exception ex)
@@ -304,12 +306,38 @@ private static Dictionary<string, string> GetWin32DiskDrive(uint index)
304306
{ "Name", ""},
305307
{ "Partitions", ""},
306308
{ "Status", ""},
307-
{ "Size", ""}
309+
{ "Size", ""},
310+
{ "Letters", ""}
308311
};
309312
}
310313
}
311314
#endregion Get info from Win32_DiskDrive
312315

316+
/// <summary>
317+
/// Gets the drive letters on the supplied device ID.
318+
/// </summary>
319+
/// <param name="deviceID">Device ID from Win32_DiskDrive. e.g. \\.\PHYSICALDISK0</param>
320+
/// <returns>String of drive letters.</returns>
321+
static string GetDriveLetters(string deviceID)
322+
{
323+
const string scope = @"\\.\root\CIMV2";
324+
StringBuilder sb = new();
325+
326+
CimSession cim = CimSession.Create(null);
327+
string query = $"ASSOCIATORS OF {{Win32_DiskDrive.DeviceID='{deviceID}'}} WHERE AssocClass = Win32_DiskDriveToDiskPartition";
328+
foreach (CimInstance partitions in cim.QueryInstances(scope, "WQL", query))
329+
{
330+
string? partition = partitions.CimInstanceProperties["DeviceID"].Value.ToString();
331+
query = $"ASSOCIATORS OF {{Win32_DiskPartition.DeviceID='{partition}'}} WHERE AssocClass = Win32_LogicalDiskToPartition";
332+
foreach (CimInstance drive in cim.QueryInstances(scope, "WQL", query))
333+
{
334+
string? name = drive.CimInstanceProperties["Name"].Value.ToString();
335+
_ = sb.Append(CultureInfo.InvariantCulture, $"{name} ");
336+
}
337+
}
338+
return sb.ToString().TrimEnd();
339+
}
340+
313341
#region Get info from MSFT_Disk
314342
/// <summary>
315343
/// Gets MSFT_Disk info for the specified device.

TimVer/Languages/Strings.en-US.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<sys:String x:Key="DriveInfo_DeviceID">Device ID</sys:String>
8080
<sys:String x:Key="DriveInfo_DiskType">Disk Type</sys:String>
8181
<sys:String x:Key="DriveInfo_DriveType_CDRom">CD-ROM</sys:String>
82+
<sys:String x:Key="DriveInfo_DriveLetters">Drive Letters</sys:String>
8283
<sys:String x:Key="DriveInfo_DriveType_Fixed">Fixed</sys:String>
8384
<sys:String x:Key="DriveInfo_DriveType_Network">Network</sys:String>
8485
<sys:String x:Key="DriveInfo_DriveType_NoRootDirectory">No Root Directory</sys:String>
@@ -295,6 +296,7 @@
295296
<sys:String x:Key="SettingsItem_ShowBootDriveColumn">Show Boot Drive column</sys:String>
296297
<sys:String x:Key="SettingsItem_ShowBusTypeColumn">Show Bus Type column</sys:String>
297298
<sys:String x:Key="SettingsItem_ShowDiskTypeColumn">Show Disk Type column</sys:String>
299+
<sys:String x:Key="SettingsItem_ShowDriveLettersColumn">Show Drive Letters column</sys:String>
298300
<sys:String x:Key="SettingsItem_ShowExit">Show Exit in Navigation bar</sys:String>
299301
<sys:String x:Key="SettingsItem_ShowFormatColumn">Show Format column</sys:String>
300302
<sys:String x:Key="SettingsItem_ShowFriendlyName">Show Friendly Name column</sys:String>
@@ -432,4 +434,10 @@
432434
<!-- Begin changes on 2024/09/11 @ 21:25 UTC-->
433435
<!-- A | SettingsItem_DisplayFont -->
434436
<!-- End of changes on 2024/09/11 @ 21:25 UTC-->
437+
438+
<!-- Begin changes on 2024/09/23 @ 20:35 UTC-->
439+
<!-- A | DriveInfo_DriveLetters -->
440+
<!-- A | SettingsItem_ShowDriveLettersColumn -->
441+
<!-- End of changes on 2024/09/23 @ 20:35 UTC-->
442+
435443
</ResourceDictionary>

TimVer/Models/PhysicalDrives.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ public partial class PhysicalDrives : ObservableObject
1616
[ObservableProperty]
1717
private string? _diskType;
1818

19+
/// <summary>
20+
/// Drive letters assigned.
21+
/// </summary>
22+
[ObservableProperty]
23+
private string? _driveLetters;
24+
1925
/// <summary>
2026
/// Firmware revision number.
2127
/// </summary>

TimVer/Views/DrivesPage.xaml

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@
188188
Visibility="{Binding ShowPartitions,
189189
Source={x:Static config:UserSettings.Setting},
190190
Converter={StaticResource BooleanToVisibilityConverter}}" />
191+
<DataGridTextColumn Binding="{Binding DriveLetters}"
192+
Header="{DynamicResource DriveInfo_DriveLetters}"
193+
Visibility="{Binding ShowDriveLetters,
194+
Source={x:Static config:UserSettings.Setting},
195+
Converter={StaticResource BooleanToVisibilityConverter}}" />
191196
<DataGridTextColumn Binding="{Binding DiskType}"
192197
Header="{DynamicResource DriveInfo_DiskType}"
193198
Visibility="{Binding ShowDiskType,
@@ -292,6 +297,8 @@
292297
<RowDefinition Height="24" />
293298
<RowDefinition Height="24" />
294299
<RowDefinition Height="24" />
300+
<RowDefinition Height="24" />
301+
<RowDefinition Height="24" />
295302
</Grid.RowDefinitions>
296303
<!--#endregion-->
297304

@@ -317,74 +324,80 @@
317324

318325
<TextBlock Grid.Row="3" Grid.Column="1"
319326
VerticalAlignment="Center"
320-
Text="{DynamicResource DriveInfo_MediaType}" />
327+
Text="{DynamicResource DriveInfo_DriveLetters}" />
321328
<TextBlock Grid.Row="3" Grid.Column="3"
322-
Text="{Binding MediaType}" />
329+
Text="{Binding DriveLetters}" />
323330

324331
<TextBlock Grid.Row="4" Grid.Column="1"
325332
VerticalAlignment="Center"
326-
Text="{DynamicResource DriveInfo_DiskType}" />
333+
Text="{DynamicResource DriveInfo_MediaType}" />
327334
<TextBlock Grid.Row="4" Grid.Column="3"
328-
Text="{Binding DiskType}" />
335+
Text="{Binding MediaType}" />
329336

330337
<TextBlock Grid.Row="5" Grid.Column="1"
331338
VerticalAlignment="Center"
332-
Text="{DynamicResource DriveInfo_Interface}" />
339+
Text="{DynamicResource DriveInfo_DiskType}" />
333340
<TextBlock Grid.Row="5" Grid.Column="3"
334-
Text="{Binding Interface}" />
341+
Text="{Binding DiskType}" />
335342

336343
<TextBlock Grid.Row="6" Grid.Column="1"
337344
VerticalAlignment="Center"
338-
Text="{DynamicResource DriveInfo_BusType}" />
345+
Text="{DynamicResource DriveInfo_Interface}" />
339346
<TextBlock Grid.Row="6" Grid.Column="3"
340-
Text="{Binding BusType}" />
347+
Text="{Binding Interface}" />
341348

342349
<TextBlock Grid.Row="7" Grid.Column="1"
343350
VerticalAlignment="Center"
344-
Text="{DynamicResource DriveInfo_Health}" />
351+
Text="{DynamicResource DriveInfo_BusType}" />
345352
<TextBlock Grid.Row="7" Grid.Column="3"
346-
Text="{Binding Health}" />
353+
Text="{Binding BusType}" />
347354

348355
<TextBlock Grid.Row="8" Grid.Column="1"
349356
VerticalAlignment="Center"
350-
Text="{DynamicResource DriveInfo_PartitionStyle}" />
357+
Text="{DynamicResource DriveInfo_Health}" />
351358
<TextBlock Grid.Row="8" Grid.Column="3"
352-
Text="{Binding PartitionStyle}" />
359+
Text="{Binding Health}" />
353360

354361
<TextBlock Grid.Row="9" Grid.Column="1"
355362
VerticalAlignment="Center"
356-
Text="{DynamicResource DriveInfo_BootDrive}" />
363+
Text="{DynamicResource DriveInfo_PartitionStyle}" />
357364
<TextBlock Grid.Row="9" Grid.Column="3"
358-
Text="{Binding IsBoot}" />
365+
Text="{Binding PartitionStyle}" />
359366

360367
<TextBlock Grid.Row="10" Grid.Column="1"
361368
VerticalAlignment="Center"
362-
Text="{DynamicResource DriveInfo_SystemDrive}" />
369+
Text="{DynamicResource DriveInfo_BootDrive}" />
363370
<TextBlock Grid.Row="10" Grid.Column="3"
364-
Text="{Binding IsSystem}" />
371+
Text="{Binding IsBoot}" />
365372

366373
<TextBlock Grid.Row="11" Grid.Column="1"
367374
VerticalAlignment="Center"
368-
Text="{DynamicResource DriveInfo_Model}" />
375+
Text="{DynamicResource DriveInfo_SystemDrive}" />
369376
<TextBlock Grid.Row="11" Grid.Column="3"
370-
Text="{Binding Model}" />
377+
Text="{Binding IsSystem}" />
371378

372379
<TextBlock Grid.Row="12" Grid.Column="1"
373380
VerticalAlignment="Center"
374-
Text="{DynamicResource DriveInfo_Name}" />
381+
Text="{DynamicResource DriveInfo_Model}" />
375382
<TextBlock Grid.Row="12" Grid.Column="3"
376-
Text="{Binding Name}" />
383+
Text="{Binding Model}" />
377384

378385
<TextBlock Grid.Row="13" Grid.Column="1"
379386
VerticalAlignment="Center"
380-
Text="{DynamicResource DriveInfo_FriendlyName}" />
387+
Text="{DynamicResource DriveInfo_Name}" />
381388
<TextBlock Grid.Row="13" Grid.Column="3"
382-
Text="{Binding FriendlyName}" />
389+
Text="{Binding Name}" />
383390

384391
<TextBlock Grid.Row="14" Grid.Column="1"
385392
VerticalAlignment="Center"
386-
Text="{DynamicResource DriveInfo_SerialNumber}" />
393+
Text="{DynamicResource DriveInfo_FriendlyName}" />
387394
<TextBlock Grid.Row="14" Grid.Column="3"
395+
Text="{Binding FriendlyName}" />
396+
397+
<TextBlock Grid.Row="15" Grid.Column="1"
398+
VerticalAlignment="Center"
399+
Text="{DynamicResource DriveInfo_SerialNumber}" />
400+
<TextBlock Grid.Row="15" Grid.Column="3"
388401
Text="{Binding SerialNumber}" />
389402
</Grid>
390403
</ScrollViewer>

TimVer/Views/SettingsPage.xaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@
373373
<RowDefinition Height="30" />
374374
<RowDefinition Height="30" />
375375
<RowDefinition Height="30" />
376+
<RowDefinition Height="30" />
376377
</Grid.RowDefinitions>
377378
<Grid.ColumnDefinitions>
378379
<ColumnDefinition Width="auto" />
@@ -386,26 +387,31 @@
386387
IsChecked="{Binding ShowPartitions,
387388
Source={x:Static config:UserSettings.Setting}}" />
388389
<CheckBox Grid.Row="1" Grid.Column="0"
390+
Padding="10,0"
391+
Content="{DynamicResource SettingsItem_ShowDriveLettersColumn}"
392+
IsChecked="{Binding ShowDriveLetters,
393+
Source={x:Static config:UserSettings.Setting}}" />
394+
<CheckBox Grid.Row="2" Grid.Column="0"
389395
Padding="10,0"
390396
Content="{DynamicResource SettingsItem_ShowDiskTypeColumn}"
391397
IsChecked="{Binding ShowDiskType,
392398
Source={x:Static config:UserSettings.Setting}}" />
393-
<CheckBox Grid.Row="2" Grid.Column="0"
399+
<CheckBox Grid.Row="3" Grid.Column="0"
394400
Padding="10,0"
395401
Content="{DynamicResource SettingsItem_ShowMediaTypeColumn}"
396402
IsChecked="{Binding ShowMediaType,
397403
Source={x:Static config:UserSettings.Setting}}" />
398-
<CheckBox Grid.Row="3" Grid.Column="0"
404+
<CheckBox Grid.Row="4" Grid.Column="0"
399405
Padding="10,0"
400406
Content="{DynamicResource SettingsItem_ShowInterfaceColumn}"
401407
IsChecked="{Binding ShowInterface,
402408
Source={x:Static config:UserSettings.Setting}}" />
403-
<CheckBox Grid.Row="4" Grid.Column="0"
409+
<CheckBox Grid.Row="5" Grid.Column="0"
404410
Padding="10,0"
405411
Content="{DynamicResource SettingsItem_ShowBusTypeColumn}"
406412
IsChecked="{Binding ShowBusType,
407413
Source={x:Static config:UserSettings.Setting}}" />
408-
<CheckBox Grid.Row="5" Grid.Column="0"
414+
<CheckBox Grid.Row="6" Grid.Column="0"
409415
Padding="10,0"
410416
Content="{DynamicResource SettingsItem_ShowHealthColumn}"
411417
IsChecked="{Binding ShowHealth,

0 commit comments

Comments
 (0)