Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
xfileoperation.h
1//
2// xfileoperation.h
3// These functions are declared in macos_fileoperation, win_fileoperation...
4//
5// Created by Mootools on 20/05/2016.
6// Copyright © 2016 Mootools. All rights reserved.
7//
8
9#ifndef xfileoperation_h
10#define xfileoperation_h
11
12#include "XTime.h"
13#include "XFile.h"
14
15BEGIN_MOOTOOLS_NAMESPACE
16
17//////////////////////////////////////////////////////////////
18// File access - Open / close file
19//
20//bool xFileOpen(FILE **f, const CXString& name, const CXString& mode);
21#define XFILE_ERROR ((fileuint)-1)
22
23xFileHandle xFileOpen(const CXString& name, unsigned int mode);
24bool xFileClose(xFileHandle handle); // Return true if handle is NULL or file handle succeed to be closed.
25fileuint xFileRead(xFileHandle handle, void *buffer, fileuint maxByteToRead); // return the effective number of byte read. XFILE_ERROR means an error
26fileuint xFileWrite(xFileHandle handle, const void *buffer, fileuint byteToWrite); // Return the effective number of byte written. XFILE_ERROR or less means an error
27bool xFileFlush(xFileHandle handle);
28bool xFileIsValid(xFileHandle handle); // Return true if the handle is valid, false if null or invalid.
29fileuint xFileSeek(xFileHandle handle, longint position, CXFile::SeekPosition mode); // Position the file pointer. Return the position or XFILE_ERROR
30fileuint xFileGetPosition(xFileHandle handle); // Get file pointer position. Return the position or XFILE_ERROR
31fileuint xFileGetSize(xFileHandle handle); // Return file size or XFILE_ERROR
32bool xFileSetSize(xFileHandle handle, fileuint size);
33
34xFileHandle xFileGetHandleFromStream(FILE *stream); // Get an O/S file handle from a FILE stream, NULL if fails
35FILE *xFileGetStreamFromHandle(xFileHandle fileHandle, unsigned int mode); // Get a file handle from a FILE stream, NULL if fails
36
37///////////////////////////////////////////
38// Basic file operation Copy / Delete files
39bool xFileRename(const CXString& srcfile, const CXString& newfile);
40bool xFileCopy(const CXString& srcfile, const CXString& newfile, bool dontOverwrite);
41bool xFileDelete(const CXString& file);
42bool xDirectoryCreate(const CXString& dir);
43bool xDirectoryRemove(const CXString& dir); // Remove directory, fails if directory is not empty
44
45//////////////////////////////////////////////////////////
46// Get file information and find file on disk
47//
48
49typedef enum XFILE_ATTRIBUTE XEnumType(unsigned int)
50{
51 XFILE_ATTRIBUTE_INVALID = 0, // filename is invalid
52 XFILE_ATTRIBUTE_NORMAL = 0x01,
53 XFILE_ATTRIBUTE_READONLY = 0x02,
54 XFILE_ATTRIBUTE_HIDDEN = 0x04,
55 XFILE_ATTRIBUTE_DIRECTORY = 0x08,
56} XFILE_ATTRIBUTE;
57
58typedef struct xFileInfo
59{
60 unsigned int attributes; // XFILE_ATTRIBUTE combination, XFILE_ATTRIBUTE_INVALID if file does not exists
61 fileuint size; // -1 if file does not exist
62} xFileInfo;
63
64typedef struct xFileFindInfo
65{
66 CXString filename;
67 xFileInfo fileinfo;
68} xFileFindInfo;
69
70bool xFileGetInfo(const CXString& filename, xFileInfo& info); // Get file info, return false if file does not exists.
71xFileFindHandle xFileFindInit(const CXString& filename, xFileFindInfo *info); // info is optionnal. If not provided, we only check the existence of the file
72bool xFileFindNext(xFileFindHandle handle, xFileFindInfo *info); // info is optionnal. If not provided, we only check the existence of the file
73bool xFileFindClose(xFileFindHandle handle);
74
75typedef enum
76{
77 XFILE_TIME_CREATED = 1,
78 XFILE_TIME_MODIFIED,
79 XFILE_TIME_ACCESS,
80} XFILE_TIMETYPE;
81
82//////////////////////////////////////////////////////////
83// Information on file
84//
85
86bool xFileGetTime(CXTime& filetime, const CXString& file, XFILE_TIMETYPE type);
87bool xFileSetTime(const CXTime& time, const CXString& filename, XFILE_TIMETYPE type);
88
89//////////////////////////////////////////////////////////
90// Special features - running context
91//
92bool xFileGetTmpFolder(CXString& tmpfolder); // Return true if tmp folder is support by the OS, false if not. tmpFolder value is set to the tmp directory or a tmp folder in the application directory
93bool xFileGetCurrentDirectory(CXString& currentfolder); // Return true if current folder is support by the OS or previously set by xFileSetCurrentDirectory, false if not. currentfolder value is set to the current OS directory or the application directory with a slash termination
94bool xFileSetCurrentDirectory(const CXString& newcurrentfolder); // Set the current directory. Return true if it succeed
95
96CXString xFileGetRunningApplicationName(); // Return the path of the running application in lower case string, including the path
97CXFileException::FileExceptionType xFileGetLastErrorException(); // Return an OS error code related to file operation. If no error code is not supported by the OS return CXFileException::none
98
99END_MOOTOOLS_NAMESPACE
100
101#endif /* xfileoperation_h */
CXFile is the base class for different kind of file (CXStdioFile, CXMemFile...)
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
Definition XTime.h:18