forked from kittybupu/openVCB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenVCBMain.cpp
More file actions
101 lines (84 loc) · 2.19 KB
/
openVCBMain.cpp
File metadata and controls
101 lines (84 loc) · 2.19 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
#include "openVCB.h"
#ifndef NDEBUG
# ifndef _DEBUG
# define _DEBUG
# endif
#endif
/*--------------------------------------------------------------------------------------*/
namespace openVCB::util {
UU static FILE *log = nullptr;
void logf(UU PRINTF_FORMAT_STRING format, ...)
{
#ifdef _DEBUG
if (!log)
return;
va_list ap;
va_start(ap, format);
(void)vfprintf(log, format, ap);
va_end(ap);
(void)fputc('\n', log);
(void)fflush(log);
#endif
}
void logs(UU _In_z_ char const *msg, UU size_t len)
{
#ifdef _DEBUG
if (!log)
return;
(void)fwrite(msg, 1, len, log);
(void)fputc('\n', log);
#endif
}
void logs(UU _In_z_ char const *msg)
{
#ifdef _DEBUG
if (!log)
return;
(void)fputs(msg, log);
(void)fputc('\n', log);
#endif
}
} // namespace openVCB::util
/*--------------------------------------------------------------------------------------*/
#ifdef _WIN32
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN 1
# endif
# include <Windows.h>
BOOL WINAPI
DllMain(UU HINSTANCE inst, DWORD fdwReason, LPVOID)
{
using namespace std::literals;
switch (fdwReason) {
case DLL_PROCESS_ATTACH: {
# ifdef _DEBUG
(void)::_set_abort_behavior(0, _WRITE_ABORT_MSG);
(void)::signal(SIGABRT, [](int) {});
wchar_t fname[2048];
if (::GetModuleFileNameW(inst, fname, std::size(fname)) == 0) {
::MessageBoxW(nullptr, L"Error determining openVCB.dll file path.", L"ERROR", MB_OK);
::exit(1);
}
auto path = absolute(std::filesystem::path(fname)).parent_path();
path /= L"OpenVCB.log"sv;
if (_wfopen_s(&openVCB::util::log, path.c_str(), L"w") != 0) {
::MessageBoxW(nullptr, L"Error opening openVCB.dll log file.", L"ERROR", MB_OK);
::exit(1);
}
# endif
break;
}
case DLL_PROCESS_DETACH:
# ifdef _DEBUG
if (openVCB::util::log)
(void)fclose(openVCB::util::log);
break;
# endif
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
default:
break;
}
return TRUE;
}
#endif