00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "fsIEContextMenuMgr.h"
00009
00010 #ifdef _DEBUG
00011 #undef THIS_FILE
00012 static char THIS_FILE[]=__FILE__;
00013 #define new DEBUG_NEW
00014 #endif
00015
00016 fsIEContextMenuMgr::fsIEContextMenuMgr()
00017 {
00018
00019 }
00020
00021 fsIEContextMenuMgr::~fsIEContextMenuMgr()
00022 {
00023
00024 }
00025
00026 BOOL fsIEContextMenuMgr::AddContextMenu(LPCSTR pszMenuName, LPCSTR pszMenuUrl, DWORD dwContext)
00027 {
00028 CRegKey key;
00029
00030 CString strKey = "Software\\Microsoft\\Internet Explorer\\MenuExt\\";
00031 strKey += pszMenuName;
00032
00033 if (ERROR_SUCCESS != key.Create (HKEY_CURRENT_USER, strKey))
00034 return FALSE;
00035
00036 if (ERROR_SUCCESS != key.SetValue (pszMenuUrl))
00037 return FALSE;
00038
00039 if (dwContext)
00040 {
00041 if (ERROR_SUCCESS != key.SetValue (dwContext, "Contexts"))
00042 return FALSE;
00043 }
00044
00045 key.SetValue (1, "Free Download Manager");
00046
00047 return TRUE;
00048 }
00049
00050 BOOL fsIEContextMenuMgr::IsContextMenuPresent(LPCSTR pszMenuName)
00051 {
00052 CRegKey key;
00053
00054 CString strKey = "Software\\Microsoft\\Internet Explorer\\MenuExt\\";
00055 strKey += pszMenuName;
00056
00057 if (ERROR_SUCCESS != key.Open (HKEY_CURRENT_USER, strKey))
00058 return FALSE;
00059
00060 return TRUE;
00061 }
00062
00063 void fsIEContextMenuMgr::ReadState()
00064 {
00065 m_bDLThisMenu = IsContextMenuPresent (LS (L_DLTHISIEMENU));
00066 m_bDLPageMenu = IsContextMenuPresent (LS (L_DLPAGEIEMENU));
00067 m_bDLAllMenu = IsContextMenuPresent (LS (L_DLALLIEMENU));
00068 m_bDLSelectedMenu = IsContextMenuPresent (LS (L_DLSELECTEDIEMENU));
00069 m_bDLFlashVideoMenu = IsContextMenuPresent (LS (L_DLFLASHVIDEOIEMENU));
00070 }
00071
00072 BOOL fsIEContextMenuMgr::IsDLPageMenuPresent()
00073 {
00074 return m_bDLPageMenu;
00075 }
00076
00077 BOOL fsIEContextMenuMgr::IsDLThisMenuPresent()
00078 {
00079 return m_bDLThisMenu;
00080 }
00081
00082 BOOL fsIEContextMenuMgr::AddIEMenus()
00083 {
00084 BOOL bOk = TRUE;
00085 CString strUrl = "file://";
00086
00087
00088 CString strPath = ((CFdmApp*)AfxGetApp ())->m_strAppPath;
00089 if (strPath == "")
00090 return FALSE;
00091 if (strPath [strPath.GetLength () - 1] != '/' && strPath [strPath.GetLength () - 1] != '\\')
00092 strPath += '\\';
00093 strUrl += strPath;
00094
00095 if (m_bDLThisMenu == FALSE && _App.Monitor_IEMenu_DLThis ())
00096 {
00097 CString str = strUrl + "dllink.htm";
00098 bOk = bOk && AddContextMenu (LS (L_DLTHISIEMENU), str, IEMENU_CONTEXT_LINK | IEMENU_CONTEXT_IMAGE);
00099 if (bOk)
00100 m_bDLThisMenu = TRUE;
00101 }
00102
00103 if (m_bDLPageMenu == FALSE && _App.Monitor_IEMenu_DLPage ())
00104 {
00105 CString str = strUrl + "dlpage.htm";
00106 if (AddContextMenu (LS (L_DLPAGEIEMENU), str, IEMENU_CONTEXT_DEFAULT|IEMENU_CONTEXT_SELECTEDTEXT))
00107 m_bDLPageMenu = TRUE;
00108 else
00109 bOk = FALSE;
00110 }
00111
00112 if (m_bDLAllMenu == FALSE && _App.Monitor_IEMenu_DLAll ())
00113 {
00114 CString str = strUrl + "dlall.htm";
00115 if (AddContextMenu (LS (L_DLALLIEMENU), str, IEMENU_CONTEXT_DEFAULT|IEMENU_CONTEXT_SELECTEDTEXT|IEMENU_CONTEXT_LINK|IEMENU_CONTEXT_IMAGE))
00116 m_bDLAllMenu = TRUE;
00117 else
00118 bOk = FALSE;
00119 }
00120
00121 if (m_bDLSelectedMenu == FALSE && _App.Monitor_IEMenu_DLSelected ())
00122 {
00123 CString str = strUrl + "dlselected.htm";
00124 if (AddContextMenu (LS (L_DLSELECTEDIEMENU), str, IEMENU_CONTEXT_DEFAULT|IEMENU_CONTEXT_SELECTEDTEXT|IEMENU_CONTEXT_LINK|IEMENU_CONTEXT_IMAGE))
00125 m_bDLSelectedMenu = TRUE;
00126 else
00127 bOk = FALSE;
00128 }
00129
00130 if (m_bDLFlashVideoMenu == FALSE && _App.Monitor_IEMenu_DLFlashVideo ())
00131 {
00132 CString str = strUrl + "dlfvideo.htm";
00133 if (AddContextMenu (LS (L_DLFLASHVIDEOIEMENU), str, IEMENU_CONTEXT_DEFAULT|IEMENU_CONTEXT_SELECTEDTEXT|IEMENU_CONTEXT_LINK|IEMENU_CONTEXT_IMAGE))
00134 m_bDLFlashVideoMenu = TRUE;
00135 else
00136 bOk = FALSE;
00137 _App.WriteTranslatedStringToRegistry ("dlfvideoiemenu", LS (L_DLFLASHVIDEOIEMENU));
00138 }
00139
00140 return bOk;
00141 }
00142
00143 BOOL fsIEContextMenuMgr::IsIEMenusPresent()
00144 {
00145 return m_bDLThisMenu || m_bDLPageMenu || m_bDLAllMenu || m_bDLSelectedMenu ||
00146 m_bDLFlashVideoMenu;
00147 }
00148
00149 BOOL fsIEContextMenuMgr::DeleteIEMenus()
00150 {
00151 BOOL bOk = TRUE;
00152
00153 if (m_bDLThisMenu)
00154 {
00155 bOk = bOk && DeleteContextMenu (LS (L_DLTHISIEMENU));
00156 m_bDLThisMenu = FALSE;
00157 }
00158
00159 if (m_bDLPageMenu)
00160 {
00161 bOk = bOk && DeleteContextMenu (LS (L_DLPAGEIEMENU));
00162 m_bDLPageMenu = FALSE;
00163 }
00164
00165 if (m_bDLAllMenu)
00166 {
00167 bOk = bOk && DeleteContextMenu (LS (L_DLALLIEMENU));
00168 m_bDLAllMenu = FALSE;
00169 }
00170
00171 if (m_bDLSelectedMenu)
00172 {
00173 bOk = bOk && DeleteContextMenu (LS (L_DLSELECTEDIEMENU));
00174 m_bDLSelectedMenu = FALSE;
00175 }
00176
00177 if (m_bDLFlashVideoMenu)
00178 {
00179 bOk = bOk && DeleteContextMenu (LS (L_DLFLASHVIDEOIEMENU));
00180 m_bDLFlashVideoMenu = FALSE;
00181 }
00182
00183
00184 DeleteContextMenu ("Download all by Free Download Manager");
00185 DeleteContextMenu ("Download by Free Download Manager");
00186 DeleteContextMenu ("Download selected by Free Download Manager");
00187 DeleteContextMenu ("Download web site by Free Download Manager");
00188
00189 return bOk;
00190 }
00191
00192 BOOL fsIEContextMenuMgr::DeleteContextMenu(LPCSTR pszMenuName)
00193 {
00194 CRegKey key;
00195
00196 CString strKey = "Software\\Microsoft\\Internet Explorer\\MenuExt";
00197
00198 if (ERROR_SUCCESS != key.Open (HKEY_CURRENT_USER, strKey))
00199 return FALSE;
00200
00201 if (ERROR_SUCCESS != key.DeleteSubKey (pszMenuName))
00202 return FALSE;
00203
00204 return TRUE;
00205 }
00206
00207 BOOL fsIEContextMenuMgr::IsDLAllMenuPresent()
00208 {
00209 return m_bDLAllMenu;
00210 }
00211
00212 BOOL fsIEContextMenuMgr::IsDLSelectedMenuPresent()
00213 {
00214 return m_bDLSelectedMenu;
00215 }
00216
00217 void fsIEContextMenuMgr::DeleteAllFDMsIEMenus()
00218 {
00219 CRegKey key;
00220
00221 CString strKey = "Software\\Microsoft\\Internet Explorer\\MenuExt";
00222
00223 if (ERROR_SUCCESS != key.Open (HKEY_CURRENT_USER, strKey))
00224 return;
00225
00226 char szSubKey [1000]; DWORD dwszSubKey = sizeof (szSubKey);
00227 FILETIME ft;
00228
00229 fs::list <fsString> vSubKeys;
00230 DWORD dwIndex = 0;
00231
00232 while (ERROR_SUCCESS == RegEnumKeyEx (key, dwIndex++, szSubKey, &dwszSubKey,
00233 NULL, NULL, NULL, &ft))
00234 {
00235 dwszSubKey = sizeof (szSubKey);
00236
00237 CRegKey key2;
00238 if (ERROR_SUCCESS != key2.Open (key, szSubKey))
00239 continue;
00240
00241 DWORD dwFDM = FALSE;
00242 key2.QueryValue (dwFDM, "Open Download Manager");
00243
00244 if (dwFDM)
00245 vSubKeys.add (szSubKey);
00246 }
00247
00248 for (int i = 0; i < vSubKeys.size (); i++)
00249 key.DeleteSubKey (vSubKeys [i]);
00250 }
00251
00252 BOOL fsIEContextMenuMgr::IsDLFlashVideoMenuPresent()
00253 {
00254 return m_bDLFlashVideoMenu;
00255 }