Mercurial > minori
comparison src/sys/osx/filesystem.cc @ 196:f0ff06a45c42
date: use std::optional for values
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Thu, 07 Dec 2023 16:28:11 -0500 |
| parents | 975a3f0965e2 |
| children | c4ca035c565d |
comparison
equal
deleted
inserted
replaced
| 195:975a3f0965e2 | 196:f0ff06a45c42 |
|---|---|
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace osx { | 18 namespace osx { |
| 19 | 19 |
| 20 bool GetApplicationSupportDirectory(std::string& result) { | 20 bool GetApplicationSupportDirectory(std::string& result) { |
| 21 const CFArrayRef strings = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true); | 21 // NSArray* strings = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, ON); |
| 22 const CFArrayRef strings = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, ON); | |
| 22 if (!strings) | 23 if (!strings) |
| 23 return false; | 24 return false; |
| 24 | 25 |
| 26 // NSIndex index = [strings count]; | |
| 25 const CFIndex count = CFArrayGetCount(strings); | 27 const CFIndex count = CFArrayGetCount(strings); |
| 26 if (count < 1) { | 28 if (count < 1) { |
| 27 CFRelease(strings); | 29 CFRelease(strings); |
| 28 return false; | 30 return false; |
| 29 } | 31 } |
| 30 | 32 |
| 33 // NSString* string = [strings objectAtIndex: 0]; | |
| 31 const CFStringRef string = reinterpret_cast<CFStringRef>(CFArrayGetValueAtIndex(strings, 0)); | 34 const CFStringRef string = reinterpret_cast<CFStringRef>(CFArrayGetValueAtIndex(strings, 0)); |
| 32 if (!string) { | 35 if (!string) { |
| 33 CFRelease(strings); | 36 CFRelease(strings); |
| 34 return false; | 37 return false; |
| 35 } | 38 } |
| 36 | 39 |
| 40 // result = [string UTF8String]; | |
| 37 result.resize(CFStringGetMaximumSizeForEncoding(CFStringGetLength(string), kCFStringEncodingUTF8) + 1); | 41 result.resize(CFStringGetMaximumSizeForEncoding(CFStringGetLength(string), kCFStringEncodingUTF8) + 1); |
| 38 if (!CFStringGetCString(string, &result.front(), result.length(), kCFStringEncodingUTF8)) { | 42 if (!CFStringGetCString(string, &result.front(), result.length(), kCFStringEncodingUTF8)) { |
| 39 CFRelease(strings); | 43 CFRelease(strings); |
| 40 return false; | 44 return false; |
| 41 } | 45 } |
