/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. // All fields should be in network order. See CoreServices/CarbonCore/Finder.h
  39. // for details on what flags and extendedFlags can be.
  40. #pragma pack(push, 1)
  41. typedef struct {
  42. union {
  43. struct {
  44. UInt32 type;
  45. UInt32 creator;
  46. } fileInfo;
  47. struct {
  48. UInt16 y1; // Top left of window.
  49. UInt16 x1;
  50. UInt16 y2; // Bottom right of window.
  51. UInt16 x2;
  52. } dirInfo;
  53. } fileOrDirInfo;
  54. UInt16 flags; // Finder flags.
  55. struct {
  56. UInt16 y;
  57. UInt16 x;
  58. } location;
  59. UInt16 reserved;
  60. } GenericFinderInfo;
  61. typedef struct {
  62. UInt32 ignored0;
  63. UInt32 ignored1;
  64. UInt16 extendedFlags; // Extended finder flags.
  65. UInt16 ignored3;
  66. UInt32 ignored4;
  67. } GenericExtendedFinderInfo;
  68. typedef struct {
  69. GenericFinderInfo base;
  70. GenericExtendedFinderInfo extended;
  71. } PackedFinderInfo;
  72. #pragma pack(pop)
  73. @implementation GMFinderInfo
  74. + (GMFinderInfo *)finderInfo {
  75. return [[[GMFinderInfo alloc] init] autorelease];
  76. }
  77. - (id)init {
  78. if ((self = [super init])) {
  79. flags_ = 0;
  80. extendedFlags_ = 0;
  81. typeCode_ = 0;
  82. creatorCode_ = 0;
  83. }
  84. return self;
  85. }
  86. - (void)setFlags:(UInt16)flags {
  87. flags_ = flags;
  88. }
  89. - (void)setExtendedFlags:(UInt16)extendedFlags {
  90. extendedFlags_ = extendedFlags;
  91. }
  92. - (void)setTypeCode:(OSType)typeCode {
  93. typeCode_ = typeCode;
  94. }
  95. - (void)setCreatorCode:(OSType)creatorCode {
  96. creatorCode_ = creatorCode;
  97. }
  98. - (NSData *)data {
  99. PackedFinderInfo info;
  100. assert(sizeof(info) == 32);
  101. memset(&info, 0, sizeof(info));
  102. info.base.fileOrDirInfo.fileInfo.type = htonl(typeCode_);
  103. info.base.fileOrDirInfo.fileInfo.creator = htonl(creatorCode_);
  104. info.base.flags = htons(flags_);
  105. info.extended.extendedFlags = htons(extendedFlags_);
  106. return [NSData dataWithBytes:&info length:sizeof(info)];
  107. }
  108. + (NSData *)finderInfoWithFinderFlags:(UInt16)flags {
  109. return [GMFinderInfo finderInfoWithFinderFlags:flags
  110. typeCode:0
  111. creatorCode:0];
  112. }
  113. + (NSData *)finderInfoWithFinderFlags:(UInt16)flags
  114. typeCode:(OSType)typeCode
  115. creatorCode:(OSType)creatorCode {
  116. GMFinderInfo* info = [GMFinderInfo finderInfo];
  117. [info setFlags:flags];
  118. [info setTypeCode:typeCode];
  119. [info setCreatorCode:creatorCode];
  120. return [info data];
  121. }
  122. @end