STDMETHODIMP CSubPicAllocatorPresenterImpl::GetString(LPCSTR field, LPWSTR* value, int* chars)
{
    CheckPointer(value, E_POINTER);
    CheckPointer(chars, E_POINTER);
    CStringW ret = nullptr;

    if (!strcmp(field, "name")) {
        ret = L"MPC-HC";
    } else if (!strcmp(field, "version")) {
        ret = VersionInfo::GetVersionString();
    } else if (!strcmp(field, "yuvMatrix")) {
        ret = L"None";

        if (m_inputMediaType.IsValid() && m_inputMediaType.formattype == FORMAT_VideoInfo2) {
            VIDEOINFOHEADER2* pVIH2 = (VIDEOINFOHEADER2*)m_inputMediaType.pbFormat;

            if (pVIH2->dwControlFlags & AMCONTROL_COLORINFO_PRESENT) {
                DXVA2_ExtendedFormat& flags = (DXVA2_ExtendedFormat&)pVIH2->dwControlFlags;

                ret = (flags.NominalRange == DXVA2_NominalRange_Normal) ? L"PC." : L"TV.";

                switch (flags.VideoTransferMatrix) {
                    case DXVA2_VideoTransferMatrix_BT601:
                        ret.Append(L"601");
                        break;
                    case DXVA2_VideoTransferMatrix_BT709:
                        ret.Append(L"709");
                        break;
                    case DXVA2_VideoTransferMatrix_SMPTE240M:
                        ret.Append(L"240M");
                        break;
                    default:
                        ret = L"None";
                        break;
                }
            }
        }
    }

    if (!ret.IsEmpty()) {
        int len = ret.GetLength();
        size_t sz = (len + 1) * sizeof(WCHAR);
        LPWSTR buf = (LPWSTR)LocalAlloc(LPTR, sz);

        if (!buf) {
            return E_OUTOFMEMORY;
        }

        wcscpy_s(buf, len + 1, ret);
        *chars = len;
        *value = buf;

        return S_OK;
    }

    return E_INVALIDARG;
}
/*
 * Retrieve 'module dir path\firefox.exe'
 *
 * @aPathBuffer Buffer to fill
 */
static bool GetDesktopBrowserPath(CStringW& aPathBuffer)
{
  if (!GetModulePath(aPathBuffer))
    return false;

  // ceh.exe sits in dist/bin root with the desktop browser. Since this
  // is a firefox only component, this hardcoded filename is ok.
  aPathBuffer.Append(L"\\");
  aPathBuffer.Append(kFirefoxExe);
  return true;
}
  /*
   * Retrieve the target path if it is the default browser
   * or if not default, retreives the target path if it is a firefox browser
   * or if the target is not firefox, relies on a hack to get the
   * 'module dir path\firefox.exe'
   * The reason why it's not good to rely on the CEH path is because there is
   * no guarantee win8 will use the CEH at our expected path.  It has an in
   * memory cache even if the registry is updated for the CEH path.
   *
   * @aPathBuffer Buffer to fill
   */
  bool GetDesktopBrowserPath(CStringW& aPathBuffer)
  {
    // If the target was the default browser itself then return early.  Otherwise
    // rely on a hack to check CEH path and calculate it relative to it.

    if (mTargetIsDefaultBrowser || mTargetIsBrowser) {
      aPathBuffer = mTarget;
      return true;
    }

    if (!GetModulePath(aPathBuffer))
      return false;

    // ceh.exe sits in dist/bin root with the desktop browser. Since this
    // is a firefox only component, this hardcoded filename is ok.
    aPathBuffer.Append(L"\\");
    aPathBuffer.Append(kFirefoxExe);
    return true;
  }
