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

📄 alcframe.cpp

📁 电驴的MAC源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  SetFileToHash();}/// Set File to hash in wxTextCtrlvoidAlcFrame::SetFileToHash(){#ifdef __WXMSW__	wxString browseroot;	LPITEMIDLIST pidl;	HRESULT hr = SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &pidl);	if (SUCCEEDED(hr)) {		if (!SHGetPathFromIDList(pidl, wxStringBuffer(browseroot, MAX_PATH))) {			browseroot = wxFileName::GetHomeDir();		}	} else {		browseroot = wxFileName::GetHomeDir();	}	if (pidl) {		LPMALLOC pMalloc;		SHGetMalloc(&pMalloc);		if (pMalloc) {			pMalloc->Free(pidl);			pMalloc->Release();		}	}#elif defined(__WXMAC__)	FSRef fsRef;	wxString browseroot;	if (FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &fsRef) == noErr)	{		CFURLRef	urlRef		= CFURLCreateFromFSRef(NULL, &fsRef);		CFStringRef	cfString	= CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle);		CFRelease(urlRef) ;		browseroot = wxMacCFStringHolder(cfString).AsString(wxLocale::GetSystemEncoding());	} else {		browseroot = wxFileName::GetHomeDir();	}#else	wxString browseroot = wxFileName::GetHomeDir();#endif  const wxString & filename =    wxFileSelector (_("Select the file you want to compute the eD2k link"),                    browseroot, wxEmptyString, wxEmptyString, wxT("*.*"),                    wxFD_OPEN | wxFD_FILE_MUST_EXIST, this);  if (!filename.empty ())    {      m_inputFileTextCtrl->SetValue(filename);    }}/// Toolbar Save As buttonvoidAlcFrame::OnBarSaveAs (wxCommandEvent & WXUNUSED(event)){  SaveEd2kLinkToFile();}/// Save As buttonvoidAlcFrame::OnSaveAsButton(wxCommandEvent & WXUNUSED(event)){  SaveEd2kLinkToFile();}/// Copy Ed2k link to clip boardvoidAlcFrame::CopyEd2kLinkToClipBoard(){  wxString link = m_ed2kTextCtrl->GetValue();  if (!link.IsEmpty())    {      wxClipboardLocker clipLocker;      if ( !clipLocker )        {          wxLogError(_("Can't open the clipboard"));          return;        }      wxTheClipboard->AddData(new wxTextDataObject(link));    }  else    {      SetStatusText (_("Nothing to copy for now !"));    }}/// Copy buttonvoidAlcFrame::OnCopyButton(wxCommandEvent & WXUNUSED(event)){  CopyEd2kLinkToClipBoard();}/// Toolbar Copy buttonvoidAlcFrame::OnBarCopy(wxCommandEvent & WXUNUSED(event)){  CopyEd2kLinkToClipBoard();}/// Save computed Ed2k link to filevoidAlcFrame::SaveEd2kLinkToFile(){  wxString link(m_ed2kTextCtrl->GetValue());  if (!link.IsEmpty())    {      const wxString & filename =        wxFileSelector (_("Select the file to your computed eD2k link"),                        wxFileName::GetHomeDir(),wxT("my_ed2k_link"),                        wxT("txt"), wxT("*.txt"), wxFD_SAVE, this);      if (!filename.empty ())        {          // Open file and let wxFile destructor close the file          // Closing it explicitly may crash on Win32 ...          wxFile file(filename,wxFile::write_append);          if (! file.IsOpened())            {              SetStatusText (_("Unable to open ") + filename);              return;            }          file.Write(link + wxTextFile::GetEOL());        }      else        {          SetStatusText (_("Please, enter a non empty file name"));        }    }  else    {      SetStatusText (_("Nothing to save for now !"));    }}/// Toolbar About buttonvoidAlcFrame::OnBarAbout (wxCommandEvent & WXUNUSED(event)){  wxMessageBox (_                ("aLinkCreator, the aMule eD2k link creator\n\n(c) 2004 ThePolish <thepolish@vipmail.ru>\n\nPixmaps from http://www.everaldo.com and http://www.icomania.com\nand http://jimmac.musichall.cz/ikony.php3\n\nDistributed under GPL"),                _("About aLinkCreator"), wxOK | wxCENTRE | wxICON_INFORMATION);}/// Close Buttonvoid AlcFrame::OnCloseButton (wxCommandEvent & WXUNUSED(event)){  Close (false);}/// Hook into MD4/ED2K routinebool AlcFrame::Hook(int percent){  // Update progress bar  bool goAhead = ::wxGetApp().GetMainFrame()->m_progressBar->Update(percent);  if (!goAhead)    {      // Destroying progressbar: no merci for croissants !      ::wxGetApp().GetMainFrame()->m_progressBar->Destroy();      // Now, be paranoid      delete ::wxGetApp().GetMainFrame()->m_progressBar;      ::wxGetApp().GetMainFrame()->m_progressBar = NULL;    }  return (goAhead);}/// Compute Hashes on Start Buttonvoid AlcFrame::OnStartButton (wxCommandEvent & WXUNUSED(event)){  size_t i;  wxString filename = m_inputFileTextCtrl->GetValue();  if (!filename.empty ())    {      // Initialize computation      m_goAhead=true;      // Chrono      wxStopWatch chrono;      // wxFileName needed for base name      wxFileName fileToHash(filename);      // Set waiting msg      m_e2kHashTextCtrl->SetValue(_("Hashing..."));      m_ed2kTextCtrl->SetValue(_("Hashing..."));#ifdef WANT_MD4SUM      // Create MD4 progress bar dialog      m_progressBar=new wxProgressDialog  (_("aLinkCreator is working for you"), _("Computing MD4 Hash..."),                                           100, this, wxPD_AUTO_HIDE | wxPD_CAN_ABORT | wxPD_REMAINING_TIME);      m_md4HashTextCtrl->SetValue(_("Hashing..."));      // Md4 hash      MD4 md4;      m_md4HashTextCtrl->SetValue(md4.calcMd4FromFile(filename,Hook));      // Deleting MD4 progress bar dialog      delete m_progressBar;      m_progressBar=NULL;#endif      // Create ED2K progress bar dialog      m_progressBar=new wxProgressDialog  (_("aLinkCreator is working for you"), _("Computing eD2k Hashes..."),                                           100, this, wxPD_AUTO_HIDE | wxPD_CAN_ABORT | wxPD_REMAINING_TIME);      // Compute ed2k Hash      Ed2kHash hash;      // Test the return value to see if was aborted.      if (hash.SetED2KHashFromFile(filename, Hook))        {          wxArrayString ed2kHash (hash.GetED2KHash());          // Get URLs          wxArrayString arrayOfUrls;          wxString url;          for (i=0;i < m_inputUrlListBox->GetCount();++i)            {              url=m_inputUrlListBox->GetString(i);              if (url.Right(1) == wxT("/"))                {                  url += fileToHash.GetFullName();                }		arrayOfUrls.Add(wxURI(url).BuildURI());            }          arrayOfUrls.Shrink(); // Reduce memory usage          // Ed2k hash          m_e2kHashTextCtrl->SetValue(ed2kHash.Last());          // Ed2k link          m_ed2kTextCtrl->SetValue(hash.GetED2KLink(m_parthashesCheck->IsChecked(), &arrayOfUrls));        }      else        {          // Set cancelled msg          m_e2kHashTextCtrl->SetValue(_("Cancelled !"));          m_ed2kTextCtrl->SetValue(_("Cancelled !"));        }      // Deleting progress bar dialog      delete m_progressBar;      m_progressBar=NULL;      // Set status text      SetStatusText (wxString::Format(_("Done in %.2f s"),                                      chrono.Time()*.001));    }  else    {      // Set status text      SetStatusText (_("Please, enter a non empty file name"));    }}/// Add an URL to the URL list boxvoidAlcFrame::OnAddUrlButton (wxCommandEvent & WXUNUSED(event)){  wxString url(m_inputAddTextCtrl->GetValue());  if (!url.IsEmpty())    {      // Check if the URL already exist in list      size_t i;      bool UrlNotExists = true;      for (i=0;i < m_inputUrlListBox->GetCount();++i)        {          if (url == m_inputUrlListBox->GetString(i))            {              UrlNotExists =false;              break;            }        }      // Add only a not already existant URL      if (UrlNotExists)        {	  m_inputUrlListBox->Append(wxURI(url).BuildURI());          m_inputAddTextCtrl->SetValue(wxEmptyString);        }      else        {          wxLogError(_("You have already added this URL !"));        }    }  else    {      SetStatusText (_("Please, enter a non empty URL"));    }}/// Remove the selected URL from the URL list boxvoidAlcFrame::OnRemoveUrlButton (wxCommandEvent & WXUNUSED(event)){  m_inputUrlListBox->Delete(m_inputUrlListBox->GetSelection());}/// Clear the URL list boxvoidAlcFrame::OnClearUrlButton (wxCommandEvent & WXUNUSED(event)){  m_inputUrlListBox->Clear();}// File_checked_for_headers

⌨️ 快捷键说明

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