⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setup.c

📁 一个提供档案及Partition作加解密的程式支援以下的加密演算法AESBlowfishCAST5SerpentTriple DESTwofishAES-BlowfishAES-TwofishAES-
💻 C
📖 第 1 页 / 共 3 页
字号:

		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 (szTmp, "%s%s", szDir, "TrueCrypt User Guide.pdf");
		sprintf (szTmp2, "%s%s", szLinkDir, "\\TrueCrypt User's Guide.lnk");

		IconMessage (hwndDlg, szTmp2);
		if (CreateLink (szTmp, "", szTmp2) != S_OK)
			goto error;

		GetWindowsDirectory (szDir, sizeof (szDir));
		x = strlen (szDir);
		if (szDir[x - 1] == '\\')
			bSlash = TRUE;
		else
			bSlash = FALSE;

		if (bSlash == FALSE)
			strcat (szDir, "\\");

		sprintf (szTmp, "%s%s", szDir, "TrueCrypt Setup.exe");
		sprintf (szTmp2, "%s%s", szLinkDir, "\\Uninstall TrueCrypt.lnk");

		IconMessage (hwndDlg, szTmp2);
		if (CreateLink (szTmp, "/u", szTmp2) != S_OK)
			goto error;

	}

	if (bDesktopIcon)
	{
		strcpy (szDir, szDestDir);
		x = strlen (szDestDir);
		if (szDestDir[x - 1] == '\\')
			bSlash = TRUE;
		else
			bSlash = FALSE;

		if (bSlash == FALSE)
			strcat (szDir, "\\");

		if (nCurrentOS == WIN_NT && IsDlgButtonChecked (hwndDlg, IDC_ALL_USERS))
			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
RebootPrompt (HWND hwndDlg, BOOL bOK)
{
	if (bOK == TRUE)
	{
		SetWindowText (GetDlgItem ((HWND) hwndDlg, IDOK), "E&xit");

		EnableWindow (GetDlgItem ((HWND) hwndDlg, IDCANCEL), FALSE);

		bDone = TRUE;

		if (nCurrentOS == WIN_NT)
		{
			if (bUninstall == FALSE)
				MessageBox ((HWND) hwndDlg, "TrueCrypt has been successfuly installed.", lpszTitle, MB_ICONINFORMATION);
			else
				MessageBox ((HWND) hwndDlg, "TrueCrypt has been successfuly uninstalled.", lpszTitle, MB_ICONINFORMATION);
		}
		else
		{
			int x;

			if (bUninstall == FALSE)
				x = MessageBox ((HWND) hwndDlg, "TrueCrypt has been successfuly installed.\nTo use TrueCrypt your system must be restarted.", lpszTitle, MB_ICONINFORMATION);
			else
				x = MessageBox ((HWND) hwndDlg, "TrueCrypt has been successfuly uninstalled.\nYour system must be restarted.", lpszTitle, MB_ICONINFORMATION);
		}
	}
	else
	{
		if (bUninstall == FALSE)
			MessageBox ((HWND) hwndDlg, "The installation has failed!", lpszTitle, MB_ICONHAND);
		else
			MessageBox ((HWND) hwndDlg, "The uninstall has failed!", lpszTitle, MB_ICONHAND);
	}
}

static void SetSystemRestorePoint (void *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, "%s", "Creating system restore point");

		// Initialize the RESTOREPOINTINFO structure
		RestPtInfo.dwEventType = BEGIN_SYSTEM_CHANGE;

		// Notify the system that changes are about to be made.
		// An application is to be installed.
		RestPtInfo.dwRestorePtType = APPLICATION_INSTALL;

		// Set RestPtInfo.llSequenceNumber.
		RestPtInfo.llSequenceNumber = 0;

		// String to be displayed by System Restore for this restore point. 
		strcpy(RestPtInfo.szDescription, "TrueCrypt installation");

		// Notify the system that changes are to be made and that
		// the beginning of the restore point should be marked. 
		if(!_SRSetRestorePoint(&RestPtInfo, &SMgrStatus)) 
		{
			StatusMessage (hwndDlg, "%s", "Failed to create System Restore point!");
			failed = TRUE;
		}

		return;
	}

	if (failed)	return;

	StatusMessage (hwndDlg, "%s", "Closing system restore point");

	// The application performs some installation operations here.

	// Re-initialize the RESTOREPOINTINFO structure to notify the 
	// system that the operation is finished.
	RestPtInfo.dwEventType = END_SYSTEM_CHANGE;

	// End the system change by returning the sequence number 
	// received from the first call to SRSetRestorePoint.
	RestPtInfo.llSequenceNumber = SMgrStatus.llSequenceNumber;

	// Notify the system that the operation is done and that this
	// is the end of the restore point.
	if(!_SRSetRestorePoint(&RestPtInfo, &SMgrStatus)) 
	{
		StatusMessage (hwndDlg, "%s", "Closing system restore point failed!");
	}
	else
		StatusMessage (hwndDlg, "%s", "System restore point created");

}

