Skip to content

Commit 17f32d2

Browse files
committed
Bugfixes for windows and ini file reading.
1 parent c710ce6 commit 17f32d2

1 file changed

Lines changed: 28 additions & 7 deletions

File tree

src/Settings.cpp

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
void Settings::splitList(const std::string& line, std::vector<std::string>& items) {
1515
size_t lastDelim = 0;
1616
size_t delim;
17-
while(std::string::npos != (delim = line.find(':'))) {
17+
while (std::string::npos != (delim = line.find(';', lastDelim))) {
1818
items.push_back(line.substr(lastDelim, delim));
1919

2020
lastDelim = delim + 1;
@@ -52,7 +52,7 @@ void Settings::readIni() {
5252
while(getline(in, line)) {
5353
size_t delim = line.find('=');
5454

55-
if(std::string::npos == delim) {
55+
if(std::string::npos != delim) {
5656
std::string name = line.substr(0, delim);
5757
std::string value = line.substr(delim + 1);
5858

@@ -67,7 +67,7 @@ void Settings::outputEntryList(std::ofstream& out, const std::string& name, cons
6767
out << name << "=";
6868
for(size_t i = 0; i < values.size(); ++i) {
6969
if(0 != i) {
70-
out << ":";
70+
out << ";";
7171
}
7272
out << values[i];
7373
}
@@ -124,12 +124,33 @@ bool Settings::parseCommandLine(int nargs, const char **args) {
124124
}
125125
speed = speedArg.getValue();
126126

127-
readDirectories = dirArg.getValue();
127+
std::vector<std::string> addionalDirs = dirArg.getValue();
128+
for (auto&& item : addionalDirs) {
129+
readDirectories.push_back(item);
130+
}
128131
if(0 == readDirectories.size()) {
129-
const char *homeDir;
130-
if ((homeDir = getenv("HOME")) == NULL) {
131-
std::cerr << "Could not get the home directory." << std::endl;
132+
const char *homeDirC;
133+
std::string homeDir = "";
134+
135+
#ifdef _WINDOWS
136+
if ((homeDirC = getenv("HOMEDRIVE")) == NULL) {
137+
std::cerr << "Could not get the home drive." << std::endl;
138+
exit(-1);
132139
}
140+
homeDir = homeDirC;
141+
if ((homeDirC = getenv("HOMEPATH")) == NULL) {
142+
std::cerr << "Could not get the home path." << std::endl;
143+
exit(-1);
144+
}
145+
homeDir += homeDirC;
146+
#else
147+
if ((homeDirC = getenv("HOME")) == NULL) {
148+
std::cerr << "Could not get the home directory." << std::endl;
149+
exit(-1);
150+
} else {
151+
homeDir = homeDirC;
152+
}
153+
#endif
133154

134155
std::string factorioDir = homeDir;
135156
factorioDir += "/.local/share/Steam/steamapps/common/Factorio/data/base/prototypes/recipe";

0 commit comments

Comments
 (0)