-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIO.cpp
More file actions
128 lines (99 loc) · 4.13 KB
/
IO.cpp
File metadata and controls
128 lines (99 loc) · 4.13 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "IO.h"
#include <iostream>
namespace Engine
{
//Important: Don't try to use IO in the constructor of a global object may result in an error or unexpected behavoir
namespace IO {
const char* projectPath;
std::vector<std::string> filePaths;//contains all the project folder files and directories
//pair<Name,Path>
std::vector<std::pair<std::string, std::string>> shaderPaths;//contains all the project folder shaders
std::vector<std::pair<std::string, std::string>> computeShaderPaths;
std::vector<std::pair<std::string, std::string>> texturePaths;
std::vector<std::pair<std::string, std::string>> modelPaths;
const char* getProjectPath() { return projectPath; }
void setProjectPath(const char* path) { projectPath = path; }
std::vector<std::string>* getFilePaths() { return &filePaths; }
std::vector<std::pair<std::string, std::string>>* getShaderPaths() { return &shaderPaths; }
std::vector<std::pair<std::string, std::string>>* getComputeShaderPaths() { return &computeShaderPaths; }
std::vector<std::pair<std::string, std::string>>* getTexturesPaths() { return &texturePaths; }
std::vector<std::pair<std::string, std::string>>* getModelPaths() { return &modelPaths; }
void printProjectFiles() {
for (auto& p : fs::recursive_directory_iterator(projectPath)) {
//std::cout << p.path() << '\n';
std::string s = p.path().string();
std::cout << s << " Has extension " << p.path().has_extension() << '\n';
}
}
void printEngineRCSFiles() {
for (auto& p : fs::recursive_directory_iterator("./rcs")) {
//std::cout << p.path() << '\n';
std::string s = p.path().string();
std::cout << s << " Has extension " << p.path().has_extension() << '\n';
}
}
void scanFiles() {
filePaths.clear();
shaderPaths.clear();
computeShaderPaths.clear();
texturePaths.clear();
modelPaths.clear();
//Scan Engine resources Path
for (auto& p : fs::recursive_directory_iterator("./rcs")) {
std::string path = p.path().string();
std::string extension = p.path().extension().string();
std::string nameExt = p.path().filename().string();//name with extension
std::string name = nameExt.substr(0, nameExt.size() - extension.size());//name without extension
//Convert extension to lowercase
char c;
int i = 0;
std::string lExtension = "";
while (extension[i])
{
lExtension += std::tolower(extension[i]);
i++;
}
if (p.path().has_extension())
{
if (lExtension == ".glsl")
shaderPaths.push_back(std::pair<std::string, std::string>(name, path));
if (lExtension == ".comp")
computeShaderPaths.push_back(std::pair<std::string, std::string>(name, path));
else if (lExtension == ".jpg" || lExtension == ".png")
texturePaths.push_back(std::pair<std::string, std::string>(name, path));
else if (lExtension == ".obj" || lExtension == ".gltf")
modelPaths.push_back(std::pair<std::string, std::string>(name, path));
}
filePaths.push_back(path);//Add path
}
//Scan Project Path
for (auto& p : fs::recursive_directory_iterator(projectPath)) {
std::string path = p.path().string();
std::string extension = p.path().extension().string();
std::string nameExt = p.path().filename().string();//name with extension
std::string name = nameExt.substr(0, nameExt.size() - extension.size());//name without extension
//Convert extension to lowercase
char c;
int i = 0;
std::string lExtension = "";
while (extension[i])
{
lExtension += std::tolower(extension[i]);
i++;
}
if (p.path().has_extension())
{
if (lExtension == ".glsl")
shaderPaths.push_back(std::pair<std::string, std::string>(name, path));
if (lExtension == ".comp")
computeShaderPaths.push_back(std::pair<std::string, std::string>(path, name));
else if (lExtension == ".jpg" || lExtension == ".png")
texturePaths.push_back(std::pair<std::string, std::string>(name, path));
else if (lExtension == ".obj" || lExtension == ".gltf")
modelPaths.push_back(std::pair<std::string, std::string>(name, path));
}
filePaths.push_back(path);//Add path
}
}
}
}