Exemplo n.º 1
0
void UrlToFdm (LPCSTR pszUrl)
{
	IWGUrlReceiver* wg;
	HRESULT hr;
	if (FAILED (hr=CoCreateInstance (CLSID_WGUrlReceiver, NULL, CLSCTX_ALL, IID_IWGUrlReceiver, (void**) &wg)))
	{
		char szMsg [1000];
		lstrcpy (szMsg, "Free Download Manager is not properly installed! Please reinstall Free Download Manager\n\nIf you want to download with your browser please remove \"npfdm.dll\" file in the Plugin directory of your browser.\n\nError code: ");
		char sz [100];
		_itoa_s (hr, sz, 100, 16);
		lstrcat (szMsg, sz);
		MessageBox (NULL, szMsg, "Error", MB_ICONERROR);
		return;
	}

	_bstr_t url = pszUrl;
	wg->put_Url (url);
	wg->AddDownload ();
	wg->Release ();
}
Exemplo n.º 2
0
void fsFDMCmdLineParser::Parse()
{
	HANDLE hAppMutex = CreateMutex (NULL, TRUE, _pszAppMutex);
	
	
	if (GetLastError () == ERROR_ALREADY_EXISTS)
		m_bAnotherFDMStarted = TRUE;

	CloseHandle (hAppMutex);

	if (FALSE == m_parser.Parse ())
		return;

	m_bForceSilent = FALSE;

	CFdmApp* app = (CFdmApp*) AfxGetApp ();

	for (int i = 0; i < m_parser.Get_ParameterCount (); i++)
	{
		LPCSTR pszParam = m_parser.Get_Parameter (i);
		LPCSTR pszValue = m_parser.Get_ParameterValue (i);

		if (strcmp (pszParam, "?") == 0)
		{
			MessageBox (0, "fdm.exe [-fs] [-url=]url1 [-url=]url2 ...\n\n-fs - force silent mode.\nIf url contains spaces it should be in quotes.\n\nExample:\nfdm.exe -fs \"http://site.com/read me.txt\"", "Command line usage", 0);
		}
		else if (stricmp (pszParam, "fs") == 0)
		{
			m_bForceSilent = TRUE;
		}
		else if (stricmp (pszParam, "URL") == 0 || *pszParam == 0)
		{
			fsURL url;
			BOOL bUrl = IR_SUCCESS == url.Crack (pszValue) && pszValue [1] != ':';
			BOOL bTorrent = FALSE;

			if (bUrl == FALSE)
			{
				bTorrent = strlen (pszValue) > 8 &&
					0 == stricmp (pszValue + strlen (pszValue) - 8, ".torrent");
			}

			if (bUrl == FALSE && bTorrent == FALSE)
				continue;

			if (bTorrent)
			{
				static BOOL bBtI = vmsFdmAppMgr::MakeSureBtInstalled ();
				if (bBtI)
					AddTorrentFile (pszValue);
				continue;
			}

			if (m_bAnotherFDMStarted)
			{
				IWGUrlReceiver* pAdd = NULL;
				CoCreateInstance (CLSID_WGUrlReceiver, NULL, CLSCTX_ALL,
					IID_IWGUrlReceiver, (void**) &pAdd);

				if (pAdd)
				{
					CComBSTR url = pszValue;
					pAdd->put_Url (url);
					if (m_bForceSilent)
						pAdd->put_ForceSilent (TRUE);
					pAdd->AddDownload ();
					pAdd->Release ();
				}
			}
			else
			{
				CFdmApp::_inc_UrlToAdd url;
				url.strUrl = pszValue;
				url.bForceSilent = m_bForceSilent;
				app->m_vUrlsToAdd.add (url);
			}
		}
		else if (stricmp (pszParam, "nostart") == 0)
		{
			m_bNeedExit = true;
		}
		else if (stricmp (pszParam, "assocwithtorrent") == 0)
		{
			bool bAssoc = strcmp (pszValue, "0") != 0;
			if (bAssoc)
			{
				_App.Bittorrent_OldTorrentAssociation (vmsTorrentExtension::GetCurrentAssociation ());
				vmsTorrentExtension::Associate ();
			}
			else
			{
				vmsTorrentExtension::AssociateWith (_App.Bittorrent_OldTorrentAssociation ());
			}
		}
	}
}
Exemplo n.º 3
0
BOOL fsUrlToFdm (LPCSTR pszUrl, LPCSTR pszReferer, LPCSTR pszCookies, LPCSTR pszPostData, BOOL bUseSkipExtsList)
{
	if (is_ServerToSkip (pszUrl))
		return FALSE;

	if (pszReferer && is_ServerToSkip (pszReferer))
		return FALSE;

	if (is_ExtToSkip (pszUrl, bUseSkipExtsList))
		return FALSE;

	fsURL urlH;
	if (IR_SUCCESS != urlH.Crack (pszUrl))
		return FALSE;
	LPCSTR pszHost = urlH.GetHostName ();
	if (stricmp (pszHost, "megashares.com") == 0 ||
		(strlen (pszHost) > sizeof ("megashares.com") && stricmp (pszHost+strlen (pszHost)-sizeof("megashares.com"), ".megashares.com") == 0))
	{
		pszReferer = "";
	}

	IWGUrlReceiver* wg;
	HRESULT hr;
	if (FAILED (hr=CoCreateInstance (CLSID_WGUrlReceiver, NULL, CLSCTX_ALL, IID_IWGUrlReceiver, (void**) &wg)))
	{
		char szMsg [1000];
		lstrcpy (szMsg, "Free Download Manager is not properly installed! Please reinstall Free Download Manager or try to reboot your PC.\n\nError code: 0x");
		char sz [100];
		itoa ((UINT)hr, sz, 16);
		lstrcat (szMsg, sz);
		MessageBox (NULL, szMsg, "Error", MB_ICONERROR);
		return FALSE;
	}

	wg->put_IgnoreSize (FALSE);

	_bstr_t url = pszUrl;
	wg->put_Url (url);
	if (pszCookies)
	{
		_bstr_t cookies = pszCookies;
		wg->put_Cookies (cookies);
	}
	if (pszReferer)
	{
		_bstr_t referer = pszReferer;
		wg->put_Referer (referer);
	}
	if (pszPostData)
	{
		_bstr_t ah = pszPostData;
		wg->put_PostData (ah);
	}
	wg->put_CheckExtension (FALSE);
	hr = wg->AddDownload ();

	if (FAILED (hr))
		return FALSE;

	CRegKey wgKey;
	if (ERROR_SUCCESS == wgKey.Open (HKEY_CURRENT_USER, "Software\\FreeDownloadManager.ORG\\Free Download Manager\\Settings\\Monitor", KEY_READ))
	{
		DWORD b = FALSE;
		if (ERROR_SUCCESS != wgKey.QueryValue (b, "AllowDownload"))
			b = TRUE;
		if (b == FALSE)	
		{
			wg->Release ();
			return TRUE;
		}
	}
	
	CComBSTR bstrState;
	do {
		Sleep (10);
		wg->get_UIState (&bstrState);
	} while (bstrState == L"in_progress");

	wg->Release ();

	return bstrState == L"added";
}
void fsFDMCmdLineParser::Parse(PerformTasksOfType enPTT)
{
	
	extern vmsAppMutex _appMutex;
	m_bAnotherFDMStarted = _appMutex.isAnotherInstanceStartedAlready ();

	if (FALSE == m_parser.Parse ())
		return;

	m_bForceSilent = FALSE;

	CFdmApp* app = (CFdmApp*) AfxGetApp ();

	for (int i = 0; i < m_parser.Get_ParameterCount (); i++)
	{
		LPCSTR pszParam = m_parser.Get_Parameter (i);
		LPCSTR pszValue = m_parser.Get_ParameterValue (i);

		if (strcmp (pszParam, "?") == 0 && enPTT == Normal)
		{
			MessageBox (0, "fdm.exe [-fs] [-url=]url1 [-url=]url2 ...\n\n-fs - force silent mode.\nIf url contains spaces it should be in quotes.\n\nExample:\nfdm.exe -fs \"http://site.com/read me.txt\"", "Command line usage", 0);
		}
		else if (stricmp (pszParam, "fs") == 0)
		{
			m_bForceSilent = TRUE;
		}
		else if ((stricmp (pszParam, "URL") == 0 || *pszParam == 0) && enPTT == Normal)
		{
			fsURL url;
			BOOL bUrl = IR_SUCCESS == url.Crack (pszValue) && pszValue [1] != ':';
			BOOL bTorrent = FALSE;

			if (bUrl == FALSE)
			{
				bTorrent = strlen (pszValue) > 8 && 
					0 == stricmp (pszValue + strlen (pszValue) - 8, ".torrent");

				if (_tcsstr(pszValue, _T("magnet:")) != 0)
				{
					bTorrent = TRUE;
				}
			}

			if (bUrl == FALSE && bTorrent == FALSE)
				continue;

			if (bTorrent)
			{
				static BOOL bBtI = vmsFdmAppMgr::MakeSureBtInstalled ();
				if (bBtI)
					AddTorrent (pszValue);
				continue;
			}

			if (m_bAnotherFDMStarted)
			{
				IWGUrlReceiver* pAdd = NULL;
				CoCreateInstance (CLSID_WGUrlReceiver, NULL, CLSCTX_ALL, 
					IID_IWGUrlReceiver, (void**) &pAdd);

				if (pAdd)
				{
					CComBSTR url = pszValue;
					pAdd->put_Url (url);
					if (m_bForceSilent)
						pAdd->put_ForceSilent (TRUE);
					pAdd->AddDownload ();
					pAdd->Release ();
				}
			}
			else
			{
				CFdmApp::_inc_UrlToAdd url;
				url.strUrl = pszValue;
				url.bForceSilent = m_bForceSilent;
				app->m_vUrlsToAdd.add (url);
			}
		}
		else if (stricmp (pszParam, "nostart") == 0)
		{
			m_bNeedExit = true;
		}
		else if (stricmp (pszParam, "assocwithtorrent") == 0 && enPTT == Elevated)
		{
			bool bAssoc = strcmp (pszValue, "0") != 0;
			if (bAssoc)
			{
				_App.Bittorrent_OldTorrentAssociation (vmsTorrentExtension::GetCurrentAssociation ());
				vmsTorrentExtension::Associate ();
			}
			else
			{
				vmsTorrentExtension::AssociateWith (_App.Bittorrent_OldTorrentAssociation ());
			}
		}
		else if (stricmp (pszParam, "assocwithmagnet") == 0 && enPTT == Elevated)
		{
			bool bAssoc = strcmp (pszValue, "0") != 0;
			vmsFdmUtils::AssociateFdmWithMagnetLinks (bAssoc);
		}
		else if (!stricmp (pszParam, "RegServer"))
		{
			m_bNeedRegisterServer = true;
		}
		else if (!stricmp (pszParam, "UnregServer"))
		{
			m_bNeedUnregisterServer = true;
		}
		else if (!stricmp (pszParam, "runelevated"))
		{
			m_bRunAsElevatedTasksProcessor = true;
		}
		else if (!stricmp (pszParam, "ie"))
		{
			m_bInstallIeIntegration = true;
		}
		else if (!stricmp (pszParam, "installIntegration") || !stricmp (pszParam, "deinstallIntegration") && enPTT == Elevated)
		{
			std::vector <int> v;
			ReadIntVector (pszValue, v);
			bool bInstall = !stricmp (pszParam, "installIntegration");
			for (size_t i = 0; i < v.size (); i++)
			{
				if (bInstall)
					m_vBrowsersToInstallIntegration.push_back ((vmsKnownBrowsers::Browser) v [i]);
				else
					m_vBrowsersToDeinstallIntegration.push_back ((vmsKnownBrowsers::Browser) v [i]);
			}
		}
	}
}