Fix problem with directories having slash at the end

This commit is contained in:
Thraix
2019-10-05 14:32:02 +02:00
parent dab0006ebb
commit 6b2b83d25c
2 changed files with 29 additions and 17 deletions
+2 -2
View File
@@ -2,12 +2,12 @@
#libdirs #libdirs
#includedirs #includedirs
#srcdir #srcdir
src/ src
#defines #defines
_DEBUG _DEBUG
#compileflags #compileflags
#outputdir #outputdir
bin/ bin
#projectname #projectname
MakeGen MakeGen
#outputname #outputname
+27 -15
View File
@@ -24,28 +24,32 @@ ConfigFile ConfigFile::Load(const std::string& filepath)
std::string* s; std::string* s;
bool* b; bool* b;
bool isDirectory = false;
std::ifstream file(filepath+CONFIG_FILENAME); std::ifstream file(filepath+CONFIG_FILENAME);
std::string line; std::string line;
if(file.is_open()) if(file.is_open())
{ {
std::map<std::string, std::string*> strings = // config name, { pointer to memory, isDirectory}
std::map<std::string, std::pair<std::string*, bool>> strings =
{ {
{"#srcdir", &conf.srcdir}, {"#srcdir", {&conf.srcdir, true}},
{"#outputdir", &conf.outputdir}, {"#outputdir", {&conf.outputdir, true}},
{"#outputname", &conf.outputname}, {"#outputname", {&conf.outputname, false}},
{"#projectname", &conf.projectname}, {"#projectname", {&conf.projectname, false}},
{"#hfile", &conf.hFile}, {"#hfile", {&conf.hFile, false}},
}; };
std::map<std::string, std::vector<std::string>*> vectors = // config name, { pointer to memory, isDirectory}
std::map<std::string, std::pair<std::vector<std::string>*, bool>> vectors =
{ {
{"#libs", &conf.libs}, {"#libs", {&conf.libs, false}},
{"#libdirs", &conf.libdirs}, {"#libdirs", {&conf.libdirs, true}},
{"#includedirs", &conf.includedirs}, {"#includedirs", {&conf.includedirs, true}},
{"#compileflags", &conf.flags}, {"#compileflags", {&conf.flags, false}},
{"#defines", &conf.defines}, {"#defines", {&conf.defines, false}},
{"#dependencies", &conf.dependencies}, {"#dependencies", {&conf.dependencies, true}},
}; };
std::map<std::string, bool*> booleans = std::map<std::string, bool*> booleans =
@@ -66,7 +70,8 @@ ConfigFile ConfigFile::Load(const std::string& filepath)
auto&& itStr{strings.find(line)}; auto&& itStr{strings.find(line)};
if(itStr != strings.end()) if(itStr != strings.end())
{ {
s = itStr->second; s = itStr->second.first;
isDirectory = itStr->second.second;
loadFlag = FLAG_STRING; loadFlag = FLAG_STRING;
} }
else else
@@ -74,7 +79,8 @@ ConfigFile ConfigFile::Load(const std::string& filepath)
auto&& itVec{vectors.find(line)}; auto&& itVec{vectors.find(line)};
if(itVec != vectors.end()) if(itVec != vectors.end())
{ {
vec = itVec->second; vec = itVec->second.first;
isDirectory = itVec->second.second;
loadFlag = FLAG_VECTOR; loadFlag = FLAG_VECTOR;
} }
else else
@@ -97,10 +103,16 @@ ConfigFile ConfigFile::Load(const std::string& filepath)
{ {
if(loadFlag == FLAG_STRING) if(loadFlag == FLAG_STRING)
{ {
if(isDirectory && line[line.size()-1] != '/')
line += '/';
*s = line; *s = line;
} }
else if(loadFlag == FLAG_VECTOR) else if(loadFlag == FLAG_VECTOR)
{ {
if(isDirectory && line[line.size()-1] != '/')
{;
line += '/';
}
vec->push_back(line); vec->push_back(line);
} }
else if(loadFlag == FLAG_BOOL) else if(loadFlag == FLAG_BOOL)