-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
80 lines (73 loc) · 2.4 KB
/
Copy pathmain.cpp
File metadata and controls
80 lines (73 loc) · 2.4 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
#include "pch.h"
#include "MainMenu.h"
#include "Config.h"
static void printUsage()
{
std::wcout
<< L"MYUTILS - utility launcher\n\n"
<< L" myutils scan saved folder, else current folder\n"
<< L" myutils -dir \"C:\\path\" scan a folder for this run only\n"
<< L" myutils \"C:\\path\" same (bare path)\n"
<< L" myutils -dir set \"C:\\path\" save a default folder, then scan it\n"
<< L" myutils -dir clear forget the saved folder\n"
<< L" myutils -dir show print the saved folder\n"
<< L" myutils -h | --help show this help\n";
}
int wmain(int argc, wchar_t* argv[])
{
std::wstring oneOffDir;
bool saveIt = false;
for (int i = 1; i < argc; ++i)
{
std::wstring a = argv[i];
if (a == L"-h" || a == L"--help" || a == L"/?")
{
printUsage();
return 0;
}
else if (a == L"-dir" || a == L"--dir" || a == L"-d")
{
std::wstring next = (i + 1 < argc) ? std::wstring(argv[i + 1]) : L"";
if (next == L"set")
{
if (i + 2 < argc) { oneOffDir = argv[i + 2]; saveIt = true; i += 2; }
else { std::wcout << L"Usage: myutils -dir set \"C:\\path\"\n"; return 1; }
}
else if (next == L"clear")
{
std::wcout << (myutils::config::clearScanDir()
? L"Saved folder cleared.\n"
: L"No saved folder to clear.\n");
return 0;
}
else if (next == L"show")
{
std::wstring saved = myutils::config::loadScanDir();
std::wcout << (saved.empty() ? L"No saved folder.\n"
: L"Saved folder: " + saved + L"\n");
return 0;
}
else if (!next.empty())
{
oneOffDir = next; ++i;
}
}
else if (oneOffDir.empty() && !a.empty() && a[0] != L'-')
{
oneOffDir = a;
}
}
std::wstring scanDir;
if (!oneOffDir.empty())
{
if (saveIt) myutils::config::saveScanDir(oneOffDir);
scanDir = oneOffDir;
}
else
{
scanDir = myutils::config::loadScanDir();
}
myutils::MainMenu menu;
menu.run(scanDir);
return 0;
}