1
0

main.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // Winamp error feedback plugin
  2. // Copyright (C) 2005 Nullsoft
  3. //#define PLUGIN_DESC "Nullsoft Error Feedback"
  4. #define PLUGIN_VER L"1.16"
  5. #include ".\main.h"
  6. #include "configDlg.h"
  7. #include "crashDlg.h"
  8. #include "api__gen_crasher.h"
  9. #include "../nu/ServiceWatcher.h"
  10. ServiceWatcher watcher;
  11. Settings settings;
  12. prefsDlgRecW prefItem = {0};
  13. char *winampVersion;
  14. static wchar_t prefsTitle[64];
  15. // wasabi based services for localisation support
  16. api_service *WASABI_API_SVC = 0;
  17. api_language *WASABI_API_LNG = 0;
  18. api_syscb *WASABI_API_SYSCB = 0;
  19. api_application *WASABI_API_APP = 0;
  20. HINSTANCE WASABI_API_LNG_HINST = 0, WASABI_API_ORIG_HINST = 0;
  21. int init(void);
  22. void config(void);
  23. void quit(void);
  24. extern "C" winampGeneralPurposePlugin plugin =
  25. {
  26. GPPHDR_VER_U,
  27. "nullsoft(gen_crasher.dll)",
  28. init,
  29. config,
  30. quit,
  31. };
  32. extern "C" __declspec(dllexport) winampGeneralPurposePlugin * winampGetGeneralPurposePlugin() { return &plugin; }
  33. int init(void)
  34. {
  35. if (!settings.IsOk()) return GEN_INIT_FAILURE;
  36. // loader so that we can get the localisation service api for use
  37. WASABI_API_SVC = (api_service*)SendMessage(plugin.hwndParent, WM_WA_IPC, 0, IPC_GET_API_SERVICE);
  38. if (!WASABI_API_SVC || WASABI_API_SVC == (api_service *)1)
  39. return GEN_INIT_FAILURE;
  40. waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid(applicationApiServiceGuid);
  41. if (sf) WASABI_API_SYSCB = reinterpret_cast<api_syscb*>(sf->getInterface());
  42. watcher.WatchWith(WASABI_API_SVC);
  43. watcher.WatchFor(&WASABI_API_LNG, languageApiGUID);
  44. WASABI_API_SYSCB->syscb_registerCallback(&watcher);
  45. sf = WASABI_API_SVC->service_getServiceByGuid(applicationApiServiceGuid);
  46. if (sf) WASABI_API_APP = reinterpret_cast<api_application*>(sf->getInterface());
  47. // need to have this initialised before we try to do anything with localisation features
  48. WASABI_API_START_LANG(plugin.hDllInstance,GenCrasherLangGUID);
  49. static wchar_t szDescription[256];
  50. swprintf(szDescription, ARRAYSIZE(szDescription),
  51. WASABI_API_LNGSTRINGW(IDS_NULLSOFT_ERROR_FEEDBACK), PLUGIN_VER);
  52. plugin.description = (char*)szDescription;
  53. //register prefs screen
  54. prefItem.dlgID = IDD_CONFIG;
  55. prefItem.name = WASABI_API_LNGSTRINGW_BUF(IDS_ERROR_FEEDBACK,prefsTitle,64);
  56. prefItem.proc = (void*) ConfigDlgProc;
  57. prefItem.hInst = WASABI_API_LNG_HINST;
  58. prefItem.where = -1;
  59. SendMessageA(plugin.hwndParent, WM_WA_IPC, (WPARAM) &prefItem, IPC_ADD_PREFS_DLGW);
  60. winampVersion = (char *)SendMessageA(plugin.hwndParent,WM_WA_IPC,0,IPC_GETVERSIONSTRING);
  61. return GEN_INIT_SUCCESS;
  62. }
  63. void config(void)
  64. {
  65. SendMessage(plugin.hwndParent,WM_WA_IPC,(WPARAM)&prefItem,IPC_OPENPREFSTOPAGE);
  66. }
  67. void quit(void)
  68. {
  69. watcher.StopWatching();
  70. watcher.Clear();
  71. waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid(languageApiGUID);
  72. if (sf) sf->releaseInterface(WASABI_API_LNG);
  73. WASABI_API_LNG=0;
  74. }
  75. int StartHandler(wchar_t* iniPath)
  76. {
  77. settings.SetPath(iniPath);
  78. if (!settings.Load())
  79. {
  80. if (!(settings.CreateDefault(iniPath) && settings.Save()))
  81. {
  82. //OutputDebugString(L"Feedback plugin - unable to read settings. Error feedback disabled.\r\n");
  83. }
  84. }
  85. SetUnhandledExceptionFilter(FeedBackFilter);
  86. //OutputDebugString(L"Error FeedBack started.\r\n");
  87. return 0;
  88. }
  89. PEXCEPTION_POINTERS gExceptionInfo;
  90. LONG WINAPI FeedBackFilter( struct _EXCEPTION_POINTERS *pExceptionInfo )
  91. {
  92. if (alreadyProccessing) return EXCEPTION_CONTINUE_EXECUTION;
  93. alreadyProccessing = TRUE;
  94. gExceptionInfo = pExceptionInfo;
  95. // show user dialog
  96. HWND hwnd;
  97. if (WASABI_API_LNG)
  98. hwnd = WASABI_API_CREATEDIALOGPARAMW(IDD_CRASHDLG, NULL, CrashDlgProc, (LPARAM)WASABI_API_ORIG_HINST);
  99. else
  100. #ifdef _M_IX86
  101. hwnd = CreateDialogParam(plugin.hDllInstance, MAKEINTRESOURCE(IDD_CRASHDLG), NULL, CrashDlgProc, (LPARAM)plugin.hDllInstance);
  102. #endif
  103. #ifdef _M_X64
  104. hwnd = CreateDialogParam(plugin.hDllInstance, MAKEINTRESOURCE(IDD_CRASHDLG), NULL, (DLGPROC)CrashDlgProc, (LPARAM)plugin.hDllInstance);
  105. #endif
  106. SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
  107. while (IsWindow(hwnd))
  108. {
  109. MSG msg;
  110. if (!GetMessage(&msg, NULL, 0, 0)) break;
  111. if (IsDialogMessage(hwnd, &msg)) continue;
  112. TranslateMessage(&msg);
  113. DispatchMessage(&msg);
  114. }
  115. return EXCEPTION_EXECUTE_HANDLER;
  116. }