Changeset View
Changeset View
Standalone View
Standalone View
intern/ghost/intern/GHOST_SystemPathsCocoa.mm
| Show All 30 Lines | |||||
| } | } | ||||
| GHOST_SystemPathsCocoa::~GHOST_SystemPathsCocoa() | GHOST_SystemPathsCocoa::~GHOST_SystemPathsCocoa() | ||||
| { | { | ||||
| } | } | ||||
| #pragma mark Base directories retrieval | #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) | |||||
| { | { | ||||
| static char tempPath[512] = ""; | static char tempPath[512] = ""; | ||||
brecht: Don't share the same `static` variable for all paths, there should be one per path so they… | |||||
| NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | @autoreleasepool { | ||||
| NSString *basePath; | const NSArray *const paths = NSSearchPathForDirectoriesInDomains( | ||||
| NSArray *paths; | NSApplicationSupportDirectory, mask, YES); | ||||
| paths = NSSearchPathForDirectoriesInDomains( | if ([paths count] == 0) { | ||||
| NSApplicationSupportDirectory, NSLocalDomainMask, YES); | |||||
| if ([paths count] > 0) | |||||
| basePath = [paths objectAtIndex:0]; | |||||
| else { | |||||
| [pool drain]; | |||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| const NSString *const basePath = [paths objectAtIndex:0]; | |||||
| snprintf(tempPath, | snprintf(tempPath, | ||||
| sizeof(tempPath), | sizeof(tempPath), | ||||
| "%s/Blender/%s", | "%s/Blender/%s", | ||||
| [basePath cStringUsingEncoding:NSASCIIStringEncoding], | [basePath cStringUsingEncoding:NSASCIIStringEncoding], | ||||
| versionstr); | versionstr); | ||||
| } | |||||
| [pool drain]; | |||||
| return tempPath; | 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] = ""; | return GetApplicationSupportDir(versionstr, NSLocalDomainMask); | ||||
| 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, | const char *GHOST_SystemPathsCocoa::getUserDir(int, const char *versionstr) const | ||||
| sizeof(tempPath), | { | ||||
| "%s/Blender/%s", | return GetApplicationSupportDir(versionstr, NSUserDomainMask); | ||||
| [basePath cStringUsingEncoding:NSASCIIStringEncoding], | |||||
| versionstr); | |||||
| [pool drain]; | |||||
| return tempPath; | |||||
| } | } | ||||
| const char *GHOST_SystemPathsCocoa::getUserSpecialDir(GHOST_TUserSpecialDirTypes type) const | const char *GHOST_SystemPathsCocoa::getUserSpecialDir(GHOST_TUserSpecialDirTypes type) const | ||||
| { | { | ||||
| static char tempPath[512] = ""; | static char tempPath[512] = ""; | ||||
| NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | @autoreleasepool { | ||||
| NSString *basePath; | |||||
| NSArray *paths; | |||||
| NSSearchPathDirectory ns_directory; | NSSearchPathDirectory ns_directory; | ||||
| switch (type) { | switch (type) { | ||||
| case GHOST_kUserSpecialDirDesktop: | case GHOST_kUserSpecialDirDesktop: | ||||
| ns_directory = NSDesktopDirectory; | ns_directory = NSDesktopDirectory; | ||||
| break; | break; | ||||
| case GHOST_kUserSpecialDirDocuments: | case GHOST_kUserSpecialDirDocuments: | ||||
| ns_directory = NSDocumentDirectory; | ns_directory = NSDocumentDirectory; | ||||
| break; | break; | ||||
| case GHOST_kUserSpecialDirDownloads: | case GHOST_kUserSpecialDirDownloads: | ||||
| ns_directory = NSDownloadsDirectory; | ns_directory = NSDownloadsDirectory; | ||||
| break; | break; | ||||
| case GHOST_kUserSpecialDirMusic: | case GHOST_kUserSpecialDirMusic: | ||||
| ns_directory = NSMusicDirectory; | ns_directory = NSMusicDirectory; | ||||
| break; | break; | ||||
| case GHOST_kUserSpecialDirPictures: | case GHOST_kUserSpecialDirPictures: | ||||
| ns_directory = NSPicturesDirectory; | ns_directory = NSPicturesDirectory; | ||||
| break; | break; | ||||
| case GHOST_kUserSpecialDirVideos: | case GHOST_kUserSpecialDirVideos: | ||||
| ns_directory = NSMoviesDirectory; | ns_directory = NSMoviesDirectory; | ||||
| break; | break; | ||||
| case GHOST_kUserSpecialDirCaches: | case GHOST_kUserSpecialDirCaches: | ||||
| ns_directory = NSCachesDirectory; | ns_directory = NSCachesDirectory; | ||||
| break; | break; | ||||
| default: | default: | ||||
| GHOST_ASSERT( | GHOST_ASSERT( | ||||
| false, | false, | ||||
| "GHOST_SystemPathsCocoa::getUserSpecialDir(): Invalid enum value for type parameter"); | "GHOST_SystemPathsCocoa::getUserSpecialDir(): Invalid enum value for type parameter"); | ||||
| [pool drain]; | |||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| paths = NSSearchPathForDirectoriesInDomains(ns_directory, NSUserDomainMask, YES); | const NSArray *const paths = NSSearchPathForDirectoriesInDomains( | ||||
| ns_directory, NSUserDomainMask, YES); | |||||
| if ([paths count] > 0) | if ([paths count] == 0) { | ||||
| basePath = [paths objectAtIndex:0]; | |||||
| else { | |||||
| [pool drain]; | |||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| const NSString *const basePath = [paths objectAtIndex:0]; | |||||
| strncpy( | strncpy(tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding], sizeof(tempPath)); | ||||
| (char *)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding], sizeof(tempPath)); | } | ||||
| [pool drain]; | |||||
| return tempPath; | return tempPath; | ||||
| } | } | ||||
| const char *GHOST_SystemPathsCocoa::getBinaryDir() const | const char *GHOST_SystemPathsCocoa::getBinaryDir() const | ||||
| { | { | ||||
| static char tempPath[512] = ""; | 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) { | if (basePath == nil) { | ||||
| [pool drain]; | |||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| strcpy((char *)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]); | strcpy(tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]); | ||||
| } | |||||
| [pool drain]; | |||||
| return tempPath; | return tempPath; | ||||
| } | } | ||||
| void GHOST_SystemPathsCocoa::addToSystemRecentFiles(const char *filename) const | void GHOST_SystemPathsCocoa::addToSystemRecentFiles(const char *filename) const | ||||
| { | { | ||||
| /* TODO: implement for macOS */ | /* TODO: implement for macOS */ | ||||
| } | } | ||||
Don't share the same static variable for all paths, there should be one per path so they don't overwrite each other.