void CCollectionCreateDialog::OnBnClickedOk() { //Some users have noted that the collection can at times //save a collection with a invalid name... OnEnKillFocusCollectionName(); CString sFileName; m_CollectionNameEdit.GetWindowText(sFileName); if (!sFileName.IsEmpty()) { m_pCollection->m_sCollectionAuthorName.Empty(); m_pCollection->SetCollectionAuthorKey(NULL, 0); m_pCollection->m_sCollectionName = sFileName; m_pCollection->m_bTextFormat = (m_CollectionCreateFormatCheck.GetCheck() == BST_CHECKED); CString sFilePath; sFilePath.Format(_T("%s\\%s.emulecollection"), thePrefs.GetMuleDirectory(EMULE_INCOMINGDIR), m_pCollection->m_sCollectionName); using namespace CryptoPP; RSASSA_PKCS1v15_SHA_Signer* pSignkey = NULL; if (m_CollectionCreateSignNameKeyCheck.GetCheck()) { bool bCreateNewKey = false; HANDLE hKeyFile = ::CreateFile(thePrefs.GetMuleDirectory(EMULE_CONFIGDIR) + _T("collectioncryptkey.dat"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hKeyFile != INVALID_HANDLE_VALUE) { if (::GetFileSize(hKeyFile, NULL) == 0) bCreateNewKey = true; ::CloseHandle(hKeyFile); } else bCreateNewKey = true; if (bCreateNewKey) { try { AutoSeededRandomPool rng; InvertibleRSAFunction privkey; privkey.Initialize(rng, 1024); Base64Encoder privkeysink(new FileSink(CStringA(thePrefs.GetMuleDirectory(EMULE_CONFIGDIR) + _T("collectioncryptkey.dat")))); privkey.DEREncode(privkeysink); privkeysink.MessageEnd(); } catch(...) { ASSERT(0); } } try { FileSource filesource(CStringA(thePrefs.GetMuleDirectory(EMULE_CONFIGDIR) + _T("collectioncryptkey.dat")), true,new Base64Decoder); pSignkey = new RSASSA_PKCS1v15_SHA_Signer(filesource); RSASSA_PKCS1v15_SHA_Verifier pubkey(*pSignkey); byte abyMyPublicKey[1000]; ArraySink asink(abyMyPublicKey, 1000); pubkey.DEREncode(asink); int nLen = asink.TotalPutLength(); asink.MessageEnd(); m_pCollection->SetCollectionAuthorKey(abyMyPublicKey, nLen); } catch(...) { ASSERT(0); } m_pCollection->m_sCollectionAuthorName = thePrefs.GetUserNick(); } if (!PathFileExists(sFilePath)) { m_pCollection->WriteToFileAddShared(pSignkey); } else { if (AfxMessageBox(GetResString(IDS_COLL_REPLACEEXISTING), MB_ICONWARNING | MB_ICONQUESTION | MB_DEFBUTTON2 | MB_YESNO) == IDNO) return; bool bDeleteSuccessful = ShellDeleteFile(sFilePath); if (bDeleteSuccessful) { CKnownFile* pKnownFile = theApp.knownfiles->FindKnownFileByPath(sFilePath); if (pKnownFile) { theApp.sharedfiles->RemoveFile(pKnownFile, true); if (pKnownFile->IsKindOf(RUNTIME_CLASS(CPartFile))) theApp.emuledlg->transferwnd->GetDownloadList()->ClearCompleted(static_cast<CPartFile*>(pKnownFile)); } m_pCollection->WriteToFileAddShared(pSignkey); } else { AfxMessageBox(GetResString(IDS_COLL_ERR_DELETING),MB_ICONWARNING | MB_ICONQUESTION | MB_DEFBUTTON2 | MB_YESNO); } } delete pSignkey; pSignkey = NULL; OnOK(); } }
BOOL CSharedDirsTreeCtrl::OnCommand(WPARAM wParam, LPARAM lParam) { CTypedPtrList<CPtrList, CKnownFile*> selectedList; int iSelectedItems = m_pSharedFilesCtrl->GetItemCount(); for (int i = 0; i < iSelectedItems; i++) { selectedList.AddTail((CKnownFile*)m_pSharedFilesCtrl->GetItemData(i)); } CDirectoryItem* pSelectedDir = GetSelectedFilter(); // folder based if (pSelectedDir != NULL){ switch (wParam){ case MP_OPENFOLDER: if (pSelectedDir && pSelectedDir->m_eItemType == SDI_NO){ ShellExecute(NULL, _T("open"), pSelectedDir->m_strFullPath, NULL, NULL, SW_SHOW); } break; case MP_SHAREDIR: EditSharedDirectories(pSelectedDir, true, false); break; case MP_SHAREDIRSUB: EditSharedDirectories(pSelectedDir, true, true); break; case MP_UNSHAREDIR: EditSharedDirectories(pSelectedDir, false, false); break; case MP_UNSHAREDIRSUB: EditSharedDirectories(pSelectedDir, false, true); break; } } // file based if (selectedList.GetCount() > 0 && pSelectedDir != NULL) { CKnownFile* file = NULL; if (selectedList.GetCount() == 1) file = selectedList.GetHead(); switch (wParam){ case MP_GETED2KLINK:{ CString str; POSITION pos = selectedList.GetHeadPosition(); while (pos != NULL) { file = selectedList.GetNext(pos); if (!str.IsEmpty()) str += _T("\r\n"); str += CreateED2kLink(file); } theApp.CopyTextToClipboard(str); break; } // file operations case MP_REMOVE: case MPG_DELETE:{ if (IDNO == AfxMessageBox(GetResString(IDS_CONFIRM_FILEDELETE),MB_ICONWARNING | MB_ICONQUESTION | MB_DEFBUTTON2 | MB_YESNO)) return TRUE; m_pSharedFilesCtrl->SetRedraw(FALSE); bool bRemovedItems = false; while (!selectedList.IsEmpty()) { CKnownFile* myfile = selectedList.RemoveHead(); if (!myfile || myfile->IsPartFile()) continue; BOOL delsucc = FALSE; if (!PathFileExists(myfile->GetFilePath())) delsucc = TRUE; else{ // Delete if (!thePrefs.GetRemoveToBin()){ delsucc = DeleteFile(myfile->GetFilePath()); } else{ // delete to recycle bin :( TCHAR todel[MAX_PATH+1]; memset(todel, 0, sizeof todel); _tcsncpy(todel, myfile->GetFilePath(), ARRSIZE(todel)-2); SHFILEOPSTRUCT fp = {0}; fp.wFunc = FO_DELETE; fp.hwnd = theApp.emuledlg->m_hWnd; fp.pFrom = todel; fp.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_SILENT;// | FOF_NOERRORUI delsucc = (SHFileOperation(&fp) == 0); } } if (delsucc){ theApp.sharedfiles->RemoveFile(myfile); bRemovedItems = true; if (myfile->IsKindOf(RUNTIME_CLASS(CPartFile))) theApp.emuledlg->transferwnd->downloadlistctrl.ClearCompleted(static_cast<CPartFile*>(myfile)); } else{ CString strError; strError.Format( GetResString(IDS_ERR_DELFILE) + _T("\r\n\r\n%s"), myfile->GetFilePath(), GetErrorMessage(GetLastError())); AfxMessageBox(strError); } } m_pSharedFilesCtrl->SetRedraw(TRUE); if (bRemovedItems) m_pSharedFilesCtrl->AutoSelectItem(); break; } case MP_CMT: ShowFileDialog(selectedList, IDD_COMMENT); break; case MPG_ALTENTER: case MP_DETAIL: ShowFileDialog(selectedList); break; case MP_SHOWED2KLINK: ShowFileDialog(selectedList, IDD_ED2KLINK); break; case MP_PRIOVERYLOW: case MP_PRIOLOW: case MP_PRIONORMAL: case MP_PRIOHIGH: case MP_PRIOVERYHIGH: case MP_PRIOAUTO: { POSITION pos = selectedList.GetHeadPosition(); while (pos != NULL) { CKnownFile* file = selectedList.GetNext(pos); switch (wParam) { case MP_PRIOVERYLOW: file->SetAutoUpPriority(false); file->SetUpPriority(PR_VERYLOW); m_pSharedFilesCtrl->UpdateFile(file); break; case MP_PRIOLOW: file->SetAutoUpPriority(false); file->SetUpPriority(PR_LOW); m_pSharedFilesCtrl->UpdateFile(file); break; case MP_PRIONORMAL: file->SetAutoUpPriority(false); file->SetUpPriority(PR_NORMAL); m_pSharedFilesCtrl->UpdateFile(file); break; case MP_PRIOHIGH: file->SetAutoUpPriority(false); file->SetUpPriority(PR_HIGH); m_pSharedFilesCtrl->UpdateFile(file); break; case MP_PRIOVERYHIGH: file->SetAutoUpPriority(false); file->SetUpPriority(PR_VERYHIGH); m_pSharedFilesCtrl->UpdateFile(file); break; case MP_PRIOAUTO: file->SetAutoUpPriority(true); file->UpdateAutoUpPriority(); m_pSharedFilesCtrl->UpdateFile(file); break; } } break; } default: if (wParam>=MP_WEBURL && wParam<=MP_WEBURL+256){ theWebServices.RunURL(file, wParam); } break; } } return TRUE; }