Exemplo n.º 1
0
  DWORD do_exception_filter(const tstring & exe_dir,
                            EXCEPTION_POINTERS & eps,
                            tstring & message) {
    std::string exception_information = get_exception_information(eps);

    tstringstream sstr;
    sstr << TBuffer(exception_information.c_str());

    std::ofstream error_log(NarrowBuffer((exe_dir + _T("\\err_log.txt")).c_str()));
    if (error_log) {
      error_log << exception_information;
      sstr << _T("\nThis message has been written to err_log.txt");
    }
  
    message = sstr.str();
    return EXCEPTION_EXECUTE_HANDLER;
  }
Exemplo n.º 2
0
gint plugin_init(gchar **error)
{
  PyObject *inst_StringIO = NULL;

  /* Version check */
  if(!check_plugin_version(MAKE_NUMERIC_VERSION(3,7,6,9), VERSION_NUMERIC, _("Python"), error))
    return -1;

  /* load hooks */
  hook_compose_create = hooks_register_hook(COMPOSE_CREATED_HOOKLIST, my_compose_create_hook, NULL);
  if(hook_compose_create == (guint)-1) {
    *error = g_strdup(_("Failed to register \"compose create hook\" in the Python plugin"));
    return -1;
  }

  /* script directories */
  if(!make_sure_directories_exist(error))
    goto err;

  /* initialize python interpreter */
  Py_Initialize();

  /* The Python C API only offers to print an exception to sys.stderr. In order to catch it
   * in a string, a StringIO object is created, to which sys.stderr can be redirected in case
   * an error occured. */
  inst_StringIO = get_StringIO_instance();

  /* initialize Claws Mail Python module */
  initclawsmail();
  if(PyErr_Occurred()) {
    *error = get_exception_information(inst_StringIO);
    goto err;
  }

  if(PyRun_SimpleString("import clawsmail") == -1) {
    *error = g_strdup("Error importing the clawsmail module");
    goto err;
  }

  /* initialize python interactive shell */
  if(!parasite_python_init(error)) {
    goto err;
  }

  /* load menu options */
  if(!python_menu_init(error)) {
    goto err;
  }

  /* problems here are not fatal */
  run_auto_script_file_if_it_exists(PYTHON_SCRIPTS_AUTO_STARTUP, NULL);

  debug_print("Python plugin loaded\n");

  return 0;

err:
  hooks_unregister_hook(COMPOSE_CREATED_HOOKLIST, hook_compose_create);
  Py_XDECREF(inst_StringIO);
  return -1;
}