-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
OperationPathList.cpp
42 lines (34 loc) · 1.21 KB
/
OperationPathList.cpp
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
#include "OperationPathList.h"
#include "InputOutput.h"
#include "Helpers.h"
#include <fstream>
#include <locale>
#include <codecvt>
ClassFactory<OperationPathList> OperationPathList::RegisteredFactory(GetCommand());
OperationPathList::OperationPathList(std::queue<std::wstring> & oArgList, const std::wstring & sCommand) : Operation(oArgList)
{
// exit if there are not enough arguments to parse
const std::vector<std::wstring> sSubArgs = ProcessAndCheckArgs(1, oArgList, L"\\0");
// open the file
std::wifstream fFile(sSubArgs.at(0).c_str());
// adapt the stream to read windows unicode files
(void) fFile.imbue(std::locale(fFile.getloc(), new std::codecvt_utf8<wchar_t,
0x10ffff, std::consume_header>));
// read the file line-by-line
std::wstring sLine;
while (std::getline(fFile, sLine))
{
// sometimes a carriage return appears in the input stream so adding
// it here ensures it is stripped from the very end
std::vector<std::wstring> oLineItems = SplitArgs(sLine, L"\r");
if (oLineItems.size() != 1)
{
wprintf(L"ERROR: Unable to parse string path list file.");
std::exit(-1);
}
// store off the argument
InputOutput::ScanPaths().push_back(oLineItems.at(0));
}
// cleanup
fFile.close();
};