Devilution
Diablo devolved - magic behind the 1996 computer game
appfat.cpp
Go to the documentation of this file.
1 
6 #include "all.h"
7 #include "../3rdParty/Storm/Source/storm.h"
8 #include <config.h>
9 
11 
12 char sz_error_buf[256];
17 
18 void app_fatal(const char *pszFmt, ...)
19 {
20  va_list va;
21 
22  va_start(va, pszFmt);
23  FreeDlg();
24 
25  if (pszFmt)
26  MsgBox(pszFmt, va);
27 
28  va_end(va);
29 
30  diablo_quit(1);
31 }
32 
33 void MsgBox(const char *pszFmt, va_list va)
34 {
35  char text[256];
36 
37  vsnprintf(text, 256, pszFmt, va);
38 
39  UiErrorOkDialog("Error", text);
40 }
41 
42 void FreeDlg()
43 {
44  if (terminating && cleanup_thread_id != SDL_GetThreadID(NULL))
45  SDL_Delay(20000);
46 
47  terminating = TRUE;
48  cleanup_thread_id = SDL_GetThreadID(NULL);
49 
50  if (gbMaxPlayers > 1) {
51  if (SNetLeaveGame(3))
52  SDL_Delay(2000);
53  }
54 
55  SNetDestroy();
56 }
57 
58 void DrawDlg(char *pszFmt, ...)
59 {
60  char text[256];
61  va_list va;
62 
63  va_start(va, pszFmt);
64  vsnprintf(text, 256, pszFmt, va);
65  va_end(va);
66 
67  UiErrorOkDialog(PROJECT_NAME, text, false);
68 }
69 
70 #ifdef _DEBUG
71 void assert_fail(int nLineNo, const char *pszFile, const char *pszFail)
72 {
73  app_fatal("assertion failed (%d:%s)\n%s", nLineNo, pszFile, pszFail);
74 }
75 #endif
76 
77 void ErrDlg(const char *title, const char *error, char *log_file_path, int log_line_nr)
78 {
79  char text[1024];
80 
81  FreeDlg();
82 
83  snprintf(text, 1024, "%s\n\nThe error occurred at: %s line %d", error, log_file_path, log_line_nr);
84 
85  UiErrorOkDialog(title, text);
86  app_fatal(NULL);
87 }
88 
89 void FileErrDlg(const char *error)
90 {
91  char text[1024];
92 
93  FreeDlg();
94 
95  if (!error)
96  error = "";
97  snprintf(
98  text,
99  1024,
100  "Unable to open a required file.\n"
101  "\n"
102  "Verify that the MD5 of diabdat.mpq matches one of the following values\n"
103  "011bc6518e6166206231080a4440b373\n"
104  "68f049866b44688a7af65ba766bef75a\n"
105  "\n"
106  "The problem occurred when loading:\n%s",
107  error);
108 
109  UiErrorOkDialog("Data File Error", text);
110  app_fatal(NULL);
111 }
112 
113 void InsertCDDlg(const char *fileName)
114 {
115  char text[1024];
116  snprintf(
117  text,
118  1024,
119  "Unable to open %s.\n"
120  "\n"
121  "Make sure that it is in the game folder and that the file name is in all lowercase.",
122  fileName);
123 
124  UiErrorOkDialog("Data File Error", text);
125  app_fatal(NULL);
126 }
127 
128 void DirErrorDlg(char *error)
129 {
130  char text[1024];
131 
132  snprintf(text, 1024, "Unable to write to location:\n%s", error);
133 
134  UiErrorOkDialog("Read-Only Directory Error", text);
135  app_fatal(NULL);
136 }
137 
FileErrDlg
void FileErrDlg(const char *error)
Definition: appfat.cpp:89
InsertCDDlg
void InsertCDDlg(const char *fileName)
Definition: appfat.cpp:113
DirErrorDlg
void DirErrorDlg(char *error)
Definition: appfat.cpp:128
all.h
gbMaxPlayers
BYTE gbMaxPlayers
Specifies the maximum number of players in a game, where 1 represents a single player game and 4 repr...
Definition: multi.cpp:34
ErrDlg
void ErrDlg(const char *title, const char *error, char *log_file_path, int log_line_nr)
Definition: appfat.cpp:77
sz_error_buf
DEVILUTION_BEGIN_NAMESPACE char sz_error_buf[256]
Definition: appfat.cpp:12
FreeDlg
void FreeDlg()
Definition: appfat.cpp:42
MsgBox
void MsgBox(const char *pszFmt, va_list va)
Definition: appfat.cpp:33
cleanup_thread_id
int cleanup_thread_id
Thread id of the last callee to FreeDlg().
Definition: appfat.cpp:16
app_fatal
void app_fatal(const char *pszFmt,...)
Definition: appfat.cpp:18
DEVILUTION_END_NAMESPACE
#define DEVILUTION_END_NAMESPACE
Definition: types.h:10
diablo_quit
void diablo_quit(int exitStatus)
Definition: diablo.cpp:333
DEVILUTION_BEGIN_NAMESPACE
Definition: sha.cpp:10
DrawDlg
void DrawDlg(char *pszFmt,...)
Definition: appfat.cpp:58
terminating
BOOL terminating
Set to true when a fatal error is encountered and the application should shut down.
Definition: appfat.cpp:14