current user / for all users functionality, use program files dir, added eye candy...
[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         SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, 0, 0);
237         SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, 1, 0);
238     }
239     if(message == WM_COMMAND) {
240         if((wParam&0xffff) == IDC_BROWSE) {
241             BROWSEINFOA browse;
242             memset(&browse, 0, sizeof(browse));
243             browse.ulFlags = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_USENEWUI;// | BIF_RETURNONLYFSDIRS; //BIF_VALIDATE
244             browse.pszDisplayName = (CHAR*)malloc(MAX_PATH);
245             memset(browse.pszDisplayName, 0, MAX_PATH);
246             browse.lpszTitle = "Select installation directory";
247             printf("Start browsing %s\n", browse.pszDisplayName);
248             browse.pidlRoot = SHBrowseForFolder(&browse);
249             printf("Browsing returns %s / %08x\n", browse.pszDisplayName, browse.pidlRoot);
250             if(browse.pszDisplayName) {
251                 if(SHGetPathFromIDList(browse.pidlRoot, browse.pszDisplayName)) {
252                     printf("Path is %s\n", browse.pszDisplayName);
253                     install_path = browse.pszDisplayName;
254                 }
255             }
256             SendDlgItemMessage(hwnd, IDC_INSTALL_PATH, WM_SETTEXT, 0, (LPARAM)install_path);
257             return 0;
258
259         }
260         else if((wParam&0xffff) == IDC_ALLUSERS) {
261             SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, 1, 0);
262             SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, 0, 0);
263         }
264         else if((wParam&0xffff) == IDC_CURRENTUSER) {
265             SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, 0, 0);
266             SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, 1, 0);
267         }
268         else if((wParam&0xffff) == IDC_INSTALL_PATH) {
269             SendDlgItemMessage(hwnd, IDC_INSTALL_PATH, WM_GETTEXT, sizeof(pathBuf), (LPARAM)&(pathBuf[0]));
270             if(pathBuf[0]) {
271                 install_path = pathBuf;
272             }
273             return 0;
274         }
275     }
276     return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_BACK|PSWIZB_NEXT);
277 }
278 HWND statuswnd;
279 static int progress_pos = 0;
280 void PropertyArchiveStatus(int type, char*text)
281 {
282     if(text && text[0]=='[') return;
283     SetDlgItemText(statuswnd, IDC_INFO, strdup(text));
284     int t;
285     /* There are usually 6 messages, and a range of 54 to fill, so 
286        step 9 times */
287     for(t=0;t<9;t++) {
288         SendDlgItemMessage(statuswnd, IDC_PROGRESS, PBM_SETPOS, ++progress_pos, 0);
289         processMessages();
290         Sleep(30);
291     }
292     if(type<0) {
293         while(1) {
294             int ret = MessageBox(0, text, "Error", MB_RETRYCANCEL|MB_ICONERROR);
295             if(ret==IDRETRY) continue;
296             else break;
297         }
298     }
299 }
300 BOOL CALLBACK PropertySheetFunc3(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
301     HWND dialog = GetParent(hwnd);
302     if(message == WM_INITDIALOG) {
303         SetDlgItemText(hwnd, IDC_INFO, "Ready to install");
304     }
305     if(message == WM_NOTIFY && (((LPNMHDR)lParam)->code == PSN_WIZNEXT)) {
306         PropSheet_SetWizButtons(dialog, 0);
307         SendMessage(dialog, PSM_CANCELTOCLOSE, 0, 0); //makes wine display a warning
308         SetDlgItemText(hwnd, IDC_TITLE, "Installing files...");
309         statuswnd = hwnd;
310         SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0, (LPARAM)MAKELONG(0,54));
311         progress_pos = 0;
312         SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS, progress_pos, 0);
313         int success = unpack_archive(crndata, install_path, PropertyArchiveStatus);
314         return 0;
315     }
316     return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_BACK|PSWIZB_NEXT);
317 }
318
319 static HRESULT (WINAPI *f_SHGetSpecialFolderPath)(HWND hwnd, LPTSTR lpszPath, int nFolder, BOOL fCreate);
320
321 BOOL CALLBACK PropertySheetFunc4(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
322     if(message == WM_INITDIALOG) {
323         pdf2swf_path = concatPaths(install_path, "pdf2swf_gui.exe");
324         FILE*fi = fopen(pdf2swf_path, "rb");
325         if(fi) {
326             config_createLinks = 1;
327             fclose(fi);
328         }
329         if(!config_createLinks) {
330             SendDlgItemMessage(hwnd, IDC_STARTMENU, SW_HIDE, 0, 0);
331             SendDlgItemMessage(hwnd, IDC_DESKTOP, SW_HIDE, 0, 0);
332         }
333
334         SendDlgItemMessage(hwnd, IDC_STARTMENU, BM_SETCHECK, config_createStartmenu, 0);
335         SendDlgItemMessage(hwnd, IDC_DESKTOP, BM_SETCHECK, config_createStartmenu, 0);
336     }
337     if(message == WM_COMMAND) {
338         if((wParam&0xffff) == IDC_STARTMENU) {
339             config_createStartmenu = SendDlgItemMessage(hwnd, IDC_STARTMENU, BM_GETCHECK, 0, 0);
340             config_createStartmenu^=1;
341             SendDlgItemMessage(hwnd, IDC_STARTMENU, BM_SETCHECK, config_createStartmenu, 0);
342             return 0;
343         }
344         if((wParam&0xffff) == IDC_DESKTOP) {
345             config_createDesktop = SendDlgItemMessage(hwnd, IDC_DESKTOP, BM_GETCHECK, 0, 0);
346             config_createDesktop^=1;
347             SendDlgItemMessage(hwnd, IDC_DESKTOP, BM_SETCHECK, config_createDesktop, 0);
348             return 0;
349         }
350     }
351
352     if(message == WM_NOTIFY && (((LPNMHDR)lParam)->code == PSN_WIZFINISH)) {
353         if(!addRegistryEntries(install_path)) {
354             MessageBox(0, "Couldn't create Registry Entries", "SWFTools Install", MB_OK|MB_ICONERROR);
355             return 1;
356         }
357
358         char mypath[MAX_PATH];
359         path_startmenu[0] = 0;
360         path_desktop[0] = 0;
361         if(config_forAllUsers) {
362             f_SHGetSpecialFolderPath(NULL, path_desktop, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
363             f_SHGetSpecialFolderPath(NULL, path_startmenu, CSIDL_COMMON_PROGRAMS, 0);
364         }
365         /* get local program/desktop directory- this is both for forAllUsers=0 as well
366            as a fallback if the above didn't return any paths */
367         if(!path_startmenu[0]) {
368             f_SHGetSpecialFolderPath(NULL, path_startmenu, CSIDL_PROGRAMS, 0);
369         }
370         if(!path_desktop[0]) {
371             f_SHGetSpecialFolderPath(NULL, path_desktop, CSIDL_DESKTOPDIRECTORY, 0);
372         }
373
374         if(config_createLinks) {
375             if(config_createDesktop && path_desktop[0]) {
376                 char* linkName = concatPaths(path_desktop, "pdf2swf.lnk");
377                 if(!CreateShortcut(pdf2swf_path, "pdf2swf", linkName, 0, 0, 0, install_path)) {
378                     MessageBox(0, "Couldn't create desktop shortcut", "Install.exe", MB_OK);
379                     return 1;
380                 }
381             }
382             if(config_createStartmenu && path_startmenu[0]) {
383                 char* group = concatPaths(path_startmenu, "pdf2swf");
384                 CreateDirectory(group, 0);
385                 char* linkName = concatPaths(group, "pdf2swf.lnk");
386                 if(!CreateShortcut(pdf2swf_path, "pdf2swf", linkName, 0, 0, 0, install_path)) {
387                     MessageBox(0, "Couldn't create start menu entry", "Install.exe", MB_OK);
388                     return 1;
389                 }
390             }
391         }
392     }
393     return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_FINISH);
394 }
395
396 #ifndef PSP_HIDEHEADER
397 #define PSP_HIDEHEADER  2048
398 #endif
399
400 typedef struct _wizardpage {
401     DLGPROC function;
402     int resource;
403 } wizardpage_t;
404
405 void runPropertySheet(HWND parent)
406 {
407     PROPSHEETHEADER sheet;
408
409     wizardpage_t wpage[5] = {
410         {PropertySheetFunc1, IDD_LICENSE},
411         {PropertySheetFunc2, IDD_INSTALLDIR},
412         {PropertySheetFunc3, IDD_PROGRESS},
413         {PropertySheetFunc4, IDD_FINISH},
414     };
415     int num = sizeof(wpage)/sizeof(wpage[0]);
416     HPROPSHEETPAGE pages[num];
417     int t;
418     for(t=0;t<num;t++) {
419         PROPSHEETPAGE page;
420         memset(&page, 0, sizeof(PROPSHEETPAGE));
421         page.dwSize = sizeof(PROPSHEETPAGE);
422         page.dwFlags = PSP_DEFAULT|PSP_HIDEHEADER;
423         page.hInstance = me;
424         page.pfnDlgProc = wpage[t].function;
425         page.pszTemplate = MAKEINTRESOURCE(wpage[t].resource);
426         pages[t] = CreatePropertySheetPage(&page);
427     }
428
429     memset(&sheet, 0, sizeof(PROPSHEETHEADER));
430     sheet.dwSize = sizeof(PROPSHEETHEADER);
431     sheet.hInstance = me;
432     sheet.hwndParent = parent;
433     sheet.phpage = pages;
434     sheet.dwFlags = PSH_WIZARD;
435     sheet.nPages = num;
436     PropertySheet(&sheet);
437 }
438
439 int WINAPI WinMain(HINSTANCE _me,HINSTANCE hPrevInst,LPSTR lpszArgs, int nWinMode)
440 {
441     me = _me;
442     WNDCLASSEX wcl_background;
443     wcl_background.hInstance    = me;
444     wcl_background.lpfnWndProc  = WindowFunc;
445     wcl_background.lpszClassName= "SWFTools Install";
446     wcl_background.style        = CS_HREDRAW | CS_VREDRAW;
447     wcl_background.hIcon        = LoadIcon(NULL, IDI_APPLICATION);
448     wcl_background.hIconSm      = LoadIcon(NULL, IDI_APPLICATION);
449     wcl_background.hCursor      = LoadCursor(NULL, IDC_ARROW);
450     wcl_background.lpszMenuName = NULL; //no menu
451     wcl_background.cbClsExtra   = 0;
452     wcl_background.cbWndExtra   = 0;
453     wcl_background.hbrBackground= CreateSolidBrush(RGB(0, 0, 128));
454     wcl_background.cbSize       = sizeof(WNDCLASSEX);
455
456     HINSTANCE shell32 = LoadLibrary("shell32.dll");
457     if(!shell32) {
458         MessageBox(0, "Could not load shell32.dll", "Install.exe", MB_OK);
459         return 1;
460     }
461     f_SHGetSpecialFolderPath = (HRESULT (WINAPI*)(HWND,LPTSTR,int,BOOL))GetProcAddress(shell32, "SHGetSpecialFolderPathA");
462     if(!f_SHGetSpecialFolderPath) {
463         MessageBox(0, "Could not load shell32.dll", "Install.exe", MB_OK);
464         return 1;
465     }
466         
467     HRESULT coret = CoInitialize(NULL);
468     if(FAILED(coret)) {
469         MessageBox(0, "Could not initialize COM interface", "Install.exe", MB_OK);
470         return 1;
471     }
472
473     path_programfiles[0] = 0;
474     f_SHGetSpecialFolderPath(NULL, path_programfiles, CSIDL_PROGRAM_FILES, 0);
475
476     if(!RegisterClassEx(&wcl_background)) {
477         MessageBox(0, "Could not register window background class", "Install.exe", MB_OK);
478         return 1;
479     }
480
481     HWND background = CreateWindow(wcl_background.lpszClassName, "Setup SWFTools",
482                          0, 0, 0, 
483                          GetSystemMetrics(SM_CXFULLSCREEN),
484                          GetSystemMetrics(SM_CYFULLSCREEN),
485                          NULL, NULL, me, 
486                          (void*)"background");
487     
488     if(!background) {
489         MessageBox(0, "Could not create installation background window", "Install.exe", MB_OK);
490         return 1;
491     }
492
493     ShowWindow(background, SW_SHOWMAXIMIZED);
494     SetForegroundWindow(background);
495     UpdateWindow(background);
496
497     logo = LoadBitmap(me, "SWFTOOLS");
498     
499     install_path = getRegistryEntry("Software\\quiss.org\\swftools\\InstallPath");
500     install_path = 0;
501     if(!install_path || !install_path[0]) {
502         if(path_programfiles[0]) {
503             install_path = concatPaths(path_programfiles, "SWFTools");
504         } else {
505             install_path = "c:\\swftools\\";
506         }
507     }
508
509     CoInitialize(0);
510     InitCommonControls();
511
512     RECT r = {0,0,0,0};
513     GetWindowRect(background, &r);
514     int xx = 320, yy = 200;
515     if(r.right - r.left > 320)
516         xx = r.right - r.left;
517     if(r.right - r.left > 200)
518         yy = r.bottom - r.top;
519     
520     int ret = 0;
521     runPropertySheet(background);
522
523     return ret;
524 }
525