Exemplo n.º 1
0
	int ReadMem(kMemory* pk_Mem, void* buffer, UINT count)
	{
		if (mu32_BlockSize > 0) // read from the blocks in memory (Cache)
		{
			// Cabinet.dll opens two handles to the CAB file
			// The data in the first block of the CAB file is read multiple times by BOTH handles
			if (pk_Mem->s32_Pos + count < mu32_BlockSize)
				return mi_FirstBlock.ReadData(buffer, pk_Mem->s32_Pos, count);

			// One CAB file handle reads the CAB index (filenames)
			// The other handle reads the compressed data
			// To avoid unneccessary downloads each CAB file handle has its own cache
			DWORD u32_Cache = (DWORD)(INT_PTR) pk_Mem->p_Addr;
			return mi_Cache[u32_Cache].ReadData(buffer, pk_Mem->s32_Pos, count);
		}
		else // read from the downloaded file on disk
		{
			SetFilePointer(mi_Internet.GetDownloadFile(), pk_Mem->s32_Pos, 0, FILE_BEGIN);

			DWORD u32_Read;
			if (!ReadFile(mi_Internet.GetDownloadFile(), buffer, count, &u32_Read, 0))
			{
				mi_Error.Set(FDIERROR_READ_CABFILE, GetLastError(),0);
				return -1;
			}
			return u32_Read;
		}
	}
Exemplo n.º 2
0
bool CDownload::Next()
{
	if (m_List.empty())
		return false;

	DOWNLOAD& Download = m_List.front();
	CString strSrcURL = Download.strSrcURL;
	if (strSrcURL.GetLength() <= 0)
		return false;

	if (m_bShowProgress)
	{
		m_ProgressDialog.SetLineText(1/*dwLine*/, strSrcURL);
	    m_ProgressDialog.UpdateProgress(0, 100/*dwMax*/);
		m_ProgressDialog.ResetTimer();
	}

	if (m_bGoOnline)
	{
		CInternet Internet;
		if (!Internet.GoOnline(strSrcURL, NULL/*hwndParentWindow*/, false/*bForceLANOnlineSilently*/))
			return false;
	}

	#ifdef NETSCAPE
		CCtp* pCtp = (CCtp*)m_lParam;
		NPN_GetURL(pCtp->m_pNPPInstance, strSrcURL, NULL);
	#else
		CBindStatusCallback2<CCtp>::Download(CComBSTR(strSrcURL), this, m_pClientSite);
	#endif NETSCAPE

	return true;
}
Exemplo n.º 3
0
	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;
	}
Exemplo n.º 4
0
	int CloseMem(kMemory* pk_Mem)
	{
		// The download file must be kept open! (Maybe the user wants to extract more files later)
		mi_Internet.CloseInternet();
		delete pk_Mem;
		return 0;
	}
Exemplo n.º 5
0
bool CHpAutoUpdate::Start(bool bSilent, CString& strManifestURL)
{
	if (!m_pCtp)
		return false;

	// Check the online status to see if we need to defer this operation
	CInternet Internet;
	if (!Internet.IsOnline(false/*bForceLANOnline*/))
	{
		if (!bSilent)
			CMessageBox::Message(String(IDS_AUTOUPDATE_ONLINE_PROMPT));

		return false;
	}

	if (bSilent)
	{
		if (!IsSilentUpdateAllowed())
			return false;

		RegisterSilentUpdate();
	}

	m_bSilent = bSilent;
	
	// Go get the manifest file
#ifdef _DEBUG
	CString szManifestURL = "http://localhost/dataupload/hpmanifest.xml";
#else
	CString strImgHost = m_pCtp->GetContextImgHost();
	CString szManifestURL = strImgHost + String(IDS_HPMANIFEST_URL);
#endif
	int index = max(szManifestURL.ReverseFind('/'), szManifestURL.ReverseFind('\\'));
	m_strManifestPath = szManifestURL.Left(index + 1);

	m_strManifestFile = RandomFileName();

	if (!m_pCtp->GetDownload().Init(1/*iFileType*/, CAutoUpdate::MyGetManifestCallback, (LPARAM)m_pCtp, DL_KILLINPROGRESS))
		return false;

	m_pCtp->GetDownload().AddFile(szManifestURL, m_strManifestFile, NULL);
	m_pCtp->GetDownload().Start(true/*m_bGoOnline*/);

	return true;
}
Exemplo n.º 6
0
	// CleanUp() must only be called if this class is not destroyed with its destructor
	// It must be called to close the connection to the server and close the download file which is still open
	// This is NOT done automatically to allow re-using this class (e.g. multiple extraction of single files)
	BOOL CleanUp()
	{
		mi_Internet.CleanUp();       // close handles
		mi_FirstBlock.Init(0,0,0,0); // free memory
		mi_Cache[0].Init  (0,0,0);
		mi_Cache[1].Init  (0,0,0);
		
		// Clean up base class
		return CExtract::CleanUp();
	}
