// MainDlg.h : interface of the CMainDlg class // ///////////////////////////////////////////////////////////////////////////// #include "rtsverif.h" #pragma once class CMainDlg : public CDialogImpl { public: WTL::CComboBoxEx m_DrvCombo;// комбо со списком драйвов WTL::CListViewCtrl m_FileList,m_DirList; // листвью с файлами и директориями HIMAGELIST m_hImageList; // системный имажлист char m_CurrentDir[_MAX_PATH*4];//текущая директория int m_iDirCount,m_iFileCount;// количество директорий, количество файлов в текущей диретории VHANDLE vHandle; RTSVPipeConnection vpipe;// структура коннекта для верифа BOOL VerifEnable; enum { IDD = IDD_MAINDLG }; BEGIN_MSG_MAP(CMainDlg) MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) COMMAND_ID_HANDLER(ID_APP_ABOUT, OnAppAbout) COMMAND_ID_HANDLER(IDOK, OnOK) COMMAND_ID_HANDLER(IDCANCEL, OnCancel) NOTIFY_ID_HANDLER(IDC_LIST1,OnDirListNotify) NOTIFY_ID_HANDLER(IDC_LIST2,OnFileListNotify) COMMAND_ID_HANDLER(IDC_COMBO1,OnDriveComboCommand) COMMAND_HANDLER(IDB_REFRESH, BN_CLICKED, OnBnClickedRefresh) END_MSG_MAP() // Handler prototypes (uncomment arguments if needed): // LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) // LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) // LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/) LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) { LONG wl; // center the dialog on the screen CenterWindow(); // set icons HICON hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME), IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR); SetIcon(hIcon, TRUE); HICON hIconSmall = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR); SetIcon(hIconSmall, FALSE); m_DrvCombo = GetDlgItem(IDC_COMBO1); wl = m_DrvCombo.GetWindowLong(GWL_STYLE); m_DrvCombo.SetWindowLong(GWL_STYLE,wl|CBS_HASSTRINGS|CBS_SORT); m_hImageList = GetSystemImageList();//получить системный имажлист //заполнение комбобокса списком дисков. char buf[255]; SHFILEINFO shfi; COMBOBOXEXITEM cbx; m_DrvCombo.SetImageList(m_hImageList); cbx.mask = CBEIF_TEXT|CBEIF_IMAGE|CBEIF_SELECTEDIMAGE; GetLogicalDriveStrings(255,buf); char *tmp=buf; int i=0; while(*tmp){ SHGetFileInfo(tmp,0,&shfi,sizeof(SHFILEINFO), SHGFI_SYSICONINDEX|SHGFI_SMALLICON); cbx.pszText=tmp; cbx.cchTextMax=4; cbx.iItem=i++; cbx.iImage=shfi.iIcon; cbx.iSelectedImage = shfi.iIcon; int ret = m_DrvCombo.InsertItem (&cbx); tmp+=StrSpn(tmp,tmp)+1; } // подготовка списков файлов и директорий m_FileList=GetDlgItem(IDC_LIST2); wl = m_FileList.GetWindowLong(GWL_STYLE); m_FileList.SetWindowLong(GWL_STYLE,wl|LVS_SHAREIMAGELISTS); m_FileList.SetImageList(m_hImageList,LVSIL_SMALL); m_DirList = GetDlgItem(IDC_LIST1); wl = m_DirList.GetWindowLong(GWL_STYLE); m_DirList.SetWindowLong(GWL_STYLE,wl|LVS_SHAREIMAGELISTS); m_DirList.SetImageList(m_hImageList,LVSIL_SMALL); m_DirList.AddColumn(" Go to Up Directory ",0); // Отображение директорий и файлов GetPrivateProfileString("OPTIONS","CurrentDir","A:\\",m_CurrentDir,_MAX_PATH*4,".\\VerifGui.ini"); // StrCpy(m_CurrentDir,"C:\\"); i=0; if(!PathFileExists(m_CurrentDir)){ PathStripToRoot(m_CurrentDir); if(!PathFileExists(m_CurrentDir)){ m_CurrentDir[0]='A'-1; do{ m_CurrentDir[0]++; i++; }while (!PathFileExists(m_CurrentDir)&&(m_CurrentDir[0]<(25+48))) ; if ((m_CurrentDir[0]>=(25+48))) { MessageBox("Can't find any drive","ERROR"); EndDialog(-1); } } } SetDrive(m_CurrentDir); SetDlgItemText(IDC_STATIC,m_CurrentDir); RefreshLists(); GetPrivateProfileString("OPTIONS","Pipe","\\\\.\\pipe\\rtsverif",buf,254,".\\VerifGui.ini"); // StrCpy(buf,"\\\\.\\pipe\\rtsverif"); StrCpy(vpipe.name,buf); vpipe.initTimeout=vpipe.operTimeout=5000; if(!(vHandle=RTSVInit(RTSV_PIPE,&vpipe))) { MessageBox("Can't open verif system","Verif error"); VerifEnable=FALSE; } else VerifEnable=TRUE; return TRUE; } LRESULT OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { CSimpleDialog dlg; dlg.DoModal(); return 0; } LRESULT OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { char cFile[_MAX_PATH*4],cName[_MAX_PATH],cError[20],cErrText[50]; int iNum = m_FileList.GetSelectionMark(); int Error; m_FileList.GetItemText(iNum,0,cName,_MAX_PATH); PathCombine(cFile,m_CurrentDir,cName); if(!(Error = VerifyFile(cFile))){ MessageBox("SIGNATURE IS OK","OK"); RefreshLists(); } else { switch (Error){ case 1: MessageBox("WRONG KEY","ERROR"); break; case 2: break; default: wnsprintf(cError,19,"0x%04X",Error); StrCpy(cErrText,"FILE IS NOT VALID - "); StrCat(cErrText,cError); MessageBox(cErrText,"ERROR CHECK"); } } return 0; } LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { FinalizeWork(); EndDialog(wID); return 0; } int ShowFiles(CListViewCtrl* lv, char* CurrentDir,BOOL Dir)//Dir - ищутся директории { lv->DeleteAllItems(); WIN32_FIND_DATA findData; char Path[_MAX_PATH*4], FileName[_MAX_PATH*4]; PathCombine(Path,CurrentDir,"*"); BOOL Res=TRUE; SHFILEINFO shfi; UINT attr; HANDLE hFind = ::FindFirstFile(Path,&findData); int* Count=&m_iFileCount; if (Dir) Count=&m_iDirCount; while((hFind!=INVALID_HANDLE_VALUE)&&Res){ PathCombine(FileName,CurrentDir,findData.cFileName); SHGetFileInfo(FileName,0,&shfi,sizeof(SHFILEINFO), SHGFI_SYSICONINDEX|SHGFI_SMALLICON); attr=findData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY; BOOL bname = StrCmp(findData.cFileName,".")&&StrCmp(findData.cFileName,".."); if((Dir ==(attr&&TRUE)) && (bname) ) lv->AddItem((*Count)++,0,findData.cFileName,shfi.iIcon); Res = FindNextFile(hFind,&findData); } FindClose(hFind); return 0; } HIMAGELIST GetSystemImageList(bool BigIcon=FALSE) { HRESULT hRes = NULL; HIMAGELIST hImage = NULL; SHFILEINFO shfi; ITEMIDLIST* pidl; IMalloc* pMalloc; hRes = SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidl); hImage = (HIMAGELIST)SHGetFileInfo((LPCSTR)pidl, 0, &shfi, sizeof(SHFILEINFO), SHGFI_PIDL | SHGFI_SYSICONINDEX | (BigIcon ? SHGFI_LARGEICON : SHGFI_SMALLICON)); hRes = SHGetMalloc(&pMalloc); pMalloc->Free(pidl); pMalloc->Release(); return hImage; } LRESULT OnDirListNotify(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/){ LPNMITEMACTIVATE itemAct= (LPNMITEMACTIVATE)pnmh; char cName[_MAX_PATH*4]; switch(pnmh->code){ case NM_CLICK: if(itemAct->iItem<0) break; m_DirList.GetItemText(itemAct->iItem,0,cName,_MAX_PATH*4); PathAppend(m_CurrentDir,cName); SetDlgItemText(IDC_STATIC,m_CurrentDir); RefreshLists(); break; case LVN_COLUMNCLICK : PathAppend(m_CurrentDir,".."); SetDlgItemText(IDC_STATIC,m_CurrentDir); RefreshLists(); break; } return 0; } LRESULT OnFileListNotify(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/){ LPNMITEMACTIVATE itemAct= (LPNMITEMACTIVATE)pnmh; char cName[_MAX_PATH*4],cFullName[_MAX_PATH*4]; switch(pnmh->code){ case NM_DBLCLK: if(itemAct->iItem<0) break; m_FileList.GetItemText(itemAct->iItem,0,cName,_MAX_PATH*4); PathCombine(cFullName,m_CurrentDir,cName); ShellExecute(m_hWnd,"",cName,"",m_CurrentDir,SW_SHOWDEFAULT); break; } return 0; } LRESULT OnDriveComboCommand(WORD wNotifyCode, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/){ char cDrv[10]; switch(wNotifyCode){ case CBN_SELCHANGE: //MessageBox("Ok"); m_DrvCombo.GetLBText(m_DrvCombo.GetCurSel(),cDrv); if(PathFileExists(cDrv)){ StrCpy(m_CurrentDir,cDrv); SetDlgItemText(IDC_STATIC,m_CurrentDir); RefreshLists(); } else{ MessageBox("Drive not availiable","ERROR"); PathStripToRoot(m_CurrentDir); SetDlgItemText(IDC_STATIC,m_CurrentDir); SetDrive(m_CurrentDir); } break; } return 0; } void RefreshLists(void) { m_iDirCount=m_iFileCount=0; ShowFiles(&m_DirList,m_CurrentDir,TRUE); ShowFiles(&m_FileList,m_CurrentDir,FALSE); } void SetDrive(char* cDrv) { char tempstr[6]; //StrNCpy(cRoot,cDrv,3); for(int i=0;i