Rev 57 | Rev 85 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#ifndef __FILE_IO_H__#define __FILE_IO_H__#include "CyString.h"#include "StringList.h"#include <fstream>#include <vector>#include "DirIO.h"#include <time.h>#if defined(_WIN32) || defined(OS2) || defined(MSDOS)#include <fcntl.h>#include <io.h>#define MY_SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY)#else#define MY_SET_BINARY_MODE(file)#endif#define EPOCH_DIFF 0x019DB1DED53E8000LL /* 116444736000000000 nsecs */#define RATE_DIFF 10000000 /* 100 nsecs */class C_File;enum {FILEERR_NONE, FILEERR_NOFILE, FILEERR_NOOPEN, FILEERR_TOSMALL, FILEERR_NOWRITE};class SPKEXPORT CFileIO{public:static bool Remove(const Utils::String &filename);static bool Exists(const Utils::String &filename);public:CFileIO();//CFileIO(const Utils::String &sFilename, bool bBinary = true);CFileIO(CyString filename);CFileIO(C_File *file);~CFileIO ();bool startWrite();bool startRead();bool startModify();bool startAppend();bool StartRead();void StopRead();bool AtEnd() const;bool atEnd() const;size_t fileSize() const;time_t modifiedTime();time_t GetCreationTime();void SetCreationTime(time_t time);bool writeSize(unsigned int iSize);bool write(CFileIO &file, size_t iSize);bool write(const unsigned char *buf, ...);bool write(const char *buf, ...);bool write(const char *buf, unsigned int iSize);bool write(const unsigned char *buf, unsigned int iSize);bool put(const unsigned char c);void close();Utils::String readEndOfLine();void seek(unsigned int iPos);void seekEnd(unsigned int iPos = 0);void seekStart(unsigned int iPos = 0);size_t position();int readSize();bool read(unsigned char *buf, size_t iSize, bool bEndChar = false);unsigned char *read(size_t iAmount);unsigned char *readAll(size_t *pSize = NULL);std::fstream &stream();std::vector<CyString> *ReadLines();CyStringList *ReadLinesStr();bool WriteFile(std::vector<CyString> *lines);bool WriteFileUTF(std::vector<CyString> *lines);bool WriteFile(CyStringList *lines);bool remove();bool Rename(CyString toFile);bool copy(const Utils::String &toFile, bool keepTime = false);bool isOpened() const;bool Open ( CyString filename, bool = true );Utils::String baseName() const;const Utils::String &fullFilename() const { return m_sFilename; }const Utils::String &filename() const { return m_sFile; }CyString GetFullFilename () { return m_sFilename; }CyString GetFilename () { return m_sFile; }CyString GetDir() { return m_sDirIO.Dir(); }CDirIO &GetDirIO() { return m_sDirIO; }bool NoFile () { return m_sFilename.empty(); }size_t GetFilesize () { return m_lSize; }char *ReadToData ( size_t *size );bool WriteData ( const char *data, size_t size );bool WriteString ( CyString data );bool WritePartFile ( size_t *offsets, size_t numOffset );int TruncateFile ( size_t offset, size_t datasize );bool WipeFile();bool exists() const;bool ExistsOld () const;bool AppendFile ( CyString filename );bool AppendData ( const char *d, size_t size );bool AppendDataToPos ( const char *d, size_t size, size_t start );bool CheckFileExtension(CyString ext) { return (GetFileExtension().Compare(ext)) ? true : false; }Utils::String extension();CyString GetFileExtension ();CyString ChangeFileExtension ( CyString ext );CyString GetWindowsFilename();void SetDir ( CyString dir );void setAutoDelete(bool bDelete);private:int _in() const;int _out() const;int _append() const;int _inout() const;bool _start(int iFlags, bool bSeekP);void _readFileSize ();void _seek(int iPos, int iFrom);bool _write(const char *buf, va_list args);private:Utils::String m_sFilename;Utils::String m_sFile;CDirIO m_sDirIO;bool m_bSeekP;bool m_bBinary;bool m_bAutoDelete;std::fstream m_fId;size_t m_lSize;};#endif //__FILE_IO_H__