Mercurial > minori
annotate 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 |
rev | line source |
---|---|
194
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
1 #include "sys/osx/filesystem.h" |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
2 |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
3 #include <CoreFoundation/CoreFoundation.h> |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
4 |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
5 #include <string> |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
6 |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
7 static constexpr unsigned long NSApplicationSupportDirectory = 14; |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
8 static constexpr unsigned long NSUserDomainMask = 1; |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
9 |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
10 extern "C" { |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
11 CFArrayRef NSSearchPathForDirectoriesInDomains(unsigned long directory, unsigned long domainMask, int expandTilde); |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
12 } |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
13 |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
14 namespace osx { |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
15 |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
16 bool GetApplicationSupportDirectory(std::string& result) { |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
17 const CFArrayRef strings = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true); |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
18 if (!strings) |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
19 return false; |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
20 |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
21 const CFIndex count = CFArrayGetCount(strings); |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
22 if (count < 1) { |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
23 CFRelease(strings); |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
24 return false; |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
25 } |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
26 |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
27 const CFStringRef string = reinterpret_cast<CFStringRef>(CFArrayGetValueAtIndex(strings, 0)); |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
28 if (!string) { |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
29 CFRelease(strings); |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
30 return false; |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
31 } |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
32 |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
33 result.resize(CFStringGetMaximumSizeForEncoding(CFStringGetLength(string), kCFStringEncodingUTF8) + 1); |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
34 if (!CFStringGetCString(string, &result.front(), result.length(), kCFStringEncodingUTF8)) { |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
35 CFRelease(strings); |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
36 return false; |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
37 } |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
38 result.resize(result.find('\0')); |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
39 |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
40 return true; |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
41 } |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
42 |
8548dc425697
sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
43 } // namespace osx |