InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
IUCFPackageUtils.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Greg St. Pierre
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //========================================================================================
23 
24 
25 #ifndef IUCFPackageUtils_h__
26 #define IUCFPackageUtils_h__
27 
28 #include "JBXID.h"
29 #include "Utils.h"
30 
31 /*
32  IUCFPackageUtils
33 
34  A class used to create and/or open a UCFPackage. PackageRef preserves the UCFPackage
35  when opened by a caller.
36 */
37 
38 
40 {
41 public:
42  enum {kDefaultIID = IID_IUCFPACKAGETUTILS};
43 
44  enum CompressionType
45  {
46  kNone = 0,
47  kStandard = 8, // the value for zip deflated
48  kLastValue = 0x7fffffff // promote the enumeration
49  };
50 
51  enum UCFErrorCode
52  {
53  kSuccess = 0, // Success
54  kFailure, // Generic 'something bad happened' failure
55  kInvalidParam, // Specified parameter was incorrect
56 
57  kNoSuchFile, // Specified file wasn't found
58  kOpenFile, // Specified file couldn't be opened
59  kIOFailure, // I/O error
60 
61  kInvalidURI, // Specified URI is invalid
62 
63  kNoSuchAsset, // Specified asset doesn't exist
64  kAssetAlreadyExists, // Asset already in the job bag
65 
66  kOperationInProgress, // Failure due to in-progress operation
67  kInvalidOutsideUpdate, // Specified operation cannot be performed outside an update
68 
69  kCanceledError, // Operation was canceled by user
70  };
71 
72  /*
73  PackageRef
74 
75  Simple wrapper for the package and the manifest file
76  that is passed to the caller to retain a reference to
77  the packaging instance. Caller should not reference
78  any of the contents.
79  */
80 
81  class PackageRef
82  {
83  public:
84  UCFErrorCode GetLastError() { return fError; }
85 
86  protected:
87  PackageRef() : fError(kSuccess) {}
88  virtual ~PackageRef() {}
89 
90  private:
91  friend class UCFPackageUtils;
92  UCFErrorCode fError;
93  };
94 
95  typedef PackageRef* PackageRefPtr;
96 
97  // UCF can write property into two different locations, zip entry or new UCF speccific entry.
98  // If your ucf package needs to be compatible with zip application, they have to be set before
99  // stream is opened. Please use IUCFStreamProperty interface to set UCF specific property.
101  {
102  OSType fileType;
103  OSType creator;
104  uint64 timeStamp;
105  };
106 
107 public:
108  /* UCF library support three modes for opening packages:
109 
110  1. reading only(std::ios::in)
111  2. writing only(std::ios::out)
112  3. rewriting(std::ios::in | std::ios::out | std::ios::trunc) -- which uses a temp file
113  Mode 3 is similar to update a package. But updated package has to be saved to a new file.
114 
115  Right now, this interface only support 1 and 2.
116  */
117 
118  // Create package for write (mode 2)
119  virtual PackageRefPtr CreatePackage(const IDFile & file, const AString& mimeType, bool16 createManifest, UCFErrorCode & err) = 0;
120  virtual PackageRefPtr CreatePackage(const IPMStream * stream, const AString& mimeType, bool16 createManifest, UCFErrorCode & err) = 0;
121 
122  // Open a stream in package for write.
123  virtual IPMStream* CreateStream(PackageRefPtr ref, const WideString & packageRelativePath, CompressionType compress, FileProperty * entryProp = nil) = 0;
124 
125  // Close package
126  virtual UCFErrorCode ClosePackage(PackageRefPtr ref) = 0;
127 
128  // Close and dsicard change (assume it is created for write)
129  virtual UCFErrorCode ClosePackageWithoutSave(PackageRefPtr ref) = 0;
130 
131  // Open existing package for read. Need to call ClosePackage when finish. (mode 1)
132  virtual PackageRefPtr OpenPackage(const IDFile & file, UCFErrorCode & err) = 0;
133  virtual PackageRefPtr OpenPackage(const IPMStream * stream, UCFErrorCode & err) = 0;
134 
135  // Open a existing file in package for read
136  virtual IPMStream* OpenStream(PackageRefPtr ref, const WideString & packageRelativePath) = 0;
137 
138  // Package a folder into a UCF package or unpackage a UCF file to a folder.
139  virtual UCFErrorCode PackageUCF( const IDFile& FromFolder, IDFile& ToIDMLFile, const WideString & type, bool16 overwriteExisting = kTrue) = 0;
140  virtual UCFErrorCode UnPackageUCF( const IDFile& FromIDMLFile, IDFile& ToFolder ) = 0;
141 
142  // Misc functions.
143  virtual bool16 FileExists(PackageRefPtr ref, const WideString & packageRelativePath) = 0;
144  virtual bool16 IsUCFPackage(const IDFile & file) = 0;
145  virtual UCFErrorCode ExtractPackage(PackageRefPtr ref, const IDFile & folder) = 0;
146 
147  // packageRelativePath should be full file spec (path + name)
148  virtual bool16 AddExistingFile(PackageRefPtr ref, const IDFile & file, const WideString & packageRelativePath) = 0;
149 
150  // Set zip file comment. Must call before close package
151  virtual UCFErrorCode SetPackageComment(PackageRefPtr ref, const WideString & comment) = 0;
152 };
153 
154 
155 #endif // IUCFPackageUtils_h__