Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "HFile.h"
- HFile::HFile()
- {
- FileHandle = NULL;
- }
- HFile::~HFile()
- {
- Close();
- }
- bool HFile::Open(const char* FilePath,bool CreateIfNotExists /* = true */)
- {
- FileHandle = CreateFile(
- FilePath,
- GENERIC_READ || GENERIC_WRITE,
- 0,
- NULL,
- CreateIfNotExists? OPEN_ALWAYS:OPEN_EXISTING,
- 0,
- NULL);
- return FileHandle != INVALID_HANDLE_VALUE;
- }
- bool HFile::Open(const string FilePath, bool CreateIfNotExists /* = true */)
- {
- return Open(FilePath.c_str(),CreateIfNotExists);
- }
- bool HFile::Create(const char* FilePath)
- {
- FileHandle = CreateFile(
- FilePath,
- GENERIC_WRITE,
- 0,
- NULL,
- CREATE_ALWAYS,
- 0,
- NULL);
- return FileHandle != INVALID_HANDLE_VALUE;
- }
- bool HFile::Create(const string& FilePath)
- {
- return Create(FilePath.c_str());
- }
- void HFile::Write(const char* info,UINT infoLen)
- {
- DWORD Temp;
- if (!WriteFile(FileHandle,info,infoLen, &Temp,NULL))
- printf("Can't Write\n");
- }
- void HFile::Write(const char* info)
- {
- Write(info,strlen(info));
- }
- void HFile::Write(const string& info)
- {
- Write(info.c_str(),info.length());
- }
- void HFile::Write(const int& n)
- {
- char* info = new char[50];
- sprintf(info,"%i",n);
- Write(info);
- delete[] info;
- }
- void HFile::Write(const double& n)
- {
- char* info = new char[50];
- sprintf(info,"%f",n);
- Write(info);
- delete[] info;
- }
- void HFile::WriteLine(const char* info)
- {
- Write(info);
- Write("\r\n");
- }
- void HFile::WriteLine(const string& info)
- {
- Write(info);
- Write("\r\n");
- }
- void HFile::WriteLine(const int&n)
- {
- Write(n);
- Write("\r\n");
- }
- void HFile::WriteLine(const double&n)
- {
- Write(n);
- Write("\r\n");
- }
- void HFile::WriteByte(byte n)
- {
- Write((char*)&n,1);
- }
- bool HFile::Read(char* output,UINT count)
- {
- DWORD ReadedBytes;
- return ReadFile(FileHandle,output,count,&ReadedBytes,NULL) && ReadedBytes;
- }
- bool HFile::Read(string& output,UINT count)
- {
- char* GetStr;
- bool Result = Read(GetStr,count);
- output = GetStr;
- delete[] GetStr;
- return Result;
- }
- bool HFile::ReadChar(char& output)
- {
- return Read(&output,1);
- }
- bool HFile::PeekChar(char& output)
- {
- bool result = ReadChar(output);
- DWORD CurrentPoint = SetFilePointer(FileHandle,0,NULL,FILE_CURRENT);
- long Posit;
- SetFilePointer(FileHandle,CurrentPoint-1,&Posit,FILE_BEGIN);
- return result;
- }
- bool HFile::ReadToSplit(string& output,const char* Split)
- {
- char Symbol;
- bool res = ReadChar(Symbol);
- if (!res) return false;
- output = "";
- while (strspn(&Symbol,Split) == 0)
- {
- output += Symbol;
- res = ReadChar(Symbol);
- if (!res) return false;
- }
- return true;
- }
- bool HFile::ReadToSplit(char* output,const char* Split)
- {
- string Str;
- bool res = ReadToSplit(Str,Split);
- if (!Str.empty())
- output = (char*)Str.c_str();
- return res;
- }
- void HFile::Close()
- {
- CloseHandle(FileHandle);
- }
Advertisement
Add Comment
Please, Sign In to add comment