Cleanup: const, autoreleasepool, remove unneeded cast.
Early return in some places also. De-duplicate getSystemDir and getUserDir also. Reviewed By: #platform_macos, brecht Differential Revision: https://developer.blender.org/D13211
This commit is contained in:
parent
7b88a4a3ba
commit
96387a2eff
|
@ -36,130 +36,101 @@ GHOST_SystemPathsCocoa::~GHOST_SystemPathsCocoa()
|
|||
|
||||
#pragma mark Base directories retrieval
|
||||
|
||||
static const char *GetApplicationSupportDir(const char *versionstr,
|
||||
const NSSearchPathDomainMask mask,
|
||||
char *tempPath,
|
||||
const std::size_t len_tempPath)
|
||||
{
|
||||
@autoreleasepool {
|
||||
const NSArray *const paths = NSSearchPathForDirectoriesInDomains(
|
||||
NSApplicationSupportDirectory, mask, YES);
|
||||
|
||||
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::getSystemDir(int, const char *versionstr) const
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
snprintf(tempPath,
|
||||
sizeof(tempPath),
|
||||
"%s/Blender/%s",
|
||||
[basePath cStringUsingEncoding:NSASCIIStringEncoding],
|
||||
versionstr);
|
||||
|
||||
[pool drain];
|
||||
return tempPath;
|
||||
return GetApplicationSupportDir(versionstr, NSLocalDomainMask, tempPath, sizeof(tempPath));
|
||||
}
|
||||
|
||||
const char *GHOST_SystemPathsCocoa::getUserDir(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);
|
||||
|
||||
[pool drain];
|
||||
return tempPath;
|
||||
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;
|
||||
@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");
|
||||
[pool drain];
|
||||
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;
|
||||
}
|
||||
const NSString *const basePath = [paths objectAtIndex:0];
|
||||
|
||||
strncpy(tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding], sizeof(tempPath));
|
||||
}
|
||||
|
||||
paths = NSSearchPathForDirectoriesInDomains(ns_directory, NSUserDomainMask, YES);
|
||||
|
||||
if ([paths count] > 0)
|
||||
basePath = [paths objectAtIndex:0];
|
||||
else {
|
||||
[pool drain];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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];
|
||||
@autoreleasepool {
|
||||
const NSString *const basePath = [[NSBundle mainBundle] bundlePath];
|
||||
|
||||
if (basePath == nil) {
|
||||
[pool drain];
|
||||
return NULL;
|
||||
if (basePath == nil) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy(tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
|
||||
}
|
||||
|
||||
strcpy((char *)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
|
||||
|
||||
[pool drain];
|
||||
return tempPath;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue