-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathutils.cpp
62 lines (55 loc) · 1.91 KB
/
utils.cpp
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
#include "utils.h"
#include <cstdio>
void errorPopup(const char* message) {
// This should be:
// popup_message::g_show(... , popup_message::icon_error);
// But we sometimes need this to be modal (as it will be followed by crash)
MessageBoxW(nullptr,
uT(PFC_string_formatter()
<< "foo_chronflow: " << message
<< "\r\n\r\nIf this happens more than once, please report this error "
"in the foo_chronflow "
"thread on Hydrogenaudo or via mail to foocomp@chronial.de"),
L"Error in foo_chronflow", MB_OK | MB_ICONERROR);
}
void errorPopupWin32(const char* message) {
errorPopup(PFC_string_formatter() << message << "\r\nWin32 Error Message: "
<< format_win32_error(GetLastError()));
}
std::string linux_lineendings(std::string s) {
boost::replace_all(s, "\r\n", "\n");
return std::move(s);
}
std::string windows_lineendings(std::string s) {
boost::replace_all(s, "\r\n", "\n");
boost::replace_all(s, "\n", "\r\n");
return std::move(s);
}
double time() {
static std::array<t_int64, 2> resolution_and_offset = [] {
LARGE_INTEGER resolution;
QueryPerformanceFrequency(&resolution);
LARGE_INTEGER offset;
QueryPerformanceCounter(&offset);
return std::array<t_int64, 2>{resolution.QuadPart, offset.QuadPart};
}();
LARGE_INTEGER count;
QueryPerformanceCounter(&count);
return double(count.QuadPart - resolution_and_offset[1]) / resolution_and_offset[0];
}
#ifdef _DEBUG
namespace console {
out::out() {
*this << " " << std::fixed << std::setprecision(2);
}
out::~out() {
static HANDLE console = [] {
AllocConsole();
return GetStdHandle(STD_OUTPUT_HANDLE);
}();
*this << "\n";
auto str = pfc::stringcvt::string_wide_from_utf8(this->str().c_str());
WriteConsole(console, str.get_ptr(), str.length(), nullptr, nullptr);
}
} // namespace console
#endif