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:
@@ -92,6 +92,9 @@ public:
|
|||||||
|
|
||||||
virtual bool HasBeenModified() const;
|
virtual bool HasBeenModified() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const char* _RelativizePath(const BPath& path) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BMessage fOriginalSettings;
|
BMessage fOriginalSettings;
|
||||||
entry_ref fRef;
|
entry_ref fRef;
|
||||||
|
|||||||
@@ -426,11 +426,32 @@ BMailAddOnSettings::~BMailAddOnSettings()
|
|||||||
status_t
|
status_t
|
||||||
BMailAddOnSettings::Load(const BMessage& message)
|
BMailAddOnSettings::Load(const BMessage& message)
|
||||||
{
|
{
|
||||||
const char* path = NULL;
|
const char* pathString = NULL;
|
||||||
if (message.FindString("add-on path", &path) != B_OK)
|
if (message.FindString("add-on path", &pathString) != B_OK)
|
||||||
return B_BAD_VALUE;
|
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)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
@@ -450,7 +471,7 @@ status_t
|
|||||||
BMailAddOnSettings::Save(BMessage& message)
|
BMailAddOnSettings::Save(BMessage& message)
|
||||||
{
|
{
|
||||||
BPath path(&fRef);
|
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)
|
if (status == B_OK)
|
||||||
status = message.AddMessage("settings", this);
|
status = message.AddMessage("settings", this);
|
||||||
if (status != B_OK)
|
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 -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user