summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Preferences.cxx6
-rw-r--r--src/Fl_cocoa.mm40
-rw-r--r--src/drivers/Darwin/Fl_Darwin_System_Driver.cxx20
3 files changed, 43 insertions, 23 deletions
diff --git a/src/Fl_Preferences.cxx b/src/Fl_Preferences.cxx
index 424f0bc87..4ac4d8a69 100644
--- a/src/Fl_Preferences.cxx
+++ b/src/Fl_Preferences.cxx
@@ -923,7 +923,7 @@ Fl_Preferences::RootNode::~RootNode() {
// read a preferences file and construct the group tree and with all entry leafs
int Fl_Preferences::RootNode::read() {
- if (!filename_) // RUNTIME preferences
+ if (!filename_) // RUNTIME preferences, or filename could not be created
return -1;
if ( (root_ & Fl_Preferences::CORE) && !(fileAccess_ & Fl_Preferences::CORE_READ_OK) ) {
prefs_->node->clearDirtyFlags();
@@ -972,7 +972,7 @@ int Fl_Preferences::RootNode::read() {
// write the group tree and all entry leafs
int Fl_Preferences::RootNode::write() {
- if (!filename_) // RUNTIME preferences
+ if (!filename_) // RUNTIME preferences, or filename could not be created
return -1;
if ( (root_ & Fl_Preferences::CORE) && !(fileAccess_ & Fl_Preferences::CORE_WRITE_OK) )
return -1;
@@ -1010,7 +1010,7 @@ int Fl_Preferences::RootNode::write() {
// - copy the path into the buffer at "path"
// - if the resulting path is longer than "pathlen", it will be cropped
char Fl_Preferences::RootNode::getPath( char *path, int pathlen ) {
- if (!filename_) // RUNTIME preferences
+ if (!filename_) // RUNTIME preferences. or filename could not be created
return 1; // return 1 (not -1) to be consistent with fl_make_path()
if (pathlen<=0)
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index b0a13d714..80022fdd4 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -4387,6 +4387,46 @@ int Fl_Darwin_System_Driver::calc_mac_os_version() {
return fl_mac_os_version;
}
+char *Fl_Darwin_System_Driver::preference_rootnode(Fl_Preferences *prefs, Fl_Preferences::Root root,
+ const char *vendor, const char *application)
+{
+ static char *filename = 0L;
+
+ // Allocate this only when we need it, but then keep it allocated.
+ if (!filename) filename = (char*)::calloc(1, FL_PATH_MAX);
+
+ switch (root&Fl_Preferences::ROOT_MASK) {
+ case Fl_Preferences::SYSTEM:
+ // This is safe, even on machines that use different languages
+ strcpy(filename, "/Library/Preferences");
+ break;
+ case Fl_Preferences::USER:
+ { // Find the home directory, but return NULL if components were not found.
+ // If we ever port this to iOS: this returns tha location of the app!
+ NSString *nsHome = NSHomeDirectory();
+ if (!nsHome) return 0L;
+ const char *cHome = [nsHome UTF8String];
+ if (!cHome) return 0L;
+ snprintf(filename, FL_PATH_MAX, "%s/Library/Preferences", cHome);
+ break; }
+ }
+
+ // Make sure that the parameters are not NULL
+ if ( (vendor==0L) || (vendor[0]==0) )
+ vendor = "unknown";
+ if ( (application==0L) || (application[0]==0) )
+ application = "unknown";
+
+ // Our C path names for preferences will be:
+ // SYSTEM: "/Library/Preferences/$vendor/$application.prefs"
+ // SYSTEM: "/Users/$user/Preferences/$vendor/$application.prefs"
+ snprintf(filename + strlen(filename), FL_PATH_MAX - strlen(filename),
+ "/%s/%s.prefs", vendor, application);
+
+ return filename;
+}
+
+
//
// End of "$Id$".
//
diff --git a/src/drivers/Darwin/Fl_Darwin_System_Driver.cxx b/src/drivers/Darwin/Fl_Darwin_System_Driver.cxx
index 754f29342..548b0287a 100644
--- a/src/drivers/Darwin/Fl_Darwin_System_Driver.cxx
+++ b/src/drivers/Darwin/Fl_Darwin_System_Driver.cxx
@@ -242,26 +242,6 @@ void Fl_Darwin_System_Driver::newUUID(char *uuidBuffer)
CFRelease(theUUID);
}
-char *Fl_Darwin_System_Driver::preference_rootnode(Fl_Preferences *prefs, Fl_Preferences::Root root,
- const char *vendor, const char *application)
-{
- static char filename[ FL_PATH_MAX ];
- // TODO: verify that this is the Apple sanctioned way of finding these folders
- // (On Windows, this frequently leads to issues with internationalized systems)
- // Carbon: err = FindFolder( kLocalDomain, kPreferencesFolderType, 1, &spec.vRefNum, &spec.parID );
- switch (root&Fl_Preferences::ROOT_MASK) {
- case Fl_Preferences::SYSTEM:
- strcpy(filename, "/Library/Preferences");
- break;
- case Fl_Preferences::USER:
- sprintf(filename, "%s/Library/Preferences", getenv("HOME"));
- break;
- }
- snprintf(filename + strlen(filename), sizeof(filename) - strlen(filename),
- "/%s/%s.prefs", vendor, application);
- return filename;
-}
-
/*
* returns pointer to the filename, or null if name ends with ':'
*/