示例#1
0
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;
}
示例#2
0
DecorInfoUtility::DecorInfoUtility(bool scanNow)
	:
	fHasScanned(false)
{
	// get default decorator from app_server
	DecorInfo* info = new(std::nothrow) DecorInfo("Default");
	if (info == NULL || info->InitCheck() != B_OK)	{
		delete info;
		fprintf(stderr, "DecorInfoUtility::constructor\tdefault decorator's "
			"DecorInfo failed InitCheck()\n");
		return;
	}

	fList.AddItem(info);

	if (scanNow)
		ScanDecorators();
}
示例#3
0
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;
}