annotate src/sys/osx/filesystem.cc @ 207:9d9e6242dd1a

CI/macos: initial macos CI, CI/windows: fix 64-bit build?
author Paper <paper@paper.us.eu.org>
date Tue, 02 Jan 2024 07:08:23 -0500
parents c4ca035c565d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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>
195
975a3f0965e2 locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents: 194
diff changeset
4 #include <objc/runtime.h>
194
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
5
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
6 #include <string>
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
7
195
975a3f0965e2 locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents: 194
diff changeset
8 /* These constants are defined in Foundation but not
975a3f0965e2 locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents: 194
diff changeset
9 * exposed to CoreFoundation users.
975a3f0965e2 locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents: 194
diff changeset
10 */
194
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11 static constexpr unsigned long NSApplicationSupportDirectory = 14;
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12 static constexpr unsigned long NSUserDomainMask = 1;
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 extern "C" {
195
975a3f0965e2 locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents: 194
diff changeset
15 CFArrayRef NSSearchPathForDirectoriesInDomains(unsigned long directory, unsigned long domainMask, BOOL expandTilde);
194
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 }
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18 namespace osx {
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20 bool GetApplicationSupportDirectory(std::string& result) {
196
f0ff06a45c42 date: use std::optional for values
Paper <mrpapersonic@gmail.com>
parents: 195
diff changeset
21 // NSArray* strings = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, ON);
197
c4ca035c565d *: misc. patches
Paper <mrpapersonic@gmail.com>
parents: 196
diff changeset
22 const CFArrayRef strings = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true);
194
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23 if (!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
196
f0ff06a45c42 date: use std::optional for values
Paper <mrpapersonic@gmail.com>
parents: 195
diff changeset
26 // NSIndex index = [strings count];
194
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27 const CFIndex count = CFArrayGetCount(strings);
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
28 if (count < 1) {
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
196
f0ff06a45c42 date: use std::optional for values
Paper <mrpapersonic@gmail.com>
parents: 195
diff changeset
33 // NSString* string = [strings objectAtIndex: 0];
194
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
34 const CFStringRef string = reinterpret_cast<CFStringRef>(CFArrayGetValueAtIndex(strings, 0));
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
35 if (!string) {
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
36 CFRelease(strings);
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
37 return false;
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
38 }
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
39
196
f0ff06a45c42 date: use std::optional for values
Paper <mrpapersonic@gmail.com>
parents: 195
diff changeset
40 // result = [string UTF8String];
194
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
41 result.resize(CFStringGetMaximumSizeForEncoding(CFStringGetLength(string), kCFStringEncodingUTF8) + 1);
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
42 if (!CFStringGetCString(string, &result.front(), result.length(), kCFStringEncodingUTF8)) {
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
43 CFRelease(strings);
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
44 return false;
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
45 }
195
975a3f0965e2 locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents: 194
diff changeset
46 result.resize(result.find_first_of('\0'));
194
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
47
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
48 return true;
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
49 }
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
50
8548dc425697 sys/osx: remove all objective-c++ stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
51 } // namespace osx