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

View File

@ -38,11 +38,14 @@ All rights reserved.
#include <Locale.h> #include <Locale.h>
#include <NodeMonitor.h> #include <NodeMonitor.h>
#include <Path.h> #include <Path.h>
#include <PathFinder.h>
#include <PathMonitor.h> #include <PathMonitor.h>
#include <PopUpMenu.h> #include <PopUpMenu.h>
#include <Resources.h> #include <Resources.h>
#include <Roster.h> #include <Roster.h>
#include <Screen.h> #include <Screen.h>
#include <String.h>
#include <StringList.h>
#include <Volume.h> #include <Volume.h>
#include <VolumeRoster.h> #include <VolumeRoster.h>
@ -126,62 +129,52 @@ FindElement(struct AddonShortcut* item, void* castToOther)
static void static void
LoadAddOnDir(directory_which dirName, BDeskWindow* window, LoadAddOnDir(BDirectory directory, BDeskWindow* window,
LockingList<AddonShortcut>* list) LockingList<AddonShortcut>* list)
{ {
BPath path; BEntry entry;
if (find_directory(dirName, &path) == B_OK) { while (directory.GetNextEntry(&entry) == B_OK) {
path.Append("Tracker"); Model* model = new Model(&entry);
if (model->InitCheck() == B_OK && model->IsSymLink()) {
BDirectory dir; // resolve symlinks
BEntry entry; Model* resolved = new Model(model->EntryRef(), true, true);
if (resolved->InitCheck() == B_OK)
if (dir.SetTo(path.Path()) != B_OK) model->SetLinkTo(resolved);
return; else
delete resolved;
while (dir.GetNextEntry(&entry) == B_OK) { }
Model* model = new Model(&entry); if (model->InitCheck() != B_OK
if (model->InitCheck() == B_OK && model->IsSymLink()) { || !model->ResolveIfLink()->IsExecutable()) {
// resolve symlinks delete model;
Model* resolved = new Model(model->EntryRef(), true, true); continue;
if (resolved->InitCheck() == B_OK)
model->SetLinkTo(resolved);
else
delete resolved;
}
if (model->InitCheck() != B_OK
|| !model->ResolveIfLink()->IsExecutable()) {
delete model;
continue;
}
char* name = strdup(model->Name());
if (!list->EachElement(MatchOne, name)) {
struct AddonShortcut* item = new struct AddonShortcut;
item->model = model;
BResources resources(model->ResolveIfLink()->EntryRef());
size_t size;
char* shortcut = (char*)resources.LoadResource(B_STRING_TYPE,
kDefaultShortcut, &size);
if (shortcut == NULL || strlen(shortcut) > 1)
item->key = '\0';
else
item->key = shortcut[0];
AddOneShortcut(model, item->key, kDefaultModifiers, window);
item->defaultKey = item->key;
item->modifiers = kDefaultModifiers;
list->AddItem(item);
}
free(name);
} }
BNode node(path.Path()); char* name = strdup(model->Name());
node_ref nodeRef; if (!list->EachElement(MatchOne, name)) {
node.GetNodeRef(&nodeRef); struct AddonShortcut* item = new struct AddonShortcut;
item->model = model;
TTracker::WatchNode(&nodeRef, B_WATCH_DIRECTORY, window);
BResources resources(model->ResolveIfLink()->EntryRef());
size_t size;
char* shortcut = (char*)resources.LoadResource(B_STRING_TYPE,
kDefaultShortcut, &size);
if (shortcut == NULL || strlen(shortcut) > 1)
item->key = '\0';
else
item->key = shortcut[0];
AddOneShortcut(model, item->key, kDefaultModifiers, window);
item->defaultKey = item->key;
item->modifiers = kDefaultModifiers;
list->AddItem(item);
}
free(name);
} }
BNode node(&directory, NULL);
node_ref nodeRef;
node.GetNodeRef(&nodeRef);
TTracker::WatchNode(&nodeRef, B_WATCH_DIRECTORY, window);
} }
@ -279,10 +272,13 @@ BDeskWindow::InitAddonsList(bool update)
fAddonsList->MakeEmpty(true); fAddonsList->MakeEmpty(true);
} }
LoadAddOnDir(B_USER_NONPACKAGED_ADDONS_DIRECTORY, this, fAddonsList); BStringList addOnPaths;
LoadAddOnDir(B_USER_ADDONS_DIRECTORY, this, fAddonsList); BPathFinder::FindPaths(B_FIND_PATH_ADD_ONS_DIRECTORY, "Tracker/",
LoadAddOnDir(B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY, this, fAddonsList); addOnPaths);
LoadAddOnDir(B_SYSTEM_ADDONS_DIRECTORY, this, fAddonsList); 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) if (message.FindString("command", &command) != B_OK)
continue; continue;
BPath path;
bool isInAddons = false; bool isInAddons = false;
if (find_directory(B_SYSTEM_ADDONS_DIRECTORY, &path)
== B_OK) { BStringList addOnPaths;
path.Append("Tracker/"); BPathFinder::FindPaths(B_FIND_PATH_ADD_ONS_DIRECTORY,
isInAddons = command.FindFirst(path.Path()) == 0; "Tracker/", addOnPaths);
} for (int32 i = 0; i < addOnPaths.CountStrings(); i++) {
if (!isInAddons if (command.FindFirst(addOnPaths.StringAt(i)) == 0) {
&& (find_directory(B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY, isInAddons = true;
&path) == B_OK)) { break;
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) if (!isInAddons)
continue; continue;