Blender  V3.3
GHOST_SystemPathsCocoa.mm
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2010 Blender Foundation. All rights reserved. */
3 
4 #import <Foundation/Foundation.h>
5 
6 #include "GHOST_Debug.h"
8 
9 #pragma mark initialization/finalization
10 
12 {
13 }
14 
16 {
17 }
18 
19 #pragma mark Base directories retrieval
20 
21 static const char *GetApplicationSupportDir(const char *versionstr,
22  const NSSearchPathDomainMask mask,
23  char *tempPath,
24  const std::size_t len_tempPath)
25 {
26  @autoreleasepool {
27  const NSArray *const paths = NSSearchPathForDirectoriesInDomains(
28  NSApplicationSupportDirectory, mask, YES);
29 
30  if ([paths count] == 0) {
31  return NULL;
32  }
33  const NSString *const basePath = [paths objectAtIndex:0];
34 
35  snprintf(tempPath,
36  len_tempPath,
37  "%s/Blender/%s",
38  [basePath cStringUsingEncoding:NSASCIIStringEncoding],
39  versionstr);
40  }
41  return tempPath;
42 }
43 
44 const char *GHOST_SystemPathsCocoa::getSystemDir(int, const char *versionstr) const
45 {
46  static char tempPath[512] = "";
47  return GetApplicationSupportDir(versionstr, NSLocalDomainMask, tempPath, sizeof(tempPath));
48 }
49 
50 const char *GHOST_SystemPathsCocoa::getUserDir(int, const char *versionstr) const
51 {
52  static char tempPath[512] = "";
53  return GetApplicationSupportDir(versionstr, NSUserDomainMask, tempPath, sizeof(tempPath));
54 }
55 
57 {
58  static char tempPath[512] = "";
59  @autoreleasepool {
60  NSSearchPathDirectory ns_directory;
61 
62  switch (type) {
64  ns_directory = NSDesktopDirectory;
65  break;
67  ns_directory = NSDocumentDirectory;
68  break;
70  ns_directory = NSDownloadsDirectory;
71  break;
73  ns_directory = NSMusicDirectory;
74  break;
76  ns_directory = NSPicturesDirectory;
77  break;
79  ns_directory = NSMoviesDirectory;
80  break;
82  ns_directory = NSCachesDirectory;
83  break;
84  default:
86  false,
87  "GHOST_SystemPathsCocoa::getUserSpecialDir(): Invalid enum value for type parameter");
88  return NULL;
89  }
90 
91  const NSArray *const paths = NSSearchPathForDirectoriesInDomains(
92  ns_directory, NSUserDomainMask, YES);
93  if ([paths count] == 0) {
94  return NULL;
95  }
96  const NSString *const basePath = [paths objectAtIndex:0];
97 
98  strncpy(tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding], sizeof(tempPath));
99  }
100  return tempPath;
101 }
102 
104 {
105  static char tempPath[512] = "";
106 
107  @autoreleasepool {
108  const NSString *const basePath = [[NSBundle mainBundle] bundlePath];
109 
110  if (basePath == nil) {
111  return NULL;
112  }
113 
114  strcpy(tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
115  }
116  return tempPath;
117 }
118 
119 void GHOST_SystemPathsCocoa::addToSystemRecentFiles(const char *filename) const
120 {
121  /* TODO: implement for macOS */
122 }
#define snprintf
Definition: BLI_winstuff.h:53
#define GHOST_ASSERT(x, info)
Definition: GHOST_Debug.h:54
static const char * GetApplicationSupportDir(const char *versionstr, const NSSearchPathDomainMask mask, char *tempPath, const std::size_t len_tempPath)
GHOST_TUserSpecialDirTypes
Definition: GHOST_Types.h:562
@ GHOST_kUserSpecialDirDesktop
Definition: GHOST_Types.h:563
@ GHOST_kUserSpecialDirMusic
Definition: GHOST_Types.h:566
@ GHOST_kUserSpecialDirPictures
Definition: GHOST_Types.h:567
@ GHOST_kUserSpecialDirVideos
Definition: GHOST_Types.h:568
@ GHOST_kUserSpecialDirDownloads
Definition: GHOST_Types.h:565
@ GHOST_kUserSpecialDirCaches
Definition: GHOST_Types.h:569
@ GHOST_kUserSpecialDirDocuments
Definition: GHOST_Types.h:564
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
const char * getUserDir(int version, const char *versionstr) const
const char * getUserSpecialDir(GHOST_TUserSpecialDirTypes type) const
const char * getSystemDir(int version, const char *versionstr) const
const char * getBinaryDir() const
void addToSystemRecentFiles(const char *filename) const
int count
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
Definition: math_float4.h:513