📄 npfreeamp.c
字号:
return NPERR_GENERIC_ERROR;
}
strcat(This->szFreeAmpExe, "\\");
strcat(This->szFreeAmpExe, BRANDING_EXE_FILE);
RegCloseKey(hKey);
Debug_v("url: '%s'", stream->url);
pPtr = strrchr(stream->url, '/');
if (pPtr == NULL)
{
MessageBox(NULL, "Cannot determine the name of the file to be downloaded.",
"Download Plugin", MB_OK);
return NPERR_GENERIC_ERROR;
}
strcpy(szBase, pPtr + 1);
pPtr = strrchr(szBase, '.');
if (pPtr)
{
strcpy(szExt, pPtr + 1);
*pPtr = 0;
}
else
szExt[0] = 0;
sprintf(This->szFileName, "%s.%s", szBase, szExt);
for(i = 0;; i++)
{
if (i == 0)
sprintf(This->szTargetFile, "%s\\%s.%s", szBuf, szBase, szExt);
else
sprintf(This->szTargetFile, "%s\\%s-%d.%s", szBuf, szBase, i + 1, szExt);
if (_access(This->szTargetFile, 0))
break;
}
This->fpFile = fopen(This->szTargetFile, "wb");
if (This->fpFile == NULL)
{
MessageBox(NULL, "Cannot create the download file. Please check you player installation.",
"Download Plugin", MB_OK);
return NPERR_GENERIC_ERROR;
}
return NPERR_NO_ERROR;
}
int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile
* mode so we can take any size stream in our
* write call (since we ignore it) */
int32
NPP_WriteReady(NPP instance, NPStream *stream)
{
PluginInstance* This;
if (instance != NULL)
This = (PluginInstance*) instance->pdata;
/* Number of bytes ready to accept in NPP_Write() */
return STREAMBUFSIZE;
}
int32
NPP_Write(NPP instance, NPStream *stream, int32 offset,
int32 len, void *buffer)
{
int iRet;
if (instance != NULL)
{
PluginInstance* This = (PluginInstance*) instance->pdata;
RECT sRect;
if (This->fpFile == NULL)
return -1;
iRet = fwrite(buffer, sizeof(char), len, This->fpFile);
if (iRet != len)
MessageBox(NULL, "Cannot write file to disk. Disk Full?",
"Download Plugin", MB_OK);
This->iBytesReceived += len;
This->iPercentDone = This->iBytesReceived * 100 / stream->end;
sRect = This->fPlatform.sProgressRect;
sRect.right += 100;
InvalidateRect(This->fPlatform.fhWnd, &sRect, FALSE);
UpdateWindow(This->fPlatform.fhWnd);
len = iRet;
}
else
len = -1;
return len; /* The number of bytes accepted */
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++
* NPP_DestroyStream:
* Indicates the closure and deletion of a stream, and returns an error value.
*
* The NPP_DestroyStream function is called when the stream identified by
* stream for the plug-in instance denoted by instance will be destroyed. You
* should delete any private data allocated in stream->pdata at this time.
+++++++++++++++++++++++++++++++++++++++++++++++++*/
NPError
NPP_DestroyStream(NPP instance, NPStream *stream, NPError reason)
{
STARTUPINFO sInfo;
PROCESS_INFORMATION sProcess;
PluginInstance *This;
char szArgs[_MAX_PATH];
BOOL bRet;
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR;
This = (PluginInstance*) instance->pdata;
if (This->fpFile)
fclose(This->fpFile);
if (reason == NPRES_DONE)
{
BOOL bImport;
bImport = SendMessage(This->fPlatform.hImportWnd, BM_GETCHECK, 0, 0);
memset(&sInfo, 0, sizeof(sInfo));
sInfo.cb = sizeof(STARTUPINFO);
if (bImport)
sprintf(szArgs, "%s -import \"%s\"", This->szFreeAmpExe, This->szTargetFile);
else
sprintf(szArgs, "%s -delete \"%s\"", This->szFreeAmpExe, This->szTargetFile);
//sprintf(szArgs, "%s \"%s\"", This->szFreeAmpExe, This->szTargetFile);
bRet = CreateProcess(NULL, szArgs, NULL, NULL, FALSE,
CREATE_NEW_PROCESS_GROUP, NULL, NULL, &sInfo, &sProcess);
}
else
unlink(This->szTargetFile);
EnableWindow(This->fPlatform.hDeleteWnd, FALSE);
EnableWindow(This->fPlatform.hImportWnd, FALSE);
return NPERR_NO_ERROR;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++
* NPP_StreamAsFile:
* Provides a local file name for the data from a stream.
*
* NPP_StreamAsFile provides the instance with a full path to a local file,
* identified by fname, for the stream specified by stream. NPP_StreamAsFile is
* called as a result of the plug-in requesting mode NP_ASFILEONLY or
* NP_ASFILE in a previous call to NPP_NewStream. If an error occurs while
* retrieving the data or writing the file, fname may be NULL.
+++++++++++++++++++++++++++++++++++++++++++++++++*/
void
NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname)
{
PluginInstance* This;
if (instance != NULL)
This = (PluginInstance*) instance->pdata;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++
* NPP_Print:
+++++++++++++++++++++++++++++++++++++++++++++++++*/
void
NPP_Print(NPP instance, NPPrint* printInfo)
{
if(printInfo == NULL)
return;
if (instance != NULL) {
PluginInstance* This = (PluginInstance*) instance->pdata;
if (printInfo->mode == NP_FULL) {
/*
* PLUGIN DEVELOPERS:
* If your plugin would like to take over
* printing completely when it is in full-screen mode,
* set printInfo->pluginPrinted to TRUE and print your
* plugin as you see fit. If your plugin wants Netscape
* to handle printing in this case, set
* printInfo->pluginPrinted to FALSE (the default) and
* do nothing. If you do want to handle printing
* yourself, printOne is true if the print button
* (as opposed to the print menu) was clicked.
* On the Macintosh, platformPrint is a THPrint; on
* Windows, platformPrint is a structure
* (defined in npapi.h) containing the printer name, port,
* etc.
*/
void* platformPrint =
printInfo->print.fullPrint.platformPrint;
NPBool printOne =
printInfo->print.fullPrint.printOne;
/* Do the default*/
printInfo->print.fullPrint.pluginPrinted = FALSE;
}
else { /* If not fullscreen, we must be embedded */
/*
* PLUGIN DEVELOPERS:
* If your plugin is embedded, or is full-screen
* but you returned false in pluginPrinted above, NPP_Print
* will be called with mode == NP_EMBED. The NPWindow
* in the printInfo gives the location and dimensions of
* the embedded plugin on the printed page. On the
* Macintosh, platformPrint is the printer port; on
* Windows, platformPrint is the handle to the printing
* device context.
*/
NPWindow* printWindow =
&(printInfo->print.embedPrint.window);
void* platformPrint =
printInfo->print.embedPrint.platformPrint;
}
}
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++
* NPP_URLNotify:
* Notifies the instance of the completion of a URL request.
*
* NPP_URLNotify is called when Netscape completes a NPN_GetURLNotify or
* NPN_PostURLNotify request, to inform the plug-in that the request,
* identified by url, has completed for the reason specified by reason. The most
* common reason code is NPRES_DONE, indicating simply that the request
* completed normally. Other possible reason codes are NPRES_USER_BREAK,
* indicating that the request was halted due to a user action (for example,
* clicking the "Stop" button), and NPRES_NETWORK_ERR, indicating that the
* request could not be completed (for example, because the URL could not be
* found). The complete list of reason codes is found in npapi.h.
*
* The parameter notifyData is the same plug-in-private value passed as an
* argument to the corresponding NPN_GetURLNotify or NPN_PostURLNotify
* call, and can be used by your plug-in to uniquely identify the request.
+++++++++++++++++++++++++++++++++++++++++++++++++*/
void
NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
{
/* Not used in the Simple plugin. */
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++
* NPP_HandleEvent:
* Mac-only, but stub must be present for Windows
* Delivers a platform-specific event to the instance.
*
* On the Macintosh, event is a pointer to a standard Macintosh EventRecord.
* All standard event types are passed to the instance as appropriate. In general,
* return TRUE if you handle the event and FALSE if you ignore the event.
+++++++++++++++++++++++++++++++++++++++++++++++++*/
#ifndef XP_UNIX
int16
NPP_HandleEvent(NPP instance, void* event)
{
PluginInstance* This;
int16 eventHandled = FALSE;
if (instance == NULL)
return eventHandled;
This = (PluginInstance*) instance->pdata;
eventHandled = PlatformHandleEvent(This, event);
return eventHandled;
}
#endif /* ndef XP_UNIX */
/*******************************************************************************/
LRESULT CALLBACK PluginWindowProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
const char* gInstanceLookupString = "instance->pdata";
/*+++++++++++++++++++++++++++++++++++++++++++++++++
* PlatformNew
*
* Initialize any Platform-Specific instance data.
+++++++++++++++++++++++++++++++++++++++++++++++++*/
void
PlatformNew( PluginInstance* This )
{
This->fPlatform.fhWnd = NULL;
This->fPlatform.fDefaultWindowProc = NULL;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++
* PlatformDestroy
*
* Destroy any Platform-Specific instance data.
+++++++++++++++++++++++++++++++++++++++++++++++++*/
NPError
PlatformDestroy( PluginInstance* This )
{
if( This->fWindow != NULL ) { /* If we have a window, clean
* it up. */
SetWindowLong( This->fPlatform.fhWnd, GWL_WNDPROC, (LONG)This->fPlatform.fDefaultWindowProc);
This->fPlatform.fDefaultWindowProc = NULL;
This->fPlatform.fhWnd = NULL;
DeleteObject(This->fPlatform.hEmusic);
DeleteObject(This->fPlatform.hFreeamp);
DestroyWindow(This->fPlatform.hImportWnd);
DestroyWindow(This->fPlatform.hDeleteWnd);
}
return NPERR_NO_ERROR;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++
* PlatformSetWindow
*
* Perform platform-specific window operations
+++++++++++++++++++++++++++++++++++++++++++++++++*/
NPError
PlatformSetWindow( PluginInstance* This, NPWindow* window )
{
SIZE sSize;
HDC hDc;
RECT sRect;
if( This->fWindow != NULL ) /* If we already have a window, clean
* it up before trying to subclass
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -