3 Part of the rfx installer (Main program).
5 Copyright (c) 2004-2008 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"
34 static int config_forAllUsers = 0;
35 static int config_createLinks = 0;
36 static int config_createStartmenu = 1;
37 static int config_createDesktop = 1;
38 static int config_deleteextra = 1;
40 static char path_startmenu[MAX_PATH] = "\0";
41 static char path_desktop[MAX_PATH] = "\0";
42 static char path_programfiles[MAX_PATH] = "\0";
44 static char pathBuf[MAX_PATH];
45 static int do_abort = 0;
47 static char* pdf2swf_path;
49 static char registry_path[1024];
51 static char*install_path = "c:\\swftools\\";
52 #define SOFTWARE_DOMAIN "quiss.org"
53 #define SOFTWARE_NAME "SWFTools"
54 #define INSTALLER_NAME "SWFTools Installer"
56 static HBITMAP logo = 0;
60 #define USER_SETMESSAGE 0x7f01
64 extern int crndata_len;
65 extern int crn_decompressed_size;
66 extern char*license_text;
68 #include "background.c"
71 typedef struct _filelist
74 struct _filelist*next;
78 static filelist_t* registerFile(filelist_t*next, const char*filename, char type)
80 filelist_t*file = malloc(sizeof(filelist_t));
81 file->filename = strdup(filename);
87 static filelist_t* readFileList(char*filename)
89 FILE*fi = fopen(filename, "rb");
93 fseek(fi, 0, SEEK_END);
95 fseek(fi, 0, SEEK_SET);
96 char*data = malloc(len+1);
97 fread(data, len, 1, fi);
101 filelist_t*list = 0,*lpos=0;;
103 if(data[t]=='\r' || data[t]=='\n') {
105 if(strchr("DFI", line[0]) && line[1]==' ' && line[2]!=' ') {
106 filelist_t*f = malloc(sizeof(filelist_t));
108 f->filename=strdup(line+2);
117 // skip line- this usually only happens if somebody tampered
120 while(t<len && (data[t]=='\0' || data[t]=='\r' || data[t]=='\n'))
130 static void writeFileList(filelist_t*file, const char*filename)
132 FILE*fi = fopen(filename, "wb");
133 fprintf(fi, "[%s installed files]\r\n", SOFTWARE_NAME);
136 sprintf(buf, "Couldn't write file %s", filename);
137 MessageBox(0, buf, INSTALLER_NAME, MB_OK|MB_ICONERROR);
142 fprintf(fi, "%c %s\r\n", file->type, file->filename);
148 static filelist_t*installedFiles = 0;
150 static void addFile(const char*filename)
152 installedFiles = registerFile(installedFiles, filename, 'F');
154 static void addDir(const char*filename)
156 installedFiles = registerFile(installedFiles, filename, 'D');
159 static void handleTemplateFile(const char*filename)
161 FILE*fi = fopen(filename, "rb");
162 fseek(fi, 0, SEEK_END);
164 fseek(fi, 0, SEEK_SET);
165 char*file = malloc(len+1);
166 fread(file, len, 1, fi);
168 int l = strlen(install_path);
169 fi = fopen(filename, "wb");
173 pos = strstr(pos, "%%PATH%%");
179 fwrite(lastpos, pos-lastpos, 1, fi);
180 fwrite(install_path, l, 1, fi);
181 pos+=8; // length of "%%PATH%%"
184 fwrite(lastpos, pos-lastpos, 1, fi);
189 static int setRegistryEntry(char*key,char*value)
193 int ret1 = -1, ret2= -1;
194 ret1 = RegCreateKey(HKEY_CURRENT_USER, key, &hkey1);
195 if(config_forAllUsers) {
196 ret2 = RegCreateKey(HKEY_LOCAL_MACHINE, key, &hkey2);
200 fprintf(stderr, "registry: CreateKey %s failed\n", key);
204 installedFiles = registerFile(installedFiles, key, 'k');
207 installedFiles = registerFile(installedFiles, key, 'K');
211 ret1 = RegSetValue(hkey1, NULL, REG_SZ, value, strlen(value)+1);
213 ret2 = RegSetValue(hkey2, NULL, REG_SZ, value, strlen(value)+1);
215 fprintf(stderr, "registry: SetValue %s failed\n", key);
222 static char* getRegistryEntry(char*path)
230 rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0, KEY_ALL_ACCESS/* KEY_READ*/, &key);
231 if (rc != ERROR_SUCCESS) {
232 fprintf(stderr, "RegOpenKeyEx failed\n");
235 rc = RegQueryValueEx(key, NULL, 0, 0, 0, (LPDWORD)&size) ;
236 if(rc != ERROR_SUCCESS) {
237 fprintf(stderr, "RegQueryValueEx(1) failed: %d\n", rc);
240 buf = (char*)malloc(size+1);
241 rc = RegQueryValueEx(key, NULL, 0, &type, (BYTE*)buf, (LPDWORD)&size);
242 if(rc != ERROR_SUCCESS) {
243 fprintf(stderr, "RegQueryValueEx(2) failed: %d\n", rc);
246 if(type == REG_SZ || type == REG_EXPAND_SZ) {
247 while(size && buf[size-1] == '\0')
252 } else if(type == REG_BINARY) {
257 void processMessages()
260 while(PeekMessage(&msg,NULL,0,0,0))
262 GetMessage(&msg, NULL, 0, 0);
263 TranslateMessage(&msg);
264 DispatchMessage(&msg);
268 int addRegistryEntries(char*install_dir)
271 ret = setRegistryEntry(registry_path, install_dir);
276 int CreateShortcut(char*path, char*description, char*filename, char*arguments, int iconindex, char*iconpath, char*workdir)
278 printf("Creating %s -> %s\n", filename, path);
279 WCHAR wszFilename[MAX_PATH];
280 IShellLink *ps1 = NULL;
281 IPersistFile *pPf = NULL;
283 hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (void*)&ps1);
284 if(FAILED(hr)) return 0;
285 hr = ps1->lpVtbl->QueryInterface(ps1, &IID_IPersistFile, (void **)&pPf);
286 if(FAILED(hr)) return 0;
287 hr = ps1->lpVtbl->SetPath(ps1, path);
288 if(FAILED(hr)) return 0;
289 hr = ps1->lpVtbl->SetDescription(ps1, description);
292 hr = ps1->lpVtbl->SetArguments(ps1, arguments);
293 if(FAILED(hr)) return 0;
296 hr = ps1->lpVtbl->SetIconLocation(ps1, iconpath, iconindex);
297 if (FAILED(hr)) return 0;
300 hr = ps1->lpVtbl->SetWorkingDirectory(ps1, workdir);
301 if (FAILED(hr)) return 0;
303 MultiByteToWideChar(CP_ACP, 0, filename, -1, wszFilename, MAX_PATH);
304 hr = pPf->lpVtbl->Save(pPf, wszFilename, TRUE);
308 pPf->lpVtbl->Release(pPf);
309 ps1->lpVtbl->Release(ps1);
314 static int CreateURL(const char*url, const char*path)
316 FILE*fi = fopen(path, "wb");
319 fprintf(fi, "[InternetShortcut]\r\n");
320 fprintf(fi, "URL=http://localhost:8081/\r\n");
327 BOOL CALLBACK PropertySheetFuncCommon(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, int buttons)
331 HWND dialog = GetParent(hwnd);
333 if(message == WM_INITDIALOG) {
335 SendDlgItemMessage(hwnd, IDC_BITMAP, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)logo);
338 GetWindowRect(dialog, &rc);
339 int width = rc.right - rc.left;
340 int height = rc.bottom - rc.top;
341 MoveWindow(dialog, (GetSystemMetrics(SM_CXSCREEN) - width)/2, (GetSystemMetrics(SM_CYSCREEN) - height)/2, width, height, FALSE);
345 if(message == WM_NOTIFY && (((LPNMHDR)lParam)->code == PSN_SETACTIVE)) {
346 PropSheet_SetWizButtons(dialog, buttons);
353 BOOL CALLBACK PropertySheetFunc1(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
354 if(message == WM_INITDIALOG) {
355 SetDlgItemText(hwnd, IDC_LICENSE, license_text);
357 return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_NEXT);
359 BOOL CALLBACK PropertySheetFunc2(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
360 if(message == WM_INITDIALOG) {
361 SetDlgItemText(hwnd, IDC_INSTALL_PATH, install_path);
363 config_forAllUsers = 0;
364 SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, config_forAllUsers, 0);
365 SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, config_forAllUsers^1, 0);
367 if(message == WM_COMMAND) {
368 if((wParam&0xffff) == IDC_BROWSE) {
370 memset(&browse, 0, sizeof(browse));
371 browse.ulFlags = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_USENEWUI;// | BIF_RETURNONLYFSDIRS; //BIF_VALIDATE
372 browse.pszDisplayName = (CHAR*)malloc(MAX_PATH);
373 memset(browse.pszDisplayName, 0, MAX_PATH);
374 browse.lpszTitle = "Select installation directory";
375 browse.pidlRoot = SHBrowseForFolder(&browse);
376 if(browse.pszDisplayName) {
377 if(SHGetPathFromIDList(browse.pidlRoot, browse.pszDisplayName)) {
378 install_path = browse.pszDisplayName;
379 int l = strlen(install_path);
380 while(l && install_path[l-1]=='\\') {
385 SendDlgItemMessage(hwnd, IDC_INSTALL_PATH, WM_SETTEXT, 0, (LPARAM)install_path);
389 else if((wParam&0xffff) == IDC_ALLUSERS) {
390 config_forAllUsers = 1;
391 SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, config_forAllUsers, 0);
392 SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, config_forAllUsers^1, 0);
394 else if((wParam&0xffff) == IDC_CURRENTUSER) {
395 config_forAllUsers = 0;
396 SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, config_forAllUsers, 0);
397 SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, config_forAllUsers^1, 0);
399 else if((wParam&0xffff) == IDC_INSTALL_PATH) {
400 SendDlgItemMessage(hwnd, IDC_INSTALL_PATH, WM_GETTEXT, sizeof(pathBuf), (LPARAM)&(pathBuf[0]));
402 install_path = pathBuf;
403 int l = strlen(install_path);
404 while(l && install_path[l-1]=='\\') {
411 return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_BACK|PSWIZB_NEXT);
414 static int progress_pos = 0;
416 void PropertyArchiveError(char*text)
419 int ret = MessageBox(0, text, "Error", MB_RETRYCANCEL|MB_ICONERROR);
420 if(ret==IDRETRY) continue;
425 void PropertyArchive_NewFile(char*filename)
430 void PropertyArchive_NewDirectory(char*filename)
436 static int lastlen = 0;
437 void PropertyArchiveStatus(int pos, int len)
440 SendDlgItemMessage(statuswnd, IDC_PROGRESS, PBM_SETRANGE, 0, (LPARAM)MAKELONG(0,len));
443 SendDlgItemMessage(statuswnd, IDC_PROGRESS, PBM_SETPOS, pos, 0);
447 void PropertyArchiveMessage(char*text)
449 if(text && text[0]=='[') {
452 SetDlgItemText(statuswnd, IDC_INFO, strdup(text));
456 void print_space(char*dest, char*msg, ULONGLONG size)
459 sprintf(dest, "%s%d Bytes", msg, size);
460 else if(size < 1048576l)
461 sprintf(dest, "%s%.2f Kb", msg, size/1024.0);
462 else if(size < 1073741824l)
463 sprintf(dest, "%s%.2f Mb", msg, size/1048576.0);
464 else if(size < 1099511627776ll)
465 sprintf(dest, "%s%.2f Gb", msg, size/1073741824.0);
467 sprintf(dest, "%s%.2f Tb", msg, size/1125899906842624.0);
470 BOOL CALLBACK PropertySheetFunc3(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
471 HWND dialog = GetParent(hwnd);
472 if(message == WM_INITDIALOG) {
473 SetDlgItemText(hwnd, IDC_INFO, "Ready to install");
476 print_space(buf, "Space required: ", crn_decompressed_size);
477 SetDlgItemText(hwnd, IDC_SPACE1, buf);
478 ULARGE_INTEGER available,total,totalfree;
479 available.QuadPart=0;
481 totalfree.QuadPart=0;
482 if(GetDiskFreeSpaceEx(install_path, &available, &total, &totalfree)) {
483 print_space(buf, "Space available: ", available.QuadPart);
485 sprintf(buf, "Space available: [Error %d]", GetLastError());
486 if(GetLastError() == ERROR_FILE_NOT_FOUND && install_path[0] && install_path[1]==':') {
487 /* installation directory does not yet exist */
488 char path[3]={'c',':',0};
489 path[0] = install_path[0];
490 if(GetDiskFreeSpaceEx(path, &available, &total, &totalfree)) {
491 print_space(buf, "Space available: ", available.QuadPart);
495 SetDlgItemText(hwnd, IDC_SPACE2, buf);
497 if(message == WM_NOTIFY && (((LPNMHDR)lParam)->code == PSN_WIZNEXT)) {
498 SetDlgItemText(hwnd, IDC_SPACE1, "");
499 SetDlgItemText(hwnd, IDC_SPACE2, "");
500 PropSheet_SetWizButtons(dialog, 0);
501 SendMessage(dialog, PSM_CANCELTOCLOSE, 0, 0); //makes wine display a warning
502 SetDlgItemText(hwnd, IDC_TITLE, "Installing files...");
505 status.status = PropertyArchiveStatus;
506 status.message = PropertyArchiveMessage;
507 status.error = PropertyArchiveError;
508 status.new_file = PropertyArchive_NewFile;
509 status.new_directory = PropertyArchive_NewDirectory;
510 int success = unpack_archive(crndata, crndata_len, install_path, &status);
511 memset(&status, 0, sizeof(status_t));
513 MessageBox(0, "Couldn't extract all installation files", INSTALLER_NAME, MB_OK|MB_ICONERROR);
519 return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_BACK|PSWIZB_NEXT);
522 static HRESULT (WINAPI *f_SHGetSpecialFolderPath)(HWND hwnd, LPTSTR lpszPath, int nFolder, BOOL fCreate);
524 BOOL CALLBACK PropertySheetFunc4(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
525 if(message == WM_INITDIALOG) {
526 pdf2swf_path = concatPaths(install_path, "pdf2swf_gui.exe");
527 FILE*fi = fopen(pdf2swf_path, "rb");
529 printf("a GUI program exists, creating desktop/startmenu links\n");
530 config_createLinks = 1;
533 if(!config_createLinks) {
534 SendDlgItemMessage(hwnd, IDC_STARTMENU, SW_HIDE, 0, 0);
535 SendDlgItemMessage(hwnd, IDC_DESKTOP, SW_HIDE, 0, 0);
538 SendDlgItemMessage(hwnd, IDC_STARTMENU, BM_SETCHECK, config_createStartmenu, 0);
539 SendDlgItemMessage(hwnd, IDC_DESKTOP, BM_SETCHECK, config_createDesktop, 0);
541 if(message == WM_COMMAND) {
542 if((wParam&0xffff) == IDC_STARTMENU) {
543 config_createStartmenu = SendDlgItemMessage(hwnd, IDC_STARTMENU, BM_GETCHECK, 0, 0);
544 config_createStartmenu^=1;
545 SendDlgItemMessage(hwnd, IDC_STARTMENU, BM_SETCHECK, config_createStartmenu, 0);
548 if((wParam&0xffff) == IDC_DESKTOP) {
549 config_createDesktop = SendDlgItemMessage(hwnd, IDC_DESKTOP, BM_GETCHECK, 0, 0);
550 config_createDesktop^=1;
551 SendDlgItemMessage(hwnd, IDC_DESKTOP, BM_SETCHECK, config_createDesktop, 0);
556 if(message == WM_NOTIFY && (((LPNMHDR)lParam)->code == PSN_WIZFINISH)) {
557 if(!addRegistryEntries(install_path)) {
558 MessageBox(0, "Couldn't create Registry Entries", INSTALLER_NAME, MB_OK|MB_ICONERROR);
562 char mypath[MAX_PATH];
563 path_startmenu[0] = 0;
565 if(config_forAllUsers) {
566 f_SHGetSpecialFolderPath(NULL, path_desktop, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
567 f_SHGetSpecialFolderPath(NULL, path_startmenu, CSIDL_COMMON_PROGRAMS, 0);
569 /* get local program/desktop directory- this is both for forAllUsers=0 as well
570 as a fallback if the above didn't return any paths */
571 if(!path_startmenu[0]) {
572 f_SHGetSpecialFolderPath(NULL, path_startmenu, CSIDL_PROGRAMS, 0);
574 if(!path_desktop[0]) {
575 f_SHGetSpecialFolderPath(NULL, path_desktop, CSIDL_DESKTOPDIRECTORY, 0);
578 char*uninstall_path = concatPaths(install_path, "uninstall.exe");
580 if(config_createLinks) {
581 if(config_createDesktop && path_desktop[0]) {
582 char* linkName = concatPaths(path_desktop, "pdf2swf.lnk");
583 printf("Creating desktop link %s -> %s\n", linkName, pdf2swf_path);
584 if(!CreateShortcut(pdf2swf_path, "pdf2swf", linkName, 0, 0, 0, install_path)) {
585 MessageBox(0, "Couldn't create desktop shortcut", INSTALLER_NAME, MB_OK);
589 if(config_createStartmenu && path_startmenu[0]) {
590 char* group = concatPaths(path_startmenu, "pdf2swf");
591 CreateDirectory(group, 0);
592 char* linkName = concatPaths(group, "pdf2swf.lnk");
593 if(!CreateShortcut(pdf2swf_path, "pdf2swf", concatPaths(group, "pdf2swf.lnk"), 0, 0, 0, install_path) ||
594 !CreateShortcut(uninstall_path, "uninstall", concatPaths(group, "uninstall.lnk"), 0, 0, 0, install_path)) {
595 MessageBox(0, "Couldn't create start menu entry", INSTALLER_NAME, MB_OK);
600 printf("not creating desktop/startmenu links\n");
603 char*uninstall_ini = concatPaths(install_path, "uninstall.ini");
604 addFile(uninstall_ini);
605 writeFileList(installedFiles, uninstall_ini);
607 return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_FINISH);
613 void findfiles(char*path, int*pos, char*data, int len, char del)
615 WIN32_FIND_DATA findFileData;
616 HANDLE hFind = FindFirstFile(concatPaths(path, "*"), &findFileData);
617 if(hFind == INVALID_HANDLE_VALUE)
620 if(findFileData.cFileName[0] == '.' &&
621 (findFileData.cFileName[0] == '.' || findFileData.cFileName == '\0'))
623 char*f = concatPaths(path, findFileData.cFileName);
624 if(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
625 findfiles(f, pos, data, len, del);
632 /* don't list the uninstaller as file- it's going to be removed *after*
633 everything else is done */
634 char*uninstaller="uninstall.exe";
635 int ll = strlen(uninstaller);
637 if(!strcasecmp(&f[l-ll],uninstaller)) {
644 memcpy(&data[*pos], f, l);(*pos)+=l;
645 data[(*pos)++] = '\r';
646 data[(*pos)++] = '\n';
656 } while(FindNextFile(hFind, &findFileData));
660 static char*extrafiles = 0;
662 BOOL CALLBACK PropertySheetFunc5(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
663 HWND dialog = GetParent(hwnd);
664 if(message == WM_INITDIALOG) {
665 SetDlgItemText(hwnd, IDC_INFO, "Ready to deinstall");
667 if(message == WM_NOTIFY && (((LPNMHDR)lParam)->code == PSN_WIZNEXT)) {
669 filelist_t* list = readFileList("uninstall.ini");
671 list = readFileList(concatPaths(install_path, "uninstall.ini"));
673 //Don't abort. If there's still something there, it'll be catched by the "extra files"
674 //functionality later
675 //MessageBox(0, "Couldn't determine installed files list- did you run uninstall twice?", INSTALLER_NAME, MB_OK);
679 filelist_t* l = list;
681 while(l) {num++;l=l->next;}
683 PropSheet_SetWizButtons(dialog, 0);
684 SendMessage(dialog, PSM_CANCELTOCLOSE, 0, 0);
685 SetDlgItemText(hwnd, IDC_TITLE, "Uninstalling files...");
686 SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0, (LPARAM)MAKELONG(0,num));
690 SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS, num, 0);
692 DeleteFile(l->filename);
693 else if(l->type=='D')
694 RemoveDirectory(l->filename);
695 else if(l->type=='I')
696 /* skip- we will remove ourselves later */;
701 findfiles(install_path, &len, 0, 0, 0);
703 extrafiles = malloc(len);
705 findfiles(install_path, &pos, extrafiles, len, 0);
707 PropSheet_RemovePage(dialog, 1, 0);
711 return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_BACK|PSWIZB_NEXT);
714 BOOL CALLBACK PropertySheetFunc6(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
715 if(message == WM_INITDIALOG) {
716 SendDlgItemMessage(hwnd, IDC_DELETEEXTRA, BM_SETCHECK, config_deleteextra, 0);
718 SetDlgItemText(hwnd, IDC_FILELIST, extrafiles);
721 if(message == WM_COMMAND) {
722 if((wParam&0xffff) == IDC_DELETEEXTRA) {
723 config_deleteextra = SendDlgItemMessage(hwnd, IDC_DELETEEXTRA, BM_GETCHECK, 0, 0);
724 config_deleteextra ^=1;
725 SendDlgItemMessage(hwnd, IDC_DELETEEXTRA, BM_SETCHECK, config_deleteextra, 0);
729 if(message == WM_NOTIFY && (((LPNMHDR)lParam)->code == PSN_WIZNEXT)) {
730 if(config_deleteextra) {
732 findfiles(install_path, &pos, 0, 0, 1);
735 return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_NEXT);
738 BOOL CALLBACK PropertySheetFunc7(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
739 if(message == WM_INITDIALOG) {
742 return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_FINISH);
746 #ifndef PSP_HIDEHEADER
747 #define PSP_HIDEHEADER 2048
750 typedef struct _wizardpage {
755 void runPropertySheet(HWND parent)
757 PROPSHEETHEADER sheet;
759 wizardpage_t wpage[5] = {
761 {PropertySheetFunc1, IDD_LICENSE},
762 {PropertySheetFunc2, IDD_INSTALLDIR},
763 {PropertySheetFunc3, IDD_PROGRESS},
764 {PropertySheetFunc4, IDD_FINISH},
766 {PropertySheetFunc5, IDD_SURE},
767 {PropertySheetFunc6, IDD_EXTRAFILES},
768 {PropertySheetFunc7, IDD_DEINSTALLED},
771 int num = sizeof(wpage)/sizeof(wpage[0]);
772 HPROPSHEETPAGE pages[num];
776 memset(&page, 0, sizeof(PROPSHEETPAGE));
777 page.dwSize = sizeof(PROPSHEETPAGE);
778 page.dwFlags = PSP_DEFAULT|PSP_HIDEHEADER;
780 page.pfnDlgProc = wpage[t].function;
781 page.pszTemplate = MAKEINTRESOURCE(wpage[t].resource);
782 pages[t] = CreatePropertySheetPage(&page);
785 memset(&sheet, 0, sizeof(PROPSHEETHEADER));
786 sheet.dwSize = sizeof(PROPSHEETHEADER);
787 sheet.hInstance = me;
788 sheet.hwndParent = parent;
789 sheet.phpage = pages;
790 sheet.dwFlags = PSH_WIZARD;
792 PropertySheet(&sheet);
797 static void remove_self()
799 char exename[MAX_PATH];
800 char batname[MAX_PATH];
803 GetModuleFileName(NULL, exename, sizeof(exename));
804 sprintf(batname, "%s.bat", exename);
805 fp = fopen(batname, "w");
806 fprintf(fp, ":Repeat\n");
807 fprintf(fp, "del \"%s\"\n", exename);
808 fprintf(fp, "if exist \"%s\" goto Repeat\n", exename);
809 fprintf(fp, "del \"%s\"\n", batname);
813 PROCESS_INFORMATION pi;
814 memset(&si, 0, sizeof(si));
815 si.dwFlags = STARTF_USESHOWWINDOW;
816 si.wShowWindow = SW_HIDE;
818 if (CreateProcess(NULL, batname, NULL, NULL, FALSE,
819 CREATE_SUSPENDED | IDLE_PRIORITY_CLASS,
820 NULL, "\\", &si, &pi)) {
821 SetThreadPriority(pi.hThread, THREAD_PRIORITY_IDLE);
822 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
823 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
824 CloseHandle(pi.hProcess);
825 ResumeThread(pi.hThread);
826 CloseHandle(pi.hThread);
831 int WINAPI WinMain(HINSTANCE _me,HINSTANCE hPrevInst,LPSTR lpszArgs, int nWinMode)
834 sprintf(registry_path, "Software\\%s\\%s\\InstallPath", SOFTWARE_DOMAIN, SOFTWARE_NAME);
837 logo = LoadBitmap(me, "LOGO");
839 install_path = getRegistryEntry(registry_path);
840 if(!install_path || !install_path[0]) {
841 MessageBox(0, "Couldn't find software installation directory- did you run the deinstallation twice?", INSTALLER_NAME, MB_OK);
846 InitCommonControls();
848 runPropertySheet(background);
854 int WINAPI WinMain(HINSTANCE _me,HINSTANCE hPrevInst,LPSTR lpszArgs, int nWinMode)
857 WNDCLASSEX wcl_background;
858 wcl_background.hInstance = me;
859 wcl_background.lpfnWndProc = WindowFunc;
860 wcl_background.lpszClassName= INSTALLER_NAME;
861 wcl_background.style = CS_HREDRAW | CS_VREDRAW;
862 wcl_background.hIcon = LoadIcon(NULL, IDI_APPLICATION);
863 wcl_background.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
864 wcl_background.hCursor = LoadCursor(NULL, IDC_ARROW);
865 wcl_background.lpszMenuName = NULL; //no menu
866 wcl_background.cbClsExtra = 0;
867 wcl_background.cbWndExtra = 0;
868 wcl_background.hbrBackground= CreateSolidBrush(RGB(0, 0, 128));
869 wcl_background.cbSize = sizeof(WNDCLASSEX);
871 sprintf(registry_path, "Software\\%s\\%s\\InstallPath", SOFTWARE_DOMAIN, SOFTWARE_NAME);
873 HINSTANCE shell32 = LoadLibrary("shell32.dll");
875 MessageBox(0, "Could not load shell32.dll", INSTALLER_NAME, MB_OK);
878 f_SHGetSpecialFolderPath = (HRESULT (WINAPI*)(HWND,LPTSTR,int,BOOL))GetProcAddress(shell32, "SHGetSpecialFolderPathA");
879 if(!f_SHGetSpecialFolderPath) {
880 MessageBox(0, "Could not load shell32.dll", INSTALLER_NAME, MB_OK);
884 HRESULT coret = CoInitialize(NULL);
886 MessageBox(0, "Could not initialize COM interface", INSTALLER_NAME, MB_OK);
890 path_programfiles[0] = 0;
891 f_SHGetSpecialFolderPath(NULL, path_programfiles, CSIDL_PROGRAM_FILES, 0);
893 if(!RegisterClassEx(&wcl_background)) {
894 MessageBox(0, "Could not register window background class", INSTALLER_NAME, MB_OK);
898 HWND background = CreateWindow(wcl_background.lpszClassName, INSTALLER_NAME,
900 GetSystemMetrics(SM_CXFULLSCREEN),
901 GetSystemMetrics(SM_CYFULLSCREEN),
903 (void*)"background");
906 MessageBox(0, "Could not create installation background window", INSTALLER_NAME, MB_OK);
910 ShowWindow(background, SW_SHOWMAXIMIZED);
911 SetForegroundWindow(background);
912 UpdateWindow(background);
914 logo = LoadBitmap(me, "LOGO");
916 install_path = getRegistryEntry(registry_path);
917 if(!install_path || !install_path[0]) {
918 if(path_programfiles[0]) {
919 install_path = concatPaths(path_programfiles, SOFTWARE_NAME);
921 install_path = concatPaths("c:\\", SOFTWARE_NAME);
925 InitCommonControls();
927 runPropertySheet(background);