Example #1
0
File: alcc.cpp Project: geekt/amule
/// Running Alcc
int alcc::OnRun ()
{
  // Used to tell alcc to use aMule catalog
  m_locale.Init();
  m_locale.AddCatalog(wxT(PACKAGE));

  wxLog::DontCreateOnDemand();
  wxLogStderr * stderrLog = new wxLogStderr;
  wxLogStderr * stdoutLog = new wxLogStderr(stdout);
  delete wxLog::SetActiveTarget(stderrLog); // Log on Stderr
#if wxCHECK_VERSION(2, 9, 0)
  wxLog::SetTimestamp("");   // Disable timestamp on messages
#else
  wxLog::SetTimestamp(NULL); // Disable timestamp on messages
#endif

  Ed2kHash hash;
  size_t i;
  for (i=0;i<(m_filesToHash.GetCount());++i)
    {
      if (wxFileExists(m_filesToHash[i]))
        {
          if (m_flagVerbose)
            {
              wxLogMessage(_("Processing file number %u: %s"),i+1,m_filesToHash[i].c_str());

              if (m_flagPartHashes)
                {
                  wxLogMessage(_("You have asked for part hashes (Only used for files > 9.5 MB)"));
                }
            }

          if (hash.SetED2KHashFromFile(m_filesToHash[i], NULL))
            {
				// Print the link to stdout
				wxLog::SetActiveTarget(stdoutLog);
                wxLogMessage(wxT("%s"), hash.GetED2KLink(m_flagPartHashes).c_str());
				// Everything else goes to stderr
				wxLog::SetActiveTarget(stderrLog);
            }
        }
      else
        {
            if (m_flagVerbose)
                {
                    wxLogMessage(_("%s ---> Non existant file !\n"),m_filesToHash[i].c_str());
                }
        }
    }
  return 0;
}
Example #2
0
/// Compute Hashes on Start Button
void 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"));
    }
}