Skip to content

Commit df4847c

Browse files
authored
added alias to path file
The `-pathFile` now accepts a '>' separated plain text file, which specifies the exported path and its alias. e.g. ``` /some/path > /alias /other/path > /another/alias ``` P.S. not sure if the code style is correct, the other branch uses space, but this branch uses tab.
1 parent 005ca93 commit df4847c

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

src/MountProg.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <string.h>
44
#include <map>
55
#include <fstream>
6+
#include <sstream>
67
#include <iostream>
78
#include <string>
89
#include <direct.h>
@@ -299,18 +300,32 @@ bool CMountProg::ReadPathsFromFile(char* sFileName)
299300
std::ifstream pathFile(sFileName);
300301

301302
if (pathFile.is_open()) {
302-
std::string line;
303+
std::string line, path;
304+
std::vector<std::string> paths;
305+
std::istringstream ss;
303306

304307
while (std::getline(pathFile, line)) {
305-
char *pCurPath = (char*)malloc(line.size() + 1);
306-
pCurPath = (char*)line.c_str();
308+
ss.clear();
309+
paths.clear();
310+
ss.str(line);
307311

308-
if (pCurPath != NULL) {
309-
char curPathAlias[MAXPATHLEN];
310-
strcpy_s(curPathAlias, pCurPath);
311-
char *pCurPathAlias = (char*)malloc(strlen(curPathAlias));
312-
pCurPathAlias = curPathAlias;
312+
// split path and alias separated by '>'
313+
while (std::getline(ss, path, '>')) {
314+
paths.push_back(path);
315+
}
316+
if (paths.size() < 1) {
317+
continue;
318+
}
319+
if (paths.size() < 2) {
320+
paths.push_back(paths[0]);
321+
}
313322

323+
char *pCurPath = (char*)malloc(paths[0].size() + 1);
324+
pCurPath = (char*)paths[0].c_str();
325+
326+
if (pCurPath != NULL) {
327+
char *pCurPathAlias = (char*)malloc(paths[1].size() + 1);
328+
pCurPathAlias = (char*)paths[1].c_str();
314329
Export(pCurPath, pCurPathAlias);
315330
}
316331
}

0 commit comments

Comments
 (0)