From d8c022250dcfaaf6cba80a709147f5d626108492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sat, 7 Nov 2015 20:46:45 +0100 Subject: [PATCH] BMailAccountSettings: use BPathFinder. * This allows to put add-ons in non-packaged folders, too. * Also, Set{In|Out}boundAddOn() only ever looked in the system dir. --- headers/os/mail/MailSettings.h | 2 + src/kits/mail/MailSettings.cpp | 69 +++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 30 deletions(-) diff --git a/headers/os/mail/MailSettings.h b/headers/os/mail/MailSettings.h index eac7c85d307..26b63366d72 100644 --- a/headers/os/mail/MailSettings.h +++ b/headers/os/mail/MailSettings.h @@ -171,6 +171,8 @@ class BMailAccountSettings { private: status_t _CreateAccountFilePath(); + status_t _GetAddOnRef(const char* subPath, + const char* name, entry_ref& ref); private: status_t fStatus; diff --git a/src/kits/mail/MailSettings.cpp b/src/kits/mail/MailSettings.cpp index 98984203ad1..52cabe4ff55 100644 --- a/src/kits/mail/MailSettings.cpp +++ b/src/kits/mail/MailSettings.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -431,23 +432,24 @@ BMailAddOnSettings::Load(const BMessage& message) return B_BAD_VALUE; BPath path(pathString); - if (!path.IsAbsolute()) { - directory_which which[] = { - B_USER_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; + if (!path.IsAbsolute()) { + BStringList paths; + BPathFinder().FindPaths(B_FIND_PATH_ADD_ONS_DIRECTORY, "mail_daemon", + paths); - path.Append("mail_daemon"); - path.Append(pathString); + status_t status = B_ENTRY_NOT_FOUND; - if (BEntry(path.Path()).Exists()) + for (int32 i = 0; i < paths.CountStrings(); i++) { + path.SetTo(paths.StringAt(i), pathString); + BEntry entry(path.Path()); + if (entry.Exists()) { + status = B_OK; break; + } } + if (status != B_OK) + return status; } status_t status = get_ref_for_path(path.Path(), &fRef); @@ -737,17 +739,11 @@ BMailAccountSettings::ReturnAddress() const bool BMailAccountSettings::SetInboundAddOn(const char* name) { - BPath path; - status_t status = find_directory(B_BEOS_ADDONS_DIRECTORY, &path); - if (status != B_OK) - return false; - path.Append("mail_daemon"); - path.Append("inbound_protocols"); - path.Append(name); entry_ref ref; - get_ref_for_path(path.Path(), &ref); - fInboundSettings.SetAddOnRef(ref); + if (_GetAddOnRef("mail_daemon/inbound_protocols", name, ref) != B_OK) + return false; + fInboundSettings.SetAddOnRef(ref); return true; } @@ -755,17 +751,11 @@ BMailAccountSettings::SetInboundAddOn(const char* name) bool BMailAccountSettings::SetOutboundAddOn(const char* name) { - BPath path; - status_t status = find_directory(B_BEOS_ADDONS_DIRECTORY, &path); - if (status != B_OK) - return false; - path.Append("mail_daemon"); - path.Append("outbound_protocols"); - path.Append(name); entry_ref ref; - get_ref_for_path(path.Path(), &ref); - fOutboundSettings.SetAddOnRef(ref); + if (_GetAddOnRef("mail_daemon/outbound_protocols", name, ref) != B_OK) + return false; + fOutboundSettings.SetAddOnRef(ref); return true; } @@ -980,3 +970,22 @@ BMailAccountSettings::_CreateAccountFilePath() path.Append(fileName); return fAccountFile.SetTo(path.Path()); } + + +status_t +BMailAccountSettings::_GetAddOnRef(const char* subPath, const char* name, + entry_ref& ref) +{ + BStringList paths; + BPathFinder().FindPaths(B_FIND_PATH_ADD_ONS_DIRECTORY, subPath, paths); + + for (int32 i = 0; i < paths.CountStrings(); i++) { + BPath path(paths.StringAt(i), name); + BEntry entry(path.Path()); + if (entry.Exists()) { + if (entry.GetRef(&ref) == B_OK) + return B_OK; + } + } + return B_ENTRY_NOT_FOUND; +}