From: kramm Date: Thu, 19 Jun 2008 20:29:28 +0000 (+0000) Subject: added Vista elevation code X-Git-Tag: buttons-working~122 X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=commitdiff_plain;h=e0ec3fa71d079e7a289c624bf8aa9fd1957d2f5a added Vista elevation code --- diff --git a/installer/installer.c b/installer/installer.c index 439fc2f..05017f4 100644 --- a/installer/installer.c +++ b/installer/installer.c @@ -48,6 +48,8 @@ static char* pdf2swf_path; static char registry_path[1024]; +static char elevated = 0; + static char*install_path = "c:\\swftools\\"; #define SOFTWARE_DOMAIN "quiss.org" #define SOFTWARE_NAME "SWFTools" @@ -254,6 +256,21 @@ static char* getRegistryEntry(char*path) } } +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; @@ -360,7 +377,6 @@ BOOL CALLBACK PropertySheetFunc2(HWND hwnd, UINT message, WPARAM wParam, LPARAM if(message == WM_INITDIALOG) { SetDlgItemText(hwnd, IDC_INSTALL_PATH, install_path); - config_forAllUsers = 0; SendDlgItemMessage(hwnd, IDC_ALLUSERS, BM_SETCHECK, config_forAllUsers, 0); SendDlgItemMessage(hwnd, IDC_CURRENTUSER, BM_SETCHECK, config_forAllUsers^1, 0); } @@ -408,6 +424,23 @@ BOOL CALLBACK PropertySheetFunc2(HWND hwnd, UINT message, WPARAM wParam, LPARAM return 0; } } + if(message == WM_NOTIFY && (((LPNMHDR)lParam)->code == PSN_SETACTIVE)) { + if(!elevated && !has_full_access && config_forAllUsers) { + 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; @@ -483,7 +516,8 @@ BOOL CALLBACK PropertySheetFunc3(HWND hwnd, UINT message, WPARAM wParam, LPARAM print_space(buf, "Space available: ", available.QuadPart); } else { sprintf(buf, "Space available: [Error %d]", GetLastError()); - if(GetLastError() == ERROR_FILE_NOT_FOUND && install_path[0] && install_path[1]==':') { + 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]; @@ -589,6 +623,7 @@ BOOL CALLBACK PropertySheetFunc4(HWND hwnd, UINT message, WPARAM wParam, LPARAM if(config_createStartmenu && path_startmenu[0]) { char* group = concatPaths(path_startmenu, "pdf2swf"); CreateDirectory(group, 0); + addDir(group); char* linkName = concatPaths(group, "pdf2swf.lnk"); if(!CreateShortcut(pdf2swf_path, "pdf2swf", concatPaths(group, "pdf2swf.lnk"), 0, 0, 0, install_path) || !CreateShortcut(uninstall_path, "uninstall", concatPaths(group, "uninstall.lnk"), 0, 0, 0, install_path)) { @@ -623,9 +658,9 @@ void findfiles(char*path, int*pos, char*data, int len, char del) char*f = concatPaths(path, findFileData.cFileName); if(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { findfiles(f, pos, data, len, del); - if(del) { - RemoveDirectory(f); - } + /* always try to remove directories- if they are empty, this + will work, and they won't prevent superdirectory deletion later */ + RemoveDirectory(f); } else { int l = strlen(f); @@ -662,7 +697,7 @@ static char*extrafiles = 0; BOOL CALLBACK PropertySheetFunc5(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HWND dialog = GetParent(hwnd); if(message == WM_INITDIALOG) { - SetDlgItemText(hwnd, IDC_INFO, "Ready to deinstall"); + SetDlgItemText(hwnd, IDC_INFO, "Ready to uninstall"); } if(message == WM_NOTIFY && (((LPNMHDR)lParam)->code == PSN_WIZNEXT)) { @@ -768,7 +803,22 @@ void runPropertySheet(HWND parent) {PropertySheetFunc7, IDD_DEINSTALLED}, #endif }; + int num = sizeof(wpage)/sizeof(wpage[0]); + +#ifndef DEINSTALL + if(elevated) { + /* remove license. + TODO: remove installdir querying, too (pass installdir + to second process) */ + int t; + for(t=1;t