diff options
author | Teddy Wing | 2018-10-25 02:26:49 +0200 |
---|---|---|
committer | Teddy Wing | 2018-10-25 02:26:49 +0200 |
commit | 75593fed6ba244bf3ad68e07fadb880f75c2ef99 (patch) | |
tree | 95cad7ac35b2b2223d91c43cce27a34effc87d40 | |
parent | 40425fa0d211e879f93a282472b5a90906d9668f (diff) | |
download | DomeKey-75593fed6ba244bf3ad68e07fadb880f75c2ef99.tar.bz2 |
XDG: Add methods to get the XDG_DATA_HOME path
Gets the path from the environment variable or uses the default path.
Additionally provides a method for getting the "dome-key" subdirectory
in XDG_DATA_HOME.
-rw-r--r-- | DomeKey/XDG.h | 3 | ||||
-rw-r--r-- | DomeKey/XDG.m | 22 |
2 files changed, 25 insertions, 0 deletions
diff --git a/DomeKey/XDG.h b/DomeKey/XDG.h index a633fa7..de020b5 100644 --- a/DomeKey/XDG.h +++ b/DomeKey/XDG.h @@ -10,4 +10,7 @@ @interface XDG : NSObject ++ (NSURL *)dataPath; ++ (NSURL *)domeKeyDataPath; + @end diff --git a/DomeKey/XDG.m b/DomeKey/XDG.m index 5d2b4d1..5127739 100644 --- a/DomeKey/XDG.m +++ b/DomeKey/XDG.m @@ -8,6 +8,28 @@ #import "XDG.h" +static NSString * const DOME_KEY_DIR = @"dome-key"; + @implementation XDG ++ (NSURL *)dataPath +{ + NSString *xdg_data_home = [[[NSProcessInfo processInfo] environment] + objectForKey:@"XDG_DATA_HOME"]; + + if (!xdg_data_home) { + // xdg_data_home = @"~/.local/share"; + xdg_data_home = [@"~/.local/share" stringByExpandingTildeInPath]; + } + + return [NSURL fileURLWithPath:xdg_data_home isDirectory:YES]; +} + ++ (NSURL *)domeKeyDataPath +{ + return [[self dataPath] + URLByAppendingPathComponent:DOME_KEY_DIR + isDirectory:YES]; +} + @end |