Beispiel #1
0
void C_BaseObject::GetStatusText( wchar_t *pStatus, int iMaxStatusLen )
{
	wchar_t wszName[128];
	g_pVGuiLocalize->ConvertANSIToUnicode( GetStatusName(),  wszName, sizeof(wszName) );

	g_pVGuiLocalize->ConstructString( pStatus, iMaxStatusLen, L"%s1", 1, wszName );
}
Beispiel #2
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void C_BaseObject::GetTargetIDDataString( wchar_t *sDataString, int iMaxLenInBytes )
{
	sDataString[0] = '\0';

	// Don't show anything if the building cannot be upgraded at all.
	if ( m_iHighestUpgradeLevel <= 1 )
		return;

	C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
	if ( !pLocalPlayer )
		return;

	wchar_t wszBuilderName[ MAX_PLAYER_NAME_LENGTH ];
	wchar_t wszObjectName[ 32 ];
	wchar_t wszUpgradeProgress[ 32 ];
	wchar_t wszLevel[ 5 ];

	_snwprintf(wszLevel, ARRAYSIZE(wszLevel) - 1, L"%d", m_iUpgradeLevel);

	g_pVGuiLocalize->ConvertANSIToUnicode( GetStatusName(), wszObjectName, sizeof(wszObjectName) );

	C_BasePlayer *pBuilder = GetOwner();

	if ( pBuilder )
	{
		g_pVGuiLocalize->ConvertANSIToUnicode( pBuilder->GetPlayerName(), wszBuilderName, sizeof(wszBuilderName) );
	}
	else
	{
		wszBuilderName[0] = '\0';
	}

	if (m_iUpgradeLevel >= m_iHighestUpgradeLevel)
	{
		const char *printFormatString = "#TF_playerid_object_level";

		g_pVGuiLocalize->ConstructString(sDataString, iMaxLenInBytes, g_pVGuiLocalize->Find(printFormatString),
			1,
			wszLevel);
	}
	else
	{
		// level 1 and 2 show upgrade progress
		_snwprintf(wszUpgradeProgress, ARRAYSIZE(wszUpgradeProgress) - 1, L"%d / %d", m_iUpgradeMetal, m_iUpgradeMetalRequired);
		wszUpgradeProgress[ARRAYSIZE(wszUpgradeProgress) - 1] = '\0';

		const char *printFormatString = "#TF_playerid_object_upgrading_level";		

		g_pVGuiLocalize->ConstructString(sDataString, iMaxLenInBytes, g_pVGuiLocalize->Find(printFormatString),
			2,
			wszLevel,
			wszUpgradeProgress);
	}



}
Beispiel #3
0
//
//	Handle IO control requests in the device thread
//
VOID
VfdIoCtlThread(
	IN	PDEVICE_EXTENSION		DeviceExtension,
	IN	PIRP					Irp,
	IN	ULONG					ControlCode)
{
	switch (ControlCode) {
	case IOCTL_VFD_OPEN_IMAGE:
		//	open the file from the caller's security context
		//	-- this allows this driver to open network files
		if (DeviceExtension->SecurityContext) {
			SeImpersonateClient(DeviceExtension->SecurityContext, NULL);
		}

		Irp->IoStatus.Status = VfdOpenImage(DeviceExtension,
			(PVFD_IMAGE_INFO)Irp->AssociatedIrp.SystemBuffer);

		PsRevertToSelf();
		break;

	case IOCTL_VFD_CLOSE_IMAGE:
	case IOCTL_DISK_EJECT_MEDIA:
	case IOCTL_STORAGE_EJECT_MEDIA:
		VfdCloseImage(DeviceExtension);
		Irp->IoStatus.Status = STATUS_SUCCESS;
		break;

	case IOCTL_DISK_FORMAT_TRACKS:
	case IOCTL_DISK_FORMAT_TRACKS_EX:
		Irp->IoStatus.Status = VfdFormatTrack(DeviceExtension,
			(PFORMAT_PARAMETERS)Irp->AssociatedIrp.SystemBuffer);
		break;

	default:
		//	This shouldn't happen...
		VFDTRACE(0,
			("[VFD] %s passed to the device thread\n",
			GetIoControlName(ControlCode)));

		Irp->IoStatus.Status = STATUS_DRIVER_INTERNAL_ERROR;
	}

#if DBG
	if ((NT_SUCCESS(Irp->IoStatus.Status) && (TraceFlags & VFDINFO) == VFDINFO) ||
		(TraceFlags & VFDWARN) == VFDWARN) {
		VFDTRACE(0,("[VFD] %-40s - %s\n",
			GetIoControlName(ControlCode),
			GetStatusName(Irp->IoStatus.Status)));
	}
#endif
}
BattleStatusEffect::BattleStatusEffect(GLOBAL_STATUS type, GLOBAL_INTENSITY intensity, BattleActor* actor) :
	GlobalStatusEffect(type, intensity),
	_name(GetStatusName(type)),
	_affected_actor(actor),
	_timer(0),
	_apply_function(NULL),
	_icon_image(NULL)
{
	if ((type <= GLOBAL_STATUS_INVALID) || (type >= GLOBAL_STATUS_TOTAL)) {
		IF_PRINT_WARNING(GLOBAL_DEBUG) << "constructor received an invalid type argument: " << type << endl;
		return;
	}
	if ((intensity <= GLOBAL_INTENSITY_INVALID) || (intensity >= GLOBAL_INTENSITY_TOTAL)) {
		IF_PRINT_WARNING(GLOBAL_DEBUG) << "constructor received an invalid intensity argument: " << intensity << endl;
		return;
	}
	if (actor == NULL) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "constructor received NULL actor argument" << endl;
		return;
	}

	uint32 table_id = static_cast<uint32>(type);
	ReadScriptDescriptor& script_file = GlobalManager->GetStatusEffectsScript();
	if (script_file.DoesTableExist(table_id) == false) {
		IF_PRINT_WARNING(GLOBAL_DEBUG) << "Lua definition file contained no entry for status effect: " << table_id << endl;
		return;
	}

	script_file.OpenTable(table_id);
	if (script_file.DoesFunctionExist("Apply")) {
		_apply_function = new ScriptObject();
		(*_apply_function) = script_file.ReadFunctionPointer("Apply");
	}
	else {
		PRINT_WARNING << "no apply function found in Lua definition file for status: " << table_id << endl;
	}
	script_file.CloseTable();

	if (script_file.IsErrorDetected()) {
		if (BATTLE_DEBUG) {
			PRINT_WARNING << "one or more errors occurred while reading status effect data - they are listed below" << endl;
			cerr << script_file.GetErrorMessages() << endl;
		}
	}

	_ApplyChange();
}
Beispiel #5
0
void IOEvent::OnEventWrapper(Epoller* p){
    do{
        //set processing
        int pre_mask =
                __sync_lock_test_and_set(&_events, EVENT_PROCESSING);

        assert(pre_mask&EVENT_PENDING);

        TRACE(GetStatusName()<<",pre_mask:"<<StatusToStr(pre_mask));

        this->OnEvent(p, pre_mask);

        // if not set events when process, set events to 0
    }while(!__sync_bool_compare_and_swap (&_events, EVENT_PROCESSING,0) );

    ReleaseRef();
}
CString CBCGPRibbonBackstagePagePrint::XPrinterInfo::GetDisplayName() const
{
	CString str(strPrinterName);
	if (!strServerName.IsEmpty ())
	{
		CBCGPLocalResource localRes;

		CString strLine;
		strLine.LoadString (IDP_BCGBARRES_PRINT_NAME);

		CString strFmt;
		strFmt.Format(strLine, (LPCTSTR)strPrinterName + strServerName.GetLength () + 1, (LPCTSTR)strServerName + 2);

		str = strFmt;
	}

	str += _T("\n") + GetStatusName();

	return str;
}
Beispiel #7
0
//---------------------------------------------------------------------------
void Job::Dump ( const Dag *dag ) const {
    dprintf( D_ALWAYS, "---------------------- Job ----------------------\n");
    dprintf( D_ALWAYS, "      Node Name: %s\n", _jobName );
    dprintf( D_ALWAYS, "           Noop: %s\n", _noop ? "true" : "false" );
    dprintf( D_ALWAYS, "         NodeID: %d\n", _jobID );
    dprintf( D_ALWAYS, "    Node Status: %s\n", GetStatusName() );
    dprintf( D_ALWAYS, "Node return val: %d\n", retval );
	if( _Status == STATUS_ERROR ) {
		dprintf( D_ALWAYS, "          Error: %s\n", error_text );
	}
    dprintf( D_ALWAYS, "Job Submit File: %s\n", _cmdFile );
	if( _scriptPre ) {
		dprintf( D_ALWAYS, "     PRE Script: %s\n", _scriptPre->GetCmd() );
	}
	if( _scriptPost ) {
		dprintf( D_ALWAYS, "    POST Script: %s\n", _scriptPost->GetCmd() );
	}
	if( retry_max > 0 ) {
		dprintf( D_ALWAYS, "          Retry: %d\n", retry_max );
	}
	if( _CondorID._cluster == -1 ) {
		dprintf( D_ALWAYS, " %7s Job ID: [not yet submitted]\n",
				 JobTypeString() );
	}
	else {
		dprintf( D_ALWAYS, " %7s Job ID: (%d.%d.%d)\n", JobTypeString(),
				 _CondorID._cluster, _CondorID._proc, _CondorID._subproc );
	}
  
    for (int i = 0 ; i < 3 ; i++) {
        dprintf( D_ALWAYS, "%15s: ", queue_t_names[i] );

		std::set<JobID_t>::const_iterator qit;
		for (qit = _queues[i].begin(); qit != _queues[i].end(); qit++) {
			Job *node = dag->Dag::FindNodeByNodeID( *qit );
			dprintf( D_ALWAYS | D_NOHEADER, "%s, ", node->GetJobName() );
		}
        dprintf( D_ALWAYS | D_NOHEADER, "<END>\n" );
    }
}
Beispiel #8
0
NTSTATUS
VfdReadWrite (
	IN PDEVICE_OBJECT			DeviceObject,
	IN PIRP						Irp)
{
	PDEVICE_EXTENSION			device_extension;
	PIO_STACK_LOCATION			io_stack;
	NTSTATUS					status;

	device_extension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;

	io_stack = IoGetCurrentIrpStackLocation(Irp);

#if DBG
	if (DeviceObject && DeviceObject->DeviceExtension &&
		((PDEVICE_EXTENSION)DeviceObject->DeviceExtension)->DeviceName.Buffer) {

		VFDTRACE(VFDINFO, ("[VFD] %-40s %ws\n",
			GetMajorFuncName(io_stack->MajorFunction),
			((PDEVICE_EXTENSION)DeviceObject->DeviceExtension)->DeviceName.Buffer));
	}
	else {
		VFDTRACE(VFDINFO, ("[VFD] %-40s %p\n",
			GetMajorFuncName(io_stack->MajorFunction),
			DeviceObject));
	}
#endif	// DBG

#ifdef VFD_PNP

	if (device_extension->DeviceState != VFD_WORKING) {

		// Device is not yet started or being removed, reject any IO request
		// TODO: Queue the IRPs

		VFDTRACE(VFDWARN, ("[VFD] Device not ready\n"));

		status = STATUS_INVALID_DEVICE_STATE;
		goto complete_request;
	}
	else {
		status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, Irp);

		if (!NT_SUCCESS(status)) {
			VFDTRACE(0, ("[VFD] Acquire RemoveLock failed: %s\n", GetStatusName(status)));

			goto complete_request;
		}
	}
