22using System . Collections . Generic ;
33using System . Collections . Immutable ;
44using System . Collections . Specialized ;
5+ using System . Diagnostics . CodeAnalysis ;
56using System . IO ;
67using System . Linq ;
78using System . Net . Http ;
2324using Ps3DiscDumper . Sfo ;
2425using Ps3DiscDumper . Utils ;
2526using Ps3DiscDumper . Utils . MacOS ;
27+ using WmiLight ;
2628using FileInfo = System . IO . FileInfo ;
2729
2830namespace Ps3DiscDumper ;
@@ -130,23 +132,22 @@ private List<string> EnumeratePhysicalDrivesWindows()
130132 throw new NotImplementedException ( "This should never happen, shut up msbuild" ) ;
131133
132134 var physicalDrives = new List < string > ( ) ;
133- #if ! TRIMMED
134135 try
135136 {
136- using var physicalMediaQuery = new System . Management . ManagementObjectSearcher ( "SELECT * FROM Win32_PhysicalMedia" ) ;
137- var drives = physicalMediaQuery . Get ( ) ;
137+ using var wmiConnection = new WmiConnection ( ) ;
138+ var drives = wmiConnection . CreateQuery ( "SELECT * FROM Win32_PhysicalMedia" ) ;
138139 foreach ( var drive in drives )
139140 {
140- if ( drive . Properties [ "Tag" ] . Value is string tag
141+ if ( drive [ "Tag" ] is string tag
141142 && tag . StartsWith ( @"\\.\CDROM" ) )
142143 physicalDrives . Add ( tag ) ;
143144 }
144- using var cdromQuery = new System . Management . ManagementObjectSearcher ( "SELECT * FROM Win32_CDROMDrive" ) ;
145- drives = cdromQuery . Get ( ) ;
145+ drives = wmiConnection . CreateQuery ( "SELECT * FROM Win32_CDROMDrive" ) ;
146146 foreach ( var drive in drives )
147147 {
148148 // Name and Caption are the same, so idk if they can be different
149- Log . Info ( $ "Found optical media drive { drive . Properties [ "Name" ] . Value } ({ drive . Properties [ "Drive" ] . Value } )") ;
149+ var logicalUnit = drive [ "SCSILogicalUnit" ] ? . ToString ( ) ;
150+ Log . Info ( $@ "Found optical media drive { drive [ "Name" ] } ({ drive [ "Drive" ] } ; \\.\CDROM{ logicalUnit } )") ;
150151 }
151152 }
152153 catch ( Exception e )
@@ -155,10 +156,6 @@ private List<string> EnumeratePhysicalDrivesWindows()
155156 for ( var i = 0 ; i < 32 ; i ++ )
156157 physicalDrives . Add ( $@ "\\.\CDROM{ i } ") ;
157158 }
158- #else
159- for ( var i = 0 ; i < 32 ; i ++ )
160- physicalDrives . Add ( $@ "\\.\CDROM{ i } ") ;
161- #endif
162159 return physicalDrives ;
163160 }
164161
0 commit comments