// Reads and displays information about the device
void DisplayDeviceInformation(
    IPortableDeviceServiceManager*  pServiceManager,
    PCWSTR                          pPnpServiceID)
{
    PWSTR                           pPnpDeviceID    = NULL;
    CComPtr<IPortableDeviceManager> pIPortableDeviceManager;

    // Retrieve the PnP identifier of the device that contains this service
    HRESULT hr = pServiceManager->GetDeviceForService(pPnpServiceID, &pPnpDeviceID);
    if (SUCCEEDED(hr))
    {
        // Retrieve the IPortableDeviceManager interface from IPortableDeviceServiceManager
        hr = pServiceManager->QueryInterface(IID_PPV_ARGS(&pIPortableDeviceManager));
        if (SUCCEEDED(hr))
        {        
            DisplayFriendlyName(pIPortableDeviceManager, pPnpDeviceID);
            printf("    ");
            DisplayManufacturer(pIPortableDeviceManager, pPnpDeviceID);
            printf("    ");
            DisplayDescription(pIPortableDeviceManager, pPnpDeviceID);
            printf("\n");
        }
        else
        {
            printf("! Failed to QueryInterface IID_IPortableDeviceManager, hr = 0x%lx\n",hr);
        }
    }
    else
    {
        printf("! Failed to get the device PnP identifier, hr = 0x%lx\n",hr);
    }
    
    CoTaskMemFree(pPnpDeviceID);
}
Esempio n. 2
0
/***********************************************************
handle event when list is selected
***********************************************************/
bool JournalBox::HandleQuestTreeSelected (const CEGUI::EventArgs& e)
{
	CEGUI::Tree * tree = static_cast<CEGUI::Tree *> (
		CEGUI::WindowManager::getSingleton().getWindow("Root/JournalWin/tab/questtab/Tree"));

	const MyTreeItem * it = static_cast<const MyTreeItem *>(tree->getFirstSelectedItem());
	if(it)
		DisplayDescription (it->Description, false);

	return true;
}
// Enumerates all Windows Portable Devices, displays the friendly name,
// manufacturer, and description of each device.  This function also
// returns the total number of devices found.
DWORD EnumerateAllDevices()
{
    DWORD                           cPnPDeviceIDs = 0;
    PWSTR*                          pPnpDeviceIDs = NULL;
    CComPtr<IPortableDeviceManager> pPortableDeviceManager;

    // CoCreate the IPortableDeviceManager interface to enumerate
    // portable devices and to get information about them.
	//<SnippetDeviceEnum1>
    HRESULT hr = CoCreateInstance(CLSID_PortableDeviceManager,
                                  NULL,
                                  CLSCTX_INPROC_SERVER,
                                  IID_PPV_ARGS(&pPortableDeviceManager));
    if (FAILED(hr))
    {
        printf("! Failed to CoCreateInstance CLSID_PortableDeviceManager, hr = 0x%lx\n",hr);
    }
	//</SnippetDeviceEnum1>

    // First, pass NULL as the PWSTR array pointer to get the total number
    // of devices found on the system.
	//<SnippetDeviceEnum2>
    if (SUCCEEDED(hr))
    {
        hr = pPortableDeviceManager->GetDevices(NULL, &cPnPDeviceIDs);
        if (FAILED(hr))
        {
            printf("! Failed to get number of devices on the system, hr = 0x%lx\n",hr);
        }
    }

    // Report the number of devices found.  NOTE: we will report 0, if an error
    // occured.

    printf("\n%d Windows Portable Device(s) found on the system\n\n", cPnPDeviceIDs);
	//</SnippetDeviceEnum2>
    // Second, allocate an array to hold the PnPDeviceID strings returned from
    // the IPortableDeviceManager::GetDevices method
    if (SUCCEEDED(hr) && (cPnPDeviceIDs > 0))
    {
        pPnpDeviceIDs = new (std::nothrow) PWSTR[cPnPDeviceIDs];
        if (pPnpDeviceIDs != NULL)
        {
            DWORD dwIndex = 0;

            hr = pPortableDeviceManager->GetDevices(pPnpDeviceIDs, &cPnPDeviceIDs);
            if (SUCCEEDED(hr))
            {
                // For each device found, display the devices friendly name,
                // manufacturer, and description strings.
                for (dwIndex = 0; dwIndex < cPnPDeviceIDs; dwIndex++)
                {
                    printf("[%d] ", dwIndex);
                    DisplayFriendlyName(pPortableDeviceManager, pPnpDeviceIDs[dwIndex]);
                    printf("    ");
                    DisplayManufacturer(pPortableDeviceManager, pPnpDeviceIDs[dwIndex]);
                    printf("    ");
                    DisplayDescription(pPortableDeviceManager, pPnpDeviceIDs[dwIndex]);
                }
            }
            else
            {
                printf("! Failed to get the device list from the system, hr = 0x%lx\n",hr);
            }

            // Free all returned PnPDeviceID strings by using CoTaskMemFree.
            // NOTE: CoTaskMemFree can handle NULL pointers, so no NULL
            //       check is needed.
			//<SnippetDeviceEnum3>
            for (dwIndex = 0; dwIndex < cPnPDeviceIDs; dwIndex++)
            {
                CoTaskMemFree(pPnpDeviceIDs[dwIndex]);
                pPnpDeviceIDs[dwIndex] = NULL;
            }

            // Delete the array of PWSTR pointers
            delete [] pPnpDeviceIDs;
            pPnpDeviceIDs = NULL;
			//</SnippetDeviceEnum3>
        }
        else
        {
            printf("! Failed to allocate memory for PWSTR array\n");
        }
    }

    return cPnPDeviceIDs;
}
Esempio n. 4
0
/***********************************************************
call to regenerate the quest book display
***********************************************************/
void JournalBox::RebuildBook(bool reset)
{
	CEGUI::Tree * tree = static_cast<CEGUI::Tree *> (
		CEGUI::WindowManager::getSingleton().getWindow("Root/JournalWin/tab/questtab/Tree"));

	CEGUI::Tree * tree2 = static_cast<CEGUI::Tree *> (
		CEGUI::WindowManager::getSingleton().getWindow("Root/JournalWin/tab/questdonetab/Tree"));

	if(reset)
	{
		tree->resetList();
		tree2->resetList();
		_mapquestarea.clear();
		_mapquestdonearea.clear();
		CEGUI::WindowManager::getSingleton().getWindow("Root/JournalWin/tab/questtab/Description")->setText("");
		CEGUI::WindowManager::getSingleton().getWindow("Root/JournalWin/tab/questdonetab/Description")->setText("");
		_first_book_init = true;
	}


	// rebuild quests
	{
		// remove extra quests
		std::map<std::string, CEGUI::TreeItem *>::iterator itmap = _mapquestarea.begin();
		while(itmap != _mapquestarea.end())
		{
			bool remove = false;
			std::vector<CEGUI::TreeItem*> items = itmap->second->getItemList();
			for(size_t i=0; i<items.size(); ++i)
			{
				if(_QuestsStarted.find(static_cast<MyTreeItem *> (items[i])->QuestId) == _QuestsStarted.end())
				{	
					itmap->second->removeItem(items[i]);
					if(itmap->second->getItemCount() == 0)
						remove = true;
				}
			}

			if(remove)
			{
				tree->removeItem(itmap->second);
				_mapquestarea.erase(itmap++);
			}
			else
				++itmap;
		}

		// add missing quests
		LbaNet::QuestsMap::const_iterator itstarted = _QuestsStarted.begin();
		LbaNet::QuestsMap::const_iterator endstarted = _QuestsStarted.end();
		for(; itstarted != endstarted; ++itstarted)
		{
			const LbaNet::QuestInfo &qi = itstarted->second;
			if(qi.Visible)
			{
				std::string Tittle = Localizer::getInstance()->GetText(Localizer::Quest, (long)qi.TittleTextId);
				std::string Description = Localizer::getInstance()->GetText(Localizer::Quest, (long)qi.DescriptionTextId);
				std::string QuestArea = Localizer::getInstance()->GetText(Localizer::Quest, (long)qi.QuestAreaTextId);

				if(QuestArea == "")
					QuestArea = "General";

				std::vector<CEGUI::String> listt;
				CreateTextList(Description, listt);



				std::map<std::string, CEGUI::TreeItem *>::iterator itm = _mapquestarea.find(QuestArea);
				if(itm != _mapquestarea.end())
				{
					bool found = false;
					std::vector<CEGUI::TreeItem*> items = itm->second->getItemList();
					for(size_t i=0; i<items.size(); ++i)
					{
						if(static_cast<MyTreeItem *> (items[i])->QuestId == qi.Id)
						{	
							found = true;
							break;
						}
					}

					if(!found)
					{
						MyTreeItem * titm = new MyTreeItem((const unsigned char *)Tittle.c_str(), listt, (long)qi.Id);
						itm->second->addItem(titm);

						if(_first_book_init)
						{
							if(_selected_tree_quests == Tittle)
							{
								titm->setSelected(true);
								DisplayDescription (titm->Description, false);
							}
						}
					}
				}
				else
				{
					MyTreeItem * titm = new MyTreeItem((const unsigned char *)Tittle.c_str(), listt, (long)qi.Id);
					std::vector<CEGUI::String> empty;
					CEGUI::TreeItem * root = new MyTreeItem((const unsigned char *)QuestArea.c_str(), empty);
					tree->addItem(root);
					root->addItem(titm);
					_mapquestarea[QuestArea] = root;

					if(_first_book_init)
					{
						if(_selected_tree_quests == Tittle)
						{
							titm->setSelected(true);
							DisplayDescription (titm->Description, false);
						}
					}
				}
			}
		}
	}


	// rebuild quests done
	{
		// remove extra quests
		std::map<std::string, CEGUI::TreeItem *>::iterator itmap = _mapquestdonearea.begin();
		while(itmap != _mapquestdonearea.end())
		{
			bool remove = false;
			std::vector<CEGUI::TreeItem*> items = itmap->second->getItemList();
			for(size_t i=0; i<items.size(); ++i)
			{
				if(_QuestsFinished.find(static_cast<MyTreeItem *> (items[i])->QuestId) == _QuestsFinished.end())
				{	
					itmap->second->removeItem(items[i]);
					if(itmap->second->getItemCount() == 0)
						remove = true;
				}
			}

			if(remove)
			{
				tree->removeItem(itmap->second);
				_mapquestdonearea.erase(itmap++);
			}
			else
				++itmap;
		}

		// add missing quests
		LbaNet::QuestsMap::const_iterator itfinished = _QuestsFinished.begin();
		LbaNet::QuestsMap::const_iterator endfinished = _QuestsFinished.end();
		for(; itfinished != endfinished; ++itfinished)
		{
			const LbaNet::QuestInfo &qi = itfinished->second;
			if(qi.Visible)
			{
				std::string Tittle = Localizer::getInstance()->GetText(Localizer::Quest, (long)qi.TittleTextId);
				std::string Description = Localizer::getInstance()->GetText(Localizer::Quest, (long)qi.DescriptionTextId);
				std::string QuestArea = Localizer::getInstance()->GetText(Localizer::Quest, (long)qi.QuestAreaTextId);

				if(QuestArea == "")
					QuestArea = Localizer::getInstance()->GetText(Localizer::GUI, 84);

				std::vector<CEGUI::String> listt;
				CreateTextList(Description, listt);



				std::map<std::string, CEGUI::TreeItem *>::iterator itm = _mapquestdonearea.find(QuestArea);
				if(itm != _mapquestdonearea.end())
				{
					bool found = false;
					std::vector<CEGUI::TreeItem*> items = itm->second->getItemList();
					for(size_t i=0; i<items.size(); ++i)
					{
						if(static_cast<MyTreeItem *> (items[i])->QuestId == qi.Id)
						{	
							found = true;
							break;
						}
					}

					if(!found)
					{
						MyTreeItem * titm = new MyTreeItem((const unsigned char *)Tittle.c_str(), listt, (long)qi.Id);
						itm->second->addItem(titm);

						if(_first_book_init)
						{
							if(_selected_tree_done_quests == Tittle)
							{
								titm->setSelected(true);
								DisplayDescription (titm->Description, true);
							}
						}
					}
				}
				else
				{
					MyTreeItem * titm = new MyTreeItem((const unsigned char *)Tittle.c_str(), listt, (long)qi.Id);
					std::vector<CEGUI::String> empty;
					CEGUI::TreeItem * root = new MyTreeItem((const unsigned char *)QuestArea.c_str(), empty);
					tree2->addItem(root);
					root->addItem(titm);
					_mapquestdonearea[QuestArea] = root;

					if(_first_book_init)
					{
						if(_selected_tree_done_quests == Tittle)
						{
							titm->setSelected(true);
							DisplayDescription (titm->Description, true);
						}
					}
				}
			}
		}
	}


	if(!_first_book_init)
	{
		if(tree->getFirstSelectedItem() == NULL)
			CEGUI::WindowManager::getSingleton().getWindow("Root/JournalWin/tab/questtab/Description")->setText("");
		
		if(tree2->getFirstSelectedItem() == NULL)
			CEGUI::WindowManager::getSingleton().getWindow("Root/JournalWin/tab/questdonetab/Description")->setText("");
	}

	if(_first_book_init)
	{
		_first_book_init = false;

		{
			std::map<std::string, CEGUI::TreeItem *>::iterator itm =	_mapquestarea.begin();
			std::map<std::string, CEGUI::TreeItem *>::iterator endm =	_mapquestarea.end();
			for(; itm != endm; ++itm)
			{
				if(std::find(_open_tree_quests.begin(), _open_tree_quests.end(), itm->first) != _open_tree_quests.end())
					itm->second->toggleIsOpen();
			}

		}

		{
			std::map<std::string, CEGUI::TreeItem *>::iterator itm =	_mapquestdonearea.begin();
			std::map<std::string, CEGUI::TreeItem *>::iterator endm =	_mapquestdonearea.end();
			for(; itm != endm; ++itm)
			{
				if(std::find(_open_tree_done_quests.begin(), _open_tree_done_quests.end(), itm->first) != _open_tree_done_quests.end())
					itm->second->toggleIsOpen();
			}
		}
	}

}