#endif	// VFD_PNP

/*
	//	Check if volume verification is required

	if ((DeviceObject->Flags & DO_VERIFY_VOLUME) &&
		!(io_stack->Flags & SL_OVERRIDE_VERIFY_VOLUME)) {

		status = STATUS_VERIFY_REQUIRED;
		goto complete_request;
	}
*/

	//	Check if an image is opened

	if (!device_extension->FileHandle &&
		!device_extension->FileBuffer)	{

		status = STATUS_NO_MEDIA_IN_DEVICE;
		goto complete_request;
	}


	// Check if write operation is allowed

	if (io_stack->MajorFunction == IRP_MJ_WRITE &&
		(device_extension->MediaFlags & VFD_FLAG_WRITE_PROTECTED)) {

		status = STATUS_MEDIA_WRITE_PROTECTED;
		goto complete_request;
	}


	// Check for invalid parameters.  It is an error for the starting offset
	// + length to go past the end of the partition, or for the length or
	// offset to not be a proper multiple of the sector size.
	//
	// Others are possible, but we don't check them since we trust the
	// file system and they aren't deadly.

	if ((IO_READ_OFF(io_stack) + IO_READ_LEN(io_stack)) >
		VFD_SECTOR_TO_BYTE(device_extension->Sectors)) {

		VFDTRACE(VFDWARN,
			("[VFD] Offset:%I64u + Length:%u goes past the media size %lu\n",
			IO_READ_OFF(io_stack), IO_READ_LEN(io_stack),
			VFD_SECTOR_TO_BYTE(device_extension->Sectors)));

		status = STATUS_INVALID_PARAMETER;
		goto complete_request;
	}

	if (!VFD_SECTOR_ALIGNED((IO_READ_LEN(io_stack))) ||
		!VFD_SECTOR_ALIGNED((IO_READ_OFF(io_stack)))) {

		VFDTRACE(VFDWARN,
			("[VFD] Invalid Alignment Offset:%I64u Length:%u\n",
			IO_READ_OFF(io_stack), IO_READ_LEN(io_stack)));

		status = STATUS_INVALID_PARAMETER;
		goto complete_request;
	}

	//	If read/write data length is 0, we are done

	if (IO_READ_LEN(io_stack) == 0) {
		status = STATUS_SUCCESS;
		goto complete_request;
	}

	//	It seems that actual read/write operation is going to take place
	//	so mark the IRP as pending, insert the IRP into queue list
	//	then signal the device thread to perform the operation

	IoMarkIrpPending(Irp);

	ExInterlockedInsertTailList(
		&device_extension->ListHead,
		&Irp->Tail.Overlay.ListEntry,
		&device_extension->ListLock);

	KeSetEvent(
		&device_extension->RequestEvent,
		(KPRIORITY) 0,
		FALSE);

	VFDTRACE(VFDINFO,("[VFD] %-40s - STATUS_PENDING\n",
		GetMajorFuncName(io_stack->MajorFunction)));

	return STATUS_PENDING;