Exemple #4
0
void GenTextFromPat(const STRARRAY &Pat, const STRARRAY &Var, CStringW &strOut)
{
	if (!Pat.empty() || Pat.size() % 2 != 1)
	{
		strOut.Empty();

		STRARRAY::const_iterator i = Pat.begin();
		strOut.Append(*i++);
		for (; i != Pat.end(); ++i)
		{
			BOOL bFile = FALSE;
			CStringW strCurVar = *i;
			if (strCurVar[0] == _T('f') || strCurVar[0] == _T('F'))
			{
				bFile = TRUE;
				strCurVar.Delete(0, 1);
			}
			UINT nNum = atoi(CStringA(strCurVar));
			if (nNum < Var.size())
			{
				if (bFile)
				{
					CStringW strFile;
					if (0 == LoadTextFile(CString(Var[nNum]),
						CODEPAGE_GB2312, strFile))
					{
						strOut.Append(strFile);
					}
				}
				else
				{
					strOut.Append(Var[nNum]);
				}
			}
			strOut.Append(*++i);
		}
	}
}
Exemple #5
0
void CCsvFile::WriteLine(const CStringArray & a)
{
	CStringW	line;

	for(int i = 0; i < a.GetCount(); i++)
	{
		if(a[i].Find(',') >= 0)
			line += _T("\"") + a[i] + _T("\"");
		else
			line += a[i];
		line.Append(_T(","));
	}
	line.TrimRight(',');
	WriteString(line);
	WriteString(_T("\n"));
}
Exemple #6
0
inline CStringW ZLStrConv::a2w(LPCSTR lpBuf, UINT uCodePage, int nBufLen)
{
    CStringW sRetW;
    int nDstLen = ::MultiByteToWideChar( uCodePage, 0, lpBuf, nBufLen, NULL, 0 );
    if (nDstLen > 0)
    {
        wchar_t* pResult = new wchar_t[nDstLen];
        BOOL bSuc = (0 < ::MultiByteToWideChar(uCodePage, 0, lpBuf, nBufLen, pResult, nDstLen));
        if (bSuc)
        {
            sRetW.Append(pResult, nDstLen - 1);
        }
        delete[] pResult;
    }
    return sRetW;
}
CStringW CConfigShortcuts::AssembleKeyString(int Mod, int Key)
{
	CAccelerator *pAccel = theApp.GetAccelerator();
	CStringW KeyStr;

	if (Mod & MOD_SHIFT) {
		KeyStr.Append(pAccel->GetVKeyName(VK_SHIFT));
		KeyStr.Append(L" + ");
	}

	if (Mod & MOD_CONTROL) {
		KeyStr.Append(pAccel->GetVKeyName(VK_CONTROL));
		KeyStr.Append(L" + ");
	}

	if (Mod & MOD_ALT) {
		KeyStr.Append(pAccel->GetVKeyName(VK_MENU));
		KeyStr.Append(L" + ");
	}

	KeyStr.Append(pAccel->GetVKeyName(Key));

	return KeyStr;
}
Exemple #8
0
int sproxy()
{
	unsigned __int64 nFlags;
	BOOL bHasInvalid;
	CStringW wszUrl;
	CStringW wszOut;
	CStringA szNamespace;
	wchar_t **argvW = NULL ;
	int argc = 0 ;

	argvW = CommandLineToArgvW(GetCommandLineW(),&argc);
	if(argvW == NULL)
	{
		EmitError(IDS_SDL_CMDLINE_FAILURE, GetLastError());
		return 1;
	}
	PreProcessCommandLine(argc, argvW, wszOut, szNamespace, &nFlags, &bHasInvalid);
	
	g_bUseWchar_t = ((nFlags & SPROXYFLAG_NOWCHAR_T) == 0);

	if ((nFlags & SPROXYFLAG_NOLOGO) == 0)
	{
		PrintHeader();
	}
	
	if (nFlags & SPROXYFLAG_USAGE)
	{
		PrintUsage(true);
		GlobalFree(argvW);
		return 0;
	}

	ParseCommandLine(argc, argvW, wszUrl, bHasInvalid);

	GlobalFree(argvW);	

	bHasInvalid = FALSE;
	if (wszUrl.IsEmpty())
	{
		EmitCmdLineError(IDS_SDL_MISSING_OPTION, nFlags & SPROXYFLAG_WSDLINPUT ?"<wsdl_location>":"<discomap_location>");
		bHasInvalid = TRUE;
	}

	if (bHasInvalid != FALSE)
	{
		printf("\r\n");
		PrintUsage();
		return 1;
	}

	if (nFlags & SPROXYFLAG_NOWARN)
	{
		SetEmitWarnings(false);
	}

	CHeapPtr<char> spSzNamespace;

	if (szNamespace && *szNamespace)
	{
		if (FAILED(CreateSafeCppName(&spSzNamespace, szNamespace)))
		{
			EmitErrorHr(E_OUTOFMEMORY);
			return 1;
		}
	}

	CoInitialize(NULL);
	HRESULT hr = S_OK;
	{
		CAutoPtr<CDiscoMapParser> dmParser;
		if(!(nFlags & SPROXYFLAG_WSDLINPUT))
		{
			CComPtr<ISAXXMLReader> spDMReader;
			hr = CoCreateInstance(__uuidof(SAXXMLReader30), NULL, CLSCTX_ALL,
				__uuidof(ISAXXMLReader), (void **)&spDMReader);

			if (FAILED(hr))
			{
				ATLTRACE( _T("CoCreateInstance failed!\n") );
				return 1;
			}

			dmParser.Attach(new CDiscoMapParser(spDMReader, NULL, 0));
			if(dmParser == NULL)
			{
				ATLTRACE(_T("Failed to create Discomap Parser : out of memory!\n"));
				return 1;
			}
			dmParser->SetDynamicAlloc(FALSE);
			hr = spDMReader->putContentHandler( dmParser );
			if (FAILED(hr))
			{
				ATLTRACE( _T("putContentHandler failed!\n") );
				return 1;
			}
			
			CErrorHandler errDM;
			errDM.SetLocation(wszUrl);

			hr = spDMReader->putErrorHandler( &errDM);
			if (FAILED(hr))
			{
				ATLTRACE( _T("putErrorHandler failed!\n") );
				return 1;
			}

			g_pDMDoc = dmParser->GetDiscoMapDocument();
			if (g_pDMDoc == NULL)
			{
				ATLTRACE( _T("failed to create document: out of memory!\n") );
				return 1;
			}
			

			hr = g_pDMDoc->SetDocumentUri( wszUrl, wszUrl.GetLength());

			if (FAILED(hr))
			{
				ATLTRACE( _T("failed to set document uri: out of memory!\n") );
				return 1;
			}

			g_wszFile = wszUrl;

			hr = spDMReader->parseURL( wszUrl );
			if (FAILED(hr))
			{
				ATLTRACE( _T("parseURL failed!\n") );
				if ((hr == E_SAX_LOADFAILED) || 
					(hr == E_SAX_FILENOTFOUND) ||
					(hr == E_SAX_PATHNOTFOUND) ||
					(hr == E_SAX_ACCESSDENIED))
				{
					EmitError(IDS_SDL_FAILED_DM_OPEN, wszUrl);
				}
				EmitError(IDS_SDL_PROCESS_DM_FAILURE, wszUrl);
				return 1;
			}
		}

		if(nFlags & SPROXYFLAG_WSDLINPUT)
			g_wszFile = wszUrl;
		else
			g_wszFile = g_pDMDoc->GetWSDLFile();

		CComPtr<ISAXXMLReader> spReader;
		hr = CoCreateInstance(__uuidof(SAXXMLReader30), NULL, CLSCTX_ALL,
			__uuidof(ISAXXMLReader), (void **)&spReader);

		if (FAILED(hr))
		{
			ATLTRACE( _T("CoCreateInstance failed!\n") );
			return 1;
		}

		CWSDLParser parser(spReader, NULL, 0);
		parser.SetDynamicAlloc(FALSE);
		hr = spReader->putContentHandler( &parser );
		if (FAILED(hr))
		{
			ATLTRACE( _T("putContentHandler failed!\n") );
			return 1;
		}

		CErrorHandler err;
		err.SetLocation(g_wszFile);

		hr = spReader->putErrorHandler( &err );
		if (FAILED(hr))
		{
			ATLTRACE( _T("putErrorHandler failed!\n") );
			return 1;
		}

		CWSDLDocument * pDoc = parser.GetWSDLDocument();
		if (pDoc == NULL)
		{
			ATLTRACE( _T("failed to create document: out of memory!\n") );
			return 1;
		}
		
		hr = pDoc->SetDocumentUri( g_wszFile, g_wszFile.GetLength());
		if (FAILED(hr))
		{
			ATLTRACE( _T("failed to set document uri: out of memory!\n") );
			return 1;
		}

		wchar_t wszTmp[ATL_URL_MAX_URL_LENGTH];
		if(g_wszFile.Find(L"://") != -1 && ((g_wszFile.Left(5)).MakeLower() != L"file:") )
		{
			// The URL needs to be escaped only if it's not a local file
			if(AtlEscapeUrl(g_wszFile,wszTmp,0,ATL_URL_MAX_URL_LENGTH-1,ATL_URL_BROWSER_MODE) == FALSE)
			{
				ATLTRACE( _T("failed to escape uri!\n") );
				return 1;
			}

			hr = spReader->parseURL( wszTmp );
		}
		else
		{
			hr = spReader->parseURL( g_wszFile );
		}
		
		if (FAILED(hr))
		{
			ATLTRACE( _T("parseURL failed!\n") );
			if ((hr == E_SAX_LOADFAILED) || 
			    (hr == E_SAX_FILENOTFOUND) ||
			    (hr == E_SAX_PATHNOTFOUND) ||
			    (hr == E_SAX_ACCESSDENIED))
			{
				EmitError(IDS_SDL_FAILED_WSDL_OPEN, g_wszFile);
			}
			EmitError(IDS_SDL_PROCESS_FAILURE, g_wszFile);
			return 1;
		}

		CCodeTypeBuilder builder;
		CCodeProxy proxy;
		hr = builder.Initialize(parser.GetWSDLDocument(), &proxy);

		if (FAILED(hr))
		{
			ATLTRACE( _T("builder.Initialize failed!\n") );
			return PrintGenerateFailure(wszOut);
		}

		hr = builder.Build();
		if (FAILED(hr))
		{
			ATLTRACE( _T("builder.Build failed!\n") );
			return PrintGenerateFailure(wszOut);
		}

		if (wszOut.IsEmpty())
		{
			wszOut.Preallocate(proxy.GetServiceName().GetLength()+4);
			wszOut = (LPCSTR)proxy.GetServiceName();
			wszOut.Append(L".h", 2);
		}

		Emit(IDS_SDL_SUCCESS, wszOut);
		CComObjectStack<CCppCodeGenerator> gen;
		hr = gen.Generate(wszOut, &proxy, 
				(nFlags & SPROXYFLAG_NOPRAGMA) ? false : true, 
				(nFlags & SPROXYFLAG_NOCLOBBER) ? true : false,
				(nFlags & SPROXYFLAG_NONAMESPACE) ? false : true,
				(nFlags & SPROXYFLAG_NOPROXY) ? false : true,
				spSzNamespace ? spSzNamespace : (szNamespace.IsEmpty() ? 0 : LPCSTR(szNamespace)));
		if (FAILED(hr))
		{
			ATLTRACE( _T("gen.Generate failed!\n") );
			return PrintGenerateFailure(wszOut);
		}
	}
	CoUninitialize();

	return 0;
}
Exemple #9
0
void CSubAction::DoMisc()
{
	if (m_nMisc==ExecuteCommandMisc)
	{
		if (m_szCommand!=NULL)
			CLocateDlg::ExecuteCommand(m_szCommand);
		return;
	}
	else if (m_nMisc==InsertAsterisks)
	{
		CLocateDlg* pLocateDlg=GetLocateDlg();
		if (pLocateDlg==NULL)
			return;

		CStringW Text;
		pLocateDlg->m_NameDlg.m_Name.GetText(Text);
		DWORD dwSelStart=pLocateDlg->m_NameDlg.m_Name.GetEditSel();
		WORD wSelEnd=HIWORD(dwSelStart);
		dwSelStart&=0xFFFF;

		// If asterisks are already at the beginning and the end, replace spaces
		if (Text[0]==L'*' && Text.LastChar()==L'*')
			Text.ReplaceChars(L' ',L'*');
		else 
		{
			if (Text[0]!=L'*')
			{
				Text.InsChar(0,L'*');
				
				// Update selection
				if (dwSelStart==wSelEnd)
				{
					dwSelStart++;
					wSelEnd++;
				}
				else 
				{
					if (dwSelStart>0)
						dwSelStart++;
					wSelEnd++;
				}
			}
			
			if (Text.LastChar()!=L'*')
			{
				// Update selection first
				if (wSelEnd==Text.GetLength())
				{
					if (dwSelStart==wSelEnd)
						dwSelStart++;
					wSelEnd++; 
				}

				Text.Append(L'*');
			}
		}

		pLocateDlg->m_NameDlg.m_Name.SetText(Text);
		pLocateDlg->m_NameDlg.m_Name.SetEditSel(dwSelStart,wSelEnd);
		pLocateDlg->OnFieldChange(CLocateDlg::isNameChanged);
		return;
	}
	

	// Send/Post Message

	BOOL bFreeWParam=FALSE,bFreeLParam=FALSE;
	
	HWND hWnd=NULL;
	WPARAM wParam=NULL,lParam=NULL;

	if (m_pSendMessage->szWindow[0]=='0')
	{
		if (m_pSendMessage->szWindow[1]=='x' || 
			m_pSendMessage->szWindow[1]=='X')
		{
			// Hex value
			LPWSTR szTemp;
			hWnd=(HWND)wcstoul(m_pSendMessage->szWindow+2,&szTemp,16);
		}
	}
	else if (strcasecmp(m_pSendMessage->szWindow,L"HWND_BROADCAST")==0)
		hWnd=HWND_BROADCAST;
	else if (GetLocateDlg()!=NULL && strcasecmp(m_pSendMessage->szWindow,L"LOCATEDLG")==0)
		hWnd=*GetLocateDlg();
	else if (strcasecmp(m_pSendMessage->szWindow,L"LOCATEST")==0)
		hWnd=*GetTrayIconWnd();
	else if (wcsncmp(m_pSendMessage->szWindow,L"Find",4)==0)
	{
		int nIndex=(int)FirstCharIndex(m_pSendMessage->szWindow,L'(');
		if (nIndex!=-1)
		{
			LPCWSTR pText=m_pSendMessage->szWindow+nIndex+1;
			LPWSTR pClassAndWindow[3]={NULL,NULL,NULL};
			
			nIndex=(int)FirstCharIndex(pText,L',');
			if (nIndex==-1)
			{
				nIndex=(int)FirstCharIndex(pText,L')');
				if (nIndex==-1)
					pClassAndWindow[0]=alloccopy(pText);
				else
					pClassAndWindow[0]=alloccopy(pText,nIndex);
			}
			else
			{
				pClassAndWindow[0]=alloccopy(pText,nIndex);
				pText+=nIndex+1;

				nIndex=(int)FirstCharIndex(pText,L')');
				pClassAndWindow[1]=alloccopy(pText,nIndex);
			}

			EnumWindows(WindowEnumProc,LPARAM(pClassAndWindow));

			// Third cell is handle to window
			hWnd=(HWND)pClassAndWindow[2];

			delete[] pClassAndWindow[0];
			if (pClassAndWindow[1])
				delete[] pClassAndWindow[1];
		}
	}
	


	// Parse wParam
	if (m_pSendMessage->szWParam!=NULL)
	{
		if (m_pSendMessage->szWParam[0]=='0')
		{
			if (m_pSendMessage->szWParam[1]=='x' || 
				m_pSendMessage->szWParam[1]=='X')
			{
				// Hex value
				LPWSTR szTemp;
				wParam=(WPARAM)wcstoul(m_pSendMessage->szWParam+2,&szTemp,16);
			}
			else if (m_pSendMessage->szWParam[1]!='\0')
			{
				DWORD dwLength;
				wParam=(WPARAM)dataparser(m_pSendMessage->szWParam,istrlen(m_pSendMessage->szWParam),gmalloc,&dwLength);
				*((BYTE*)wParam+dwLength)=0;
				bFreeWParam=TRUE;
			}
		}
		else if ((wParam=_wtoi(m_pSendMessage->szWParam))==0)
		{
			DWORD dwLength;
			wParam=(WPARAM)dataparser(m_pSendMessage->szWParam,istrlen(m_pSendMessage->szWParam),gmalloc,&dwLength);
			*((BYTE*)wParam+dwLength)=0;
			bFreeWParam=TRUE;
		}
	}

	// Parse lParam
	if (m_pSendMessage->szLParam!=NULL)
	{
		if (m_pSendMessage->szLParam[0]=='0')
		{
			if (m_pSendMessage->szLParam[1]=='x' || 
				m_pSendMessage->szLParam[1]=='X')
			{
				// Hex value
				LPWSTR szTemp;
				lParam=(WPARAM)wcstoul(m_pSendMessage->szLParam+2,&szTemp,16);
			}
			else if (m_pSendMessage->szLParam[1]!='\0')
			{
				DWORD dwLength;
				lParam=(WPARAM)dataparser(m_pSendMessage->szLParam,istrlen(m_pSendMessage->szLParam),gmalloc,&dwLength);
				*((BYTE*)lParam+dwLength)=0;
				bFreeLParam=TRUE;
			}
		}
		else if ((lParam=_wtoi(m_pSendMessage->szLParam))==0)
		{
			DWORD dwLength;
			lParam=(WPARAM)dataparser(m_pSendMessage->szLParam,istrlen(m_pSendMessage->szLParam),gmalloc,&dwLength);
			*((BYTE*)lParam+dwLength)=0;
            bFreeLParam=TRUE;
		}
	}

	if (hWnd!=NULL)
	{
		if (m_nMisc==PostMessage)
			::PostMessage(hWnd,m_pSendMessage->nMessage,wParam,lParam);
		else
			::SendMessage(hWnd,m_pSendMessage->nMessage,wParam,lParam);
	}

	if (bFreeWParam)
		GlobalFree((HANDLE)wParam);
	if (bFreeLParam)
		GlobalFree((HANDLE)lParam);

}