summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Weidauer <sven.weidauer@gmail.com>2011-01-17 16:18:14 +0000
committerSven Weidauer <sven.weidauer@gmail.com>2011-01-17 16:18:14 +0000
commit583047def6d7167e005a19037ac9057bac65aad8 (patch)
treea99cb2b311477008b18a2a0a680b0b18314a9dcd
parent045183032f29bdb2211bd2933dd318342fecf041 (diff)
downloadnetsurf-583047def6d7167e005a19037ac9057bac65aad8.tar.gz
netsurf-583047def6d7167e005a19037ac9057bac65aad8.tar.bz2
Getting a real path for the options file
svn path=/trunk/netsurf/; revision=11350
-rw-r--r--cocoa/gui.m32
1 files changed, 30 insertions, 2 deletions
diff --git a/cocoa/gui.m b/cocoa/gui.m
index 80ab9cb2a..100ee7ff6 100644
--- a/cocoa/gui.m
+++ b/cocoa/gui.m
@@ -27,6 +27,7 @@
#import "desktop/options.h"
#import "desktop/textinput.h"
#import "desktop/selection.h"
+#import "utils/utils.h"
char *default_stylesheet_url;
char *adblock_stylesheet_url;
@@ -306,13 +307,40 @@ static char *gui_get_resource_url( NSString *name, NSString *type )
return strdup( [[[NSURL fileURLWithPath: path] absoluteString] UTF8String] );
}
-int main( int argc, char **argv )
+static NSString *cocoa_get_preferences_path()
{
- char options[PATH_MAX];
+ NSArray *paths = NSSearchPathForDirectoriesInDomains( NSApplicationSupportDirectory, NSUserDomainMask, YES );
+ NSCAssert( [paths count] >= 1, @"Where is the application support directory?" );
+
+ NSString *netsurfPath = [[paths objectAtIndex: 0] stringByAppendingPathComponent: @"NetSurf"];
+
+ NSFileManager *fm = [NSFileManager defaultManager];
+ BOOL isDirectory = NO;
+ BOOL exists = [fm fileExistsAtPath: netsurfPath isDirectory: &isDirectory];
+
+ if (!exists) {
+ exists = [fm createDirectoryAtPath: netsurfPath attributes: nil];
+ isDirectory = YES;
+ }
+ if (!(exists && isDirectory)) {
+ die( "Cannot create netsurf preferences directory" );
+ }
+
+ return netsurfPath;
+}
+
+static const char *cocoa_get_options_file()
+{
+ NSString *prefPath = [cocoa_get_preferences_path() stringByAppendingPathComponent: @"options"];
+ return [prefPath UTF8String];
+}
+int main( int argc, char **argv )
+{
gui_pool = [[NSAutoreleasePool alloc] init];
const char * const messages = [[[NSBundle mainBundle] pathForResource: @"messages" ofType: nil] UTF8String];
+ const char * const options = cocoa_get_options_file();
default_stylesheet_url = gui_get_resource_url( @"default", @"css" );
quirks_stylesheet_url = gui_get_resource_url( @"quirks", @"css" );
adblock_stylesheet_url = gui_get_resource_url( @"adblock", @"css" );