bool DoSelect(HWND hWnd, const TCHAR* title, const TCHAR* folder, TCHAR* output) { TCHAR buf[MAX_PATH + 4]; BROWSEINFO bi; bi.hwndOwner = hWnd; bi.pidlRoot = NULL; bi.pszDisplayName = buf; bi.lpszTitle = title; bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_VALIDATE | BIF_EDITBOX | BIF_NEWDIALOGSTYLE; // | BIF_STATUSTEXT; bi.lpfn = BrowseCallbackProc; bi.lParam = reinterpret_cast<LPARAM>(const_cast<TCHAR*>(folder)); bi.iImage = 0; ITEMIDLIST* item_list= ::SHBrowseForFolder(&bi); if (item_list == NULL) return false; *output = 0; ::SHGetPathFromIDList(item_list, output); IMallocPtr malloc; if (::SHGetMalloc(&malloc) == NOERROR) malloc->Free(item_list); return true; }
bool CreateLinkToExifPro(const TCHAR* exif_pro_path, const TCHAR* description, const TCHAR* link_name, int special_folder_id) { ITEMIDLIST* idl= 0; if (::SHGetSpecialFolderLocation(0, special_folder_id, &idl) == 0) { TCHAR path[2 * MAX_PATH]; ::SHGetPathFromIDList(idl, path); IMallocPtr malloc; if (::SHGetMalloc(&malloc) == 0) malloc->Free(idl); TCHAR link[2 * MAX_PATH]; AppendFileName(path, link_name, link); if (CreateLink(exif_pro_path, link, description) != S_OK) return false; TCHAR key[MAX_PATH]; wsprintf(key, L"UninstLink_%d", special_folder_id); CreateUninstallLinkInfo(link, key); return true; } return false; }
void fsGetSystemAppDataFolder (LPSTR pszRes) { LPITEMIDLIST pidl = NULL; if (SUCCEEDED (SHGetSpecialFolderLocation (NULL, CSIDL_APPDATA, &pidl))) { SHGetPathFromIDList (pidl, pszRes); if (pszRes [lstrlen (pszRes)-1] != '\\') lstrcat (pszRes, "\\"); IMallocPtr spMalloc; SHGetMalloc (&spMalloc); spMalloc->Free (pidl); } else { GetWindowsDirectory (pszRes, MAX_PATH); if (pszRes [3] != 0) lstrcat (pszRes, "\\"); lstrcat (pszRes, "Application Data\\"); } }
void fsOpNetIntegrationMgr::Initialize() { CRegKey key; CString strOpKey = "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Opera.exe"; CString strNetKey1 = "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Netscp.exe"; CString strNetKey2 = "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Netscp6.exe"; CString strNetKey3 = "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Netscape.exe"; CString strNetKey4 = "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\navigator.exe"; CString strFfKey = "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Firefox.exe"; CString strMozSKey1 = "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\SeaMonkey.exe"; CString strMozSKey2 = "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\mozilla.exe"; if (ERROR_SUCCESS == key.Open (HKEY_CURRENT_USER, "Software\\Opera Software", KEY_READ)) { char szPath [MY_MAX_PATH] = ""; DWORD dw = sizeof (szPath); if (ERROR_SUCCESS == key.QueryValue (szPath, "Plugin Path", &dw)) { if (*szPath) { m_strOpPath = szPath; if (m_strOpPath [m_strOpPath.GetLength () - 1] != '\\' || m_strOpPath [m_strOpPath.GetLength () - 1] != '/') m_strOpPath += '\\'; } } } if (m_strOpPath == "" && ERROR_SUCCESS == key.Open (HKEY_CLASSES_ROOT, "Applications\\Opera.exe\\shell\\open\\command", KEY_READ)) { char sz [MY_MAX_PATH] = ""; DWORD dw = sizeof (sz); key.QueryValue (sz, NULL, &dw); vmsCommandLine cl; cl.fromString (sz, true); if (cl.getExe () != NULL && *cl.getExe () != 0) { *sz = 0; fsGetPath (cl.getExe (), sz); if (*sz) { m_strOpPath = sz; if (m_strOpPath [m_strOpPath.GetLength () - 1] != '\\' || m_strOpPath [m_strOpPath.GetLength () - 1] != '/') m_strOpPath += '\\'; if (GetFileAttributes (m_strOpPath + "program\\plugins") != DWORD (-1)) m_strOpPath += "program\\plugins\\"; else m_strOpPath += "Plugins\\"; } } } if (m_strOpPath == "" && ERROR_SUCCESS == key.Open (HKEY_LOCAL_MACHINE, strOpKey, KEY_READ)) { char szPath [MY_MAX_PATH] = ""; DWORD dw = sizeof (szPath); key.QueryValue (szPath, "Path", &dw); if (*szPath) { m_strOpPath = szPath; if (m_strOpPath [m_strOpPath.GetLength () - 1] != '\\' || m_strOpPath [m_strOpPath.GetLength () - 1] != '/') m_strOpPath += '\\'; if (GetFileAttributes (m_strOpPath + "program\\plugins") != DWORD (-1)) m_strOpPath += "program\\plugins\\"; else m_strOpPath += "Plugins\\"; } key.Close (); } if (m_strOpPath == "") { m_strOpPath = _App.Monitor_OperaPDInstalledTo (); } if (ERROR_SUCCESS == key.Open (HKEY_LOCAL_MACHINE, strNetKey1, KEY_READ) || ERROR_SUCCESS == key.Open (HKEY_LOCAL_MACHINE, strNetKey2, KEY_READ) || ERROR_SUCCESS == key.Open (HKEY_LOCAL_MACHINE, strNetKey3, KEY_READ) || ERROR_SUCCESS == key.Open (HKEY_LOCAL_MACHINE, strNetKey4, KEY_READ)) { char szPath [MY_MAX_PATH] = ""; DWORD dw = sizeof (szPath); key.QueryValue (szPath, "Path", &dw); if (*szPath) { m_strNetPath = szPath; if (m_strNetPath [m_strNetPath.GetLength () - 1] != '\\' || m_strNetPath [m_strNetPath.GetLength () - 1] != '/') m_strNetPath += '\\'; m_strNetPath += "Plugins\\"; } key.Close (); if (m_strNetPath == m_strOpPath) m_strNetPath = _App.Monitor_NetscapePDInstalledTo (); } else { m_strNetPath = _App.Monitor_NetscapePDInstalledTo (); } if (ERROR_SUCCESS == key.Open (HKEY_LOCAL_MACHINE, strFfKey, KEY_READ)) { char szPath [MY_MAX_PATH] = ""; DWORD dw = sizeof (szPath); key.QueryValue (szPath, "Path", &dw); if (*szPath) { m_strFfPath = szPath; if (m_strFfPath [m_strFfPath.GetLength () - 1] != '\\' || m_strFfPath [m_strFfPath.GetLength () - 1] != '/') m_strFfPath += '\\'; m_strFfPath += "Plugins\\"; } key.Close (); } else { m_strFfPath = _App.Monitor_FirefoxPDInstalledTo (); } if (ERROR_SUCCESS == key.Open (HKEY_LOCAL_MACHINE, strMozSKey1, KEY_READ) || ERROR_SUCCESS == key.Open (HKEY_LOCAL_MACHINE, strMozSKey2, KEY_READ)) { char szPath [MY_MAX_PATH] = ""; DWORD dw = sizeof (szPath); key.QueryValue (szPath, "Path", &dw); if (*szPath) { m_strMozSPath = szPath; if (m_strMozSPath [m_strMozSPath.GetLength () - 1] != '\\' || m_strMozSPath [m_strMozSPath.GetLength () - 1] != '/') m_strMozSPath += '\\'; m_strMozSPath += "Plugins\\"; } key.Close (); } else { m_strMozSPath = _App.Monitor_MozillaSuitePDInstalledTo (); } if (ERROR_SUCCESS == key.Open (HKEY_LOCAL_MACHINE, "Software\\Clients\\StartMenuInternet\\Safari.exe\\shell\\open\\command", KEY_READ)) { char szCmd [MY_MAX_PATH] = ""; DWORD dw = sizeof (szCmd); key.QueryValue (szCmd, NULL, &dw); if (*szCmd) { LPSTR psz = szCmd; if (*psz == '"') { LPSTR psz2 = strchr (psz+1, '"'); if (psz2) *psz2 = 0; psz++; } else { LPSTR psz2 = strchr (psz, ' '); if (psz2) *psz2 = 0; } LPSTR psz3 = strrchr (psz, '\\'); if (psz3) psz3 [1] = 0; strcat (psz, "Plugins\\"); m_strSafariPath = psz; } } else { m_strSafariPath = _App.Monitor_SafariPDInstalledTo (); } if (ERROR_SUCCESS == key.Open (HKEY_LOCAL_MACHINE, "Software\\Clients\\StartMenuInternet\\chrome.exe\\shell\\open\\command", KEY_READ)) { char szCmd [MY_MAX_PATH] = ""; DWORD dw = sizeof (szCmd); key.QueryValue (szCmd, NULL, &dw); if (*szCmd) { LPSTR psz = szCmd; if (*psz == '"') { LPSTR psz2 = strchr (psz+1, '"'); if (psz2) *psz2 = 0; psz++; } else { LPSTR psz2 = strchr (psz, ' '); if (psz2) *psz2 = 0; } LPSTR psz3 = strrchr (psz, '\\'); if (psz3) psz3 [1] = 0; strcat (psz, "Plugins\\"); m_strChromePath = psz; } } else { LPITEMIDLIST pidl = NULL; if (SUCCEEDED (SHGetSpecialFolderLocation (NULL, CSIDL_LOCAL_APPDATA, &pidl))) { TCHAR tszPath [MY_MAX_PATH] = _T (""); SHGetPathFromIDList (pidl, tszPath); if (tszPath [_tcslen (tszPath)-1] != '\\') _tcscat (tszPath, _T ("\\")); _tcscat (tszPath, _T ("Google\\Chrome\\Application")); if (GetFileAttributes (tszPath) != DWORD (-1)) { _tcscat (tszPath, _T ("\\Plugins\\")); m_strChromePath = tszPath; } IMallocPtr spMalloc; SHGetMalloc (&spMalloc); spMalloc->Free (pidl); } if (m_strChromePath.IsEmpty ()) m_strChromePath = _App.Monitor_ChromePDInstalledTo (); } }
INT_PTR CALLBACK DialogProc( HWND hWnd, // handle to dialog box UINT msg, // message WPARAM wParam, // first message parameter LPARAM lParam) // second message parameter { switch (msg) { case WM_INITDIALOG: { DWORD common_control_lib_version= GetDllVersion(_T("comctl32.dll")); g_update_common_ctrls = common_control_lib_version < PACKVERSION(5,80); // anything below 5.80 is worth upgrading //{ // ::MessageBox(hWnd, _T("ExifPro requires Common Controls library (ComCtl32.dll) version 4.71 or higher.\n\n") // _T("This library can be found on the Microsoft download site either as a stand-alone \n") // _T("component or part of the Internet Explorer 4.0 or later install package."), // g_INSTALLER, MB_OK | MB_ICONERROR); // ::EndDialog(hWnd, IDCANCEL); // return false; //} } if (g_update_common_ctrls) { // hide it--comctl updater needs to restart ::ShowWindow(::GetDlgItem(hWnd, IDC_RUN), SW_HIDE); } { HICON icon= ::LoadIcon(g_instance_handle, MAKEINTRESOURCE(IDR_MAINFRAME)); ::SendMessage(hWnd, WM_SETICON, ICON_SMALL, LPARAM(icon)); ::SendMessage(hWnd, WM_SETICON, ICON_BIG, LPARAM(icon)); } { HDC dc= ::GetWindowDC(hWnd); int log_pixels_y= ::GetDeviceCaps(dc, LOGPIXELSY); ::ReleaseDC(hWnd, dc); // create title font { HFONT font= static_cast<HFONT>(::GetStockObject(DEFAULT_GUI_FONT)); LOGFONT lf; ::GetObject(font, sizeof lf, &lf); lf.lfWeight = FW_BOLD; lf.lfHeight = -MulDiv(18, log_pixels_y, 96); lf.lfWidth = 0; lf.lfQuality = ANTIALIASED_QUALITY; _tcscpy_s(lf.lfFaceName, LF_FACESIZE, _T("Tahoma")); g_fntTitle = ::CreateFontIndirect(&lf); } // create license info font { HFONT font= static_cast<HFONT>(::GetStockObject(DEFAULT_GUI_FONT)); LOGFONT lf; ::GetObject(font, sizeof lf, &lf); lf.lfWeight = FW_NORMAL; lf.lfHeight = -MulDiv(9, log_pixels_y, 96); lf.lfWidth = 0; //lf.lfQuality = ANTIALIASED_QUALITY; _tcscpy_s(lf.lfFaceName, LF_FACESIZE, _T("Small Fonts")); g_fntLicense = ::CreateFontIndirect(&lf); } } g_camera_image = ::ImageList_LoadImage(g_instance_handle, MAKEINTRESOURCE(IDB_CAMERA), 48, 0, CLR_NONE, IMAGE_BITMAP, LR_CREATEDIBSECTION); { TCHAR path[2 * MAX_PATH]= _T("c:\\Program Files"); ITEMIDLIST* idl= 0; if (g_IsWindows64) { if (HINSTANCE dll= ::LoadLibrary(_T("shell32.dll"))) { typedef HRESULT (STDAPICALLTYPE *FN_SHGetKnownFolderIDList)(REFKNOWNFOLDERID, DWORD, HANDLE, PIDLIST_ABSOLUTE*); FN_SHGetKnownFolderIDList SHGetKnownFolderIDListFn= reinterpret_cast<FN_SHGetKnownFolderIDList>(::GetProcAddress(dll, "SHGetKnownFolderIDList")); if (SHGetKnownFolderIDListFn) { if (SHGetKnownFolderIDListFn(FOLDERID_ProgramFilesX64, 0, HANDLE(0), &idl) == S_OK) { ::SHGetPathFromIDList(idl, path); IMallocPtr malloc; if (::SHGetMalloc(&malloc) == 0) malloc->Free(idl); } } ::FreeLibrary(dll); } if (idl == 0) { TCHAR buffer[MAX_PATH]; DWORD d= ::GetEnvironmentVariable(_T("ProgramW6432"), buffer, MAX_PATH); if (d > 0) _tcscpy_s(path, MAX_PATH, buffer); } } else if (::SHGetSpecialFolderLocation(hWnd, CSIDL_PROGRAM_FILES, &idl) == 0) { ::SHGetPathFromIDList(idl, path); IMallocPtr malloc; if (::SHGetMalloc(&malloc) == 0) malloc->Free(idl); } _tcscat_s(path, MAX_PATH * 2, _T("\\ExifPro ") EP_VER); ::SetDlgItemText(hWnd, IDC_FOLDER, path); if (pfnAutoCompleteFn) (*pfnAutoCompleteFn)(::GetDlgItem(hWnd, IDC_FOLDER), SHACF_FILESYSTEM); } ::CheckDlgButton(hWnd, IDC_RUN, 1); ::CheckDlgButton(hWnd, IDC_ADD_ICON, 1); ::CheckDlgButton(hWnd, IDC_PROGRAMS, 1); if (HWND edit= ::GetDlgItem(hWnd, IDC_FOLDER)) ::SendMessage(edit, EM_LIMITTEXT, MAX_PATH - 16, 0); ::SendMessage(hWnd, WM_NEXTDLGCTL, WPARAM(::GetDlgItem(hWnd, IDOK)), 1L); return false; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: { TCHAR path[MAX_PATH]= { 0 }; if (::GetDlgItemText(hWnd, IDC_FOLDER, path, MAX_PATH) > 0) { HCURSOR cursor= ::SetCursor(::LoadCursor(0, IDC_WAIT)); if (InstallExifPro(path, !!::IsDlgButtonChecked(hWnd, IDC_ADD_ICON), !!::IsDlgButtonChecked(hWnd, IDC_PROGRAMS))) { if (!g_update_common_ctrls) // if comctl updated it waits for a restart { // launch ExifPro? if (::IsDlgButtonChecked(hWnd, IDC_RUN)) { TCHAR exif[MAX_PATH * 2]= { 0 }; AppendFileName(path, g_EXIF_APP, exif); ::ShellExecute(0, _T("open"), exif, 0, 0, SW_SHOWNORMAL); } else { ::MessageBox(hWnd, _T("ExifPro was installed successfully."), g_INSTALLER, MB_ICONINFORMATION | MB_OK); } } ::EndDialog(hWnd, wParam); } } } return true; case IDCANCEL: ::EndDialog(hWnd, wParam); return TRUE; case IDC_BROWSE_DIR: BrowseDir(hWnd); break; case ID_LICENSE: ShowLicense(); break; } return TRUE; case WM_ERASEBKGND: if (HDC dc= HDC(wParam)) { RECT rect; ::GetClientRect(hWnd, &rect); RECT rectTop= rect; rectTop.bottom = 50; rect.top = rectTop.bottom; ::SetBkMode(dc, OPAQUE); ::SetBkColor(dc, RGB(255,255,255)); ::ExtTextOut(dc, 0, 0, ETO_OPAQUE, &rectTop, 0, 0, 0); ::ImageList_Draw(g_camera_image, 0, dc, 14, 7, ILD_NORMAL); HGDIOBJ hOld= ::SelectObject(dc, g_fntTitle); ::SetTextColor(dc, RGB(0,0,0)); const TCHAR* title= _T("ExifPro ") EP_VER _T(" Installer"); ::ExtTextOut(dc, 74, 13, 0, 0, title, _tcslen(title), 0); ::SelectObject(dc, hOld); ::SetBkColor(dc, ::GetSysColor(COLOR_3DSHADOW)); RECT rectLine= rectTop; rectLine.top = rectLine.bottom - 1; ::ExtTextOut(dc, 0, 0, ETO_OPAQUE, &rectLine, 0, 0, 0); ::SetBkColor(dc, ::GetSysColor(COLOR_3DFACE)); ::ExtTextOut(dc, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0); hOld = ::SelectObject(dc, g_fntLicense); ::SetTextColor(dc, RGB(0,0,0)); const TCHAR* info= _T("By installing this product, you are agreeing to be bound by the terms of the license."); ::ExtTextOut(dc, rect.left + 16, rect.bottom - 16, 0, 0, info, _tcslen(info), 0); ::SelectObject(dc, hOld); } return true; } return 0; }