@@ -80,7 +80,7 @@ public actor IPSWExtractor {
8080 var result = ClassifiedEntries ( )
8181 for entry in archive {
8282 let name = entry. path
83- let basename = ( name as NSString ) . lastPathComponent
83+ let basename = URL ( fileURLWithPath : name ) . lastPathComponent
8484 if basename. hasPrefix ( " kernelcache " ) {
8585 result. kernelcaches. append ( entry)
8686 } else if name. hasSuffix ( " .dmg " ) || name. hasSuffix ( " .dmg.aea " ) {
@@ -144,7 +144,7 @@ public actor IPSWExtractor {
144144
145145 var paths : [ URL ] = [ ]
146146 for entry in entries {
147- let basename = ( entry. path as NSString ) . lastPathComponent
147+ let basename = URL ( fileURLWithPath : entry. path) . lastPathComponent
148148 let destPath = kernelsDir. appendingPathComponent ( basename)
149149 _ = try archive. extract ( entry, to: destPath)
150150 paths. append ( destPath)
@@ -164,7 +164,7 @@ public actor IPSWExtractor {
164164 }
165165
166166 let entryByFilename = Dictionary (
167- dmgEntries. map { ( ( ( $0. path as NSString ) . lastPathComponent) , $0) } ,
167+ dmgEntries. map { ( ( URL ( fileURLWithPath : $0. path) . lastPathComponent) , $0) } ,
168168 uniquingKeysWith: { first, _ in first }
169169 )
170170
@@ -184,14 +184,14 @@ public actor IPSWExtractor {
184184 Self . logger. warning ( " No manifest DMG mapping; using largest DMG as system image " )
185185 }
186186
187- let systemBasename = ( systemEntry. path as NSString ) . lastPathComponent
187+ let systemBasename = URL ( fileURLWithPath : systemEntry. path) . lastPathComponent
188188 let systemPath = workDir. appendingPathComponent ( systemBasename)
189189 Self . logger. info ( " Extracting system DMG: \( systemBasename) ( \( systemEntry. uncompressedSize) bytes) " )
190190 _ = try archive. extract ( systemEntry, to: systemPath)
191191
192192 var cryptexPath : URL ?
193193 if let cryptexEntry {
194- let cryptexBasename = ( cryptexEntry. path as NSString ) . lastPathComponent
194+ let cryptexBasename = URL ( fileURLWithPath : cryptexEntry. path) . lastPathComponent
195195 let path = workDir. appendingPathComponent ( cryptexBasename)
196196 Self . logger. info ( " Extracting cryptex DMG: \( cryptexBasename) ( \( cryptexEntry. uncompressedSize) bytes) " )
197197 _ = try archive. extract ( cryptexEntry, to: path)
@@ -249,7 +249,7 @@ public actor IPSWExtractor {
249249 let info = roleDict [ " Info " ] as? [ String : Any ] ,
250250 let filePath = info [ " Path " ] as? String ,
251251 filePath. hasSuffix ( " .dmg " ) || filePath. hasSuffix ( " .dmg.aea " ) {
252- let filename = ( filePath as NSString ) . lastPathComponent
252+ let filename = URL ( fileURLWithPath : filePath ) . lastPathComponent
253253 dmgRoles [ roleName] = filename
254254 }
255255 }
@@ -265,7 +265,7 @@ public actor IPSWExtractor {
265265 let kernelPath = kernelInfo [ " Path " ] as? String else {
266266 continue
267267 }
268- let kernelFilename = ( kernelPath as NSString ) . lastPathComponent
268+ let kernelFilename = URL ( fileURLWithPath : kernelPath ) . lastPathComponent
269269 kernelDeviceMap [ kernelFilename, default: [ ] ] . insert ( productType)
270270 }
271271 }
@@ -304,15 +304,10 @@ public actor IPSWExtractor {
304304 /// Parse OS version and build from IPSW filename as a last resort.
305305 /// Example: "UniversalMac_15.6.1_24G90_Restore.ipsw" → ("15.6.1", "24G90")
306306 private func parseFromFilename( _ filename: String ) -> ( osVersion: String , buildNumber: String ) {
307- let pattern = #"UniversalMac_([0-9]+\.[0-9]+(?:\.[0-9]+)?)_([A-Za-z0-9]+)_Restore"#
308- guard let regex = try ? NSRegularExpression ( pattern: pattern) ,
309- let match = regex. firstMatch (
310- in: filename, range: NSRange ( filename. startIndex... , in: filename)
311- ) ,
312- let versionRange = Range ( match. range ( at: 1 ) , in: filename) ,
313- let buildRange = Range ( match. range ( at: 2 ) , in: filename) else {
307+ let regex = /UniversalMac_(\d+\.\d+(?:\.\d+)?)_([A-Za-z0-9]+)_Restore/
308+ guard let match = filename. firstMatch ( of: regex) else {
314309 return ( " " , " " )
315310 }
316- return ( String ( filename [ versionRange ] ) , String ( filename [ buildRange ] ) )
311+ return ( String ( match . 1 ) , String ( match . 2 ) )
317312 }
318313}
0 commit comments