Пример #1
0
bool CTorrent::AddTorrentFromFile(const QByteArray& Torrent)
{
    CFile* pFile = GetFile();

    m_TorrentInfo = new CTorrentInfo(this);
    if(!m_TorrentInfo->LoadTorrentFile(Torrent))
        return false;

    // Privat etorrents should only be shared on the torrent network
    // Note: we overwrite any user choices except the file is completed than the use has all liberties
    if(pFile->IsIncomplete() && m_TorrentInfo->IsPrivate())
        pFile->SetProperty("Torrent", 2);

    if(!pFile->IsPending())
        SaveTorrentToFile();

    pFile->SetFileSize(m_TorrentInfo->GetTotalLength());
    LoadPieceHashes();

    theCore->m_TorrentManager->RegisterInfoHash(m_TorrentInfo->GetInfoHash());

    pFile->SetMasterHash(m_pHash);

    pFile->SetFileName(m_TorrentInfo->GetTorrentName());

    pFile->SetProperty("Description", m_TorrentInfo->GetProperty("Description"));

    SetupPartMap();

    return true;
}
Пример #2
0
bool CTorrent::InstallMetadata()
{
    CFile* pFile = GetFile();

    ASSERT(m_TorrentInfo);

    CPartMap* pPartMap = pFile->GetPartMap();
    if(pPartMap && !CompareSubFiles(pPartMap))
    {
        if(pFile->GetInspector()->BadMetaData(GetHash()))
            pPartMap = NULL;
        else
            return false;
    }

    if(m_pHash->Compare(pFile->GetMasterHash().data()))
        pFile->SetFileName(m_TorrentInfo->GetTorrentName());

    bool bOpenIO = false;
    CJoinedPartMap* pJoinedParts = qobject_cast<CJoinedPartMap*>(pPartMap);
    if((pPartMap == NULL && !pFile->IsComplete()) || (pJoinedParts && pJoinedParts->GetLinks().isEmpty()))
    {
        bOpenIO = true;
        if(!pPartMap)
            pFile->SetFileSize(m_TorrentInfo->GetTotalLength());

        SetupPartMap();

        if(!pPartMap && !pFile->IsPending())
            pFile->SetFilePath();
    }

    LoadPieceHashes();

    if(pFile->IsIncomplete() && pFile->GetMasterHash()->GetType() == HashTorrent)
        pFile->CleanUpHashes();

    // Note: if neo is the masterhash the IO is already opened
    if(bOpenIO && !pFile->IsPending())
        pFile->Resume();
    return true;
}