00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "Dlg_CheckFileIntegrity.h"
00009 #include "Hash\vmsHash.h"
00010
00011 #ifdef _DEBUG
00012 #define new DEBUG_NEW
00013 #undef THIS_FILE
00014 static char THIS_FILE[] = __FILE__;
00015 #endif
00016
00017 CDlg_CheckFileIntegrity::CDlg_CheckFileIntegrity(CWnd* pParent )
00018 : CDialog(CDlg_CheckFileIntegrity::IDD, pParent)
00019 {
00020
00021
00022
00023 }
00024
00025 void CDlg_CheckFileIntegrity::DoDataExchange(CDataExchange* pDX)
00026 {
00027 CDialog::DoDataExchange(pDX);
00028
00029 DDX_Control(pDX, IDC_ALGORITHM, m_wndAlgorithm);
00030
00031 }
00032
00033 BEGIN_MESSAGE_MAP(CDlg_CheckFileIntegrity, CDialog)
00034
00035 ON_BN_CLICKED(IDC_PASTEFROMCLIPBOARD, OnPastefromclipboard)
00036
00037 END_MESSAGE_MAP()
00038
00039 BOOL CDlg_CheckFileIntegrity::OnInitDialog()
00040 {
00041 CDialog::OnInitDialog();
00042
00043 LPCSTR ppszAlgs [] = {
00044 "MD5", "SHA-1", "SHA-2 256", "SHA-2 384", "SHA-2 512",
00045 "CRC 32"
00046 };
00047
00048 UINT ppnAlgs [] = {
00049 HA_MD5, HA_SHA1,
00050 HA_SHA2, HA_SHA2 + 1000 + HSHA2S_384, HA_SHA2 + 1000 + HSHA2S_512,
00051 HA_CRC32,
00052 };
00053
00054 CString strLastAlg = _App.Hash_LastAlgorithm ();
00055
00056 for (int i = 0; i < sizeof (ppszAlgs) / sizeof (LPCSTR); i++)
00057 {
00058 m_wndAlgorithm.AddString (ppszAlgs [i]);
00059 m_wndAlgorithm.SetItemData (i, ppnAlgs [i]);
00060 if (strLastAlg.CompareNoCase (ppszAlgs [i]) == 0)
00061 m_wndAlgorithm.SetCurSel (i);
00062 }
00063
00064 if (CB_ERR == m_wndAlgorithm.GetCurSel ())
00065 m_wndAlgorithm.SetCurSel (0);
00066
00067 ApplyLanguage ();
00068
00069 if (m_strChecksum.IsEmpty () == FALSE)
00070 {
00071 SetDlgItemText (IDC_CHECKSUM, m_strChecksum);
00072 UINT nAlg = m_nAlgorithm;
00073 if (nAlg == HA_SHA2 && m_nSHA2Strength != 0)
00074 nAlg += 1000 + m_nSHA2Strength;
00075 for (int i = 0; i < m_wndAlgorithm.GetCount (); i++)
00076 {
00077 if (m_wndAlgorithm.GetItemData (i) == nAlg)
00078 {
00079 m_wndAlgorithm.SetCurSel (i);
00080 break;
00081 }
00082 }
00083 }
00084 else
00085 {
00086 PasteChecksum (true);
00087 }
00088
00089 ((CEdit*)GetDlgItem (IDC_CHECKSUM))->SetSel (MAKELPARAM (-1, 0));
00090
00091 return TRUE;
00092
00093 }
00094
00095 void CDlg_CheckFileIntegrity::ApplyLanguage()
00096 {
00097 fsDlgLngInfo lnginfo [] = {
00098 fsDlgLngInfo (IDC__INFOMSG, L_CHECKINTEGRITY_INFOMSG),
00099 fsDlgLngInfo (IDC__ALGORITHM, L_ALGORITHM, TRUE),
00100 fsDlgLngInfo (IDC__CHECKSUM, L_CHECKSUM, TRUE),
00101 fsDlgLngInfo (IDC_PASTEFROMCLIPBOARD, L_PASTEFROMCLIPBOARD),
00102 fsDlgLngInfo (IDCANCEL, L_CANCEL),
00103 fsDlgLngInfo (IDOK, L_CHECK),
00104 };
00105
00106 _LngMgr.ApplyLanguage (this, lnginfo, sizeof (lnginfo) / sizeof (fsDlgLngInfo), L_CHECKFILEINTEGRITY);
00107 }
00108
00109 void CDlg_CheckFileIntegrity::OnOK()
00110 {
00111 m_nAlgorithm = m_wndAlgorithm.GetItemData (m_wndAlgorithm.GetCurSel ());
00112 m_nSHA2Strength = HSHA2S_256;
00113
00114 if (m_nAlgorithm >= 1000) {
00115 m_nSHA2Strength = m_nAlgorithm - HA_SHA2 - 1000;
00116 m_nAlgorithm = HA_SHA2;
00117 }
00118 if (m_nAlgorithm != HA_SHA2)
00119 m_nSHA2Strength = 0;
00120
00121 GetDlgItemText (IDC_CHECKSUM, m_strChecksum);
00122 if (m_strChecksum.GetLength () == 0)
00123 return;
00124
00125 CString str; m_wndAlgorithm.GetWindowText (str);
00126 _App.Hash_LastAlgorithm (str);
00127
00128 CDialog::OnOK();
00129 }
00130
00131 void CDlg_CheckFileIntegrity::OnPastefromclipboard()
00132 {
00133 PasteChecksum (false);
00134 }
00135
00136 void CDlg_CheckFileIntegrity::PasteChecksum(bool bCheckValid)
00137 {
00138 LPCSTR psz = _ClipbrdMgr.Text ();
00139 if (psz) {
00140 if (bCheckValid) {
00141 LPCSTR psz2 = psz;
00142 while (*psz2) {
00143 if (!(
00144 (*psz2 >= '0' && *psz2 <= '9') ||
00145 (*psz2 >= 'a' && *psz2 <= 'f') ||
00146 (*psz2 >= 'A' && *psz2 <= 'F') ||
00147 (*psz2 == ' ' || *psz2 == '-')
00148 ))
00149 return;
00150 psz2++;
00151 }
00152 }
00153 SetDlgItemText (IDC_CHECKSUM, psz);
00154 }
00155 }