Subversion Repositories spk

Rev

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