HatchKeeper  0.90
The Free Open-Source Egg Incubation Software
HK_File.cpp
Go to the documentation of this file.
1 /*******************************************************************/
9 #include "../headers/File.h"
10 
14 HK_File::HK_File(string Path){HK_FilePath = Path;}
15 
17 bool HK_File::Copy(string Target)
18 {
19  return CopyFile(HK_FilePath, Target);
20 }
21 
23 bool HK_File::CopyFile(string Original, string Target)
24 {
25  FILE *fold , *fnew;
26 
27 
28  if( (fold = fopen(Original.c_str(), "rb")) == NULL)
29  return false;
30 
31  if( (fnew = fopen(Target.c_str(), "wb")) == NULL) {
32  fclose(fold);
33  return false;
34  }
35 
36  int c;
37  while(1) {
38  c = fgetc(fold);
39 
40  if( !feof(fold))
41  fputc(c, fnew);
42  else
43  break;
44  }
45  fclose(fold);
46  fclose(fnew);
47 
48  return true;
49 }
50 
52 string HK_File::GetPath(){return HK_FilePath;}
53 
56 {
57  return ReadTextFile(HK_FilePath);
58 }
59 
61 string HK_File::ReadTextFile(string FileName)
62 {
63  char Char;
64  string Text;
65 
66  ifstream FileIn(FileName);
67  if (!FileIn)
68  return "Error: Can't Open File";
69 
70  while (FileIn.get(Char))
71  Text += Char;
72 
73  FileIn.close();
74 
75  return Text;
76 }
77 
78 
80 bool HK_File::WriteText(string Text)
81 {
82  return WriteTextFile(HK_FilePath,Text);
83 }
84 
86 bool HK_File::WriteTextFile(string FileName, string Text)
87 {
88  ofstream OutFile(FileName);
89 
90  if(!OutFile)
91  return false;
92 
93  if(OutFile.fail())
94  return false;
95 
96  OutFile<<Text<<endl;
97 
98  OutFile.close();
99 
100  return true;
101 }
102 
103 
104 
106 vector<string> HK_File::ScanFiles(string Path)
107 {
108 
109 
110 }
vector< string > ScanFiles(string Path)
Not Setup Yet.
Definition: HK_File.cpp:106
bool WriteTextFile(string FileName, string Text)
Opens Filename And Writes Text.
Definition: HK_File.cpp:86
bool CopyFile(string Original, string Target)
A Simple C Function To Copy File From Original To Target.
Definition: HK_File.cpp:23
bool WriteText(string Text)
Writes Text To HK_FilePath.
Definition: HK_File.cpp:80
bool Copy(string Target)
Copy HK_FilePath To Target.
Definition: HK_File.cpp:17
HK_File()
Constructor.
Definition: HK_File.cpp:12
string GetPath()
Returns Path.
Definition: HK_File.cpp:52
string ReadText()
Reads HK_FilePath Into String.
Definition: HK_File.cpp:55
string HK_FilePath
Definition: File.h:28
string ReadTextFile(string FileName)
Reads FileName Into String.
Definition: HK_File.cpp:61