Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
IoCommon.h
1#ifndef IOCOMMON_H
2#define IOCOMMON_H
3
4#include "FileInfo.h"
5
6BEGIN_MOOTOOLS_NAMESPACE
7
8typedef bool (*ValidFileMethod)(LPCTSTR, void *);
9
10typedef enum
11{
12 IO_FILE_OK = 1,
13
14 IO_FILE_UNKNOWN_ERROR = 0,
15 IO_FILE_CANT_OPEN_FILE = -1,
16 IO_FILE_UNKNOWN_FILE_TYPE = -2,
17 IO_FILE_BAD_FILE_FORMAT = -3,
18 IO_FILE_MEMORY_ERROR = -4,
19 IO_FILE_CRITICAL_ERROR = -5, // A catched exception was thrown meaning that a critical error occured when reading saving the file
20 IO_SAVE_FILE_DISK_FULL = -6,
21 IO_SAVE_FILE_ACCESS_DENIED = -7,
22 IO_SAVE_EMPTY_FILE = -8,
23 IO_CANT_SAVE_IN_THIS_FORMAT = -9,
24 IO_LOAD_EMPTY_FILE = -10,
25 IO_USER_ABORT_OPERATION = -11,
26 IO_CUSTOM_ERROR = -12,
27} IO_FILE_RESULT;
28
29typedef enum IoShowDialog
30{
31 IO_NO_DIALOG = 0, // No dialog to display
32 IO_DIALOG_RECOMMENDED = 1, // Better to display dialog to define a compression factor for example. The IO works without it.
33 IO_NEED_DIALOG = 2, // Dialog absolutely needed to read the format (ie raw format). The IO does not works without it.
34} IoShowDialog;
35
36//! @struct IoLogInfo
37//! @brief Provides log detail info to IoFile
38typedef struct IoLogInfo
39{
40 enum loglevel
41 {
42 LOG_NONE = 0,
43 LOG_ALL = 0xFF,
44 LOG_INFO = 0x01,
45 LOG_WARNING = 0x02,
46 LOG_ERROR = 0x04,
47 } level;
48 CXString txt;
49
50public:
51 IoLogInfo()
52 {
53 level = LOG_NONE;
54 }
55
56 IoLogInfo(const CXString& txt, loglevel level)
57 {
58 this->txt = txt;
59 this->level = level;
60 }
61} IoLogInfo;
62
63class DLL_TOOLSFUNCTION CIoOptions
64{
65 public:
66 typedef enum
67 {
68 IOOPTIONS_NONE = 0x00,
69 IOOPTIONS_LOAD = 0x01, // Save mode otherwise
70 IOOPTIONS_SHOWALLDLGOPTIONS = 0x02, // this display all options when (ie update mode) defining format options for a batch process for example.
71 IOOPTIONS_ALLOW_GLOBALOPTIONS = 0x04, // Allow to display global options such log report event accordingly to global prefs (overidde default options, in case we have another way to display log)
72
73 // these are global options load automatically and shared among all parser
74 IOOPTIONS_GLOBAL_PREFS = 0xFFFF0000,
75 IOOPTIONS_GLOBAL_SHOWLOG = 0x00010000, // this display the log option
76 } IoOptionsFlags;
77
78 private:
79 unsigned options; // runtime options
81
82 protected:
83 CXCriticalSection threadLock;
84 CCustomData parserData; // Store specific parser options for serialization
85
86 public:
88 virtual ~CIoOptions();
89
90 void SetFlag(IoOptionsFlags flag, bool set);
91 bool IsFlagSet(IoOptionsFlags flag) const;
92
93 // Init parser options from provided or previously saved data
94 virtual void InitFromSavedPrefs(const CCustomData& data) = 0; // Init options from saved prefs data. GetParserOptions must be called after InitFromSavedPrefs, if some specific settings must be set by the called
95 virtual const CCustomData& SaveToSavedPrefs() = 0; // Save struct to saved prefs data
96
97 CCustomData& GetParserOptions() { return parserData; } // Use when caller provide the reading and saving options. GetParserOptions allows to provide extra parser settings, such an FBX password for example. If settings come from saved prefs, InitFromSavedPrefs to initialize the data.
98 const CCustomData& GetParserOptions() const { return parserData; } // Use when caller provide the reading and saving options. GetParserOptions allows to provide extra parser settings, such an FBX password for example. If settings come from saved prefs, InitFromSavedPrefs to initialize the data.
99
100 void AddLogInfo(IoLogInfo::loglevel level, const CXString& txt);
101 void AddLogInfo(IoLogInfo::loglevel level, unsigned int errorCode, LPCTSTR filename = NULL);
102
103#ifndef MOOTOOLS_NO_UI
104 void DisplayLog(unsigned int loglevel, CWnd *pParent);
105#endif
106};
107
108#define IO_FILECLASS_ID MAKE_CUSTOM_ID('I', 'O', 'C', 'L')
109
110typedef enum FILE_PARSER_FLAGS
111{
112 FILE_PARSER_DEFAULT = 0x00,
113 FILE_PARSER_SAVING = 0x00, // Set it to 0 so we just have to check FILE_PARSER_LOADING to see if loading
114 FILE_PARSER_LOADING = 0x01,
115 FILE_PARSER_SILENT_MODE = 0x02, // No dialogs, no messages
116 FILE_PARSER_SHOW_DIALOG = 0x04, // Always show export dialogs (apply to bitmap export only, 3d export only use FILE_PARSER_SILENT_MODE or not)
117 // TODO: FILE_PARSER_PARAMETERS_PROVIDED should be deprecated, as CFileIo::iodata is intended to store only collected data
118 // Parameters of the parser are provided using GetCustomData()
119 // We don't take care of default settings, and don't save settings in preferences files
120 FILE_PARSER_PARAMETERS_PROVIDED = 0x08,
121 FILE_PARSER_QUICK_MODE = 0x10, // Try to open in quick mode
122 FILE_PARSER_SHOW_FILE_DIALOG = 0x20, // a name might be provided, but the file selector must be shown to the user (apply to bitmap export only, 3d export only use FILE_PARSER_SILENT_MODE or not)
123} FILE_PARSER_FLAGS;
124
125class CFileIo;
126class CFileParser;
127
128class CFileIo;
129class DLL_TOOLSFUNCTION CFileParser
130{
131protected:
132 CFileIo *io;
133 CXWnd *pParent;
134
135public:
136 CFileParser(CFileIo& io);
137 virtual ~CFileParser();
138
139 CFileIo *GetIoMgr() { return io; };
140
141 // Parser flags
142 bool IsSilentMode() const;
143 bool IsFlagSet(FILE_PARSER_FLAGS flag) const;
144
145 // Load/Save process
146 IoShowDialog MustShowDialog();
147};
148
149class DLL_TOOLSFUNCTION CFileIo
150{
151 friend CFileParser;
152
153 private:
154 CFileInfo fileInfo;
155 unsigned int flags;
156
157 unsigned int altParserClass;
158 CCustomData iodata; // Store extra information collected from the parser. This is not related to I/O settings, but allow to get some additional information after file has been readed or saved
159 int ioError;
160 CXString errorTxt;
161
162 protected:
163 CFileParser *ioparser;
164 CXWnd *pParent;
165
166 virtual CFileParser *InitParser();
167 virtual void CloseParser();
168
169 bool CanTryAnotherParser() const { return fileInfo.CanTryAnotherParser(); }
170 void TryNextParser() { fileInfo.TryNextParser(); }
171
172 public:
173 CFileIo(const CFileNameSpec&, unsigned int flags, CXWnd *pParent = NULL);
174 CFileIo(unsigned int fileclass, unsigned int flags, CXWnd *pParent = NULL);
175 virtual ~CFileIo();
176
177 CXWnd *GetParentWnd()
178 {
179 return pParent;
180 };
181
182 CCustomData& GetCustomData() { return iodata; };
183
184 CXString GetCurrentShortFileName(void);
185 CXString GetCurrentCompleteFileName(void);
186 CXString GetCurrentFilePath(void);
187 void SetAlternativeClass(unsigned int altClass);
188 unsigned int GetAlternativeClass() const;
189 bool IsMultiParserExtension() const { return (fileInfo.GetParserNbr() > 1); }
190
191#ifndef MOOTOOLS_NO_UI
192 bool FileDialogBox(int type, bool makeNameUnique = false); // makeNameUnique is useful only for saving dialog box
193#ifndef MOOTOOLS_NO_MULTIPLE_FILEDLG
195#endif
196#endif
197
198#ifndef MOOTOOLS_CRUNCHERSDK
199 bool GetFileList(CXStringArray&, ValidFileMethod, void *, bool);
200 static bool FindMatchingFile(CXString& findname, const CXString& basename, int value);
201#endif
202
203 bool IsLoading() const { return IsFlagSet(FILE_PARSER_LOADING); }
204
205 bool IsURL(bool trueOnlyIfFileURL) const
206 {
208 return (fileInfo.IsURL() && fileInfo.IsFile());
209
210 return fileInfo.IsURL();
211 }
212
213 CXString GetName() const
214 {
215 return fileInfo.GetName();
216 }
217
218 CXString GetCompleteName() const
219 {
220 return fileInfo.GetCompleteName();
221 }
222
223 CXString GetPath() const
224 {
225 return fileInfo.GetPath();
226 }
227
228 CXString GetExtension() const
229 {
230 return fileInfo.GetExtension();
231 }
232
233 CXString GetNameWithoutExt() const
234 {
235 return fileInfo.GetNameWithoutExt();
236 }
237
238 void SetNewFileName(const CFileNameSpec& filespec)
239 {
240#ifdef _DEBUG
241 XASSERT(filespec.GetClass() == GetClass());
242#endif
243 fileInfo.Init(filespec);
244 }
245
246 unsigned int GetKindOf(void) const
247 {
248 return fileInfo.GetKindOf();
249 }
250
251 unsigned int GetClass(void) const
252 {
253 return fileInfo.GetClass();
254 }
255
256 unsigned int GetProperties(void) const
257 {
258 return fileInfo.GetProperties();
259 }
260
261 unsigned int GetParser() const
262 {
263 if (IsLoading())
264 return fileInfo.GetLoader();
265
266 return fileInfo.GetSaver();
267 }
268
269 // Errors information
270 bool ReportIoError(CIoOptions *options = NULL, unsigned int level = IoLogInfo::LOG_WARNING|IoLogInfo::LOG_ERROR);
271 bool ReportIoError(const CXString& error);
272 CXString GetIoErrorTxt() const;
273 static CXString GetIoErrorTxtFromCode(bool loading, int code, LPCTSTR filename = NULL);
274
275 int GetIoError() const
276 {
277 return ioError;
278 };
279
280 void SetIoError(IO_FILE_RESULT error, CIoOptions *options = NULL, IoLogInfo::loglevel level = IoLogInfo::LOG_ERROR);
281 void SetIoError(const CXString& error, CIoOptions *options = NULL, IoLogInfo::loglevel level = IoLogInfo::LOG_ERROR);
282
283 // Load and save flags
284 unsigned int GetFlags() const { return flags; };
285 void SetFlag(FILE_PARSER_FLAGS state, bool set);
286 bool IsFlagSet(unsigned int state) const;
287 void SetSilentMode(bool silent) { SetFlag(FILE_PARSER_SILENT_MODE, silent); }
288 bool IsSilentMode() { return IsFlagSet(FILE_PARSER_SILENT_MODE); }
289
290 // Parser information
291 static IoShowDialog HasDialog(unsigned int fileclass, bool loading);
292
293 // Settings options
294 static CXString GetPreferencesFilePath();
295 bool SaveIoParameters(bool loading, const CCustomData& iodata, unsigned int fileclass) const; // Return true if some prefs are saved, false otherwise
296 bool LoadIoParameters(bool loading, CCustomData& iodata, unsigned int fileclass) const; // Return true if some prefs are loaded modifying iodata, false otherwise
297};
298
299END_MOOTOOLS_NAMESPACE
300
301#endif /* IOBMAPMGR_H */
Contains many convenient functions for handling files, paths and give a way to add some custom format...
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
CCustomData is a handly class for storing any kind of data.
Definition CustomData.h:106
A convenient class to get some information giving a specific file name through a CFileNameSpec object...
Definition FileInfo.h:375
unsigned int GetSaver() const
Return saver of file.
bool IsFile() const
Is the filename a file?
unsigned int GetLoader() const
Return loader of file.
void Init(const CFileNameSpec &filepec, FILENAME_TYPE type=FILENAME_UNKNOWN)
Retrieve info about a file giving a CFileNameSpec. If known type can be provided to resolve some name...
unsigned int GetClass() const
Return type file class.
bool IsURL() const
Is the filename an URL? Note: An URL can also be a directory or a file.
CXString GetName() const
Return filename (without path)
unsigned int GetProperties() const
Return type of file.
unsigned int GetKindOf() const
Return kind of file.
CXString GetPath() const
Return path.
CXString GetCompleteName() const
Return filename (path included)
CXString GetNameWithoutExt() const
Return filename (without path and extension)
unsigned int GetParserNbr() const
Return the parser number for the extension.
CXString GetExtension() const
Return extension.
Definition IoCommon.h:150
A given extension may match several formats. In case of conflict CFileNameSpec is a way to indicate t...
Definition FileInfo.h:156
Definition IoCommon.h:130
Definition IoCommon.h:64
Definition XThreadSync.h:20
CXStringArray implement an array of CXString.
Definition XStringArray.h:25
Provides log detail info to IoFile.
Definition IoCommon.h:39