comparison src/sys/osx/filesystem.cc @ 194:8548dc425697

sys/osx: remove all objective-c++ stuff mmmm :)
author Paper <mrpapersonic@gmail.com>
date Thu, 07 Dec 2023 03:17:05 -0500
parents
children 975a3f0965e2
comparison
equal deleted inserted replaced
193:0ad2507c3e60 194:8548dc425697
1 #include "sys/osx/filesystem.h"
2
3 #include <CoreFoundation/CoreFoundation.h>
4
5 #include <string>
6
7 static constexpr unsigned long NSApplicationSupportDirectory = 14;
8 static constexpr unsigned long NSUserDomainMask = 1;
9
10 extern "C" {
11 CFArrayRef NSSearchPathForDirectoriesInDomains(unsigned long directory, unsigned long domainMask, int expandTilde);
12 }
13
14 namespace osx {
15
16 bool GetApplicationSupportDirectory(std::string& result) {
17 const CFArrayRef strings = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true);
18 if (!strings)
19 return false;
20
21 const CFIndex count = CFArrayGetCount(strings);
22 if (count < 1) {
23 CFRelease(strings);
24 return false;
25 }
26
27 const CFStringRef string = reinterpret_cast<CFStringRef>(CFArrayGetValueAtIndex(strings, 0));
28 if (!string) {
29 CFRelease(strings);
30 return false;
31 }
32
33 result.resize(CFStringGetMaximumSizeForEncoding(CFStringGetLength(string), kCFStringEncodingUTF8) + 1);
34 if (!CFStringGetCString(string, &result.front(), result.length(), kCFStringEncodingUTF8)) {
35 CFRelease(strings);
36 return false;
37 }
38 result.resize(result.find('\0'));
39
40 return true;
41 }
42
43 } // namespace osx