aboutsummaryrefslogtreecommitdiff
path: root/Src/Winamp/setup/setupfactory.cpp
blob: fdb417ef749ad9951636a62430f0088fea9fa8de (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#include "./setupfactory.h"
#include <api/service/waservicefactorybase.h>
#include <api/service/services.h>
#include "api.h"
#include "gen.h"
#include "main.h"

#define GUID_DEFINE
#include "./setup.h"
#undef GUID_DEFINE

//#include "./spage_lang.h"
//#include "./spage_connect.h"
#include "./spage_skin.h"
#include "./spage_assoc.h"
//#include "./spage_feedback.h"

#include "./sjob_register.h"
#include <shlwapi.h>

class setup_factory : public waServiceFactory
{
public:
	setup_factory();
	virtual ~setup_factory();
public:
	int AddRef();
	int Release();
	FOURCC GetServiceType();
	const char *GetServiceName();
	GUID GetGUID();
	void *GetInterface(int global_lock);
	int SupportNonLockingInterface();
	int ReleaseInterface(void *ifc);
	const char *GetTestString();
	int ServiceNotify(int msg, int param1, int param2);

private:
	int ref;
	svc_setup *psvcSetup;
protected:
	RECVS_DISPATCH;
};


#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

BOOL Setup_RegisterService(void)
{
	setup_factory *psf = new setup_factory();
	WASABI_API_SVC->service_register(psf);
	return (0 != psf->Release());
}

int Setup_RegisterDefault(void)
{
	waServiceFactory *psf = WASABI_API_SVC->service_getServiceByGuid(UID_SVC_SETUP);
	if (!psf) return 0;

	svc_setup *pSvc = (svc_setup*)psf->getInterface();
	if (pSvc)
	{
		int index = 0;
		ifc_setuppage *pp;
		ifc_setupjob *pj;
	//	pp = new setup_page_lang();
	//	if (pp) { pSvc->InsertPage(pp, &index); pp->Release(); }

		pp = new setup_page_skin();
		if (pp) { pSvc->InsertPage(pp, &++index); pp->Release(); }

//		pp = new setup_page_connect();
//		if (pp) { pSvc->InsertPage(pp, &++index); pp->Release(); }

		pp = new setup_page_assoc();
		if (pp) { pSvc->InsertPage(pp, &++index); pp->Release(); }

		// disabled for 5.66
//		pp = new setup_page_feedback();
//		if (pp) { pSvc->InsertPage(pp, &++index); pp->Release(); }

		pj = new setup_job_register();
		if (pj) { pSvc->AddJob(pj); pj->Release(); }

		pSvc->Release();
		return 1;
	}

	return 0;
}

int Setup_RegisterPlugins(void)
{
	wchar_t dirstr[MAX_PATH] = {0};
	WIN32_FIND_DATAW d = {0};
	PathCombineW(dirstr, PLUGINDIR, L"GEN_*.DLL");

	HANDLE h = FindFirstFileW(dirstr,&d);
	if (h != INVALID_HANDLE_VALUE) 
	{
		do 
		{
			wchar_t temp[MAX_PATH] = {0};
			PathCombineW(temp, PLUGINDIR, d.cFileName);
			HINSTANCE hLib = LoadLibraryW(temp);
			if (hLib)
			{
				winampGeneralPurposePluginGetter pr = (winampGeneralPurposePluginGetter) GetProcAddress(hLib,"winampGetGeneralPurposePlugin");
				if (pr)
				{
					Plugin_RegisterSetup fn = (Plugin_RegisterSetup)GetProcAddress(hLib, "RegisterSetup");
					if (NULL == fn || FALSE == fn(hLib, WASABI_API_SVC))
					{
						winampGeneralPurposePlugin *plugin = pr();
						if (plugin && (plugin->version == GPPHDR_VER || plugin->version == GPPHDR_VER_U))
						{
							char desc[128] = {0};
							lstrcpynA(desc, plugin->description, sizeof(desc));
							if (desc[0] && !memcmp(desc, "nullsoft(", 9))
							{
								// we'll let this leak for all 3rd party plug-ins as some crash during
								// setup when we try to unload the plug-in e.g gen_Wake_up_call.dll
								FreeModule(hLib);
							}
						}
					}
				}
			}
		} while (FindNextFileW(h,&d));
		FindClose(h);
	}
	return 1;
}

#ifdef __cplusplus
}
#endif // __cplusplus



setup_factory::setup_factory() : ref(1), psvcSetup(NULL)
{
}

setup_factory::~setup_factory()
{
	if (NULL != psvcSetup)
	{
		psvcSetup->Release();
	}
}

int setup_factory::AddRef(void)
{
	return ++ref;
}

int setup_factory::Release(void)
{	
	if (1 == ref) 
	{
		delete(this);
		return 0;
	}
	return --ref;
}

FOURCC setup_factory::GetServiceType() 
{ 
	return WaSvc::UNIQUE;  
}

const char *setup_factory::GetServiceName() 
{ 
	return "Setup Service"; 
}

GUID setup_factory::GetGUID() 
{ 
	return UID_SVC_SETUP; 
}

int setup_factory::SupportNonLockingInterface()
{ 
	return 1; 
}

const char *setup_factory::GetTestString() 
{ 
	return NULL; 
}

int setup_factory::ServiceNotify(int msg, int param1, int param2)
{ 
	switch(msg)
	{
		case SvcNotify::ONREGISTERED:
			AddRef();
			break;
		case SvcNotify::ONDEREGISTERED:
			Release();
			break;
	}
	return 1; 
}

void *setup_factory::GetInterface(int global_lock)
{	
	if (NULL == psvcSetup) 
	{
		psvcSetup = WASetup::CreateInstance();
		if (NULL == psvcSetup)
			return NULL;
	}

	psvcSetup->AddRef();
	return psvcSetup;
}

int setup_factory::ReleaseInterface(void *ifc)
{
	if (ifc == psvcSetup && NULL != psvcSetup)
	{
		if (0 == psvcSetup->Release())
			psvcSetup = NULL;
	}
	return 1;
}

#ifdef CBCLASS
#undef CBCLASS
#endif

#define CBCLASS setup_factory
START_DISPATCH
CB(ADDREF, AddRef)
CB(RELEASE, Release)
CB(WASERVICEFACTORY_GETSERVICETYPE, GetServiceType)
CB(WASERVICEFACTORY_GETSERVICENAME, GetServiceName)
CB(WASERVICEFACTORY_GETGUID, GetGUID)
CB(WASERVICEFACTORY_GETINTERFACE, GetInterface)
CB(WASERVICEFACTORY_SUPPORTNONLOCKINGGETINTERFACE, SupportNonLockingInterface) 
CB(WASERVICEFACTORY_RELEASEINTERFACE, ReleaseInterface)
CB(WASERVICEFACTORY_GETTESTSTRING, GetTestString)
CB(WASERVICEFACTORY_SERVICENOTIFY, ServiceNotify)
END_DISPATCH