Media_server: use find_paths_etc.

* Replace code to find the plug-ins with the new APIs.
* Prepare for hybrid-aware code (but we need to use the app
    architecture, not the media_server one)
This commit is contained in:
Adrien Destugues 2014-03-31 17:39:35 +02:00
parent d71e18fef4
commit 48058f7bc9
1 changed files with 37 additions and 26 deletions

View File

@ -14,6 +14,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <Architecture.h>
#include <Autolock.h> #include <Autolock.h>
#include <Directory.h> #include <Directory.h>
#include <Entry.h> #include <Entry.h>
@ -57,14 +58,6 @@ private:
}; };
static const directory_which sDirectories[] = {
B_USER_NONPACKAGED_ADDONS_DIRECTORY,
B_USER_ADDONS_DIRECTORY,
B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY,
B_SYSTEM_ADDONS_DIRECTORY
};
// #pragma mark - // #pragma mark -
@ -125,14 +118,19 @@ AddOnManager::GetDecoderForFormat(xfer_entry_ref* _decoderRef,
// of system add-ons by user add-ons, in case they offer decoders // of system add-ons by user add-ons, in case they offer decoders
// for the same format. // for the same format.
char** directories = NULL;
size_t directoryCount = 0;
if (find_paths_etc(get_architecture(), B_FIND_PATH_ADD_ONS_DIRECTORY,
"media/plugins", B_FIND_PATH_EXISTING_ONLY, &directories,
&directoryCount) != B_OK) {
printf("AddOnManager::GetDecoderForFormat: failed to locate plugins\n");
return B_ENTRY_NOT_FOUND;
}
BPath path; BPath path;
for (uint i = 0; i < sizeof(sDirectories) / sizeof(directory_which); i++) { for (uint i = 0; i < directoryCount; i++) {
if (find_directory(sDirectories[i], &path) != B_OK path.SetTo(directories[i]);
|| path.Append("media/plugins") != B_OK) {
printf("AddOnManager::GetDecoderForFormat: failed to construct "
"path for directory %u\n", i);
continue;
}
if (_FindDecoder(format, path, _decoderRef)) if (_FindDecoder(format, path, _decoderRef))
return B_OK; return B_OK;
} }
@ -151,14 +149,19 @@ AddOnManager::GetReaders(xfer_entry_ref* outRefs, int32* outCount,
// See GetDecoderForFormat() for why we need to scan the list by path. // See GetDecoderForFormat() for why we need to scan the list by path.
char** directories = NULL;
size_t directoryCount = 0;
if (find_paths_etc(get_architecture(), B_FIND_PATH_ADD_ONS_DIRECTORY,
"media/plugins", B_FIND_PATH_EXISTING_ONLY, &directories,
&directoryCount) != B_OK) {
printf("AddOnManager::GetReaders: failed to locate plugins\n");
return B_ENTRY_NOT_FOUND;
}
BPath path; BPath path;
for (uint i = 0; i < sizeof(sDirectories) / sizeof(directory_which); i++) { for (uint i = 0; i < directoryCount; i++) {
if (find_directory(sDirectories[i], &path) != B_OK path.SetTo(directories[i]);
|| path.Append("media/plugins") != B_OK) {
printf("AddOnManager::GetReaders: failed to construct "
"path for directory %u\n", i);
continue;
}
_GetReaders(path, outRefs, outCount, maxCount); _GetReaders(path, outRefs, outCount, maxCount);
} }
@ -302,16 +305,24 @@ AddOnManager::_RegisterAddOns()
|| !strcasecmp(buffer, "enabled") || !strcasecmp(buffer, "enabled")
|| !strcmp(buffer, "1")); || !strcmp(buffer, "1"));
char** directories = NULL;
size_t directoryCount = 0;
if (find_paths_etc(get_architecture(), B_FIND_PATH_ADD_ONS_DIRECTORY,
"media/plugins", B_FIND_PATH_EXISTING_ONLY, &directories,
&directoryCount) != B_OK) {
printf("AddOnManager::RegisterAddOns: failed to locate plugins\n");
return;
}
node_ref nref; node_ref nref;
BDirectory directory; BDirectory directory;
BPath path; BPath path;
for (uint i = 0; i < sizeof(sDirectories) / sizeof(directory_which); i++) { for (uint i = 0; i < directoryCount; i++) {
if (disableUserAddOns && i <= 1) if (disableUserAddOns && i <= 1)
continue; continue;
if (find_directory(sDirectories[i], &path) == B_OK if (directory.SetTo(directories[i]) == B_OK
&& path.Append("media/plugins") == B_OK
&& directory.SetTo(path.Path()) == B_OK
&& directory.GetNodeRef(&nref) == B_OK) { && directory.GetNodeRef(&nref) == B_OK) {
fAddOnMonitorHandler->AddDirectory(&nref); fAddOnMonitorHandler->AddDirectory(&nref);
// NOTE: This may already start registering add-ons in the // NOTE: This may already start registering add-ons in the