PageRenderTime 39ms CodeModel.GetById 15ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 0ms

/core/sdk-objc/GMFinderInfo.m

http://macfuse.googlecode.com/
Objective C | 133 lines | 84 code | 11 blank | 38 comment | 2 complexity | 72540017a80189407f2df8ae83b9b660 MD5 | raw file
  1// ================================================================
  2// Copyright (c) 2007, Google Inc.
  3// All rights reserved.
  4//
  5// Redistribution and use in source and binary forms, with or without
  6// modification, are permitted provided that the following conditions are
  7// met:
  8//
  9// * Redistributions of source code must retain the above copyright
 10//   notice, this list of conditions and the following disclaimer.
 11// * Redistributions in binary form must reproduce the above
 12//   copyright notice, this list of conditions and the following disclaimer
 13//   in the documentation and/or other materials provided with the
 14//   distribution.
 15// * Neither the name of Google Inc. nor the names of its
 16//   contributors may be used to endorse or promote products derived from
 17//   this software without specific prior written permission.
 18//
 19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 20// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 21// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 22// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 23// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 25// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 26// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 27// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 28// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 29// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 30// ================================================================
 31//
 32//  GMFinderInfo.m
 33//  MacFUSE
 34//
 35//  Created by ted on 12/29/07.
 36//
 37#import "GMFinderInfo.h"
 38
 39// All fields should be in network order. See CoreServices/CarbonCore/Finder.h
 40// for details on what flags and extendedFlags can be.
 41#pragma pack(push, 1)
 42typedef struct {
 43  union {
 44    struct {
 45      UInt32 type;
 46      UInt32 creator;
 47    } fileInfo;
 48    struct {
 49      UInt16 y1;  // Top left of window.
 50      UInt16 x1;
 51      UInt16 y2;  // Bottom right of window.
 52      UInt16 x2;
 53    } dirInfo;
 54  } fileOrDirInfo;
 55  UInt16 flags;  // Finder flags.
 56  struct {
 57    UInt16 y;
 58    UInt16 x;
 59  } location;
 60  UInt16 reserved;
 61} GenericFinderInfo;
 62
 63typedef struct {
 64  UInt32 ignored0;
 65  UInt32 ignored1;
 66  UInt16 extendedFlags;  // Extended finder flags.
 67  UInt16 ignored3;
 68  UInt32 ignored4;
 69} GenericExtendedFinderInfo;
 70
 71typedef struct {
 72  GenericFinderInfo base;
 73  GenericExtendedFinderInfo extended;
 74} PackedFinderInfo;
 75#pragma pack(pop)
 76
 77@implementation GMFinderInfo
 78
 79+ (GMFinderInfo *)finderInfo {
 80  return [[[GMFinderInfo alloc] init] autorelease];
 81}
 82
 83- (id)init {
 84  if ((self = [super init])) {
 85    flags_ = 0;
 86    extendedFlags_ = 0;
 87    typeCode_ = 0;
 88    creatorCode_ = 0;
 89  }
 90  return self;
 91}
 92
 93- (void)setFlags:(UInt16)flags {
 94  flags_ = flags;
 95}
 96- (void)setExtendedFlags:(UInt16)extendedFlags {
 97  extendedFlags_ = extendedFlags;
 98}
 99- (void)setTypeCode:(OSType)typeCode {
100  typeCode_ = typeCode;
101}
102- (void)setCreatorCode:(OSType)creatorCode {
103  creatorCode_ = creatorCode;
104}
105
106- (NSData *)data {
107  PackedFinderInfo info;
108  assert(sizeof(info) == 32);
109  memset(&info, 0, sizeof(info));
110  info.base.fileOrDirInfo.fileInfo.type = htonl(typeCode_);
111  info.base.fileOrDirInfo.fileInfo.creator = htonl(creatorCode_);
112  info.base.flags = htons(flags_);
113  info.extended.extendedFlags = htons(extendedFlags_);
114  return [NSData dataWithBytes:&info length:sizeof(info)];    
115}
116
117+ (NSData *)finderInfoWithFinderFlags:(UInt16)flags {
118  return [GMFinderInfo finderInfoWithFinderFlags:flags
119                                        typeCode:0
120                                     creatorCode:0];
121}
122
123+ (NSData *)finderInfoWithFinderFlags:(UInt16)flags
124                             typeCode:(OSType)typeCode
125                          creatorCode:(OSType)creatorCode {
126  GMFinderInfo* info = [GMFinderInfo finderInfo];
127  [info setFlags:flags];
128  [info setTypeCode:typeCode];
129  [info setCreatorCode:creatorCode];
130  return [info data];
131}
132
133@end