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