-
-
Notifications
You must be signed in to change notification settings - Fork 584
/
Copy pathdll_log.hpp
113 lines (106 loc) · 2.79 KB
/
dll_log.hpp
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
/*
* Copyright (C) 2014 Patrick Mours
* SPDX-License-Identifier: BSD-3-Clause OR MIT
*/
#pragma once
#include <cassert>
#include <cinttypes>
#include <string>
#include <filesystem>
namespace reshade::log
{
/// <summary>
/// Severity levels for logging.
/// </summary>
enum class level
{
/// <summary>
/// | ERROR | ...
/// </summary>
error = 1,
/// <summary>
/// | WARN | ...
/// </summary>
warning = 2,
/// <summary>
/// | INFO | ...
/// </summary>
info = 3,
/// <summary>
/// | DEBUG | ...
/// </summary>
debug = 4,
};
/// <summary>
/// Opens a log file for writing.
/// </summary>
/// <param name="path">Path to the log file.</param>
/// <param name="ec">Error code that is set on failure.</param>
bool open_log_file(const std::filesystem::path &path, std::error_code &ec);
/// <summary>
/// Constructs a single log message including current time and level and writes it to the open log file.
/// </summary>
void message(level level, const char *format, ...);
#if defined(_HRESULT_DEFINED)
inline std::string hr_to_string(HRESULT hr)
{
switch (hr)
{
case E_NOTIMPL:
return "E_NOTIMPL";
case E_OUTOFMEMORY:
return "E_OUTOFMEMORY";
case E_INVALIDARG:
return "E_INVALIDARG";
case E_NOINTERFACE:
return "E_NOINTERFACE";
case E_FAIL:
return "E_FAIL";
case 0x8876017C:
return "D3DERR_OUTOFVIDEOMEMORY";
case 0x88760868:
return "D3DERR_DEVICELOST";
case 0x8876086A:
return "D3DERR_NOTAVAILABLE";
case 0x8876086C:
return "D3DERR_INVALIDCALL";
case 0x88760870:
return "D3DERR_DEVICEREMOVED";
case 0x88760874:
return "D3DERR_DEVICEHUNG";
case DXGI_ERROR_INVALID_CALL:
return "DXGI_ERROR_INVALID_CALL";
case DXGI_ERROR_UNSUPPORTED:
return "DXGI_ERROR_UNSUPPORTED";
case DXGI_ERROR_DEVICE_REMOVED:
return "DXGI_ERROR_DEVICE_REMOVED";
case DXGI_ERROR_DEVICE_HUNG:
return "DXGI_ERROR_DEVICE_HUNG";
case DXGI_ERROR_DEVICE_RESET:
return "DXGI_ERROR_DEVICE_RESET";
case DXGI_ERROR_DRIVER_INTERNAL_ERROR:
return "DXGI_ERROR_DRIVER_INTERNAL_ERROR";
default:
char temp_string[11];
return std::string(temp_string, std::snprintf(temp_string, std::size(temp_string), "%#lx", static_cast<unsigned long>(hr)));
}
}
#endif
#if defined(_REFIID_DEFINED) && defined(_COMBASEAPI_H_)
inline std::string iid_to_string(REFIID riid)
{
OLECHAR riid_string[40];
const int len = StringFromGUID2(riid, riid_string, static_cast<int>(std::size(riid_string)));
if (len != 0)
{
char temp_string[40];
assert(len < static_cast<int>(std::size(temp_string)));
for (int i = 0; i < len; ++i)
// The GUID string contains only ANSI characters, so can just mask off the first few bits to convert
temp_string[i] = riid_string[i] & 0xFF;
return std::string(temp_string, len);
}
return "{...}";
}
#endif
}