Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'intern/ghost/intern/GHOST_SystemPathsCocoa.mm')
-rw-r--r--intern/ghost/intern/GHOST_SystemPathsCocoa.mm166
1 files changed, 70 insertions, 96 deletions
diff --git a/intern/ghost/intern/GHOST_SystemPathsCocoa.mm b/intern/ghost/intern/GHOST_SystemPathsCocoa.mm
index 3b29d5106f6..4032c145ab4 100644
--- a/intern/ghost/intern/GHOST_SystemPathsCocoa.mm
+++ b/intern/ghost/intern/GHOST_SystemPathsCocoa.mm
@@ -36,127 +36,101 @@ GHOST_SystemPathsCocoa::~GHOST_SystemPathsCocoa()
#pragma mark Base directories retrieval
-const char *GHOST_SystemPathsCocoa::getSystemDir(int, const char *versionstr) const
+static const char *GetApplicationSupportDir(const char *versionstr,
+ const NSSearchPathDomainMask mask,
+ char *tempPath,
+ const std::size_t len_tempPath)
{
- static char tempPath[512] = "";
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSString *basePath;
- NSArray *paths;
-
- paths = NSSearchPathForDirectoriesInDomains(
- NSApplicationSupportDirectory, NSLocalDomainMask, YES);
-
- if ([paths count] > 0)
- basePath = [paths objectAtIndex:0];
- else {
- [pool drain];
- return NULL;
- }
+ @autoreleasepool {
+ const NSArray *const paths = NSSearchPathForDirectoriesInDomains(
+ NSApplicationSupportDirectory, mask, YES);
- snprintf(tempPath,
- sizeof(tempPath),
- "%s/Blender/%s",
- [basePath cStringUsingEncoding:NSASCIIStringEncoding],
- versionstr);
-
- [pool drain];
+ if ([paths count] == 0) {
+ return NULL;
+ }
+ const NSString *const basePath = [paths objectAtIndex:0];
+
+ snprintf(tempPath,
+ len_tempPath,
+ "%s/Blender/%s",
+ [basePath cStringUsingEncoding:NSASCIIStringEncoding],
+ versionstr);
+ }
return tempPath;
}
-const char *GHOST_SystemPathsCocoa::getUserDir(int, const char *versionstr) const
+const char *GHOST_SystemPathsCocoa::getSystemDir(int, const char *versionstr) const
{
static char tempPath[512] = "";
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSString *basePath;
- NSArray *paths;
-
- paths = NSSearchPathForDirectoriesInDomains(
- NSApplicationSupportDirectory, NSUserDomainMask, YES);
-
- if ([paths count] > 0)
- basePath = [paths objectAtIndex:0];
- else {
- [pool drain];
- return NULL;
- }
-
- snprintf(tempPath,
- sizeof(tempPath),
- "%s/Blender/%s",
- [basePath cStringUsingEncoding:NSASCIIStringEncoding],
- versionstr);
+ return GetApplicationSupportDir(versionstr, NSLocalDomainMask, tempPath, sizeof(tempPath));
+}
- [pool drain];
- return tempPath;
+const char *GHOST_SystemPathsCocoa::getUserDir(int, const char *versionstr) const
+{
+ static char tempPath[512] = "";
+ return GetApplicationSupportDir(versionstr, NSUserDomainMask, tempPath, sizeof(tempPath));
}
const char *GHOST_SystemPathsCocoa::getUserSpecialDir(GHOST_TUserSpecialDirTypes type) const
{
static char tempPath[512] = "";
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSString *basePath;
- NSArray *paths;
- NSSearchPathDirectory ns_directory;
-
- switch (type) {
- case GHOST_kUserSpecialDirDesktop:
- ns_directory = NSDesktopDirectory;
- break;
- case GHOST_kUserSpecialDirDocuments:
- ns_directory = NSDocumentDirectory;
- break;
- case GHOST_kUserSpecialDirDownloads:
- ns_directory = NSDownloadsDirectory;
- break;
- case GHOST_kUserSpecialDirMusic:
- ns_directory = NSMusicDirectory;
- break;
- case GHOST_kUserSpecialDirPictures:
- ns_directory = NSPicturesDirectory;
- break;
- case GHOST_kUserSpecialDirVideos:
- ns_directory = NSMoviesDirectory;
- break;
- default:
- GHOST_ASSERT(
- false,
- "GHOST_SystemPathsCocoa::getUserSpecialDir(): Invalid enum value for type parameter");
- [pool drain];
+ @autoreleasepool {
+ NSSearchPathDirectory ns_directory;
+
+ switch (type) {
+ case GHOST_kUserSpecialDirDesktop:
+ ns_directory = NSDesktopDirectory;
+ break;
+ case GHOST_kUserSpecialDirDocuments:
+ ns_directory = NSDocumentDirectory;
+ break;
+ case GHOST_kUserSpecialDirDownloads:
+ ns_directory = NSDownloadsDirectory;
+ break;
+ case GHOST_kUserSpecialDirMusic:
+ ns_directory = NSMusicDirectory;
+ break;
+ case GHOST_kUserSpecialDirPictures:
+ ns_directory = NSPicturesDirectory;
+ break;
+ case GHOST_kUserSpecialDirVideos:
+ ns_directory = NSMoviesDirectory;
+ break;
+ case GHOST_kUserSpecialDirCaches:
+ ns_directory = NSCachesDirectory;
+ break;
+ default:
+ GHOST_ASSERT(
+ false,
+ "GHOST_SystemPathsCocoa::getUserSpecialDir(): Invalid enum value for type parameter");
+ return NULL;
+ }
+
+ const NSArray *const paths = NSSearchPathForDirectoriesInDomains(
+ ns_directory, NSUserDomainMask, YES);
+ if ([paths count] == 0) {
return NULL;
- }
-
- paths = NSSearchPathForDirectoriesInDomains(ns_directory, NSUserDomainMask, YES);
+ }
+ const NSString *const basePath = [paths objectAtIndex:0];
- if ([paths count] > 0)
- basePath = [paths objectAtIndex:0];
- else {
- [pool drain];
- return NULL;
+ strncpy(tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding], sizeof(tempPath));
}
-
- strncpy(
- (char *)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding], sizeof(tempPath));
-
- [pool drain];
return tempPath;
}
const char *GHOST_SystemPathsCocoa::getBinaryDir() const
{
static char tempPath[512] = "";
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSString *basePath;
-
- basePath = [[NSBundle mainBundle] bundlePath];
- if (basePath == nil) {
- [pool drain];
- return NULL;
- }
+ @autoreleasepool {
+ const NSString *const basePath = [[NSBundle mainBundle] bundlePath];
- strcpy((char *)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
+ if (basePath == nil) {
+ return NULL;
+ }
- [pool drain];
+ strcpy(tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
+ }
return tempPath;
}