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.
This commit is contained in:
Axel Dörfler 2012-11-04 17:27:11 +01:00
parent b448d260c3
commit f90a3bbd67
2 changed files with 44 additions and 4 deletions

View File

@ -92,6 +92,9 @@ public:
virtual bool HasBeenModified() const;
private:
const char* _RelativizePath(const BPath& path) const;
private:
BMessage fOriginalSettings;
entry_ref fRef;

View File

@ -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 -