@@ -375,12 +375,17 @@ extension String {
375
375
376
376
return fallback
377
377
}
378
+
379
+ guard !user. isEmpty else {
380
+ return fallbackUserDirectory ( )
381
+ }
378
382
379
383
return user. withCString ( encodedAs: UTF16 . self) { pwszUserName in
380
384
var cbSID : DWORD = 0
381
385
var cchReferencedDomainName : DWORD = 0
382
386
var eUse : SID_NAME_USE = SidTypeUnknown
383
- guard LookupAccountNameW ( nil , pwszUserName, nil , & cbSID, nil , & cchReferencedDomainName, & eUse) else {
387
+ LookupAccountNameW ( nil , pwszUserName, nil , & cbSID, nil , & cchReferencedDomainName, & eUse)
388
+ guard cbSID > 0 else {
384
389
return fallbackUserDirectory ( )
385
390
}
386
391
@@ -395,10 +400,11 @@ extension String {
395
400
fatalError ( " unable to convert SID to string for user \( user) " )
396
401
}
397
402
398
- return #"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\#\ (String(decodingCString: pwszSID!, as: UTF16.self))"# . withCString ( encodedAs: UTF16 . self) { pwszKeyPath in
403
+ return #"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\ \# (String ( decodingCString: pwszSID!, as: UTF16 . self) ) "# . withCString ( encodedAs: UTF16 . self) { pwszKeyPath in
399
404
return " ProfileImagePath " . withCString ( encodedAs: UTF16 . self) { pwszKey in
400
405
var cbData : DWORD = 0
401
- guard RegGetValueW ( HKEY_LOCAL_MACHINE, pwszKeyPath, pwszKey, RRF_RT_REG_SZ, nil , nil , & cbData) == ERROR_SUCCESS else {
406
+ RegGetValueW ( HKEY_LOCAL_MACHINE, pwszKeyPath, pwszKey, RRF_RT_REG_SZ, nil , nil , & cbData)
407
+ guard cbData > 0 else {
402
408
fatalError ( " unable to query ProfileImagePath for user \( user) " )
403
409
}
404
410
return withUnsafeTemporaryAllocation ( of: WCHAR . self, capacity: Int ( cbData) ) { pwszData in
0 commit comments