Example #1
0
// 保存
void CImageViewDlg::OnBnClickedButton3()
{
	CString content = _T("1");
	CInputDlg dlg(_T("输入图片序号:"), content, NULL, FALSE, CInputDlg::IDD, this);
	if (dlg.DoModal() != IDOK || content == _T(""))
		return;
	int index = _ttoi(content) - 1;
	if (index < 0 || (UINT)index >= m_imageURL->size())
		return;

	if (m_image[index].IsNull())
		return;

	BROWSEINFO bi;
	ZeroMemory(&bi, sizeof(bi));
	bi.lpszTitle = _T("保存目录:");
	bi.ulFlags = BIF_STATUSTEXT;
	LPITEMIDLIST pidlSel = SHBrowseForFolder(&bi);

	if (pidlSel != NULL)
	{
		CString folder;
		SHGetPathFromIDList(pidlSel, folder.GetBuffer(MAX_PATH));
		folder.ReleaseBuffer();
		
		CString imgName = GetImageName((*m_imageURL)[index]);
		m_image[index].Save(folder + _T("\\") + imgName);
	}
}
Example #2
0
inline bool MtgCard::operator==(const MtgCard& rhs) {
    return GetLayout() == rhs.GetLayout() &&
            GetManacost() == rhs.GetManacost() &&
            GetCmc() == rhs.GetCmc() &&
            CompareStringList(GetColors(), rhs.GetColors()) &&
            type == rhs.type &&
            CompareStringList(GetSupertypes(), rhs.GetSupertypes()) &&
            CompareStringList(GetTypes(), rhs.GetTypes()) &&
            CompareStringList(GetSubtypes(), rhs.GetSubtypes()) &&
            GetRarity() == rhs.GetRarity() &&
            text == rhs.GetText() &&
            GetFlavor() == rhs.GetFlavor() &&
            GetArtist() == rhs.GetArtist() &&
            GetNumber() == rhs.GetNumber() &&
            GetPower() == rhs.GetPower() &&
            GetToughness() == rhs.GetToughness() &&
            GetLoyalty() == rhs.GetLoyalty() &&
            GetMultiverseid() == rhs.GetMultiverseid() &&
            CompareIntList(GetVariations(), rhs.GetVariations()) &&
            GetImageName() == rhs.GetImageName() &&
            GetWatermark() == rhs.GetWatermark() &&
            GetBorder() == rhs.GetBorder() &&
            IsTimeshifted() == rhs.IsTimeshifted() &&
            GetHand() == rhs.GetHand() &&
            GetLife() == rhs.GetLife() &&
            IsReserved() == rhs.IsReserved() &&
            GetReleasedate() == rhs.GetReleasedate() &&
            IsStarter() == rhs.IsStarter() &&
            CompareStringPairList(GetRulings(), rhs.GetRulings()) &&
            CompareStringPairList(GetForeignNames(), rhs.GetForeignNames()) &&
            GetOriginalText() == rhs.GetOriginalText() &&
            GetOriginalType() == rhs.GetOriginalType() &&
            CompareStringPairList(GetLegalities(), rhs.GetLegalities()) &&
            GetEdition() == rhs.GetEdition();
}
Example #3
0
// 设置图片
void CImageViewDlg::SetImages(unique_ptr<vector<CString> > imageURL)
{
	m_imageURL = std::move(imageURL);
	m_image.resize(m_imageURL->size());

	// 读取图片到m_image
	for (UINT i = 0; i < m_imageURL->size(); i++)
	{
		CString imgName = GetImageName((*m_imageURL)[i]);
		if (PathFileExists(IMG_CACHE_PATH + imgName))
		{
			// 读取图片缓存
			if (!m_image[i].IsNull())
				m_image[i].Destroy();
			m_image[i].Load(IMG_CACHE_PATH + imgName);
		}
		else
		{
			// 下载图片
			unique_ptr<BYTE[]> buffer;
			ULONG size;
			if (HTTPGetRaw((*m_imageURL)[i], &buffer, &size) == NET_SUCCESS)
			{
				ReadImage(buffer.get(), size, m_image[i]);

				CreateDir(IMG_CACHE_PATH);
				CFile file;
				if (file.Open(IMG_CACHE_PATH + imgName, CFile::modeCreate | CFile::modeWrite))
					file.Write(buffer.get(), size);
			}
		}
	}

	UpdateScrollRange();
}
Example #4
0
void CHandBookHeroLayer::initCellIconByData( AData *pAData, CLayout *pCell )
{
	//message AData{
	//	optional int32 type = 1;		//类型 1英雄,2装备,3怪物
	//	optional int32 thumb = 2;		
	//	optional int32 color = 3;		//边框颜色
	//	optional int32 process = 4;		//英雄、装备代表进阶数,怪物代表击杀数
	//	optional int32 max_process = 5;
	//	optional int32 param = 6;
	//}


	Prize *prize = new Prize; 
	//获取数据
	int iType = 1;
	if ( pAData->type()==1 || pAData->type()==3 )
	{
		iType = 2;
	}
	int iColor = pAData->color();
	int iIconId = pAData->thumb();
	int iRank = pAData->process();

	string str = GetImageName(iType, iColor, iIconId);

	//图标
	CImageView* pBgRect = (CImageView *)pCell->findWidgetById("headBg");
	CImageView *itemSpr = CImageView::create(str.c_str());
	if (!itemSpr)
	{
		itemSpr = CImageView::create("prop/32003.png");
		CCLOG("[ ERROR ] CPopItem::addTableCell Lost Image = %d");
	}
	pBgRect->addChild(itemSpr);
	NodeFillParent(itemSpr);

	//品质+事件
	CImageView *mask= (CImageView *)pCell->findWidgetById("head");
	mask->setTexture(setItemQualityTexture(iColor));
	mask->setUserData(pAData);
	mask->setTag(iType);
	mask->setTouchEnabled(true);
	mask->setOnClickListener(this, ccw_click_selector(CHandBookHeroLayer::onShowRankUp));

	//进阶
	for ( int i=0; i<5; i++)
	{
		CImageView *pStar = (CImageView *)pCell->getChildByTag(i+3);
		//阶级到,点亮
		if (i<iRank)
		{
			pStar->setShaderProgram(ShaderDataMgr->getShaderByType(ShaderDefault));
		}
		else
		{
			pStar->setShaderProgram(ShaderDataMgr->getShaderByType(ShaderStone));
		}
	}
}
Example #5
0
// 检查图片违规2,下载图片、比较图片
BOOL DoCheckImageIllegal(vector<CString>& imgs, CString& msg)
{
	for (const CString& img : imgs)
	{
		CString imgName = GetImageName(img);

		// 检查缓存结果
		if (g_leagalImage.find(imgName) != g_leagalImage.end())
			continue;
		if (g_illegalImage.find(imgName) != g_illegalImage.end())
			return TRUE;

		// 读取图片
		Mat image;
		if (PathFileExists(IMG_CACHE_PATH + imgName))
		{
			// 读取图片缓存
			ReadImage(IMG_CACHE_PATH + imgName, image);
		}
		else
		{
			// 下载图片
			unique_ptr<BYTE[]> buffer;
			ULONG size;
			if (HTTPGetRaw(img, &buffer, &size, FALSE) == NET_SUCCESS)
			{
				ReadImage(buffer.get(), size, image);

				CreateDir(IMG_CACHE_PATH);
				CFile file;
				if (file.Open(IMG_CACHE_PATH + imgName, CFile::modeCreate | CFile::modeWrite))
					file.Write(buffer.get(), size);
			}
		}

		if (image.data == NULL || image.cols < 30 || image.rows < 30) // 尺寸太小不比较
			continue;
		// 判断和违规图片比较大于阈值
		g_plan.m_optionsLock.Lock();
		for (const NameImage& i : g_plan.m_images)
		{
			if (i.img.cols < 30 || i.img.rows < 30) // 尺寸太小不比较
				continue;
			double mssim = getMSSIM(image, i.img);
			if (mssim > g_plan.m_SSIMThreshold)
			{
				msg.Format(_T("<font color=red> 触发违规图片 </font>%s<font color=red> 相似度%.3lf</font>"),
					(LPCTSTR)i.name, mssim);
				g_illegalImage.insert(imgName);
				g_plan.m_optionsLock.Unlock();
				return TRUE;
			}
		}
		g_leagalImage.insert(imgName);
		g_plan.m_optionsLock.Unlock();
	}

	return FALSE;
}
Example #6
0
std::string PDFImageObject::ObjectEntry()
{
//	if ( !ImageLen() )
//		buffer = ObjectHeader();
	buffer +=  "<<\r";
	buffer += "/Type /XObject\r";
	buffer += "/Subtype /Image\r";
	buffer += "/Name /";
	buffer += GetImageName();
	buffer += "\r";
	buffer += "/Width ";
	buffer += GetWidth();
	buffer += "\r";
	buffer += "/Height ";
	buffer += GetHeight();
	buffer += "\r";
	buffer += "/BitsPerComponent ";
	buffer += GetBitsPerComponent();
	buffer += "\r";

	buffer += "/ColorSpace ";
//	buffer += GetColorSpace();
//	buffer += "\r";
	buffer += GetColorSpaceObjIdStr();

	if ( !GetFilter().empty() ) 
	{
		buffer += "/Filter ";
		buffer += GetFilter();
		buffer += "\r";
	}

	buffer += "/Length ";
	if ( !ImageLen() )
		buffer += intToStr( imageData.length() );
	else
		buffer += intToStr( imageLen );
	buffer += "\r";

	buffer += ">>\r";
	buffer += "stream\r";
	if ( !ImageLen() )
	{
		buffer += imageData;
		buffer += "\r% Trev2\rendstream\r";
	}
	AddContents( buffer );
	if ( !ImageLen() )
		return PDFBodyObject::ObjectEntry();
	else
		return GetContents();
}
Example #7
0
// 从目录读取图片到g_images
void ReadImages(const CString& dir)
{
	vector<CString> imagePath;

	if (dir == _T(""))
	{
		g_plan.m_images.clear();
		return;
	}
	CFileFind fileFind;
	static const TCHAR* IMG_EXT[] = { _T("\\*.jpg"), _T("\\*.png"), _T("\\*.gif"), _T("\\*.jpeg"), _T("\\*.bmp") };
	for (int i = 0; i < _countof(IMG_EXT); i++)
	{
		BOOL flag = fileFind.FindFile(dir + IMG_EXT[i]);
		while (flag)
		{
			flag = fileFind.FindNextFile();
			imagePath.push_back(fileFind.GetFilePath());
		}
	}

	g_plan.m_images.resize(imagePath.size());
	UINT imgCount = 0;
	for (CString& i : imagePath)
	{
		g_plan.m_images[imgCount].name = GetImageName(i);
		if (ReadImage(i, g_plan.m_images[imgCount].img))
			imgCount++;
	}
	if (imagePath.size() != imgCount)
	{
		g_plan.m_images.resize(imgCount);
		CString msg;
		msg.Format(_T("%u张图片加载失败!"), imagePath.size() - imgCount);
		AfxMessageBox(msg, MB_ICONINFORMATION);
	}
}
Example #8
0
void CStrengthenItem::addTableCell(unsigned int uIdx, CTableViewCell * pCell)
{
	CLayout *lay = UICloneMgr::cloneLayout(m_cell);

	CItem &item =  *(m_itemList.at(uIdx));// m_itemData.itemList.at(uIdx);

	pCell->setTag(uIdx);

	const ItemData * itemData = DataCenter::sharedData()->getItemDesc()->getCfg(item.itemId);

	for (int i = 1; i <=11; i++)
	{
		CCNode *child = lay->getChildByTag(i);
		if (!child) continue;
		lay->removeChild(child);
		pCell->addChild(child);

		if (i==1)
		{
			CImageView *bgImg = (CImageView*)child;
			if (m_toHero>0)
			{
				if (!item.canUse&&item.armor.hero!=m_toHero)
				{
					CColorView *colorView = CColorView::create(ccc4(0,0,0,100));
					colorView->setContentSize(bgImg->getContentSize());
 					colorView->setPosition(bgImg->getPosition());
					pCell->addChild(colorView,1);
				}
				
				if(item.armor.hero<=0)
				{
					//记录库存
					m_iCountEquipStock++;
				}
			}
			
			bgImg->setTouchEnabled(true);
			bgImg->setUserData(m_itemList.at(uIdx));
			bgImg->setOnClickListener(this,ccw_click_selector(CStrengthenItem::onTouchItem));
		}
		else if (i==2)
		{
			((CButton*)child)->setEnabled(false);
			CCSprite *mask = CCSprite::createWithTexture(setItemQualityTexture(item.quality));
			mask->setPosition(ccp(child->getContentSize().width/2,child->getContentSize().height/2));
			child->addChild(mask, 10);

			CCSprite *prop = CCSprite::create(GetImageName(1, item.quality, item.iconId).c_str());
			if (!prop)
			{
				prop = CImageView::create("prop/32003.png");
			}
			prop->setPosition(ccp(child->getContentSize().width/2,child->getContentSize().height/2));
			child->addChild(prop);

			//添加星星
			CLayout* pStarLayout = getStarLayout(item.iStar);
			child->addChild(pStarLayout, 10);
		}
		else if (i==3)
		{
			CLabel *label = (CLabel*)child;
			if(itemData)
			{
				label->setString(itemData->itemName.c_str());
			}
		}
		else if (i==4)
		{
			CLabel *label = (CLabel*)child;
			
			if (item.itemLevel==0)
			{
				label->removeFromParent();
			}
			else
			{
				label->setString(CCString::createWithFormat("+%d",item.itemLevel)->getCString());
				label->setPositionX(pCell->getChildByTag(3)->getPositionX()+pCell->getChildByTag(3)->getContentSize().width+10);
			}
		}
		else if (i==5)
		{
			CLabel *label = (CLabel*)child;
			if (item.itemLevel==0)
			{
				label->setVisible(false);
			}
			else
			{
				label->setVisible(true);
				//if (item.itemLevel==item.armor.strenLv)
				//{
				//	label->setString(CCString::createWithFormat("Lv.%s",GETLANGSTR(229))->getCString());
				//}
				//else
				//{
				//	label->setString(CCString::createWithFormat("Lv.%d",item.itemLevel)->getCString());
				//}
				label->setString(CCString::createWithFormat("+%d",item.itemLevel)->getCString());
			}
		}
		else if (i==6)
		{
			CCSprite *head = (CCSprite*)child;
			if (item.armor.hero>0)
			{
				CCSprite *img = CCSprite::create(getImageName(&item.armor).c_str());
				if(!img)
				{
					img = CCSprite::create("headIcon/101.png");
					CCLOG("ERROR CStrengthenItem::addTableCell");
				}

				CCSprite *mask = (CCSprite*) lay->getChildByTag(7);
				lay->removeChild(mask);
				pCell->addChild(mask);

				img->setScale(0.53f);
				img->setPosition(ccp(head->getContentSize().width/2,head->getContentSize().height/2+14));
				head->addChild(img);
			}
			else
			{
				pCell->removeChild(child);
			}
		}
		else if (i==7)
		{
			pCell->removeChild(child);
		}
		else if (i==8)
		{
			child->setVisible(item.stren);
		}
		else if(i==9)
		{
			if (item.itemLevel==0)
			{
				child->setVisible(false);
			}
			else
			{
				child->setVisible(true);
			}
		}
		else if( i ==10)
		{
			CCNode* pCombatTip = (CCNode*)child;
			pCombatTip->setVisible(item.armor.armorType != 5);
		}
		else if (i==11)
		{
			CLabelAtlas* pLabel = (CLabelAtlas*)child;
			pLabel->setAnchorPoint(ccp(0, 0.5f));
			pLabel->setString(ToString(item.armor.combat));
			pLabel->setVisible(item.armor.armorType != 5);
		}
	}
}
Example #9
0
EFI_STATUS
EFIAPI
SetOptionsCallback (
  IN EFI_FORM_CALLBACK_PROTOCOL       *This,
  IN UINT16                           KeyValue,
  IN EFI_IFR_DATA_ARRAY               *Data,
  OUT EFI_HII_CALLBACK_PACKET         **Packet
  )
