コード例 #1
0
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();
}
コード例 #2
0
void vmsDownloadMgrEx::GetSplittedSectionsList(std::vector <vmsSectionInfo> &v)
{
	try
	{
		std::vector <vmsSectionInfo> vBtSects;
		if (m_spBtMgr)
			m_spBtMgr->GetSectionsInfo (vBtSects);
		
		v.clear ();
		size_t num = GetNumberOfSections ();
		vmsSectionInfo *sectLast = NULL;
		
		for (size_t i = 0; i < num; i++)
		{
			vmsSectionInfo sect;
			if (m_spBtMgr)
				sect = vBtSects [i];
			else
				GetSectionInfo (i, &sect);
			if (sectLast != NULL && 
				(sectLast->uDCurrent == sect.uDStart || sectLast->uDCurrent+1 == sect.uDStart))
			{
				sectLast->uDEnd = sect.uDEnd;
				sectLast->uDCurrent = sect.uDCurrent;
			}
			else
			{
				v.push_back (sect);
				
				
				std::vector <vmsSectionInfo>::iterator itLastSect = v.end () - 1;
				sectLast = &(*itLastSect);
				
			}
		}
	}
	catch (const std::exception& ex)
	{
		ASSERT (FALSE);
		vmsLogger::WriteLog(_T("vmsDownloadMgrEx::GetSplittedSectionsList ") + tstringFromString(ex.what()));
		v.clear ();
	}
	catch (...)
	{
		ASSERT (FALSE);
		vmsLogger::WriteLog(_T("vmsDownloadMgrEx::GetSplittedSectionsList unknown exception"));
		v.clear ();
	}
}
コード例 #3
0
void vmsTpDownloadMgr::getObjectItselfStateBuffer(LPBYTE pb, LPDWORD pdwSize, bool bSaveToStorage)
{
	vmsAUTOLOCKSECTION (m_csDownload);

	#define CHECK_SIZE(need) {if (lpBuffer != NULL && *pdwSize < (UINT)(lpBuffer + need - pb)) return;}

	LPBYTE lpBuffer = pb;

	DWORD dwNeedSize;
	dwNeedSize = sizeof (int) + m_info.strTorrentUrl.GetLength();
	dwNeedSize += sizeof (int) + m_info.strOutputPath.GetLength();
	dwNeedSize += sizeof (int) + m_info.strFileName.GetLength();
	dwNeedSize += sizeof (int); 
	dwNeedSize += sizeof (int); 
	dwNeedSize += sizeof (UINT64); 

	dwNeedSize += sizeof (m_info.bDone);
	dwNeedSize += sizeof (m_info.fPercentDone);
	dwNeedSize += sizeof (m_info.nDownloadedBytes);
	
	
	
	

	*pdwSize = dwNeedSize;

	if (pb == NULL) {
		return;
	}

	int i;

	
	i = strlen(m_info.strTorrentUrl);
	CHECK_SIZE (sizeof (int));
	CopyMemory (lpBuffer, &i, sizeof (int));
	lpBuffer += sizeof (int);
	CHECK_SIZE (i);
	CopyMemory (lpBuffer, m_info.strTorrentUrl, i);
	lpBuffer += i;
	
	
	i = strlen(m_info.strOutputPath);
	CHECK_SIZE (sizeof (int));
	CopyMemory (lpBuffer, &i, sizeof (int));
	lpBuffer += sizeof (int);
	CHECK_SIZE (i);
	CopyMemory (lpBuffer, m_info.strOutputPath, i);
	lpBuffer += i;

	
	i = strlen(m_info.strFileName);
	CHECK_SIZE (sizeof (int));
	CopyMemory (lpBuffer, &i, sizeof (int));
	lpBuffer += sizeof (int);
	CHECK_SIZE (i);
	CopyMemory (lpBuffer, m_info.strFileName, i);
	lpBuffer += i;
	

	
	i = GetStreamingSpeed (false);
	CHECK_SIZE (sizeof (int));
	CopyMemory (lpBuffer, &i, sizeof (int));
	lpBuffer += sizeof (int);

	
	m_info.nNumSections = GetNumberOfSections (false);
	CHECK_SIZE (sizeof (int));
	CopyMemory (lpBuffer, &m_info.nNumSections, sizeof (int));
	lpBuffer += sizeof (int);

	
	UINT64 fileSize = GetTotalFilesSize (false);
	CHECK_SIZE (sizeof (UINT64));
	CopyMemory (lpBuffer, &fileSize, sizeof (UINT64));
	lpBuffer += sizeof (UINT64);

	m_info.bDone = IsDone();
	CHECK_SIZE (sizeof (m_info.bDone));
	CopyMemory (lpBuffer, &m_info.bDone, sizeof (m_info.bDone));
	lpBuffer += sizeof (m_info.bDone);

	m_info.fPercentDone = GetPercentDone(false);
	CHECK_SIZE (sizeof (m_info.fPercentDone));
	CopyMemory (lpBuffer, &m_info.fPercentDone, sizeof (m_info.fPercentDone));
	lpBuffer += sizeof (m_info.fPercentDone);

	m_info.nDownloadedBytes = GetDownloadedBytesCount(false);
	CHECK_SIZE (sizeof (m_info.nDownloadedBytes));
	CopyMemory (lpBuffer, &m_info.nDownloadedBytes, sizeof (m_info.nDownloadedBytes));
	lpBuffer += sizeof (m_info.nDownloadedBytes);

	*pdwSize = lpBuffer - pb;

	return;
}
コード例 #4
0
ファイル: inifile.cpp プロジェクト: NyouB/4t4c
void IniFile::SaveFile (std::wstring& FileName)
{
	// this function dumps a given dictionary into a loadable ini file.

	FILE *fp;
	int section_index;
	wchar_t *section_name;
	int section_count;
	int index;
	int length;
	wchar_t key[256];

	// try to open the INI file in ASCII write mode
	fp = _wfsopen (FileName.c_str(), L"w", _SH_DENYNO);
	if (fp == NULL)
		return; // cancel if unable to open file

	// keep only the file name for the comment
	if (wcsrchr (FileName.c_str(), L'/') != NULL)
	{
		const wchar_t* Tmp= wcsrchr (FileName.c_str(), L'/') + 1;
		// print the INI file name as a comment
		fwprintf (fp, L"# %s\n", Tmp);
	}
	else if (wcsrchr (FileName.c_str(), L'\\') != NULL)
	{
		const wchar_t* Tmp = wcsrchr (FileName.c_str(), L'\\') + 1;
		// print the INI file name as a comment
		fwprintf (fp, L"# %s\n", Tmp);
	}


	// get the number of sections there are in this INI dictionary
	section_count = GetNumberOfSections ();

	// for each section...
	for (section_index = 0; section_index < section_count; section_index++)
	{
		section_name = GetSectionName (section_index); // read section name

		// is it the default section ?
		if (wcscmp (section_name, INIFile_default_section) == 0)
			fwprintf (fp, L"\n"); // don't put the default section's name in the INI file
		else
			fwprintf (fp, L"\n[%s]\n", section_name); // dump all other sections into the INI file

		// build the section identifier to be used when looking up the dictionary
		swprintf(key, 256, L"%s%c", section_name, INI_SECTION_SEPARATOR);
		length = (int) wcslen (key);

		// then for each entry in the dictionary...
		for (index = 0; index < Dictionary->entry_count; index++)
		{
			if (Dictionary->entries[index].key[0] == 0)
				continue; // skip empty slots

			// does this key belong to the section we want ? if so, dump it
			if (wcsncmp (Dictionary->entries[index].key, key, length) == 0)
			{
				// if key starts or ends with a space, enclose it between quotes, else don't
				if ((Dictionary->entries[index].value[0] != 0)
					&& (iswspace (Dictionary->entries[index].value[0])
					|| iswspace (Dictionary->entries[index].value[wcslen (Dictionary->entries[index].value) - 1])))
					fwprintf (fp, L"%s = \"%s\"\n", Dictionary->entries[index].key + length, Dictionary->entries[index].value);
				else
					fwprintf (fp, L"%s = %s\n", Dictionary->entries[index].key + length, Dictionary->entries[index].value);
			}
		}
	}

	fclose (fp); // finished, close the file

	return; // and return
}