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