Blender  V2.93
GHOST_SystemPathsCocoa.mm
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2010 Blender Foundation.
17  * All rights reserved.
18  *
19  *
20  */
21 
22 #import <Foundation/Foundation.h>
23 
24 #include "GHOST_Debug.h"
25 #include "GHOST_SystemPathsCocoa.h"
26 
27 #pragma mark initialization/finalization
28 
30 {
31 }
32 
34 {
35 }
36 
37 #pragma mark Base directories retrieval
38 
39 const GHOST_TUns8 *GHOST_SystemPathsCocoa::getSystemDir(int, const char *versionstr) const
40 {
41  static char tempPath[512] = "";
42  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
43  NSString *basePath;
44  NSArray *paths;
45 
46  paths = NSSearchPathForDirectoriesInDomains(
47  NSApplicationSupportDirectory, NSLocalDomainMask, YES);
48 
49  if ([paths count] > 0)
50  basePath = [paths objectAtIndex:0];
51  else {
52  [pool drain];
53  return NULL;
54  }
55 
56  snprintf(tempPath,
57  sizeof(tempPath),
58  "%s/Blender/%s",
59  [basePath cStringUsingEncoding:NSASCIIStringEncoding],
60  versionstr);
61 
62  [pool drain];
63  return (GHOST_TUns8 *)tempPath;
64 }
65 
66 const GHOST_TUns8 *GHOST_SystemPathsCocoa::getUserDir(int, const char *versionstr) const
67 {
68  static char tempPath[512] = "";
69  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
70  NSString *basePath;
71  NSArray *paths;
72 
73  paths = NSSearchPathForDirectoriesInDomains(
74  NSApplicationSupportDirectory, NSUserDomainMask, YES);
75 
76  if ([paths count] > 0)
77  basePath = [paths objectAtIndex:0];
78  else {
79  [pool drain];
80  return NULL;
81  }
82 
83  snprintf(tempPath,
84  sizeof(tempPath),
85  "%s/Blender/%s",
86  [basePath cStringUsingEncoding:NSASCIIStringEncoding],
87  versionstr);
88 
89  [pool drain];
90  return (GHOST_TUns8 *)tempPath;
91 }
92 
94 {
95  static char tempPath[512] = "";
96  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
97  NSString *basePath;
98  NSArray *paths;
99  NSSearchPathDirectory ns_directory;
100 
101  switch (type) {
103  ns_directory = NSDesktopDirectory;
104  break;
106  ns_directory = NSDocumentDirectory;
107  break;
109  ns_directory = NSDownloadsDirectory;
110  break;
112  ns_directory = NSMusicDirectory;
113  break;
115  ns_directory = NSPicturesDirectory;
116  break;
118  ns_directory = NSMoviesDirectory;
119  break;
120  default:
121  GHOST_ASSERT(
122  false,
123  "GHOST_SystemPathsCocoa::getUserSpecialDir(): Invalid enum value for type parameter");
124  [pool drain];
125  return NULL;
126  }
127 
128  paths = NSSearchPathForDirectoriesInDomains(ns_directory, NSUserDomainMask, YES);
129 
130  if ([paths count] > 0)
131  basePath = [paths objectAtIndex:0];
132  else {
133  [pool drain];
134  return NULL;
135  }
136 
137  strncpy(
138  (char *)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding], sizeof(tempPath));
139 
140  [pool drain];
141  return (GHOST_TUns8 *)tempPath;
142 }
143 
145 {
146  static GHOST_TUns8 tempPath[512] = "";
147  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
148  NSString *basePath;
149 
150  basePath = [[NSBundle mainBundle] bundlePath];
151 
152  if (basePath == nil) {
153  [pool drain];
154  return NULL;
155  }
156 
157  strcpy((char *)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
158 
159  [pool drain];
160  return tempPath;
161 }
162 
163 void GHOST_SystemPathsCocoa::addToSystemRecentFiles(const char *filename) const
164 {
165  /* TODO: implement for macOS */
166 }
#define snprintf
Definition: BLI_winstuff.h:69
#define GHOST_ASSERT(x, info)
Definition: GHOST_Debug.h:79
GHOST_TUserSpecialDirTypes
Definition: GHOST_Types.h:568
@ GHOST_kUserSpecialDirDesktop
Definition: GHOST_Types.h:569
@ GHOST_kUserSpecialDirMusic
Definition: GHOST_Types.h:572
@ GHOST_kUserSpecialDirPictures
Definition: GHOST_Types.h:573
@ GHOST_kUserSpecialDirVideos
Definition: GHOST_Types.h:574
@ GHOST_kUserSpecialDirDownloads
Definition: GHOST_Types.h:571
@ GHOST_kUserSpecialDirDocuments
Definition: GHOST_Types.h:570
unsigned char GHOST_TUns8
Definition: GHOST_Types.h:60
_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 GHOST_TUns8 * getSystemDir(int version, const char *versionstr) const
const GHOST_TUns8 * getUserSpecialDir(GHOST_TUserSpecialDirTypes type) const
const GHOST_TUns8 * getUserDir(int version, const char *versionstr) const
void addToSystemRecentFiles(const char *filename) const
const GHOST_TUns8 * getBinaryDir() const
int count