/*++

Routine Description:

  This is the function that is called to provide results data to the driver.  This data
  consists of a unique key which is used to identify what data is either being passed back
  or being asked for. 
  
  The callback function finish two main task: 
  1. Invoke the configuration protocol setoptions function according to user selection which
     is recorded by KeyValue.
  2. Collect all the available driver and controller infos to update the formset.
  
  
Arguments:

  KeyValue - A unique Goto OpCode callback value which record user's selection, 
                     In Set Options page, every item is associated to a goto IFR, and has a unique callback key.

  Data -         No use here.
  Packet-       No use here.
  
  Returns -    Always successful

--*/
{
  EFI_CALLBACK_INFO                         *Private;
  EFI_HII_UPDATE_DATA                       *UpdateData;
  
  EFI_STATUS                                Status;
  CHAR8                                     Language[4]; 
  CHAR16                                    Lang[4];
  UINTN                                     LangSize;
  
  UINTN                                     Index;   
  UINTN                                     ChoiceIndex;
  UINT8                                     *Location;
  
  UINTN                                     DriverImageHandleCount;
  EFI_HANDLE                                *DriverImageHandleBuffer;
  
  EFI_DRIVER_CONFIGURATION_PROTOCOL         *DriverConfiguration;
  EFI_DRIVER_BINDING_PROTOCOL               *DriverBinding;
  EFI_LOADED_IMAGE_PROTOCOL                 *LoadedImage;
#if (EFI_SPECIFICATION_VERSION >= 0x00020000)
  EFI_COMPONENT_NAME_PROTOCOL               *ComponentName;
#else
  EFI_COMPONENT_NAME2_PROTOCOL              *ComponentName;
#endif
  EFI_FORM_BROWSER_PROTOCOL                 *FormBrowser;
  
  EFI_DEVICE_PATH_PROTOCOL                  *DevicePath;
  UINTN                                     ControllerHandleIndex;
  CHAR16                                    *ControllerHandleName;  
  BOOLEAN                                   FreeControllerHandleName;
  UINTN                                     ControllerHandleCount;
  EFI_HANDLE                                *ControllerHandleBuffer;

  UINTN                                     ChildControllerHandleIndex;
  CHAR16                                    *ChildControllerHandleName;
  BOOLEAN                                   FreeChildControllerHandleName;
  UINTN                                     ChildControllerHandleCount;
  EFI_HANDLE                                *ChildControllerHandleBuffer;

  CHAR16                                    *NewString;
  STRING_REF                                NewStringToken;
  CHAR16                                    *DriverName;
  BOOLEAN                                   FreeDriverName;

  EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED  ActionRequired;
  
  
  Private     = EFI_CALLBACK_INFO_FROM_THIS (This);

  //
  // Get current language to set options
  //
  LangSize = 0x3;
  Status = gRT->GetVariable (
              L"Lang",
              &gEfiGlobalVariableGuid,
              NULL,
              &LangSize,
              Language
              );

  ASSERT_EFI_ERROR (Status);
  
  Status = GetCurrentLanguage (Lang);
  ASSERT_EFI_ERROR (Status);
  //
  // Tast1:  Invoke the configuration protocol setoptions function according to user selection.
  // KeyValue between 0x100~0x200 means user select a driver or device item in 'Set Options'  dynamic page
  //
  if ((0x100 <= KeyValue) && (KeyValue <= 0x200)) {
  
    ChoiceIndex = KeyValue - 0x100;
    ActionRequired = 0;
    
    //
    // There should only be one Form Configuration protocol
    //
    Status = gBS->LocateProtocol (
                    &gEfiFormBrowserProtocolGuid, 
                    NULL, 
                    &FormBrowser
                    );
    ASSERT_EFI_ERROR (Status);
    
    //
    // Invoke the user selceted item's SetOptions function with corresponding driver or device handles 
    //
    gST->ConOut->ClearScreen (gST->ConOut);
    mChoice[ChoiceIndex].DriverConfiguration->SetOptions (
                                              mChoice[ChoiceIndex].DriverConfiguration,
                                              mChoice[ChoiceIndex].ControllerHandle,
                                              mChoice[ChoiceIndex].ChildControllerHandle,
                                              Language,
                                              &ActionRequired
                                              );
    gST->ConOut->ClearScreen (gST->ConOut);
    
    //
    // Notify user the action required after SetOptions function finish, and do the action according to user intent
    //
    Status = ProcessActionRequired (
                FormBrowser,
                Private,
                ActionRequired,
                mChoice[ChoiceIndex].DriverImageHandle,
                mChoice[ChoiceIndex].ControllerHandle,
                mChoice[ChoiceIndex].ChildControllerHandle
                );
    gST->ConOut->ClearScreen (gST->ConOut);
    
  }
  
  //
  // Task 2: Collect all the available driver infos and update the formset.
  // The available driver is those drivers which install efi driver configuration protocol
  //

  //
  // Allocate memory to Update form
  //
  DriverImageHandleBuffer = NULL;
  ControllerHandleBuffer = NULL;
  ChildControllerHandleBuffer = NULL;
  UpdateData = NULL;
  UpdateData = EfiLibAllocateZeroPool (UPDATE_DATA_SIZE);  
  ASSERT (UpdateData != NULL);
  //
  // Clear all the content in dynamic page 
  //  
  UpdateData->FormSetUpdate       = FALSE;
  UpdateData->FormCallbackHandle  = 0;
  UpdateData->FormUpdate          = FALSE;
  UpdateData->FormTitle           = 0;
  UpdateData->DataCount           = 0xff;
  UpdateData->Data                = NULL;

  Private->Hii->UpdateForm (
                  Private->Hii,
                  Private->RegisteredHandle,
                  (EFI_FORM_LABEL) 0x1234,  // Label 0x1234
                  FALSE,                    // Remove Op-codes (will never remove form/endform)
                  UpdateData                // Significant value is UpdateData->DataCount
                  );
  //
  // When user enter the page at first time, the 'first refresh' string is given to notify user to refresh all the drivers,
  // then the 'first refresh' string will be replaced by the 'refresh' string, and the two strings content are  same after the replacement
  //
  NewStringToken = (STRING_REF) STR_FIRST_REFRESH;
  NewString = GetString (Private, (STRING_REF) STR_REFRESH);
  ASSERT (NewString != NULL);
  Status = Private->Hii->NewString (Private->Hii, Lang, Private->RegisteredHandle, &NewStringToken, NewString);
  ASSERT_EFI_ERROR (Status); 
  gBS->FreePool (NewString);
  
  NewStringToken = (STRING_REF) STR_FIRST_REFRESH_HELP;
  NewString = GetString (Private, (STRING_REF) STR_REFRESH_HELP);
  ASSERT (NewString != NULL);
  Status = Private->Hii->NewString (Private->Hii, Lang, Private->RegisteredHandle, &NewStringToken, NewString);
  ASSERT_EFI_ERROR (Status); 
  gBS->FreePool (NewString); 

  //
  // Get all drivers handles which has configuration protocol
  //
  DriverImageHandleCount  = 0;
  Status = gBS->LocateHandleBuffer (
                  ByProtocol,
                  &gEfiDriverConfigurationProtocolGuid,
                  NULL,
                  &DriverImageHandleCount,
                  &DriverImageHandleBuffer
                  );       

  //
  // Scan every driver image handle to get its and its managed device and child device info, 
  // including Component name/image name/device handle and so on. Create and associate a item
  // in Set Option page to very driver and its managed device and  child device
  //
  ChoiceIndex = 0; // Item index in Set Option page 
  for (Index = 0; (Index < DriverImageHandleCount) && (ChoiceIndex < MAX_CHOICE_NUM); Index++) {
    //
    // step1 : get the driver info
    //
    DriverConfiguration = NULL;
    Status = gBS->OpenProtocol (
                    DriverImageHandleBuffer[Index],
                    &gEfiDriverConfigurationProtocolGuid,
                    (VOID **) &DriverConfiguration,
                    NULL,
                    NULL,
                    EFI_OPEN_PROTOCOL_GET_PROTOCOL
                    );
    ASSERT_EFI_ERROR (Status);
    
    DriverBinding =NULL;
    Status = gBS->OpenProtocol (
                    DriverImageHandleBuffer[Index],
                    &gEfiDriverBindingProtocolGuid,
                    (VOID **) &DriverBinding,
                    NULL,
                    NULL,
                    EFI_OPEN_PROTOCOL_GET_PROTOCOL
                    );
    if (EFI_ERROR (Status)) {
      continue;
    } 

    LoadedImage = NULL;
    Status = gBS->OpenProtocol (
                    DriverBinding->ImageHandle,
                    &gEfiLoadedImageProtocolGuid,
                    (VOID **) &LoadedImage,
                    NULL,
                    NULL,
                    EFI_OPEN_PROTOCOL_GET_PROTOCOL
                    );
    if (EFI_ERROR (Status)) {
      LoadedImage = NULL;
    }

    ComponentName  = NULL;
    Status = gBS->OpenProtocol (
                    DriverBinding->ImageHandle,
#if (EFI_SPECIFICATION_VERSION >= 0x00020000)
                    &gEfiComponentName2ProtocolGuid,
#else
                    &gEfiComponentNameProtocolGuid,
#endif
                    (VOID **) &ComponentName,
                    NULL,
                    NULL,
                    EFI_OPEN_PROTOCOL_GET_PROTOCOL
                    );
    if (EFI_ERROR(Status)) {
      return EFI_UNSUPPORTED;
    }

    //
    // Get the driver name
    // First try to get its component name, if fail, get its image name then 
    //
    Status = EFI_UNSUPPORTED;
    DriverName = NULL;
    FreeDriverName = FALSE;
    if ((ComponentName != NULL) && (ComponentName->GetDriverName != NULL)) {
      Status = ComponentName->GetDriverName (
                                ComponentName,
                                Language,
                                &DriverName
                                );
    }
    if (EFI_ERROR (Status) && (LoadedImage != NULL)) {
      DriverName = GetImageName (LoadedImage);
    }
    if (DriverName == NULL) {
      DriverName = GetString (Private, (STRING_REF) STR_DRIVER_DEFAULT_NAME);
      ASSERT (DriverName != NULL);
      FreeDriverName = TRUE;  // the DriverName string need to free pool
    }
    //
    // Create a item for the driver in set options page
    // Clear the Update buffer 
    //
    UpdateData->FormSetUpdate       = FALSE;
    UpdateData->FormCallbackHandle  = 0;
    UpdateData->FormUpdate          = FALSE;
    UpdateData->FormTitle           = 0;
    UpdateData->DataCount           = 0;
    Location = (UINT8 *) &UpdateData->Data;
    //
    // Export the driver name string and create item in set options page
    //
    NewString = EfiLibAllocateZeroPool (EfiStrSize (DriverName) + EfiStrSize (L" |-"));
    EfiStrCat (NewString, L" |-");
    EfiStrCat (NewString, DriverName);
    NewStringToken = mChoice[ChoiceIndex].DescriptionToken;
    Status = Private->Hii->NewString (Private->Hii, NULL, Private->RegisteredHandle, &NewStringToken, NewString);
    ASSERT_EFI_ERROR (Status);
    gBS->FreePool (NewString); 
    if (FreeDriverName) {
      gBS->FreePool (DriverName);
    }
    
    CreateGotoOpCode (
      0x1234,                       
      NewStringToken,               // Description String Token
      STR_GOTO_HELP_DRIVER,         // Description Help String Token
      EFI_IFR_FLAG_INTERACTIVE,     // Flag designating callback is active
      (UINT16) ChoiceIndex + 0x100, // Callback key value
      Location                      // Buffer to fill with op-code
      );
    //
    // Update the buffer items number and adjust next item address to new one
    //
    UpdateData->DataCount +=1 ;
    Location = Location + ((EFI_IFR_OP_HEADER *) Location)->Length;
    //
    // Associate callback key with  setoptions function related parameters to used by Task 1
    //
    mChoice[ChoiceIndex].DriverImageHandle = DriverImageHandleBuffer[Index];
    mChoice[ChoiceIndex].DriverConfiguration = DriverConfiguration;
    mChoice[ChoiceIndex].ControllerHandle = NULL;
    mChoice[ChoiceIndex].ChildControllerHandle = NULL;
    mChoice[ChoiceIndex].DescriptionToken = NewStringToken;
    ChoiceIndex++;    
    
    //
    // step2 : get the driver direct managed device info
    //
    
    //
    // Get the driver all direct managed devices handles
    //
    Status = GetDeviceHandlesManagedByDriver (
              DriverImageHandleBuffer[Index],
              &ControllerHandleCount,           // Get managed devices count
              &ControllerHandleBuffer           // return all handles in buffer
              );
    if (ControllerHandleBuffer == NULL) {
      continue;
    }
    
    for (ControllerHandleIndex = 0; ControllerHandleIndex < ControllerHandleCount; ControllerHandleIndex++) {
      //
      // Get the  managed device name
      // First try to get its component name, if fail, get its device path then 
      // The component name string need not free pool, but the device path string and default string need safe free pool after export the string to Hii database
      //
      FreeControllerHandleName = FALSE;
      ControllerHandleName = NULL;
      Status = EFI_UNSUPPORTED;
      if ((ComponentName != NULL) && (ComponentName->GetControllerName != NULL)) {
        Status = ComponentName->GetControllerName (
                                  ComponentName,
                                  ControllerHandleBuffer[ControllerHandleIndex],
                                  NULL,
                                  Language,
                                  &ControllerHandleName
                                  );
      }
      if (EFI_ERROR (Status)) {
        Status = gBS->OpenProtocol (
                        ControllerHandleBuffer[ControllerHandleIndex],
                        &gEfiDevicePathProtocolGuid,
                        (VOID **) &DevicePath,
                        NULL,
                        NULL,
                        EFI_OPEN_PROTOCOL_GET_PROTOCOL
                        );
        if (!EFI_ERROR (Status)) {
          ControllerHandleName = DevicePathToStr ( DevicePath );
          FreeControllerHandleName = TRUE; // the Controller Handle Name string need to free pool
        }
      }
      if (ControllerHandleName == NULL) {
        ControllerHandleName = GetString (Private, (STRING_REF) STR_DRIVER_CONTROLLER_DEFAULT_NAME);
        ASSERT (ControllerHandleName != NULL);
        FreeControllerHandleName = TRUE;  // the Controller Handle Name string need to free pool
      }
      //
      // do some alignment for NewString if needed
      //
      AlignmentItem (ControllerHandleName, L"   |-", &NewString);
      
      NewStringToken = mChoice[ChoiceIndex].DescriptionToken;
      Private->Hii->NewString (
                          Private->Hii,
                          NULL, 
                          Private->RegisteredHandle, 
                          &NewStringToken, 
                          NewString
                          );
      gBS->FreePool (NewString); 
      if (FreeControllerHandleName) {
        gBS->FreePool (ControllerHandleName);      
      }
      
      CreateGotoOpCode (
        0x1234,                 
        NewStringToken,                     // Description String Token
        STR_GOTO_HELP_DEVICE,               // Description Help String Token
        EFI_IFR_FLAG_INTERACTIVE,           // Flag designating callback is active
        (UINT16) ChoiceIndex + 0x100,       // Callback key value
        Location                            // Buffer to fill with op-code
        );
      //
      // Update the buffer items number and adjust next item address to new one
      //
      UpdateData->DataCount +=1 ;
      Location = Location + ((EFI_IFR_OP_HEADER *) Location)->Length;
      //
      // Associate callback key with  setoptions function related parameters to used by Task 1
      //
      mChoice[ChoiceIndex].DriverImageHandle = DriverImageHandleBuffer[Index];
      mChoice[ChoiceIndex].DriverConfiguration = DriverConfiguration;
      mChoice[ChoiceIndex].ControllerHandle = ControllerHandleBuffer[ControllerHandleIndex];
      mChoice[ChoiceIndex].ChildControllerHandle = NULL;
      mChoice[ChoiceIndex].DescriptionToken = NewStringToken;
      ChoiceIndex++;
      
      //
      // step3 : get the infos of child devices created by the driver
      //
      Status = GetChildDeviceHandlesManagedByDriver (
                DriverImageHandleBuffer[Index],
                ControllerHandleBuffer[ControllerHandleIndex],
                &ChildControllerHandleCount,      // Get managed devices count
                &ChildControllerHandleBuffer      // return all handles in buffer
                );

      for (ChildControllerHandleIndex = 0; ChildControllerHandleIndex < ChildControllerHandleCount; ChildControllerHandleIndex++) {
        //
        // Get the  managed child device name
        // First try to get its component name, if fail, get its device path then 
        // The component name string need not free pool, but the device path string  need safe free pool after export the string to Hii database
        //
        FreeChildControllerHandleName = FALSE;
        ChildControllerHandleName = NULL;
        Status = EFI_UNSUPPORTED;
        if ((ComponentName != NULL) && (ComponentName->GetDriverName != NULL)) {
          Status = ComponentName->GetControllerName (
                                    ComponentName,
                                    ControllerHandleBuffer[ControllerHandleIndex],
                                    ChildControllerHandleBuffer[ChildControllerHandleIndex],
                                    Language,
                                    &ChildControllerHandleName
                                    );
        }
        if (EFI_ERROR (Status)) {
          Status = gBS->OpenProtocol (
                          ChildControllerHandleBuffer[ChildControllerHandleIndex],
                          &gEfiDevicePathProtocolGuid,
                          (VOID **) &DevicePath,
                          NULL,
                          NULL,
                          EFI_OPEN_PROTOCOL_GET_PROTOCOL
                          );
          if (!EFI_ERROR (Status)) {
            ChildControllerHandleName = DevicePathToStr ( DevicePath );
            FreeChildControllerHandleName = TRUE; // the Child Controller Handle Name string need to free pool
          }
        } 
        if (ChildControllerHandleName == NULL) {
          ChildControllerHandleName = GetString (Private, (STRING_REF) STR_DRIVER_CHILD_CONTROLLER_DEFAULT_NAME);
          ASSERT (ChildControllerHandleName != NULL);
          FreeChildControllerHandleName = TRUE;  // the Controller Handle Name string need to free pool
        }

        //
        // do some alignment for NewString if needed
        //
        AlignmentItem (ChildControllerHandleName, L"     |--", &NewString);
        
        NewStringToken = mChoice[ChoiceIndex].DescriptionToken;
        Private->Hii->NewString ( 
                            Private->Hii,
                            NULL, 
                            Private->RegisteredHandle, 
                            &NewStringToken, 
                            NewString
                            );
        gBS->FreePool (NewString); 
        if (FreeChildControllerHandleName) {
          gBS->FreePool (ChildControllerHandleName);      
        }
        CreateGotoOpCode (
          0x1234,                 
          NewStringToken,                          // Description String Token
          STR_GOTO_HELP_CHILD_DEVICE,              // Description Help String Token
          EFI_IFR_FLAG_INTERACTIVE,                // Flag designating callback is active
          (UINT16) ChoiceIndex + 0x100,            // Callback key value
          Location                                 // Buffer to fill with op-code
          );
        //
        // Update the buffer items number and adjust next item address to new one
        //
        UpdateData->DataCount +=1 ;
        Location = Location + ((EFI_IFR_OP_HEADER *) Location)->Length;
        //
        // Associate callback key with  setoptions function related parameters to used by Task 1
        //
        mChoice[ChoiceIndex].DriverImageHandle = DriverImageHandleBuffer[Index];
        mChoice[ChoiceIndex].DriverConfiguration = DriverConfiguration;
        mChoice[ChoiceIndex].ControllerHandle = ControllerHandleBuffer[ControllerHandleIndex];
        mChoice[ChoiceIndex].ChildControllerHandle = ChildControllerHandleBuffer[ChildControllerHandleIndex];
        mChoice[ChoiceIndex].DescriptionToken = NewStringToken;
        ChoiceIndex++;
      }
      if (ChildControllerHandleBuffer != NULL) {
        gBS->FreePool (ChildControllerHandleBuffer);
      }
    }

    //
    // Update Set Option page form
    //
    Private->Hii->UpdateForm (
                    Private->Hii,
                    Private->RegisteredHandle,
                    (EFI_FORM_LABEL) 0x1234,
                    TRUE,
                    UpdateData
                    );    

    if (ControllerHandleBuffer != NULL) {
      gBS->FreePool (ControllerHandleBuffer);
    }
    
  }
  
  gBS->FreePool (UpdateData);  
  
  if (DriverImageHandleBuffer != NULL) {
    gBS->FreePool (DriverImageHandleBuffer);
  }

  return EFI_SUCCESS;
}
Example #10
0
PVOID
DllLoaded(
    IN HANDLE Process,
    IN HANDLE Thread,
    IN LPLOAD_DLL_DEBUG_INFO LoadDll,
    IN HANDLE OutputWindow
)
/*++

Routine Description:

    This routine puts the loaded dll into the list

Arguments:

    ProcessId -- Supplies the id of the process this dll was loaded for
    ThreadId -- Supplies the id of the thread this dll was loaded for
    LoadDll -- Supplies the information about the dll that was loaded

Return Value:

    None.

--*/
{
    PLOADED_DLL Dll;
    PUCHAR ImageName;
    HANDLE SectionHandle;
    PVOID ImageBase;
    BOOL Success;
    UCHAR StringBuffer[256];

    //
    // Inialize if we haven't already
    //
    if (!Initialized) {
        InitializeCriticalSection(
            &DllListCriticalSection
        );
        Initialized = TRUE;
    }

    //
    // Map the image into our address space for name and symbols
    //

    ImageBase = MapImage(
                    LoadDll->hFile,
                    &SectionHandle
                );

    if (!ImageBase) {
        printf("Sprof: could not map image to get name and symbols.\n");
        printf(
            "Sprof: Dll at %lx will be profiled without symbols\n",
            LoadDll->lpBaseOfDll
        );
    }

    //
    // Get the name of the Image
    //

    ImageName = GetImageName(ImageBase);

    if (!ImageName) {
        printf("Sprof: could not get image name.\n");
    }

    //
    // Allocate a structure for the new dll
    //

    Dll = malloc(sizeof(LOADED_DLL));

    //
    // Initialize the structure for the new dll
    //

    memset(Dll,0,sizeof(LOADED_DLL));
    Dll->DllInfo = *LoadDll;
    Dll->FileMapping = SectionHandle;
    Dll->BaseOfMapping = ImageBase;
    Dll->ImageName = ImageName;
    Dll->OffsetOfCode = GetImageCodeBase(ImageBase);
    Dll->BaseOfCode = Dll->OffsetOfCode + (ULONG)(LoadDll->lpBaseOfDll);
    Dll->SizeOfCode = GetImageCodeSize(ImageBase);
    Dll->Process = Process;


    //
    // Put this dll into the list
    //

    Success = InsertDll(Dll);
    if (!Success) {
        printf(
            "Sprof: could not insert dll %s into loaded dll list\n",
            Dll->ImageName
        );
    }

    sprintf(StringBuffer,"%s loaded",ImageName);
    PrintToSprofWindow(OutputWindow,StringBuffer);

    return Dll;
}
Example #11
0
PVOID
CreateModule32(
    PVOID ModuleList,
    HANDLE Process,
    IN LPLOAD_DLL_DEBUG_INFO LoadDll,
    IN HANDLE OutputWindow
)
/*++

Routine Description:

    This routine creates a module 32 object and adds it to the module list

Arguments:

    ModuleList -- Supplies the module list
    Process -- Supplies the handle of the process this module is loaded for
    LoadDll -- Supplies the debug info on the dll
    OutputWindow -- Supplies a handle to a window to output to

Return Value:

    Pointer to a 32 bit module

--*/
{
    PUCHAR ImageName;
    HANDLE SectionHandle;
    PVOID ImageBase;
    MODULE32 Module;
    UCHAR StringBuffer[256];

    if ((ModuleList == NULL) || (LoadDll == NULL)) {
        return NULL;
    }

    //
    // Map the image into our address space for name and symbols
    //

    ImageBase = MapImage(
                    LoadDll->hFile,
                    &SectionHandle
                );

    if (!ImageBase) {
        printf("Sprof: could not map image to get name and symbols.\n");
        printf(
            "Sprof: Dll at %lx will be profiled without symbols\n",
            LoadDll->lpBaseOfDll
        );
    }

    //
    // Get the name of the Image
    //

    ImageName = GetImageName(ImageBase);

    if (!ImageName) {
        printf("Sprof: could not get image name.\n");
    }

    memset(&Module,0,sizeof(MODULE32));
    Module.FileHandle = LoadDll->hFile;
    Module.FileMapping = SectionHandle;
    Module.BaseOfMapping = ImageBase;
    Module.ImageName = ImageName;
    Module.BaseOfImage = LoadDll->lpBaseOfDll;
    Module.OffsetOfCode = GetImageCodeBase(ImageBase);
    Module.BaseOfCode = Module.OffsetOfCode + (ULONG)Module.BaseOfImage;
    Module.SizeOfCode = GetImageCodeSize(ImageBase);
    Module.Process = Process;
    Module.ReferenceCount = 1;

    // bugbug errrors in insert
    sprintf(StringBuffer,"%s loaded",ImageName);
    PrintToSprofWindow(OutputWindow,StringBuffer);

    return InsertDataInList(ModuleList, &Module);

}
Example #12
0
EFI_STATUS
EFIAPI
UpdateBindingDriverSelectPage (
    IN EFI_CALLBACK_INFO                *Private,
    IN UINT16                           KeyValue,
    IN EFI_IFR_DATA_ARRAY               *Data
)
/*++

Routine Description:
  Prepare to let user select the drivers which need mapping with the device controller selected in first page

Arguments:

  KeyValue - The callback key value of device controller item in first page
  Data -         EFI_IFR_DATA_ARRAY data.
  Packet-       No use here.

  Returns -    Always successful

--*/
{
    EFI_HII_UPDATE_DATA                       *UpdateData;
    EFI_STATUS                                Status;
    UINTN                                     Index;
    UINT8                                     *Location;

    CHAR16                                    *NewString;
    STRING_REF                                NewStringToken;
    STRING_REF                                NewStringHelpToken;
    UINTN                                     DriverImageHandleCount;

    EFI_DRIVER_BINDING_PROTOCOL               *DriverBindingInterface;
    EFI_LOADED_IMAGE_PROTOCOL                 *LoadedImage;
    CHAR16                                    *DriverName;
    BOOLEAN                                   FreeDriverName;

    EFI_DEVICE_PATH_PROTOCOL                  *LoadedImageHandleDevicePath;
    EFI_DEVICE_PATH_PROTOCOL                  *TatalFilePath;
    EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *BusSpecificDriverOverride;
    EFI_HANDLE                                DriverBindingHandle;
    //
    // If user select a controller item in the first page  the following code will be run.
    // During second page, user will see all currnet driver bind protocol driver, the driver name and its device path will be shown
    //
    //First acquire the list of Loaded Image Protocols, and then when  want the name of the driver, look up all the Driver Binding Protocols
    // and find the first one whose ImageHandle field matches the image handle of the Loaded Image Protocol.
    // then use the Component Name Protocol on the same handle as the first matching Driver Binding Protocol to look up the name of the driver.
    //


    mCurrentPage = 0x02;
    //
    // Switch the item callback key value to its NO. in mDevicePathHandleBuffer
    //
    mSelectedCtrIndex = KeyValue - 0x100;
    ASSERT (0 <= mSelectedCtrIndex < MAX_CHOICE_NUM);
    mLastSavedDriverImageNum = 0;
    //
    // Clear all the content in dynamic page
    //
    UpdateData = NULL;
    UpdateData = EfiLibAllocateZeroPool (UPDATE_DATA_SIZE);
    ASSERT (UpdateData != NULL);

    UpdateData->FormSetUpdate       = FALSE;
    UpdateData->FormCallbackHandle  = 0;
    UpdateData->FormUpdate          = FALSE;
    UpdateData->FormTitle           = 0;
    UpdateData->DataCount           = 0xff;
    UpdateData->Data                = NULL;

    Private->Hii->UpdateForm (
        Private->Hii,
        Private->RegisteredHandle,
        (EFI_FORM_LABEL) 0x1200,  // Label 0x1234
        FALSE,                    // Remove Op-codes (will never remove form/endform)
        UpdateData                // Significant value is UpdateData->DataCount
    );

    //
    // Show all driver which support loaded image protocol in second page
    //
    DriverImageHandleCount  = 0;
    Status = gBS->LocateHandleBuffer (
                 ByProtocol,
                 &gEfiLoadedImageProtocolGuid,
                 NULL,
                 &DriverImageHandleCount,
                 &mDriverImageHandleBuffer
             );
    if (EFI_ERROR (Status) || (DriverImageHandleCount == 0)) {
        return EFI_NOT_FOUND;
    }

    mDriverImageHandleCount = DriverImageHandleCount;
    for (Index = 0; Index < DriverImageHandleCount; Index++) {
        //
        // Step1: Get the driver image total file path for help string and the driver name.
        //

        //
        // Find driver's Loaded Image protocol
        //
        LoadedImage =NULL;
        Status = gBS->OpenProtocol (
                     mDriverImageHandleBuffer[Index],
                     &gEfiLoadedImageProtocolGuid,
                     (VOID **) &LoadedImage,
                     NULL,
                     NULL,
                     EFI_OPEN_PROTOCOL_GET_PROTOCOL
                 );
        if (EFI_ERROR (Status)) {
            ((MyIfrNVData *) Data->NvRamMap)->DriSelection[Index] = 0;
            continue;
        }
        mDriverImageProtocol[Index] = LoadedImage;
        //
        // Find its related driver binding protocol
        //
        DriverBindingInterface = NULL;
        DriverBindingHandle = NULL;
        DriverBindingInterface = LibGetBindingProtocolFromImageHandle (
                                     mDriverImageHandleBuffer[Index],
                                     &DriverBindingHandle
                                 );
        if (DriverBindingInterface == NULL) {
            ((MyIfrNVData *) Data->NvRamMap)->DriSelection[Index] = 0;
            continue;
        }

        //
        // Get the driver image total file path for help string
        //
        LoadedImageHandleDevicePath = NULL;
        Status = gBS->HandleProtocol (
                     LoadedImage->DeviceHandle,
                     &gEfiDevicePathProtocolGuid,
                     &LoadedImageHandleDevicePath
                 );
        if (EFI_ERROR (Status)) {
            ((MyIfrNVData *) Data->NvRamMap)->DriSelection[Index] = 0;
            continue;
        }

        if (((MyIfrNVData *) Data->NvRamMap)->PciDeviceFilter == 0x01) {
            //
            // only care the driver which is in a Pci device option rom,
            // and the driver's LoadedImage->DeviceHandle must point to a pci device which has efi option rom
            //
            if (!EFI_ERROR (Status)) {
                Status = gBS->HandleProtocol(
                             LoadedImage->DeviceHandle,
                             &gEfiBusSpecificDriverOverrideProtocolGuid,
                             &BusSpecificDriverOverride
                         );
                if (EFI_ERROR (Status) || BusSpecificDriverOverride == NULL) {
                    ((MyIfrNVData *) Data->NvRamMap)->DriSelection[Index] = 0;
                    continue;
                }
            } else {
                ((MyIfrNVData *) Data->NvRamMap)->DriSelection[Index] = 0;
                continue;
            }
        }

        TatalFilePath = NULL;
        TatalFilePath = EfiAppendDevicePath (LoadedImageHandleDevicePath, LoadedImage->FilePath);

        //
        // For driver name, try to get its component name, if fail, get its image name,
        // if also fail, give a default name.
        //
        FreeDriverName = FALSE;
        DriverName = GetComponentName (DriverBindingHandle);
        if (DriverName == NULL) {
            //
            // get its image name
            //
            DriverName = GetImageName (LoadedImage);
        }
        if (DriverName == NULL) {
            //
            // give a default name
            //
            DriverName = GetString (Private, (STRING_REF) STR_DRIVER_DEFAULT_NAME);
            ASSERT (DriverName != NULL);
            FreeDriverName = TRUE;  // the DriverName string need to free pool
        }


        //
        // Step2 Export the driver name string and create check box item in second page
        //

        //
        // Clear the Update buffer
        //
        UpdateData->FormSetUpdate       = FALSE;
        UpdateData->FormCallbackHandle  = 0;
        UpdateData->FormUpdate          = FALSE;
        UpdateData->FormTitle           = 0;
        UpdateData->DataCount           = 0;
        Location = (UINT8 *) &UpdateData->Data;
        //
        // First create the driver image name
        //
        NewString = EfiLibAllocateZeroPool (EfiStrSize (DriverName));
        if (EFI_ERROR (LibCheckMapping (mControllerDevicePathProtocol[mSelectedCtrIndex], TatalFilePath, &mMappingDataBase, NULL, NULL))) {
            ((MyIfrNVData *) Data->NvRamMap)->DriSelection[Index] = 0x00;
        } else {
            ((MyIfrNVData *) Data->NvRamMap)->DriSelection[Index] = 0x01;
            mLastSavedDriverImageNum++;
        }
        EfiStrCat (NewString, DriverName);
        NewStringToken = mDriverImageToken[Index];
        Status = Private->Hii->NewString (Private->Hii, NULL, Private->RegisteredHandle, &NewStringToken, NewString);
        mDriverImageToken[Index] = NewStringToken;
        ASSERT_EFI_ERROR (Status);
        gBS->FreePool (NewString);
        if (FreeDriverName) {
            gBS->FreePool (DriverName);
        }

        //
        // Second create the driver image device path as item help string
        //
        if (TatalFilePath == NULL) {
            DriverName = EfiLibAllocateZeroPool (EfiStrSize (L"This driver device path and file path are both NULL! Maybe it is a Option Rom driver. Can not save it!"));
            EfiStrCat (DriverName, L"This driver device path and file path are both NULL! Maybe it is a Option Rom driver. Can not save it!");
        } else {
            DriverName = DevicePathToStr (TatalFilePath);
        }
        NewString = EfiLibAllocateZeroPool (EfiStrSize (DriverName));
        EfiStrCat (NewString, DriverName);
        NewStringHelpToken = mDriverImageFilePathToken[Index];
        Status = Private->Hii->NewString (Private->Hii, NULL, Private->RegisteredHandle, &NewStringHelpToken, NewString);
        mDriverImageFilePathToken[Index] = NewStringHelpToken;
        ASSERT_EFI_ERROR (Status);
        gBS->FreePool (NewString);
        gBS->FreePool (DriverName);

        CreateCheckBoxOpCode (
            (UINT16) (DRIVER_SELECTION_QUESTION_ID + Index),
            (UINT8) 1,
            NewStringToken,                               // Description String Token
            NewStringHelpToken,                           // Description Help String Token
            EFI_IFR_FLAG_INTERACTIVE,                     // Flag designating callback is active
            (UINT16) Index + 0x500,                       // Callback key value
            Location                                      // Buffer to fill with op-code
        );

        UpdateData->DataCount +=1 ;
        Location = Location + ((EFI_IFR_OP_HEADER *) Location)->Length;

        //
        // Update second page form
        //
        Private->Hii->UpdateForm (
            Private->Hii,
            Private->RegisteredHandle,
            (EFI_FORM_LABEL) 0x1200,
            TRUE,
            UpdateData
        );
    }
    gBS->FreePool (UpdateData);
    return EFI_SUCCESS;
}
Example #13
0
/////////////////////////////////////////////////////////////////////////////
// CFaceProcess message handlers
BOOL CFaceProcess::OnInitDialog(){
	// TODO: Add extra initialization here
	//调用基类函数
	CDialog::OnInitDialog();
	//获取当前要操作的路径和操作类型
      b_flagProcess= CStaticAssistant::GetEncryptFlag();
      path=CStaticAssistant::GetCurrentPath();
	/************************************************************************/
		 /* 根据功能标志b_flagProgress决定是否先训练人脸识别模型
		    如果是解密,就训练*/
	/************************************************************************/
	int i=1;
	CString   picName="";
	/*********加上存放相对路径*********************/
    CString   headPath="ImageLab/";
    char* pszStr=0;
	/*********如果是解密*********************/
    if(b_flagProcess==FALSE){             
	  while(i<needTrainNumber+1){
		 picName=GetImageName(path,i);
    /*********加上后缀名称*********************/
		 picName=headPath+picName+".pgm";
		 picName="11 "+picName;      //新训练默认为11号人脸
	     pszStr= picName.GetBuffer(picName.GetLength());
		 if(faceRecognitor.addFaceImgArray(pszStr,true,i)==true)
 			 i++;
	  }//while
   }//if
   /*********如果是解密,训练模型*********************/
   if(b_flagProcess==FALSE){  
	    GetDlgItem(IDC_STATIC_CORRECT)->EnableWindow(TRUE);//使控件有效
		faceRecognitor.learn();
   }
   GetDlgItem(IDC_OK)->EnableWindow(FALSE);//使控件无效
   /*********set icon*********************/
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
   /*********显示背景资源图片*********************/
	pwnd = GetDlgItem(IDC_SHOW_PIC);
	pwnd->MoveWindow(20,25,385,300);
    pDC =pwnd->GetDC();
	//pDC =GetDC();
    hDC= pDC->GetSafeHdc();
	pwnd->GetClientRect(&rect);
	CDC MemDC; 
	CBitmap m_Bitmap1;
	BOOL b=m_Bitmap1.LoadBitmap(IDB_BKGROUND);
	if(b==false)
		AfxMessageBox("加载背景图片失败");
	MemDC.CreateCompatibleDC(NULL);
	MemDC.SelectObject(&m_Bitmap1);
	
	//CClientDC dc(this); 
	pDC->StretchBlt(rect.left,rect.top,rect.Width(),rect.Height(),&MemDC,0,0,48,48,SRCCOPY);
	m_Bitmap1.DeleteObject();
	MemDC.DeleteDC();
	Invalidate();
	/************************************************************************/
	/* 根据功能设置控件状态                                                          */
	/************************************************************************/
	GetDlgItem(ID_CLOSE_CAPTURE)->EnableWindow(FALSE);//使控件无效
	GetDlgItem(IDC_RECOGNISE)->EnableWindow(FALSE);//使控件无效 
	GetDlgItem(IDC_STATIC_CORRECT)->EnableWindow(FALSE);//使控件无效
	GetDlgItem(IDC_STATIC_OTHER)->EnableWindow(FALSE);//使控件无效
	//GetDlgItem(IDC_STATIC_CORRECT)->EnableWindow(FALSE);//使控件无效
	GetDlgItem(IDC_SAVE_PIC)->EnableWindow(FALSE);//使控件无效
	/***********************设置显示初始值*********************/
	SetDlgItemText(IDC_STATIC_FRAME_COUNT,"无");
	SetDlgItemText(IDC_STATIC_Width,"无");
	SetDlgItemText(IDC_STATIC_HEIGHT,"无");
	SetDlgItemText(IDC_STATIC_FPS,"无");
	SetDlgItemText(IDC_STATIC_CORRECT,"无");
	SetDlgItemText(IDC_STATIC_OTHER,"无");
	/***********************初始化相关变量**********************/
	m_Video=0;
	b_Process=0;
	m_fameCount=0;
    m_vieoProtery=0;
	m_GrabFrame=0;
	m_SaveFrame=0;
	return  TRUE;
}
Example #14
0
BOOL  CFaceProcess::OnSavePic() 
{
	// TODO: Add your control notification handler code here
	KillTimer(timer);
	if (!m_Video){
// 	{AfxMessageBox("先打开摄像头"); return false; 	}
// 	m_GrabFrame=cvQueryFrame(m_Video);
// 	if (!m_GrabFrame)
// 	{AfxMessageBox("截取视屏帧失败,请重试!"); return false; 	}
	//static	char countsnap='1';
	if( !cvGrabFrame( m_Video))
		return FALSE;
	m_GrabFrame = cvRetrieveFrame(m_Video );
	if( !m_GrabFrame)
		return FALSE;
	if( !m_SaveFrame)
		m_SaveFrame = cvCreateImage( cvSize(m_GrabFrame->width,m_GrabFrame->height),
		IPL_DEPTH_8U, m_GrabFrame->nChannels );
	if( m_GrabFrame->origin == IPL_ORIGIN_TL )
		cvCopy( m_GrabFrame, m_SaveFrame, 0 );
	else
			cvFlip( m_GrabFrame, m_SaveFrame, 0 );
	}//if (!m_Video){
	static  int countsnap=1;
	CString   m_name1=GetImageName(path,countsnap);
	/*********加上后缀名称,加上存放相对路径*********************/
	CString   headPath="ImageLab/";
			  m_name1=headPath+m_name1+".pgm";
	const char* pszStr1 = m_name1.GetBuffer(m_name1.GetLength());
	//AfxMessageBox(m_name);
	IplImage * m_snap1=cvCreateImage(cvGetSize(m_SaveFrame),m_SaveFrame->depth,m_SaveFrame->nChannels);
	        cvCopy(m_SaveFrame,m_snap1,NULL);
	        //m_snap1->origin=1;//等于0保存倒立图向
	IplImage *faceImage1=0;
	IplImage *faceGray1=0;
	//检测人脸
	try{
    	if(faceDetector.detect_and_draw(m_snap1)){
	                  faceImage1=faceDetector.getFaceImage();
	                 // faceImage1->origin=1;
	                  //化简图片
	                  if(faceSimplifier.Simplify(faceImage1)){
	                           faceGray1=faceSimplifier.getFaceImage();
                               //faceGray1->origin=1;//等于0保存倒立图向
         	                   cvSaveImage(pszStr1,faceGray1);	//把图像写入文件
							   countsnap++;
					  }
		}
		SetTimer(timer,1,NULL) ;
	}catch(...)
	{
		SetTimer(timer,1,NULL) ;
        AfxMessageBox("保存图片失败--OnSavePic!!");
		return false;
	}
	if(countsnap>3)
			GetDlgItem(IDC_OK)->EnableWindow(TRUE);//使控件有效
	if(m_snap1)
		cvReleaseImage(&m_snap1);
    if(faceImage1)
		cvReleaseImage(&faceImage1);
	if(faceGray1)
		cvReleaseImage(&faceGray1);
	return true;
}
Example #15
0
void CPipeServer::Start(void)
{
	BYTE command;
	while (TRUE)
	{
		CreatePipeandWaitForconnect();

		try
		{
			while (TRUE)
			{
				command=ReadByte();

				switch(command)
				{
					case MONOCMD_INITMONO:
						InitMono();					
						break;	

					case MONOCMD_OBJECT_GETCLASS:
						Object_GetClass();
						break;

					case MONOCMD_ENUMDOMAINS:
						EnumDomains();
						break;

					case MONOCMD_SETCURRENTDOMAIN:
						SetCurrentDomain();
						break;

					case MONOCMD_ENUMASSEMBLIES:
						EnumAssemblies();
						break;

					case MONOCMD_GETIMAGEFROMASSEMBLY:
						GetImageFromAssembly();
						break;

					case MONOCMD_GETIMAGENAME:
						GetImageName();
						break;

					case MONOCMD_ENUMCLASSESINIMAGE:
						EnumClassesInImage();
						break;

					case MONOCMD_ENUMFIELDSINCLASS:
						EnumFieldsInClass();
						break;

					case MONOCMD_ENUMMETHODSINCLASS:
						EnumMethodsInClass();
						break;

					case MONOCMD_COMPILEMETHOD:
						CompileMethod();
						break;

					case MONOCMD_GETMETHODHEADER:
						GetMethodHeader();
						break;

					case MONOCMD_GETMETHODHEADER_CODE:
						GetILCode();
						break;

					case MONOCMD_LOOKUPRVA:
						RvaMap();
						break;

					case MONOCMD_GETJITINFO:
						GetJitInfo();
						break;

					case MONOCMD_FINDCLASS:
						FindClass();
						break;

					case MONOCMD_FINDMETHOD:
						FindMethod();
						break;

					case MONOCMD_GETMETHODNAME:
						GetMethodName();
						break;		

					case MONOCMD_GETMETHODCLASS:
						GetMethodClass();
						break;

					case MONOCMD_GETCLASSNAME:
						GetKlassName();
						break;

					case MONOCMD_GETCLASSNAMESPACE:
						GetClassNamespace();
						break;

					case MONOCMD_FREEMETHOD:
						FreeMethod();
						break;

					case MONOCMD_TERMINATE:												
						return;

					case MONOCMD_DISASSEMBLE:
						DisassembleMethod();
						break;

					case MONOCMD_GETMETHODSIGNATURE:
						GetMethodSignature();
						break;

					case MONOCMD_GETPARENTCLASS:
						GetParentClass();
						break;

					case MONOCMD_GETSTATICFIELDADDRESSFROMCLASS:
						GetStaticFieldAddressFromClass();
						break;
				}
			}			
		}
		catch (char *e)
		{
			//Pipe error, or something else that wasn't caught. Exit the connection and start over	
			OutputDebugStringA("Pipe error:\n");
			OutputDebugStringA(e);

			if (attached)
			{
				mono_thread_detach(mono_selfthread);
				attached=FALSE;
			}
			

		}
		catch (...)
		{
			OutputDebugStringA("Unexpected pipe error\n");
			if (attached)
			{
				mono_thread_detach(mono_selfthread);
				attached=FALSE;
			}	
		}

	}

}