RigsofRods
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ErrorUtils.cpp
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5  Copyright 2013-2020 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8 
9  Rigs of Rods is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License version 3, as
11  published by the Free Software Foundation.
12 
13  Rigs of Rods is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
28 #include "ErrorUtils.h"
29 #include "Utils.h"
30 
31 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
32 #include <windows.h>
33 #include <shlobj.h>
34 #include <shellapi.h> // for ShellExecuteW
35 #define _L
36 #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE
37 #define _L
38 #elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
39 #include "Language.h"
40 #endif
41 
42 #include <string>
43 
44 using namespace Ogre;
45 
46 int ErrorUtils::ShowError(const std::string& title, const std::string& err)
47 {
48  LOG(fmt::format("[RoR|ErrorPopupDialog] {}: {}", title, err));
49  std::string infoText = _L("An internal error occured in Rigs of Rods.\n\nTechnical details below: \n\n");
50  return ErrorUtils::ShowMsgBox(_L("FATAL ERROR"), infoText + err, 0);
51 }
52 
53 int ErrorUtils::ShowInfo(const std::string& title, const std::string& err)
54 {
55  return ErrorUtils::ShowMsgBox(title, err, 1);
56 }
57 
58 int ErrorUtils::ShowMsgBox(const std::string& title, const std::string& err, int type)
59 {
60  // we might call the ErrorUtils::ShowMsgBox without having ogre created yet!
61  //LOG("message box: " + title + ": " + err);
62 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
63  int mtype = MB_ICONERROR;
64  if (type == 1)
65  mtype = MB_ICONINFORMATION;
66  std::wstring title_w = RoR::Utf8ToWideChar(title);
67  std::wstring err_w = RoR::Utf8ToWideChar(err);
68  MessageBoxW(NULL, err_w.c_str(), title_w.c_str(), MB_OK | mtype | MB_TOPMOST);
69 #elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
70  printf("\n\n%s: %s\n\n", title.c_str(), err.c_str());
71 #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE
72  printf("\n\n%s: %s\n\n", title.c_str(), err.c_str());
73  //CFOptionFlags flgs;
74  //CFUserNotificationDisplayAlert(0, kCFUserNotificationStopAlertLevel, NULL, NULL, NULL, T("A network error occured"), T("Bad server port."), NULL, NULL, NULL, &flgs);
75 #endif
76  return 0;
77 }
ErrorUtils::ShowError
static int ShowError(const std::string &title, const std::string &message)
shows a simple error message box
Definition: ErrorUtils.cpp:46
ErrorUtils::ShowMsgBox
static int ShowMsgBox(const std::string &title, const std::string &err, int type)
shows a generic message box
Definition: ErrorUtils.cpp:58
format
Truck file format(technical spec)
RoR::Utf8ToWideChar
std::wstring Utf8ToWideChar(std::string input_utf8)
Definition: Utils.cpp:149
Utils.h
Language.h
ErrorUtils::ShowInfo
static int ShowInfo(const std::string &title, const std::string &message)
shows a simple info message box
Definition: ErrorUtils.cpp:53
ErrorUtils.h
_L
#define _L
Definition: ErrorUtils.cpp:35
Ogre
Definition: ExtinguishableFireAffector.cpp:35