-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath.cpp
More file actions
149 lines (104 loc) · 2.38 KB
/
Copy pathpath.cpp
File metadata and controls
149 lines (104 loc) · 2.38 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "path.h"
#include <QDir>
namespace
{
QString remove_last_dir(QString dir)
{
int v1 = dir.lastIndexOf(QChar('/'));
int v2 = dir.lastIndexOf(QChar('\\'));
if (v1 == v2)
return QString();
int v = std::max(v1, v2);
return dir.mid(0, v);
}
QString getProjectDir()
{
QString current = QDir::currentPath();
for (int i = 0; i < 5; i++)
{
current = remove_last_dir(current);
if (QFile::exists(current + "/main.cpp"))
{
return current + "/";
}
}
return {};
}
QString getShaderBuildDir()
{
auto project_dir = getProjectDir();
if (project_dir.isEmpty())
return {};
const auto build_dir = project_dir + "shaders/build/";
if (QDir(build_dir).exists())
{
return build_dir;
}
return {};
}
QString getShaderDir()
{
QFile file(QDir::currentPath() + "/shaders.ini");
if (file.open(QIODevice::ReadOnly))
{
return QString::fromUtf8(file.readAll().trimmed());
}
QString current_shader = QDir::currentPath() + "/resources/shaders/build/";
if (QDir(current_shader).exists())
{
return current_shader;
}
QString project_shader_dir = getShaderBuildDir();
if (project_shader_dir.isEmpty())
return {};
if (file.open(QIODevice::WriteOnly))
{
file.write(project_shader_dir.toUtf8());
}
return project_shader_dir;
}
QString getResourcesDir()
{
QFile file(QDir::currentPath() + "/resources.ini");
if (file.open(QIODevice::ReadOnly))
{
return QString::fromUtf8(file.readAll().trimmed());
}
QString current_resources = QDir::currentPath() + "/resources/";
if (QDir(current_resources).exists())
{
return current_resources;
}
auto project_dir = getProjectDir();
if (project_dir.isEmpty())
return {};
QString resources_dir = project_dir + "resources/";
if (!QDir(resources_dir).exists())
{
return {};
}
if (file.open(QIODevice::WriteOnly))
{
file.write(resources_dir.toUtf8());
}
return resources_dir;
}
QString path_resources;
QString path_shaders;
}
QString path::getResources()
{
if (path_resources.isEmpty())
{
path_resources = getResourcesDir();
}
return path_resources;
}
QString path::getShaders()
{
if (path_shaders.isEmpty())
{
path_shaders = getShaderDir();
}
return path_shaders;
}