Exemplo n.º 7
0
	// 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);
	}
Exemplo n.º 8
0
	// Extract the CAB file at the given URL into the given target directory
	// If u16_LocalFile = ""  -> a temporary file will be created
	// A Cabfile will be written to disk ONLY if u32_Blocksize = 0 !!
	// u16_TargetDir = L"" AND Blocksize = 0 --> only download any file from internet to disk
	BOOL ExtractUrlW(const CStrW& sw_URL, DWORD u32_Blocksize, const CStrW& sw_LocalFile, const CStrW& sw_TargetDir, void* pParam = NULL)
	{
		if (!Initialize(sw_URL, sw_LocalFile, u32_Blocksize))
			return FALSE;

		// Just a download without CAB extraction
		if (!u32_Blocksize && sw_LocalFile.Len() && !sw_TargetDir.Len())
		{
			// The caller may want to access the file immediately -> close all
			mi_Internet.CleanUp();
			return TRUE;
		}

		// Pass it on to the base class
		return ExtractFileW(L"*CABINET\\*URL", sw_TargetDir, pParam);
	}
Exemplo n.º 9
0
	// See comment in Internet.hpp !!!
	void GetProgress(ULONGLONG* pu64_Size, ULONGLONG* pu64_Read)
	{
		mi_Internet.GetProgress(pu64_Size, pu64_Read);
	}
Exemplo n.º 10
0
	// This function aborts the currently active operation.
	void AbortOperation()
	{
		CExtract::AbortOperation();
		mi_Internet.AbortOperation();
	}
Exemplo n.º 11
0
	// Download only the first u32_MaxDownload Bytes of the file
	// Ignored for partial downloads!
	void SetMaxDownload(DWORD u32_MaxDownload)
	{
		mi_Internet.SetMaxDownload(u32_MaxDownload);
	}
Exemplo n.º 12
0
	// Set FTP mode passive / active
	void SetPassiveFtpMode(BOOL b_Passive)
	{
		mi_Internet.FtpSetPassiveMode(b_Passive);
	}
Exemplo n.º 13
0
	// Modifies the HTTP headers which are sent to the server. (separated by pipe)
	// e.g. "Referer: http://www.test.com|Accept-Language:en"  (no space before or after pipe!!)
	// If the value of a header is empty, the header is removed.
	void SetHttpHeadersW(const CStrW& sw_Headers)
	{
		mi_Internet.HttpSetHeaders(sw_Headers);
	}
Exemplo n.º 14
0
	// Set a proxy or multiple proxies:
	// String Format= "http=http://Proxy1.com:8000 https=https://Proxy2.com:443"
	// You can specify separate proxies for HTTP, HTTPS, FTP
	// u16_Proxy = "" --> Use Internet Explorer default settings
	void SetProxyW(const CStrW& sw_Proxy)
	{
		mi_Internet.SetProxy(sw_Proxy);
	}
Exemplo n.º 15
0
 // Set a proxy or multiple proxies:
 // String Format= "http=http://Proxy1.com:8000 https=https://Proxy2.com:443"
 // You can specify separate proxies for HTTP, HTTPS, FTP
 // u16_Proxy = "" --> Use Internet Explorer default settings
 // The proxy user and proxy password are normally stored by Internet Explorer but this does not work always.
 // If Wininet.dll returns error 407 repeatedly try setting User and Password here
 void SetProxyW(const CStrW& sw_Server, const CStrW& sw_User=L"", const CStrW& sw_Pass=L"")
 {
     mi_Internet.SetProxy(sw_Server, sw_User, sw_Pass);
 }