void vmsTrafficUsageModeMgr::CheckNeedResetAllSpeedsInfo(void)
{
	if (!(m_dwState & TUMM_SPEEDS_INFO_CAN_BE_INCORRECT))
		return;

	bool bAllUsesCurrentAdapter = true;

	vmsAUTOLOCKSECTION (m_csManageForSpeed);

	for (size_t i = 0; bAllUsesCurrentAdapter && i < m_vpManageForSpeed.size (); i++)
	{
		ManageForSpeedItemsList *pList = m_vpManageForSpeed [i];

		for (size_t j = 0; bAllUsesCurrentAdapter && j < pList->vItems.size (); j++)
		{
			if (pList->vItems [j].state & ManageForSpeedItem::MSIS_MAY_USE_NOT_CURRENT_ADAPTER)
				bAllUsesCurrentAdapter = false;
		}
	}

	vmsAUTOLOCKSECTION_UNLOCK (m_csManageForSpeed);

	if (!bAllUsesCurrentAdapter)
		return;

	vmsAUTOLOCKSECTION (m_csMisc);
	m_dwState &= ~TUMM_SPEEDS_INFO_CAN_BE_INCORRECT;
	vmsAUTOLOCKSECTION_UNLOCK (m_csMisc);

	ResetAllSpeedsInfo ();
	ReadCurrentAdapterInfo ();
}
void vmsTrafficUsageModeMgr::CheckIfBestInterfaceChanged ()
{
	vmsIpHelper iph;
	if (!iph.GetAdaptersInfo ())
		return;

	DWORD dwIfIndex;
	if (NO_ERROR != GetBestInterface (inet_addr ("8.8.8.8"), &dwIfIndex))
		return;

	PIP_ADAPTER_INFO pAdapter = iph.FindAdapterByIfIndex (dwIfIndex);
	if (!pAdapter)
		return;

	if (pAdapter->IpAddressList.IpAddress.String == m_strCurrentIP)
		return;

	if (!(m_dwState & TUMM_SPEEDS_INFO_CAN_BE_INCORRECT))
		SaveCurrentAdapterInfo ();

	std::string strAdapterAddress;
	for (UINT i = 0; i < pAdapter->AddressLength; i++)
	{
		char sz [10];
		itoa (pAdapter->Address [i], sz, 16);
		if (sz [1] == 0)
			strAdapterAddress += '0';
		strAdapterAddress += sz;
	}

	m_strCurrentAdapterAddress = strAdapterAddress;
	m_strCurrentIP = pAdapter->IpAddressList.IpAddress.String;

	vmsAUTOLOCKSECTION (m_csMisc);
	m_dwState |= TUMM_SPEEDS_INFO_CAN_BE_INCORRECT;
	vmsAUTOLOCKSECTION_UNLOCK (m_csMisc);

	vmsAUTOLOCKSECTION (m_csManageForSpeed);
	
	for (size_t i = 0; i < m_vpManageForSpeed.size (); i++)
	{
		ManageForSpeedItemsList *pList = m_vpManageForSpeed [i];

		for (size_t j = 0; j < pList->vItems.size (); j++)
			pList->vItems [j].state |= ManageForSpeedItem::MSIS_MAY_USE_NOT_CURRENT_ADAPTER;
	}
	vmsAUTOLOCKSECTION_UNLOCK (m_csManageForSpeed);

	ResetAllSpeedsInfo ();
}
void vmsBrowserActivityMonitor::RemoveItem(size_t nIndex)
{
	assert (nIndex < m_vList.size ());
	m_bsd.ModifyActiveDownloadsCount (-1);
	vmsAUTOLOCKSECTION (m_csList);
	m_vList.erase (m_vList.begin () + nIndex);
}
void vmsTrafficUsageModeMgr::ResetAllSpeedsInfo(bool bForDownload)
{
	vmsAUTOLOCKSECTION (m_csManageForSpeed);

	NetworkStat &ns = refgetNetworkStat (bForDownload);
	ns.bandwidthMeasureStart.Reset ();
	ns.uConnectionBandwidth = ns.uCurrentBandwidth = UINT64_MAX;
	ns.vTotalSpeed.clear ();
	ns.currentBandwidthExplorer.Reset ();
	ns.currentBandwidthExploreInLimitedMode.Reset ();

	for (size_t i = 0; i < m_vpManageForSpeed.size (); i++)
	{
		ManageForSpeedItemsList *pList = m_vpManageForSpeed [i];

		pList->vTotalSpeed.clear ();
		pList->totalSpeedExplorer.Reset ();

		for (size_t j = 0; j < pList->vItems.size (); j++)
		{
			ManageForSpeedItem *pItem = &pList->vItems [j];
			pItem->getData (bForDownload).vSpeed.clear ();
		}
	}
}
Exemplo n.º 5
0
void CWGUrlReceiver::StartJobThread(LPTHREAD_START_ROUTINE pfn)
{
	UIThread *thr = (UIThread*) RUNTIME_CLASS (UIThread)->CreateObject ();
	_ic_DownloadInfo* dlinfo = new _ic_DownloadInfo;
	*dlinfo = m_dlInfo;

	if (pfn == _threadAddPage  ||
			(!dlinfo->bForceSilent && !_App.Monitor_Silent ()))
	{
		CComObject <CFdmUiWindow> *pUiWindow = NULL;		
		CComObject <CFdmUiWindow>::CreateInstance (&pUiWindow);
		dlinfo->pUiWindow = pUiWindow;
		if (pUiWindow)
			pUiWindow->AddRef ();
		vmsAUTOLOCKSECTION (m_csLastUiWindow);
		m_spLastUiWindow = pUiWindow;
	}
	else
	{
		dlinfo->pUiWindow = NULL;
	}

	thr->set_Thread (pfn, dlinfo);
	thr->CreateThread ();

	if (m_hJobt)
		CloseHandle (m_hJobt);

	DuplicateHandle (GetCurrentProcess (), thr->m_hThread, GetCurrentProcess (),
		&m_hJobt, 0, TRUE, DUPLICATE_SAME_ACCESS);
}
fsInternetResult vmsTpDownloadMgr::SetToRestartState()
{
	vmsAUTOLOCKSECTION (m_csDownload);

	
	m_info.dwFastResumeDataSize = 0;

	
		
	m_info.nUploadedBytes = 0;
	m_info.fShareRating = 0;
	m_info.nWastedBytes = 0;
	m_info.fPercentDone = 0;
	m_info.bDone = FALSE;
	m_info.nDownloadedBytes = 0;

	setDirty();

	if (m_enAER != AER_RENAME_2)
	{
		if (FALSE == DeleteFile ())
			return IR_ERROR;
	}
	else
		m_bRename_CheckIfRenamed = TRUE;

	if (m_dldr) m_dldr->ReStart();

	return IR_SUCCESS;
}
Exemplo n.º 7
0
void vmsBtSessionImpl::RestoreDownloadHandle (vmsBtDownloadImpl* dld)
{
	vmsAUTOLOCKSECTION (m_csRestoreTorrentHandle);

	if (dld == NULL || dld->GetHandle().is_valid ())
		return;

	try 
	{
		vmsBtFileImplPtr dldImpl = dld->GetTorrentImpl();
		if (dldImpl == NULL || dldImpl->m_torrent == NULL)
		{
			return;
		}
		libtorrent::torrent_handle& handleLink = dld->GetHandle();
		handleLink = m_session.add_torrent(*dldImpl->m_torrent, dld->GetOutputPath());
		dld->GetHandle().pause();
	}
	catch (...) 
	{
		return;
	}

	vmsAUTOLOCKSECTION_UNLOCK (m_csRestoreTorrentHandle);

	if (m_pfnEvHandler)
	{
		vmsBtSessionEvent ev;
		ev.enType = BTSET_BTDLD_WAS_RESET;
		ev.pDownload = dld;
		ev.pszMsg = NULL;
		m_pfnEvHandler (this, &ev, m_pEvData);
	}
}
Exemplo n.º 8
0
void vmsOverlappedWinsockCalls::RemoveCall(int nIndex)
{
	assert (nIndex >= 0 && nIndex < m_vCalls.size ());
	if (nIndex < 0 || size_t (nIndex) >= m_vCalls.size ())
		return;
	vmsAUTOLOCKSECTION (m_csCalls);
	m_vCalls.erase (m_vCalls.begin () + nIndex);
}
Exemplo n.º 9
0
vmsOverlappedWinsockCalls::Call* vmsOverlappedWinsockCalls::getCall(int nIndex)
{
	assert (nIndex >= 0 && nIndex < m_vCalls.size ());
	if (nIndex < 0 || size_t (nIndex) >= m_vCalls.size ())
		return NULL;
	vmsAUTOLOCKSECTION (m_csCalls);
	return &m_vCalls [nIndex];
}
Exemplo n.º 10
0
int vmsBtSessionImpl::get_TotalDownloadConnectionCount ()
{
	vmsAUTOLOCKSECTION (m_csDownloads);
	int n = 0;
	for (size_t i = 0; i < m_vDownloads.size (); i++)
		n += m_vDownloads [i]->get_DownloadConnectionCount ();
	return n;
}
Exemplo n.º 11
0
tstring vmsAppSmallTipsMgr::getTip()
{
	vmsAUTOLOCKSECTION (m_csTipAcc);
	if (m_vTips.empty ())
		return _T ("");
	if (m_nCurrentTip == -1)
		SetupCurrentTipIndex ();
	return m_vTips [m_nCurrentTip].c_str ();
}
BOOL vmsTpDownloadMgr::IsDownloading()
{
	vmsAUTOLOCKSECTION (m_csDownload);
	
	if (m_dldr == NULL)
		return FALSE;

	return m_dldr->get_State () == STREAMING_DOWNLOADING;
}
void vmsBrowserActivityMonitor::CreateNewItem(LPCWSTR pwszUrl)
{
	m_bsd.ModifyActiveDownloadsCount (1);
	ActivityInfo ai;
	ai.wstrUrl = pwszUrl;
	ai.dwTimeLastActivity = GetTickCount ();
	vmsAUTOLOCKSECTION (m_csList);
	m_vList.push_back (ai);
}
Exemplo n.º 14
0
int vmsOverlappedWinsockCalls::FindCallIndex(SOCKET s, LPWSAOVERLAPPED lpOverlapped)
{
	vmsAUTOLOCKSECTION (m_csCalls);
	for (size_t i = 0; i < m_vCalls.size (); i++)
	{
		if (m_vCalls [i].s == s && m_vCalls [i].lpOverlapped == lpOverlapped)
			return i;
	}
	return -1;
}
STDMETHODIMP CFDMFlashVideoDownloads::QueryService(REFGUID guidService, REFIID riid, void** ppv)
{
	if (IsEqualIID (guidService, IID_IFdmUiWindow))
	{
		vmsAUTOLOCKSECTION (m_csLastUiWindow);
		if (m_spLastUiWindow)
			return m_spLastUiWindow->QueryInterface (riid, ppv);
	}
	return E_NOINTERFACE;
}
void vmsTrafficUsageModeMgr::SetTUMManage(fsTUMManage enManage)
{
	vmsAUTOLOCKSECTION (m_csTUMManage);
	m_enTUMManage = enManage;
	if (enManage == TM_OFF) 
	{
		if (GetTUM () != m_enUserTUM)
			SetTUM (m_enUserTUM); 
	}
}
void vmsTrafficUsageModeMgr::removeManageForSpeedItem(vmsDownloaderWithNetworkUsageAdjustment* pItem)
{
	assert (pItem);
	if (!pItem)
		return;
	vmsAUTOLOCKSECTION (m_csManageForSpeed);
	int nPriorityIndex, nIndex = findManageForSpeedItemIndex (pItem, &nPriorityIndex);
	if (nIndex != -1)
		m_vpManageForSpeed [nPriorityIndex]->vItems.erase (m_vpManageForSpeed [nPriorityIndex]->vItems.begin () + nIndex);
}
BOOL vmsTpDownloadMgr::IsDone()
{
	vmsAUTOLOCKSECTION (m_csDownload);

	if (m_dldr == NULL)
		return FALSE;

	BOOL bDone = m_dldr->IsDone();
	return bDone ? bDone : m_info.bDone;
}
void vmsBrowserActivityMonitor::onActivity(LPCWSTR pwszUrl)
{
	vmsAUTOLOCKSECTION (m_csList);
	int nIndex = FindItemByUrl (pwszUrl);
	if (nIndex != -1)
	{
		m_vList [nIndex].dwTimeLastActivity = GetTickCount ();
		return;
	}
	CreateNewItem (pwszUrl);
}
Exemplo n.º 20
0
BOOL fsSitesMgr::SaveToFile(HANDLE hFile)
{
    vmsAUTOLOCKSECTION (m_csSites);

    int cPermSites = GetSiteCount () - GetTempSiteCount ();

    DWORD dw;

    fsSitesFileHdr hdr;

    if (!WriteFile (hFile, &hdr, sizeof (hdr), &dw, NULL))
        return FALSE;

    if (!WriteFile (hFile, &cPermSites, sizeof (cPermSites), &dw, NULL))
        return FALSE;

    BOOL bMaySavePwds = _App.SM_KeepPasswords () &&
                        _App.SM_DontSavePwdsToDisk () == FALSE;

    for (int i = 0; i < GetSiteCount (); i++)
    {
        fsSiteInfo *site = GetSite (i);

        if (site->bTemp)
            continue;

        if (!fsSaveStrToFile (site->strName, hFile))
            return FALSE;

        if (!fsSaveStrToFile (bMaySavePwds ? site->strPassword : NULL, hFile))
            return FALSE;

        if (!fsSaveStrToFile (bMaySavePwds ? site->strUser : NULL, hFile))
            return FALSE;

        UINT nGrpId = site->pGroup ? site->pGroup->nId : (UINT)-1;
        if (!WriteFile (hFile, &nGrpId, sizeof (UINT), &dw, NULL))
            return FALSE;

        if (!WriteFile (hFile, &site->dwFtpFlags, sizeof (site->dwFtpFlags), &dw, NULL))
            return FALSE;

        if (!WriteFile (hFile, &site->cConnsNow, sizeof (site->cConnsNow), &dw, NULL))
            return FALSE;

        if (!WriteFile (hFile, &site->cMaxConns, sizeof (site->cMaxConns), &dw, NULL))
            return FALSE;

        if (!WriteFile (hFile, &site->dwValidFor, sizeof (site->dwValidFor), &dw, NULL))
            return FALSE;
    }

    return TRUE;
}
Exemplo n.º 21
0
libtorrent::torrent_status& vmsBtDownloadImpl::status ()
{
    if (GetTickCount () - m_dwDob_status)
    {
        vmsAUTOLOCKSECTION (m_csStatusGuard);
        m_status = m_handle.status ();
        m_dwDob_status = GetTickCount ();
    }

    return m_status;
}
void vmsBrowserActivityMonitor::RemoveTimedoutItems(void)
{
	DWORD dwNow = GetTickCount ();

	vmsAUTOLOCKSECTION (m_csList);

	for (size_t i = 0; i < m_vList.size (); i++)
	{
		if (dwNow - m_vList [i].dwTimeLastActivity >= 10*1000)
			RemoveItem (i--); 
	}
}
void vmsTpDownloadMgr::GetSectionInfo(int nIndex, vmsSectionInfo *sect)
{
	vmsAUTOLOCKSECTION (m_csDownload);
	
	UINT64 uTotal = GetTotalFilesSize ();
	int ns = GetNumberOfSections();
	UINT64 uPerPiece = uTotal / ns;
	
	sect->uDStart = nIndex * uPerPiece;
	sect->uDEnd = nIndex == ns-1 ? uTotal : sect->uDStart + uPerPiece - 1;
	sect->uDCurrent = GetDownloadedBytesCount();
}
void vmsTrafficUsageModeMgr::setRestrainAll(bool bSet)
{
	if (m_bRestrainAll != bSet)
	{
		if (!bSet)
		{
			vmsAUTOLOCKSECTION (m_csMisc);
			m_cSecondsNoSpeedMeasure = 7;
		}
		m_bRestrainAll = bSet;
		_DldsMgr.setNeedApplyTrafficLimit ();
	}
}
void vmsTrafficUsageModeMgr::setTUM(fsTUM tum, bool bByUser)
{
	if (GetTUM () != tum)
	{
		vmsAUTOLOCKSECTION (m_csMisc);
		m_cSecondsNoSpeedMeasure = 7;
		vmsAUTOLOCKSECTION_UNLOCK (m_csMisc);
		if (bByUser)
			m_enUserTUM = tum;
		m_enCurrentTUM = tum;
		BuildCurrentSettings ();
	}
}
Exemplo n.º 26
0
void fsSitesMgr::DeleteAllTempSites()
{
    vmsAUTOLOCKSECTION (m_csSites);

    for (int i = m_vSites.size () - 1; i >= 0; i--)
    {
        if (m_vSites [i]->bTemp)
        {
            Event (SM_SITEDELETED, m_vSites [i]);
            m_vSites.erase (m_vSites.begin () + i);
        }
    }
}
void vmsTrafficUsageModeMgr::addManageForSpeedItem(vmsDownloaderWithNetworkUsageAdjustment* pItem)
{
	assert (pItem);
	if (!pItem)
		return;
	vmsAUTOLOCKSECTION (m_csManageForSpeed);
	int iPriorityIndex = -1;
	if (findManageForSpeedItemIndex (pItem, &iPriorityIndex) == -1)
	{
		if (iPriorityIndex == -1)
			iPriorityIndex = GetPriorityListIndex (pItem->getPriority ());
		m_vpManageForSpeed [iPriorityIndex]->vItems.push_back (pItem);
	}
}
Exemplo n.º 28
0
void vmsOverlappedWinsockCalls::AddCall(SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount, LPWSAOVERLAPPED lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine, bool bSend)
{
	Call c;
	c.s = s;
	for (DWORD i = 0; i < dwBufferCount; i++)
		c.vBuffers.push_back (lpBuffers [i]);
	c.lpOverlapped = lpOverlapped;
	c.lpCompletionRoutine = lpCompletionRoutine;
	c.bSend = bSend;
	vmsAUTOLOCKSECTION (m_csCalls);
	int nIndex = FindCallIndex (s, lpOverlapped);
	if (nIndex != -1)
		m_vCalls.erase (m_vCalls.begin () + nIndex);
	m_vCalls.push_back (c);
}
UINT64 vmsTpDownloadMgr::GetDownloadedBytesCount(bool bSetDirtyFlag)
{
	vmsAUTOLOCKSECTION (m_csDownload);
	if (m_dldr == NULL)
		return 0;

	UINT64 bytesCount = m_dldr->get_TotalDownloadedBytesCount ();
	
	if (bytesCount) {
		UINT64 uiOldDownloadedBytes = m_info.nDownloadedBytes;
		m_info.nDownloadedBytes = bytesCount;
		if (bSetDirtyFlag && m_info.nDownloadedBytes != uiOldDownloadedBytes)
			setDirty();
	}
	return m_info.nDownloadedBytes;
}
Exemplo n.º 30
0
void vmsAppSmallTipsMgr::Load()
{
	vmsAUTOLOCKSECTION (m_csTipAcc);

	m_vTips.clear ();
	std::vector <tstring> vEngTips;

	Load_imp (fsGetDataFilePath ("tips.dat"), m_vTips, false);
	Load_imp (fsGetProgramFilePath ("tips.dat"), vEngTips, !m_vTips.empty ());	

	if (vEngTips.size () > m_vTips.size ())
	{
		for (size_t i = m_vTips.size (); i < vEngTips.size (); i++)
			m_vTips.push_back (vEngTips [i]);
	}
}