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