re-enabled registry path evaluation, enabled currentuser/allusers radio button
[swftools.git] / installer / installer.c
1 /* installer.c
2
3    Part of the swftools installer (Main program).
4    
5    Copyright (c) 2004 Matthias Kramm <kramm@quiss.org> 
6  
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
20
21 #include <windows.h>
22 #include <commctrl.h>
23 #include <commdlg.h>
24 #include <shlobj.h>
25 #include <prsht.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include "installer.h"
29
30 #include "depack.h"
31
32 #include "../config.h" //for swftools version
33 #include "../lib/os.h" //for registry functions
34
35 static int config_forAllUsers = 0;
36 static int config_createLinks = 0;
37 static int config_createStartmenu = 1;
38 static int config_createDesktop = 1;
39
40 static char path_startmenu[MAX_PATH] = "\0";
41 static char path_desktop[MAX_PATH] = "\0";
42 static char path_programfiles[MAX_PATH] = "\0";
43
44 extern char*crndata;
45 extern char*license_text;
46
47 static char*install_path = "c:\\swftools\\";
48 static char pathBuf[1024];
49 static int do_abort = 0;
50
51 static char* pdf2swf_path;
52
53 static HBITMAP logo = 0;
54
55 static HINSTANCE me;
56
57 #define USER_SETMESSAGE 0x7f01
58
59 void tball(HDC hdc, double px, double py, double sx, double sy)
60 {
61     MoveToEx(hdc, 75.25*sx+px, -32.50*sy+py, 0);
62     LineTo(hdc, 74.75*sx+px, -24.80*sy+py); LineTo(hdc, 74.95*sx+px, -3.45*sy+py); LineTo(hdc, 75.25*sx+px, -32.50*sy+py);
63     LineTo(hdc, 44.85*sx+px, -104.30*sy+py); LineTo(hdc, 74.75*sx+px, -24.80*sy+py); LineTo(hdc, 17.30*sx+px, -91.80*sy+py);
64     LineTo(hdc, 29.35*sx+px, -10.10*sy+py); LineTo(hdc, 74.75*sx+px, -24.80*sy+py); LineTo(hdc, 47.60*sx+px, 63.80*sy+py);
65     LineTo(hdc, 74.75*sx+px, 51.10*sy+py); LineTo(hdc, 74.95*sx+px, -3.45*sy+py);
66     MoveToEx(hdc, 74.75*sx+px, 51.10*sy+py, 0);
67     LineTo(hdc, 29.35*sx+px, 118.75*sy+py); LineTo(hdc, -45.20*sx+px, 155.35*sy+py);
68     LineTo(hdc, -127.95*sx+px, 145.10*sy+py); LineTo(hdc, -194.85*sx+px, 104.30*sy+py);
69     LineTo(hdc, -225.25*sx+px, 32.50*sy+py); LineTo(hdc, -224.75*sx+px, -51.10*sy+py);
70     LineTo(hdc, -179.35*sx+px, -118.75*sy+py); LineTo(hdc, -104.80*sx+px, -155.35*sy+py);
71     LineTo(hdc, -22.05*sx+px, -145.10*sy+py); LineTo(hdc, 44.85*sx+px, -104.30*sy+py);
72     LineTo(hdc, 17.30*sx+px, -91.80*sy+py); LineTo(hdc, -75.00*sx+px, -122.60*sy+py);
73     LineTo(hdc, -45.20*sx+px, -43.70*sy+py); LineTo(hdc, 17.30*sx+px, -91.80*sy+py);
74     LineTo(hdc, -22.05*sx+px, -145.10*sy+py); LineTo(hdc, -75.00*sx+px, -122.60*sy+py);
75     LineTo(hdc, -104.80*sx+px, -155.35*sy+py); LineTo(hdc, -167.30*sx+px, -107.25*sy+py);
76     LineTo(hdc, -75.00*sx+px, -122.60*sy+py); LineTo(hdc, -127.95*sx+px, -63.55*sy+py);
77     LineTo(hdc, -45.20*sx+px, -43.70*sy+py); LineTo(hdc, 29.35*sx+px, -10.10*sy+py);
78     LineTo(hdc, 47.60*sx+px, 63.80*sy+py); LineTo(hdc, -25.70*sx+px, 52.45*sy+py);
79     LineTo(hdc, -25.70*sx+px, 128.45*sy+py); LineTo(hdc, 47.60*sx+px, 63.80*sy+py);
80     LineTo(hdc, 29.35*sx+px, 118.75*sy+py); LineTo(hdc, -25.70*sx+px, 128.45*sy+py);
81     LineTo(hdc, -45.20*sx+px, 155.35*sy+py); LineTo(hdc, -118.85*sx+px, 143.85*sy+py);
82     LineTo(hdc, -127.95*sx+px, 145.10*sy+py);
83     MoveToEx(hdc, -179.35*sx+px, -118.75*sy+py, 0);
84     LineTo(hdc, -167.30*sx+px, -107.25*sy+py); LineTo(hdc, -127.95*sx+px, -63.55*sy+py);
85     LineTo(hdc, -118.85*sx+px, 21.65*sy+py); LineTo(hdc, -45.20*sx+px, -43.70*sy+py);
86     LineTo(hdc, -25.70*sx+px, 52.45*sy+py); LineTo(hdc, 29.35*sx+px, -10.10*sy+py);
87     MoveToEx(hdc, -225.25*sx+px, 32.50*sy+py, 0);
88     LineTo(hdc, -194.85*sx+px, -17.85*sy+py); LineTo(hdc, -224.75*sx+px, -51.10*sy+py);
89     LineTo(hdc, -167.30*sx+px, -107.25*sy+py); LineTo(hdc, -194.85*sx+px, -17.85*sy+py);
90     LineTo(hdc, -127.95*sx+px, -63.55*sy+py);
91     MoveToEx(hdc, -175.85*sx+px, 77.60*sy+py, 0);
92     LineTo(hdc, -96.35*sx+px, 99.55*sy+py); LineTo(hdc, -118.85*sx+px, 21.65*sy+py);
93     LineTo(hdc, -175.85*sx+px, 77.60*sy+py); LineTo(hdc, -225.25*sx+px, 32.50*sy+py);
94     MoveToEx(hdc, -118.85*sx+px, 143.85*sy+py, 0);
95     LineTo(hdc, -175.85*sx+px, 77.60*sy+py); LineTo(hdc, -194.85*sx+px, 104.30*sy+py);
96     LineTo(hdc, -118.85*sx+px, 143.85*sy+py); LineTo(hdc, -96.35*sx+px, 99.55*sy+py);
97     LineTo(hdc, -25.70*sx+px, 52.45*sy+py); LineTo(hdc, -118.85*sx+px, 21.65*sy+py);
98     LineTo(hdc, -194.85*sx+px, -17.85*sy+py); LineTo(hdc, -175.85*sx+px, 77.60*sy+py);
99     MoveToEx(hdc, -96.35*sx+px, 99.55*sy+py, 0);
100     LineTo(hdc, -25.70*sx+px, 128.45*sy+py); LineTo(hdc, -118.85*sx+px, 143.85*sy+py);
101 }
102
103 static HWND wnd_background = 0;
104 LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
105 {
106     if(message == WM_CREATE) {
107         CREATESTRUCT*cs = ((LPCREATESTRUCT)lParam);
108         if(cs->lpCreateParams && !strcmp((char*)cs->lpCreateParams, "background")) {
109             wnd_background = hwnd;
110         }
111     }
112     if(hwnd == wnd_background && message == WM_PAINT) {
113         HDC hdc;
114         PAINTSTRUCT ps;
115         RECT rc;
116         GetWindowRect(hwnd, &rc);
117         int width = rc.right - rc.left;
118         int height = rc.bottom - rc.top;
119
120         hdc = BeginPaint(hwnd, &ps);
121         SetBkMode(hdc, TRANSPARENT);
122
123         double s = width / 1282.0;
124         
125         HPEN pen0 = CreatePen(PS_SOLID, 2, RGB(0, 32, 128));
126         HPEN oldPen = (HPEN)SelectObject(hdc, pen0);
127         tball(hdc, 0.7*width,0.2*height,s,s);
128
129         HPEN pen1 = CreatePen(PS_SOLID, 2, RGB(0, 48, 128));
130         (HPEN)SelectObject(hdc, pen1);
131         tball(hdc, 0.233*width,0.3*height,s*2,s*2);
132         
133         HPEN pen2 = CreatePen(PS_SOLID, 2, RGB(0, 64, 128));
134         (HPEN)SelectObject(hdc, pen2);
135         tball(hdc, width, 1.2*height,s*3,-s*3);
136
137         SelectObject(hdc, oldPen); 
138         DeleteObject(pen1);
139         DeleteObject(pen2);
140         EndPaint(hwnd, &ps);
141         return 1;
142     }
143     return DefWindowProc(hwnd, message, wParam, lParam);
144 }
145
146 void processMessages()
147 {
148     MSG msg;
149     while(PeekMessage(&msg,NULL,0,0,0))
150     {
151         GetMessage(&msg, NULL, 0, 0);
152         TranslateMessage(&msg);
153         DispatchMessage(&msg);
154     }
155 }
156
157 int addRegistryEntries(char*install_dir)
158 {
159     int ret;
160     ret = setRegistryEntry("Software\\quiss.org\\swftools\\InstallPath", install_dir);
161     if(!ret) return 0;
162     return 1;
163 }
164
165 int CreateShortcut(char*path, char*description, char*filename, char*arguments, int iconindex, char*iconpath, char*workdir)
166 {
167     WCHAR wszFilename[MAX_PATH];
168     IShellLink *ps1 = NULL;
169     IPersistFile *pPf = NULL;
170     HRESULT hr;
171     hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (void*)&ps1);
172     if(FAILED(hr)) return 0;
173     hr = ps1->lpVtbl->QueryInterface(ps1, &IID_IPersistFile, (void **)&pPf);
174     if(FAILED(hr)) return 0;
175     hr = ps1->lpVtbl->SetPath(ps1, path);
176     if(FAILED(hr)) return 0;
177     hr = ps1->lpVtbl->SetDescription(ps1, description);
178     
179     if (arguments) {
180         hr = ps1->lpVtbl->SetArguments(ps1, arguments);
181         if(FAILED(hr)) return 0;
182     }
183     if (iconpath) {
184         hr = ps1->lpVtbl->SetIconLocation(ps1, iconpath, iconindex);
185         if (FAILED(hr)) return 0;
186     }
187     if (workdir) {
188         hr = ps1->lpVtbl->SetWorkingDirectory(ps1, workdir);
189         if (FAILED(hr)) return 0;
190     }
191     MultiByteToWideChar(CP_ACP, 0, filename, -1, wszFilename, MAX_PATH);
192     hr = pPf->lpVtbl->Save(pPf, wszFilename, TRUE);
193     if(FAILED(hr)) {
194         return 0;
195     }
196     pPf->lpVtbl->Release(pPf);
197     ps1->lpVtbl->Release(ps1);
198     return 1;
199 }
200
201 BOOL CALLBACK PropertySheetFuncCommon(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, int buttons)
202 {
203     LPNMHDR lpnm;
204         
205     HWND dialog = GetParent(hwnd);
206
207     if(message == WM_INITDIALOG) {
208         if(logo)
209             SendDlgItemMessage(hwnd, IDC_BITMAP, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)logo);
210
211         RECT rc;
212         GetWindowRect(dialog, &rc);
213         int width = rc.right - rc.left;
214         int height = rc.bottom - rc.top;
215         MoveWindow(dialog, (GetSystemMetrics(SM_CXSCREEN) - width)/2, (GetSystemMetrics(SM_CYSCREEN) - height)/2, width, height, FALSE);
216         return FALSE;
217      }
218
219     if(message == WM_NOTIFY && (((LPNMHDR)lParam)->code == PSN_SETACTIVE)) {
220         PropSheet_SetWizButtons(dialog, buttons);
221         return FALSE;
222     }
223     return FALSE;
224 }
225
226 BOOL CALLBACK PropertySheetFunc1(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
227     if(message == WM_INITDIALOG) {
228         SetDlgItemText(hwnd, IDC_LICENSE, license_text);
229     }
230     return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_NEXT);
231 }
232 BOOL CALLBACK PropertySheetFunc2(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
233     if(message == WM_INITDIALOG) {
234         SetDlgItemText(hwnd, IDC_INSTALL_PATH, install_path);
235
236         config_forAllUsers = 0;
237         SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, config_forAllUsers, 0);
238         SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, config_forAllUsers^1, 0);
239     }
240     if(message == WM_COMMAND) {
241         if((wParam&0xffff) == IDC_BROWSE) {
242             BROWSEINFOA browse;
243             memset(&browse, 0, sizeof(browse));
244             browse.ulFlags = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_USENEWUI;// | BIF_RETURNONLYFSDIRS; //BIF_VALIDATE
245             browse.pszDisplayName = (CHAR*)malloc(MAX_PATH);
246             memset(browse.pszDisplayName, 0, MAX_PATH);
247             browse.lpszTitle = "Select installation directory";
248             printf("Start browsing %s\n", browse.pszDisplayName);
249             browse.pidlRoot = SHBrowseForFolder(&browse);
250             printf("Browsing returns %s / %08x\n", browse.pszDisplayName, browse.pidlRoot);
251             if(browse.pszDisplayName) {
252                 if(SHGetPathFromIDList(browse.pidlRoot, browse.pszDisplayName)) {
253                     printf("Path is %s\n", browse.pszDisplayName);
254                     install_path = browse.pszDisplayName;
255                 }
256             }
257             SendDlgItemMessage(hwnd, IDC_INSTALL_PATH, WM_SETTEXT, 0, (LPARAM)install_path);
258             return 0;
259
260         }
261         else if((wParam&0xffff) == IDC_ALLUSERS) {
262             config_forAllUsers = 1;
263             SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, config_forAllUsers, 0);
264             SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, config_forAllUsers^1, 0);
265         }
266         else if((wParam&0xffff) == IDC_CURRENTUSER) {
267             config_forAllUsers = 0;
268             SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, config_forAllUsers, 0);
269             SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, config_forAllUsers^1, 0);
270         }
271         else if((wParam&0xffff) == IDC_INSTALL_PATH) {
272             SendDlgItemMessage(hwnd, IDC_INSTALL_PATH, WM_GETTEXT, sizeof(pathBuf), (LPARAM)&(pathBuf[0]));
273             if(pathBuf[0]) {
274                 install_path = pathBuf;
275             }
276             return 0;
277         }
278     }
279     return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_BACK|PSWIZB_NEXT);
280 }
281 HWND statuswnd;
282 static int progress_pos = 0;
283 void PropertyArchiveStatus(int type, char*text)
284 {
285     if(text && text[0]=='[') return;
286     SetDlgItemText(statuswnd, IDC_INFO, strdup(text));
287     int t;
288     /* There are usually 6 messages, and a range of 54 to fill, so 
289        step 9 times */
290     for(t=0;t<9;t++) {
291         SendDlgItemMessage(statuswnd, IDC_PROGRESS, PBM_SETPOS, ++progress_pos, 0);
292         processMessages();
293         Sleep(30);
294     }
295     if(type<0) {
296         while(1) {
297             int ret = MessageBox(0, text, "Error", MB_RETRYCANCEL|MB_ICONERROR);
298             if(ret==IDRETRY) continue;
299             else break;
300         }
301     }
302 }
303 BOOL CALLBACK PropertySheetFunc3(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
304     HWND dialog = GetParent(hwnd);
305     if(message == WM_INITDIALOG) {
306         SetDlgItemText(hwnd, IDC_INFO, "Ready to install");
307     }
308     if(message == WM_NOTIFY && (((LPNMHDR)lParam)->code == PSN_WIZNEXT)) {
309         PropSheet_SetWizButtons(dialog, 0);
310         SendMessage(dialog, PSM_CANCELTOCLOSE, 0, 0); //makes wine display a warning
311         SetDlgItemText(hwnd, IDC_TITLE, "Installing files...");
312         statuswnd = hwnd;
313         SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0, (LPARAM)MAKELONG(0,54));
314         progress_pos = 0;
315         SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS, progress_pos, 0);
316         int success = unpack_archive(crndata, install_path, PropertyArchiveStatus);
317         return 0;
318     }
319     return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_BACK|PSWIZB_NEXT);
320 }
321
322 static HRESULT (WINAPI *f_SHGetSpecialFolderPath)(HWND hwnd, LPTSTR lpszPath, int nFolder, BOOL fCreate);
323
324 BOOL CALLBACK PropertySheetFunc4(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
325     if(message == WM_INITDIALOG) {
326         pdf2swf_path = concatPaths(install_path, "pdf2swf_gui.exe");
327         FILE*fi = fopen(pdf2swf_path, "rb");
328         if(fi) {
329             config_createLinks = 1;
330             fclose(fi);
331         }
332         if(!config_createLinks) {
333             SendDlgItemMessage(hwnd, IDC_STARTMENU, SW_HIDE, 0, 0);
334             SendDlgItemMessage(hwnd, IDC_DESKTOP, SW_HIDE, 0, 0);
335         }
336
337         SendDlgItemMessage(hwnd, IDC_STARTMENU, BM_SETCHECK, config_createStartmenu, 0);
338         SendDlgItemMessage(hwnd, IDC_DESKTOP, BM_SETCHECK, config_createStartmenu, 0);
339     }
340     if(message == WM_COMMAND) {
341         if((wParam&0xffff) == IDC_STARTMENU) {
342             config_createStartmenu = SendDlgItemMessage(hwnd, IDC_STARTMENU, BM_GETCHECK, 0, 0);
343             config_createStartmenu^=1;
344             SendDlgItemMessage(hwnd, IDC_STARTMENU, BM_SETCHECK, config_createStartmenu, 0);
345             return 0;
346         }
347         if((wParam&0xffff) == IDC_DESKTOP) {
348             config_createDesktop = SendDlgItemMessage(hwnd, IDC_DESKTOP, BM_GETCHECK, 0, 0);
349             config_createDesktop^=1;
350             SendDlgItemMessage(hwnd, IDC_DESKTOP, BM_SETCHECK, config_createDesktop, 0);
351             return 0;
352         }
353     }
354
355     if(message == WM_NOTIFY && (((LPNMHDR)lParam)->code == PSN_WIZFINISH)) {
356         if(!addRegistryEntries(install_path)) {
357             MessageBox(0, "Couldn't create Registry Entries", "SWFTools Install", MB_OK|MB_ICONERROR);
358             return 1;
359         }
360
361         char mypath[MAX_PATH];
362         path_startmenu[0] = 0;
363         path_desktop[0] = 0;
364         if(config_forAllUsers) {
365             f_SHGetSpecialFolderPath(NULL, path_desktop, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
366             f_SHGetSpecialFolderPath(NULL, path_startmenu, CSIDL_COMMON_PROGRAMS, 0);
367         }
368         /* get local program/desktop directory- this is both for forAllUsers=0 as well
369            as a fallback if the above didn't return any paths */
370         if(!path_startmenu[0]) {
371             f_SHGetSpecialFolderPath(NULL, path_startmenu, CSIDL_PROGRAMS, 0);
372         }
373         if(!path_desktop[0]) {
374             f_SHGetSpecialFolderPath(NULL, path_desktop, CSIDL_DESKTOPDIRECTORY, 0);
375         }
376
377         if(config_createLinks) {
378             if(config_createDesktop && path_desktop[0]) {
379                 char* linkName = concatPaths(path_desktop, "pdf2swf.lnk");
380                 printf("Creating desktop link %s -> %s\n", linkName, pdf2swf_path);
381                 if(!CreateShortcut(pdf2swf_path, "pdf2swf", linkName, 0, 0, 0, install_path)) {
382                     MessageBox(0, "Couldn't create desktop shortcut", "Install.exe", MB_OK);
383                     return 1;
384                 }
385             }
386             if(config_createStartmenu && path_startmenu[0]) {
387                 char* group = concatPaths(path_startmenu, "pdf2swf");
388                 CreateDirectory(group, 0);
389                 char* linkName = concatPaths(group, "pdf2swf.lnk");
390                 printf("Creating %s -> %s\n", linkName, pdf2swf_path);
391                 if(!CreateShortcut(pdf2swf_path, "pdf2swf", linkName, 0, 0, 0, install_path)) {
392                     MessageBox(0, "Couldn't create start menu entry", "Install.exe", MB_OK);
393                     return 1;
394                 }
395             }
396         } else {
397             printf("not creating desktop/startmenu links\n");
398         }
399     }
400     return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_FINISH);
401 }
402
403 #ifndef PSP_HIDEHEADER
404 #define PSP_HIDEHEADER  2048
405 #endif
406
407 typedef struct _wizardpage {
408     DLGPROC function;
409     int resource;
410 } wizardpage_t;
411
412 void runPropertySheet(HWND parent)
413 {
414     PROPSHEETHEADER sheet;
415
416     wizardpage_t wpage[5] = {
417         {PropertySheetFunc1, IDD_LICENSE},
418         {PropertySheetFunc2, IDD_INSTALLDIR},
419         {PropertySheetFunc3, IDD_PROGRESS},
420         {PropertySheetFunc4, IDD_FINISH},
421     };
422     int num = sizeof(wpage)/sizeof(wpage[0]);
423     HPROPSHEETPAGE pages[num];
424     int t;
425     for(t=0;t<num;t++) {
426         PROPSHEETPAGE page;
427         memset(&page, 0, sizeof(PROPSHEETPAGE));
428         page.dwSize = sizeof(PROPSHEETPAGE);
429         page.dwFlags = PSP_DEFAULT|PSP_HIDEHEADER;
430         page.hInstance = me;
431         page.pfnDlgProc = wpage[t].function;
432         page.pszTemplate = MAKEINTRESOURCE(wpage[t].resource);
433         pages[t] = CreatePropertySheetPage(&page);
434     }
435
436     memset(&sheet, 0, sizeof(PROPSHEETHEADER));
437     sheet.dwSize = sizeof(PROPSHEETHEADER);
438     sheet.hInstance = me;
439     sheet.hwndParent = parent;
440     sheet.phpage = pages;
441     sheet.dwFlags = PSH_WIZARD;
442     sheet.nPages = num;
443     PropertySheet(&sheet);
444 }
445
446 int WINAPI WinMain(HINSTANCE _me,HINSTANCE hPrevInst,LPSTR lpszArgs, int nWinMode)
447 {
448     me = _me;
449     WNDCLASSEX wcl_background;
450     wcl_background.hInstance    = me;
451     wcl_background.lpfnWndProc  = WindowFunc;
452     wcl_background.lpszClassName= "SWFTools Install";
453     wcl_background.style        = CS_HREDRAW | CS_VREDRAW;
454     wcl_background.hIcon        = LoadIcon(NULL, IDI_APPLICATION);
455     wcl_background.hIconSm      = LoadIcon(NULL, IDI_APPLICATION);
456     wcl_background.hCursor      = LoadCursor(NULL, IDC_ARROW);
457     wcl_background.lpszMenuName = NULL; //no menu
458     wcl_background.cbClsExtra   = 0;
459     wcl_background.cbWndExtra   = 0;
460     wcl_background.hbrBackground= CreateSolidBrush(RGB(0, 0, 128));
461     wcl_background.cbSize       = sizeof(WNDCLASSEX);
462
463     HINSTANCE shell32 = LoadLibrary("shell32.dll");
464     if(!shell32) {
465         MessageBox(0, "Could not load shell32.dll", "Install.exe", MB_OK);
466         return 1;
467     }
468     f_SHGetSpecialFolderPath = (HRESULT (WINAPI*)(HWND,LPTSTR,int,BOOL))GetProcAddress(shell32, "SHGetSpecialFolderPathA");
469     if(!f_SHGetSpecialFolderPath) {
470         MessageBox(0, "Could not load shell32.dll", "Install.exe", MB_OK);
471         return 1;
472     }
473         
474     HRESULT coret = CoInitialize(NULL);
475     if(FAILED(coret)) {
476         MessageBox(0, "Could not initialize COM interface", "Install.exe", MB_OK);
477         return 1;
478     }
479
480     path_programfiles[0] = 0;
481     f_SHGetSpecialFolderPath(NULL, path_programfiles, CSIDL_PROGRAM_FILES, 0);
482
483     if(!RegisterClassEx(&wcl_background)) {
484         MessageBox(0, "Could not register window background class", "Install.exe", MB_OK);
485         return 1;
486     }
487
488     HWND background = CreateWindow(wcl_background.lpszClassName, "Setup SWFTools",
489                          0, 0, 0, 
490                          GetSystemMetrics(SM_CXFULLSCREEN),
491                          GetSystemMetrics(SM_CYFULLSCREEN),
492                          NULL, NULL, me, 
493                          (void*)"background");
494     
495     if(!background) {
496         MessageBox(0, "Could not create installation background window", "Install.exe", MB_OK);
497         return 1;
498     }
499
500     ShowWindow(background, SW_SHOWMAXIMIZED);
501     SetForegroundWindow(background);
502     UpdateWindow(background);
503
504     logo = LoadBitmap(me, "SWFTOOLS");
505     
506     install_path = getRegistryEntry("Software\\quiss.org\\swftools\\InstallPath");
507     if(!install_path || !install_path[0]) {
508         if(path_programfiles[0]) {
509             install_path = concatPaths(path_programfiles, "SWFTools");
510         } else {
511             install_path = "c:\\swftools\\";
512         }
513     }
514
515     CoInitialize(0);
516     InitCommonControls();
517
518     RECT r = {0,0,0,0};
519     GetWindowRect(background, &r);
520     int xx = 320, yy = 200;
521     if(r.right - r.left > 320)
522         xx = r.right - r.left;
523     if(r.right - r.left > 200)
524         yy = r.bottom - r.top;
525     
526     int ret = 0;
527     runPropertySheet(background);
528
529     return ret;
530 }
531