00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "fsFDMCmdLineParser.h"
00009
00010 #ifdef _DEBUG
00011 #undef THIS_FILE
00012 static char THIS_FILE[]=__FILE__;
00013 #define new DEBUG_NEW
00014 #endif
00015
00016 fsFDMCmdLineParser::fsFDMCmdLineParser()
00017 {
00018 m_bAnotherFDMStarted = FALSE;
00019 m_bForceSilent = FALSE;
00020 }
00021
00022 fsFDMCmdLineParser::~fsFDMCmdLineParser()
00023 {
00024
00025 }
00026
00027 void fsFDMCmdLineParser::Parse()
00028 {
00029 HANDLE hAppMutex = CreateMutex (NULL, TRUE, _pszAppMutex);
00030
00031
00032 if (GetLastError () == ERROR_ALREADY_EXISTS)
00033 m_bAnotherFDMStarted = TRUE;
00034
00035 CloseHandle (hAppMutex);
00036
00037 if (FALSE == m_parser.Parse ())
00038 return;
00039
00040 m_bForceSilent = FALSE;
00041
00042 CFdmApp* app = (CFdmApp*) AfxGetApp ();
00043
00044 for (int i = 0; i < m_parser.Get_ParameterCount (); i++)
00045 {
00046 LPCSTR pszParam = m_parser.Get_Parameter (i);
00047 LPCSTR pszValue = m_parser.Get_ParameterValue (i);
00048
00049 if (strcmp (pszParam, "?") == 0)
00050 {
00051 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);
00052 }
00053 else if (stricmp (pszParam, "fs") == 0)
00054 {
00055 m_bForceSilent = TRUE;
00056 }
00057 else if (stricmp (pszParam, "URL") == 0 || *pszParam == 0)
00058 {
00059 fsURL url;
00060 BOOL bUrl = IR_SUCCESS == url.Crack (pszValue) && pszValue [1] != ':';
00061 BOOL bTorrent = FALSE;
00062
00063 if (bUrl == FALSE)
00064 {
00065 bTorrent = strlen (pszValue) > 10 &&
00066 0 == stricmp (pszValue + strlen (pszValue) - 8, ".torrent");
00067 }
00068
00069 if (bUrl == FALSE && bTorrent == FALSE)
00070 continue;
00071
00072 if (bTorrent)
00073 {
00074 if (_App.Bittorrent_Enable () == FALSE)
00075 {
00076 if (IDYES != MessageBox (NULL, LS (L_ENABLEBTISREQ), LS (L_CONFIRMATION), MB_ICONQUESTION | MB_YESNO))
00077 continue;
00078 _App.Bittorrent_Enable (TRUE);
00079 }
00080 AddTorrentFile (pszValue);
00081 continue;
00082 }
00083
00084 if (m_bAnotherFDMStarted)
00085 {
00086 IWGUrlReceiver* pAdd = NULL;
00087 CoCreateInstance (CLSID_WGUrlReceiver, NULL, CLSCTX_ALL,
00088 IID_IWGUrlReceiver, (void**) &pAdd);
00089
00090 if (pAdd)
00091 {
00092 CComBSTR url = pszValue;
00093 pAdd->put_Url (url);
00094 if (m_bForceSilent)
00095 pAdd->put_ForceSilent (TRUE);
00096 pAdd->AddDownload ();
00097 pAdd->Release ();
00098 }
00099 }
00100 else
00101 {
00102 CFdmApp::_inc_UrlToAdd url;
00103 url.strUrl = pszValue;
00104 url.bForceSilent = m_bForceSilent;
00105 app->m_vUrlsToAdd.add (url);
00106 }
00107 }
00108 }
00109 }
00110
00111 BOOL fsFDMCmdLineParser::is_ForceSilentSpecified()
00112 {
00113 return m_bForceSilent;
00114 }
00115
00116 void fsFDMCmdLineParser::AddTorrentFile(LPCSTR pszFile)
00117 {
00118 if (m_bAnotherFDMStarted)
00119 {
00120 IFdmTorrentFilesRcvr* pAdd = NULL;
00121 CoCreateInstance (CLSID_FdmTorrentFilesRcvr, NULL, CLSCTX_ALL,
00122 IID_IFdmTorrentFilesRcvr, (void**) &pAdd);
00123
00124 if (pAdd)
00125 {
00126 CComBSTR file = pszFile;
00127 pAdd->put_ForceSilent (m_bForceSilent);
00128 pAdd->CreateBtDownloadFromFile (file);
00129 pAdd->Release ();
00130 }
00131 }
00132 else
00133 {
00134 CFdmApp::_inc_UrlToAdd url;
00135 url.strUrl = pszFile;
00136 url.bForceSilent = m_bForceSilent;
00137 ((CFdmApp*) AfxGetApp ())->m_vTorrentFilesToAdd.add (url);
00138 }
00139 }