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

📄 hxresmg.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: hxresmg.cpp,v 1.8.20.1 2004/07/09 02:07:27 hubbe Exp $ *  * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved. *  * The contents of this file, and the files included with this file, * are subject to the current version of the RealNetworks Public * Source License (the "RPSL") available at * http://www.helixcommunity.org/content/rpsl unless you have licensed * the file under the current version of the RealNetworks Community * Source License (the "RCSL") available at * http://www.helixcommunity.org/content/rcsl, in which case the RCSL * will apply. You may also obtain the license terms directly from * RealNetworks.  You may not use this file except in compliance with * the RPSL or, if you have a valid RCSL with RealNetworks applicable * to this file, the RCSL.  Please see the applicable RPSL or RCSL for * the rights, obligations and limitations governing use of the * contents of the file. *  * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL") in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your version of * this file only under the terms of the GPL, and not to allow others * to use your version of this file under the terms of either the RPSL * or RCSL, indicate your decision by deleting the provisions above * and replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient may * use your version of this file under the terms of any one of the * RPSL, the RCSL or the GPL. *  * This file is part of the Helix DNA Technology. RealNetworks is the * developer of the Original Code and owns the copyrights in the * portions it created. *  * This file, and the files included with this file, is distributed * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET * ENJOYMENT OR NON-INFRINGEMENT. *  * Technology Compatibility Kit Test Suite(s) Location: *    http://www.helixcommunity.org/content/tck *  * Contributor(s): *  * ***** END LICENSE BLOCK ***** */#include "hxcom.h"#include "hlxclib/stdio.h"#include "hlxclib/stdlib.h"#ifdef _WINDOWS#include <windows.h>#endif#if defined(_MACINTOSH) && !defined(_MAC_MACHO)#include <stat.h>#else#include "hlxclib/sys/stat.h"#endif#include "hxxrsmg.h"#include "hxplugn.h"#include "hxfiles.h"#include "hxcomm.h"#include "hxxres.h"#include "hxengin.h"#include "ihxpckts.h"#include "hxprefs.h"#include "hxmon.h"#include "hxslist.h"#include "hxstrutl.h"#include "chxpckts.h"#include "md5.h"#include "findfile.h"#include "hxresmg.h"#include "dllpath.h"#include "hxheap.h"#ifdef _DEBUG#undef HX_THIS_FILEstatic const char HX_THIS_FILE[] = __FILE__;#endif// IHXPreferences key defines#define EXT_RES_DIR		"ExtResources"#define EXT_RES_DATA_KEY	"ExternalResourcesData"#define FILE_INFO_KEY		"FileInfo"#define CHECKSUM_KEY		"XRSCheckSum"#define LANGUAGE_KEY		"Language"#define LANG_ID_KEY		"LangID"// for OS_SEPARATOR_CHAR and OS_SEPARATOR_STRING#include "hxdir.h"// static initializations#if !defined(HELIX_CONFIG_NOSTATICS)HXExternalResourceManager* HXExternalResourceManager::m_pResourceManager = NULL;#else#include "globals/hxglobals.h"const HXExternalResourceManager* const HXExternalResourceManager::m_pResourceManager = NULL;#endif// HXExternalResourceManager methodsHXExternalResourceManager::HXExternalResourceManager(IUnknown* pContext):     m_lRefCount(0)    ,m_pResourceList(NULL)    ,m_pContext(pContext)    ,m_pHXXResPlugin(NULL)    ,m_ulLanguageID(0x0409)    ,m_pExternalResDir(NULL)    ,m_pPrefs(NULL)    ,m_pRegistry(NULL){    if(m_pContext)    {	m_pContext->AddRef();    }    Init();}HXExternalResourceManager::~HXExternalResourceManager(){    delete[] m_pExternalResDir;    if(m_pResourceList)    {	CHXSimpleList::Iterator i = m_pResourceList->Begin();	for (; i != m_pResourceList->End(); ++i)	{	    IHXXResFile* pRes = (IHXXResFile*)(*i);	    pRes->Close();	    pRes->Release();	}    }    HX_DELETE(m_pResourceList);    HX_RELEASE(m_pPrefs);    HX_RELEASE(m_pRegistry);    HX_RELEASE(m_pContext);    HX_RELEASE(m_pHXXResPlugin);#if defined(HELIX_CONFIG_NOSTATICS)    HXExternalResourceManager*& m_pResourceManager =	(HXExternalResourceManager*&)HXGlobalPtr::Get(	    &HXExternalResourceManager::m_pResourceManager);#endif    m_pResourceManager = NULL;}HXExternalResourceManager*HXExternalResourceManager::Instance(IUnknown* pContext){#if defined(HELIX_CONFIG_NOSTATICS)    HXExternalResourceManager*& m_pResourceManager =	(HXExternalResourceManager*&)HXGlobalPtr::Get(	    &HXExternalResourceManager::m_pResourceManager);#endif    if(!m_pResourceManager)    {	m_pResourceManager = new HXExternalResourceManager(pContext);    }    if (m_pResourceManager)    {	m_pResourceManager->AddRef();    }    return m_pResourceManager;}// IUnknown methodsSTDMETHODIMP HXExternalResourceManager::QueryInterface(REFIID riid, void** ppvObj){    QInterfaceList qiList[] =        {            { GET_IIDHANDLE(IID_IHXExternalResourceManager), (IHXExternalResourceManager*)this },            { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)(IHXExternalResourceManager*)this },        };        return ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);}STDMETHODIMP_(ULONG32) HXExternalResourceManager::AddRef(){    return InterlockedIncrement(&m_lRefCount);}STDMETHODIMP_(ULONG32) HXExternalResourceManager::Release(){    if (InterlockedDecrement(&m_lRefCount) > 0)    {	return m_lRefCount;    }    delete this;    return 0;}// IHXExternalResourceManager methodsSTDMETHODIMPHXExternalResourceManager::Init(){    HX_RESULT rc = GetHXXResPlugin();    if(HXR_OK == rc)    {	// get language and res directory preferences/reg entries	if (HXR_OK == m_pContext->QueryInterface(IID_IHXPreferences,						(void**)&m_pPrefs) &&	    HXR_OK == m_pContext->QueryInterface(IID_IHXRegistry, 						(void**)&m_pRegistry))	{	    IHXBuffer* pBuffer = NULL;	    CHXString strTemp;	    strTemp.Format("%s.%s",HXREGISTRY_PREFPROPNAME, "LangID");	    if(HXR_OK == m_pRegistry->GetStrByName(strTemp, pBuffer))	    {		const char* pActualLangID = (const char*)pBuffer->GetBuffer();		m_ulLanguageID = strtol(pActualLangID, NULL, 10);		HX_RELEASE(pBuffer);	    }            const char* pPath = NULL;            // Get the plugin directory from the Dll Access Paths            if (GetDLLAccessPath() &&                (pPath = GetDLLAccessPath()->GetPath(DLLTYPE_PLUGIN)) &&                *pPath)            {                UINT32 ulBufLen = strlen(pPath) + 1 + strlen(EXT_RES_DIR) + 1;                m_pExternalResDir = new char[ulBufLen];                SafeStrCpy(m_pExternalResDir, pPath, ulBufLen);                if (m_pExternalResDir[strlen(m_pExternalResDir)-1] != OS_SEPARATOR_CHAR)                {                    SafeStrCat(m_pExternalResDir, OS_SEPARATOR_STRING, ulBufLen);                }                SafeStrCat(m_pExternalResDir, EXT_RES_DIR, ulBufLen);                rc = LoadResourceFiles();            }	}    }    return rc;}STDMETHODIMPHXExternalResourceManager::CreateExternalResourceReader(				    const char* pShortName,				    REF(IHXExternalResourceReader*) pReader){    HX_RESULT rc = HXR_OK;    HXExternalResourceReader* pHXReader = new HXExternalResourceReader(this);    if(!pHXReader)    {	return HXR_OUTOFMEMORY;    }    pHXReader->AddRef();    pHXReader->Init(pShortName, m_pResourceList);    pReader = pHXReader;    return rc;}// HXExternalResourceManager private methodsHX_RESULTHXExternalResourceManager::GetHXXResPlugin(){    HX_RESULT rc = HXR_FAILED;    IUnknown* pUnk = NULL;    IUnknown* pUnknownInstance = NULL;    IHXCommonClassFactory* pCommonClassFactory = NULL;    IHXPluginGroupEnumerator* pGroupEnumerator = NULL;    UINT32 ulNumPlugins = 0;    // enumerate the plugins    if (HXR_OK != m_pContext->QueryInterface(				IID_IHXCommonClassFactory,				(void**)&pCommonClassFactory))    {	goto cleanup;    }    if (HXR_OK != pCommonClassFactory->CreateInstance(				CLSID_IHXPluginGroupEnumerator,				(void**)&pUnk))    {	goto cleanup;    }    if (HXR_OK != pUnk->QueryInterface(IID_IHXPluginGroupEnumerator,				    (void**)&pGroupEnumerator))    {	goto cleanup;    }    if (HXR_OK != pGroupEnumerator->Init(IID_IHXXResFile))    {	goto cleanup;    }    ulNumPlugins = pGroupEnumerator->GetNumOfPlugins();    if(ulNumPlugins > 0)    {	if (HXR_OK == pGroupEnumerator->GetPlugin(0, pUnknownInstance))	{	    m_pHXXResPlugin = pUnknownInstance;	    m_pHXXResPlugin->AddRef();	    rc = HXR_OK;	}    }cleanup:    HX_RELEASE(pUnk);    HX_RELEASE(pUnknownInstance);    HX_RELEASE(pCommonClassFactory);    HX_RELEASE(pGroupEnumerator);    return rc;}BOOLHXExternalResourceManager::ContainsCurrentLanguage(IHXXResFile* pResFile){    BOOL rc = FALSE;    if(!pResFile)    {	return rc;    }    UINT32 ulLangID = 0;    BOOL bFound = FALSE;    rc = pResFile->GetFirstResourceLanguage(ulLangID);    while(HXR_OK == rc)    {	if(m_ulLanguageID == ulLangID)	{	    rc = TRUE;	    break;	}	rc = pResFile->GetNextResourceLanguage(ulLangID);    };    return rc;}IHXXResFile*HXExternalResourceManager::MakeResFileObject(const char* pPath){    IHXXResFile* pResFile = NULL;    if(m_pHXXResPlugin &&	HXR_OK == m_pHXXResPlugin->QueryInterface(IID_IHXXResFile, 						(void**)&pResFile))    {	HX_RESULT rc = HXR_OK;	// open res file and see if it contains any resources with the	// current language ID	pResFile->Open(pPath);	if(ContainsCurrentLanguage(pResFile))	{	    pResFile->SetLanguage(m_ulLanguageID);	}	else	{	    HX_RELEASE(pResFile);   // don't want this one	}    }    return pResFile;}HX_RESULTHXExternalResourceManager::Stat(const char* pPath, struct stat* pStatBuffer){    HX_RESULT rc = HXR_OK;

⌨️ 快捷键说明

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