| 1 |
cycrow |
1 |
#ifndef __FILE_IO_H__
|
|
|
2 |
#define __FILE_IO_H__
|
|
|
3 |
|
| 121 |
cycrow |
4 |
#pragma warning( push )
|
|
|
5 |
#pragma warning( disable : 4251)
|
|
|
6 |
|
| 1 |
cycrow |
7 |
#include "CyString.h"
|
|
|
8 |
#include "StringList.h"
|
| 111 |
cycrow |
9 |
#include "Utils/StringList.h"
|
| 1 |
cycrow |
10 |
#include <fstream>
|
|
|
11 |
#include <vector>
|
|
|
12 |
#include "DirIO.h"
|
|
|
13 |
|
|
|
14 |
#include <time.h>
|
|
|
15 |
|
|
|
16 |
#if defined(_WIN32) || defined(OS2) || defined(MSDOS)
|
|
|
17 |
#include <fcntl.h>
|
|
|
18 |
#include <io.h>
|
|
|
19 |
#define MY_SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY)
|
|
|
20 |
#else
|
|
|
21 |
#define MY_SET_BINARY_MODE(file)
|
|
|
22 |
#endif
|
|
|
23 |
|
|
|
24 |
#define EPOCH_DIFF 0x019DB1DED53E8000LL /* 116444736000000000 nsecs */
|
|
|
25 |
#define RATE_DIFF 10000000 /* 100 nsecs */
|
|
|
26 |
|
|
|
27 |
class C_File;
|
|
|
28 |
|
|
|
29 |
enum {FILEERR_NONE, FILEERR_NOFILE, FILEERR_NOOPEN, FILEERR_TOSMALL, FILEERR_NOWRITE};
|
|
|
30 |
|
|
|
31 |
class SPKEXPORT CFileIO
|
|
|
32 |
{
|
|
|
33 |
public:
|
| 52 |
cycrow |
34 |
static bool Remove(const Utils::String &filename);
|
|
|
35 |
static bool Exists(const Utils::String &filename);
|
|
|
36 |
|
|
|
37 |
public:
|
|
|
38 |
CFileIO();
|
| 121 |
cycrow |
39 |
CFileIO(const Utils::String &sFilename, bool bBinary);
|
| 52 |
cycrow |
40 |
CFileIO(CyString filename);
|
|
|
41 |
CFileIO(C_File *file);
|
| 1 |
cycrow |
42 |
~CFileIO ();
|
|
|
43 |
|
| 52 |
cycrow |
44 |
bool startWrite();
|
|
|
45 |
bool startRead();
|
|
|
46 |
bool startModify();
|
|
|
47 |
bool startAppend();
|
| 56 |
cycrow |
48 |
bool atEnd() const;
|
| 1 |
cycrow |
49 |
|
| 52 |
cycrow |
50 |
size_t fileSize() const;
|
|
|
51 |
|
| 160 |
cycrow |
52 |
time_t modifiedTime() const;
|
|
|
53 |
time_t creationTime() const;
|
|
|
54 |
void setCreationTime(time_t time);
|
| 1 |
cycrow |
55 |
|
| 123 |
cycrow |
56 |
bool writeSize(size_t iSize);
|
| 52 |
cycrow |
57 |
bool write(CFileIO &file, size_t iSize);
|
|
|
58 |
bool write(const unsigned char *buf, ...);
|
|
|
59 |
bool write(const char *buf, ...);
|
| 123 |
cycrow |
60 |
bool write(const char *buf, size_t iSize);
|
|
|
61 |
bool write(const unsigned char *buf, size_t iSize);
|
| 52 |
cycrow |
62 |
bool put(const unsigned char c);
|
|
|
63 |
|
|
|
64 |
void close();
|
|
|
65 |
|
|
|
66 |
Utils::String readEndOfLine();
|
|
|
67 |
|
| 123 |
cycrow |
68 |
void seek(size_t iPos);
|
|
|
69 |
void seekEnd(size_t iPos = 0);
|
|
|
70 |
void seekStart(size_t iPos = 0);
|
| 58 |
cycrow |
71 |
size_t position();
|
| 52 |
cycrow |
72 |
|
| 56 |
cycrow |
73 |
int readSize();
|
| 52 |
cycrow |
74 |
bool read(unsigned char *buf, size_t iSize, bool bEndChar = false);
|
|
|
75 |
unsigned char *read(size_t iAmount);
|
|
|
76 |
unsigned char *readAll(size_t *pSize = NULL);
|
|
|
77 |
|
|
|
78 |
std::fstream &stream();
|
|
|
79 |
|
| 166 |
cycrow |
80 |
std::vector<Utils::String>* readLines() const;
|
| 170 |
cycrow |
81 |
size_t readLines(std::vector<Utils::String>& to) const;
|
|
|
82 |
size_t readLines(Utils::CStringList& to) const;
|
| 173 |
cycrow |
83 |
//CyStringList *ReadLinesStr();
|
| 111 |
cycrow |
84 |
Utils::CStringList *readLinesStr();
|
|
|
85 |
|
| 161 |
cycrow |
86 |
bool WriteFile(CyStringList *lines);
|
| 121 |
cycrow |
87 |
bool writeFile(std::vector<Utils::String> *lines);
|
|
|
88 |
bool writeFileUTF(std::vector<Utils::String> *lines);
|
|
|
89 |
bool writeFile(Utils::CStringList *lines);
|
| 1 |
cycrow |
90 |
|
| 52 |
cycrow |
91 |
bool remove();
|
| 158 |
cycrow |
92 |
bool Rename(const Utils::String &toFile);
|
| 52 |
cycrow |
93 |
bool copy(const Utils::String &toFile, bool keepTime = false);
|
| 1 |
cycrow |
94 |
|
| 52 |
cycrow |
95 |
bool isOpened() const;
|
| 82 |
cycrow |
96 |
bool open(const Utils::String &sFilename, bool bBinary = true);
|
| 1 |
cycrow |
97 |
|
| 57 |
cycrow |
98 |
Utils::String baseName() const;
|
| 160 |
cycrow |
99 |
const Utils::String &fullFilename() const { return _sFilename; }
|
|
|
100 |
const Utils::String &filename() const { return _sFile; }
|
|
|
101 |
const Utils::String &dir() const { return _sDirIO.dir(); }
|
|
|
102 |
CDirIO &GetDirIO() { return _sDirIO; }
|
| 1 |
cycrow |
103 |
|
| 160 |
cycrow |
104 |
bool NoFile () { return _sFilename.empty(); }
|
| 1 |
cycrow |
105 |
size_t GetFilesize () { return m_lSize; }
|
|
|
106 |
|
|
|
107 |
char *ReadToData ( size_t *size );
|
|
|
108 |
bool WriteData ( const char *data, size_t size );
|
| 82 |
cycrow |
109 |
bool writeString ( const Utils::String &data );
|
| 1 |
cycrow |
110 |
|
|
|
111 |
bool WritePartFile ( size_t *offsets, size_t numOffset );
|
|
|
112 |
int TruncateFile ( size_t offset, size_t datasize );
|
|
|
113 |
bool WipeFile();
|
|
|
114 |
|
| 52 |
cycrow |
115 |
bool exists() const;
|
|
|
116 |
bool ExistsOld () const;
|
| 82 |
cycrow |
117 |
bool appendFile ( const Utils::String &filename );
|
| 1 |
cycrow |
118 |
bool AppendData ( const char *d, size_t size );
|
|
|
119 |
bool AppendDataToPos ( const char *d, size_t size, size_t start );
|
|
|
120 |
|
| 119 |
cycrow |
121 |
bool isFileExtension(const Utils::String &ext) { return (extension().Compare(ext)) ? true : false; }
|
|
|
122 |
|
| 160 |
cycrow |
123 |
Utils::String extension() const;
|
|
|
124 |
Utils::String getWindowsFilename() const;
|
| 124 |
cycrow |
125 |
Utils::String changeFileExtension(const Utils::String &ext) const;
|
| 1 |
cycrow |
126 |
|
| 118 |
cycrow |
127 |
void setDir(const Utils::String &dir);
|
| 52 |
cycrow |
128 |
void setAutoDelete(bool bDelete);
|
| 1 |
cycrow |
129 |
|
|
|
130 |
private:
|
| 52 |
cycrow |
131 |
int _in() const;
|
|
|
132 |
int _out() const;
|
|
|
133 |
int _append() const;
|
|
|
134 |
int _inout() const;
|
|
|
135 |
bool _start(int iFlags, bool bSeekP);
|
| 51 |
cycrow |
136 |
|
|
|
137 |
void _readFileSize ();
|
| 52 |
cycrow |
138 |
void _seek(int iPos, int iFrom);
|
| 51 |
cycrow |
139 |
|
| 52 |
cycrow |
140 |
bool _write(const char *buf, va_list args);
|
|
|
141 |
|
| 160 |
cycrow |
142 |
void _updateFilename();
|
|
|
143 |
|
| 51 |
cycrow |
144 |
private:
|
| 160 |
cycrow |
145 |
Utils::String _sFilename;
|
|
|
146 |
Utils::String _sFile;
|
|
|
147 |
Utils::String _sExt;
|
|
|
148 |
CDirIO _sDirIO;
|
| 1 |
cycrow |
149 |
|
| 52 |
cycrow |
150 |
bool m_bSeekP;
|
| 1 |
cycrow |
151 |
bool m_bBinary;
|
| 52 |
cycrow |
152 |
bool m_bAutoDelete;
|
| 1 |
cycrow |
153 |
|
| 52 |
cycrow |
154 |
std::fstream m_fId;
|
| 1 |
cycrow |
155 |
|
|
|
156 |
size_t m_lSize;
|
|
|
157 |
};
|
|
|
158 |
|
| 121 |
cycrow |
159 |
#pragma warning( pop )
|
| 1 |
cycrow |
160 |
#endif //__FILE_IO_H__
|
|
|
161 |
|