HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP_OTLUtils.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: OP_OTLUtils.h (OP Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __OP_OTLUtils__
13 #define __OP_OTLUtils__
14 
15 #include "OP_API.h"
16 #include <UT/UT_Compression.h>
17 #include <UT/UT_Map.h>
18 #include <UT/UT_StringArray.h>
19 #include <UT/UT_StringHolder.h>
20 #include <UT/UT_StringMap.h>
21 #include <UT/UT_UniquePtr.h>
22 #include <SYS/SYS_Types.h>
23 
24 #include <iosfwd>
25 
26 
27 class OP_Network;
28 class OP_OTLLibrary;
29 class FS_IndexFile;
30 class UT_IStream;
31 class UT_String;
32 class UT_WorkBuffer;
33 
34 
36 {
37 public:
38 
39  OP_OTLUtils();
40 
42  {
43  if (!theInstance)
44  theInstance = new OP_OTLUtils();
45  return theInstance;
46  }
47  // -----------------------------------------------------------------------
48  // High level routines to handle compression/decompression and
49  // conversion to/from MIME
50 
51  // auto decompress Contents and load into buffer
52  static bool getContentsSection(FS_IndexFile &indexFile,
54 
55  // provide stream for auto decompressed Contents stream
56  static UT_UniquePtr<UT_IStream> getContentsStream(
57  FS_IndexFile &deffile,
58  exint *uncompressed_buflen = nullptr);
59  // provide stream for auto decompressed Contents stream
60  static UT_UniquePtr<UT_IStream> getContentsStream(UT_IStream &is,
61  exint nbytes,
62  const UT_StringHolder &file_name,
63  exint *uncompressed_buflen = nullptr);
64 
65  // save the given buffer into the contents section appropriate
66  // for the indexfile given
67  static bool saveContentsSection(FS_IndexFile &indexFile,
68  const UT_WorkBuffer &contents_cpio);
69 
70  // If the contents section for the specified definition needs to be
71  // processed in any way then do so.
72  static bool processContentsSection(FS_IndexFile &indexFile,
73  const UT_String &section_name);
74 
75  // expand an indexfile into a directory and optionally convert
76  // the Contents section to the VCS friendly format if possible.
77  static bool expandToDirectory(OP_OTLLibrary *library,
78  const char *destdir,
79  bool vcsfriendly = false);
80 
81  static bool collapseLibrary(const char *libfile,
82  const char *srcdir,
83  bool createbackup = true);
84  // -----------------------------------------------------------------------
85  // Utility Functions for examining directories and such
86 
87  // expand an indexfile into a directory and optionally convert
88  // the Contents section to the VCS friendly format if possible.
89 
90  // Search all the assets for a filename within them
91  static void findAllSections(const char *srcdir,
92  const char *filename,
93  UT_StringArray &allfiles,
94  bool append = false);
95 
96  // Search all the assets for an existing MIME converted Contents section
97  static void findAllMimeSections(const char *srcdir,
98  UT_StringArray &allfiles,
99  bool append = false);
100 
101  // Determine if this directory is probably a valid HDA.
102  static bool isExpandedOtl(const char *src);
103 
104  // -----------------------------------------------------------------------
105  // Functions to help out doing diffs of assets.
106 
107  // Get the contents as text format regardless of how it's stored.
108  // This isn't guaranteed to be strictly the MIME format..
109  static bool getContentsAsText(FS_IndexFile &indexfile,
110  UT_WorkBuffer &contents_text,
111  bool strip_modtime = true);
112 
113 
114  static bool getNetworkSummary(UT_IStream &is,
115  UT_WorkBuffer &summary,
116  const char *prefix = nullptr,
117  bool isHipFile = false);
118 
119  static bool getNetworkSummary(OP_Network *network,
120  UT_WorkBuffer &summary,
121  const char *prefix = nullptr,
122  const char *root_name = nullptr);
123 
124  // -----------------------------------------------------------------------
125  // Mid level routines to handle compression/decompression and
126  // conversion to/from MIME.
127 
128  // Compress and write the given contents buffer
129  static bool compressContents(const UT_WorkBuffer &contents_cpio,
131  std::ostream *os);
132 
133  static bool convertContentsFromText(const UT_StringArray &files,
134  UT_StringArray &out_delete_files);
135  static bool convertContentsToText(const UT_StringArray &files,
136  bool preserve_modtime,
137  UT_StringArray &out_delete_files);
138 
139  // -----------------------------------------------------------------------
140  // Node data conversion
141 
142  typedef bool(*ConvertSectionToTextFunc)(const UT_StringHolder &src_path,
143  const UT_WorkBuffer &in_data,
144  UT_WorkBuffer &out_data,
145  bool &store_external);
146 
147  typedef bool(*ConvertSectionFromTextFunc)(const UT_StringHolder &src_path,
148  const UT_WorkBuffer &in_data,
149  UT_WorkBuffer &out_data);
150 
152  {
153  ConvertSectionToTextFunc myToText;
154  ConvertSectionFromTextFunc myFromText;
155  ConversionFuncs(ConvertSectionToTextFunc to_text = nullptr,
156  ConvertSectionFromTextFunc from_text = nullptr)
157  : myToText(to_text), myFromText(from_text)
158  {}
159  };
161 
162 
163  static bool registerConversionFuncs(const UT_StringHolder &extension,
164  ConvertSectionToTextFunc to_text,
165  ConvertSectionFromTextFunc from_text);
166 
168  { return getInstance()->myConversions; }
169 
170  // -----------------------------------------------------------------------
171  // Raw Contents conversions
172 
173  static bool CPIOToMIME(UT_IStream &is,
174  std::ostream &os,
175  bool preserve_modtime,
176  const char *externals_dest = nullptr);
177  static bool MIMEToCPIO(UT_IStream &is,
178  std::ostream &os,
179  const char *externals_dest = nullptr);
180 
181  // -----------------------------------------------------------------------
182  // Parameter conversions
183 
184  static UT_StringHolder getNameFromCompression(
186  static UT_CompressionType getCompressionFromName(
187  const UT_StringHolder &section_name);
188 
189  // -----------------------------------------------------------------------
190  // Public data
191 
193 
196 
197 private:
198  ConversionList myConversions;
199 
200  static OP_OTLUtils *theInstance;
201 
202  static ConversionList &_getConversions()
203  { return getInstance()->myConversions; }
204 
205 };
206 
207 #endif
208 
GT_API const UT_StringHolder filename
UT_StringMap< ConversionFuncs > ConversionList
Definition: OP_OTLUtils.h:160
Unsorted map container.
Definition: UT_Map.h:83
static const UT_StringArray allContentsSectionNames
Definition: OP_OTLUtils.h:194
static OP_OTLUtils * getInstance()
Definition: OP_OTLUtils.h:41
static const ConversionList & getConversions()
Definition: OP_OTLUtils.h:167
png_infop png_charpp int * compression_type
Definition: png.h:2467
UT_Map< UT_StringHolder, UT_CompressionType > CompressionMap
Definition: OP_OTLUtils.h:192
ConvertSectionFromTextFunc myFromText
Definition: OP_OTLUtils.h:154
int64 exint
Definition: SYS_Types.h:116
ConversionFuncs(ConvertSectionToTextFunc to_text=nullptr, ConvertSectionFromTextFunc from_text=nullptr)
Definition: OP_OTLUtils.h:155
GLboolean * data
Definition: glcorearb.h:130
UT_CompressionType
#define OP_API
Definition: OP_API.h:10
static const CompressionMap contentsCompressionNameMap
Definition: OP_OTLUtils.h:195
ConvertSectionToTextFunc myToText
Definition: OP_OTLUtils.h:153
GLenum src
Definition: glcorearb.h:1792