aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/General/gen_crasher/main.cpp
blob: 7385db073782b7c78828a18f26b7fe140676bf4b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Winamp error feedback plugin
// Copyright (C) 2005 Nullsoft

//#define PLUGIN_DESC "Nullsoft Error Feedback"
#define PLUGIN_VER L"1.16"

#include ".\main.h"
#include "configDlg.h"
#include "crashDlg.h"
#include "api__gen_crasher.h"
#include "../nu/ServiceWatcher.h"

ServiceWatcher watcher;
Settings settings;
prefsDlgRecW prefItem = {0};
char *winampVersion;
static wchar_t prefsTitle[64];

// wasabi based services for localisation support
api_service *WASABI_API_SVC = 0;
api_language *WASABI_API_LNG = 0;
api_syscb *WASABI_API_SYSCB = 0;
api_application *WASABI_API_APP = 0;
HINSTANCE WASABI_API_LNG_HINST = 0, WASABI_API_ORIG_HINST = 0;

int init(void);
void config(void);
void quit(void);

extern "C" winampGeneralPurposePlugin plugin =
{
	GPPHDR_VER_U,
	"nullsoft(gen_crasher.dll)",
	init,
	config,
	quit,
};

extern "C" __declspec(dllexport) winampGeneralPurposePlugin * winampGetGeneralPurposePlugin() {	return &plugin; }

int init(void)
{
	if (!settings.IsOk()) return GEN_INIT_FAILURE;

	// loader so that we can get the localisation service api for use
	WASABI_API_SVC = (api_service*)SendMessage(plugin.hwndParent, WM_WA_IPC, 0, IPC_GET_API_SERVICE);
	if (!WASABI_API_SVC || WASABI_API_SVC == (api_service *)1)
		return GEN_INIT_FAILURE;

	waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid(applicationApiServiceGuid);
	if (sf) WASABI_API_SYSCB = reinterpret_cast<api_syscb*>(sf->getInterface());

	watcher.WatchWith(WASABI_API_SVC);
	watcher.WatchFor(&WASABI_API_LNG, languageApiGUID);
	WASABI_API_SYSCB->syscb_registerCallback(&watcher);

	sf = WASABI_API_SVC->service_getServiceByGuid(applicationApiServiceGuid);
	if (sf) WASABI_API_APP = reinterpret_cast<api_application*>(sf->getInterface());

	// need to have this initialised before we try to do anything with localisation features
	WASABI_API_START_LANG(plugin.hDllInstance,GenCrasherLangGUID);

	static wchar_t szDescription[256];
	swprintf(szDescription, ARRAYSIZE(szDescription),
			 WASABI_API_LNGSTRINGW(IDS_NULLSOFT_ERROR_FEEDBACK), PLUGIN_VER);
	plugin.description = (char*)szDescription;

	//register prefs screen
	prefItem.dlgID = IDD_CONFIG;
	prefItem.name = WASABI_API_LNGSTRINGW_BUF(IDS_ERROR_FEEDBACK,prefsTitle,64);
	prefItem.proc = (void*) ConfigDlgProc;
	prefItem.hInst = WASABI_API_LNG_HINST;
	prefItem.where = -1;
	SendMessageA(plugin.hwndParent, WM_WA_IPC, (WPARAM) &prefItem, IPC_ADD_PREFS_DLGW);
	winampVersion = (char *)SendMessageA(plugin.hwndParent,WM_WA_IPC,0,IPC_GETVERSIONSTRING);
	return GEN_INIT_SUCCESS;
}

void config(void)
{
	SendMessage(plugin.hwndParent,WM_WA_IPC,(WPARAM)&prefItem,IPC_OPENPREFSTOPAGE);
}

void quit(void)
{
	watcher.StopWatching();
	watcher.Clear();

	waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid(languageApiGUID);
	if (sf) sf->releaseInterface(WASABI_API_LNG);
	WASABI_API_LNG=0;
}

int StartHandler(wchar_t* iniPath)
{	
	settings.SetPath(iniPath);
	if (!settings.Load()) 
	{
		if (!(settings.CreateDefault(iniPath) && settings.Save()))
		{
			//OutputDebugString(L"Feedback plugin - unable to read settings. Error feedback disabled.\r\n");
		}
	}
	SetUnhandledExceptionFilter(FeedBackFilter);
	//OutputDebugString(L"Error FeedBack started.\r\n");
	return 0;
}

PEXCEPTION_POINTERS gExceptionInfo;

LONG WINAPI FeedBackFilter( struct _EXCEPTION_POINTERS *pExceptionInfo )
{
	if (alreadyProccessing) return EXCEPTION_CONTINUE_EXECUTION;
	
	alreadyProccessing = TRUE;
	gExceptionInfo = pExceptionInfo; 

	// show user dialog
	HWND hwnd;
	if (WASABI_API_LNG)
		hwnd = WASABI_API_CREATEDIALOGPARAMW(IDD_CRASHDLG, NULL, CrashDlgProc, (LPARAM)WASABI_API_ORIG_HINST);
	else 
	#ifdef _M_IX86
		hwnd = CreateDialogParam(plugin.hDllInstance, MAKEINTRESOURCE(IDD_CRASHDLG), NULL, CrashDlgProc, (LPARAM)plugin.hDllInstance);
	#endif
	#ifdef _M_X64
		hwnd = CreateDialogParam(plugin.hDllInstance, MAKEINTRESOURCE(IDD_CRASHDLG), NULL, (DLGPROC)CrashDlgProc, (LPARAM)plugin.hDllInstance);
	#endif

	SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
	while (IsWindow(hwnd))
	{
		MSG msg;
		if (!GetMessage(&msg, NULL, 0, 0)) break;
		if (IsDialogMessage(hwnd, &msg)) continue;
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return EXCEPTION_EXECUTE_HANDLER;
}