Subversion Repositories spk

Rev

Rev 179 | Rev 196 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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