コード例 #1
0
void parseWhereFrom(QueryData &results, const std::string &path) {

  CFStringRef CFPath = CFStringCreateWithCString(
      kCFAllocatorDefault, path.c_str(), kCFStringEncodingUTF8);

  MDItemRef metadata = MDItemCreate(kCFAllocatorDefault, CFPath);
  CFRelease(CFPath);

  if (metadata == nullptr) {
    VLOG(1) << "Metadata for " << path << " is null";
    return;
  }

  CFTypeRef attributes;
  attributes = MDItemCopyAttribute(metadata, kMDItemWhereFroms);
  CFRelease(metadata);

  if (attributes == nullptr) {
    VLOG(1) << "No attributes found for " << path;
    return;
  }

  CFArrayRef attribs = (CFArrayRef)attributes;
  CFIndex count = CFArrayGetCount(attribs);

  for (CFIndex i = 0; i < count; i++) {
    CFStringRef attribute = (CFStringRef)CFArrayGetValueAtIndex(attribs, i);
    auto where_from_attribute = stringFromCFString(attribute);
    if (!where_from_attribute.empty()) {
      setRow(results, path, "where_from", where_from_attribute);
    }
  }

  CFRelease(attributes);
}
コード例 #2
0
ファイル: spotlight.c プロジェクト: xli/spotlight
static MDItemRef createMDItemByPath(VALUE path) {
    CFStringRef pathRef = rbstr2cfstring(path);
    MDItemRef mdi = MDItemCreate(kCFAllocatorDefault, pathRef);
    RELEASE_IF_NOT_NULL(pathRef);
    if (!mdi) {
        rb_raise(rb_eTypeError, "Could not find MDItem by given path");
    }
    return mdi;
}