-
Notifications
You must be signed in to change notification settings - Fork 814
/
Copy pathappfat.cpp
98 lines (79 loc) · 2.36 KB
/
appfat.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
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
/**
* @file appfat.cpp
*
* Implementation of error dialogs.
*/
#include <config.h>
#include <SDL.h>
#include <fmt/format.h>
#ifdef USE_SDL1
#include "utils/sdl2_to_1_2_backports.h"
#endif
#include "diablo.h"
#include "multi.h"
#include "storm/storm_net.hpp"
#include "utils/language.h"
#include "utils/sdl_thread.h"
#include "utils/str_cat.hpp"
#include "utils/ui_fwd.h"
namespace devilution {
namespace {
/** Set to true when a fatal error is encountered and the application should shut down. */
bool Terminating = false;
/** Thread id of the last callee to FreeDlg(). */
SDL_threadID CleanupThreadId;
/**
* @brief Cleans up after a fatal application error.
*/
void FreeDlg()
{
if (Terminating && CleanupThreadId != this_sdl_thread::get_id())
SDL_Delay(20000);
Terminating = true;
CleanupThreadId = this_sdl_thread::get_id();
if (gbIsMultiplayer) {
if (SNetLeaveGame(3))
SDL_Delay(2000);
}
SNetDestroy();
}
} // namespace
void DisplayFatalErrorAndExit(std::string_view title, std::string_view body)
{
FreeDlg();
UiErrorOkDialog(title, body);
diablo_quit(1);
}
void app_fatal(std::string_view str)
{
DisplayFatalErrorAndExit(_("Error"), str);
}
#ifdef _DEBUG
void assert_fail(int nLineNo, const char *pszFile, const char *pszFail)
{
app_fatal(StrCat("assertion failed (", pszFile, ":", nLineNo, ")\n", pszFail));
}
#endif
void ErrDlg(const char *title, std::string_view error, std::string_view logFilePath, int logLineNr)
{
DisplayFatalErrorAndExit(
title,
fmt::format(fmt::runtime(_(/* TRANSLATORS: Error message that displays relevant information for bug report */ "{:s}\n\nThe error occurred at: {:s} line {:d}")),
error, logFilePath, logLineNr));
}
void InsertCDDlg(std::string_view archiveName)
{
DisplayFatalErrorAndExit(_("Data File Error"),
fmt::format(fmt::runtime(_("Unable to open main data archive ({:s}).\n"
"\n"
"Make sure that it is in the game folder.")),
archiveName));
}
void DirErrorDlg(std::string_view error)
{
DisplayFatalErrorAndExit(
_("Read-Only Directory Error"),
fmt::format(fmt::runtime(_(/* TRANSLATORS: Error when Program is not allowed to write data */ "Unable to write to location:\n{:s}")),
error));
}
} // namespace devilution