-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileManager.cpp
More file actions
74 lines (61 loc) · 1.81 KB
/
FileManager.cpp
File metadata and controls
74 lines (61 loc) · 1.81 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
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <filesystem>
#include <fstream>
#include "FileWatcher.h"
#include "Engine.h"
#include "FileManager.h"
FileManager::FileManager(Engine* _engine, std::string _dirPath){
engine = _engine;
dirPath = _dirPath;
std::filesystem::create_directory(dirPath);
}
FileManager::FileManager(std::string _testPath) { // this is for testing
dirPath = _testPath;
}
void FileManager::writeFile(std::string _path, char* _data, unsigned int _dataLength) {
std::string path = _path;
path.erase(0,1);
path = dirPath + path;
std::string directory = "";
std::string cur = "";
for(unsigned i = 0; i < path.length(); i++) {
if (path.at(i) == '/') {
directory += cur;
std::filesystem::create_directory(directory);
cur = "";
}
cur += path.at(i);
}
if (cur.at(1) != '.') {
std::ofstream(path, std::ios::binary).write(_data, _dataLength);
engine->fileWatcher->updateFileTimes(path);
} else {
//std::cerr << "didnt write" << temp << std::endl;
}
}
std::vector<char> FileManager::getFileData(std::string _path) {
std::string path = _path;
path.erase(0,1);
path = dirPath + path;
std::ifstream input(path, std::ios::binary);
std::vector<char> bytes(
(std::istreambuf_iterator<char>(input)),
(std::istreambuf_iterator<char>())
);
input.close();
return bytes;
}
void FileManager::deleteFile(std::string _path) {
std::string path = _path;
path.erase(0,1);
path = dirPath + path;
std::filesystem::remove( path.c_str() );
}
void FileManager::deleteDirectory(std::string _path){
std::string path = _path;
path.erase(0,1);
path = dirPath + path;
std::filesystem::remove_all( path.c_str() );
}