Blender V4.3
GHOST_SystemPathsCocoa.mm
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2010 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#import <AppKit/NSDocumentController.h>
6#import <Foundation/Foundation.h>
7
8#include "GHOST_Debug.hh"
10
11/* --------------------------------------------------------------------
12 * Base directories retrieval.
13 */
14
15static const char *GetApplicationSupportDir(const char *versionstr,
16 const NSSearchPathDomainMask mask,
17 char *tempPath,
18 const std::size_t len_tempPath)
19{
20 @autoreleasepool {
21 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, mask, YES);
22
23 if (paths.count == 0) {
24 return nullptr;
25 }
26 NSString *basePath = [paths objectAtIndex:0];
27
28 snprintf(tempPath,
29 len_tempPath,
30 "%s/Blender/%s",
31 [basePath cStringUsingEncoding:NSASCIIStringEncoding],
32 versionstr);
33 }
34 return tempPath;
35}
36
37const char *GHOST_SystemPathsCocoa::getSystemDir(int /* version */, const char *versionstr) const
38{
39 static char tempPath[512] = "";
40 return GetApplicationSupportDir(versionstr, NSLocalDomainMask, tempPath, sizeof(tempPath));
41}
42
43const char *GHOST_SystemPathsCocoa::getUserDir(int /* version */, const char *versionstr) const
44{
45 static char tempPath[512] = "";
46 return GetApplicationSupportDir(versionstr, NSUserDomainMask, tempPath, sizeof(tempPath));
47}
48
50{
51 static char tempPath[512] = "";
52 @autoreleasepool {
53 NSSearchPathDirectory ns_directory;
54
55 switch (type) {
57 ns_directory = NSDesktopDirectory;
58 break;
60 ns_directory = NSDocumentDirectory;
61 break;
63 ns_directory = NSDownloadsDirectory;
64 break;
66 ns_directory = NSMusicDirectory;
67 break;
69 ns_directory = NSPicturesDirectory;
70 break;
72 ns_directory = NSMoviesDirectory;
73 break;
75 ns_directory = NSCachesDirectory;
76 break;
77 default:
79 false,
80 "GHOST_SystemPathsCocoa::getUserSpecialDir(): Invalid enum value for type parameter");
81 return nullptr;
82 }
83
84 NSArray *paths = NSSearchPathForDirectoriesInDomains(ns_directory, NSUserDomainMask, YES);
85 if (paths.count == 0) {
86 return nullptr;
87 }
88 NSString *basePath = [paths objectAtIndex:0];
89
90 const char *basePath_cstr = [basePath cStringUsingEncoding:NSASCIIStringEncoding];
91 int basePath_len = strlen(basePath_cstr);
92
93 basePath_len = MIN(basePath_len, sizeof(tempPath) - 1);
94 memcpy(tempPath, basePath_cstr, basePath_len);
95 tempPath[basePath_len] = '\0';
96 }
97 return tempPath;
98}
99
101{
102 static char tempPath[512] = "";
103
104 @autoreleasepool {
105 NSString *basePath = [[NSBundle mainBundle] bundlePath];
106
107 if (basePath == nil) {
108 return nullptr;
109 }
110
111 const char *basePath_cstr = [basePath cStringUsingEncoding:NSASCIIStringEncoding];
112 int basePath_len = strlen(basePath_cstr);
113
114 basePath_len = MIN(basePath_len, sizeof(tempPath) - 1);
115 memcpy(tempPath, basePath_cstr, basePath_len);
116 tempPath[basePath_len] = '\0';
117 }
118 return tempPath;
119}
120
122{
123 @autoreleasepool {
124 NSURL *file_url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:filepath]];
125 [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:file_url];
126 }
127}
#define GHOST_ASSERT(x, info)
static const char * GetApplicationSupportDir(const char *versionstr, const NSSearchPathDomainMask mask, char *tempPath, const std::size_t len_tempPath)
GHOST_TUserSpecialDirTypes
@ GHOST_kUserSpecialDirDesktop
@ GHOST_kUserSpecialDirMusic
@ GHOST_kUserSpecialDirPictures
@ GHOST_kUserSpecialDirVideos
@ GHOST_kUserSpecialDirDownloads
@ GHOST_kUserSpecialDirCaches
@ GHOST_kUserSpecialDirDocuments
#define MIN(_a, _b)
const char * getBinaryDir() const override
const char * getUserSpecialDir(GHOST_TUserSpecialDirTypes type) const override
void addToSystemRecentFiles(const char *filepath) const override
const char * getUserDir(int version, const char *versionstr) const override
const char * getSystemDir(int version, const char *versionstr) const override