-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
InputOutput.h
125 lines (103 loc) · 2.85 KB
/
InputOutput.h
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#pragma once
#include <string>
#include <iostream>
#include "OperationLog.h"
class InputOutput
{
private:
static std::wstring & GetFileName() noexcept
{
thread_local std::wstring sScreenBuffer;
return sScreenBuffer;
}
static std::wstring & GetDetail() noexcept
{
thread_local std::wstring sScreenBuffer;
return sScreenBuffer;
}
public:
static bool & InQuietMode() noexcept
{
static bool bQuietMode = false;
return bQuietMode;
}
static bool & InWhatIfMode() noexcept
{
static bool bWhatIfMode = false;
return bWhatIfMode;
}
static bool & ExcludeHiddenSystem() noexcept
{
static bool bExcludeHiddenSystem = false;
return bExcludeHiddenSystem;
}
static short & MaxThreads() noexcept
{
static short iMaxThreads = 5;
return iMaxThreads;
}
static bool & Log() noexcept
{
static bool bLog = false;
return bLog;
}
static std::vector<std::wstring> & ScanPaths() noexcept
{
static std::vector<std::wstring> vScanPaths;
return vScanPaths;
}
static void AddFile(const std::wstring & sLine)
{
// discover the long file name prefix so we can subtract it from the display path
static std::wstring sPrefix;
static size_t iPrefix = static_cast<size_t>(-1);
if (iPrefix == static_cast<size_t>(-1))
{
const std::wstring sUnc = L"\\??\\UNC\\";
const std::wstring sLocal = L"\\??\\";
if (sLine.compare(0, sUnc.size(), sUnc) == 0) { iPrefix = sUnc.size(); sPrefix = L"\\\\"; }
else if (sLine.compare(0, sLocal.size(), sLocal) == 0) iPrefix = sLocal.size();
else iPrefix = 0;
}
GetFileName() = sPrefix + sLine.substr(iPrefix);
GetDetail() = L"";
}
static void AddInfo(const std::wstring & sLine, const std::wstring & sPart, bool bMandatory = false)
{
if (Log())
{
OperationLog::LogFileItem(L"INFO", GetFileName(), sLine + ((sPart.empty()) ? L"" : L" in " + sPart));
}
if (!InQuietMode() || bMandatory)
{
GetDetail() += L" INFO: " + sLine + ((sPart.empty()) ? L"" : L" in " + sPart) + L"\n";
}
}
static void AddWarning(const std::wstring & sLine, const std::wstring & sPart = L"")
{
if (Log())
{
OperationLog::LogFileItem(L"WARNING", GetFileName(), sLine + ((sPart.empty()) ? L"" : L" in " + sPart));
}
GetDetail() += L" WARNING: " + sLine + ((sPart.empty()) ? L"" : L" in " + sPart) + L"\n";
}
static void AddError(const std::wstring & sLine, const std::wstring & sExtended = L"")
{
if (Log())
{
OperationLog::LogFileItem(L"ERROR", GetFileName(), sLine);
}
GetDetail() += L" ERROR: " + sLine + L"\n";
if (!sExtended.empty()) GetDetail() += L" ERROR DETAIL: " + sExtended + L"\n";
}
static void WriteToScreen()
{
// output to screen if there is anything to write
if (!GetFileName().empty() && !GetDetail().empty())
{
wprintf(L"OBJECT: %s", (GetFileName() + L"\n" + GetDetail()).c_str());
}
// clear out buffer now that it's printed
GetDetail() = L"";
}
};