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; }
status_t DecorInfoUtility::ScanDecorators() { BPath decorPath; 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()); ret = dir.InitCheck(); if (ret != B_OK) { fprintf(stderr, "DecorInfoUtility::ScanDecorators:\tERROR: " "DECORATORS_DIR not found!\n"); return ret; } 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; } } } BPath path; entry_ref ref; // Now, look at file system, skip the entries for which we already have // a DecorInfo in the list. while (dir.GetNextRef(&ref) == B_OK) { path.SetTo(decorPath.Path()); path.Append(ref.name); 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); } fHasScanned = true; return B_OK; }