/core/sdk-objc/GMResourceFork.h

http://macfuse.googlecode.com/ · C Header · 148 lines · 36 code · 19 blank · 93 comment · 0 complexity · fa297e7ebc18991f4972ae320f577642 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. // GMResourceFork.h
  33. // MacFUSE
  34. //
  35. // Created by ted on 12/29/07.
  36. //
  37. /*!
  38. * @header GMResourceFork
  39. *
  40. * A utility class to construct raw resource fork data.
  41. *
  42. * In OS 10.4, the ResourceFork for a file may be present in an AppleDouble (._)
  43. * file that is associated with the file. In 10.5+, the ResourceFork is present
  44. * in the com.apple.ResourceFork extended attribute on a file.
  45. */
  46. #import <Foundation/Foundation.h>
  47. #define GM_EXPORT __attribute__((visibility("default")))
  48. @class GMResource;
  49. /*!
  50. * @class
  51. * @discussion This class can be used to construct raw NSData for a resource
  52. * fork. For more information about resource forks, see the CarbonCore/Finder.h
  53. * header file.
  54. */
  55. GM_EXPORT @interface GMResourceFork : NSObject {
  56. @private
  57. NSMutableDictionary* resourcesByType_;
  58. }
  59. /*! @abstract Returns an autoreleased GMResourceFork */
  60. + (GMResourceFork *)resourceFork;
  61. /*!
  62. * @abstract Adds a resource to the resource fork by specifying components.
  63. * @discussion See CarbonCore/Finder.h for some common resource identifiers.
  64. * @param resType The four-char code for the resource, e.g. 'icns'
  65. * @param resID The ID of the resource, e.g. 256 for webloc 'url' contents
  66. * @param name The name of the resource; may be nil (retained)
  67. * @param data The raw data for the resource (retained)
  68. */
  69. - (void)addResourceWithType:(ResType)resType
  70. resID:(ResID)resID
  71. name:(NSString *)name
  72. data:(NSData *)data;
  73. /*!
  74. * @abstract Adds a resource to the resource fork.
  75. * @discussion See CarbonCore/Finder.h for some common resource identifiers.
  76. * @param resource The resource to add.
  77. */
  78. - (void)addResource:(GMResource *)resource;
  79. /*!
  80. * @abstract Constucts the raw data for the resource fork.
  81. * @result NSData for the resource fork containing all added resources.
  82. */
  83. - (NSData *)data;
  84. @end
  85. /*!
  86. * @class
  87. * @discussion This class represents a single resource in a resource fork.
  88. */
  89. GM_EXPORT @interface GMResource : NSObject {
  90. @private
  91. ResType resType_; // FourCharCode, i.e. 'icns'
  92. ResID resID_; // SInt16, i.e. 256 for webloc 'url ' contents.
  93. NSString* name_; // Retained: The name of the resource.
  94. NSData* data_; // Retained: The raw data for the resource.
  95. }
  96. /*!
  97. * @abstract Returns an autoreleased resource by specifying components.
  98. * @discussion See CarbonCore/Finder.h for some common resource identifiers.
  99. * @param resType The four-char code for the resource, e.g. 'icns'
  100. * @param resID The ID of the resource, e.g. 256 for webloc 'url' contents
  101. * @param name The name of the resource; may be nil (retained)
  102. * @param data The raw data for the resource (retained)
  103. */
  104. + (GMResource *)resourceWithType:(ResType)resType
  105. resID:(ResID)resID
  106. name:(NSString *)name // May be nil
  107. data:(NSData *)data;
  108. /*!
  109. * @abstract Initializes a resource by specifying components.
  110. * @discussion See CarbonCore/Finder.h for some common resource identifiers.
  111. * @param resType The four-char code for the resource, e.g. 'icns'
  112. * @param resID The ID of the resource, e.g. 256 for webloc 'url' contents
  113. * @param name The name of the resource; may be nil (retained)
  114. * @param data The raw data for the resource (retained)
  115. */
  116. - (id)initWithType:(ResType)resType
  117. resID:(ResID)resID
  118. name:(NSString *)name // May be nil
  119. data:(NSData *)data;
  120. /*! @abstract The resource ID */
  121. - (ResID)resID;
  122. /*! @abstract The four-char code resource type */
  123. - (ResType)resType;
  124. /*! @abstract The resource name or nil if none */
  125. - (NSString *)name;
  126. /*! @abstract The resource data */
  127. - (NSData *)data;
  128. @end
  129. #undef GM_EXPORT