mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Wrap disk scope in try/catch, default to unspecified if error.
This commit is contained in:
parent
07e0f92a74
commit
cf29bae7a7
@ -12,7 +12,9 @@ namespace Wabbajack.Common
|
||||
if (driveLetter.Length == 3 && (driveLetter[1] == ':' && driveLetter[2] == '\\')) driveLetter = driveLetter.Remove(driveLetter.Length - 2);
|
||||
if (driveLetter.Length > 3) Utils.Error("Incorrect drive name! Must be X, X: or X:\\");
|
||||
|
||||
Utils.Log($"Phsyical Disk: {driveLetter}");
|
||||
DriveLetter = driveLetter;
|
||||
|
||||
try {
|
||||
|
||||
// Connect to storage scope
|
||||
var scope = new ManagementScope(@"\\.\root\microsoft\windows\storage");
|
||||
@ -30,19 +32,23 @@ namespace Wabbajack.Common
|
||||
// Get disk information
|
||||
var physical = physicalSearcher.Get().Cast<ManagementBaseObject>().Single();
|
||||
|
||||
DriveLetter = driveLetter;
|
||||
DeviceId = (string)physical["DeviceId"];
|
||||
MediaType = (MediaTypes)Convert.ToInt32(physical["MediaType"]);
|
||||
BusType = (BusTypes)Convert.ToInt32(physical["BusType"]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.Log($"Caught error getting disk info: {ex.Message}. Treating disk as Unspecified.");
|
||||
}
|
||||
}
|
||||
|
||||
public string DriveLetter { get; }
|
||||
|
||||
public string DeviceId { get; }
|
||||
public string DeviceId { get; } = "-1";
|
||||
|
||||
public MediaTypes MediaType { get; }
|
||||
public MediaTypes MediaType { get; } = MediaTypes.Unspecified;
|
||||
|
||||
public BusTypes BusType { get; }
|
||||
public BusTypes BusType { get; } = BusTypes.Unknown;
|
||||
|
||||
// https://docs.microsoft.com/en-us/previous-versions/windows/desktop/stormgmt/msft-physicaldisk#properties
|
||||
public enum MediaTypes
|
||||
|
Loading…
Reference in New Issue
Block a user