Tracker: Use BPathFinder to find add-ons

This commit is contained in:
John Scipione
2014-06-14 20:48:15 -04:00
parent 6cf062b93d
commit 1f17f750db
+22 -39
View File
@@ -38,11 +38,14 @@ All rights reserved.
#include <Locale.h>
#include <NodeMonitor.h>
#include <Path.h>
#include <PathFinder.h>
#include <PathMonitor.h>
#include <PopUpMenu.h>
#include <Resources.h>
#include <Roster.h>
#include <Screen.h>
#include <String.h>
#include <StringList.h>
#include <Volume.h>
#include <VolumeRoster.h>
@@ -126,20 +129,11 @@ FindElement(struct AddonShortcut* item, void* castToOther)
static void
LoadAddOnDir(directory_which dirName, BDeskWindow* window,
LoadAddOnDir(BDirectory directory, BDeskWindow* window,
LockingList<AddonShortcut>* list)
{
BPath path;
if (find_directory(dirName, &path) == B_OK) {
path.Append("Tracker");
BDirectory dir;
BEntry entry;
if (dir.SetTo(path.Path()) != B_OK)
return;
while (dir.GetNextEntry(&entry) == B_OK) {
while (directory.GetNextEntry(&entry) == B_OK) {
Model* model = new Model(&entry);
if (model->InitCheck() == B_OK && model->IsSymLink()) {
// resolve symlinks
@@ -176,13 +170,12 @@ LoadAddOnDir(directory_which dirName, BDeskWindow* window,
free(name);
}
BNode node(path.Path());
BNode node(&directory, NULL);
node_ref nodeRef;
node.GetNodeRef(&nodeRef);
TTracker::WatchNode(&nodeRef, B_WATCH_DIRECTORY, window);
}
}
// #pragma mark - BDeskWindow
@@ -279,10 +272,13 @@ BDeskWindow::InitAddonsList(bool update)
fAddonsList->MakeEmpty(true);
}
LoadAddOnDir(B_USER_NONPACKAGED_ADDONS_DIRECTORY, this, fAddonsList);
LoadAddOnDir(B_USER_ADDONS_DIRECTORY, this, fAddonsList);
LoadAddOnDir(B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY, this, fAddonsList);
LoadAddOnDir(B_SYSTEM_ADDONS_DIRECTORY, this, fAddonsList);
BStringList addOnPaths;
BPathFinder::FindPaths(B_FIND_PATH_ADD_ONS_DIRECTORY, "Tracker/",
addOnPaths);
for (int32 i = 0; i < addOnPaths.CountStrings(); i++) {
LoadAddOnDir(BDirectory(addOnPaths.StringAt(i)), this,
fAddonsList);
}
}
}
@@ -324,31 +320,18 @@ BDeskWindow::ApplyShortcutPreferences(bool update)
if (message.FindString("command", &command) != B_OK)
continue;
BPath path;
bool isInAddons = false;
if (find_directory(B_SYSTEM_ADDONS_DIRECTORY, &path)
== B_OK) {
path.Append("Tracker/");
isInAddons = command.FindFirst(path.Path()) == 0;
BStringList addOnPaths;
BPathFinder::FindPaths(B_FIND_PATH_ADD_ONS_DIRECTORY,
"Tracker/", addOnPaths);
for (int32 i = 0; i < addOnPaths.CountStrings(); i++) {
if (command.FindFirst(addOnPaths.StringAt(i)) == 0) {
isInAddons = true;
break;
}
if (!isInAddons
&& (find_directory(B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY,
&path) == B_OK)) {
path.Append("Tracker/");
isInAddons = command.FindFirst(path.Path()) == 0;
}
if (!isInAddons
&& (find_directory(B_USER_ADDONS_DIRECTORY, &path)
== B_OK)) {
path.Append("Tracker/");
isInAddons = command.FindFirst(path.Path()) == 0;
}
if (!isInAddons
&& (find_directory(B_USER_NONPACKAGED_ADDONS_DIRECTORY,
&path) == B_OK)) {
path.Append("Tracker/");
isInAddons = command.FindFirst(path.Path()) == 0;
}
if (!isInAddons)
continue;