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

📄 chgrstrm.cpp

📁 Windows上的MUD客户端程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*----------------------------------------------------------------------------
                        _                              _ _       
        /\             | |                            | (_)      
       /  \   _ __   __| |_ __ ___  _ __ ___   ___  __| |_  __ _ 
      / /\ \ | '_ \ / _` | '__/ _ \| '_ ` _ \ / _ \/ _` | |/ _` |
     / ____ \| | | | (_| | | | (_) | | | | | |  __/ (_| | | (_| |
    /_/    \_\_| |_|\__,_|_|  \___/|_| |_| |_|\___|\__,_|_|\__,_|

    The contents of this file are subject to the Andromedia Public
	License Version 1.0 (the "License"); you may not use this file
	except in compliance with the License. You may obtain a copy of
	the License at http://www.andromedia.com/APL/

    Software distributed under the License is distributed on an
	"AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
	implied. See the License for the specific language governing
	rights and limitations under the License.

    The Original Code is Pueblo client code, released November 4, 1998.

    The Initial Developer of the Original Code is Andromedia Incorporated.
	Portions created by Andromedia are Copyright (C) 1998 Andromedia
	Incorporated.  All Rights Reserved.

	Andromedia Incorporated                         415.365.6700
	818 Mission Street - 2nd Floor                  415.365.6701 fax
	San Francisco, CA 94103

    Contributor(s):
	--------------------------------------------------------------------------
	   Chaco team:  Dan Greening, Glenn Crocker, Jim Doubek,
	                Coyote Lussier, Pritham Shetty.

					Wrote and designed original codebase.

------------------------------------------------------------------------------

	Implementation for the mime handlers for ChMaze.

----------------------------------------------------------------------------*/

// $Header: 

#include "grheader.h"


#include <ChReg.h>
#include <ChHTTP.h>
#include <ChUtil.h>	
#include <ChUnzip.h>	

#include <ChDibDecoder.h>
#include <ChGIFDecoder.h>
#include <ChJPEGDecoder.h>

#if !defined(CH_VRML_VIEWER) && !defined(CH_VRML_PLUGIN )
#include "ChCore.h"
#include <ChMsgTyp.h>
#include <ChModule.h>
#include "ChGrMod.h"
#endif


#include "ChMaze.h"
#include "ChMazDep.h"
#include "ChRLImg.h"


#include "ChGrStrm.h"
#include "ChRenderData.h"


#if !defined(CH_VRML_VIEWER) && !defined(CH_VRML_PLUGIN )  
ChGraphicStreamManager::ChGraphicStreamManager( ChCore* pCore, ChHTTPStreamManager* pNext) 
						: m_pNextStream( pNext ),
						  m_pCore( pCore )
#else
ChGraphicStreamManager::ChGraphicStreamManager( ChHTTPStreamManager* pNext) : m_pNextStream( pNext )
#endif
{


	m_iSysType = ChUtil::GetSystemType();

	if (  m_iSysType == CH_SYS_WINNT	||  m_iSysType == CH_SYS_WIN95 )
	{									// Initialize the critcal section

		::InitializeCriticalSection( &m_syncDecode );
	}
}

ChGraphicStreamManager::~ChGraphicStreamManager( )
{
	if (  m_iSysType == CH_SYS_WINNT ||  m_iSysType == CH_SYS_WIN95 )
	{									// Initialize the critcal section

		::DeleteCriticalSection( &m_syncDecode );
	}
}


int ChGraphicStreamManager::NewStream( chparam requestData, pChHTTPStream pStream, bool boolSeekable  )
{
	return streamAsFile;
}


void ChGraphicStreamManager::StreamAsFile(chparam requestData, pChHTTPStream pStream, const char* fname)
{

	int iMimeType = ChHTTPConn::GetMimeType( pStream->GetMimeType() );

	ChGraphicHTTPReq::type loadType = ChGraphicHTTPReq::scene;
	ChGraphicHTTPReq *pHTTPReq	 = (ChGraphicHTTPReq *)requestData;

	if(requestData)
	{
		loadType = pHTTPReq->GetType();
	}

	switch(loadType)
	{
		#if !defined(CH_VRML_VIEWER) && !defined(CH_VRML_PLUGIN )  
		case ChGraphicHTTPReq::anchor:
		case ChGraphicHTTPReq::script:
		case ChGraphicHTTPReq::sprite:
		case ChGraphicHTTPReq::background:
		case ChGraphicHTTPReq::document:
		{
			ChModuleID idModule = 0;

			if ( loadType == ChGraphicHTTPReq::document )
			{
				ChGraphicDocumentHTTPReq* pReq = (ChGraphicDocumentHTTPReq*)pHTTPReq;
				idModule = pReq->GetModuleID();
			}
			else
			{
				if ( pHTTPReq->GetView() )
				{
					idModule = ((ChGraphicView*)pHTTPReq->GetView())->GetMainInfo()->GetModuleID();
				}
			}

			if ( idModule )
			{
				ChLoadCompleteMsg*	pMsg = new ChLoadCompleteMsg( pStream->GetURL(), 
								pStream->GetCacheFilename(), 
								pStream->GetMimeType(),
								requestData );
				#if defined( CH_MSW ) && defined( CH_ARCH_32 )
				if ( ChUtil::GetSystemProperties() & CH_PROP_MULTITHREADED )
				{  // Send it to the core frame which will to the dispatch
			
					m_pCore->AsyncDispatchMsg( idModule, pMsg );
				}
				else
				{
					m_pCore->DispatchMsg( idModule, *pMsg );
					delete pMsg;
				}
				#else
				m_pCore->DispatchMsg( idModule, *pMsg );
				delete pMsg;
				#endif	// defined( CH_MSW )
			}
			break;
		}
		#endif
		case ChGraphicHTTPReq::scene:
		{
			#if defined(CH_VRML_VIEWER) || defined(CH_VRML_PLUGIN )
	 		// Load a file of vrml
			if ( GetNextStreamMgr() )
			{
				GetNextStreamMgr()->StreamAsFile( requestData,  pStream, fname);
			}
			#else
			TRACE( "We should never have come here\n" );
			ASSERT( false );
			#endif

			delete pHTTPReq;  // it's done
			break;
		}
		case ChGraphicHTTPReq::texture:
		{
											// Load a texture
 			ChMazeTextureHTTPReq *pReq = (ChMazeTextureHTTPReq *)pHTTPReq;

			if( pReq->GetPage() == pReq->GetView()->GetCurrentPage() )
			{
				pReq->SetTextureType( iMimeType );
				// load the texture
				LoadTexture( iMimeType, pStream, pReq );
			}
			else
			{	// no longer required
				delete pReq;  // it's done
			}

			break;
		}
		case ChGraphicHTTPReq::wwwInline:
		{
			// Load the inline file
 			ChMazeInlineHTTPReq *pReq = (ChMazeInlineHTTPReq *)pHTTPReq;
			pReq->GetView()->GetRenderContext()->LockQv();	
			if(pReq->GetPage() == pReq->GetView()->GetCurrentPage() && !pReq->IsCancelled())
			{
				ASSERT(pReq->GetInlineNode());

			   	if ( ChHTTPConn::typeVRML == iMimeType )
				{
					pReq->SetFileType( iMimeType );

					int iType =  ChUnzip::GetZipType( pStream->GetCacheFilename() );

					if ( iType != ChUnzip::typeUnknown )
					{
					  	string strNewFile;

						ChUtil::GetTempFileName( strNewFile, 0, 0, ".wrl" );

						ChUnzip unzip;

						if ( unzip.UnzipFileTo( pStream->GetCacheFilename(), 
										iType == ChUnzip::typeGZIP ? UNZIP_OPT_GZIP_FILE : UNZIP_DEF_OPTION,
										0, strNewFile ) )
						{
					  	
							// load the file
							pReq->GetView()->LoadWWWInline( pStream->GetURL(), strNewFile, pReq->GetInlineNode() );

							// add file to temp list
							ChUtil::AddFileToTempList( strNewFile );
						}
					}
					else
					{

						// load the file
						pReq->GetView()->LoadWWWInline( pStream->GetURL(), 
										pStream->GetCacheFilename(), pReq->GetInlineNode());
					}
				}
														 // request phase is complete
				((ChQvWWWInlineRenderData*)(pReq->GetInlineNode()->GetRenderData()))->SetReq(0);

			}
			else
			{
				if(pReq->IsCancelled()) TRACE("Inline HTTP request cancelled\n");
			}
			pReq->GetView()->GetRenderContext()->UnlockQv();	
			delete pReq;  // it's done
			break;
		}
		default:
		{
			break;
		}
	}

}

void ChGraphicStreamManager::DestroyStream( chparam requestData, pChHTTPStream pStream, int iReason )
{
	if(iReason)
	{
		TRACE1("Stream request failed; reason %d\n", iReason);
		#if !defined(CH_VRML_VIEWER) && !defined(CH_VRML_PLUGIN )  
		ChGraphicHTTPReq::type loadType = ChGraphicHTTPReq::scene;
		ChGraphicHTTPReq *pHTTPReq	 = (ChGraphicHTTPReq *)requestData;

		if(requestData)
		{
			loadType = pHTTPReq->GetType();
		}
		ChModuleID idModule = 0;

		if ( loadType == ChGraphicHTTPReq::document )
		{
			ChGraphicDocumentHTTPReq* pReq = (ChGraphicDocumentHTTPReq*)pHTTPReq;
			idModule = pReq->GetModuleID();
		}
		else
		{
			if ( pHTTPReq->GetView() )
			{
				if((ChGraphicView*)pHTTPReq->GetView())
				{
					idModule = ((ChGraphicView*)pHTTPReq->GetView())->GetMainInfo()->GetModuleID();
				}
			}
		}

		if ( idModule )
		{
			string strError = pStream->GetErrorMsg();
			ChLoadErrorMsg*	pMsg = new ChLoadErrorMsg( "", idModule, pStream->GetURL(), 
							iReason,
							requestData,
							strError );
			#if defined( CH_MSW ) && defined( CH_ARCH_32 )
			if ( ChUtil::GetSystemProperties() & CH_PROP_MULTITHREADED )
			{  // Send it to the core frame which will to the dispatch
		
				m_pCore->AsyncDispatchMsg( idModule, pMsg );
			}
			else
			{
				m_pCore->DispatchMsg( idModule, *pMsg );
				delete pMsg;
			}
			#else
			m_pCore->DispatchMsg( idModule, *pMsg );
			delete pMsg;
			#endif	// defined( CH_MSW )
		}
		#else // Plugin and viewer only
		ChGraphicHTTPReq *pHTTPReq	 = (ChGraphicHTTPReq *)requestData;
		if ( pHTTPReq && pHTTPReq->GetView() )
		{
			string * pMsg = new string( pStream->GetErrorMsg() );
			// The merssage string is deleted by the message handler
			((ChGraphicView*)pHTTPReq->GetView())->PostMessage(  WM_VRML_MAZE_ERROR, 
												CH_MAZE_HTTP_ERROR_BASE + iReason, 
												(LPARAM)pMsg );
		}
		#endif	   

⌨️ 快捷键说明

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