void
DoUninstall (void *hwndDlg)
{
	BOOL bOK = TRUE;

	EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), FALSE);

	WaitCursor ();

	SendMessage (GetDlgItem ((HWND) hwndDlg, IDC_FILES), LB_RESETCONTENT, 0, 0);

	if (DoDriverUnload (hwndDlg) == FALSE)
	{
		bOK = FALSE;
	}
	else if (DoServiceUninstall (hwndDlg, "TrueCryptService") == FALSE)
	{
		bOK = FALSE;
	}
	else if (DoServiceUninstall (hwndDlg, "truecrypt") == FALSE)
	{
		bOK = FALSE;
	}
	else if (DoFilesInstall ((HWND) hwndDlg, dlg_file_name, FALSE) == FALSE)
	{
		bOK = FALSE;
	}
	else if (DoRegUninstall ((HWND) hwndDlg) == FALSE)
	{
		bOK = FALSE;
	}
	else if (DoShortcutsUninstall (hwndDlg, dlg_file_name) == FALSE)
	{
		bOK = FALSE;
	}
	else
	{
		RemoveMessage ((HWND) hwndDlg, dlg_file_name);
		if (StatRemoveDirectory (dlg_file_name) == FALSE)
		{
			handleWin32Error ((HWND) hwndDlg);
			bOK = FALSE;
		}
	}

	NormalCursor ();

	EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), TRUE);

	RebootPrompt (hwndDlg, bOK);

}

void
DoInstall (void *hwndDlg)
{
	BOOL bOK = TRUE;

	EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), FALSE);

	WaitCursor ();

	SendMessage (GetDlgItem ((HWND) hwndDlg, IDC_FILES), LB_RESETCONTENT, 0, 0);

	if (DoDriverUnload (hwndDlg) == FALSE)
	{
		NormalCursor ();
		EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), TRUE);
		return;
	}
	
	if (IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_SYSTEM_RESTORE)))
	{
		SetSystemRestorePoint (hwndDlg, FALSE);
	}

	if (DoServiceUninstall (hwndDlg, "TrueCryptService") == FALSE)
	{
		bOK = FALSE;
	}
	else if (DoServiceUninstall (hwndDlg, "truecrypt") == FALSE)
	{
		bOK = FALSE;
	}
	else if (DoFilesInstall ((HWND) hwndDlg, dlg_file_name, TRUE) == FALSE)
	{
		bOK = FALSE;
	}
	else if (DoRegInstall ((HWND) hwndDlg, dlg_file_name,
		IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_FILE_TYPE)),
			       TRUE) == FALSE)
	{
		bOK = FALSE;
	}
	else if (DoDriverInstall (hwndDlg) == FALSE)
	{
		bOK = FALSE;
	}
	else if (DoShortcutsInstall (hwndDlg, dlg_file_name,
				     IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_PROG_GROUP)),
					 IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_DESKTOP_ICON))) == FALSE)
	{
		bOK = FALSE;
	}

	if (IsButtonChecked (GetDlgItem ((HWND) hwndDlg, IDC_SYSTEM_RESTORE)))
		SetSystemRestorePoint (hwndDlg, TRUE);

	if (bOK)
		StatusMessage (hwndDlg, "%s", "Installation completed.");

	NormalCursor ();

	EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), TRUE);

	RebootPrompt (hwndDlg, bOK);
}


