naev 0.11.5
glue_macos.m
Go to the documentation of this file.
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4
14#include "glue_macos.h"
15#include <Foundation/Foundation.h>
16
17
21static int macos_writeString ( NSString *str, char *res, size_t n )
22{
23 BOOL ok = [str getCString:res
24 maxLength:n
25 encoding:NSUTF8StringEncoding];
26 return ok ? 0 : -1;
27}
28
29
33int macos_isBundle ( void )
34{
35 NSString *path = [[NSBundle mainBundle] bundlePath];
36 return [path hasSuffix:@".app"] ? 1 : 0;
37}
38
42int macos_resourcesPath ( char *res, size_t n )
43{
44 NSString *path = [[NSBundle mainBundle] resourcePath];
45 return macos_writeString( path, res, n );
46}
47
48
52static int macos_userLibraryDir ( NSString *kind, char *res, size_t n )
53{
54 NSString *path = [@[
55 NSHomeDirectory(),
56 @"/Library/",
57 kind,
58 @"/org.naev.Naev/"
59 ] componentsJoinedByString:@""];
60 return macos_writeString( path, res, n );
61}
62
63
67int macos_configPath ( char *res, size_t n )
68{
69 return macos_userLibraryDir( @"Preferences", res, n );
70}
71
72
76int macos_cachePath ( char *res, size_t n )
77{
78 return macos_userLibraryDir( @"Caches", res, n );
79}
static int macos_writeString(NSString *str, char *res, size_t n)
Write an NSString to a C buffer.
Definition glue_macos.m:21
int macos_resourcesPath(char *res, size_t n)
Get the path to the bundle resources directory.
Definition glue_macos.m:42
int macos_isBundle(void)
Determine if we're running from inside an app bundle.
Definition glue_macos.m:33
int macos_cachePath(char *res, size_t n)
Get the cache directory path.
Definition glue_macos.m:76
static int macos_userLibraryDir(NSString *kind, char *res, size_t n)
Get the path to the specified user directory.
Definition glue_macos.m:52
int macos_configPath(char *res, size_t n)
Get the config directory path.
Definition glue_macos.m:67