예제 #1
0
RSExport RSErrorRef RSErrorCreateWithKeysAndValues(RSAllocatorRef allocator, RSStringRef domain, RSIndex code, const void** keys, const void** values, RSIndex userInfoValuesCount)
{
    RSDictionaryRef userInfo = RSDictionaryCreate(allocator, keys, values, RSDictionaryRSTypeContext, userInfoValuesCount);
    RSErrorRef err = RSErrorCreate(allocator, domain, code, userInfo);
    RSRelease(userInfo);
    return err;
}
BOOL __RSFileManagerContentsDirectory(RSFileManagerRef fmg, RSStringRef path, __autorelease RSErrorRef* error, __RSFileManagerContentsContext* context, BOOL shouldRecursion)
{
    DIR *db;
    char filename[2*RSMaxPathSize] = {0};
    struct dirent *p = nil;
    memcpy(filename, RSStringGetCStringPtr(path, RSStringEncodingMacRoman), RSStringGetLength(path));
    db = opendir(filename);
    if (db == nil)
    {
        if (error)
        {
            RSDictionaryRef userInfo = RSDictionaryCreate(RSAllocatorSystemDefault, (const void**)RSErrorTargetKey, (const void**)&path, 1, RSDictionaryRSTypeContext);
            *error = RSErrorCreate(RSAllocatorSystemDefault, RSErrorDomainRSCoreFoundation, kErrExisting, userInfo);
            RSRelease(userInfo);
            RSAutorelease(*error);
        }
        return NO;
    }
    memset(filename, 0, 2*RSMaxPathSize);
    RSStringRef _fileNameStr = nil;
    RSStringRef _dirPath = nil;
    BOOL success = NO;
    while ((p = readdir(db)))
    {
        if((strcmp(p->d_name, ".") == 0) ||
           (strcmp(p->d_name, "..") == 0))
            continue;
        if (RSStringGetLength(path) > 0)
        {
            if (RSStringGetCStringPtr(path, RSStringEncodingMacRoman)[RSStringGetLength(path) - 1] == '/')
                sprintf(filename,"%s%s", RSStringGetCStringPtr(path, RSStringEncodingMacRoman), p->d_name);
            else
                sprintf(filename,"%s/%s", RSStringGetCStringPtr(path, RSStringEncodingMacRoman), p->d_name);
        }
        else
            sprintf(filename,"%s/%s", RSStringGetCStringPtr(path, RSStringEncodingUTF8), p->d_name);
        _fileNameStr = RSStringCreateWithCString(RSAllocatorSystemDefault, p->d_name, RSStringEncodingMacRoman);
        __RSFileManagerContentContextAddContent(context, _fileNameStr);
        if (p->d_type & DT_DIR && shouldRecursion)
        {
            _dirPath = RSStringCreateWithCString(RSAllocatorSystemDefault, filename, RSStringEncodingMacRoman);
#if !__RSFileManagerContentsContextDoNotUseRSArray
            __RSFileManagerContentContextUpdateDirStack(context, _fileNameStr);
#endif
            success = __RSFileManagerContentsDirectory(fmg, _dirPath, error, context, shouldRecursion);
#if !__RSFileManagerContentsContextDoNotUseRSArray
            __RSFileManagerContentContextUpdateDirStack(context, nil);
#endif
            RSRelease(_dirPath);
            _dirPath = nil;
            if (success == NO) return success;
        }
        RSRelease(_fileNameStr);
        _fileNameStr = nil;
    }
    closedir(db);
    return YES;
}
예제 #3
0
RSExport RSDictionaryRef RSErrorCopyUserInfo(RSErrorRef err)
{
    __RSAssertIsError(err);
    return (err->_userInfo) ? RSRetain(err->_userInfo) : RSDictionaryCreate(RSAllocatorSystemDefault, nil, nil, RSDictionaryRSTypeContext, 0);
}
RSExport RSDictionaryRef RSDictionaryWithKeysAndValues(const void** keys, const void** values, const RSDictionaryContext* context, RSIndex count)
{
    return RSAutorelease(RSDictionaryCreate(RSAllocatorSystemDefault, keys, values, count, context));
}