From 2d94e8da564a453aaa4397056f684bba3f24abac Mon Sep 17 00:00:00 2001 From: Alex Pakhotin Date: Mon, 30 Nov 2009 12:20:22 -0800 Subject: [PATCH] bug 531332 - Enable FastStart service with the EXE installer r=gavin.sharp a=blocking-fennec --- .../installer/wince/nsInstallerDlg.cpp | 64 +++++++++++++++++-- .../mozapps/installer/wince/nsInstallerDlg.h | 3 +- .../installer/wince/uninstall/Uninstall.cpp | 32 +++++++--- 3 files changed, 83 insertions(+), 16 deletions(-) diff --git a/toolkit/mozapps/installer/wince/nsInstallerDlg.cpp b/toolkit/mozapps/installer/wince/nsInstallerDlg.cpp index 90a5a2db50b..b69d0bbbe03 100644 --- a/toolkit/mozapps/installer/wince/nsInstallerDlg.cpp +++ b/toolkit/mozapps/installer/wince/nsInstallerDlg.cpp @@ -56,6 +56,7 @@ const WCHAR c_sInstallPathTemplate[] = L"%s\\%s"; const WCHAR c_sExtractCardPathTemplate[] = L"\\%s%s\\%s"; const WCHAR c_sAppRegKeyTemplate[] = L"Software\\%s"; +const WCHAR c_sFastStartTemplate[] = L"%s\\%sfaststart.exe"; // Message handler for the dialog INT_PTR CALLBACK DlgMain(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) @@ -72,6 +73,8 @@ INT_PTR CALLBACK DlgMain(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) nsInstallerDlg::nsInstallerDlg() { m_hInst = NULL; + m_hDlg = NULL; + m_bFastStart = FALSE; m_sExtractPath[0] = 0; m_sInstallPath[0] = 0; m_sProgramFiles[0] = 0; @@ -269,6 +272,8 @@ BOOL nsInstallerDlg::PostExtract() { BOOL bResult = TRUE; + m_bFastStart = FastStartFileExists(); + if (!CreateShortcut()) { bResult = FALSE; @@ -310,19 +315,40 @@ BOOL nsInstallerDlg::StoreInstallPath() return (result == ERROR_SUCCESS); } +// Creates shortcuts for Fennec and (optionally) FastStart service. +// Note: The shortcut names have to be in sync with DeleteShortcut in Uninstaller.cpp BOOL nsInstallerDlg::CreateShortcut() { + BOOL result = FALSE; + WCHAR sFennecPath[MAX_PATH]; _snwprintf(sFennecPath, MAX_PATH, L"\"%s\\%s.exe\"", m_sInstallPath, Strings.GetString(StrID_AppShortName)); WCHAR sProgramsPath[MAX_PATH]; - if (!SHGetSpecialFolderPath(m_hDlg, sProgramsPath, CSIDL_PROGRAMS, FALSE)) - wcscpy(sProgramsPath, L"\\Windows\\Start Menu\\Programs"); + if (SHGetSpecialFolderPath(m_hDlg, sProgramsPath, CSIDL_PROGRAMS, FALSE)) + { + WCHAR sShortcutPath[MAX_PATH]; + _snwprintf(sShortcutPath, MAX_PATH, L"%s\\%s.lnk", sProgramsPath, Strings.GetString(StrID_AppShortName)); - WCHAR sShortcutPath[MAX_PATH]; - _snwprintf(sShortcutPath, MAX_PATH, L"%s\\%s.lnk", sProgramsPath, Strings.GetString(StrID_AppShortName)); + result = SHCreateShortcut(sShortcutPath, sFennecPath); + } - return SHCreateShortcut(sShortcutPath, sFennecPath); + if (m_bFastStart) + { + WCHAR sFastStartPath[MAX_PATH]; + _snwprintf(sFastStartPath, MAX_PATH, L"\"%s\\%sfaststart.exe\"", m_sInstallPath, Strings.GetString(StrID_AppShortName)); + + WCHAR sStartupPath[MAX_PATH]; + if (SHGetSpecialFolderPath(m_hDlg, sStartupPath, CSIDL_STARTUP, FALSE)) + { + WCHAR sStartupShortcutPath[MAX_PATH]; + _snwprintf(sStartupShortcutPath, MAX_PATH, L"%s\\%sFastStart.lnk", sStartupPath, Strings.GetString(StrID_AppShortName)); + + result = SHCreateShortcut(sStartupShortcutPath, sFastStartPath) && result; + } + } + + return result; } BOOL nsInstallerDlg::MoveSetupStrings() @@ -342,9 +368,19 @@ BOOL nsInstallerDlg::SilentFirstRun() UpdateWindow(m_hDlg); // make sure the text is drawn WCHAR sCmdLine[MAX_PATH]; - _snwprintf(sCmdLine, MAX_PATH, L"%s\\%s.exe", m_sInstallPath, Strings.GetString(StrID_AppShortName)); + WCHAR *sParams = NULL; + if (m_bFastStart) + { + // Run fast start exe instead - it will create the profile and stay in the background + _snwprintf(sCmdLine, MAX_PATH, c_sFastStartTemplate, m_sInstallPath, Strings.GetString(StrID_AppShortName)); + } + else + { + _snwprintf(sCmdLine, MAX_PATH, L"%s\\%s.exe", m_sInstallPath, Strings.GetString(StrID_AppShortName)); + sParams = L"-silent -nosplash"; + } PROCESS_INFORMATION pi; - BOOL bResult = CreateProcess(sCmdLine, L"-silent -nosplash", + BOOL bResult = CreateProcess(sCmdLine, sParams, NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi); if (bResult) { @@ -412,3 +448,17 @@ void nsInstallerDlg::RunUninstall() } } } + +////////////////////////////////////////////////////////////////////////// +// +// Helper functions +// +////////////////////////////////////////////////////////////////////////// + +BOOL nsInstallerDlg::FastStartFileExists() +{ + WCHAR sFastStartPath[MAX_PATH]; + _snwprintf(sFastStartPath, MAX_PATH, c_sFastStartTemplate, m_sInstallPath, Strings.GetString(StrID_AppShortName)); + // Check if file exists + return (GetFileAttributes(sFastStartPath) != INVALID_FILE_ATTRIBUTES); +} diff --git a/toolkit/mozapps/installer/wince/nsInstallerDlg.h b/toolkit/mozapps/installer/wince/nsInstallerDlg.h index 7b90e51b622..124afaef860 100644 --- a/toolkit/mozapps/installer/wince/nsInstallerDlg.h +++ b/toolkit/mozapps/installer/wince/nsInstallerDlg.h @@ -69,12 +69,13 @@ private: void RunUninstall(); void AddErrorMsg(WCHAR* sErr); + BOOL FastStartFileExists(); static const int c_nMaxErrorLen = 2048; HINSTANCE m_hInst; HWND m_hDlg; - + BOOL m_bFastStart; WCHAR m_sProgramFiles[MAX_PATH]; WCHAR m_sExtractPath[MAX_PATH]; WCHAR m_sInstallPath[MAX_PATH]; diff --git a/toolkit/mozapps/installer/wince/uninstall/Uninstall.cpp b/toolkit/mozapps/installer/wince/uninstall/Uninstall.cpp index e3a2d77af3c..daccba0777f 100644 --- a/toolkit/mozapps/installer/wince/uninstall/Uninstall.cpp +++ b/toolkit/mozapps/installer/wince/uninstall/Uninstall.cpp @@ -252,20 +252,36 @@ BOOL DeleteDirectory(const WCHAR* sPathToDelete) return TRUE; } +// Deletes shortcuts for Fennec and FastStart service created by the installer. +// Note: The shortcut names have to be in sync with CreateShortcut in nsInstallerDlg.cpp BOOL DeleteShortcut(HWND hwndParent) { + BOOL result = FALSE; + WCHAR sProgramsPath[MAX_PATH]; - if (!SHGetSpecialFolderPath(hwndParent, sProgramsPath, CSIDL_PROGRAMS, FALSE)) - wcscpy(sProgramsPath, L"\\Windows\\Start Menu\\Programs"); - - WCHAR sShortcutPath[MAX_PATH]; - _snwprintf(sShortcutPath, MAX_PATH, L"%s\\%s.lnk", sProgramsPath, Strings.GetString(StrID_AppShortName)); + if (SHGetSpecialFolderPath(hwndParent, sProgramsPath, CSIDL_PROGRAMS, FALSE)) + { + WCHAR sShortcutPath[MAX_PATH]; + _snwprintf(sShortcutPath, MAX_PATH, L"%s\\%s.lnk", sProgramsPath, Strings.GetString(StrID_AppShortName)); - if(SetFileAttributes(sShortcutPath, FILE_ATTRIBUTE_NORMAL)) - return DeleteFile(sShortcutPath); + if(SetFileAttributes(sShortcutPath, FILE_ATTRIBUTE_NORMAL)) + result = DeleteFile(sShortcutPath); + } - return FALSE; + // Handle faststart shortcut + WCHAR sStartupPath[MAX_PATH]; + if (SHGetSpecialFolderPath(hwndParent, sStartupPath, CSIDL_STARTUP, FALSE)) + { + WCHAR sStartupShortcutPath[MAX_PATH]; + _snwprintf(sStartupShortcutPath, MAX_PATH, L"%s\\%sFastStart.lnk", sStartupPath, Strings.GetString(StrID_AppShortName)); + + // It may not exist - just ignore that + if(SetFileAttributes(sStartupShortcutPath, FILE_ATTRIBUTE_NORMAL)) + DeleteFile(sStartupShortcutPath); + } + + return result; } BOOL DeleteRegistryKey()