complete_request:

	//	complete the request immediately

	Irp->IoStatus.Status = status;
	Irp->IoStatus.Information = 0;
	IoCompleteRequest(Irp, IO_NO_INCREMENT);

	VFDTRACE(VFDWARN,("[VFD] %-40s - %s\n",
		GetMajorFuncName(io_stack->MajorFunction),
		GetStatusName(status)));

	return status;
}
Beispiel #9
0
//
//	IOCTL commands handler
//
NTSTATUS
VfdDeviceControl (
	IN PDEVICE_OBJECT			DeviceObject,
	IN PIRP						Irp)
{
	PDEVICE_EXTENSION			device_extension;
	PIO_STACK_LOCATION			io_stack;
	NTSTATUS					status;

	device_extension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
	io_stack = IoGetCurrentIrpStackLocation(Irp);

	Irp->IoStatus.Information = 0;

	VFDTRACE(VFDINFO, ("[VFD] %-40s %ws\n",
		GetIoControlName(IO_CTRLCODE(io_stack)),
		device_extension->DeviceName.Buffer));

#ifdef VFD_PNP
	status = IoAcquireRemoveLock(&device_extension->RemoveLock, Irp);

	if (!NT_SUCCESS(status)) {
		VFDTRACE(0,
			("Acquire RemoveLock failed %s\n", NtStatusToStr(status)));

		Irp->IoStatus.Status = status;
		IoCompleteRequest(Irp, IO_NO_INCREMENT);
		return status;
	}
#endif	// VFD_PNP

/*
	//	Check if volume verification is required

	if ((DeviceObject->Flags & DO_VERIFY_VOLUME) &&
		!(io_stack->Flags & SL_OVERRIDE_VERIFY_VOLUME)) {

		VFDTRACE(VFDWARN,
			("[VFD] %-40s - %s\n",
				GetIoControlName(IO_CTRLCODE(io_stack)),
				GetStatusName(STATUS_VERIFY_REQUIRED)));

		Irp->IoStatus.Status = STATUS_VERIFY_REQUIRED;

		IoCompleteRequest(Irp, IO_NO_INCREMENT);

		return STATUS_VERIFY_REQUIRED;
	}
*/

	switch (IO_CTRLCODE(io_stack)) {
	case IOCTL_VFD_OPEN_IMAGE:
		//	Open an image file or create an empty RAM disk.
		//	Only a few checks are done here.
		//	Actual operation is done in device thread

		status = VfdOpenCheck(
			device_extension,
			(PVFD_IMAGE_INFO)Irp->AssociatedIrp.SystemBuffer,
			IO_INPUTLEN(io_stack));

		if (!NT_SUCCESS(status)) {
			break;
		}

		// Pass the task to the device thread
		status = STATUS_PENDING;
		break;

	case IOCTL_VFD_CLOSE_IMAGE:
	case IOCTL_DISK_EJECT_MEDIA:
	case IOCTL_STORAGE_EJECT_MEDIA:
		//	Close the current image file or delete the RAM disk
		//	Only status check is done here.
		//	Actual operation is done in device thread.

		if (!device_extension->FileHandle &&
			!device_extension->FileBuffer) {
			status = STATUS_NO_MEDIA_IN_DEVICE;
			break;
		}

		// Pass the task to the device thread
		status = STATUS_PENDING;
		break;

	case IOCTL_VFD_QUERY_IMAGE:
		//	Returns current image file information

		status = VfdQueryImage(
			device_extension,
			(PVFD_IMAGE_INFO)Irp->AssociatedIrp.SystemBuffer,
			IO_OUTPUTLEN(io_stack),
			&Irp->IoStatus.Information);

		break;

	case IOCTL_VFD_SET_LINK:
		// Create / remove a persistent drive letter
		// and store it in the registry

		if (IO_INPUTLEN(io_stack) < sizeof(CHAR)) {
			status = STATUS_INVALID_PARAMETER;
			break;
		}

#ifdef VFD_MOUNT_MANAGER
		if (OsMajorVersion >= 5) {
			//	Windows 2000/XP
			//	Create a drive letter via the mount manager

			status = VfdMountMgrMountPoint(device_extension,
				*(PCHAR)Irp->AssociatedIrp.SystemBuffer);

			//	The new drive letter will be stored in the device extension
			//	and the registry when IOCTL_MOUNTDEV_LINK_CREATED or
			//	IOCTL_MOUNTDEV_LINK_DELETED is issued from the mount manager.
		}
		else
#else	//	VFD_MOUNT_MANAGER
		{
			//	Windows NT style drive letter assignment
			//	Simply create a symbolic link and store the new value

			status = VfdSetLink(device_extension,
				*(PCHAR)Irp->AssociatedIrp.SystemBuffer);

			if (NT_SUCCESS(status)) {
				//	Store the new drive letter into the registry
				status = VfdStoreLink(device_extension);
			}
		}
#endif	//	VFD_MOUNT_MANAGER
		break;

	case IOCTL_VFD_QUERY_LINK:
		//	Return the current persistent drive letter

		if (IO_OUTPUTLEN(io_stack) < sizeof(CHAR)) {
			status = STATUS_BUFFER_TOO_SMALL;
			break;
		}

		*(PCHAR)Irp->AssociatedIrp.SystemBuffer =
			device_extension->DriveLetter;

		Irp->IoStatus.Information = sizeof(CHAR);
		status = STATUS_SUCCESS;
		break;

	case IOCTL_VFD_SET_PROTECT:
		//	Set media protect flag

		if (!device_extension->FileHandle &&
			!device_extension->FileBuffer) {
			status = STATUS_NO_MEDIA_IN_DEVICE;
			break;
		}

		device_extension->MediaFlags |= VFD_FLAG_WRITE_PROTECTED;
		status = STATUS_SUCCESS;
		break;

	case IOCTL_VFD_CLEAR_PROTECT:
		//	Clear media protect flag

		if (!device_extension->FileHandle &&
			!device_extension->FileBuffer) {
			status = STATUS_NO_MEDIA_IN_DEVICE;
			break;
		}

		device_extension->MediaFlags &= ~VFD_FLAG_WRITE_PROTECTED;
		status = STATUS_SUCCESS;
		break;

	case IOCTL_VFD_RESET_MODIFY:
		//	Reset the data modify flag

		if (!device_extension->FileHandle &&
			!device_extension->FileBuffer) {
			status = STATUS_NO_MEDIA_IN_DEVICE;
			break;
		}

		device_extension->MediaFlags &= ~VFD_FLAG_DATA_MODIFIED;
		status = STATUS_SUCCESS;
		break;

	case IOCTL_VFD_QUERY_NUMBER:
		//	Return VFD device number (\??\VirtualFD<n>)

		if (IO_OUTPUTLEN(io_stack) < sizeof(ULONG)) {
			status = STATUS_BUFFER_TOO_SMALL;
			break;
		}

		*(PULONG)Irp->AssociatedIrp.SystemBuffer=
			device_extension->DeviceNumber;

		Irp->IoStatus.Information = sizeof(ULONG);
		status = STATUS_SUCCESS;
		break;

	case IOCTL_VFD_QUERY_NAME:
		//	Return VFD device name (\Device\Floppy<n>)
		//	counted unicode string (not null terminated)

		if (IO_OUTPUTLEN(io_stack) < sizeof(USHORT)) {
			status = STATUS_BUFFER_TOO_SMALL;
			break;
		}

		{
			PUSHORT p = (PUSHORT)Irp->AssociatedIrp.SystemBuffer;

			*p = device_extension->DeviceName.Length;

			if (IO_OUTPUTLEN(io_stack) < sizeof(USHORT) + *p) {

				Irp->IoStatus.Information = sizeof(USHORT);
				status = STATUS_BUFFER_OVERFLOW;
				break;
			}

			RtlCopyMemory(p + 1, device_extension->DeviceName.Buffer, *p);

			Irp->IoStatus.Information = sizeof(USHORT) + *p;
		}

		status = STATUS_SUCCESS;
		break;

	case IOCTL_VFD_QUERY_VERSION:
		//	Return the VFD driver version

		if (IO_OUTPUTLEN(io_stack) < sizeof(ULONG)) {
			status = STATUS_BUFFER_TOO_SMALL;
			break;
		}

		*(PULONG)Irp->AssociatedIrp.SystemBuffer =
			(VFD_DRIVER_MAJOR << 16) | VFD_DRIVER_MINOR | VFD_DEBUG_FLAG;

		Irp->IoStatus.Information = sizeof(ULONG);
		status = STATUS_SUCCESS;
		break;

	//
	//	standard disk and storage I/O control requests
	//

	case IOCTL_DISK_CHECK_VERIFY:
	case IOCTL_STORAGE_CHECK_VERIFY:
	case IOCTL_STORAGE_CHECK_VERIFY2:

		if (IO_OUTPUTLEN(io_stack) >= sizeof(ULONG)) {

			*(PULONG)Irp->AssociatedIrp.SystemBuffer =
				device_extension->MediaChangeCount;

			Irp->IoStatus.Information = sizeof(ULONG);
		}

		status = STATUS_SUCCESS;
		break;

	case IOCTL_DISK_FORMAT_TRACKS:
	case IOCTL_DISK_FORMAT_TRACKS_EX:
		//	Only parameter checks are performed here
		//	Actual operation is done by the device thread

		status = VfdFormatCheck(
			device_extension,
			(PFORMAT_PARAMETERS)Irp->AssociatedIrp.SystemBuffer,
			IO_INPUTLEN(io_stack),
			IO_CTRLCODE(io_stack));

		if (!NT_SUCCESS(status)) {
			break;
		}

		// Pass the task to the device thread
		status = STATUS_PENDING;
		break;

	case IOCTL_DISK_GET_DRIVE_GEOMETRY:
		//	Returns the geometry of current media

		if (!device_extension->FileHandle &&
			!device_extension->FileBuffer) {
			status = STATUS_NO_MEDIA_IN_DEVICE;
			break;
		}
		//	fall through

	case IOCTL_DISK_GET_MEDIA_TYPES:
	case IOCTL_STORAGE_GET_MEDIA_TYPES:
		//	Return *the last mounted* disk geometry, although xxx_GET_MEDIA_TYPES
		//	commands are supposed to return all supported media types.
		//	This makes the matter much simpler...;-)
		//	If no image has been mounted yet, 1.44MB media is assumed.

		if (IO_OUTPUTLEN(io_stack) < sizeof(DISK_GEOMETRY)) {
			return STATUS_BUFFER_TOO_SMALL;
		}

		//	Copy appropriate DISK_GEOMETRY into the output buffer

		if (device_extension->Geometry) {
			RtlCopyMemory(
				Irp->AssociatedIrp.SystemBuffer,
				device_extension->Geometry,
				sizeof(DISK_GEOMETRY));
		}
		else {
			//	default = 3.5" 1.44 MB media
			RtlCopyMemory(
				Irp->AssociatedIrp.SystemBuffer,
				&geom_tbl[VFD_MEDIA_F3_1P4],
				sizeof(DISK_GEOMETRY));
		}
		Irp->IoStatus.Information = sizeof(DISK_GEOMETRY);

		status = STATUS_SUCCESS;
		break;

	case IOCTL_DISK_GET_LENGTH_INFO:
		//	Return disk length information
		//	(Windows XP requires this request to be handled)

		if (!device_extension->FileHandle &&
			!device_extension->FileBuffer) {
			status = STATUS_NO_MEDIA_IN_DEVICE;
			break;
		}

		if (IO_OUTPUTLEN(io_stack) < sizeof(GET_LENGTH_INFORMATION)) {
			status = STATUS_BUFFER_TOO_SMALL;
			break;
		}

		((PGET_LENGTH_INFORMATION)Irp->AssociatedIrp.SystemBuffer)->Length.QuadPart =
			VFD_SECTOR_TO_BYTE(device_extension->Sectors);

		Irp->IoStatus.Information = sizeof(GET_LENGTH_INFORMATION);

		status = STATUS_SUCCESS;
		break;

	case IOCTL_DISK_IS_WRITABLE:
		//	Checks if current media is writable

		if (!device_extension->FileHandle &&
			!device_extension->FileBuffer) {
			status = STATUS_NO_MEDIA_IN_DEVICE;
		}
		else if (device_extension->MediaFlags & VFD_FLAG_WRITE_PROTECTED) {
			status = STATUS_MEDIA_WRITE_PROTECTED;
		}
		else {
			status = STATUS_SUCCESS;
		}
		break;

/*
	case IOCTL_DISK_MEDIA_REMOVAL:
	case IOCTL_STORAGE_MEDIA_REMOVAL:
		//	Since removal lock is irrelevant for virtual disks,
		//	there's really nothing to do here...

		status = STATUS_SUCCESS;
		break;

	case IOCTL_STORAGE_GET_HOTPLUG_INFO:
		{
			PSTORAGE_HOTPLUG_INFO hotplug;

			if (IO_OUTPUTLEN(io_stack) < sizeof(STORAGE_HOTPLUG_INFO)) {
				status = STATUS_BUFFER_TOO_SMALL;
				break;
			}

			hotplug = (PSTORAGE_HOTPLUG_INFO)Irp->AssociatedIrp.SystemBuffer;

			RtlZeroMemory(hotplug, sizeof(STORAGE_HOTPLUG_INFO));

			hotplug->Size = sizeof(STORAGE_HOTPLUG_INFO);
			hotplug->MediaRemovable = 1;

			Irp->IoStatus.Information = sizeof(STORAGE_HOTPLUG_INFO);
			status = STATUS_SUCCESS;
		}
		break;
*/

#ifdef VFD_MOUNT_MANAGER
	//
	//	IO control requests received from the mount manager
	//	(on Windows 2000 / XP)
	//

	case IOCTL_MOUNTDEV_QUERY_UNIQUE_ID:
		//	Returns a unique ID for the target device
		status = VfdMountDevUniqueId(
			device_extension,
			Irp->AssociatedIrp.SystemBuffer,
			IO_OUTPUTLEN(io_stack),
			&Irp->IoStatus);
		break;

//	case IOCTL_MOUNTDEV_UNIQUE_ID_CHANGE_NOTIFY:

	case IOCTL_MOUNTDEV_QUERY_DEVICE_NAME:
		//	Returns the device name of the target device
		status = VfdMountDevDeviceName(
			device_extension,
			Irp->AssociatedIrp.SystemBuffer,
			IO_OUTPUTLEN(io_stack),
			&Irp->IoStatus);
		break;

	case IOCTL_MOUNTDEV_QUERY_SUGGESTED_LINK_NAME:
		//	Returns the drive letter link which we want the mount manager
		//	to create.	This request is issued in response to the volume
		//	arrival notification, and the mount manager will create the
		//	symbolic link.
		status = VfdMountDevSuggestedLink(
			device_extension,
			Irp->AssociatedIrp.SystemBuffer,
			IO_OUTPUTLEN(io_stack),
			&Irp->IoStatus);
		break;

	case IOCTL_MOUNTDEV_LINK_CREATED:
	case IOCTL_MOUNTDEV_LINK_DELETED:
		//	Issued after the mount manager created/deleted a symbolic link
		status = VfdMountDevLinkModified(
			device_extension,
			Irp->AssociatedIrp.SystemBuffer,
			IO_INPUTLEN(io_stack),
			IO_CTRLCODE(io_stack));
		break;

/*
	case IOCTL_MOUNTDEV_QUERY_STABLE_GUID:
		{
			PMOUNTDEV_STABLE_GUID guid;

			if (IO_OUTPUTLEN(io_stack) < sizeof(MOUNTDEV_STABLE_GUID)) {
				status = STATUS_INVALID_PARAMETER;
				break;
			}

			guid = Irp->AssociatedIrp.SystemBuffer;

			RtlCopyMemory(
				&guid->StableGuid, &VFD_GUID, sizeof(GUID));

			Irp->IoStatus.Information = sizeof(guid);
			status = STATUS_SUCCESS;
		}
		break;
*/
#endif	//	VFD_MOUNT_MANAGER

	default:
		//	Unknown IOCTL request
		status = STATUS_INVALID_DEVICE_REQUEST;
		break;
	}

#if DBG
	if ((NT_SUCCESS(status) && (TraceFlags & VFDINFO) == VFDINFO) ||
		(TraceFlags & VFDWARN) == VFDWARN) {
		VFDTRACE(0,("[VFD] %-40s - %s\n",
			GetIoControlName(IO_CTRLCODE(io_stack)),
			GetStatusName(status)));
	}
#endif

	if (status == STATUS_PENDING) {
		//	Let the device thread perform the operation

		IoMarkIrpPending(Irp);

		ExInterlockedInsertTailList(
			&device_extension->ListHead,
			&Irp->Tail.Overlay.ListEntry,
			&device_extension->ListLock);

		KeSetEvent(
			&device_extension->RequestEvent,
			(KPRIORITY) 0,
			FALSE);
	}
	else {
		//	complete the operation

		Irp->IoStatus.Status = status;
		IoCompleteRequest(Irp, IO_NO_INCREMENT);

#ifdef VFD_PNP
		IoReleaseRemoveLock(&device_extension->RemoveLock, Irp);
#endif	// VFD_PNP
	}

	return status;
}
/*
*	Get the text for specified lines
*/
int Cache_GetLineText(
	ClcCacheEntry *pdnce, int type, LPTSTR text, int text_size, TCHAR *variable_text, BOOL xstatus_has_priority,
	BOOL show_status_if_no_away, BOOL show_listening_if_no_away, BOOL use_name_and_message_for_xstatus,
	BOOL pdnce_time_show_only_if_different)
{
	if (text == NULL)
		return TEXT_EMPTY;
	text[0] = '\0';

	switch (type) {
	case TEXT_STATUS:
		if (GetStatusName(text, text_size, pdnce, xstatus_has_priority) == -1 && use_name_and_message_for_xstatus) {
			DBVARIANT dbv = { 0 };

			// Try to get XStatusMsg
			if (!db_get_ts(pdnce->hContact, pdnce->m_cache_cszProto, "XStatusMsg", &dbv)) {
				if (dbv.ptszVal != NULL && dbv.ptszVal[0] != 0) {
					TCHAR *tmp = NEWTSTR_ALLOCA(text);
					mir_sntprintf(text, text_size, _T("%s: %s"), tmp, dbv.ptszVal);
					CopySkipUnprintableChars(text, text, text_size - 1);
				}
				db_free(&dbv);
			}
		}

		return TEXT_STATUS;

	case TEXT_NICKNAME:
		if (pdnce->hContact && pdnce->m_cache_cszProto) {
			DBVARIANT dbv = { 0 };
			if (!db_get_ts(pdnce->hContact, pdnce->m_cache_cszProto, "Nick", &dbv)) {
				mir_tstrncpy(text, dbv.ptszVal, text_size);
				db_free(&dbv);
				CopySkipUnprintableChars(text, text, text_size - 1);
			}
		}

		return TEXT_NICKNAME;

	case TEXT_STATUS_MESSAGE:
		if (GetStatusMessage(text, text_size, pdnce, xstatus_has_priority) == -1 && use_name_and_message_for_xstatus) {
			DBVARIANT dbv = { 0 };

			// Try to get XStatusName
			if (!db_get_ts(pdnce->hContact, pdnce->m_cache_cszProto, "XStatusName", &dbv)) {
				if (dbv.pszVal != NULL && dbv.pszVal[0] != 0) {
					TCHAR *tmp = NEWTSTR_ALLOCA(text);
					mir_sntprintf(text, text_size, _T("%s: %s"), dbv.pszVal, tmp);
				}
				CopySkipUnprintableChars(text, text, text_size - 1);
				db_free(&dbv);
			}
		}
		else if (use_name_and_message_for_xstatus && xstatus_has_priority) {
			DBVARIANT dbv = { 0 };
			// Try to get XStatusName
			if (!db_get_ts(pdnce->hContact, pdnce->m_cache_cszProto, "XStatusName", &dbv)) {
				if (dbv.ptszVal != NULL && dbv.ptszVal[0] != 0)
					mir_tstrncpy(text, dbv.ptszVal, text_size);
				CopySkipUnprintableChars(text, text, text_size - 1);
				db_free(&dbv);
			}
		}

		if (text[0] == '\0') {
			if (show_listening_if_no_away) {
				Cache_GetLineText(pdnce, TEXT_LISTENING_TO, text, text_size, variable_text, xstatus_has_priority, 0, 0, use_name_and_message_for_xstatus, pdnce_time_show_only_if_different);
				if (text[0] != '\0')
					return TEXT_LISTENING_TO;
			}

			if (show_status_if_no_away) {
				//re-request status if no away
				return Cache_GetLineText(pdnce, TEXT_STATUS, text, text_size, variable_text, xstatus_has_priority, 0, 0, use_name_and_message_for_xstatus, pdnce_time_show_only_if_different);
			}
		}
		return TEXT_STATUS_MESSAGE;

	case TEXT_LISTENING_TO:
		GetListeningTo(text, text_size, pdnce);
		return TEXT_LISTENING_TO;

	case TEXT_TEXT:
	{
		TCHAR *tmp = variables_parsedup(variable_text, pdnce->tszName, pdnce->hContact);
		mir_tstrncpy(text, tmp, text_size);
		mir_free(tmp);
		CopySkipUnprintableChars(text, text, text_size - 1);
	}
	return TEXT_TEXT;

	case TEXT_CONTACT_TIME:
		if (pdnce->hTimeZone) {
			// Get pdnce time
			text[0] = 0;
			TimeZone_PrintDateTime(pdnce->hTimeZone, _T("t"), text, text_size, 0);
		}

		return TEXT_CONTACT_TIME;
	}

	return TEXT_EMPTY;
}
Beispiel #11
0
void RebuildEntireListInternal(HWND hwnd, ClcData *tmp_dat, BOOL call_orig)
{
	ClcData *dat = (ClcData*)tmp_dat;
	struct ClcGroup *group;
	struct ClcContact *item;
	TCHAR tmp[1024];
	TCHAR count[128];
	TCHAR template_contact[1024];
	TCHAR template_group[1024];
	TCHAR template_divider[1024];
	TCHAR template_info[1024];
	TCHAR *text;
	size_t size;
	int selection = dat->selection;
	BOOL has_focus = (GetFocus() == dat->hwnd_list || GetFocus() == hwnd);

	if (call_orig)
		coreCli.pfnRebuildEntireList(hwnd, (ClcData*)dat);

	MyDBGetContactSettingTString(NULL, "CLC", "TemplateContact", template_contact, 1024, TranslateT("%name% [%status% %protocol%] %status_message%"));
	MyDBGetContactSettingTString(NULL, "CLC", "TemplateGroup", template_group, 1024, TranslateT("Group: %name% %count% [%mode%]"));
	MyDBGetContactSettingTString(NULL, "CLC", "TemplateDivider", template_divider, 1024, TranslateT("Divider: %s"));
	MyDBGetContactSettingTString(NULL, "CLC", "TemplateInfo", template_info, 1024, TranslateT("Info: %s"));

	SendMessage(dat->hwnd_list, WM_SETREDRAW, FALSE, 0);

	// Reset content
	SendMessage(dat->hwnd_list, LB_RESETCONTENT, 0, 0);

	// Set font
	SendMessage(dat->hwnd_list, WM_SETFONT, (WPARAM) dat->fontInfo[FONTID_CONTACTS].hFont, 0);

	// Add all items to the list
	group = &dat->list;
	group->scanIndex = 0;
	text = tmp;
	size = _countof(tmp);
	while(1)
	{
		if (group->scanIndex == group->cl.count)
		{
			group = group->parent;
			if (group == NULL)
				break;
			text -= 2;
			size += 2;
			group->scanIndex++;
			continue;
		}

		item = group->cl.items[group->scanIndex];
		text[0] = _T('\0');
		switch(item->type)
		{
		case CLCIT_GROUP:
			{
				TCHAR *szCounts = pcli->pfnGetGroupCountsText((ClcData*)dat, item);
				const TCHAR *t[] = {
					_T("%name%"),
					_T("%count%"),
					_T("%mode%")
				};
				const TCHAR *v[] = {
					item->szText,
					count,
					item->group->expanded ? TranslateT("Expanded") : TranslateT("Collapsed")
				};
				TCHAR *txt;

				if (szCounts[0] != '\0')
					mir_sntprintf(count, _countof(count), _T("%s "), szCounts);
				else
					count[0] = _T('\0');

				txt = ParseText(template_group, t, _countof(t), v, _countof(v));
				if (txt != NULL)
					mir_tstrncpy(text, txt, (int)size);
				mir_free(txt);
				break;
			}
		case CLCIT_CONTACT:
			{
				const TCHAR *t[] = {
					_T("%name%"),
					_T("%status%"),
					_T("%protocol%"),
					_T("%status_message%")
				};
				const TCHAR *v[] = {
					item->szText,
					GetStatusName(item),
					GetProtoName(item),
					GetStatusMessage(item)
				};

				TCHAR *txt = ParseText(template_contact, t, _countof(t), v, _countof(v));
				if (txt != NULL)
					mir_tstrncpy(text, txt, (int)size);
				mir_free(txt);
				break;
			}
		case CLCIT_DIVIDER:
			{
				mir_sntprintf(text, size, template_divider, item->szText);
				break;
			}
		case CLCIT_INFO:
			{
				mir_sntprintf(text, size, template_info, item->szText);
				break;
			}
		}

		SendMessage(dat->hwnd_list, LB_ADDSTRING, 0, (LPARAM) tmp);

		if (item->type == CLCIT_GROUP && item->group->expanded)
		{
			group = item->group;
			text[0] = _T(' ');
			text[1] = _T(' ');
			text += 2;
			size -= 2;
			group->scanIndex = 0;
			continue;
		}
		group->scanIndex++;
	}

	SendMessage(dat->hwnd_list, WM_SETREDRAW, TRUE, 0);
	InvalidateRect(dat->hwnd_list, NULL, TRUE);

	dat->selection = selection;
	SendMessage(dat->hwnd_list, LB_SETCURSEL, dat->selection, 0);
	if (has_focus)
		SetFocus(dat->hwnd_list);

	dat->need_rebuild = FALSE;
}
Beispiel #12
0
/*
*	Get the text for specified lines
*/
int Cache_GetLineText(PDNCE pdnce, int type, LPTSTR text, int text_size, TCHAR *variable_text, BOOL xstatus_has_priority, 
                      BOOL show_status_if_no_away, BOOL show_listening_if_no_away, BOOL use_name_and_message_for_xstatus, 
                      BOOL pdnce_time_show_only_if_different)
{
    text[0] = '\0';
    switch(type)
    {
    case TEXT_STATUS:
        {
            if (GetStatusName(text, text_size, pdnce, xstatus_has_priority) == -1 && use_name_and_message_for_xstatus)
            {
                DBVARIANT dbv={0};

                // Try to get XStatusMsg
                if (!ModernGetSettingTString(pdnce->m_cache_hContact, pdnce->m_cache_cszProto, "XStatusMsg", &dbv)) 
                {
                    if (dbv.ptszVal != NULL && dbv.ptszVal[0] != 0)
                    {
                        TCHAR *tmp = mir_tstrdup(text);
                        mir_sntprintf(text, text_size, TEXT("%s: %s"), tmp, dbv.pszVal);
                        mir_free_and_nill(tmp);
                        CopySkipUnprintableChars(text, text, text_size-1);
                    }
                    ModernDBFreeVariant(&dbv);
                }
            }

            return TEXT_STATUS;
        }
    case TEXT_NICKNAME:
        {
            if (pdnce->m_cache_hContact && pdnce->m_cache_cszProto)
            {
                DBVARIANT dbv={0};
                if (!ModernGetSettingTString(pdnce->m_cache_hContact, pdnce->m_cache_cszProto, "Nick", &dbv)) 
                {
                    lstrcpyn(text, dbv.ptszVal, text_size);
                    ModernDBFreeVariant(&dbv);
                    CopySkipUnprintableChars(text, text, text_size-1);
                }
            }

            return TEXT_NICKNAME;
        }
    case TEXT_STATUS_MESSAGE:
        {
            if (GetStatusMessage(text, text_size, pdnce, xstatus_has_priority) == -1 && use_name_and_message_for_xstatus)
            {
                DBVARIANT dbv={0};

                // Try to get XStatusName
                if (!ModernGetSettingTString(pdnce->m_cache_hContact, pdnce->m_cache_cszProto, "XStatusName", &dbv)) 
                {
                    if (dbv.pszVal != NULL && dbv.pszVal[0] != 0)
                    {
                        TCHAR *tmp = mir_tstrdup(text);
                        
                        mir_sntprintf(text, text_size, TEXT("%s: %s"), dbv.pszVal, tmp);                        
                        mir_free_and_nill(tmp);
                    }
                    CopySkipUnprintableChars(text, text, text_size-1);
                    ModernDBFreeVariant(&dbv);
                }
            }
            else if (use_name_and_message_for_xstatus && xstatus_has_priority)
            {
                DBVARIANT dbv={0};
                // Try to get XStatusName
                if (!ModernGetSettingTString(pdnce->m_cache_hContact, pdnce->m_cache_cszProto, "XStatusName", &dbv)) 
                {
                    if (dbv.pszVal != NULL && dbv.pszVal[0] != 0)
                        mir_sntprintf(text, text_size, TEXT("%s"), dbv.pszVal);
                    CopySkipUnprintableChars(text, text, text_size-1);
                    ModernDBFreeVariant(&dbv);
                }
            }

            if (text[0] == '\0')
            {
                if (show_listening_if_no_away)
                {
                    Cache_GetLineText(pdnce, TEXT_LISTENING_TO, text, text_size, variable_text, xstatus_has_priority, 0, 0, use_name_and_message_for_xstatus, pdnce_time_show_only_if_different);
                    if (text[0] != '\0')
                        return TEXT_LISTENING_TO;
                }

                if (show_status_if_no_away)
                {
                    //re-request status if no away
                    return Cache_GetLineText(pdnce, TEXT_STATUS, text, text_size, variable_text, xstatus_has_priority, 0, 0, use_name_and_message_for_xstatus, pdnce_time_show_only_if_different);		
                }
            }
            return TEXT_STATUS_MESSAGE;
        }
    case TEXT_LISTENING_TO:
        {
            GetListeningTo(text, text_size, pdnce);
            return TEXT_LISTENING_TO;
        }
    case TEXT_TEXT:
        {
            TCHAR *tmp = variables_parsedup(variable_text, pdnce->m_cache_tcsName, pdnce->m_cache_hContact);
            lstrcpyn(text, tmp, text_size);
            if (tmp) free(tmp);
            CopySkipUnprintableChars(text, text, text_size-1);

            return TEXT_TEXT;
        }
    case TEXT_CONTACT_TIME:
        {
            if (pdnce->hTimeZone)
            {
                // Get pdnce time
                text[0] = 0;
                tmi.printDateTime( pdnce->hTimeZone, _T("t"), text, text_size, 0);
            }

            return TEXT_CONTACT_TIME;
        }
    }

    return TEXT_EMPTY;
}
Beispiel #13
0
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_BaseObject::GetTargetIDString( wchar_t *sIDString, int iMaxLenInBytes )
{
	sIDString[0] = '\0';

	C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();

	if ( !pLocalPlayer )
		return;

	if ( InSameTeam( pLocalPlayer ) || pLocalPlayer->IsPlayerClass( TF_CLASS_SPY ) || pLocalPlayer->GetTeamNumber() == TEAM_SPECTATOR )
	{
		wchar_t wszBuilderName[ MAX_PLAYER_NAME_LENGTH ];

		const char *pszStatusName = GetStatusName();
		wchar_t *wszObjectName = g_pVGuiLocalize->Find( pszStatusName );

		if ( !wszObjectName )
		{
			wszObjectName = L"";
		}

		C_BasePlayer *pBuilder = GetOwner();

		if ( pBuilder )
		{
			g_pVGuiLocalize->ConvertANSIToUnicode( pBuilder->GetPlayerName(), wszBuilderName, sizeof(wszBuilderName) );
		}
		else
		{
			wszBuilderName[0] = '\0';
		}

		// building or live, show health
		const char *printFormatString;
		
		if ( GetObjectInfo(GetType())->m_AltModes.Count() > 0 )
		{
			printFormatString = "#TF_playerid_object_mode";

			pszStatusName = GetObjectInfo( GetType() )->m_AltModes.Element( m_iObjectMode * 3 + 1 );
			wchar_t *wszObjectModeName = g_pVGuiLocalize->Find( pszStatusName );

			if ( !wszObjectModeName )
			{
				wszObjectModeName = L"";
			}

			g_pVGuiLocalize->ConstructString( sIDString, iMaxLenInBytes, g_pVGuiLocalize->Find(printFormatString),
				4,
				wszObjectName,
				wszBuilderName,
				wszObjectModeName);
		}
		else
		{
			if ( m_bMiniBuilding )
				printFormatString = "#TF_playerid_object_mini";
			else
				printFormatString = "#TF_playerid_object";

			g_pVGuiLocalize->ConstructString( sIDString, iMaxLenInBytes, g_pVGuiLocalize->Find( printFormatString ),
				3,
				wszObjectName,
				wszBuilderName );
		}
	}
}
Beispiel #14
0
//-----------------------------------------------------------------------------
// Purpose: Get a text description for the object target
//-----------------------------------------------------------------------------
const char *C_BaseObject::GetTargetDescription( void ) const
{
	return GetStatusName();
}
Beispiel #15
0
//
//	Read sectors from image file or RAM disk buffer into read buffer
//
VOID
VfdReadData(
	IN		PDEVICE_EXTENSION	DeviceExtension,
	IN OUT	PIRP				Irp,
	IN		ULONG				Length,
	IN		PLARGE_INTEGER		Offset)
{
	PVOID buf;

	VFDTRACE(VFDINFO,("[VFD] VfdReadData - IN\n"));

	buf = MmGetSystemAddressForMdlPrettySafe(
		Irp->MdlAddress, NormalPagePriority);

	if (!buf) {
		VFDTRACE(0,
			("[VFD] MmGetSystemAddressForMdlPrettySafe\n"));

		Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
		return;
	}

	if (DeviceExtension->FileHandle) {

		//	Read from image file
		Irp->IoStatus.Status = ZwReadFile(
			DeviceExtension->FileHandle,
			NULL,
			NULL,
			NULL,
			&Irp->IoStatus,
			buf,
			Length,
			Offset,
			NULL);

		if (NT_SUCCESS(Irp->IoStatus.Status)) {
			Irp->IoStatus.Information = Length;
		}
		else {
			VFDTRACE(0,
				("[VFD] ZwReadFile - %s\n",
				GetStatusName(Irp->IoStatus.Status)));
		}
	}
	else if (DeviceExtension->FileBuffer) {

		//	Copy from RAM disk buffer
		RtlMoveMemory(
			buf,
			DeviceExtension->FileBuffer + Offset->QuadPart,
			Length);

		Irp->IoStatus.Status = STATUS_SUCCESS;
		Irp->IoStatus.Information = Length;
	}
	else {
		//	no image opened
		Irp->IoStatus.Status = STATUS_NO_MEDIA_IN_DEVICE;
	}

	VFDTRACE(VFDINFO,("[VFD] VfdReadData - %s\n",
		GetStatusName(Irp->IoStatus.Status)));

	return;
}
Beispiel #16
0
//
//	Write sectors from write buffer into image file or RAM image buffer
//
VOID
VfdWriteData(
	IN		PDEVICE_EXTENSION	DeviceExtension,
	IN OUT	PIRP				Irp,
	IN		ULONG				Length,
	IN		PLARGE_INTEGER		Offset)
{
	PVOID buf;

	VFDTRACE(VFDINFO,("[VFD] VfdWriteData - IN\n"));

	buf = MmGetSystemAddressForMdlPrettySafe(
		Irp->MdlAddress, NormalPagePriority);

	if (!buf) {
		VFDTRACE(0,
			("[VFD] MmGetSystemAddressForMdlPrettySafe\n"));

		Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
		return;
	}

	if (DeviceExtension->FileHandle) {

		//	Write into image file
		Irp->IoStatus.Status = ZwWriteFile(
			DeviceExtension->FileHandle,
			NULL,
			NULL,
			NULL,
			&Irp->IoStatus,
			buf,
			Length,
			Offset,
			NULL);

		if (NT_SUCCESS(Irp->IoStatus.Status)) {
			Irp->IoStatus.Information = Length;
		}
		else {
			VFDTRACE(0,
				("[VFD] ZwWriteFile - %s\n",
				GetStatusName(Irp->IoStatus.Status)));
		}
	}
	else if (DeviceExtension->FileBuffer) {

		//	Deal with the modify flag
		if (RtlCompareMemory(
			DeviceExtension->FileBuffer + Offset->QuadPart,
			buf, Length) != Length) {
			DeviceExtension->MediaFlags |= VFD_FLAG_DATA_MODIFIED;
		}

		//	Copy into RAM image buffer
		RtlMoveMemory(
			DeviceExtension->FileBuffer + Offset->QuadPart,
			buf, Length);

		Irp->IoStatus.Status = STATUS_SUCCESS;
		Irp->IoStatus.Information = Length;
	}
	else {
		//	no image opened
		Irp->IoStatus.Status = STATUS_NO_MEDIA_IN_DEVICE;
	}

	VFDTRACE(VFDINFO,("[VFD] VfdWriteData - %s\n",
		GetStatusName(Irp->IoStatus.Status)));

	return;
}
int Cache_GetLineText(ClcCacheEntry *pdnce, int type, LPTSTR text, int text_size, ClcLineInfo &line)
{
	if (text == nullptr)
		return TEXT_EMPTY;
	text[0] = '\0';

	switch (type) {
	case TEXT_STATUS:
LBL_Status:
		if (GetStatusName(text, text_size, pdnce, line.xstatus_has_priority) == -1 && line.use_name_and_message_for_xstatus) {
			// Try to get XStatusMsg
			ptrW tszXStatusMsg(db_get_wsa(pdnce->hContact, pdnce->szProto, "XStatusMsg"));
			if (tszXStatusMsg != nullptr && tszXStatusMsg[0] != 0) {
				wchar_t *tmp = NEWWSTR_ALLOCA(text);
				mir_snwprintf(text, text_size, L"%s: %s", tmp, tszXStatusMsg);
				CopySkipUnprintableChars(text, text, text_size - 1);
			}
		}
		return TEXT_STATUS;

	case TEXT_NICKNAME:
		if (pdnce->hContact && pdnce->szProto) {
			ptrW tszNick(db_get_wsa(pdnce->hContact, pdnce->szProto, "Nick"));
			if (tszNick != nullptr) {
				mir_wstrncpy(text, tszNick, text_size);
				CopySkipUnprintableChars(text, text, text_size - 1);
			}
		}
		return TEXT_NICKNAME;

	case TEXT_STATUS_MESSAGE:
		if (GetStatusMessage(text, text_size, pdnce, line.xstatus_has_priority) == -1 && line.use_name_and_message_for_xstatus) {
			// Try to get XStatusName
			ptrW tszXStatusName(db_get_wsa(pdnce->hContact, pdnce->szProto, "XStatusName"));
			if (tszXStatusName != nullptr && tszXStatusName[0] != 0) {
				wchar_t *tmp = NEWWSTR_ALLOCA(text);
				mir_snwprintf(text, text_size, L"%s: %s", tszXStatusName, tmp);
				CopySkipUnprintableChars(text, text, text_size - 1);
			}
		}
		else if (line.use_name_and_message_for_xstatus && line.xstatus_has_priority) {
			// Try to get XStatusName
			ptrW tszXStatusName(db_get_wsa(pdnce->hContact, pdnce->szProto, "XStatusName"));
			if (tszXStatusName != nullptr && tszXStatusName[0] != 0) {
				mir_wstrncpy(text, tszXStatusName, text_size);
				CopySkipUnprintableChars(text, text, text_size - 1);
			}
		}

		if (text[0] == '\0') {
			if (line.show_listening_if_no_away) {
				GetListeningTo(text, text_size, pdnce);
				if (text[0] != '\0')
					return TEXT_LISTENING_TO;
			}

			if (line.show_status_if_no_away) // re-request status if no away
				goto LBL_Status;
		}
		return TEXT_STATUS_MESSAGE;

	case TEXT_LISTENING_TO:
		GetListeningTo(text, text_size, pdnce);
		return TEXT_LISTENING_TO;

	case TEXT_TEXT:
		{
			ptrW tmp(variables_parsedup(line.text, pdnce->tszName, pdnce->hContact));
			mir_wstrncpy(text, tmp, text_size);
			CopySkipUnprintableChars(text, text, text_size - 1);
		}
		return TEXT_TEXT;

	case TEXT_CONTACT_TIME:
		if (pdnce->hTimeZone) {
			// Get pdnce time
			text[0] = 0;
			TimeZone_PrintDateTime(pdnce->hTimeZone, L"t", text, text_size, 0);
		}
		return TEXT_CONTACT_TIME;
	}

	return TEXT_EMPTY;
}
// Get the text based on the settings for a especific line
void Cache_GetLineText(struct ClcContact *contact, int type, LPTSTR text, int text_size, TCHAR *variable_text, BOOL xstatus_has_priority, BOOL show_status_if_no_away, BOOL use_name_and_message_for_xstatus, BOOL contact_time_show_only_if_different)
{
	text[0] = '\0';
	switch(type)
	{
	case TEXT_STATUS:
		{
			if (GetStatusName(text, text_size, contact, xstatus_has_priority) == -1 && use_name_and_message_for_xstatus)
			{
				DBVARIANT dbv;

				// Try to get XStatusMsg
				if (!DBGetContactSettingTString(contact->hContact, contact->proto, "XStatusMsg", &dbv)) 
				{
					if (dbv.ptszVal != NULL && dbv.ptszVal[0] != 0)
					{
						TCHAR *tmp = mir_strdupT(text);
						mir_sntprintf(text, text_size, TEXT("%s: %s"), tmp, dbv.pszVal);
						mir_free(tmp);
					}
					DBFreeVariant(&dbv);
				}
			}

			break;
		}
	case TEXT_NICKNAME:
		{
			if (contact->hContact && contact->proto)
			{
				DBVARIANT dbv;
				if (!DBGetContactSettingTString(contact->hContact, contact->proto, "Nick", &dbv)) 
				{
					lstrcpyn(text, dbv.ptszVal, text_size);
					DBFreeVariant(&dbv);
				}
			}
			break;
		}
	case TEXT_STATUS_MESSAGE:
		{
			if (GetStatusMessage(text, text_size, contact, xstatus_has_priority) == -1 && use_name_and_message_for_xstatus)
			{
				DBVARIANT dbv;

				// Try to get XStatusName
				if (!DBGetContactSettingTString(contact->hContact, contact->proto, "XStatusName", &dbv)) 
				{
					if (dbv.pszVal != NULL && dbv.pszVal[0] != 0)
					{
						TCHAR *tmp = mir_strdupT(text);
						mir_sntprintf(text, text_size, TEXT("%s: %s"), dbv.pszVal, tmp);
						mir_free(tmp);
					}
					DBFreeVariant(&dbv);
				}
			}

			break;
		}
	case TEXT_TEXT:
		{
#ifndef UNICODE	
			if (!ServiceExists(MS_VARS_FORMATSTRING))
			{
				lstrcpyn(text, variable_text, text_size);
			}
			else
			{
				char *tmp = variables_parse(variable_text, contact->szText, contact->hContact);
				lstrcpyn(text, tmp, text_size);
				variables_free(tmp);
			}
#else
			lstrcpyn(text, variable_text, text_size);
#endif
			break;
		}
	case TEXT_CONTACT_TIME:
		{
			if (contact->timezone != -1 && (!contact_time_show_only_if_different || contact->timediff != 0))
			{
				// Get contact time
				DBTIMETOSTRINGT dbtts;
				time_t contact_time;

				contact_time = time(NULL) - contact->timediff;
				text[0] = '\0';

				dbtts.szDest = text;
				dbtts.cbDest = 70;
				dbtts.szFormat = TEXT("t");
				CallService(MS_DB_TIME_TIMESTAMPTOSTRINGT, contact_time, (LPARAM) & dbtts);
			}

			break;
		}
	}
	if (type==TEXT_STATUS_MESSAGE && show_status_if_no_away && text[0] == '\0')
	{
		//re-request status if no away
		Cache_GetLineText(contact, TEXT_STATUS, text, text_size, variable_text, xstatus_has_priority,0, use_name_and_message_for_xstatus, contact_time_show_only_if_different);		
	}

}
Beispiel #19
0
//
//	Open a virtual floppy image file or create an empty ram disk
//
NTSTATUS
VfdOpenImage (
	IN PDEVICE_EXTENSION		DeviceExtension,
	IN PVFD_IMAGE_INFO			ImageInfo)
{
	IO_STATUS_BLOCK				io_status;
	NTSTATUS					status	= STATUS_SUCCESS;
	const DISK_GEOMETRY			*geometry;
	ULONG						sectors;
	ULONG						alignment;

	VFDTRACE(0, ("[VFD] VfdOpenImage - IN\n"));

	//
	//	Store file name in the device extension
	//
	if (ImageInfo->NameLength) {

		if (ImageInfo->NameLength + 1 >
			DeviceExtension->FileName.MaximumLength) {

			//	expand the filename buffer

			if (DeviceExtension->FileName.Buffer) {
				ExFreePool(DeviceExtension->FileName.Buffer);
				RtlZeroMemory(
					&DeviceExtension->FileName,
					sizeof(ANSI_STRING));
			}

			DeviceExtension->FileName.Buffer = (PCHAR)ExAllocatePoolWithTag(
				NonPagedPool, ImageInfo->NameLength + 1, VFD_POOL_TAG);

			if (!DeviceExtension->FileName.Buffer) {
				VFDTRACE(0, ("[VFD] Can't allocate memory for image path\n"));
				return STATUS_INSUFFICIENT_RESOURCES;
			}

			DeviceExtension->FileName.MaximumLength
				= (USHORT)(ImageInfo->NameLength + 1);

			RtlZeroMemory(
				DeviceExtension->FileName.Buffer,
				DeviceExtension->FileName.MaximumLength);
		}

		if (DeviceExtension->FileName.Buffer) {
			RtlCopyMemory(
				DeviceExtension->FileName.Buffer,
				ImageInfo->FileName,
				ImageInfo->NameLength);

			DeviceExtension->FileName.Buffer[ImageInfo->NameLength] = '\0';
		}
	}

	DeviceExtension->FileName.Length = ImageInfo->NameLength;

	//
	//	Get DISK_GEOMETRY and calculate the media capacity
	//	-- validity of the ImageInfo->MediaType value is assured in
	//	the VfdOpenCheck function
	//
	geometry = &geom_tbl[ImageInfo->MediaType];

	sectors =
		geometry->Cylinders.LowPart *
		geometry->TracksPerCylinder *
		geometry->SectorsPerTrack;

	if (ImageInfo->ImageSize != 0 &&
		ImageInfo->ImageSize < VFD_SECTOR_TO_BYTE(sectors)) {

			VFDTRACE(0, ("[VFD] Image is smaller than the media\n"));
			return STATUS_INVALID_PARAMETER;
	}

	//
	//	Prepare a virtual media according to the ImageInfo
	//
	if (ImageInfo->DiskType == VFD_DISKTYPE_FILE) {
		//
		//	open an existing image file
		//
		HANDLE						file_handle;
		OBJECT_ATTRIBUTES			attributes;
		UNICODE_STRING				unicode_name;
		FILE_STANDARD_INFORMATION	file_standard;
		FILE_BASIC_INFORMATION		file_basic;
		FILE_ALIGNMENT_INFORMATION	file_alignment;
		PFILE_OBJECT				file_object;
		BOOLEAN						network_drive;

		//	convert the filename into a unicode string

		status = RtlAnsiStringToUnicodeString(
			&unicode_name, &DeviceExtension->FileName, TRUE);

		if (!NT_SUCCESS(status)) {
			VFDTRACE(0, ("[VFD] Failed to convert filename to UNICODE\n"));
			return status;
		}

		VFDTRACE(VFDINFO,
			("[VFD] Opening %s\n", DeviceExtension->FileName.Buffer));

		//	prepare an object attribute to open

		InitializeObjectAttributes(
			&attributes,
			&unicode_name,
			OBJ_CASE_INSENSITIVE,
			NULL,
			NULL);

		//	open the target file

		status = ZwCreateFile(
			&file_handle,
			GENERIC_READ | GENERIC_WRITE,
			&attributes,
			&io_status,
			NULL,
			FILE_ATTRIBUTE_NORMAL,
			0,
			FILE_OPEN,
			FILE_NON_DIRECTORY_FILE |
			FILE_RANDOM_ACCESS |
			FILE_NO_INTERMEDIATE_BUFFERING |
			FILE_SYNCHRONOUS_IO_NONALERT,
			NULL,
			0);

		RtlFreeUnicodeString(&unicode_name);

		if (!NT_SUCCESS(status)) {
			VFDTRACE(0, ("[VFD] ZwCreateFile - %s\n",
				GetStatusName(status)));
			return status;
		}

		//	Check the file size

		status = ZwQueryInformationFile(
			file_handle,
			&io_status,
			&file_standard,
			sizeof(FILE_STANDARD_INFORMATION),
			FileStandardInformation);

		if (!NT_SUCCESS(status)) {
			VFDTRACE(0,
				("[VFD] ZwQueryInformationFile - FILE_STANDARD_INFORMATION\n"));

			ZwClose(file_handle);
			goto exit_func;
		}

		//	Actual file size can be larger than the media capacity

		if (file_standard.EndOfFile.QuadPart < VFD_SECTOR_TO_BYTE(sectors)) {

			VFDTRACE(0, ("[VFD] file is smaller than the media.\n"));

			status = STATUS_INVALID_PARAMETER;

			ZwClose(file_handle);
			goto exit_func;
		}

		DeviceExtension->ImageSize = file_standard.EndOfFile.LowPart;

		// Find out whether the file is on a local disk or a network drive

		network_drive = FALSE;

		status = ObReferenceObjectByHandle(
			file_handle,
			GENERIC_READ,
			NULL,
			KernelMode,
			&file_object,
			NULL);

		if (NT_SUCCESS(status)) {
			if (file_object && file_object->DeviceObject) {
				VFDTRACE(VFDINFO, ("[VFD] Device type is 0x%08x\n",
					file_object->DeviceObject->DeviceType));

				if (file_object->DeviceObject->DeviceType
					== FILE_DEVICE_NETWORK_FILE_SYSTEM) {
					network_drive = TRUE;
				}

				// how about these types ?
				// FILE_DEVICE_NETWORK
				// FILE_DEVICE_NETWORK_BROWSER
				// FILE_DEVICE_NETWORK_REDIRECTOR
			}
			else {
				VFDTRACE(VFDWARN, ("[VFD Cannot decide the device type\n"));
			}
			ObDereferenceObject(file_object);
		}
		else {
			VFDTRACE(0, ("[VFD] ObReferenceObjectByHandle - %s\n",
				GetStatusName(status)));
		}

		if (!network_drive) {
			// The NT cache manager can deadlock if a filesystem that is using
			// the cache manager is used in a virtual disk that stores its file
			// on a file systemthat is also using the cache manager, this is
			// why we open the file with FILE_NO_INTERMEDIATE_BUFFERING above,
			// however if the file is compressed or encrypted NT will not honor
			// this request and cache it anyway since it need to store the
			// decompressed/unencrypted data somewhere, therefor we put an
			// extra check here and don't alow disk images to be compressed/
			// encrypted.

			status = ZwQueryInformationFile(
				file_handle,
				&io_status,
				&file_basic,
				sizeof(FILE_BASIC_INFORMATION),
				FileBasicInformation);

			if (!NT_SUCCESS(status)) {
				VFDTRACE(0,
					("[VFD] ZwQueryInformationFile - FILE_BASIC_INFORMATION\n"));

				ZwClose(file_handle);
				goto exit_func;
			}

			if (file_basic.FileAttributes
				& (FILE_ATTRIBUTE_COMPRESSED | FILE_ATTRIBUTE_ENCRYPTED))
			{
				VFDTRACE(0,
					("[VFD] Image file is compressed and/or encrypted\n"));

				status =  STATUS_ACCESS_DENIED;

				ZwClose(file_handle);
				goto exit_func;
			}
		}

		//	Retrieve the file alignment requirement

		status = ZwQueryInformationFile(
			file_handle,
			&io_status,
			&file_alignment,
			sizeof(FILE_ALIGNMENT_INFORMATION),
			FileAlignmentInformation);

		if (!NT_SUCCESS(status)) {
			VFDTRACE(0,
				("[VFD] ZwQueryInformationFile - FILE_ALIGNMENT_INFORMATION\n"));

			ZwClose(file_handle);
			goto exit_func;
		}

		DeviceExtension->FileHandle = file_handle;

		alignment = file_alignment.AlignmentRequirement;

		VFDTRACE(0, ("[VFD] Opened an image file\n"));
	}
	else {
		//
		//	Create an empty RAM disk
		//
		DeviceExtension->FileBuffer = (PUCHAR)ExAllocatePoolWithTag(
			NonPagedPool,
			VFD_SECTOR_TO_BYTE(sectors),
			VFD_POOL_TAG);

		if (!DeviceExtension->FileBuffer) {
			VFDTRACE(0, ("[VFD] Can't allocate memory for RAM disk\n"));
			return STATUS_INSUFFICIENT_RESOURCES;
		}

		RtlZeroMemory(
			DeviceExtension->FileBuffer,
			VFD_SECTOR_TO_BYTE(sectors));

		if (ImageInfo->ImageSize) {
			DeviceExtension->ImageSize = ImageInfo->ImageSize;
		}
		else {
			DeviceExtension->ImageSize = VFD_SECTOR_TO_BYTE(sectors);
		}

		alignment = FILE_WORD_ALIGNMENT;

		VFDTRACE(0, ("[VFD] Created an empty RAM disk\n"));
	}

	DeviceExtension->MediaChangeCount++;

	DeviceExtension->MediaType	= ImageInfo->MediaType;
	DeviceExtension->MediaFlags	= ImageInfo->MediaFlags;
	DeviceExtension->FileType	= ImageInfo->FileType;
	DeviceExtension->Geometry	= geometry;
	DeviceExtension->Sectors	= sectors;

	VFDTRACE(0, ("[VFD] Media:%d Flag:0x%02x Size:%lu Capacity:%lu\n",
		DeviceExtension->MediaType,
		DeviceExtension->MediaFlags,
		DeviceExtension->ImageSize,
		DeviceExtension->Sectors));

	DeviceExtension->DeviceObject->AlignmentRequirement
		= alignment;

exit_func:
	VFDTRACE(0, ("[VFD] VfdOpenImage - %s\n", GetStatusName(status)));

	return status;
}