naev 0.12.6
glue_macos.m
Go to the documentation of this file.
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
11#include "glue_macos.h"
12#import <Foundation/Foundation.h>
13
17static int macos_writeString ( NSString *str, char *res, size_t n )
18{
19 BOOL ok = [str getCString:res
20 maxLength:n
21 encoding:NSUTF8StringEncoding];
22 return ok ? 0 : -1;
23}
24
28int macos_isBundle ( void )
29{
30 NSString *path = [[NSBundle mainBundle] bundlePath];
31 return [path hasSuffix:@".app"] ? 1 : 0;
32}
33
37int macos_resourcesPath ( char *res, size_t n )
38{
39 NSString *path = [[NSBundle mainBundle] resourcePath];
40 return macos_writeString( path, res, n );
41}
42
46static int macos_userLibraryDir ( NSString *kind, char *res, size_t n )
47{
48 NSString *path = [@[
49 NSHomeDirectory(),
50 @"/Library/",
51 kind,
52 @"/org.naev.Naev/"
53 ] componentsJoinedByString:@""];
54 return macos_writeString( path, res, n );
55}
56
60int macos_configPath ( char *res, size_t n )
61{
62 return macos_userLibraryDir( @"Preferences", res, n );
63}
64
68int macos_cachePath ( char *res, size_t n )
69{
70 return macos_userLibraryDir( @"Caches", res, n );
71}
static int macos_writeString(NSString *str, char *res, size_t n)
Write an NSString to a C buffer.
Definition glue_macos.m:17
int macos_resourcesPath(char *res, size_t n)
Get the path to the bundle resources directory.
Definition glue_macos.m:37
int macos_isBundle(void)
Determine if we're running from inside an app bundle.
Definition glue_macos.m:28
int macos_cachePath(char *res, size_t n)
Get the cache directory path.
Definition glue_macos.m:68
static int macos_userLibraryDir(NSString *kind, char *res, size_t n)
Get the path to the specified user directory.
Definition glue_macos.m:46
int macos_configPath(char *res, size_t n)
Get the config directory path.
Definition glue_macos.m:60