Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
FileInfo.h
Go to the documentation of this file.
1//! @file FileInfo.h
2//! @brief Contains many convenient functions for handling files, paths and give a way to add some custom format support
3//!
4//////////////////////////////////////////////////////////////////////
5
6#if !defined(AFX_FILEINFO_H__12CD9483_C809_11D3_A382_9415BA0D2432__INCLUDED_)
7#define AFX_FILEINFO_H__12CD9483_C809_11D3_A382_9415BA0D2432__INCLUDED_
8
9#ifdef _MSC_VER
10#pragma once
11#endif // _MSC_VER
12
13#include "xfileoperation.h"
14#include "CustomData.h"
15
16BEGIN_MOOTOOLS_NAMESPACE
17
18class CFileExt;
19
20typedef enum IoPluginMode
21{
22 IO_INIT_PLUGIN, // Allow to add the extension handled by the plugin. data can be cast to IOInitPluginInfo
23 IO_GET_PARSER, // Ask the plugin for a given parser send the file class. data can be cast to IOGetParserInfo
24} IoPluginMode;
25
26// The exported function for io plugin
27typedef bool (*InitIOPluginFunc)(IoPluginMode mode, void *data);
28
29#define UNKNOWN_CLASS 0
30#define TGA_FILE MAKE_CUSTOM_ID('T', 'G', 'A', ' ')
31#define Z_FILE MAKE_CUSTOM_ID('Z', 'F', 'I', 'L')
32#define BMP_FILE MAKE_CUSTOM_ID('B', 'M', 'P', ' ')
33#define JPEG_FILE MAKE_CUSTOM_ID('J', 'P', 'E', 'G')
34#define GIF_FILE MAKE_CUSTOM_ID('G', 'I', 'F', ' ')
35#define PNG_FILE MAKE_CUSTOM_ID('P', 'N', 'G', ' ')
36#define TIFF_FILE MAKE_CUSTOM_ID('T', 'I', 'F', 'F')
37#define ZPIC_FILE MAKE_CUSTOM_ID('Z', 'P', 'I', 'C')
38#define PIC_FILE MAKE_CUSTOM_ID('P', 'I', 'C', ' ')
39#define RLA_FILE MAKE_CUSTOM_ID('R', 'L', 'A', ' ')
40#define IFF_FILE MAKE_CUSTOM_ID('I', 'F', 'F', ' ')
41//#define PHOTOSHOP_FILE MAKE_CUSTOM_ID('P', 'H', 'O', 'T')
42#define GIF_FILE MAKE_CUSTOM_ID('G', 'I', 'F', ' ')
43#define ICON_FILE MAKE_CUSTOM_ID('I', 'C', 'O', 'N')
44#define CURSOR_FILE MAKE_CUSTOM_ID('C', 'U', 'R', 'S')
45#define HDR_FILE MAKE_CUSTOM_ID('H', 'D', 'R', ' ')
46#define FOLDER_CLASS MAKE_CUSTOM_ID('F', 'L', 'D', 'R') // This class refers to a directory
47
48#define AMAPI_3D_FILE MAKE_CUSTOM_ID('A', 'M', 'A', 'P')
49#define CINEMA4D_3D_FILE MAKE_CUSTOM_ID('C', 'N', '4', 'D')
50#define COLLADA_3D_FILE MAKE_CUSTOM_ID('D', 'A', 'E', ' ')
51#define DIRECTX_3D_FILE MAKE_CUSTOM_ID('D', 'R', 'T', 'X')
52#define DXF_3D_FILE MAKE_CUSTOM_ID('D', 'X', 'F', '4')
53#define DXF_FBX_3D_FILE MAKE_CUSTOM_ID('D', 'X', 'F', 'B')
54#define INTERNALFORMAT_3D_FILE MAKE_CUSTOM_ID('3', 'D', 'I', 'F')
55#define KMZ_3D_FILE MAKE_CUSTOM_ID('K', 'M', 'Z', 'I')
56#define LIGHTWAVE_3D_FILE MAKE_CUSTOM_ID('L', 'I', 'G', 'T')
57#define LIGHTWAVE_3D_SCENE_FILE MAKE_CUSTOM_ID('L', 'I', 'G', 'S')
58#define LXO_3D_FILE MAKE_CUSTOM_ID('L', 'X', 'O', 'I')
59#define MAYAASCII_3D_FILE MAKE_CUSTOM_ID('M', 'Y', 'A', 'S')
60#define MAYA_3D_FILE MAKE_CUSTOM_ID('M', 'A', 'Y', 'A')
61#define SKETCHUP_3D_FILE MAKE_CUSTOM_ID('S', 'K', 'E', 'T')
62#define JT_3D_FILE MAKE_CUSTOM_ID('J', 'T', 'K', 'F')
63#define KERNELIO_3D_FILE MAKE_CUSTOM_ID('C', 'T', 'K', 'I')
64#define STL_3D_FILE MAKE_CUSTOM_ID('S', 'T', 'L', ' ')
65#define STUDIO_MAX_3D_FILE MAKE_CUSTOM_ID('3', 'M', 'A', 'X')
66#define STUDIO_3D_FILE MAKE_CUSTOM_ID('3', 'D', 'S', 'T')
67#define TRUESPACE_3D_FILE MAKE_CUSTOM_ID('T', 'R', 'U', 'E')
68#define VRML_3D_FILE MAKE_CUSTOM_ID('V', 'R', 'M', 'L')
69#define VRML97_3D_FILE MAKE_CUSTOM_ID('V', 'R', '9', '7')
70#define PLY_3D_FILE MAKE_CUSTOM_ID('P', 'L', 'Y', 'Y')
71#define WAVEFRONT_3D_FILE MAKE_CUSTOM_ID('W', 'A', 'V', 'F')
72#define XSI_3D_FILE MAKE_CUSTOM_ID('X', 'S', 'I', ' ')
73#define FBX_3D_FILE MAKE_CUSTOM_ID('F', 'B', 'X', ' ')
74#define ALEMBIC_3D_FILE MAKE_CUSTOM_ID('A', 'B', 'C', 'F')
75#define MR_3D_FILE MAKE_CUSTOM_ID('P', 'C', 'M', 'R')
76#define GLTF_3D_FILE MAKE_CUSTOM_ID('G', 'L', 'T', 'F')
77#define BLENDER_3D_FILE MAKE_CUSTOM_ID('B', 'L', 'E', 'N')
78
79#define WAV_AUDIO_FILE MAKE_CUSTOM_ID('A', 'I', 'W', 'V')
80#define WINMEDIA_AUDIO_FILE MAKE_CUSTOM_ID('A', 'I', 'W', 'M')
81#define MAC_AUDIO_FILE MAKE_CUSTOM_ID('A', 'I', 'M', 'C')
82#define UNIX_AUDIO_FILE MAKE_CUSTOM_ID('A', 'I', 'U', 'X')
83#define MPEG_AUDIO_FILE MAKE_CUSTOM_ID('A', 'I', 'M', 'G')
84#define MIDI_FILE MAKE_CUSTOM_ID('M', 'I', 'D', 'I')
85#define FLASH_FILE MAKE_CUSTOM_ID('F', 'L', 'A', 'S')
86#define HTMLS_FILE MAKE_CUSTOM_ID('I', 'H', 'T', 'M') // Add a S to avoid multiple definition
87#define RAWS_FILE MAKE_CUSTOM_ID('R', 'A', 'W', 'S')
88#define MOV_FILE MAKE_CUSTOM_ID('M', 'O', 'V', ' ')
89#define ZIP_FILE MAKE_CUSTOM_ID('Z', 'I', 'P', ' ')
90#define RAR_FILE MAKE_CUSTOM_ID('R', 'A', 'R', ' ')
91#define TAR_FILE MAKE_CUSTOM_ID('T', 'A', 'R', ' ')
92#define ZIP7_FILE MAKE_CUSTOM_ID('Z', 'I', 'P', '7')
93#define GZ_FILE MAKE_CUSTOM_ID('G', 'Z', ' ', ' ')
94#define STEGANO_FILE MAKE_CUSTOM_ID('S', 'T', 'E', 'G')
95#define PPM_FILE MAKE_CUSTOM_ID('P', 'P', 'M', ' ')
96#define AVI_FILE MAKE_CUSTOM_ID('A', 'V', 'I', ' ')
97#define MPEG4_FILE MAKE_CUSTOM_ID('M', 'P', 'G', '4') // Not supported but considered as image file
98#define FLV_FILE MAKE_CUSTOM_ID('F', 'L', 'V', ' ') // Not supported but considered as image file
99#define WMV_FILE MAKE_CUSTOM_ID('W', 'M', 'V', ' ') // Not supported but considered as image file
100#define ALL_FILE_CLASS MAKE_CUSTOM_ID('A', 'L', 'L', 'F')
101
102#define PLUGIN_PARSER MAKE_CUSTOM_ID('P', 'L', 'G', 'P')
103#define MOOTOOLS_PARSER MAKE_CUSTOM_ID('M', 'O', 'O', 'T')
104#define CALLBACK_PARSER MAKE_CUSTOM_ID('C', 'A', 'L', 'K')
105#define MAGICK_PARSER MAKE_CUSTOM_ID('M', 'A', 'G', 'I')
106#define UNKNOWN_PARSER MAKE_CUSTOM_ID('U', 'N', 'K', 'N') // can be used to add file readed/saved using another method than plugin or internal parsers.
107
108// File type : import/export possibility, type of the file
109// PRIVATE_FILE can be read but are not proposed to the user
110// (they are read with an other file type)
111
112//! @name File format properties and kind of file
113//! @anchor FILEPROP
114//! @brief Macros that define properties for a given extension
115//! @{
116#define UNKNOWN_PROPERTIES 0x00
117#define IMPORT_FILE 0x01
118#define EXPORT_FILE 0x02
119#define PRIVATE_IMPORT_FILE 0x04
120#define PRIVATE_EXPORT_FILE 0x08
121#define COMMON_EXTENSION_FILE 0x10
122#define LOAD_HAS_DIALOG 0x20
123#define LOAD_NEED_DIALOG 0x40
124#define SAVE_HAS_DIALOG 0x80
125#define SAVE_NEED_DIALOG 0x100
126#define FORCE_DISPLAY_FILE 0x200 // a flag use to display an extension (CCustomFileDialog)
127#define ONE_SHOT_FORMAT 0x400 // the format is read or saved completely in a single time (ie, an animation can't be saved frame by frame)
128#define MAIN_FORMAT_PARSER 0x800 // if multiple parser exist, this specified which should be the first to use
129
130#define KIND_OF_FILE 0xFFFFF000
131#define UNKNOWN_KIND_OF_FILE 0x00
132#define BITMAP_FILE 0x00001000
133#define ANIMATED_BITMAP_FILE 0x00002000 // It have animation (must be combinated with BITMAP_FILE)
134#define OBJECT_FILE 0x00004000
135#define SOUND_FILE 0x00008000
136#define VIDEO_FILE 0x00010000
137#define WWW_FILE 0x00020000
138#define COMPRESSED_FILE 0x00040000
139#define GENERAL_FILE 0x00080000
140#define FOLDER_FILE 0x00100000
141#define LAST_KIND_OF FOLDER_FILE // Note the last KIND OF FILE => can be used for anything else
142
143#define ALL_KIND_OF_FILES (KIND_OF_FILE)
144#define MULTIMEDIA_FILES (BITMAP_FILE|ANIMATED_BITMAP_FILE|OBJECT_FILE|SOUND_FILE|VIDEO_FILE)
145
146//! @}
147
148//! @class CFileNameSpec
149//!
150//! @brief A given extension may match several formats.
151//! In case of conflict CFileNameSpec is a way to indicate that a given file name matches a specified file class.\n
152//! CFileNameSpec(filename) simply construct a filename without specifying which is its class.\n
153//! In that case, the SDK will choose the appropriate parser based an the extension.\n
154//! If loading fails, a try will be done using the next available parser, and so on.
155class DLL_TOOLSFUNCTION CFileNameSpec
156{
157protected:
158 CXString filename;
159 unsigned int fileclass;
160 // This allow to know if the user define the class itself, or if a default class has been selected.
161 // If default class selected, several parser will be tested to read the file if several parser exists for the same ext
162 mutable bool defaultClassSelected;
163
164public:
166 CFileNameSpec(const CXString& filename, unsigned int fileclass = UNKNOWN_CLASS);
167 CFileNameSpec(LPCTSTR filename, unsigned int fileclass = UNKNOWN_CLASS);
168 bool IsSameFile(const CFileNameSpec& spec) const;
169 bool IsDefaultParserChoice() const { return defaultClassSelected; }
170 operator LPCTSTR() const;
171 operator const CXString&() const;
172 void operator=(const CXString& filename);
173 unsigned int GetClass() const;
174 void SetClass(unsigned int newclass);
175 const CXString& GetFileName() const;
176};
177
178//! @class CFileExt
179//! @brief CFileExt is the class that allows to add a custom file parser for supporting a new file format.
180//! You have to give a specific class identifier, provide the format extensions, the read/write capabilities of the parser...
181class DLL_TOOLSFUNCTION CFileExt
182{
183public:
184 CXString description;
185 CXString ext;
186 unsigned int fileclass; //!< A tag created with MAKE_CUSTOM_ID
187 unsigned int properties; //!< flags that tells about the type and the content of the file Cf. @ref FILEPROP
188 //! Specify what is the loader of the file: MOOTOOLS_PARSER, PLUGIN_PARSER, CALLBACK_PARSER or something else (ie. ImageMagick).\n
189 //! MOOTOOLS_PARSER is internal. The only allowed value are:\n
190 //! PLUGIN_PARSER when extension registered from a DLL. Such dll have .moox extension and contains an exported function bool Init3DParser(IoPluginMode mode, void *data) that declares extension handled by the plugin. When loaded, such the SDK call IO_INIT_PLUGIN to get information of the handled extensions. Then this function will be called with IoPluginMode = IO_GET_PARSER each time the extension (associated to the file class you define) is asked to be read/write.\n
191 //! CALLBACK_PARSER, when you add extension using a callback function. You have to call fileRegisterFile and set iocallback to a function that have the following type: bool Your_Callback(IoPluginMode mode, void *data). This function will be called with IoPluginMode = IO_GET_PARSER each time the extension (associated to the file class you define) is asked to be read/write.\n
192 unsigned int loader;
193 unsigned int saver; //!< Inform about the file saver: MOOTOOLS_PARSER, PLUGIN_PARSER, CALLBACK_PARSER or something else (ie. ImageMagick).
194 InitIOPluginFunc iocallback; //!< The function which allows to create parser
195
196 CFileExt()
197 {
198 Init();
199 }
200
201 void Init()
202 {
203 description.Empty();
204 ext.Empty();
205 fileclass = UNKNOWN_CLASS;
206 properties = UNKNOWN_PROPERTIES;
207 loader = UNKNOWN_PARSER;
208 saver = UNKNOWN_PARSER;
209 iocallback = NULL;
210 }
211
212 CXString GetDescription() const { return CXString(description); }
213 CXString GetExtension() const { return CXString(ext); }
214 unsigned int GetClass() const { return fileclass; }
215 unsigned int GetProperties() const { return (properties); } // Must return the whole value (many calls made try on both kindof and additional properties
216 unsigned int GetKindOf() const { return (properties & KIND_OF_FILE); }
217 unsigned int GetLoader() const { return loader; }
218 unsigned int GetSaver() const { return saver; }
219};
220
221typedef enum DirCompare
222{
223 DIFFERENT_DIRECTORY = 0,
224 SAME_DIRECTORY,
225 DIR1_IN_DIR2_DIRECTORY,
226 DIR2_IN_DIR1_DIRECTORY,
227} DirCompare;
228
229typedef enum FileValidateNameMode
230{
231 FILEVALIDATE_DEFAULT = 0,
232 FILEVALIDATE_FILENAME = 0x01, // Checking that name part of the provided filepath contains valid characters
233 FILEVALIDATE_DIRECTORY = 0x02, // Checking that directory part of the provided filepath contains valid characters, and refers to a valid disk
234 FILEVALIDATE_PATH = FILEVALIDATE_FILENAME|FILEVALIDATE_DIRECTORY, // Checking the directory part of the provided filepath
235 FILEVALIDATE_CAN_BE_RELATIVE = 0x04, // Allow the directory part to be relative
236 FILEVALIDATE_ALLOW_EMPTY_NAME = 0x08, // Allow an empty name
237 FILEVALIDATE_FILENAME_ONLY = 0x10, // the provided path must only be a filename with path part (include FILEVALIDATE_FILENAME)
238 FILEVALIDATE_QUIET = 0x20, // Don't display a message
239} FileValidateNameMode;
240
241typedef enum FileCheckAccessFlag
242{
243 FILE_CHECK_READ = 0x01,
244 FILE_CHECK_WRITE = 0x02,
245 FILE_CHECK_SHARED_READ = 0x04,
246 FILE_CHECK_SHARED_WRITE = 0x08,
247 FILE_CHECK_CREATE = 0x10,
248 FILE_CHECK_SHARED_CREATE = FILE_CHECK_CREATE|FILE_CHECK_SHARED_READ|FILE_CHECK_SHARED_WRITE,
249} FileCheckAccessFlag;
250
251//! @enum FILENAME_TYPE
252//! Allows to define what kind of file a filename is.
253typedef enum FILENAME_TYPE
254{
255 FILENAME_UNKNOWN = 0,
256 FILENAME_IS_A_FILE,
257 FILENAME_IS_A_DIRECTORY,
258 FILENAME_IS_A_NETWORK_FILE,
259 FILENAME_IS_IN_ZIP,
260 FILENAME_IS_AN_URL,
262
263void fileRegisterFiles(); //!< Automatically call to make all recognized by being registered and recognized.
264void fileUnregisterFiles();
265
266#define IOTIMEOUT_ALWAYS_USE (0x80000000) // Make the timeout being used whatever the file
267#define IOTIMEOUT_DEFAULT 750 // A default timeout value
268#define IOTIMEOUT_OCCURED ((unsigned int)-1)
269
270DLL_TOOLSFUNCTION void fileRegisterFile(CFileExt& fileinfo);
271DLL_TOOLSFUNCTION void fileUnregisterFile(unsigned int fileClass, unsigned int flags);
272DLL_TOOLSFUNCTION CFileExt *fileGetRegisteredFiles(unsigned int& size, unsigned int filter = 0);
273DLL_TOOLSFUNCTION void fileFreeRegisteredFiles(CFileExt *files, unsigned int size);
274
275DLL_TOOLSFUNCTION CXString fileCompactPath(const CXString& path, int charNbr = 15);
276DLL_TOOLSFUNCTION bool fileIsPathRelative(const CXString& mainpath);
277DLL_TOOLSFUNCTION CXString fileMakeRelativePath(const CXString& mainpath, const CXString& relpath, bool noSlashAndDotAtBeginning = false, FILENAME_TYPE type = FILENAME_UNKNOWN); //!< noSlashAndDotAtBeginning = false will return .\folder\filename.ext, noSlashAndDotAtBeginning = true will return folder\filename.ext
278DLL_TOOLSFUNCTION CXString fileMakeAbsolutePath(const CXString& mainpath, const CXString& relpath, bool slashTerminate = false); //!< if relpath is relative, it returns an absolute path using mainpath. If relpath is not relative or if creating absolute path fails, it return relpath. if slashTerminate set, a slash is added, which implies that the return result is used as a directory
279DLL_TOOLSFUNCTION bool fileMakePathShortest(CXString& path); //!< Converts C:\abc\..\abc\file.txt to C:\abc\file.txt if possible or uneeded, path is not changed if conversion fails (C:/../file.txt)
280DLL_TOOLSFUNCTION CXString fileGetCurrentDirectory();
281DLL_TOOLSFUNCTION bool filePushCurrentDirectory(const CXString& newpath, unsigned int *timeOut = NULL); //!< return true if directory change is a success. Whatever the results, filePopCurrentDirectory must always be called.
282DLL_TOOLSFUNCTION bool filePopCurrentDirectory(); //!< pop the latest push current directory
283DLL_TOOLSFUNCTION bool fileDirectoryExists(const CXString& filename, unsigned int* timeOut = NULL);
284DLL_TOOLSFUNCTION bool fileExists(const CXString& filename, unsigned int *timeOut = NULL); //!< Accessing file can take time. specify timeOut if critical (ie access through network). If timeout reach, the function return false.
285DLL_TOOLSFUNCTION bool fileCheckAccess(const CXString& filename, unsigned int flags);
286DLL_TOOLSFUNCTION bool fileGetCreationDate(const CXString& filename, CXTime& time);
287DLL_TOOLSFUNCTION bool fileSetCreationDate(const CXString& filename, const CXTime& time);
288DLL_TOOLSFUNCTION bool fileGetLastWriteDate(const CXString& filename, CXTime& time);
289DLL_TOOLSFUNCTION bool fileSetLastWriteDate(const CXString& filename, const CXTime& time);
290DLL_TOOLSFUNCTION fileuint fileGetSize(const CXString& filename);
291DLL_TOOLSFUNCTION bool fileConvertSlash(CXString& dir); //!< Make slash OS compatible
292DLL_TOOLSFUNCTION void fileRemoveDuplicatedSlash(CXString& path);
293DLL_TOOLSFUNCTION void fileSlashTerminate(CXString& dir);
294DLL_TOOLSFUNCTION bool fileIsSlashTerminated(const CXString& path);
295DLL_TOOLSFUNCTION void fileRemoveSlashTermination(CXString& filenameWithoutExt);
296DLL_TOOLSFUNCTION void fileRemoveInvalidChar(CXString& path, char spaceReplace = ' '); //!< Remove any invalid character for a filename <>:"/\|?* and eventually replaces space without something else
297DLL_TOOLSFUNCTION bool fileGetCInfo(const CXString& filename, unsigned int& checksum1, unsigned int& checksum2, bool alert = FALSE);
298DLL_TOOLSFUNCTION bool fileIsDirectory(const CXString& filename, bool checkIfExists = FALSE, unsigned int* timeOut = NULL);
299DLL_TOOLSFUNCTION bool fileIsValidFileName(const CXString& filename, unsigned int checkMode);
300DLL_TOOLSFUNCTION DirCompare fileCompareDirectory(CXString dir1, CXString dir2);
301DLL_TOOLSFUNCTION bool fileIsSameFile(const CXString& file1, const CXString& file2);
302DLL_TOOLSFUNCTION bool fileIsSameDir(const CXString& file1, const CXString& file2);
303DLL_TOOLSFUNCTION bool filePathContainMatchingFile(const CXString& path, const CXString& pattern, xFileFindInfo *info = NULL, unsigned int* timeOut = NULL); //!< Fast check if matchin file exist in path
304DLL_TOOLSFUNCTION bool fileMatchWilcards(const CXString& reffilename, const CHashTable<CXString>& hashMap);
305DLL_TOOLSFUNCTION bool fileMatchWilcards(const CXString& filename, const CXString& pattern, bool caseSensitive);
306DLL_TOOLSFUNCTION CXString fileCutName(const CXString& filename, int maxNameSize = -1); //!< name couldn't be lower than 8 characters (without extension).
307DLL_TOOLSFUNCTION CXString fileRemoveNameDigitEnding(const CXString& filename, int& value); //!< Remove the final name digit if any. Return the digit value or -1 if no digit is present
308DLL_TOOLSFUNCTION CXString fileNextNumberedName(const CXString& filename, bool parenthesisFormat = true, int namesize = -1); //!< Given a filename, it returns the next numbered filename without checking if the file exists or not. It example.jpg will return example1.jpg
309DLL_TOOLSFUNCTION CXString fileCreateUniqueName(const CXString& filename, bool parenthesisFormat = true, int namesize = -1); //!< the name is truncated if namesize > 0
310DLL_TOOLSFUNCTION CXString fileCreateTmpName(const CXString& filename, bool allowUnicode = true);
311DLL_TOOLSFUNCTION bool fileIsUNCPath(const CXString& filename);
312DLL_TOOLSFUNCTION CXString fileGetRoot(const CXString& filename);
313DLL_TOOLSFUNCTION CXString fileGetTopDirectory(const CXString& filename, bool slashTerminate = false);
314DLL_TOOLSFUNCTION CXString fileStripPath(const CXString& filename, bool removeExtension = false);
315DLL_TOOLSFUNCTION CXString fileStripName(const CXString& filename);
316DLL_TOOLSFUNCTION CXString fileStripPathAndExtension(const CXString& filename);
317DLL_TOOLSFUNCTION CXString fileRemoveExtension(const CXString& filename);
318DLL_TOOLSFUNCTION CXString fileGetExtension(const CXString& filename);
319DLL_TOOLSFUNCTION bool fileGetParentDirectory(CXString& path); //!< Retrieve the parent directory of the provided directory (C:\\tmp1\\tmp2\\ return C:\\tmp1). If the path target a file, returns the parent directory of the file directory (C:\\tmp1\\tmp2\\file.txt return C:\\tmp1\\‍)
320DLL_TOOLSFUNCTION CXString fileCleanExtensionList(const CXString& extlist, bool extByDefault = TRUE, CHashTable<CXString> *hashMap = NULL);
321DLL_TOOLSFUNCTION int fileGetHashFromExtensionList(CXString& extlist, CHashTable<CXString>& hash, bool extByDefault = TRUE);
322DLL_TOOLSFUNCTION bool fileGetExtensionInfo(unsigned int type, CFileExt& fileinfo);
323DLL_TOOLSFUNCTION int fileGetExtensionArray(unsigned int fileclass, CXStringArray& array, bool addAsterisk = FALSE);
324DLL_TOOLSFUNCTION CXString fileGetMainExtension(unsigned int fileclass);
325DLL_TOOLSFUNCTION CXString fileGetMainExtension(const CXString& ext);
326DLL_TOOLSFUNCTION int fileGetExtensionArrayByProperty(unsigned int fileproperty, CXStringArray& array, bool addAsterisk = FALSE, bool onlyMain = FALSE);
327DLL_TOOLSFUNCTION bool fileGetFileExt(const CXString& extension, CFileExt& info);
328DLL_TOOLSFUNCTION unsigned int fileFindParser(const CXString& filename, unsigned int properties);
329DLL_TOOLSFUNCTION unsigned int fileGetProperties(const CXString& filename);
330DLL_TOOLSFUNCTION unsigned int fileGetClass(const CXString& filename);
331DLL_TOOLSFUNCTION unsigned int fileGetKindOf(const CXString& filename);
332DLL_TOOLSFUNCTION unsigned int fileGetProperties(unsigned int fileclass);
333DLL_TOOLSFUNCTION unsigned int fileGetKindOf(unsigned int fileclass);
334DLL_TOOLSFUNCTION unsigned int fileGetLoader(const CXString& filename);
335DLL_TOOLSFUNCTION unsigned int fileGetSaver(const CXString& filename);
336
337// Simple file operation
338DLL_TOOLSFUNCTION bool fileDelete(const CXString& filename);
339DLL_TOOLSFUNCTION bool fileCopy(const CXString& srcfile, const CXString& newfile, bool dontOverwrite = true);
340DLL_TOOLSFUNCTION bool fileRename(const CXString& srcfile, const CXString& dstfile);
341DLL_TOOLSFUNCTION bool fileCreateDirectory(const CXString& dir, bool recurseCreate);
342DLL_TOOLSFUNCTION bool fileRemoveDirectory(const CXString& dir, bool recurse, bool evenIfNotEmpty, CXStringArray *excludeExt = NULL);
343DLL_TOOLSFUNCTION int fileGetFileCount(const CXString& dir, bool recurse);
344DLL_TOOLSFUNCTION CXString fileCreateTmpFolder(const CXString& foldername, bool createFolder = true);
345
346#ifndef MOOTOOLS_NO_UI
347DLL_TOOLSFUNCTION CXString fileCompactPath(const CXString& path, CXWnd *pWnd, int width = 0);
348DLL_TOOLSFUNCTION bool fileAskForReplace(const CXString& filename);
349#endif
350
351#if !defined(MOOTOOLS_CRUNCHERSDK) && !defined(MRSDK_USE)
352DLL_TOOLSFUNCTION bool fileIsShortcut(const CXString& filename);
353DLL_TOOLSFUNCTION unsigned int fileGetDriveType(const CXString& filename);
354DLL_TOOLSFUNCTION bool fileIsOnNetworkDrive(const CXString& filename);
355DLL_TOOLSFUNCTION bool fileIsExecutable(const CXString& filename);
356DLL_TOOLSFUNCTION bool fileConvertToUNCPath(const CXString& path, CXString& uncPath);
357#endif
358
359#ifdef __WINDOWS__
360typedef enum IoTimeOut
361{
362 IOTIMEOUT_CREATE, // timeOutData is an opaque pointer that should be passed when call START/STOP/DELETE
363 IOTIMEOUT_CREATE_AND_ALWAYS_USE, // timeOutData is an opaque pointer that should be passed when call START/STOP/DELETE
367} IoTimeOut;
368
369DLL_TOOLSFUNCTION bool fileTimeOut(IoTimeOut operation, void *&timeOutData, const CXString *path = NULL, unsigned int timeOutDelay = IOTIMEOUT_DEFAULT);
370#endif
371
372//! @class CFileInfo
373//! @brief A convenient class to get some information giving a specific file name through a CFileNameSpec object
374class DLL_TOOLSFUNCTION CFileInfo
375{
376protected:
377 CXString filename; // original file name (lower case)
378 CXString sfilename; // cased sensitive original file name
379 CXString name; // short file name
380 CXString path; // path only
381 CXString query; // url parameters
382 CXString extension; // extension only
383 CXString root; // root if exists (\\COMPUTER1, C:\\‍)
384 CXString targetPath; // shortcut path
385
386 unsigned int loader;
387 unsigned int saver;
388 unsigned int fileclass;
389 unsigned int properties;
390 InitIOPluginFunc iocallback;
391
392protected:
393 typedef enum _FileInfoFlags
394 {
395 FILEINFO_NONE = 0x00,
396 FILEINFO_IS_DIRECTORY = 0x01,
397 FILEINFO_IS_UNC_FILE = 0x02,
398 FILEINFO_IS_SHORTCUT = 0x04,
399 FILEINFO_IS_URL = 0x08,
400
401 // Initialization flags
402 FILEINFO_DIRECTORY_CHECKED = 0x1000,
403 FILEINFO_UNC_FILE_CHECKED = 0x2000,
404 FILEINFO_SHORTCUT_CHECKED = 0x4000,
405 FILEINFO_IGNORE_CURRENT_DIRECTORY = 0x8000,
406 FILEINFO_TRY_OTHER_PARSER = 0x10000, // The user does not specify a specific class and there is several parser for the extension
407
408 // Others
409 FILEINFO_MULTI_PARSER_EXT = 0x100000, // The different parsers exist for the extension
410 } FileInfoFlags;
411
412 unsigned int currentParser;
413 unsigned int flags;
414 int reverseDot, reverseSlash, reverseQuestionMark;
415 int length;
416
417 void ExtractQuery();
418 void ExtractRoot();
419 void ExtractName();
420 void ExtractPath();
421 void ExtractExtension();
422
423public:
424 CFileInfo();
425 virtual ~CFileInfo();
426
427// void Init(const CXString& filename, FILENAME_TYPE type = FILENAME_UNKNOWN); // Retrieve info about a file
428 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 ambiguities (if path is relative for example)
429
430 CXString GetCompleteName() const; //!< Return filename (path included)
431 CXString GetName() const; //!< Return filename (without path)
432 CXString GetPath() const; //!< Return path
433 CXString GetRoot() const; //!< Return root
434 CXString GetExtension() const; //!< Return extension
435 CXString GetNameWithoutExt() const; //!< Return filename (without path and extension)
436 CXString GetPathWithoutRoot() const; //!< Return path without root
437 CXString GetQuery(bool includeQuestionMark = true) const; //!< Return query if path is an url. includeQuestionMark keeps the ? unless no query is specified
438 unsigned int GetParserNbr() const; //!< Return the parser number for the extension
439
440 bool CanTryAnotherParser() const;
441 void TryNextParser();
442 unsigned int GetLoader() const; //!< Return loader of file
443 unsigned int GetSaver() const; //!< Return saver of file
444 unsigned int GetProperties() const; //!< Return type of file
445 unsigned int GetKindOf() const; //!< Return kind of file
446 unsigned int GetClass() const; //!< Return type file class
447 InitIOPluginFunc GetInitIoCallback(); //!< Return the parser initializer function if parser is added at runtime. It can be located in a plugin (moox extension that export or define as a callback
448
449#if !defined(MOOTOOLS_CRUNCHERSDK) && !defined(MRSDK_USE)
450 bool IsShortcut(); //!< Is the file a shortcut?
451 CXString ResolveShortcut(); //!< Resolve file shortcut
452#endif
453
454 bool IsFile() const; //!< Is the filename a file?
455 bool IsURL() const; //!< Is the filename an URL? Note: An URL can also be a directory or a file.
456 bool IsDirectory() const; //!< Is the filename a directory?
457 bool IsUNCPath(); //!< Is the file on network?
458 CXString GetTopDirectory() const; //!< Return the directory name which contain the file
459 CXString GetParentDirectory() const; //!< Return the parent directory path
460 int GetDigitInfo(CXString& dstname, CXString& digitstring, bool addWildcard = false, bool endDigitOnly = false) const; //!< Return the digit value of the file, the name without digit, and the digit string. If several digit exists, first look at the end of the string, then the beginning. begaddWildcard = true, then * replace the digit. endDigitOnly, only care digit which are at the end of the string (not the beginning, if some exists)
461 static int GetDigit(const CXString& filename); //!< Return the digit value of the file, the name without digit, and the digit string
462
463 bool IsSameFile(const CXString& filename) const;
464 bool IsSameDir(const CXString& cmpfilename) const;
465
466#ifdef _DEBUG
467 void Dump();
468#endif
469};
470
471END_MOOTOOLS_NAMESPACE
472
473#endif // !defined(AFX_FILEINFO_H__12CD9483_C809_11D3_A382_9415BA0D2432__INCLUDED_)
CCustomData class is a handly class for storing any kind of data.
DLL_TOOLSFUNCTION bool fileMakePathShortest(CXString &path)
Converts C:\abc..\abc\file.txt to C:\abc\file.txt if possible or uneeded, path is not changed if conv...
DLL_TOOLSFUNCTION CXString fileCreateUniqueName(const CXString &filename, bool parenthesisFormat=true, int namesize=-1)
the name is truncated if namesize > 0
DLL_TOOLSFUNCTION CXString fileCutName(const CXString &filename, int maxNameSize=-1)
name couldn't be lower than 8 characters (without extension).
DLL_TOOLSFUNCTION CXString fileNextNumberedName(const CXString &filename, bool parenthesisFormat=true, int namesize=-1)
Given a filename, it returns the next numbered filename without checking if the file exists or not....
DLL_TOOLSFUNCTION bool filePathContainMatchingFile(const CXString &path, const CXString &pattern, xFileFindInfo *info=NULL, unsigned int *timeOut=NULL)
Fast check if matchin file exist in path.
DLL_TOOLSFUNCTION CXString fileRemoveNameDigitEnding(const CXString &filename, int &value)
Remove the final name digit if any. Return the digit value or -1 if no digit is present.
FILENAME_TYPE
Definition FileInfo.h:254
DLL_TOOLSFUNCTION bool filePopCurrentDirectory()
pop the latest push current directory
DLL_TOOLSFUNCTION bool fileConvertSlash(CXString &dir)
Make slash OS compatible.
DLL_TOOLSFUNCTION CXString fileMakeAbsolutePath(const CXString &mainpath, const CXString &relpath, bool slashTerminate=false)
if relpath is relative, it returns an absolute path using mainpath. If relpath is not relative or if ...
DLL_TOOLSFUNCTION bool filePushCurrentDirectory(const CXString &newpath, unsigned int *timeOut=NULL)
return true if directory change is a success. Whatever the results, filePopCurrentDirectory must alwa...
void fileRegisterFiles()
Automatically call to make all recognized by being registered and recognized.
DLL_TOOLSFUNCTION bool fileExists(const CXString &filename, unsigned int *timeOut=NULL)
Accessing file can take time. specify timeOut if critical (ie access through network)....
DLL_TOOLSFUNCTION CXString fileMakeRelativePath(const CXString &mainpath, const CXString &relpath, bool noSlashAndDotAtBeginning=false, FILENAME_TYPE type=FILENAME_UNKNOWN)
noSlashAndDotAtBeginning = false will return .\folder\filename.ext, noSlashAndDotAtBeginning = true w...
DLL_TOOLSFUNCTION void fileRemoveInvalidChar(CXString &path, char spaceReplace=' ')
Remove any invalid character for a filename <>:"/|?* and eventually replaces space without something ...
DLL_TOOLSFUNCTION bool fileGetParentDirectory(CXString &path)
Retrieve the parent directory of the provided directory (C:\tmp1\tmp2\ return C:\tmp1)....
CXTString< TCHAR > CXString
CXString depend on the target OS. Could be CXStringW (Windows) or CXStringA (Linux / Macos)
Definition XString.h:118
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
CFileExt is the class that allows to add a custom file parser for supporting a new file format....
Definition FileInfo.h:182
unsigned int fileclass
A tag created with MAKE_CUSTOM_ID.
Definition FileInfo.h:186
InitIOPluginFunc iocallback
The function which allows to create parser.
Definition FileInfo.h:194
unsigned int properties
Definition FileInfo.h:187
unsigned int saver
Inform about the file saver: MOOTOOLS_PARSER, PLUGIN_PARSER, CALLBACK_PARSER or something else (ie....
Definition FileInfo.h:193
unsigned int loader
Definition FileInfo.h:192
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.
static int GetDigit(const CXString &filename)
Return the digit value of the file, the name without digit, and the digit string.
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 IsUNCPath()
Is the file on network?
bool IsDirectory() const
Is the filename a directory?
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.
CXString GetRoot() const
Return root.
CXString GetQuery(bool includeQuestionMark=true) const
Return query if path is an url. includeQuestionMark keeps the ? unless no query is specified.
unsigned int GetKindOf() const
Return kind of file.
CXString GetPathWithoutRoot() const
Return path without root.
CXString GetPath() const
Return path.
CXString GetCompleteName() const
Return filename (path included)
CXString GetNameWithoutExt() const
Return filename (without path and extension)
CXString GetParentDirectory() const
Return the parent directory path.
InitIOPluginFunc GetInitIoCallback()
Return the parser initializer function if parser is added at runtime. It can be located in a plugin (...
unsigned int GetParserNbr() const
Return the parser number for the extension.
CXString GetExtension() const
Return extension.
int GetDigitInfo(CXString &dstname, CXString &digitstring, bool addWildcard=false, bool endDigitOnly=false) const
Return the digit value of the file, the name without digit, and the digit string. If several digit ex...
CXString GetTopDirectory() const
Return the directory name which contain the file.
A given extension may match several formats. In case of conflict CFileNameSpec is a way to indicate t...
Definition FileInfo.h:156
CXStringArray implement an array of CXString.
Definition XStringArray.h:25
Definition XTime.h:18