Repository navigation
Expand file tree
/
Copy pathInputOutput.h
More file actions
124 lines (101 loc) · 2.71 KB
/
Copy pathInputOutput.h
File metadata and controls
124 lines (101 loc) · 2.71 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
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
#pragma once
#include <string>
#include <mutex>
#include <atomic>
#include "OperationLog.h"
class InputOutput
{
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 std::atomic<bool>& HadErrors() noexcept
{
static std::atomic<bool> bHadErrors = false;
return bHadErrors;
}
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)
{
// normalize each path independently when local and network roots share a scan
if (sLine.starts_with(L"\\??\\UNC\\")) GetFileName() = L"\\\\" + sLine.substr(8);
else if (sLine.starts_with(L"\\??\\")) GetFileName() = sLine.substr(4);
else GetFileName() = sLine;
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"")
{
HadErrors() = true;
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())
{
Print(L"OBJECT: {}", GetFileName() + L"\n" + GetDetail());
}
// clear out buffer now that it's printed
GetDetail() = L"";
}
};