?? setup.c
字號:
}
if (DoDriverUnload (hwndDlg) == FALSE)
{
bOK = FALSE;
bTempSkipSysRestore = TRUE; // Volumes are possibly mounted; defer System Restore point creation for this uninstall attempt.
}
else
{
if (!Rollback && bSystemRestore && !bTempSkipSysRestore)
SetSystemRestorePoint (hwndDlg, FALSE);
if (DoServiceUninstall (hwndDlg, "truecrypt") == FALSE)
{
bOK = FALSE;
}
else if (DoRegUninstall ((HWND) hwndDlg, FALSE) == FALSE)
{
bOK = FALSE;
}
else if (DoFilesInstall ((HWND) hwndDlg, InstallationPath) == FALSE)
{
bOK = FALSE;
}
else if (DoShortcutsUninstall (hwndDlg, InstallationPath) == FALSE)
{
bOK = FALSE;
}
else if (!DoApplicationDataUninstall (hwndDlg))
{
bOK = FALSE;
}
else
{
char temp[MAX_PATH];
FILE *f;
// Deprecated service
DoServiceUninstall (hwndDlg, "TrueCryptService");
GetTempPath (sizeof (temp), temp);
_snprintf (UninstallBatch, sizeof (UninstallBatch), "%s\\TrueCrypt-Uninstall.bat", temp);
UninstallBatch [sizeof(UninstallBatch)-1] = 0;
// Create uninstall batch
f = fopen (UninstallBatch, "w");
if (!f)
bOK = FALSE;
else
{
fprintf (f, ":loop\n"
"del \"%s%s\"\n"
"if exist \"%s%s\" goto loop\n"
"rmdir \"%s\"\n"
"del \"%s\"",
InstallationPath, "TrueCrypt Setup.exe",
InstallationPath, "TrueCrypt Setup.exe",
InstallationPath,
UninstallBatch
);
fclose (f);
}
}
}
NormalCursor ();
if (Rollback)
return;
if (bSystemRestore && !bTempSkipSysRestore)
SetSystemRestorePoint (hwndDlg, TRUE);
if (bOK)
PostMessage (hwndDlg, TC_APPMSG_UNINSTALL_SUCCESS, 0, 0);
else
bUninstallInProgress = FALSE;
EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), TRUE);
OutcomePrompt (hwndDlg, bOK);
}
void
DoInstall (void *arg)
{
HWND hwndDlg = (HWND) arg;
BOOL bOK = TRUE;
char path[MAX_PATH];
BootEncryption bootEnc (hwndDlg);
// Refresh the main GUI (wizard thread)
InvalidateRect (GetDlgItem (MainDlg, IDD_INSTL_DLG), NULL, TRUE);
ClearLogWindow(hwndDlg);
if (mkfulldir (InstallationPath, TRUE) != 0)
{
if (mkfulldir (InstallationPath, FALSE) != 0)
{
wchar_t szTmp[TC_MAX_PATH];
handleWin32Error (hwndDlg);
wsprintfW (szTmp, GetString ("CANT_CREATE_FOLDER"), InstallationPath);
MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
Error ("INSTALL_FAILED");
PostMessage (MainDlg, TC_APPMSG_INSTALL_FAILURE, 0, 0);
return;
}
}
UpdateProgressBarProc(2);
if (DoDriverUnload (hwndDlg) == FALSE)
{
NormalCursor ();
PostMessage (MainDlg, TC_APPMSG_INSTALL_FAILURE, 0, 0);
return;
}
UpdateProgressBarProc(12);
if (bSystemRestore)
SetSystemRestorePoint (hwndDlg, FALSE);
UpdateProgressBarProc(48);
if (bDisableSwapFiles
&& IsPagingFileActive())
{
if (!DisablePagingFile())
{
handleWin32Error (hwndDlg);
Error ("FAILED_TO_DISABLE_PAGING_FILES");
}
else
bRestartRequired = TRUE;
}
UpdateProgressBarProc(50);
// Remove deprecated
DoServiceUninstall (hwndDlg, "TrueCryptService");
UpdateProgressBarProc(55);
if (!SystemEncryptionUpgrade)
DoRegUninstall ((HWND) hwndDlg, TRUE);
UpdateProgressBarProc(62);
GetWindowsDirectory (path, sizeof (path));
strcat_s (path, sizeof (path), "\\TrueCrypt Setup.exe");
DeleteFile (path);
if (UpdateProgressBarProc(63) && !SystemEncryptionUpgrade && DoServiceUninstall (hwndDlg, "truecrypt") == FALSE)
{
bOK = FALSE;
}
else if (UpdateProgressBarProc(72) && DoFilesInstall ((HWND) hwndDlg, InstallationPath) == FALSE)
{
bOK = FALSE;
}
else if (UpdateProgressBarProc(80) && !SystemEncryptionUpgrade && DoRegInstall ((HWND) hwndDlg, InstallationPath, bRegisterFileExt ) == FALSE)
{
bOK = FALSE;
}
else if (UpdateProgressBarProc(85) && !SystemEncryptionUpgrade && DoDriverInstall (hwndDlg) == FALSE)
{
bOK = FALSE;
}
else if (UpdateProgressBarProc(90) && SystemEncryptionUpgrade && UpgradeBootLoader (hwndDlg) == FALSE)
{
bOK = FALSE;
}
else if (UpdateProgressBarProc(93) && DoShortcutsInstall (hwndDlg, InstallationPath, bAddToStartMenu, bDesktopIcon) == FALSE)
{
bOK = FALSE;
}
try
{
bootEnc.RenameDeprecatedSystemLoaderBackup();
}
catch (...) { }
if (bOK)
UpdateProgressBarProc(97);
if (bSystemRestore)
SetSystemRestorePoint (hwndDlg, TRUE);
if (bOK)
{
UpdateProgressBarProc(100);
UninstallBatch[0] = 0;
StatusMessage (hwndDlg, "INSTALL_COMPLETED");
PostMessage (MainDlg, TC_APPMSG_INSTALL_SUCCESS, 0, 0);
}
else
{
UpdateProgressBarProc(0);
bUninstall = TRUE;
Rollback = TRUE;
Silent = TRUE;
if (!SystemEncryptionUpgrade)
DoUninstall (hwndDlg);
bUninstall = FALSE;
Rollback = FALSE;
Silent = FALSE;
StatusMessage (hwndDlg, "ROLLBACK");
}
OutcomePrompt (hwndDlg, bOK);
if (!bOK)
{
PostMessage (MainDlg, TC_APPMSG_INSTALL_FAILURE, 0, 0);
}
else if (!bUninstall && !bDevm)
{
if (!IsHiddenOSRunning()) // A hidden OS user should not see the post-install notes twice (on decoy OS and then on hidden OS).
{
if (bUpgrade)
{
SavePostInstallTasksSettings (TC_POST_INSTALL_CFG_RELEASE_NOTES);
}
else if (bFirstTimeInstall)
{
SavePostInstallTasksSettings (TC_POST_INSTALL_CFG_TUTORIAL);
}
}
if (bRestartRequired || SystemEncryptionUpgrade)
{
bRestartRequired = TRUE;
if (AskYesNo (SystemEncryptionUpgrade ? "UPGRADE_OK_REBOOT_REQUIRED" : "CONFIRM_RESTART") == IDYES)
RestartComputer();
}
}
}
void SetInstallationPath (HWND hwndDlg)
{
HKEY hkey;
BOOL bInstallPathDetermined = FALSE;
char path[MAX_PATH+20];
ITEMIDLIST *itemList;
memset (InstallationPath, 0, sizeof (InstallationPath));
// Determine if TrueCrypt is already installed and try to determine its "Program Files" location
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt", 0, KEY_READ, &hkey) == ERROR_SUCCESS)
{
/* Default 'UninstallString' registry strings written by past versions of TrueCrypt:
------------------------------------------------------------------------------------
1.0 C:\WINDOWS\TrueCrypt Setup.exe /u [optional]
1.0a C:\WINDOWS\TrueCrypt Setup.exe /u [optional]
2.0 C:\WINDOWS\TrueCrypt Setup.exe /u [optional]
2.1 C:\WINDOWS\TrueCrypt Setup.exe /u [optional]
2.1a C:\WINDOWS\TrueCrypt Setup.exe /u [optional]
3.0 C:\WINDOWS\TrueCrypt Setup.exe /u [optional]
3.0a C:\WINDOWS\TrueCrypt Setup.exe /u [optional]
3.1 The UninstallString was NEVER written (fortunately, 3.1a replaced 3.1 after 2 weeks)
3.1a C:\WINDOWS\TrueCrypt Setup.exe /u
4.0 C:\WINDOWS\TrueCrypt Setup.exe /u C:\Program Files\TrueCrypt
4.1 C:\WINDOWS\TrueCrypt Setup.exe /u C:\Program Files\TrueCrypt
4.2 C:\WINDOWS\TrueCrypt Setup.exe /u C:\Program Files\TrueCrypt
4.2a C:\WINDOWS\TrueCrypt Setup.exe /u C:\Program Files\TrueCrypt
4.3 "C:\Program Files\TrueCrypt\TrueCrypt Setup.exe" /u C:\Program Files\TrueCrypt\
4.3a "C:\Program Files\TrueCrypt\TrueCrypt Setup.exe" /u C:\Program Files\TrueCrypt\
5.0+ "C:\Program Files\TrueCrypt\TrueCrypt Setup.exe" /u
Note: In versions 1.0-3.0a the user was able to choose whether to install the uninstaller.
The default was to install it. If it wasn't installed, there was no UninstallString.
*/
char rv[MAX_PATH*4];
DWORD size = sizeof (rv);
if (RegQueryValueEx (hkey, "UninstallString", 0, 0, (LPBYTE) &rv, &size) == ERROR_SUCCESS && strrchr (rv, '/'))
{
size_t len = 0;
// Cut and paste the location (path) where TrueCrypt is installed to InstallationPath
if (rv[0] == '"')
{
// 4.3 or later
len = strrchr (rv, '/') - rv - 2;
strncpy (InstallationPath, rv + 1, len);
InstallationPath [len] = 0;
bInstallPathDetermined = TRUE;
if (InstallationPath [strlen (InstallationPath) - 1] != '\\')
{
len = strrchr (InstallationPath, '\\') - InstallationPath;
InstallationPath [len] = 0;
}
}
else
{
// 1.0-4.2a (except 3.1)
len = strrchr (rv, '/') - rv;
if (rv[len+2] == ' ')
{
// 4.0-4.2a
strncpy (InstallationPath, rv + len + 3, strlen (rv) - len - 3);
InstallationPath [strlen (rv) - len - 3] = 0;
bInstallPathDetermined = TRUE;
}
else
{
// 1.0-3.1a (except 3.1)
// We know that TrueCrypt is installed but don't know where. It's not safe to continue installing
// over the old version.
Error ("UNINSTALL_OLD_VERSION_FIRST");
len = strrchr (rv, '/') - rv - 1;
strncpy (InstallationPath, rv, len); // Path and filename of the uninstaller
InstallationPath [len] = 0;
bInstallPathDetermined = FALSE;
ShellExecute (NULL, "open", InstallationPath, "/u", NULL, SW_SHOWNORMAL);
RegCloseKey (hkey);
exit (1);
}
}
}
RegCloseKey (hkey);
}
if (bInstallPathDetermined)
{
char mp[MAX_PATH];
// Determine whether we were launched from the folder where TrueCrypt is installed
GetModuleFileName (NULL, mp, sizeof (mp));
if (strncmp (InstallationPath, mp, min (strlen(InstallationPath), strlen(mp))) == 0)
{
// We were launched from the folder where TrueCrypt is installed
if (!IsNonInstallMode() && !bDevm)
bChangeMode = TRUE;
}
}
else
{
/* TrueCypt is not installed or it wasn't possible to determine where it is installed. */
// Default "Program Files" path.
SHGetSpecialFolderLocation (hwndDlg, CSIDL_PROGRAM_FILES, &itemList);
SHGetPathFromIDList (itemList, path);
strncat (path, "\\TrueCrypt\\", min (strlen("\\TrueCrypt\\"), sizeof(path)-strlen(path)-1));
strncpy (InstallationPath, path, sizeof(InstallationPath)-1);
}
// Make sure the path ends with a backslash
if (InstallationPath [strlen (InstallationPath) - 1] != '\\')
{
strcat (InstallationPath, "\\");
}
}
// Handler for uninstall only (install is handled by the wizard)
BOOL CALLBACK
UninstallDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
WORD lw = LOWORD (wParam);
switch (msg)
{
case WM_INITDIALOG:
MainDlg = hwndDlg;
if (!CreateAppSetupMutex ())
AbortProcess ("TC_INSTALLER_IS_RUNNING");
InitDialog (hwndDlg);
LocalizeDialog (hwndDlg, NULL);
SetWindowTextW (hwndDlg, lpszTitle);
// System Restore
SetCheckBox (hwndDlg, IDC_SYSTEM_RESTORE, bSystemRestore);
if (SystemRestoreDll == 0)
{
SetCheckBox (hwndDlg, IDC_SYSTEM_RESTORE, FALSE);
EnableWindow (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE), FALSE);
}
SetFocus (GetDlgItem (hwndDlg, IDC_UNINSTALL));
return 1;
case WM_SYSCOMMAND:
if (lw == IDC_ABOUT)
{
DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
return 1;
}
return 0;
case WM_COMMAND:
if (lw == IDC_UNINSTALL)
{
if (bDone)
{
bUninstallInProgress = FALSE;
PostMessage (hwndDlg, WM_CLOSE, 0, 0);
return 1;
}
bUninstallInProgress = TRUE;
WaitCursor ();
if (bUninstall)
_beginthread (DoUninstall, 16384, (void *) hwndDlg);
return 1;
}
if (lw == IDC_SYSTEM_RESTORE)
{
bSystemRestore = IsButtonChecked (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE));
return 1;
}
if (lw == IDCANCEL)
{
PostMessage (hwndDlg, WM_CLOSE, 0, 0);
return 1;
}
return 0;
case TC_APPMSG_UNINSTALL_SUCCESS:
SetWindowTextW (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), GetString ("FINALIZE"));
NormalCursor ();
return 1;
case WM_CLOSE:
if (bUninstallInProgress)
{
NormalCursor();
if (AskNoYes("CONFIRM_EXIT_UNIVERSAL") == IDNO)
{
return 1;
}
WaitCursor ();
}
EndDialog (hwndDlg, IDCANCEL);
return 1;
}
return 0;
}
int WINAPI WINMAIN (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszCommandLine, int nCmdShow)
{
atexit (localcleanup);
SelfExtractStartupInit();
lpszTitle = L"TrueCrypt Setup";
/* Call InitApp to initialize the common code */
InitApp (hInstance, NULL);
if (IsAdmin () != TRUE)
if (MessageBoxW (NULL, GetString ("SETUP_ADMIN"), lpszTitle, MB_YESNO | MB_ICONQUESTION) != IDYES)
{
exit (1);
}
/* Setup directory */
{
char *s;
GetModuleFileName (NULL, SetupFilesDir, sizeof (SetupFilesDir));
s = strrchr (SetupFilesDir, '\\');
if (s)
s[1] = 0;
}
/* Parse command line arguments */
if (lpszCommandLine[0] == '/')
{
if (lpszCommandLine[1] == 'u')
{
// Uninstall: /u
bUninstall = TRUE;
}
else if (lpszCommandLine[1] == 'c')
{
// Change: /c
bChangeMode = TRUE;
}
else if (lpszCommandLine[1] == 'p')
{
// Create self-extracting package: /p
bMakePackage = TRUE;
}
else if (lpszCommandLine[1] == 'd')
{
// Dev mode: /d
bDevm = TRUE;
}
}
if (bMakePackage)
{
/* Create self-extracting package */
MakeSelfExtractingPackage (NULL, SetupFilesDir);
}
else
{
SetInstallationPath (NULL);
if (!bUninstall)
{
if (IsSelfExtractingPackage())
{
if (!VerifyPackageIntegrity())
{
// Package corrupted
exit (1);
}
bDevm = FALSE;
}
else if (!bDevm)
{
MessageBox (NULL, "Error: This installer file does not contain any compressed files.\n\nTo create a self-extracting installer package (with embedded compressed files), run:\n\"TrueCrypt Setup.exe\" /p", "TrueCrypt", MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST);
exit (1);
}
if (bChangeMode)
{
/* TrueCrypt is already installed on this system and we were launched from the Program Files folder */
char *tmpStr[] = {0, "SELECT_AN_ACTION", "REPAIR_REINSTALL", "UNINSTALL", "EXIT", 0};
// Ask the user to select either Repair or Unistallation
switch (AskMultiChoice ((void **) tmpStr))
{
case 1:
bRepairMode = TRUE;
break;
case 2:
bUninstall = TRUE;
break;
default:
exit (1);
}
}
}
// System Restore
SystemRestoreDll = LoadLibrary ("srclient.dll");
if (!bUninstall)
{
/* Create the main dialog for install */
DialogBoxParamW (hInstance, MAKEINTRESOURCEW (IDD_INSTL_DLG), NULL, (DLGPROC) MainDialogProc,
(LPARAM)lpszCommandLine);
}
else
{
/* Create the main dialog for uninstall */
DialogBoxW (hInstance, MAKEINTRESOURCEW (IDD_UNINSTALL), NULL, (DLGPROC) UninstallDlgProc);
if (UninstallBatch[0])
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory (&si, sizeof (si));
si.cb = sizeof (si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
if (!CreateProcess (UninstallBatch, NULL, NULL, NULL, FALSE, IDLE_PRIORITY_CLASS, NULL, NULL, &si, &pi))
DeleteFile (UninstallBatch);
else
{
CloseHandle (pi.hProcess);
CloseHandle (pi.hThread);
}
}
}
}
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -