- if(hwnd == 0) {
- return DefWindowProc(hwnd, message, wParam, lParam);
- } else if(hwnd == wnd_progress) {
- static struct progress_data data;
-
- switch(message)
- {
- case USER_SETMESSAGE:
- data.text3 = (char*)wParam;
- SendMessage(data.wnd_text3, WM_SETTEXT, 0, (LPARAM)data.text3);
- return 0;
- case WM_CREATE: {
- memset(&data, 0, sizeof(data));
- data.text1 = "Installing SWFTools";
- data.text2 = (char*)malloc(strlen(install_path)+250);
- data.text3 = "";
- sprintf(data.text2, "to %s", install_path);
- data.pos = 0;
- data.step = 1;
-
- CREATESTRUCT*cs = ((LPCREATESTRUCT)lParam);
- RECT rc;
- GetClientRect (hwnd, &rc);
- data.width = rc.right - rc.left;
- data.height = rc.bottom - rc.top;
- data.bar_width = cs->cx - 17;
- data.bar_height= 16;
- data.bar_posx = (data.width -data.bar_width)/2;
- data.bar_posy = 56;
- data.range = 50;
-
- data.hwndButton = CreateWindow (
- PROGRESS_CLASS,
- "Progress",
- WS_CHILD | WS_VISIBLE,
- data.bar_posx,
- data.bar_posy,
- data.bar_width,
- data.bar_height,
- hwnd, /* Parent */
- 0,
- cs->hInstance,
- NULL
- );
-
- SendMessage(data.hwndButton, PBM_SETRANGE, 0, (LPARAM) MAKELONG(0,data.range));
- SendMessage(data.hwndButton, PBM_SETSTEP, (WPARAM) data.step, 0);
- return 0;
- }
- case PBM_STEPIT: {
- if(data.pos+data.step < data.range) {
- data.pos += data.step;
- SendMessage(data.hwndButton, PBM_STEPIT, wParam, lParam);
+ if(!ret1)
+ ret1 = RegSetValue(hkey1, NULL, REG_SZ, value, strlen(value)+1);
+ if(!ret2)
+ ret2 = RegSetValue(hkey2, NULL, REG_SZ, value, strlen(value)+1);
+ if(ret1 && ret2) {
+ fprintf(stderr, "registry: SetValue %s failed\n", key);
+ return 0;
+ }
+ return 1;
+}
+
+
+static char* getRegistryEntry(char*path)
+{
+ int res = 0;
+ HKEY key;
+ long rc;
+ long size = 0;
+ DWORD type;
+ char*buf;
+ rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0, KEY_ALL_ACCESS/* KEY_READ*/, &key);
+ if (rc != ERROR_SUCCESS) {
+ fprintf(stderr, "RegOpenKeyEx failed\n");
+ return 0;
+ }
+ rc = RegQueryValueEx(key, NULL, 0, 0, 0, (LPDWORD)&size) ;
+ if(rc != ERROR_SUCCESS) {
+ fprintf(stderr, "RegQueryValueEx(1) failed: %d\n", rc);
+ return 0;
+ }
+ buf = (char*)malloc(size+1);
+ rc = RegQueryValueEx(key, NULL, 0, &type, (BYTE*)buf, (LPDWORD)&size);
+ if(rc != ERROR_SUCCESS) {
+ fprintf(stderr, "RegQueryValueEx(2) failed: %d\n", rc);
+ return 0;
+ }
+ if(type == REG_SZ || type == REG_EXPAND_SZ) {
+ while(size && buf[size-1] == '\0')
+ --size;
+ buf[size] = 0;
+ /* TODO: convert */
+ return buf;
+ } else if(type == REG_BINARY) {
+ return buf;
+ }
+}
+
+static int has_full_access = 0;
+static char hasFullAccess()
+{
+ /* find out whether we can write keys in HKEY_LOCAL_MACHINE */
+ HKEY hKey;
+ int ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall", 0,
+ KEY_CREATE_SUB_KEY, &hKey);
+ if(!ret) {
+ RegCloseKey(hKey);
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+void processMessages()
+{
+ MSG msg;
+ while(PeekMessage(&msg,NULL,0,0,0))
+ {
+ GetMessage(&msg, NULL, 0, 0);
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+}
+
+int addRegistryEntries(char*install_dir)
+{
+ int ret;
+ ret = setRegistryEntry(registry_path, install_dir);
+ if(!ret) return 0;
+ return 1;
+}
+
+int CreateShortcut(char*path, char*description, char*filename, char*arguments, int iconindex, char*iconpath, char*workdir)
+{
+ printf("Creating %s -> %s\n", filename, path);
+ WCHAR wszFilename[MAX_PATH];
+ IShellLink *ps1 = NULL;
+ IPersistFile *pPf = NULL;
+ HRESULT hr;
+ hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (void*)&ps1);
+ if(FAILED(hr)) return 0;
+ hr = ps1->lpVtbl->QueryInterface(ps1, &IID_IPersistFile, (void **)&pPf);
+ if(FAILED(hr)) return 0;
+ hr = ps1->lpVtbl->SetPath(ps1, path);
+ if(FAILED(hr)) return 0;
+ hr = ps1->lpVtbl->SetDescription(ps1, description);
+
+ if (arguments) {
+ hr = ps1->lpVtbl->SetArguments(ps1, arguments);
+ if(FAILED(hr)) return 0;
+ }
+ if (iconpath) {
+ hr = ps1->lpVtbl->SetIconLocation(ps1, iconpath, iconindex);
+ if (FAILED(hr)) return 0;
+ }
+ if (workdir) {
+ hr = ps1->lpVtbl->SetWorkingDirectory(ps1, workdir);
+ if (FAILED(hr)) return 0;
+ }
+ MultiByteToWideChar(CP_ACP, 0, filename, -1, wszFilename, MAX_PATH);
+ hr = pPf->lpVtbl->Save(pPf, wszFilename, TRUE);
+ if(FAILED(hr)) {
+ return 0;
+ }
+ pPf->lpVtbl->Release(pPf);
+ ps1->lpVtbl->Release(ps1);
+ addFile(filename);
+ return 1;
+}
+
+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;
+ }