From f90a3bbd67be2e5f3aa32afcbbeff7ce36dfe531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 4 Nov 2012 17:27:11 +0100 Subject: [PATCH] Added support for letting user mail add-ons override system ones. * The path will now be relativized before storing it. * On load, the add-on will be tried to load from the user, then common and finally system add-on directory. --- headers/os/mail/MailSettings.h | 3 +++ src/kits/mail/MailSettings.cpp | 45 +++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/headers/os/mail/MailSettings.h b/headers/os/mail/MailSettings.h index 3e781490bc..eac7c85d30 100644 --- a/headers/os/mail/MailSettings.h +++ b/headers/os/mail/MailSettings.h @@ -92,6 +92,9 @@ public: virtual bool HasBeenModified() const; +private: + const char* _RelativizePath(const BPath& path) const; + private: BMessage fOriginalSettings; entry_ref fRef; diff --git a/src/kits/mail/MailSettings.cpp b/src/kits/mail/MailSettings.cpp index 2ea990d3ae..6f906b6eed 100644 --- a/src/kits/mail/MailSettings.cpp +++ b/src/kits/mail/MailSettings.cpp @@ -426,11 +426,32 @@ BMailAddOnSettings::~BMailAddOnSettings() status_t BMailAddOnSettings::Load(const BMessage& message) { - const char* path = NULL; - if (message.FindString("add-on path", &path) != B_OK) + const char* pathString = NULL; + if (message.FindString("add-on path", &pathString) != B_OK) return B_BAD_VALUE; - status_t status = get_ref_for_path(path, &fRef); + BPath path(pathString); + if (!path.IsAbsolute()) { + directory_which which[] = { + B_USER_ADDONS_DIRECTORY, + B_COMMON_ADDONS_DIRECTORY, + B_SYSTEM_ADDONS_DIRECTORY + }; + + for (size_t i = 0; i < sizeof(which) / sizeof(which[0]); i++) { + status_t status = find_directory(which[i], &path); + if (status != B_OK) + continue; + + path.Append("mail_daemon"); + path.Append(pathString); + + if (BEntry(path.Path()).Exists()) + break; + } + } + + status_t status = get_ref_for_path(path.Path(), &fRef); if (status != B_OK) return status; @@ -450,7 +471,7 @@ status_t BMailAddOnSettings::Save(BMessage& message) { BPath path(&fRef); - status_t status = message.AddString("add-on path", path.Path()); + status_t status = message.AddString("add-on path", _RelativizePath(path)); if (status == B_OK) status = message.AddMessage("settings", this); if (status != B_OK) @@ -484,6 +505,22 @@ BMailAddOnSettings::HasBeenModified() const } +/*! Cuts off the ".../add-ons/mail_daemon" part of the provided \a path + in case it exists. Otherwise, the complete path will be returned. +*/ +const char* +BMailAddOnSettings::_RelativizePath(const BPath& path) const +{ + const char* string = path.Path(); + const char* parentDirectory = "/mail_daemon/"; + const char* at = strstr(string, parentDirectory); + if (at == NULL) + return string; + + return at + strlen(parentDirectory); +} + + // #pragma mark -