You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.2 KiB

/**
* @file appfat.cpp
*
* Implementation of error dialogs.
*/
#include <config.h>
8 years ago
5 years ago
#include <fmt/format.h>
#include "diablo.h"
#include "multi.h"
#include "storm/storm_net.hpp"
#include "utils/language.h"
#include "utils/sdl_thread.h"
5 years ago
#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;
8 years ago
/**
* @brief Cleans up after a fatal application error.
*/
void FreeDlg()
8 years ago
{
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();
8 years ago
}
} // namespace
void app_fatal(string_view str)
{
FreeDlg();
UiErrorOkDialog(_("Error"), str);
diablo_quit(1);
}
#ifdef _DEBUG
void assert_fail(int nLineNo, const char *pszFile, const char *pszFail)
{
app_fatal(fmt::format("assertion failed ({}:{})\n{}", pszFile, nLineNo, pszFail));
}
#endif
void ErrDlg(const char *title, string_view error, string_view logFilePath, int logLineNr)
8 years ago
{
FreeDlg();
std::string text = 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);
UiErrorOkDialog(title, text);
diablo_quit(1);
8 years ago
}
void InsertCDDlg(string_view archiveName)
8 years ago
{
std::string text = fmt::format(
fmt::runtime(_("Unable to open main data archive ({:s}).\n"
"\n"
"Make sure that it is in the game folder.")),
archiveName);
UiErrorOkDialog(_("Data File Error"), text);
diablo_quit(1);
8 years ago
}
void DirErrorDlg(string_view error)
8 years ago
{
std::string text = fmt::format(fmt::runtime(_(/* TRANSLATORS: Error when Program is not allowed to write data */ "Unable to write to location:\n{:s}")), error);
UiErrorOkDialog(_("Read-Only Directory Error"), text);
diablo_quit(1);
8 years ago
}
} // namespace devilution