Пример #1
0
void
DownloadManagerThread::Tick()
{
  Net::Session session;

  while (!queue.empty() && !StandbyThread::IsStopped()) {
    assert(current_size == -1);
    assert(current_position == -1);

    const Item &item = queue.front();
    current_position = 0;
    mutex.Unlock();

    TCHAR path[MAX_PATH];
    LocalPath(path, item.path_relative.c_str());

    TCHAR tmp[MAX_PATH];
    _tcscpy(tmp, path);
    _tcscat(tmp, _T(".tmp"));
    File::Delete(tmp);
    bool success =
      DownloadToFile(session, item.uri.c_str(), tmp, NULL, *this) &&
      File::Replace(tmp, path);

    mutex.Lock();
    current_size = current_position = -1;
    const Item copy(std::move(queue.front()));
    queue.pop_front();
    for (auto i = listeners.begin(), end = listeners.end(); i != end; ++i)
      (*i)->OnDownloadComplete(copy.path_relative.c_str(), success);
  }
}
Пример #2
0
void
Net::DownloadToFileJob::Run(OperationEnvironment &env)
{
  success = DownloadToFile(session, url, path, md5_digest,env);
}