+static int CreateURL(const char*url, const char*path)
+{
+ FILE*fi = fopen(path, "wb");
+ if(!fi)
+ return 0;
+ fprintf(fi, "[InternetShortcut]\r\n");
+ fprintf(fi, "URL=http://localhost:8081/\r\n");
+ fclose(fi);
+ addFile(path);
+ return 1;
+}
+
+
+BOOL CALLBACK PropertySheetFuncCommon(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, int buttons)
+{
+ LPNMHDR lpnm;
+
+ HWND dialog = GetParent(hwnd);
+
+ if(message == WM_INITDIALOG) {
+ if(logo)
+ SendDlgItemMessage(hwnd, IDC_BITMAP, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)logo);
+
+ RECT rc;
+ GetWindowRect(dialog, &rc);
+ int width = rc.right - rc.left;
+ int height = rc.bottom - rc.top;
+ MoveWindow(dialog, (GetSystemMetrics(SM_CXSCREEN) - width)/2, (GetSystemMetrics(SM_CYSCREEN) - height)/2, width, height, FALSE);
+ return FALSE;
+ }
+
+ if(message == WM_NOTIFY && (((LPNMHDR)lParam)->code == PSN_SETACTIVE)) {
+ PropSheet_SetWizButtons(dialog, buttons);
+ return FALSE;
+ }
+ return FALSE;
+}
+
+#ifndef DEINSTALL
+BOOL CALLBACK PropertySheetFunc1(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
+ if(message == WM_INITDIALOG) {
+ SetDlgItemText(hwnd, IDC_LICENSE, license_text);
+ }
+ return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_NEXT);
+}
+BOOL CALLBACK PropertySheetFunc2(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
+ if(message == WM_INITDIALOG) {
+ SetDlgItemText(hwnd, IDC_INSTALL_PATH, install_path);
+
+ SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, config_forAllUsers, 0);
+ SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, config_forAllUsers^1, 0);
+ }
+ if(message == WM_COMMAND) {
+ if((wParam&0xffff) == IDC_BROWSE) {
+ BROWSEINFOA browse;
+ memset(&browse, 0, sizeof(browse));
+ browse.ulFlags = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_USENEWUI;// | BIF_RETURNONLYFSDIRS; //BIF_VALIDATE
+ browse.pszDisplayName = (CHAR*)malloc(MAX_PATH);
+ memset(browse.pszDisplayName, 0, MAX_PATH);
+ browse.lpszTitle = "Select installation directory";
+ browse.pidlRoot = SHBrowseForFolder(&browse);
+ if(browse.pszDisplayName) {
+ if(SHGetPathFromIDList(browse.pidlRoot, browse.pszDisplayName)) {
+ install_path = browse.pszDisplayName;
+ int l = strlen(install_path);
+ while(l && install_path[l-1]=='\\') {
+ install_path[--l]=0;
+ }
+ }
+ }
+ SendDlgItemMessage(hwnd, IDC_INSTALL_PATH, WM_SETTEXT, 0, (LPARAM)install_path);
+ return 0;
+
+ }
+ else if((wParam&0xffff) == IDC_ALLUSERS) {
+ config_forAllUsers = 1;
+ SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, config_forAllUsers, 0);
+ SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, config_forAllUsers^1, 0);
+ }
+ else if((wParam&0xffff) == IDC_CURRENTUSER) {
+ config_forAllUsers = 0;
+ SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, config_forAllUsers, 0);
+ SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, config_forAllUsers^1, 0);
+ }
+ else if((wParam&0xffff) == IDC_INSTALL_PATH) {
+ SendDlgItemMessage(hwnd, IDC_INSTALL_PATH, WM_GETTEXT, sizeof(pathBuf), (LPARAM)&(pathBuf[0]));
+ if(pathBuf[0]) {
+ install_path = pathBuf;
+ int l = strlen(install_path);
+ while(l && install_path[l-1]=='\\') {
+ install_path[--l]=0;
+ }
+ }
+ return 0;
+ }
+ }
+ if(message == WM_NOTIFY && (((LPNMHDR)lParam)->code == PSN_SETACTIVE)) {
+ if(!elevated && !has_full_access) {
+ OSVERSIONINFO winverinfo;
+ memset(&winverinfo, 0, sizeof(OSVERSIONINFO));
+ winverinfo.dwOSVersionInfoSize = sizeof(winverinfo);
+ if (GetVersionEx(&winverinfo) && winverinfo.dwMajorVersion >= 5) {
+ /* we're on Vista, were asked to install for all users, but don't have
+ priviledges to do so. Ask to spawn the process elevated. */
+ char exename[MAX_PATH];
+ GetModuleFileName(NULL, exename, sizeof(exename));
+ if((int)ShellExecute(0, "runas", exename, "elevated", NULL, SW_SHOWNORMAL)>32) {
+ /* that worked- the second process will do the work */
+ exit(0);
+ }
+ }
+ }
+ }
+ return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_BACK|PSWIZB_NEXT);
+}
+HWND statuswnd;
+static int progress_pos = 0;
+
+void PropertyArchiveError(char*text)
+{
+ while(1) {
+ int ret = MessageBox(0, text, "Error", MB_RETRYCANCEL|MB_ICONERROR);
+ if(ret==IDRETRY) continue;
+ else break;
+ }
+}
+
+void PropertyArchive_NewFile(char*filename)
+{
+ addFile(filename);
+ processMessages();
+}
+void PropertyArchive_NewDirectory(char*filename)
+{
+ addDir(filename);
+ processMessages();
+}
+
+static int lastlen = 0;
+void PropertyArchiveStatus(int pos, int len)
+{
+ if(len!=lastlen) {
+ SendDlgItemMessage(statuswnd, IDC_PROGRESS, PBM_SETRANGE, 0, (LPARAM)MAKELONG(0,len));
+ lastlen = len;
+ }
+ SendDlgItemMessage(statuswnd, IDC_PROGRESS, PBM_SETPOS, pos, 0);
+ processMessages();
+ Sleep(30);
+}
+void PropertyArchiveMessage(char*text)
+{
+ if(text && text[0]=='[') {
+ return;
+ }
+ SetDlgItemText(statuswnd, IDC_INFO, strdup(text));
+ processMessages();
+}
+
+void print_space(char*dest, char*msg, ULONGLONG size)
+{
+ if(size < 1024)
+ sprintf(dest, "%s%d Bytes", msg, size);
+ else if(size < 1048576l)
+ sprintf(dest, "%s%.2f Kb", msg, size/1024.0);
+ else if(size < 1073741824l)
+ sprintf(dest, "%s%.2f Mb", msg, size/1048576.0);
+ else if(size < 1099511627776ll)
+ sprintf(dest, "%s%.2f Gb", msg, size/1073741824.0);
+ else
+ sprintf(dest, "%s%.2f Tb", msg, size/1125899906842624.0);
+}
+
+BOOL CALLBACK PropertySheetFunc3(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
+ HWND dialog = GetParent(hwnd);
+ if(message == WM_INITDIALOG) {
+ SetDlgItemText(hwnd, IDC_INFO, "Ready to install");
+
+ char buf[256];
+ print_space(buf, "Space required: ", crn_decompressed_size);
+ SetDlgItemText(hwnd, IDC_SPACE1, buf);
+ ULARGE_INTEGER available,total,totalfree;
+ available.QuadPart=0;
+ total.QuadPart=0;
+ totalfree.QuadPart=0;
+ if(GetDiskFreeSpaceEx(install_path, &available, &total, &totalfree)) {
+ print_space(buf, "Space available: ", available.QuadPart);
+ } else {
+ sprintf(buf, "Space available: [Error %d]", GetLastError());
+ if((GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_PATH_NOT_FOUND)
+ && install_path[0] && install_path[1]==':') {
+ /* installation directory does not yet exist */
+ char path[3]={'c',':',0};
+ path[0] = install_path[0];
+ if(GetDiskFreeSpaceEx(path, &available, &total, &totalfree)) {
+ print_space(buf, "Space available: ", available.QuadPart);
+ }
+ }
+ }
+ SetDlgItemText(hwnd, IDC_SPACE2, buf);
+ }
+ if(message == WM_NOTIFY && (((LPNMHDR)lParam)->code == PSN_WIZNEXT)) {
+ SetDlgItemText(hwnd, IDC_SPACE1, "");
+ SetDlgItemText(hwnd, IDC_SPACE2, "");
+ PropSheet_SetWizButtons(dialog, 0);
+ SendMessage(dialog, PSM_CANCELTOCLOSE, 0, 0); //makes wine display a warning
+ SetDlgItemText(hwnd, IDC_TITLE, "Installing files...");
+ statuswnd = hwnd;
+ status_t status;
+ status.status = PropertyArchiveStatus;
+ status.message = PropertyArchiveMessage;
+ status.error = PropertyArchiveError;
+ status.new_file = PropertyArchive_NewFile;
+ status.new_directory = PropertyArchive_NewDirectory;
+ int success = unpack_archive(crndata, crndata_len, install_path, &status);
+ memset(&status, 0, sizeof(status_t));
+ if(!success) {
+ MessageBox(0, "Couldn't extract all installation files", INSTALLER_NAME, MB_OK|MB_ICONERROR);
+ do_abort=1;
+ exit(1);
+ }
+ return 0;
+ }
+ return PropertySheetFuncCommon(hwnd, message, wParam, lParam, PSWIZB_BACK|PSWIZB_NEXT);
+}