Subversion Repositories spk

Rev

Rev 173 | Rev 179 | 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
 
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;
111 cycrow 83
	Utils::CStringList *readLinesStr();
84
 
161 cycrow 85
	bool WriteFile(CyStringList *lines);
121 cycrow 86
	bool writeFile(std::vector<Utils::String> *lines);
87
	bool writeFileUTF(std::vector<Utils::String> *lines);
88
	bool writeFile(Utils::CStringList *lines);
1 cycrow 89
 
52 cycrow 90
	bool remove();
158 cycrow 91
	bool Rename(const Utils::String &toFile);
52 cycrow 92
	bool copy(const Utils::String &toFile, bool keepTime = false);
1 cycrow 93
 
52 cycrow 94
	bool isOpened() const;
82 cycrow 95
	bool open(const Utils::String &sFilename, bool bBinary = true);
1 cycrow 96
 
57 cycrow 97
	Utils::String baseName() const;
160 cycrow 98
	const Utils::String &fullFilename() const { return _sFilename; }
99
	const Utils::String &filename() const { return _sFile; }
100
	const Utils::String &dir() const { return _sDirIO.dir(); }
101
	CDirIO &GetDirIO() { return _sDirIO; }
1 cycrow 102
 
160 cycrow 103
	bool NoFile () { return _sFilename.empty(); }
1 cycrow 104
	size_t GetFilesize () { return m_lSize; }
105
 
106
	char *ReadToData ( size_t *size );
107
	bool WriteData ( const char *data, size_t size );
82 cycrow 108
	bool writeString ( const Utils::String &data );
1 cycrow 109
 
110
	bool WritePartFile ( size_t *offsets, size_t numOffset );
111
	int TruncateFile ( size_t offset, size_t datasize );
112
	bool WipeFile();
113
 
52 cycrow 114
	bool exists() const;
115
	bool ExistsOld () const;
82 cycrow 116
	bool appendFile ( const Utils::String &filename );
1 cycrow 117
	bool AppendData ( const char *d, size_t size );
118
	bool AppendDataToPos ( const char *d, size_t size, size_t start );
119
 
119 cycrow 120
	bool isFileExtension(const Utils::String &ext) { return (extension().Compare(ext)) ? true : false; }
121
 
160 cycrow 122
	Utils::String extension() const;
123
	Utils::String getWindowsFilename() const;
124 cycrow 124
	Utils::String changeFileExtension(const Utils::String &ext) const;
1 cycrow 125
 
118 cycrow 126
	void setDir(const Utils::String &dir);
52 cycrow 127
	void setAutoDelete(bool bDelete);
1 cycrow 128
 
129
private:
52 cycrow 130
	int _in() const;
131
	int _out() const;
132
	int _append() const;
133
	int _inout() const;
134
	bool _start(int iFlags, bool bSeekP);
51 cycrow 135
 
136
	void _readFileSize ();
52 cycrow 137
	void _seek(int iPos, int iFrom);
51 cycrow 138
 
52 cycrow 139
	bool _write(const char *buf, va_list args);
140
 
160 cycrow 141
	void _updateFilename();
142
 
51 cycrow 143
private:
160 cycrow 144
	Utils::String	_sFilename;
145
	Utils::String	_sFile;
146
	Utils::String	_sExt;
147
	CDirIO			_sDirIO;
1 cycrow 148
 
52 cycrow 149
	bool m_bSeekP;
1 cycrow 150
	bool m_bBinary;
52 cycrow 151
	bool m_bAutoDelete;
1 cycrow 152
 
52 cycrow 153
	std::fstream m_fId;
1 cycrow 154
 
155
	size_t m_lSize;
156
};
157
 
121 cycrow 158
#pragma warning( pop ) 
1 cycrow 159
#endif //__FILE_IO_H__
160