3 Part of the swftools installer (Main program).
5 Copyright (c) 2004 Matthias Kramm <kramm@quiss.org>
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.
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.
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 */
28 #include "installer.h"
30 #include "../config.h" //for swftools version
32 static int config_forAllUsers = 0;
33 static int config_createLinks = 0;
34 static int config_createStartmenu = 1;
35 static int config_createDesktop = 1;
37 static char path_startmenu[MAX_PATH] = "\0";
38 static char path_desktop[MAX_PATH] = "\0";
39 static char path_programfiles[MAX_PATH] = "\0";
42 extern int crndata_len;
43 extern int crn_decompressed_size;
45 extern char*license_text;
47 static char*install_path = "c:\\swftools\\";
48 static char pathBuf[MAX_PATH];
49 static int do_abort = 0;
51 static char* pdf2swf_path;
53 static HBITMAP logo = 0;
57 #define USER_SETMESSAGE 0x7f01
59 static void tball(HDC hdc, double px, double py, double sx, double sy)
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);
103 static char* concatPaths(const char*base, const char*add)
105 int l1 = strlen(base);
106 int l2 = strlen(add);
109 while(l1 && base[l1-1] == '\\')
111 while(pos < l2 && add[pos] == '\\')
114 n = (char*)malloc(l1 + (l2-pos) + 2);
117 strcpy(&n[l1+1],&add[pos]);
121 static void handleTemplateFile(const char*filename)
123 FILE*fi = fopen(filename, "rb");
124 fseek(fi, SEEK_END, 0);
126 fseek(fi, SEEK_SET, 0);
127 char*file = malloc(len);
128 fread(file, len, 1, fi);
130 int l = strlen(install_path);
131 fi = fopen(filename, "wb");
135 pos = strstr(pos, "%%PATH%%");
141 fwrite(lastpos, pos-lastpos, 1, fi);
142 fwrite(install_path, l, 1, fi);
143 pos+=8; // length of "%%PATH%%"
146 fwrite(lastpos, pos-lastpos, 1, fi);
151 static char* getRegistryEntry(char*path)
159 rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0, KEY_ALL_ACCESS/* KEY_READ*/, &key);
160 if (rc != ERROR_SUCCESS) {
161 fprintf(stderr, "RegOpenKeyEx failed\n");
164 rc = RegQueryValueEx(key, NULL, 0, 0, 0, (LPDWORD)&size) ;
165 if(rc != ERROR_SUCCESS) {
166 fprintf(stderr, "RegQueryValueEx(1) failed: %d\n", rc);
169 buf = (char*)malloc(size+1);
170 rc = RegQueryValueEx(key, NULL, 0, &type, (BYTE*)buf, (LPDWORD)&size);
171 if(rc != ERROR_SUCCESS) {
172 fprintf(stderr, "RegQueryValueEx(2) failed: %d\n", rc);
175 if(type == REG_SZ || type == REG_EXPAND_SZ) {
176 while(size && buf[size-1] == '\0')
181 } else if(type == REG_BINARY) {
186 static int setRegistryEntry(char*key,char*value)
190 int ret1 = -1, ret2= -1;
191 ret1 = RegCreateKey(HKEY_CURRENT_USER, key, &hkey1);
192 if(config_forAllUsers) {
193 ret2 = RegCreateKey(HKEY_LOCAL_MACHINE, key, &hkey2);
197 fprintf(stderr, "registry: CreateKey %s failed\n", key);
201 ret1 = RegSetValue(hkey1, NULL, REG_SZ, value, strlen(value)+1);
203 ret2 = RegSetValue(hkey2, NULL, REG_SZ, value, strlen(value)+1);
205 fprintf(stderr, "registry: SetValue %s failed\n", key);
211 static HWND wnd_background = 0;
212 LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
214 if(message == WM_CREATE) {
215 CREATESTRUCT*cs = ((LPCREATESTRUCT)lParam);
216 if(cs->lpCreateParams && !strcmp((char*)cs->lpCreateParams, "background")) {
217 wnd_background = hwnd;
220 if(hwnd == wnd_background && message == WM_PAINT) {
224 GetWindowRect(hwnd, &rc);
225 int width = rc.right - rc.left;
226 int height = rc.bottom - rc.top;
228 hdc = BeginPaint(hwnd, &ps);
229 SetBkMode(hdc, TRANSPARENT);
231 double s = width / 1282.0;
233 HPEN pen0 = CreatePen(PS_SOLID, 2, RGB(0, 32, 128));
234 HPEN oldPen = (HPEN)SelectObject(hdc, pen0);
235 tball(hdc, 0.7*width,0.2*height,s,s);
237 HPEN pen1 = CreatePen(PS_SOLID, 2, RGB(0, 48, 128));
238 (HPEN)SelectObject(hdc, pen1);
239 tball(hdc, 0.233*width,0.3*height,s*2,s*2);
241 HPEN pen2 = CreatePen(PS_SOLID, 2, RGB(0, 64, 128));
242 (HPEN)SelectObject(hdc, pen2);
243 tball(hdc, width, 1.2*height,s*3,-s*3);
245 SelectObject(hdc, oldPen);
251 return DefWindowProc(hwnd, message, wParam, lParam);
254 void processMessages()
257 while(PeekMessage(&msg,NULL,0,0,0))
259 GetMessage(&msg, NULL, 0, 0);
260 TranslateMessage(&msg);
261 DispatchMessage(&msg);
265 int addRegistryEntries(char*install_dir)
268 ret = setRegistryEntry("Software\\quiss.org\\swftools\\InstallPath", install_dir);
273 int CreateShortcut(char*path, char*description, char*filename, char*arguments, int iconindex, char*iconpath, char*workdir)
275 WCHAR wszFilename[MAX_PATH];
276 IShellLink *ps1 = NULL;
277 IPersistFile *pPf = NULL;
279 hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (void*)&ps1);
280 if(FAILED(hr)) return 0;
281 hr = ps1->lpVtbl->QueryInterface(ps1, &IID_IPersistFile, (void **)&pPf);
282 if(FAILED(hr)) return 0;
283 hr = ps1->lpVtbl->SetPath(ps1, path);
284 if(FAILED(hr)) return 0;
285 hr = ps1->lpVtbl->SetDescription(ps1, description);
288 hr = ps1->lpVtbl->SetArguments(ps1, arguments);
289 if(FAILED(hr)) return 0;
292 hr = ps1->lpVtbl->SetIconLocation(ps1, iconpath, iconindex);
293 if (FAILED(hr)) return 0;
296 hr = ps1->lpVtbl->SetWorkingDirectory(ps1, workdir);
297 if (FAILED(hr)) return 0;
299 MultiByteToWideChar(CP_ACP, 0, filename, -1, wszFilename, MAX_PATH);
300 hr = pPf->lpVtbl->Save(pPf, wszFilename, TRUE);
304 pPf->lpVtbl->Release(pPf);
305 ps1->lpVtbl->Release(ps1);
309 static int CreateURL(const char*url, const char*path)
311 FILE*fi = fopen(path, "wb");
314 fprintf(fi, "[InternetShortcut]\r\n");
315 fprintf(fi, "URL=http://localhost:8081/\r\n");
321 BOOL CALLBACK PropertySheetFuncCommon(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, int buttons)
325 HWND dialog = GetParent(hwnd);
327 if(message == WM_INITDIALOG) {
329 SendDlgItemMessage(hwnd, IDC_BITMAP, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)logo);
332 GetWindowRect(dialog, &rc);
333 int width = rc.right - rc.left;
334 int height = rc.bottom - rc.top;
335 MoveWindow(dialog, (GetSystemMetrics(SM_CXSCREEN) - width)/2, (GetSystemMetrics(SM_CYSCREEN) - height)/2, width, height, FALSE);
339 if(message == WM_NOTIFY && (((LPNMHDR)lParam)->code == PSN_SETACTIVE)) {
340 PropSheet_SetWizButtons(dialog, buttons);
346 BOOL CALLBACK PropertySheetFunc1(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
347 if(message == WM_INITDIALOG) {
348 SetDlgItemText(hwnd, IDC_LICENSE, license_text);
350 return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_NEXT);
352 BOOL CALLBACK PropertySheetFunc2(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
353 if(message == WM_INITDIALOG) {
354 SetDlgItemText(hwnd, IDC_INSTALL_PATH, install_path);
356 config_forAllUsers = 0;
357 SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, config_forAllUsers, 0);
358 SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, config_forAllUsers^1, 0);
360 if(message == WM_COMMAND) {
361 if((wParam&0xffff) == IDC_BROWSE) {
363 memset(&browse, 0, sizeof(browse));
364 browse.ulFlags = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_USENEWUI;// | BIF_RETURNONLYFSDIRS; //BIF_VALIDATE
365 browse.pszDisplayName = (CHAR*)malloc(MAX_PATH);
366 memset(browse.pszDisplayName, 0, MAX_PATH);
367 browse.lpszTitle = "Select installation directory";
368 printf("Start browsing %s\n", browse.pszDisplayName);
369 browse.pidlRoot = SHBrowseForFolder(&browse);
370 printf("Browsing returns %s / %08x\n", browse.pszDisplayName, browse.pidlRoot);
371 if(browse.pszDisplayName) {
372 if(SHGetPathFromIDList(browse.pidlRoot, browse.pszDisplayName)) {
373 printf("Path is %s\n", browse.pszDisplayName);
374 install_path = browse.pszDisplayName;
375 int l = strlen(install_path);
376 while(l && install_path[l-1]=='\\') {
381 SendDlgItemMessage(hwnd, IDC_INSTALL_PATH, WM_SETTEXT, 0, (LPARAM)install_path);
385 else if((wParam&0xffff) == IDC_ALLUSERS) {
386 config_forAllUsers = 1;
387 SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, config_forAllUsers, 0);
388 SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, config_forAllUsers^1, 0);
390 else if((wParam&0xffff) == IDC_CURRENTUSER) {
391 config_forAllUsers = 0;
392 SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, config_forAllUsers, 0);
393 SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, config_forAllUsers^1, 0);
395 else if((wParam&0xffff) == IDC_INSTALL_PATH) {
396 SendDlgItemMessage(hwnd, IDC_INSTALL_PATH, WM_GETTEXT, sizeof(pathBuf), (LPARAM)&(pathBuf[0]));
398 install_path = pathBuf;
399 int l = strlen(install_path);
400 while(l && install_path[l-1]=='\\') {
407 return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_BACK|PSWIZB_NEXT);
410 static int progress_pos = 0;
411 void PropertyArchiveStatus(int type, char*text)
413 if(text && text[0]=='[') return;
414 SetDlgItemText(statuswnd, IDC_INFO, strdup(text));
416 /* There are usually 4 messages, and a range of 40 to fill, so
419 SendDlgItemMessage(statuswnd, IDC_PROGRESS, PBM_SETPOS, ++progress_pos, 0);
425 int ret = MessageBox(0, text, "Error", MB_RETRYCANCEL|MB_ICONERROR);
426 if(ret==IDRETRY) continue;
432 void print_space(char*dest, char*msg, ULONGLONG size)
435 sprintf(dest, "%s%d Bytes", msg, size);
436 else if(size < 1048576l)
437 sprintf(dest, "%s%.2f Kb", msg, size/1024.0);
438 else if(size < 1073741824l)
439 sprintf(dest, "%s%.2f Mb", msg, size/1048576.0);
440 else if(size < 1099511627776ll)
441 sprintf(dest, "%s%.2f Gb", msg, size/1073741824.0);
443 sprintf(dest, "%s%.2f Tb", msg, size/1125899906842624.0);
446 BOOL CALLBACK PropertySheetFunc3(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
447 HWND dialog = GetParent(hwnd);
448 if(message == WM_INITDIALOG) {
449 SetDlgItemText(hwnd, IDC_INFO, "Ready to install");
452 print_space(buf, "Space required: ", crn_decompressed_size);
453 SetDlgItemText(hwnd, IDC_SPACE1, buf);
454 ULARGE_INTEGER available,total,totalfree;
455 available.QuadPart=0;
457 totalfree.QuadPart=0;
458 GetDiskFreeSpaceEx(install_path, &available, &total, &totalfree);
459 print_space(buf, "Space available: ", available.QuadPart);
460 SetDlgItemText(hwnd, IDC_SPACE2, buf);
462 if(message == WM_NOTIFY && (((LPNMHDR)lParam)->code == PSN_WIZNEXT)) {
463 SetDlgItemText(hwnd, IDC_SPACE1, "");
464 SetDlgItemText(hwnd, IDC_SPACE2, "");
465 PropSheet_SetWizButtons(dialog, 0);
466 SendMessage(dialog, PSM_CANCELTOCLOSE, 0, 0); //makes wine display a warning
467 SetDlgItemText(hwnd, IDC_TITLE, "Installing files...");
469 SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0, (LPARAM)MAKELONG(0,40));
471 SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS, progress_pos, 0);
472 int success = unpack_archive(crndata, crndata_len, install_path, PropertyArchiveStatus);
474 MessageBox(0, "Couldn't extract all installation files", "SWFTools Install", MB_OK|MB_ICONERROR);
480 return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_BACK|PSWIZB_NEXT);
483 static HRESULT (WINAPI *f_SHGetSpecialFolderPath)(HWND hwnd, LPTSTR lpszPath, int nFolder, BOOL fCreate);
485 BOOL CALLBACK PropertySheetFunc4(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
486 if(message == WM_INITDIALOG) {
487 pdf2swf_path = concatPaths(install_path, "pdf2swf_gui.exe");
488 FILE*fi = fopen(pdf2swf_path, "rb");
490 printf("a GUI program exists, creating desktop/startmenu links\n");
491 config_createLinks = 1;
494 if(!config_createLinks) {
495 SendDlgItemMessage(hwnd, IDC_STARTMENU, SW_HIDE, 0, 0);
496 SendDlgItemMessage(hwnd, IDC_DESKTOP, SW_HIDE, 0, 0);
499 SendDlgItemMessage(hwnd, IDC_STARTMENU, BM_SETCHECK, config_createStartmenu, 0);
500 SendDlgItemMessage(hwnd, IDC_DESKTOP, BM_SETCHECK, config_createStartmenu, 0);
502 if(message == WM_COMMAND) {
503 if((wParam&0xffff) == IDC_STARTMENU) {
504 config_createStartmenu = SendDlgItemMessage(hwnd, IDC_STARTMENU, BM_GETCHECK, 0, 0);
505 config_createStartmenu^=1;
506 SendDlgItemMessage(hwnd, IDC_STARTMENU, BM_SETCHECK, config_createStartmenu, 0);
509 if((wParam&0xffff) == IDC_DESKTOP) {
510 config_createDesktop = SendDlgItemMessage(hwnd, IDC_DESKTOP, BM_GETCHECK, 0, 0);
511 config_createDesktop^=1;
512 SendDlgItemMessage(hwnd, IDC_DESKTOP, BM_SETCHECK, config_createDesktop, 0);
517 if(message == WM_NOTIFY && (((LPNMHDR)lParam)->code == PSN_WIZFINISH)) {
518 if(!addRegistryEntries(install_path)) {
519 MessageBox(0, "Couldn't create Registry Entries", "SWFTools Install", MB_OK|MB_ICONERROR);
523 char mypath[MAX_PATH];
524 path_startmenu[0] = 0;
526 if(config_forAllUsers) {
527 f_SHGetSpecialFolderPath(NULL, path_desktop, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
528 f_SHGetSpecialFolderPath(NULL, path_startmenu, CSIDL_COMMON_PROGRAMS, 0);
530 /* get local program/desktop directory- this is both for forAllUsers=0 as well
531 as a fallback if the above didn't return any paths */
532 if(!path_startmenu[0]) {
533 f_SHGetSpecialFolderPath(NULL, path_startmenu, CSIDL_PROGRAMS, 0);
535 if(!path_desktop[0]) {
536 f_SHGetSpecialFolderPath(NULL, path_desktop, CSIDL_DESKTOPDIRECTORY, 0);
539 if(config_createLinks) {
540 if(config_createDesktop && path_desktop[0]) {
541 char* linkName = concatPaths(path_desktop, "pdf2swf.lnk");
542 printf("Creating desktop link %s -> %s\n", linkName, pdf2swf_path);
543 if(!CreateShortcut(pdf2swf_path, "pdf2swf", linkName, 0, 0, 0, install_path)) {
544 MessageBox(0, "Couldn't create desktop shortcut", "Install.exe", MB_OK);
548 if(config_createStartmenu && path_startmenu[0]) {
549 char* group = concatPaths(path_startmenu, "pdf2swf");
550 CreateDirectory(group, 0);
551 char* linkName = concatPaths(group, "pdf2swf.lnk");
552 printf("Creating %s -> %s\n", linkName, pdf2swf_path);
553 if(!CreateShortcut(pdf2swf_path, "pdf2swf", linkName, 0, 0, 0, install_path)) {
554 MessageBox(0, "Couldn't create start menu entry", "Install.exe", MB_OK);
559 printf("not creating desktop/startmenu links\n");
562 return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_FINISH);
565 #ifndef PSP_HIDEHEADER
566 #define PSP_HIDEHEADER 2048
569 typedef struct _wizardpage {
574 void runPropertySheet(HWND parent)
576 PROPSHEETHEADER sheet;
578 wizardpage_t wpage[5] = {
579 {PropertySheetFunc1, IDD_LICENSE},
580 {PropertySheetFunc2, IDD_INSTALLDIR},
581 {PropertySheetFunc3, IDD_PROGRESS},
582 {PropertySheetFunc4, IDD_FINISH},
584 int num = sizeof(wpage)/sizeof(wpage[0]);
585 HPROPSHEETPAGE pages[num];
589 memset(&page, 0, sizeof(PROPSHEETPAGE));
590 page.dwSize = sizeof(PROPSHEETPAGE);
591 page.dwFlags = PSP_DEFAULT|PSP_HIDEHEADER;
593 page.pfnDlgProc = wpage[t].function;
594 page.pszTemplate = MAKEINTRESOURCE(wpage[t].resource);
595 pages[t] = CreatePropertySheetPage(&page);
598 memset(&sheet, 0, sizeof(PROPSHEETHEADER));
599 sheet.dwSize = sizeof(PROPSHEETHEADER);
600 sheet.hInstance = me;
601 sheet.hwndParent = parent;
602 sheet.phpage = pages;
603 sheet.dwFlags = PSH_WIZARD;
605 PropertySheet(&sheet);
608 int WINAPI WinMain(HINSTANCE _me,HINSTANCE hPrevInst,LPSTR lpszArgs, int nWinMode)
611 WNDCLASSEX wcl_background;
612 wcl_background.hInstance = me;
613 wcl_background.lpfnWndProc = WindowFunc;
614 wcl_background.lpszClassName= "SWFTools Install";
615 wcl_background.style = CS_HREDRAW | CS_VREDRAW;
616 wcl_background.hIcon = LoadIcon(NULL, IDI_APPLICATION);
617 wcl_background.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
618 wcl_background.hCursor = LoadCursor(NULL, IDC_ARROW);
619 wcl_background.lpszMenuName = NULL; //no menu
620 wcl_background.cbClsExtra = 0;
621 wcl_background.cbWndExtra = 0;
622 wcl_background.hbrBackground= CreateSolidBrush(RGB(0, 0, 128));
623 wcl_background.cbSize = sizeof(WNDCLASSEX);
625 HINSTANCE shell32 = LoadLibrary("shell32.dll");
627 MessageBox(0, "Could not load shell32.dll", "Install.exe", MB_OK);
630 f_SHGetSpecialFolderPath = (HRESULT (WINAPI*)(HWND,LPTSTR,int,BOOL))GetProcAddress(shell32, "SHGetSpecialFolderPathA");
631 if(!f_SHGetSpecialFolderPath) {
632 MessageBox(0, "Could not load shell32.dll", "Install.exe", MB_OK);
636 HRESULT coret = CoInitialize(NULL);
638 MessageBox(0, "Could not initialize COM interface", "Install.exe", MB_OK);
642 path_programfiles[0] = 0;
643 f_SHGetSpecialFolderPath(NULL, path_programfiles, CSIDL_PROGRAM_FILES, 0);
645 if(!RegisterClassEx(&wcl_background)) {
646 MessageBox(0, "Could not register window background class", "Install.exe", MB_OK);
650 HWND background = CreateWindow(wcl_background.lpszClassName, "Setup SWFTools",
652 GetSystemMetrics(SM_CXFULLSCREEN),
653 GetSystemMetrics(SM_CYFULLSCREEN),
655 (void*)"background");
658 MessageBox(0, "Could not create installation background window", "Install.exe", MB_OK);
662 ShowWindow(background, SW_SHOWMAXIMIZED);
663 SetForegroundWindow(background);
664 UpdateWindow(background);
666 logo = LoadBitmap(me, "SWFTOOLS");
668 install_path = getRegistryEntry("Software\\quiss.org\\swftools\\InstallPath");
669 if(!install_path || !install_path[0]) {
670 if(path_programfiles[0]) {
671 install_path = concatPaths(path_programfiles, "SWFTools");
673 install_path = "c:\\swftools\\";
678 InitCommonControls();
681 GetWindowRect(background, &r);
682 int xx = 320, yy = 200;
683 if(r.right - r.left > 320)
684 xx = r.right - r.left;
685 if(r.right - r.left > 200)
686 yy = r.bottom - r.top;
689 runPropertySheet(background);