コード例 #1
0
ファイル: ExtractUrl.hpp プロジェクト: dblock/codeproject
	BOOL Initialize(WCHAR* u16_Url, WCHAR* u16_LocalFile, DWORD u32_Blocksize)
	{
		mu32_BlockSize = u32_Blocksize;
		mu32_Cache     = 0;

		if (!mi_Internet.LoadWininet())
		{
			mi_Error.Set(FDIERROR_LOAD_WININET_DLL,0,0);
			return FALSE;
		}

		// Sets Username, Password, Server, UrlPath, Port, ServiceType
		DWORD u32_ApiErr;
		if (u32_ApiErr = mi_Internet.SetUrl(u16_Url))
		{
			mi_Error.Set(FDIERROR_INTERNET, u32_ApiErr,0);
			return FALSE;
		}

		BOOL b_Offline;
		if (u32_ApiErr = mi_Internet.ConnectServer(&b_Offline))
		{
			if (b_Offline) mi_Error.Set(FDIERROR_MSIE_OFFLINE, u32_ApiErr, 0);
			else           mi_Error.Set(FDIERROR_INTERNET,     u32_ApiErr, 0);
			return FALSE;
		}

		if (u32_Blocksize > 0) // Extract via memory blocks
		{
			#if _TraceInternet
				CTrace::TraceW(L"*** Starting URL extraction. Loading blocks of %d Bytes to memory", u32_Blocksize);
			#endif

			// Minimum 50 kB
			// WARNING: Blocks smaller than 250 kB result in a very bad performance (see above)
			mu32_BlockSize = max(mu32_BlockSize, 50000);

			mi_FirstBlock.Init(mu32_BlockSize, CacheCallback, 'F','i'); // Block "Fi"
			mi_Cache[0].  Init(mu32_BlockSize, CacheCallback, '1');     // Block "1A" and "1B"
			mi_Cache[1].  Init(mu32_BlockSize, CacheCallback, '2');     // Block "2A" and "2B"
		}
		else // Extract via a file which is entirely saved to disk, then extracted
		{
			u32_ApiErr = mi_Internet.CreateDownloadFileW(u16_LocalFile);
			if (u32_ApiErr)
			{
				mi_Error.Set(FDIERROR_TARGET_FILE, u32_ApiErr,0);
				return FALSE;
			}

			DWORD u32_Status;
			if (u32_ApiErr = mi_Internet.DownloadEntireFileToDisk(&u32_Status))
			{
				mi_Error.Set(FDIERROR_INTERNET, u32_ApiErr, u32_Status);
				return FALSE;
			}
		}
		return TRUE;
	}
コード例 #2
0
ファイル: ExtractUrl.hpp プロジェクト: dblock/codeproject
	// Extract additional files from the CAB file which has been used in a previous call to ExtractUrlW()
	BOOL ExtractMoreUrlW(const CStrW& sw_TargetDir, void* pParam = NULL)
	{
		mu32_Cache = 0;
		// re-open the same connection, re-using the cache's contents or the already downloaded file
		BOOL  b_Offline;
		DWORD u32_ApiErr = mi_Internet.ConnectServer(&b_Offline);
		if (u32_ApiErr)
		{
			if (b_Offline) mi_Error.Set(FDIERROR_MSIE_OFFLINE, u32_ApiErr, 0);
			else           mi_Error.Set(FDIERROR_INTERNET,     u32_ApiErr, 0);
			return FALSE;
		}
		return ExtractFileW(L"*CABINET\\*URL", sw_TargetDir, pParam);
	}