-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadStream.cpp
90 lines (75 loc) · 1.3 KB
/
ReadStream.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "ReadStream.h"
std::ifstream* ReadStream::GetStream()
{
f.seekg(0, std::ios::beg);
return &f;
}
ReadStream::ReadStream(std::wstring filename)
{
f.open(filename, std::ios::in | std::ios::binary);
if (!f.is_open())
std::wcout << "Ôàéë íå îòêðûò";
}
ReadStream::~ReadStream()
{
if (f.is_open())
f.close();
}
HRESULT ReadStream::Read(PVOID64 buffer, INT64 seek, INT64 count)
{
if (!f.is_open())
return -1;
f.seekg(seek, std::ios::beg);
if (f.eof()) return 0;
//char *buffer = new char[count];
try
{
f.read((char*)buffer, count);
int tell = f.tellg();
if ((tell - seek) != count)
{
return -1;
}
if (tell < 0x0)
{
return -1;
}
}
catch (...)
{
std::wcout << "ERROR";
}
//return buffer;
return NOERROR;
}
ReadStreamText::ReadStreamText(std::wstring filename)
{
f.open(filename, std::ios::in);
if (!f.is_open())
std::wcout << "Ôàéë íå îòêðûò";
}
ReadStreamText::~ReadStreamText()
{
if (f.is_open())
f.close();
}
HRESULT ReadStreamText::Read(std::string* buffer, INT64 line)
{
if (!f.is_open())
return -1;
//f.seekg(seek, std::ios::beg);
if (f.eof()) return f.eof();
//char *buffer = new char[count];
try
{
char str[1024];
f >> str;
*buffer = std::string(str);
}
catch (...)
{
std::wcout << "ERROR";
}
//return buffer;
return NOERROR;
}