Subversion Repositories spk

Rev

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