Remove do-nothing command and add warning about it
[amule.git] / src / ExternalConnector.cpp
blob683a10cd3275409ce4ac4883ceaed16191ecbdf2
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2004-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 //
6 // Any parts of this program derived from the xMule, lMule or eMule project,
7 // or contributed by third-party developers are copyrighted by their
8 // respective authors.
9 //
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "ExternalConnector.h"
26 #include "config.h" // Needed for VERSION and readline detection
27 #include <common/Format.h> // Needed for CFormat
28 #include <wx/tokenzr.h> // For wxStringTokenizer
30 // For readline
31 #ifdef HAVE_LIBREADLINE
32 #if defined(HAVE_READLINE_READLINE_H)
33 #include <readline/readline.h> // Do_not_auto_remove
34 #elif defined(HAVE_READLINE_H)
35 #include <readline.h> // Do_not_auto_remove
36 #endif /* !defined(HAVE_READLINE_H) */
37 #endif /* HAVE_LIBREADLINE */
39 // For history
40 #ifdef HAVE_READLINE_HISTORY
41 #if defined(HAVE_READLINE_HISTORY_H)
42 #include <readline/history.h> // Do_not_auto_remove
43 #elif defined(HAVE_HISTORY_H)
44 #include <history.h> // Do_not_auto_remove
45 #endif /* defined(HAVE_READLINE_HISTORY_H) */
46 #endif /* HAVE_READLINE_HISTORY */
49 #include <ec/cpp/ECFileConfig.h> // Needed for CECFileConfig
50 #include <common/MD5Sum.h>
51 #include "OtherFunctions.h" // Needed for GetPassword()
52 #include "MuleVersion.h" // Needed for GetMuleVersion()
54 #ifdef _MSC_VER // silly warnings about deprecated functions
55 #pragma warning(disable:4996)
56 #endif
58 //-------------------------------------------------------------------
60 CaMuleExternalConnector* CCommandTree::m_app;
62 CCommandTree::~CCommandTree()
64 DeleteContents(m_subcommands);
68 CCommandTree* CCommandTree::AddCommand(CCommandTree* command)
70 command->m_parent = this;
71 const wxString& cmd = command->m_command;
72 CmdPos_t it;
73 for (it = m_subcommands.begin(); it != m_subcommands.end(); ++it) {
74 if ((*it)->m_command > cmd) {
75 break;
78 m_subcommands.insert(it, command);
79 return command;
83 int CCommandTree::FindCommandId(const wxString& command, wxString& args, wxString& cmdstr) const
85 wxString cmd = command.BeforeFirst(wxT(' ')).Lower();
86 for (CmdPosConst_t it = m_subcommands.begin(); it != m_subcommands.end(); ++it) {
87 if ((*it)->m_command.Lower() == cmd) {
88 args = command.AfterFirst(wxT(' ')).Trim(false);
89 return (*it)->FindCommandId(args, args, cmdstr);
92 cmdstr = GetFullCommand().Lower();
93 if (m_params == CMD_PARAM_ALWAYS && args.IsEmpty()) {
94 return CMD_ERR_MUST_HAVE_PARAM;
95 } else if (m_params == CMD_PARAM_NEVER && !args.IsEmpty()) {
96 return CMD_ERR_NO_PARAM;
97 } else {
98 if ((m_cmd_id >= 0) && (m_cmd_id & CMD_DEPRECATED)) {
99 m_app->Show(wxT('\n') + m_verbose + wxT('\n'));
100 return m_cmd_id & ~CMD_DEPRECATED;
101 } else {
102 return m_cmd_id;
108 wxString CCommandTree::GetFullCommand() const
110 wxString cmd = m_command;
112 const CCommandTree *parent = m_parent;
113 while (parent && parent->m_parent) {
114 cmd = parent->m_command + wxT(" ") + cmd;
115 parent = parent->m_parent;
118 return cmd;
122 void CCommandTree::PrintHelpFor(const wxString& command) const
124 wxString cmd = command.BeforeFirst(wxT(' ')).Lower();
125 if (!cmd.IsEmpty()) {
126 for (CmdPosConst_t it = m_subcommands.begin(); it != m_subcommands.end(); ++it) {
127 if ((*it)->m_command.Lower() == cmd) {
128 (*it)->PrintHelpFor(command.AfterFirst(wxT(' ')).Trim(false));
129 return;
132 if (m_parent) {
133 m_app->Show(CFormat(_("Unknown extension '%s' for the '%s' command.\n")) % command % GetFullCommand());
134 } else {
135 m_app->Show(CFormat(_("Unknown command '%s'.\n")) % command);
137 } else {
138 wxString fullcmd = GetFullCommand();
139 if (!fullcmd.IsEmpty()) {
140 m_app->Show(fullcmd.Upper() + wxT(": ") + wxGetTranslation(m_short) + wxT("\n"));
141 if (!m_verbose.IsEmpty()) {
142 m_app->Show(wxT("\n"));
143 m_app->Show(wxGetTranslation(m_verbose));
146 if (m_params == CMD_PARAM_NEVER) {
147 m_app->Show(_("\nThis command cannot have an argument.\n"));
148 } else if (m_params == CMD_PARAM_ALWAYS) {
149 m_app->Show(_("\nThis command must have an argument.\n"));
151 if (m_cmd_id == CMD_ERR_INCOMPLETE) {
152 m_app->Show(_("\nThis command is incomplete, you must use one of the extensions below.\n"));
154 if (!m_subcommands.empty()) {
155 CmdPosConst_t it;
156 int maxlen = 0;
157 if (m_parent) {
158 m_app->Show(_("\nAvailable extensions:\n"));
159 } else {
160 m_app->Show(_("Available commands:\n"));
162 for (it = m_subcommands.begin(); it != m_subcommands.end(); ++it) {
163 if (!((*it)->m_cmd_id >= 0 && (*it)->m_cmd_id & CMD_DEPRECATED) || m_parent) {
164 int len = (*it)->m_command.Length();
165 if (len > maxlen) {
166 maxlen = len;
170 maxlen += 4;
171 for (it = m_subcommands.begin(); it != m_subcommands.end(); ++it) {
172 if (!((*it)->m_cmd_id >= 0 && (*it)->m_cmd_id & CMD_DEPRECATED) || m_parent) {
173 m_app->Show((*it)->m_command + wxString(wxT(' '), maxlen - (*it)->m_command.Length()) + wxGetTranslation((*it)->m_short) + wxT("\n"));
176 if (!m_parent) {
177 m_app->Show(CFormat(_("\nAll commands are case insensitive.\nType '%s <command>' to get detailed info on <command>.\n")) % wxT("help"));
181 m_app->Show(wxT("\n"));
184 //-------------------------------------------------------------------
186 #ifdef HAVE_LIBREADLINE
188 const CmdList_t* CCommandTree::GetSubCommandsFor(const wxString& command, bool mayRestart) const
190 if (command.IsEmpty()) {
191 return &m_subcommands;
194 wxString cmd = command.BeforeFirst(wxT(' ')).Lower();
196 if (mayRestart && cmd == wxT("help")) {
197 return GetSubCommandsFor(command.AfterFirst(wxT(' ')), false);
200 for (CmdPosConst_t it = m_subcommands.begin(); it != m_subcommands.end(); ++it) {
201 if ((*it)->m_command.Lower() == cmd) {
202 return (*it)->GetSubCommandsFor(command.AfterFirst(wxT(' ')).Trim(false), mayRestart);
206 return NULL;
210 // Forward-declare the completion function to make sure it's declaration
211 // matches the library requirements.
212 rl_compentry_func_t command_completion;
215 // File-scope pointer to the application's command set.
216 static CCommandTree * theCommands;
219 char *command_completion(const char *text, int state)
221 static const CmdList_t* curCommands;
222 static CmdPosConst_t nextCommand;
224 if (state == 0) {
225 wxString lineBuffer(rl_line_buffer, *wxConvCurrent);
226 wxString prefix(lineBuffer.Left(rl_point).BeforeLast(wxT(' ')));
228 curCommands = theCommands->GetSubCommandsFor(prefix);
229 if (curCommands) {
230 nextCommand = curCommands->begin();
231 } else {
232 return NULL;
236 wxString test(wxString(text, *wxConvCurrent).Lower());
237 while (nextCommand != curCommands->end()) {
238 wxString curTest = (*nextCommand)->GetCommand();
239 ++nextCommand;
240 if (curTest.Lower().StartsWith(test)) {
241 return strdup(static_cast<const char *>(unicode2char(curTest)));
245 return NULL;
249 #endif /* HAVE_LIBREADLINE */
251 //-------------------------------------------------------------------
253 CaMuleExternalConnector::CaMuleExternalConnector()
254 : m_configFile(NULL),
255 m_port(-1),
256 m_ZLIB(false),
257 m_KeepQuiet(false),
258 m_Verbose(false),
259 m_interactive(false),
260 m_commands(*this),
261 m_appname(NULL),
262 m_ECClient(NULL),
263 m_InputLine(NULL),
264 m_NeedsConfigSave(false),
265 m_locale(NULL),
266 m_strFullVersion(NULL),
267 m_strOSDescription(NULL)
269 SetAppName(wxT("aMule")); // Do not change!
272 CaMuleExternalConnector::~CaMuleExternalConnector()
274 delete m_configFile;
275 delete m_locale;
276 free(m_strFullVersion);
277 free(m_strOSDescription);
280 void CaMuleExternalConnector::OnInitCommandSet()
282 m_commands.AddCommand(wxT("Quit"), CMD_ID_QUIT, wxTRANSLATE("Exits from the application."), wxEmptyString);
283 m_commands.AddCommand(wxT("Exit"), CMD_ID_QUIT, wxTRANSLATE("Exits from the application."), wxEmptyString);
284 m_commands.AddCommand(wxT("Help"), CMD_ID_HELP, wxTRANSLATE("Show help."),
285 /* TRANSLATORS:
286 Do not translate the word 'help', it is a command to the program! */
287 wxTRANSLATE("To get help on a command, type 'help <command>'.\nTo get the full command list type 'help'.\n"));
290 void CaMuleExternalConnector::Show(const wxString &s)
292 if( !m_KeepQuiet ) {
293 printf("%s", (const char *)unicode2char(s));
294 #ifdef __WINDOWS__
295 fflush(stdout);
296 #endif
300 void CaMuleExternalConnector::ShowGreet()
302 wxString text = GetGreetingTitle();
303 int len = text.Length();
304 Show(wxT('\n') + wxString(wxT('-'), 22 + len) + wxT('\n'));
305 Show(wxT('|') + wxString(wxT(' '), 10) + text + wxString(wxT(' '), 10) + wxT('|') + wxT('\n'));
306 Show(wxString(wxT('-'), 22 + len) + wxT('\n'));
307 // Do not merge the line below, or translators could translate "Help"
308 Show(CFormat(_("\nUse '%s' for command list\n\n")) % wxT("Help"));
311 void CaMuleExternalConnector::Process_Answer(const wxString& answer)
313 wxStringTokenizer tokens(answer, wxT("\n"));
314 while ( tokens.HasMoreTokens() ) {
315 Show(wxT(" > ") + tokens.GetNextToken() + wxT("\n"));
319 bool CaMuleExternalConnector::Parse_Command(const wxString& buffer)
321 wxString cmd;
322 wxStringTokenizer tokens(buffer);
323 while (tokens.HasMoreTokens()) {
324 cmd += tokens.GetNextToken() + wxT(' ');
326 cmd.Trim(false);
327 cmd.Trim(true);
328 if (cmd.IsEmpty()) {
329 return false;
331 int cmd_ID = GetIDFromString(cmd);
332 if ( cmd_ID >= 0 ) {
333 cmd_ID = ProcessCommand(cmd_ID);
335 wxString error;
336 switch (cmd_ID) {
337 case CMD_ID_HELP:
338 m_commands.PrintHelpFor(GetCmdArgs());
339 break;
340 case CMD_ERR_SYNTAX:
341 error = _("Syntax error!");
342 break;
343 case CMD_ERR_PROCESS_CMD:
344 Show(_("Error processing command - should never happen! Report bug, please\n"));
345 break;
346 case CMD_ERR_NO_PARAM:
347 error = _("This command should not have any parameters.");
348 break;
349 case CMD_ERR_MUST_HAVE_PARAM:
350 error = _("This command must have a parameter.");
351 break;
352 case CMD_ERR_INVALID_ARG:
353 error = _("Invalid argument.");
354 break;
355 case CMD_ERR_INCOMPLETE:
356 error = _("This is an incomplete command.");
357 break;
359 if (!error.IsEmpty()) {
360 Show(error + wxT('\n'));
361 wxString helpStr(wxT("help"));
362 if (!GetLastCmdStr().IsEmpty()) {
363 helpStr << wxT(' ') << GetLastCmdStr();
365 Show(CFormat(_("Type '%s' to get more help.\n")) % helpStr);
367 return cmd_ID == CMD_ID_QUIT;
370 void CaMuleExternalConnector::GetCommand(const wxString &prompt, char* buffer, size_t buffer_size)
372 #ifdef HAVE_LIBREADLINE
373 char *text = readline(unicode2char(prompt + wxT("$ ")));
374 if (text && *text &&
375 (m_InputLine == 0 || strcmp(text,m_InputLine) != 0)) {
376 add_history (text);
378 if (m_InputLine)
379 free(m_InputLine);
380 m_InputLine = text;
381 #else
382 Show(prompt + wxT("$ "));
383 const char *text = fgets(buffer, buffer_size, stdin); // == buffer if ok, NULL if eof
384 #endif /* HAVE_LIBREADLINE */
385 if ( text ) {
386 size_t len = strlen(text);
387 if (len > buffer_size - 1) {
388 len = buffer_size - 1;
390 if (buffer != text) {
391 strncpy(buffer, text, len);
393 buffer[len] = 0;
394 } else {
395 strncpy(buffer, "quit", buffer_size);
399 void CaMuleExternalConnector::TextShell(const wxString &prompt)
401 char buffer[2048];
402 wxString buf;
404 bool The_End = false;
405 do {
406 GetCommand(prompt, buffer, sizeof buffer);
407 buf = char2unicode(buffer);
408 The_End = Parse_Command(buf);
409 } while ((!The_End) && (m_ECClient->IsSocketConnected()));
412 void CaMuleExternalConnector::ConnectAndRun(const wxString &ProgName, const wxString& ProgVersion)
414 if (m_NeedsConfigSave) {
415 SaveConfigFile();
416 return;
419 #ifdef SVNDATE
420 Show(CFormat(_("This is %s %s %s\n")) % wxString::FromAscii(m_appname) % wxT(VERSION) % wxT(SVNDATE));
421 #else
422 Show(CFormat(_("This is %s %s\n")) % wxString::FromAscii(m_appname) % wxT(VERSION));
423 #endif
425 // HostName, Port and Password
426 if ( m_password.IsEmpty() ) {
427 m_password = GetPassword(true);
428 // MD5 hash for an empty string, according to rfc1321.
429 if (m_password.Encode() == wxT("D41D8CD98F00B204E9800998ECF8427E")) {
430 m_password.Clear();
434 if (!m_password.IsEmpty()) {
436 // Create the socket
437 Show(_("\nCreating client...\n"));
438 m_ECClient = new CRemoteConnect(NULL);
439 m_ECClient->SetCapabilities(m_ZLIB, true, false); // ZLIB, UTF8 numbers, notification
441 // ConnectToCore is blocking since m_ECClient was initialized with NULL
442 if (!m_ECClient->ConnectToCore(m_host, m_port, wxT("foobar"), m_password.Encode(), ProgName, ProgVersion)) {
443 // no connection => close gracefully
444 if (!m_ECClient->GetServerReply().IsEmpty()) {
445 Show(CFormat(wxT("%s\n")) % m_ECClient->GetServerReply());
447 Show(CFormat(_("Connection Failed. Unable to connect to %s:%d\n")) % m_host % m_port);
448 } else {
449 // Authenticate ourselves
450 // ConnectToCore() already authenticated for us.
451 //m_ECClient->ConnectionEstablished();
452 Show(m_ECClient->GetServerReply()+wxT("\n"));
453 if (m_ECClient->IsSocketConnected()) {
454 if (m_interactive) {
455 ShowGreet();
457 Pre_Shell();
458 TextShell(ProgName);
459 Post_Shell();
460 if (m_interactive) {
461 Show(CFormat(_("\nOk, exiting %s...\n")) % ProgName);
465 m_ECClient->DestroySocket();
466 } else {
467 Show(_("Cannot connect with an empty password.\nYou must specify a password either in config file\nor on command-line, or enter one when asked.\n\nExiting...\n"));
471 void CaMuleExternalConnector::OnInitCmdLine(wxCmdLineParser& parser, const char* appname)
473 m_appname = appname;
475 parser.AddSwitch(wxEmptyString, wxT("help"),
476 _("Show this help text."),
477 wxCMD_LINE_PARAM_OPTIONAL);
478 parser.AddOption(wxT("h"), wxT("host"),
479 _("Host where aMule is running. (default: localhost)"),
480 wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
481 parser.AddOption(wxT("p"), wxT("port"),
482 _("aMule's port for External Connection. (default: 4712)"),
483 wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL);
484 parser.AddOption(wxT("P"), wxT("password"),
485 _("External Connection password."),
486 wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
487 parser.AddOption(wxT("f"), wxT("config-file"),
488 _("Read configuration from file."),
489 wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
490 parser.AddSwitch(wxT("q"), wxT("quiet"),
491 _("Do not print any output to stdout."),
492 wxCMD_LINE_PARAM_OPTIONAL);
493 parser.AddSwitch(wxT("v"), wxT("verbose"),
494 _("Be verbose - show also debug messages."),
495 wxCMD_LINE_PARAM_OPTIONAL);
496 parser.AddOption(wxT("l"), wxT("locale"),
497 _("Sets program locale (language)."),
498 wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
499 parser.AddSwitch(wxT("w"), wxT("write-config"),
500 _("Write command line options to config file."),
501 wxCMD_LINE_PARAM_OPTIONAL);
502 parser.AddOption(wxEmptyString, wxT("create-config-from"),
503 _("Creates config file based on aMule's config file."),
504 wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
505 parser.AddSwitch(wxEmptyString, wxT("version"),
506 _("Print program version."),
507 wxCMD_LINE_PARAM_OPTIONAL);
510 bool CaMuleExternalConnector::OnCmdLineParsed(wxCmdLineParser& parser)
512 if (parser.Found(wxT("version"))) {
513 printf("%s %s\n", m_appname, (const char *)unicode2char(GetMuleVersion()));
514 return false;
517 if (!parser.Found(wxT("config-file"), &m_configFileName)) {
518 m_configFileName = wxT("remote.conf");
520 m_configDir = GetConfigDir(m_configFileName);
521 m_configFileName = m_configDir + m_configFileName;
523 wxString aMuleConfigFile;
524 if (parser.Found(wxT("create-config-from"), &aMuleConfigFile)) {
525 aMuleConfigFile = FinalizeFilename(aMuleConfigFile);
526 if (!::wxFileExists(aMuleConfigFile)) {
527 fprintf(stderr, "%s\n", (const char *)unicode2char(wxT("FATAL ERROR: File does not exist: ") + aMuleConfigFile));
528 exit(1);
530 CECFileConfig aMuleConfig(aMuleConfigFile);
531 LoadAmuleConfig(aMuleConfig);
532 SaveConfigFile();
533 m_configFile->Flush();
534 exit(0);
537 LoadConfigFile();
539 if ( !parser.Found(wxT("host"), &m_host) ) {
540 if ( m_host.IsEmpty() ) {
541 m_host = wxT("localhost");
545 long port;
546 if (parser.Found(wxT("port"), &port)) {
547 m_port = port;
550 wxString pass_plain;
551 if (parser.Found(wxT("password"), &pass_plain)) {
552 if (!pass_plain.IsEmpty()) {
553 m_password.Decode(MD5Sum(pass_plain).GetHash());
554 } else {
555 m_password.Clear();
559 if (parser.Found(wxT("write-config"))) {
560 m_NeedsConfigSave = true;
563 parser.Found(wxT("locale"), &m_language);
565 if (parser.Found(wxT("help"))) {
566 parser.Usage();
567 return false;
570 m_KeepQuiet = parser.Found(wxT("quiet"));
571 m_Verbose = parser.Found(wxT("verbose"));
573 return true;
576 void CaMuleExternalConnector::LoadAmuleConfig(CECFileConfig& cfg)
578 m_host = wxT("localhost");
579 m_port = cfg.Read(wxT("/ExternalConnect/ECPort"), 4712l);
580 cfg.ReadHash(wxT("/ExternalConnect/ECPassword"), &m_password);
581 m_language = cfg.Read(wxT("/eMule/Language"), wxEmptyString);
585 void CaMuleExternalConnector::LoadConfigFile()
587 if (!m_configFile) {
588 m_configFile = new CECFileConfig(m_configFileName);
590 if (m_configFile) {
591 m_language = m_configFile->Read(wxT("/Locale"), wxEmptyString);
592 m_host = m_configFile->Read(wxT("/EC/Host"), wxEmptyString);
593 m_port = m_configFile->Read(wxT("/EC/Port"), 4712l);
594 m_configFile->ReadHash(wxT("/EC/Password"), &m_password);
595 m_ZLIB = m_configFile->Read(wxT("/EC/ZLIB"), 1l) != 0;
599 void CaMuleExternalConnector::SaveConfigFile()
601 if (!wxFileName::DirExists(m_configDir)) {
602 wxFileName::Mkdir(m_configDir);
604 if (!m_configFile) {
605 m_configFile = new CECFileConfig(m_configFileName);
607 if (m_configFile) {
608 m_configFile->Write(wxT("/Locale"), m_language);
609 m_configFile->Write(wxT("/EC/Host"), m_host);
610 m_configFile->Write(wxT("/EC/Port"), m_port);
611 m_configFile->WriteHash(wxT("/EC/Password"), m_password);
615 bool CaMuleExternalConnector::OnInit()
617 #ifndef __WINDOWS__
618 #if wxUSE_ON_FATAL_EXCEPTION
619 // catch fatal exceptions
620 wxHandleFatalExceptions(true);
621 #endif
622 #endif
624 // If we didn't know that OnInit is called only once when creating the
625 // object, it could cause a memory leak. The two pointers below should
626 // be free()'d before assigning the new value.
627 // cppcheck-suppress publicAllocationError
628 m_strFullVersion = strdup((const char *)unicode2char(GetMuleVersion()));
629 m_strOSDescription = strdup((const char *)unicode2char(wxGetOsDescription()));
631 // Handle uncaught exceptions
632 InstallMuleExceptionHandler();
634 bool retval = wxApp::OnInit();
635 OnInitCommandSet();
636 InitCustomLanguages();
637 SetLocale(m_language);
639 #ifdef HAVE_LIBREADLINE
640 // Allow conditional parsing of the ~/.inputrc file.
642 // OnInitCmdLine() is called from wxApp::OnInit() above,
643 // thus m_appname is already set.
644 rl_readline_name = m_appname;
646 // Allow completion of our commands
647 theCommands = &m_commands;
648 rl_completion_entry_function = &command_completion;
649 #endif
651 return retval;
654 wxString CaMuleExternalConnector::SetLocale(const wxString& language)
656 if (!language.IsEmpty()) {
657 m_language = language;
658 if (m_locale) {
659 delete m_locale;
661 m_locale = new wxLocale;
662 InitLocale(*m_locale, StrLang2wx(language));
665 return m_locale == NULL ? wxString() : m_locale->GetCanonicalName();
668 #if !wxUSE_GUI && defined(__WXMAC__) && !wxCHECK_VERSION(2, 9, 0)
670 #include <wx/apptrait.h> // Do_not_auto_remove
671 #include <wx/stdpaths.h> // Do_not_auto_remove
673 class CaMuleExternalConnectorTraits : public wxConsoleAppTraits
675 public:
676 virtual wxStandardPathsBase& GetStandardPaths()
678 return s_stdPaths;
681 private:
682 static wxStandardPathsCF s_stdPaths;
685 wxStandardPathsCF CaMuleExternalConnectorTraits::s_stdPaths;
687 wxAppTraits* CaMuleExternalConnector::CreateTraits()
689 return new CaMuleExternalConnectorTraits;
692 #endif
694 #if wxUSE_ON_FATAL_EXCEPTION
695 // Gracefully handle fatal exceptions and print backtrace if possible
696 void CaMuleExternalConnector::OnFatalException()
698 /* Print the backtrace */
699 fprintf(stderr, "\n--------------------------------------------------------------------------------\n");
700 fprintf(stderr, "A fatal error has occurred and %s has crashed.\n", m_appname);
701 fprintf(stderr, "Please assist us in fixing this problem by posting the backtrace below in our\n");
702 fprintf(stderr, "'aMule Crashes' forum and include as much information as possible regarding the\n");
703 fprintf(stderr, "circumstances of this crash. The forum is located here:\n");
704 fprintf(stderr, " http://forum.amule.org/index.php?board=67.0\n");
705 fprintf(stderr, "If possible, please try to generate a real backtrace of this crash:\n");
706 fprintf(stderr, " http://wiki.amule.org/wiki/Backtraces\n\n");
707 fprintf(stderr, "----------------------------=| BACKTRACE FOLLOWS: |=----------------------------\n");
708 fprintf(stderr, "Current version is: %s %s\n", m_appname, m_strFullVersion);
709 fprintf(stderr, "Running on: %s\n\n", m_strOSDescription);
711 print_backtrace(1); // 1 == skip this function.
713 fprintf(stderr, "\n--------------------------------------------------------------------------------\n");
715 #endif
717 #ifdef __WXDEBUG__
718 void CaMuleExternalConnector::OnAssertFailure(const wxChar *file, int line, const wxChar *func, const wxChar *cond, const wxChar *msg)
720 #if !defined wxUSE_STACKWALKER || !wxUSE_STACKWALKER
721 wxString errmsg = CFormat( wxT("%s:%s:%d: Assertion '%s' failed. %s") ) % file % func % line % cond % ( msg ? msg : wxT("") );
723 fprintf(stderr, "Assertion failed: %s\n", (const char*)unicode2char(errmsg));
725 // Skip the function-calls directly related to the assert call.
726 fprintf(stderr, "\nBacktrace follows:\n");
727 print_backtrace(3);
728 fprintf(stderr, "\n");
729 #else
730 wxApp::OnAssertFailure(file, line, func, cond, msg);
731 #endif
733 #endif
734 // File_checked_for_headers