Files
test/intern/ghost/intern/GHOST_SystemPathsCocoa.mm
Campbell Barton c434782e3a File headers: SPDX License migration
Use a shorter/simpler license convention, stops the header taking so
much space.

Follow the SPDX license specification: https://spdx.org/licenses

- C/C++/objc/objc++
- Python
- Shell Scripts
- CMake, GNUmakefile

While most of the source tree has been included

- `./extern/` was left out.
- `./intern/cycles` & `./intern/atomic` are also excluded because they
  use different header conventions.

doc/license/SPDX-license-identifiers.txt has been added to list SPDX all
used identifiers.

See P2788 for the script that automated these edits.

Reviewed By: brecht, mont29, sergey

Ref D14069
2022-02-11 09:14:36 +11:00

123 lines
3.4 KiB
Plaintext

/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2010 Blender Foundation. All rights reserved. */
#import <Foundation/Foundation.h>
#include "GHOST_Debug.h"
#include "GHOST_SystemPathsCocoa.h"
#pragma mark initialization/finalization
GHOST_SystemPathsCocoa::GHOST_SystemPathsCocoa()
{
}
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] = "";
return GetApplicationSupportDir(versionstr, NSLocalDomainMask, tempPath, sizeof(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] = "";
@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;
}
const NSString *const basePath = [paths objectAtIndex:0];
strncpy(tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding], sizeof(tempPath));
}
return tempPath;
}
const char *GHOST_SystemPathsCocoa::getBinaryDir() const
{
static char tempPath[512] = "";
@autoreleasepool {
const NSString *const basePath = [[NSBundle mainBundle] bundlePath];
if (basePath == nil) {
return NULL;
}
strcpy(tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
}
return tempPath;
}
void GHOST_SystemPathsCocoa::addToSystemRecentFiles(const char *filename) const
{
/* TODO: implement for macOS */
}