Update DecorInfo to scan for decorators

Look in system and user packaged and non-packaged decorator directories.
This commit is contained in:
John Scipione
2014-02-20 19:31:49 -05:00
parent b8187adfc7
commit 14aa801ae9
3 changed files with 119 additions and 45 deletions
+1
View File
@@ -298,6 +298,7 @@ SEARCH on <post-install>fresh_install
AddFilesToHaikuImage system settings : <post-install>fresh_install ; AddFilesToHaikuImage system settings : <post-install>fresh_install ;
# decorators # decorators
AddDirectoryToHaikuImage system non-packaged add-ons decorators ;
AddDirectoryToHaikuImage home config non-packaged add-ons decorators ; AddDirectoryToHaikuImage home config non-packaged add-ons decorators ;
#AddFilesToHaikuImage home config add-ons decorators : ; #AddFilesToHaikuImage home config add-ons decorators : ;
+3
View File
@@ -8,6 +8,7 @@
#define DECOR_INFO_H #define DECOR_INFO_H
#include <Directory.h>
#include <Entry.h> #include <Entry.h>
#include <Locker.h> #include <Locker.h>
#include <ObjectList.h> #include <ObjectList.h>
@@ -121,6 +122,8 @@ public:
private: private:
DecorInfo* _FindDecor(const BString& path); DecorInfo* _FindDecor(const BString& path);
status_t _ScanDecorators(BDirectory decoratorDirectory);
private: private:
BObjectList<DecorInfo> fList; BObjectList<DecorInfo> fList;
BLocker fLock; BLocker fLock;
+115 -45
View File
@@ -12,7 +12,6 @@
#include <stdio.h> #include <stdio.h>
#include <Autolock.h> #include <Autolock.h>
#include <Directory.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <Path.h> #include <Path.h>
#include <Resources.h> #include <Resources.h>
@@ -273,7 +272,7 @@ DecorInfo::_Init(bool isUpdate)
// and, thusly, the Default decorator... // and, thusly, the Default decorator...
// If you can make it more simple, please do! // If you can make it more simple, please do!
BPath path; BPath path;
find_directory(B_BEOS_SERVERS_DIRECTORY, &path); find_directory(B_SYSTEM_SERVERS_DIRECTORY, &path);
path.Append("app_server"); path.Append("app_server");
entry.SetTo(path.Path(), true); entry.SetTo(path.Path(), true);
if (!entry.Exists()) { if (!entry.Exists()) {
@@ -374,58 +373,80 @@ DecorInfoUtility::~DecorInfoUtility()
status_t status_t
DecorInfoUtility::ScanDecorators() DecorInfoUtility::ScanDecorators()
{ {
BPath decorPath; status_t result;
status_t ret = find_directory(B_USER_ADDONS_DIRECTORY, &decorPath);
if (ret != B_OK)
return ret;
ret = decorPath.Append("decorators");
if (ret != B_OK)
return ret;
BDirectory dir(decorPath.Path()); BPath systemPath;
ret = dir.InitCheck(); result = find_directory(B_SYSTEM_ADDONS_DIRECTORY, &systemPath);
if (ret != B_OK) { if (result == B_OK)
fprintf(stderr, "DecorInfoUtility::ScanDecorators:\tERROR: " result = systemPath.Append("decorators");
"DECORATORS_DIR not found!\n");
return ret;
}
BAutolock _(fLock); if (result == B_OK) {
// First, run through our list and DecorInfos CheckForChanges() BDirectory systemDirectory(systemPath.Path());
result = systemDirectory.InitCheck();
if (fHasScanned) { if (result == B_OK) {
for (int i = fList.CountItems() - 1; i > 0; --i) { result = _ScanDecorators(systemDirectory);
DecorInfo* decorInfo = fList.ItemAt(i); if (result != B_OK) {
fprintf(stderr, "DecorInfoUtility::ScanDecorators()\tERROR: %s\n",
bool deleted = false; strerror(result));
decorInfo->CheckForChanges(deleted); return result;
if (deleted) {
fList.RemoveItem(decorInfo);
delete decorInfo;
} }
} }
} }
BPath path; BPath systemNonPackagedPath;
entry_ref ref; result = find_directory(B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY,
// Now, look at file system, skip the entries for which we already have &systemNonPackagedPath);
// a DecorInfo in the list. if (result == B_OK)
while (dir.GetNextRef(&ref) == B_OK) { result = systemNonPackagedPath.Append("decorators");
path.SetTo(decorPath.Path());
path.Append(ref.name);
if (_FindDecor(path.Path()) != NULL)
continue;
DecorInfo* decorInfo = new(std::nothrow) DecorInfo(ref); if (result == B_OK) {
if (decorInfo == NULL || decorInfo->InitCheck() != B_OK) { BDirectory systemNonPackagedDirectory(systemNonPackagedPath.Path());
fprintf(stderr, "DecorInfoUtility::ScanDecorators()\tInitCheck() " result = systemNonPackagedDirectory.InitCheck();
"failure on decorator, skipping\n"); if (result == B_OK) {
delete decorInfo; result = _ScanDecorators(systemNonPackagedDirectory);
continue; if (result != B_OK) {
fprintf(stderr, "DecorInfoUtility::ScanDecorators()\tERROR: %s\n",
strerror(result));
return result;
}
} }
}
fList.AddItem(decorInfo); BPath userPath;
result = find_directory(B_USER_ADDONS_DIRECTORY, &userPath);
if (result == B_OK)
result = userPath.Append("decorators");
if (result == B_OK) {
BDirectory userDirectory(userPath.Path());
result = userDirectory.InitCheck();
if (result == B_OK) {
result = _ScanDecorators(userDirectory);
if (result != B_OK) {
fprintf(stderr, "DecorInfoUtility::ScanDecorators()\tERROR: %s\n",
strerror(result));
return result;
}
}
}
BPath userNonPackagedPath;
result = find_directory(B_USER_NONPACKAGED_ADDONS_DIRECTORY,
&userNonPackagedPath);
if (result == B_OK)
result = userNonPackagedPath.Append("decorators");
if (result == B_OK) {
BDirectory userNonPackagedDirectory(userNonPackagedPath.Path());
result = userNonPackagedDirectory.InitCheck();
if (result == B_OK) {
result = _ScanDecorators(userNonPackagedDirectory);
if (result != B_OK) {
fprintf(stderr, "DecorInfoUtility::ScanDecorators()\tERROR: %s\n",
strerror(result));
return result;
}
}
} }
fHasScanned = true; fHasScanned = true;
@@ -586,4 +607,53 @@ DecorInfoUtility::_FindDecor(const BString& pathString)
} }
status_t
DecorInfoUtility::_ScanDecorators(BDirectory decoratorDirectory)
{
BAutolock _(fLock);
// First, run through our list and DecorInfos CheckForChanges()
if (fHasScanned) {
for (int i = fList.CountItems() - 1; i > 0; --i) {
DecorInfo* decorInfo = fList.ItemAt(i);
bool deleted = false;
decorInfo->CheckForChanges(deleted);
if (deleted) {
fList.RemoveItem(decorInfo);
delete decorInfo;
}
}
}
entry_ref ref;
// Now, look at file system, skip the entries for which we already have
// a DecorInfo in the list.
while (decoratorDirectory.GetNextRef(&ref) == B_OK) {
BPath path(&decoratorDirectory);
status_t result = path.Append(ref.name);
if (result != B_OK) {
fprintf(stderr, "DecorInfoUtility::_ScanDecorators()\tFailed to"
"append decorator file to path, skipping: %s.\n", strerror(result));
continue;
}
if (_FindDecor(path.Path()) != NULL)
continue;
DecorInfo* decorInfo = new(std::nothrow) DecorInfo(ref);
if (decorInfo == NULL || decorInfo->InitCheck() != B_OK) {
fprintf(stderr, "DecorInfoUtility::_ScanDecorators()\tInitCheck() "
"failure on decorator, skipping.\n");
delete decorInfo;
continue;
}
fList.AddItem(decorInfo);
}
return B_OK;
}
} // namespace BPrivate } // namespace BPrivate