BOOL WINAPI
InstallDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	WORD lw = LOWORD (wParam);
	if (lParam);		/* remove warning */

	switch (msg)
	{
	case WM_INITDIALOG:
		SetDefaultUserFont (hwndDlg);
		InitDialog (hwndDlg);

		{
			char path[MAX_PATH+20];
			ITEMIDLIST *i;
			SHGetSpecialFolderLocation (hwndDlg, CSIDL_PROGRAM_FILES, &i);
			SHGetPathFromIDList (i, path);
			strcat (path, "\\TrueCrypt");
			SetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), path);
		}

		if (bUninstall == FALSE)
		{
			LoadLicense (hwndDlg);
		}

		SendMessage (GetDlgItem (hwndDlg, IDC_ALL_USERS), BM_SETCHECK, BST_CHECKED, 0);
		if (nCurrentOS != WIN_NT)
			EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_ALL_USERS), FALSE);

		SendMessage (GetDlgItem (hwndDlg, IDC_FILE_TYPE), BM_SETCHECK, BST_CHECKED, 0);
		SendMessage (GetDlgItem (hwndDlg, IDC_PROG_GROUP), BM_SETCHECK, BST_CHECKED, 0);
		SendMessage (GetDlgItem (hwndDlg, IDC_DESKTOP_ICON), BM_SETCHECK, BST_CHECKED, 0);

		// System Restore
		SystemRestoreDll = LoadLibrary("srclient.dll");

		if (SystemRestoreDll != 0)
			SendMessage (GetDlgItem (hwndDlg, IDC_SYSTEM_RESTORE), BM_SETCHECK, BST_CHECKED, 0);
		else
			EnableWindow (GetDlgItem ((HWND) hwndDlg, IDC_SYSTEM_RESTORE), FALSE);

		SetWindowText (hwndDlg, lpszTitle);
		return 1;

	case WM_SYSCOMMAND:
		if (lw == IDC_ABOUT)
		{
			DialogBox (hInst, MAKEINTRESOURCE (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
			return 1;
		}
		return 0;

	case WM_COMMAND:
		if (lw == IDOK)
		{
			char szDirname[TC_MAX_PATH];

			if (bDone == TRUE)
			{
				EndDialog (hwndDlg, IDOK);
				return 1;
			}

			GetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), szDirname, sizeof (szDirname));

			if (bUninstall == FALSE)
			{
				if (mkfulldir (szDirname, TRUE) != 0)
				{
					char szTmp[TC_MAX_PATH];
					//int x;

					//sprintf (szTmp, "The directory '%s' does not exist. Do you want to create this directory?", szDirname);
					//x = MessageBox (hwndDlg, szTmp, lpszTitle, MB_ICONQUESTION | MB_YESNO);
					//if (x == IDNO)
					//{
					//	SetFocus (GetDlgItem (hwndDlg, IDC_DESTINATION));
					//	return 1;
					//}

					if (mkfulldir (szDirname, FALSE) != 0)
					{
						handleWin32Error (hwndDlg);
						sprintf (szTmp, "The directory '%s' could not be created", szDirname);
						MessageBox (hwndDlg, szTmp, lpszTitle, MB_ICONHAND);
						return 1;
					}

				}
			}

			strcpy (dlg_file_name, szDirname);

			if (bUninstall == FALSE)
				_beginthread (DoInstall, 16384, (void *) hwndDlg);
			else
				_beginthread (DoUninstall, 16384, (void *) hwndDlg);

			return 1;
		}

		if (lw == IDCANCEL)
		{
			EndDialog (hwndDlg, IDCANCEL);
			return 1;
		}

		if (lw == IDC_BROWSE)
		{
			char szDirname[TC_MAX_PATH];

			GetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), szDirname, sizeof (szDirname));

			if (BrowseDirectories (hwndDlg, "Please select installation directory", szDirname) == TRUE)
				SetWindowText (GetDlgItem (hwndDlg, IDC_DESTINATION), szDirname);
			
			return 1;
		}

		if (lw == IDC_DESTINATION && HIWORD (wParam) == EN_CHANGE && bDone == FALSE)
		{
			if (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_DESTINATION)) <= 0)
				EnableWindow (GetDlgItem (hwndDlg, IDOK), FALSE);
			else
				EnableWindow (GetDlgItem (hwndDlg, IDOK), TRUE);
			return 1;
		}

		return 0;

	case WM_CLOSE:
		EndDialog (hwndDlg, IDCANCEL);
		return 1;
	}

	return 0;
}


int WINAPI
WINMAIN (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszCommandLine,
	 int nCmdShow)
{
	if (nCmdShow && hPrevInstance);	/* Remove unused parameter warning */

	lpszTitle = "TrueCrypt Setup";

	/* Call InitApp to initialize the common code */
	InitApp (hInstance);

	if (nCurrentOS == WIN_NT && IsAdmin ()!= TRUE)
		if (MessageBox (NULL, "To successfully install/uninstall TrueCrypt you must have Administrator rights, "
				"do you want to continue?", lpszTitle, MB_YESNO | MB_ICONQUESTION) != IDYES)
			return 0;

	if (lpszCommandLine[0] == '/' && (lpszCommandLine[1] == 'u' || lpszCommandLine[1] == 'U'))
	{
		bUninstall = TRUE;
	}

	if (bUninstall == FALSE)
	{
		/* Create the main dialog box */
		DialogBox (hInstance, MAKEINTRESOURCE (IDD_INSTALL), NULL, (DLGPROC) InstallDlgProc);
	}
	else
	{
		/* Create the main dialog box */
		DialogBox (hInstance, MAKEINTRESOURCE (IDD_UNINSTALL), NULL, (DLGPROC) InstallDlgProc);
	}

	/* Terminate */
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -