⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 npfreeamp.c

📁 freeamp有名的媒体播放器
💻 C
📖 第 1 页 / 共 3 页
字号:
/*____________________________________________________________________________
	
	FreeAmp - The Free MP3 Player

	Copyright (C) 2000 EMusic.com

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
	
	$Id: npfreeamp.c,v 1.1.2.2 2000/03/02 00:00:24 robert Exp $
____________________________________________________________________________*/

#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <string.h>
#include "npapi.h"

#ifdef _WINDOWS /* Windows Includes */
#include <windows.h>
#include "resource.h"
#endif /* _WINDOWS */

#ifdef XP_UNIX
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#endif /* XP_UNIX */

// Get rid of the silly benign redef of type warnings
#ifdef WIN32
#pragma warning(disable:4142)
#endif

#include "config.h"

const int iBoxWidth = 175;
const int iBoxLines = 6;
const int iDeleteButton = 0;
const int iImportButton = 1;
HINSTANCE g_hInst = NULL;

const HKEY  kMainKey = HKEY_CURRENT_USER;
const char* kFreeAmpKey = "SOFTWARE\\"BRANDING_COMPANY;
const char* kFreeAmpVersionKey = BRANDING" v"FREEAMP_MAJOR_VERSION"."FREEAMP_MINOR_VERSION;
const char* kMainComponentKey = "Main";
const char *szText1 = "Now downloading";
const char *szText2 = "into "the_BRANDING;
const char *szSponsor = "The development of FreeAmp is sponsored by:";

/*------------------------------------------------------------------------------
 * Windows PlatformInstance
 *----------------------------------------------------------------------------*/
#ifdef XP_PC
typedef struct _PlatformInstance
{
	HWND			fhWnd, hImportWnd, hDeleteWnd;
	WNDPROC			fDefaultWindowProc;
    RECT            sProgressRect, sBorder, sDeleteRect, sImportRect;
    HBITMAP         hEmusic, hFreeamp;
} PlatformInstance;
#endif /* XP_PC */
/*------------------------------------------------------------------------------
 * UNIX PlatformInstance
 *----------------------------------------------------------------------------*/
#ifdef XP_UNIX
typedef struct _PlatformInstance
{
    Window 			window;
    Display *		display;
    uint32 			x, y;
    uint32 			width, height;
} PlatformInstance;
#endif /* XP_UNIX */
/*------------------------------------------------------------------------------
 * Macintosh PlatformInstance
 *----------------------------------------------------------------------------*/
#ifdef XP_MAC
typedef struct _PlatformInstance
{
	int				placeholder;
} PlatformInstance;
#endif /* macintosh */
/*------------------------------------------------------------------------------
 * Cross-Platform PluginInstance
 *----------------------------------------------------------------------------*/
typedef struct _PluginInstance
{
	NPWindow*			fWindow;
	uint16				fMode;
    FILE               *fpFile;
    BOOL                bFreeAmp;
    int                 iBytesReceived, iPercentDone;
    char                szFileName[_MAX_PATH];
    char                szFreeAmpExe[_MAX_PATH];
    char                szTargetFile[_MAX_PATH];
	PlatformInstance	fPlatform;
} PluginInstance;


/******************************************************************************
 * Method Declarations
 ******************************************************************************/
void        UpdateProgress(PluginInstance* This, int iPercentDone);
void		PlatformNew( PluginInstance* This );
NPError		PlatformDestroy( PluginInstance* This );
NPError		PlatformSetWindow( PluginInstance* This, NPWindow* window );
int16		PlatformHandleEvent( PluginInstance* This, void* event );


/*******************************************************************************
 * SECTION 3 - API Plugin Implementations
 ******************************************************************************/

static HWND hDebugWind;

void DebugInit_v(void)
{
    hDebugWind = FindWindow("#32770", "Debug32");
}

void Debug_v(char * format, ...)
{
    char szBuffer[4096];
    va_list argptr;
    ATOM hAtom;
    
    if (hDebugWind == NULL) 
    {
        DebugInit_v();
        if (hDebugWind == NULL) 
           return;
    }

    va_start(argptr, format);
    vsprintf(szBuffer, format, argptr);
    va_end(argptr);

    szBuffer[254] = 0;
    hAtom = GlobalAddAtom(szBuffer);
    SendMessage( hDebugWind, WM_USER + 1, 0, (LPARAM)hAtom);
    GlobalDeleteAtom(hAtom);
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, 
                    DWORD fdwReason, 
                    LPVOID lpvReserved)
{                         
    switch(fdwReason)
    { 
         case DLL_PROCESS_ATTACH:
            g_hInst = hinstDLL;
         break;
    }
    
    return TRUE;
} 

/*------------------------------------------------------------------------------
 * Cross-Platform Plug-in API Calls
 *----------------------------------------------------------------------------*/
 
NPError
NPP_Initialize(void)
{
    return NPERR_NO_ERROR;
}

jref
NPP_GetJavaClass(void)
{
	return NULL;
}

void
NPP_Shutdown(void)
{
}

NPError 
NPP_New(NPMIMEType pluginType,
	NPP instance,
	uint16 mode,
	int16 argc,
	char* argn[],
	char* argv[],
	NPSavedData* saved)
{
	NPError result = NPERR_NO_ERROR;
	PluginInstance* This;

	if (instance == NULL) {
		return NPERR_INVALID_INSTANCE_ERROR;
	}
	instance->pdata = NPN_MemAlloc(sizeof(PluginInstance));
	This = (PluginInstance*) instance->pdata;
	if (This == NULL) {
	    return NPERR_OUT_OF_MEMORY_ERROR;
	}
	/* mode is NP_EMBED, NP_FULL, or NP_BACKGROUND (see npapi.h) */
	This->fWindow = NULL;
	This->fMode = mode;
    This->fpFile = NULL;
    This->iBytesReceived = 0;
    This->iPercentDone = 0;
    This->bFreeAmp = !strcasecmp(BRANDING, "FreeAmp");
    This->fPlatform.sProgressRect.left = -1;
    This->fPlatform.sProgressRect.top = -1;
    This->fPlatform.hImportWnd = NULL;
    This->fPlatform.hDeleteWnd = NULL;
    This->fPlatform.hEmusic = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_EMUSIC));
    This->fPlatform.hFreeamp = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_FREEAMP));
	
	PlatformNew( This ); 	/* Call Platform-specific initializations */

		/* PLUGIN DEVELOPERS:
		 *	Initialize fields of your plugin
		 *	instance data here.  If the NPSavedData is non-
		 *	NULL, you can use that data (returned by you from
		 *	NPP_Destroy to set up the new plugin instance).
		 */

	return result;
}

NPError 
NPP_Destroy(NPP instance, NPSavedData** save)
{
	PluginInstance* This;

	if (instance == NULL)
		return NPERR_INVALID_INSTANCE_ERROR;

	This = (PluginInstance*) instance->pdata;
	PlatformDestroy( This ); /* Perform platform specific cleanup */
	
	/* PLUGIN DEVELOPERS:
	 *	If desired, call NP_MemAlloc to create a
	 *	NPSavedDate structure containing any state information
	 *	that you want restored if this plugin instance is later
	 *	recreated.
	 */

	if (This != NULL) {
		NPN_MemFree(instance->pdata);
		instance->pdata = NULL;
	}

	return NPERR_NO_ERROR;
}

NPError 
NPP_SetWindow(NPP instance, NPWindow* window)
{
	NPError result = NPERR_NO_ERROR;
	PluginInstance* This;

	if (instance == NULL)
		return NPERR_INVALID_INSTANCE_ERROR;

	This = (PluginInstance*) instance->pdata;

	/*
	 * PLUGIN DEVELOPERS:
	 *	Before setting window to point to the
	 *	new window, you may wish to compare the new window
	 *	info to the previous window (if any) to note window
	 *	size changes, etc.
	 */
	result = PlatformSetWindow( This, window );
	
	This->fWindow = window;
	return result;
}

NPError 
NPP_NewStream(NPP instance,
	      NPMIMEType type,
	      NPStream *stream, 
	      NPBool seekable,
	      uint16 *stype)
{
	PluginInstance* This;
    LONG            result, len;
    char            szBuf[_MAX_PATH];
    char            szBase[_MAX_PATH], szExt[_MAX_PATH];
    char           *pPtr;
    HKEY            hKey;
    DWORD           dwType;
    int             i;

	if (instance == NULL)
		return NPERR_INVALID_INSTANCE_ERROR;

	This = (PluginInstance*) instance->pdata;

    sprintf(szBuf, "%s\\%s\\%s", kFreeAmpKey, 
            kFreeAmpVersionKey, kMainComponentKey);
    result = RegOpenKeyEx(HKEY_CURRENT_USER, szBuf, 
						  0, 
                          KEY_READ,
                          &hKey);
    if (result != ERROR_SUCCESS)
    {
        MessageBox(NULL, "Cannot determine where player is installed.\r\nPlease check you player installation.",
                   "Download Plugin", MB_OK);
        return NPERR_GENERIC_ERROR;
    }    
        
    len = sizeof(szBuf);
	result = RegQueryValueEx(hKey, "SaveMusicDirectory", NULL, &dwType, (LPBYTE)szBuf, &len);
    if (result != ERROR_SUCCESS)
    {
        RegCloseKey(hKey);
        MessageBox(NULL, "Cannot determine where player is installed.\r\nPlease check you player installation.",
                   "Download Plugin", MB_OK);
        return NPERR_GENERIC_ERROR;
    }    

    len = sizeof(This->szFreeAmpExe); 
	result = RegQueryValueEx(hKey, "InstallDirectory", NULL, &dwType, (LPBYTE)This->szFreeAmpExe, &len);
    if (result != ERROR_SUCCESS)
    {
        RegCloseKey(hKey);
        MessageBox(NULL, "Cannot determine where player is installed.\r\nPlease check you player installation.",
                   "Download Plugin", MB_OK);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -