Subversion Repositories spk

Rev

Rev 82 | Rev 102 | 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();
56 cycrow 44
	bool atEnd() const;
1 cycrow 45
 
52 cycrow 46
	size_t fileSize() const;
47
 
48
	time_t modifiedTime();
1 cycrow 49
	time_t GetCreationTime();
50
	void SetCreationTime(time_t time);
51
 
52 cycrow 52
	bool writeSize(unsigned int iSize);
53
	bool write(CFileIO &file, size_t iSize);
54
	bool write(const unsigned char *buf, ...);
55
	bool write(const char *buf, ...);
56
	bool write(const char *buf, unsigned int iSize);
57
	bool write(const unsigned char *buf, unsigned int iSize);
58
	bool put(const unsigned char c);
59
 
60
	void close();
61
 
62
	Utils::String readEndOfLine();
63
 
64
	void seek(unsigned int iPos);
53 cycrow 65
	void seekEnd(unsigned int iPos = 0);
52 cycrow 66
	void seekStart(unsigned int iPos = 0);
58 cycrow 67
	size_t position();
52 cycrow 68
 
56 cycrow 69
	int readSize();
52 cycrow 70
	bool read(unsigned char *buf, size_t iSize, bool bEndChar = false);
71
	unsigned char *read(size_t iAmount);
72
	unsigned char *readAll(size_t *pSize = NULL);
73
 
74
	std::fstream &stream();
75
 
82 cycrow 76
	std::vector<Utils::String> *readLines();
1 cycrow 77
	std::vector<CyString> *ReadLines();
78
	CyStringList *ReadLinesStr();
79
	bool WriteFile(std::vector<CyString> *lines);
80
	bool WriteFileUTF(std::vector<CyString> *lines);
81
	bool WriteFile(CyStringList *lines);
82
 
52 cycrow 83
	bool remove();
1 cycrow 84
	bool Rename(CyString toFile);
52 cycrow 85
	bool copy(const Utils::String &toFile, bool keepTime = false);
1 cycrow 86
 
52 cycrow 87
	bool isOpened() const;
1 cycrow 88
	bool Open ( CyString filename, bool = true );
82 cycrow 89
	bool open(const Utils::String &sFilename, bool bBinary = true);
1 cycrow 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; }
85 cycrow 94
	const Utils::String &dir() const { return m_sDirIO.dir(); }
1 cycrow 95
	CyString GetFullFilename () { return m_sFilename; }
96
	CyString GetFilename () { return m_sFile; }
97
	CyString GetDir() { return m_sDirIO.Dir(); }
98
	CDirIO &GetDirIO() { return m_sDirIO; }
99
 
51 cycrow 100
	bool NoFile () { return m_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;
1 cycrow 113
	bool AppendFile ( CyString filename );
82 cycrow 114
	bool appendFile ( const Utils::String &filename );
1 cycrow 115
	bool AppendData ( const char *d, size_t size );
116
	bool AppendDataToPos ( const char *d, size_t size, size_t start );
117
 
118
	bool CheckFileExtension(CyString ext) { return (GetFileExtension().Compare(ext)) ? true : false; }
58 cycrow 119
	Utils::String extension();
1 cycrow 120
	CyString GetFileExtension ();
121
	CyString ChangeFileExtension ( CyString ext );
122
	CyString GetWindowsFilename();
123
 
124
	void SetDir ( CyString dir );
52 cycrow 125
	void setAutoDelete(bool bDelete);
1 cycrow 126
 
127
private:
52 cycrow 128
	int _in() const;
129
	int _out() const;
130
	int _append() const;
131
	int _inout() const;
132
	bool _start(int iFlags, bool bSeekP);
51 cycrow 133
 
134
	void _readFileSize ();
52 cycrow 135
	void _seek(int iPos, int iFrom);
51 cycrow 136
 
52 cycrow 137
	bool _write(const char *buf, va_list args);
138
 
51 cycrow 139
private:
140
	Utils::String m_sFilename;
141
	Utils::String m_sFile;
1 cycrow 142
	CDirIO   m_sDirIO;
143
 
52 cycrow 144
	bool m_bSeekP;
1 cycrow 145
	bool m_bBinary;
52 cycrow 146
	bool m_bAutoDelete;
1 cycrow 147
 
52 cycrow 148
	std::fstream m_fId;
1 cycrow 149
 
150
	size_t m_lSize;
151
};
152
 
153
#endif //__FILE_IO_H__
154