Subversion Repositories spk

Rev

Rev 1 | Rev 52 | 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:
30
	CFileIO ();
31
	CFileIO ( CyString filename );
32
	CFileIO ( C_File *file );
33
	~CFileIO ();
34
 
35
	bool StartRead();
36
	void StopRead();
37
	CyString ReadToEndLine(bool = true);
38
	bool AtEnd();
39
 
40
	time_t GetCreationTime();
41
	void SetCreationTime(time_t time);
42
 
43
	std::vector<CyString> *ReadLines();
44
	CyStringList *ReadLinesStr();
45
	bool WriteFile(std::vector<CyString> *lines);
46
	bool WriteFileUTF(std::vector<CyString> *lines);
47
	bool WriteFile(CyStringList *lines);
48
 
49
	bool Remove();
50
	bool Rename(CyString toFile);
51
	bool Copy(CyString toFile, bool keepTime = false);
52
 
53
	bool IsOpened();
54
	bool Open ( CyString filename, bool = true );
55
 
56
	CyString GetBaseName();
57
	CyString GetFullFilename () { return m_sFilename; }
58
	CyString GetFilename () { return m_sFile; }
59
	CyString GetDir() { return m_sDirIO.Dir(); }
60
	CDirIO &GetDirIO() { return m_sDirIO; }
61
 
51 cycrow 62
	bool NoFile () { return m_sFilename.empty(); }
1 cycrow 63
	size_t GetFilesize () { return m_lSize; }
64
 
65
	char *ReadToData ( size_t *size );
66
	bool WriteData ( const char *data, size_t size );
67
	bool WriteString ( CyString data );
68
 
69
	bool WritePartFile ( size_t *offsets, size_t numOffset );
70
	int TruncateFile ( size_t offset, size_t datasize );
71
	bool WipeFile();
72
 
73
 
74
	bool Exists ();
75
	bool AppendFile ( CyString filename );
76
	bool AppendData ( const char *d, size_t size );
77
	bool AppendDataToPos ( const char *d, size_t size, size_t start );
78
 
79
	bool CheckFileExtension(CyString ext) { return (GetFileExtension().Compare(ext)) ? true : false; }
80
	CyString GetFileExtension ();
81
	CyString ChangeFileExtension ( CyString ext );
82
	CyString GetWindowsFilename();
83
 
84
	void SetDir ( CyString dir );
85
 
86
private:
51 cycrow 87
	int _in();
88
	int _out();
89
	int _append();
90
 
91
	void _readFileSize ();
92
 
93
private:
94
	Utils::String m_sFilename;
95
	Utils::String m_sFile;
1 cycrow 96
	CDirIO   m_sDirIO;
97
 
98
	bool m_bOpened;
99
	bool m_bBinary;
100
 
101
	std::ifstream m_fId;
102
 
103
	size_t m_lSize;
104
};
105
 
106
#endif //__FILE_IO_H__
107