00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include <windows.h>
00008 #include "npapi.h"
00009 #include "npupp.h"
00010 #include <objbase.h>
00011 #include "..\Fdm.h"
00012 #include <comdef.h>
00013 #include "resource.h"
00014
00015 HICON _Icon = NULL;
00016 NPPluginFuncs* g_plugFuncs;
00017 HINSTANCE _hModule;
00018 const LPCSTR _pszWndClass = "FDM OpNetCatcher wnd class";
00019
00020 LRESULT WINAPI WndProc (HWND hWnd, UINT uMsg, WPARAM wp, LPARAM lp);
00021
00022 BOOL APIENTRY DllMain( HANDLE hModule,
00023 DWORD reason,
00024 LPVOID lpReserved
00025 )
00026 {
00027 switch (reason)
00028 {
00029 case DLL_PROCESS_ATTACH:
00030 CoInitialize (NULL);
00031 _hModule = (HINSTANCE) hModule;
00032 _Icon = LoadIcon ((HINSTANCE)hModule, MAKEINTRESOURCE (IDI_FDM));
00033 break;
00034
00035 case DLL_PROCESS_DETACH:
00036 CoUninitialize ();
00037 break;
00038 }
00039
00040 return TRUE;
00041 }
00042
00043 void NPP_URLNotify (NPP instance, const char* url, NPReason reason, void* notifyData)
00044 {
00045
00046 }
00047
00048 NPNetscapeFuncs *_pNFuncs;
00049 short _stdcall NP_Initialize (NPNetscapeFuncs *p)
00050 {
00051
00052 _pNFuncs = p;
00053
00054 int navMinorVers = p->version & 0xFF;
00055
00056 if (navMinorVers >= NPVERS_HAS_NOTIFICATION)
00057 g_plugFuncs->urlnotify = NPP_URLNotify;
00058
00059 if (navMinorVers >= NPVERS_HAS_LIVECONNECT)
00060 g_plugFuncs->javaClass = NULL;
00061
00062 WNDCLASSEX wc;
00063 wc.cbSize = sizeof (wc);
00064 wc.style = 0;
00065 wc.lpfnWndProc = WndProc;
00066 wc.cbClsExtra = 0;
00067 wc.cbWndExtra = 0;
00068 wc.hInstance = _hModule;
00069 wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
00070 wc.hCursor = LoadCursor (_hModule, IDC_ARROW);
00071 wc.hIcon = NULL;
00072 wc.hIconSm = NULL;
00073 wc.lpszClassName = _pszWndClass;
00074 wc.lpszMenuName = NULL;
00075 wc.style = 0;
00076 RegisterClassEx (&wc);
00077
00078 return 0;
00079 }
00080
00081 NPError WINAPI NP_Shutdown()
00082 {
00083
00084 UnregisterClass (_pszWndClass, _hModule);
00085 return NPERR_NO_ERROR;
00086 }
00087
00088 void UrlToFdm (LPCSTR pszUrl)
00089 {
00090 IWGUrlReceiver* wg;
00091 HRESULT hr;
00092 if (FAILED (hr=CoCreateInstance (CLSID_WGUrlReceiver, NULL, CLSCTX_ALL, IID_IWGUrlReceiver, (void**) &wg)))
00093 {
00094 char szMsg [1000];
00095 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: ");
00096 char sz [100];
00097 itoa (hr, sz, 16);
00098 lstrcat (szMsg, sz);
00099 MessageBox (NULL, szMsg, "Error", MB_ICONERROR);
00100 return;
00101 }
00102
00103 _bstr_t url = pszUrl;
00104 wg->put_Url (url);
00105 wg->AddDownload ();
00106 wg->Release ();
00107 }
00108
00109 DWORD WINAPI _threadUrlToFdm (LPVOID lp)
00110 {
00111 CoInitialize (NULL);
00112 UrlToFdm ((LPCSTR) lp);
00113 delete [] (LPSTR) lp;
00114 CoUninitialize ();
00115 return 0;
00116 }
00117
00118 NPError NPP_NewStream (NPP npp, NPMIMEType, NPStream* stream, NPBool, uint16* stype)
00119 {
00120 DWORD dw;
00121 char *url = new char [strlen (stream->url) + 1];
00122 strcpy (url, stream->url);
00123 CloseHandle (CreateThread (NULL, 0, _threadUrlToFdm, (void*)url, 0, &dw));
00124 *stype = NP_NORMAL;
00125 return NPERR_GENERIC_ERROR;
00126
00127 }
00128
00129 NPError NPP_New (NPMIMEType, NPP npp, uint16, int16, char* arg [], char *argv [], NPSavedData*)
00130 {
00131
00132 if (npp == NULL)
00133 return NPERR_GENERIC_ERROR;
00134
00135 npp->pdata = NULL;
00136
00137 return 0;
00138 }
00139
00140 NPError NPP_Destroy (NPP, NPSavedData** pp)
00141 {
00142
00143 return NPERR_NO_ERROR;
00144 }
00145
00146 LRESULT WINAPI WndProc (HWND hWnd, UINT uMsg, WPARAM wp, LPARAM lp)
00147 {
00148
00149 switch (uMsg)
00150 {
00151 case WM_PAINT:
00152 PAINTSTRUCT ps;
00153 HDC dc = BeginPaint (hWnd, &ps);
00154
00155 SelectObject (dc, GetStockObject (WHITE_BRUSH));
00156 SelectObject (dc, GetStockObject (WHITE_PEN));
00157 RECT rc;
00158 GetClientRect (hWnd, &rc);
00159 Rectangle (dc, rc.left, rc.top, rc.right, rc.bottom);
00160 DrawIcon (dc, 5, 5, _Icon);
00161 LPCSTR pszMsg = "Download was transferred to Free Download Manager...\nPlease use \"Back\" button to go back";
00162 RECT rcT = rc;
00163 rcT.left = 40; rcT.top = 5;
00164 DrawText (dc, pszMsg, lstrlen (pszMsg), &rcT, DT_LEFT | DT_TOP);
00165 EndPaint (hWnd, &ps);
00166 return 0;
00167
00168 }
00169
00170 return DefWindowProc (hWnd, uMsg, wp, lp);
00171 }
00172
00173 NPError NPP_SetWindow (NPP npp, NPWindow* wnd)
00174 {
00175
00176
00177 if (wnd == NULL)
00178 return NPERR_GENERIC_ERROR;
00179 if (npp == NULL)
00180 return NPERR_INVALID_INSTANCE_ERROR;
00181 if (wnd->window == NULL)
00182 return NPERR_NO_ERROR;
00183
00184 HWND hWndParent = (HWND) wnd->window;
00185
00186 if (npp->pdata == NULL)
00187 {
00188 npp->pdata = CreateWindowEx (0, _pszWndClass, "", WS_CHILD | WS_VISIBLE,
00189 0, 0, wnd->width, wnd->height, hWndParent, NULL, _hModule, NULL);
00190 }
00191 else
00192 {
00193 MoveWindow ((HWND) npp->pdata, 0, 0, wnd->width, wnd->height, TRUE);
00194 }
00195
00196 return NPERR_NO_ERROR;
00197 }
00198
00199 NPError NPP_DestroyStream (NPP, NPStream*, NPReason)
00200 {
00201
00202 return NPERR_GENERIC_ERROR;
00203 }
00204
00205 void NPP_StreamAsFile (NPP, NPStream*, const char* file)
00206 {
00207
00208 }
00209
00210 int32 NPP_WriteReady (NPP npp, NPStream* stream)
00211 {
00212
00213
00214 return 1;
00215 }
00216
00217 int32 NPP_Write (NPP npp, NPStream* stream, int32 off, int32 len, void*)
00218 {
00219
00220
00221 return -1;
00222 }
00223
00224 void NPP_Print (NPP, NPPrint*)
00225 {
00226
00227 }
00228
00229 int16 NPP_HandleEvent (NPP, void* ev)
00230 {
00231 return NPERR_GENERIC_ERROR;
00232 }
00233
00234 short _stdcall NP_GetEntryPoints (NPPluginFuncs* p)
00235 {
00236
00237 if (p == NULL)
00238 return NPERR_INVALID_FUNCTABLE_ERROR;
00239
00240 ZeroMemory (p, p->size);
00241
00242 p->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
00243 p->newp = NPP_New;
00244 p->destroy = NPP_Destroy;
00245 p->setwindow = NPP_SetWindow;
00246 p->newstream = NPP_NewStream;
00247 p->destroystream = NPP_DestroyStream;
00248 p->asfile = NPP_StreamAsFile;
00249 p->writeready = NPP_WriteReady;
00250 p->write = NPP_Write;
00251 p->print = NPP_Print;
00252 p->event = 0;
00253
00254 g_plugFuncs = p;
00255
00256 return 0;
00257 }
00258