📄 setup.c
字号:
BootEncryption bootEnc (hwndDlg);
if (bootEnc.GetInstalledBootLoaderVersion() < VERSION_NUM)
{
StatusMessage (hwndDlg, "INSTALLER_UPDATING_BOOT_LOADER");
bootEnc.InstallBootLoader (true);
Info (IsHiddenOSRunning () ? "BOOT_LOADER_UPGRADE_OK_HIDDEN_OS" : "BOOT_LOADER_UPGRADE_OK");
}
return TRUE;
}
catch (Exception &e)
{
e.Show (hwndDlg);
}
catch (...) { }
Error ("BOOT_LOADER_UPGRADE_FAILED");
return FALSE;
}
BOOL DoShortcutsUninstall (HWND hwndDlg, char *szDestDir)
{
char szLinkDir[TC_MAX_PATH];
char szTmp2[TC_MAX_PATH];
BOOL bSlash, bOK = FALSE;
HRESULT hOle;
int x;
BOOL allUsers = FALSE;
hOle = OleInitialize (NULL);
// User start menu
SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_PROGRAMS, 0);
x = strlen (szLinkDir);
if (szLinkDir[x - 1] == '\\')
bSlash = TRUE;
else
bSlash = FALSE;
if (bSlash == FALSE)
strcat (szLinkDir, "\\");
strcat (szLinkDir, "TrueCrypt");
// Global start menu
{
struct _stat st;
char path[TC_MAX_PATH];
SHGetSpecialFolderPath (hwndDlg, path, CSIDL_COMMON_PROGRAMS, 0);
strcat (path, "\\TrueCrypt");
if (_stat (path, &st) == 0)
{
strcpy (szLinkDir, path);
allUsers = TRUE;
}
}
// Start menu entries
sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
RemoveMessage (hwndDlg, szTmp2);
if (StatDeleteFile (szTmp2) == FALSE)
goto error;
sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt Website.url");
RemoveMessage (hwndDlg, szTmp2);
if (StatDeleteFile (szTmp2) == FALSE)
goto error;
sprintf (szTmp2, "%s%s", szLinkDir, "\\Uninstall TrueCrypt.lnk");
RemoveMessage (hwndDlg, szTmp2);
if (StatDeleteFile (szTmp2) == FALSE)
goto error;
sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt User's Guide.lnk");
DeleteFile (szTmp2);
// Start menu group
RemoveMessage ((HWND) hwndDlg, szLinkDir);
if (StatRemoveDirectory (szLinkDir) == FALSE)
handleWin32Error ((HWND) hwndDlg);
// Desktop icon
if (allUsers)
SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
else
SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
RemoveMessage (hwndDlg, szTmp2);
if (StatDeleteFile (szTmp2) == FALSE)
goto error;
bOK = TRUE;
error:
OleUninitialize ();
return bOK;
}
BOOL DoShortcutsInstall (HWND hwndDlg, char *szDestDir, BOOL bProgGroup, BOOL bDesktopIcon)
{
char szLinkDir[TC_MAX_PATH], szDir[TC_MAX_PATH];
char szTmp[TC_MAX_PATH], szTmp2[TC_MAX_PATH], szTmp3[TC_MAX_PATH];
BOOL bSlash, bOK = FALSE;
HRESULT hOle;
int x;
if (bProgGroup == FALSE && bDesktopIcon == FALSE)
return TRUE;
hOle = OleInitialize (NULL);
GetProgramPath (hwndDlg, szLinkDir);
x = strlen (szLinkDir);
if (szLinkDir[x - 1] == '\\')
bSlash = TRUE;
else
bSlash = FALSE;
if (bSlash == FALSE)
strcat (szLinkDir, "\\");
strcat (szLinkDir, "TrueCrypt");
strcpy (szDir, szDestDir);
x = strlen (szDestDir);
if (szDestDir[x - 1] == '\\')
bSlash = TRUE;
else
bSlash = FALSE;
if (bSlash == FALSE)
strcat (szDir, "\\");
if (bProgGroup)
{
FILE *f;
if (mkfulldir (szLinkDir, TRUE) != 0)
{
if (mkfulldir (szLinkDir, FALSE) != 0)
{
wchar_t szTmp[TC_MAX_PATH];
handleWin32Error (hwndDlg);
wsprintfW (szTmp, GetString ("CANT_CREATE_FOLDER"), szLinkDir);
MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
goto error;
}
}
sprintf (szTmp, "%s%s", szDir, "TrueCrypt.exe");
sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
IconMessage (hwndDlg, szTmp2);
if (CreateLink (szTmp, "", szTmp2) != S_OK)
goto error;
sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt Website.url");
IconMessage (hwndDlg, szTmp2);
f = fopen (szTmp2, "w");
if (f)
{
fprintf (f, "[InternetShortcut]\nURL=%s&dest=index\n", TC_APPLINK);
fclose (f);
}
else
goto error;
sprintf (szTmp, "%s%s", szDir, "TrueCrypt Setup.exe");
sprintf (szTmp2, "%s%s", szLinkDir, "\\Uninstall TrueCrypt.lnk");
strcpy (szTmp3, "/u");
IconMessage (hwndDlg, szTmp2);
if (CreateLink (szTmp, szTmp3, szTmp2) != S_OK)
goto error;
sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt User's Guide.lnk");
DeleteFile (szTmp2);
}
if (bDesktopIcon)
{
strcpy (szDir, szDestDir);
x = strlen (szDestDir);
if (szDestDir[x - 1] == '\\')
bSlash = TRUE;
else
bSlash = FALSE;
if (bSlash == FALSE)
strcat (szDir, "\\");
if (bForAllUsers)
SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_COMMON_DESKTOPDIRECTORY, 0);
else
SHGetSpecialFolderPath (hwndDlg, szLinkDir, CSIDL_DESKTOPDIRECTORY, 0);
sprintf (szTmp, "%s%s", szDir, "TrueCrypt.exe");
sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt.lnk");
IconMessage (hwndDlg, szTmp2);
if (CreateLink (szTmp, "", szTmp2) != S_OK)
goto error;
}
bOK = TRUE;
error:
OleUninitialize ();
return bOK;
}
void OutcomePrompt (HWND hwndDlg, BOOL bOK)
{
if (bOK)
{
EnableWindow (GetDlgItem ((HWND) hwndDlg, IDCANCEL), FALSE);
bDone = TRUE;
if (bUninstall == FALSE)
{
if (bDevm)
PostMessage (MainDlg, WM_CLOSE, 0, 0);
else if (bFirstTimeInstall && !SystemEncryptionUpgrade && !bUpgrade && !bDowngrade && !bRepairMode)
Info ("INSTALL_OK");
else if (!(SystemEncryptionUpgrade && bUpgrade))
Info ("SETUP_UPDATE_OK");
}
else
{
wchar_t str[4096];
swprintf (str, GetString ("UNINSTALL_OK"), InstallationPath);
MessageBoxW (hwndDlg, str, lpszTitle, MB_ICONASTERISK);
}
}
else
{
if (bUninstall == FALSE)
Error ("INSTALL_FAILED");
else
Error ("UNINSTALL_FAILED");
}
}
static void SetSystemRestorePoint (HWND hwndDlg, BOOL finalize)
{
static RESTOREPOINTINFO RestPtInfo;
static STATEMGRSTATUS SMgrStatus;
static BOOL failed = FALSE;
static BOOL (__stdcall *_SRSetRestorePoint)(PRESTOREPOINTINFO, PSTATEMGRSTATUS);
if (!SystemRestoreDll) return;
_SRSetRestorePoint = (BOOL (__stdcall *)(PRESTOREPOINTINFO, PSTATEMGRSTATUS))GetProcAddress (SystemRestoreDll,"SRSetRestorePointA");
if (_SRSetRestorePoint == 0)
{
FreeLibrary (SystemRestoreDll);
SystemRestoreDll = 0;
return;
}
if (!finalize)
{
StatusMessage (hwndDlg, "CREATING_SYS_RESTORE");
RestPtInfo.dwEventType = BEGIN_SYSTEM_CHANGE;
RestPtInfo.dwRestorePtType = APPLICATION_INSTALL;
RestPtInfo.llSequenceNumber = 0;
strcpy (RestPtInfo.szDescription, bUninstall ? "TrueCrypt uninstallation" : "TrueCrypt installation");
if(!_SRSetRestorePoint (&RestPtInfo, &SMgrStatus))
{
StatusMessage (hwndDlg, "FAILED_SYS_RESTORE");
failed = TRUE;
}
}
else if (!failed)
{
RestPtInfo.dwEventType = END_SYSTEM_CHANGE;
RestPtInfo.llSequenceNumber = SMgrStatus.llSequenceNumber;
if(!_SRSetRestorePoint(&RestPtInfo, &SMgrStatus))
{
StatusMessage (hwndDlg, "FAILED_SYS_RESTORE");
}
}
}
void DoUninstall (void *arg)
{
HWND hwndDlg = (HWND) arg;
BOOL bOK = TRUE;
BOOL bTempSkipSysRestore = FALSE;
if (!Rollback)
EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_UNINSTALL), FALSE);
WaitCursor ();
if (!Rollback)
{
ClearLogWindow (hwndDlg);
}
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 (FALSE))
{
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)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -