📄 .#loader_win32.cpp.1.40
字号:
/******************************************************************************
*******************************************************************************
** **
** Copyright (c) 2006 Videon Central, Inc. **
** All rights reserved. **
** **
** The computer program contained herein contains proprietary information **
** which is the property of Videon Central, Inc. The program may be used **
** and/or copied only with the written permission of Videon Central, Inc. **
** or in accordance with the terms and conditions stipulated in the **
** agreement/contract under which the programs have been supplied. **
** **
*******************************************************************************
******************************************************************************/
/**
* @file loader_win32.cpp
*
* $Revision: 1.40 $
*
* Microsoft Windows Loader
*
*/
#include "loader_win32.h"
#include "dbgprint.h"
#include "arch.h"
#include <string.h>
#include <malloc.h>
/********************************************************************************
CONSTANTS
********************************************************************************/
#define DEBUG_ERROR (1<<0)
#define DEBUG_TRACE (1<<1)
#define DEBUG_INFO (1<<2)
#define DEBUG_LOADER_WIN32 (DEBUG_ERROR | DEBUG_INFO)
#define DEBUG_ON(x) (DEBUG_LOADER_WIN32 & (x))
// default drive to use if no optical drive is found automatically
#define LOADER_DEFAULT_OPTICAL_DRIVE_LETTER 'D'
// automatically search for optical drives, set to 0 to force using default drive
#define LOADER_SEARCH_FOR_OPTICAL_DRIVE 1
// recognize data CD's as BDROM media
#define DETECT_CDROM_XA_AS_BDROM 1
/**
*******************************************************************************
* LoaderValidateHandle
*
* @brief Validates loader handle
*
* @param loaderHandle loader handle
*
* @return LOADER_SUCCESS if loaderHandle is a valid loader handle
*******************************************************************************/
LOADER_ERR LoaderValidateHandle( LOADER_HANDLE loaderHandle )
{
LOADER_ASSERT_ERROR( (loaderHandle==NULL), LOADER_INVALID_PARAMETER );
#if DEBUG
LoaderData* pLoaderData;
pLoaderData = (LoaderData*)loaderHandle;
// validate pointer is loader pointer
if ( pLoaderData->magicNumber != LOADER_WIN32_MAGIC_NUMBER )
{
DBGPRINT(DEBUG_ON(DEBUG_ERROR), ("LoaderValidateHandle: invalid loader handle (pointer corruption)"));
return ( LOADER_INVALID_PARAMETER );
}
#endif
return ( LOADER_SUCCESS );
}
/**
*******************************************************************************
* LoaderCreate
*
* @brief Creates a handle to a loader device, initializes any global variables,
* allocates any required memory, and returns a pointer to the device handle.
*
* @param eBusType The loader bus type. NOT USED FOR THIS IMPLEMENTATION
* @param ulDeviceNum The loader device number. NOT USED FOR THIS IMPLEMENTATION
*
* @return If successful, handle to loader
*******************************************************************************/
LOADER_HANDLE LoaderCreate(LOADER_BUS_TYPE busType, ULONG deviceNumber)
{
(void)(busType);
(void)(deviceNumber);
LoaderData* pLoaderData;
DBGPRINT(DEBUG_ON(DEBUG_TRACE), ("LoaderCreate\n"));
pLoaderData = new LoaderData;
if ( pLoaderData == NULL )
{
LOADER_REPORT_ERROR( LOADER_OUT_OF_MEMORY );
return ( NULL );
}
return ( pLoaderData );
}
/**
*******************************************************************************
* LoaderDestroy
*
* @brief Stops the storage media if necessary, closes the current session and frees
* any memory allocated during the LoaderCreate() call.
*
* @param loaderHandle Loader handle.
*
* @return Loader error
*******************************************************************************/
LOADER_ERR LoaderDestroy(LOADER_HANDLE loaderHandle)
{
LoaderData* pLoaderData;
DBGPRINT(DEBUG_ON(DEBUG_TRACE), ("LoaderDestroy\n"));
LOADER_RAISE_ERROR( LoaderValidateHandle( loaderHandle ));
pLoaderData = (LoaderData*)loaderHandle;
delete ( pLoaderData );
pLoaderData = NULL;
return ( LOADER_SUCCESS );
}
/**
*******************************************************************************
* LoaderGetConfiguration
*
* @brief
*
* @param loaderHandle Loader handle.
* @param pLoaderConfiguration Loader configuration will be returned through this pointer.
*
* @return Loader error
*******************************************************************************/
LOADER_ERR LoaderGetConfiguration(LOADER_HANDLE loaderHandle, LOADER_CONFIGURATION* pLoaderConfiguration)
{
LoaderData* pLoaderData;
DBGPRINT(DEBUG_ON(DEBUG_TRACE), ("LoaderGetConfiguration\n"));
LOADER_ASSERT_ERROR( (pLoaderConfiguration==NULL), LOADER_INVALID_PARAMETER );
LOADER_RAISE_ERROR( LoaderValidateHandle( loaderHandle ));
pLoaderData = (LoaderData*) loaderHandle;
AutoMutex(&pLoaderData->mutex);
pLoaderConfiguration->ulFirmwareVersion = 0;
pLoaderConfiguration->ulManufacturer = 0;
pLoaderConfiguration->ulModel = 0;
pLoaderConfiguration->ulRegionState = 0;
return ( LOADER_NOT_IMPLEMENTED );
}
/**
*******************************************************************************
* LoaderGetCapabilities
*
* @brief
*
* @param loaderHandle Loader handle.
* @param pLoaderCapabilities Loader capabilities will be returned through this pointer.
*
* @return Loader error
*******************************************************************************/
LOADER_ERR LoaderGetCapabilities(LOADER_HANDLE loaderHandle, LOADER_CAPABILITIES* pLoaderCapabilities)
{
LoaderData* pLoaderData;
DBGPRINT(DEBUG_ON(DEBUG_TRACE), ("LoaderGetCapabilities\n"));
LOADER_ASSERT_ERROR( (pLoaderCapabilities==NULL), LOADER_INVALID_PARAMETER );
LOADER_RAISE_ERROR( LoaderValidateHandle( loaderHandle ));
pLoaderData = (LoaderData*) loaderHandle;
AutoMutex(&pLoaderData->mutex);
pLoaderCapabilities->fCSS = TRUE; // Windows loader supports CSS key exchange
pLoaderCapabilities->fAACS = FALSE; // Windows loader does not support AACES key exchange
pLoaderCapabilities->fImmediateEject = FALSE; // Windows loader has blocking eject (will not return immediately after issuing eject call)
return ( LOADER_SUCCESS );
}
/**
*******************************************************************************
* LoaderOpenTray
*
* @brief Stops the disc if necessary, closes the session, and opens the tray.
*
* @param loaderHandle Loader handle.
*
* @return Loader error
*******************************************************************************/
LOADER_ERR LoaderOpenTray(LOADER_HANDLE loaderHandle)
{
LoaderData* pLoaderData;
BOOL win32Result;
DWORD outputByteCount;
DBGPRINT(DEBUG_ON(DEBUG_TRACE), ("LoaderOpenTray\n"));
LOADER_RAISE_ERROR( LoaderValidateHandle( loaderHandle ));
pLoaderData = (LoaderData*) loaderHandle;
AutoMutex(&pLoaderData->mutex);
if ( pLoaderData->trayStatus == LOADER_TRAY_OPEN )
{
return ( LOADER_SUCCESS );
}
pLoaderData->trayStatus = LOADER_TRAY_UNKNOWN;
if ( pLoaderData->deviceHandle == INVALID_HANDLE_VALUE )
{
// Obtain a drive handle regardless if can read media
SetErrorMode( SEM_FAILCRITICALERRORS );
pLoaderData->deviceHandle = CreateFile(pLoaderData->driveName,
0,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
}
LOADER_ASSERT_ERROR( (pLoaderData->deviceHandle==INVALID_HANDLE_VALUE), LOADER_FAILURE );
win32Result = DeviceIoControl( pLoaderData->deviceHandle, // device handle
IOCTL_STORAGE_EJECT_MEDIA, // operation
NULL, // must be NULL
0, // must be 0
NULL, // must be NULL
0, // must be 0
&outputByteCount, // output byte count
NULL); // overlapped structure for async operations
CloseHandle ( pLoaderData->deviceHandle );
pLoaderData->deviceHandle = INVALID_HANDLE_VALUE;
if (win32Result == 0 )
{
MessageBox(NULL,"Please open optical drive tray","Error: unable to open optical drive tray", MB_OK | MB_ICONERROR);
}
pLoaderData->trayStatus = LOADER_TRAY_OPEN;
return ( LOADER_SUCCESS );
}
/**
*******************************************************************************
* LoaderCloseTray
*
* @brief Loads a disc into the device, and prepares everything needed to start the disc.
*
* @param loaderHandle Loader handle.
*
* @return Loader error
*******************************************************************************/
LOADER_ERR LoaderCloseTray(LOADER_HANDLE loaderHandle)
{
LoaderData* pLoaderData;
BOOL win32Result;
DWORD outputByteCount;
DBGPRINT(DEBUG_ON(DEBUG_TRACE), ("LoaderCloseTray\n"));
LOADER_RAISE_ERROR( LoaderValidateHandle( loaderHandle ));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -