Repository navigation
Expand file tree
/
Copy pathutils.cpp
More file actions
67 lines (50 loc) · 1.5 KB
/
Copy pathutils.cpp
File metadata and controls
67 lines (50 loc) · 1.5 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
#include "utils.hpp"
#include "windows_lean.h"
#include <string>
#include <sstream>
#include "common/IDebugLog.h"
std::string get_last_error_message(size_t max_size)
{
std::string output(max_size, '\0');
get_last_error_message(output);
return output;
}
void get_last_error_message(std::string& output)
{
if (output.empty()) {
return;
}
size_t written_count = FormatMessageA(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
&output[0],
output.size(),
NULL);
output.resize(written_count);
}
void fatal_error(const char* message, bool include_last_error)
{
std::stringstream ss;
if (message != NULL) {
ss << message << '\n';
}
if (include_last_error) {
ss << "Last error:\n" << get_last_error_message();
}
std::string output = ss.str();
_ERROR(output.c_str());
}
std::string format_oblivion_version(unsigned int version)
{
std::stringstream ss;
const auto major = (version >> 24) & 0xFF;
const auto minor = (version >> 16) & 0xFF;
const auto build = version & 0xFFFF;
// clang-format off
ss << major << "."
<< minor << ".0."
<< build;
return ss.str();
}