-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFileUtils.cpp
More file actions
90 lines (73 loc) · 1.67 KB
/
FileUtils.cpp
File metadata and controls
90 lines (73 loc) · 1.67 KB
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
#include <cstdint>
#include <string>
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include "FileUtils.h"
using namespace std;
FileUtils::FileUtils() {
m_filefullpath = "";
bIsValid = false;
m_iIndex = 0;
}
// Specify the full path to the file.
void FileUtils::setFileFullPath(string s)
{
m_filefullpath = s;
if (fileExists() && getFileSize() > 0) {
bIsValid = true;
}
m_iIndex = 0;
}
string FileUtils::getFileFullPath()
{
return m_filefullpath;
}
string FileUtils::getSuffix()
{
if (m_filefullpath.find_last_of(".") != std::string::npos) {
return m_filefullpath.substr(m_filefullpath.find_last_of(".")+1);
}
return "";
}
// Return just the filename from the full path.
string FileUtils::getFilename()
{
return m_filefullpath.substr(m_filefullpath.find_last_of("/\\") + 1);
}
bool FileUtils::fileExists()
{
bool bRet = false;
if (m_filefullpath != "" ) {
ifstream infile(m_filefullpath.c_str());
bRet = infile.good();
}
return bRet;
}
uint32_t FileUtils::getFileSize()
{
uint32_t size = 0;
if (fileExists())
{
ifstream in(m_filefullpath.c_str(), ifstream::ate | ifstream::binary);
size = (uint32_t)in.tellg();
}
return size;
}
bool FileUtils:: getIsValid()
{
return bIsValid;
}
size_t FileUtils::getBytes(uint32_t num, unsigned char *buf)
{
size_t iNumCopied = 0;
FILE* fp = fopen(m_filefullpath.c_str(), "rb");
if (fp) {
fseek(fp, m_iIndex, SEEK_SET);
iNumCopied = fread(buf, sizeof(unsigned char), num, fp);
fclose(fp);
m_iIndex += iNumCopied;
}
return iNumCopied;
}