void SourceEdit::TokenizeLine(const CStringW& line, CArray<CStringW>& tokens)
{
  int i = 0;
  while (true)
  {
    // We are either at the start of the line, or the end of the previous token,
    // so scan forward to find the start of the next token.
    while (true)
    {
      if (i == line.GetLength())
        return;
      WCHAR c = line.GetAt(i);
      if ((c != L' ') && (c != L'\t'))
        break;
      i++;
    }

    // Find the end of this token
    int j = line.Find(L"  ",i);
    if (j == -1)
    {
      // No final delimiter, so this must be the last token
      if (i < line.GetLength())
        tokens.Add(line.Mid(i));
      return;
    }
    else
    {
      // Store this token and move to the end of it
      tokens.Add(line.Mid(i,j-i));
      i = j;
    }
  }
}
Exemple #2
0
// *************************************************************
//		GetDbSchemeName()
// *************************************************************
CStringW OgrStyleHelper::GetDbSchemeName(CStringW layerName, bool withTrailingPoint)
{
	int pos = layerName.ReverseFind(L'.');
	if (pos != -1)
	{
		return layerName.Mid(0, pos + withTrailingPoint ? 1 : 0);
	}
	return L"";
}
Exemple #3
0
BOOL CStdioFileEx::ReadWideString(CStringW& rString)
{
   _ASSERTE(m_pStream);
   rString = L"";// empty string without deallocating
   
   if(m_bIsUnicodeText)
   {
      // If at position 0, discard byte-order mark before reading
      if(GetPosition() == 0)
      {
         wchar_t bom;
         Read(&bom, sizeof(wchar_t));
      }
      const int nMaxSize = 128;
      LPWSTR lpsz = rString.GetBuffer(nMaxSize);
      LPWSTR lpszResult;
      int nLen = 0;
      for (;;)
      {
         lpszResult = fgetws(lpsz, nMaxSize+1, m_pStream);
         rString.ReleaseBuffer();
         
         // handle error/eof case
         if (lpszResult == NULL && !feof(m_pStream))
         {
            Afx_clearerr_s(m_pStream);
            AfxThrowFileException(CFileException::genericException, _doserrno,
               m_strFileName);
         }
         
         // if string is read completely or EOF
         if (lpszResult == NULL || (nLen = (int)lstrlenW(lpsz)) < nMaxSize || lpsz[nLen-1] == '\n')
            break;
         
         nLen = rString.GetLength();
         lpsz = rString.GetBuffer(nMaxSize + nLen) + nLen;
      }
      //remove crlf if exist.
      nLen = rString.GetLength();
      if (nLen > 1 && rString.Mid(nLen-2) == L"\r\n")
      {
         rString.GetBufferSetLength(nLen-2);
      }
      return rString.GetLength() > 0;
   }
   else
   {
      CStringA ansiString;
      BOOL bRetval = ReadAnsiString(ansiString);
      //setlocale(LC_ALL, "chs_chn.936");//no need
      rString = ansiString;
      return bRetval;
   }
}
Exemple #4
0
std::vector<CStringW> Unzip::Extract(LPCWSTR pszFilename, LPCWSTR pszFolder, std::function<bool(LPCWSTR filePath, DWORD& flagsAndAttributes)> predicate)
{
    std::vector<CStringW> result;

    unzFile uf = NULL;
    try
    {
        uf = Unzip_Open(pszFilename);

        unz_global_info gi;
        if (UNZ_OK != unzGetGlobalInfo(uf, &gi))
            throw runtime_error("failed to unzGetGlobalInfo");

        for (uLong i = 0; i < gi.number_entry; ++i)
        {
            FILETIME ftLocal;
            CStringW path = CStringW(pszFolder) + L'\\' + Unzip_GetCurentFilePath(uf, ftLocal);

            CStringW filename = path.Mid(path.ReverseFind(L'\\') + 1);
            if (filename.IsEmpty())
            {
                if (!CreateDirectoryW(path, NULL))
                    throw runtime_error("failed to CreateDirectory");
                continue;
            }

            DWORD flagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
            if (predicate(path, flagsAndAttributes))
            {
                Unzip_ExtractFile(uf, path, flagsAndAttributes, ftLocal);
                result.push_back(path);
            }

            if (i + 1 < gi.number_entry && UNZ_OK != unzGoToNextFile(uf))
                throw runtime_error("failed to unzGoToNextFile");
        }
        unzClose(uf);

        return result;
    }
    catch (...)
    {
        if (uf != NULL)
            unzClose(uf);
        for each (auto file in result)
            DeleteFileW(file);
        throw;
    }
}
Exemple #5
0
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
{
	int      argc;
	LPWSTR  *argv;
	HKEY     hKey;
	BOOL     bShowMsg = TRUE;
	DWORD    dwDisp;
	argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
	CStringW wcsPath = argv[0];
	WCHAR    szSysDir[256];
	CStringW wcsSysDir;
	::LocalFree(argv);
	wcsPath = wcsPath.Mid(0, wcsPath.ReverseFind(L'\\') + 1);    // note: '\\' is included in the Path
	::GetSystemDirectoryW(szSysDir, 256);
	wcsSysDir = szSysDir;

	// --- for TCC file
	// --- Reg ".tcc" in "HKEY_CLASSES_ROOT"
	if (::RegCreateKeyExW(	HKEY_CLASSES_ROOT, L".tcc", 0, NULL, 
							REG_OPTION_NON_VOLATILE, KEY_WRITE, 
							NULL, &hKey, &dwDisp) != ERROR_SUCCESS)
	{
		return FALSE;
	}
	::RegSetValueW(hKey, NULL, REG_SZ, L"TCC_File_Type", 0);
	::RegCloseKey(hKey);
	// --- Reg "shell\open\command" of "TCC_File_Type" in "HKEY_CLASSES_ROOT"
	if (::RegCreateKeyExW(	HKEY_CLASSES_ROOT, L"TCC_File_Type\\shell\\open\\command", 0, NULL, 
							REG_OPTION_NON_VOLATILE, KEY_WRITE, 
							NULL, &hKey, &dwDisp) != ERROR_SUCCESS)
	{
		return FALSE;
	}
	::RegSetValueW(hKey, NULL, REG_SZ, L"\"" + wcsSysDir + L"\\notepad.exe\" \"%1\"", 0);
	::RegCloseKey(hKey);
	// --- Reg "shell\edit\command" of "TCC_File_Type" in "HKEY_CLASSES_ROOT"
	if (::RegCreateKeyExW(	HKEY_CLASSES_ROOT, L"TCC_File_Type\\shell\\edit\\command", 0, NULL, 
							REG_OPTION_NON_VOLATILE, KEY_WRITE, 
							NULL, &hKey, &dwDisp) != ERROR_SUCCESS)
	{
		return FALSE;
	}
	::RegSetValueW(hKey, NULL, REG_SZ, L"\"" + wcsSysDir + L"\\notepad.exe\" \"%1\"", 0);
	::RegCloseKey(hKey);
	// --- Reg "shell\parse" of "TCC_File_Type" in "HKEY_CLASSES_ROOT"
	if (::RegCreateKeyExW(	HKEY_CLASSES_ROOT, L"TCC_File_Type\\shell\\parse", 0, NULL, 
							REG_OPTION_NON_VOLATILE, KEY_WRITE, 
							NULL, &hKey, &dwDisp) != ERROR_SUCCESS)
	{
		return FALSE;
	}
	::RegSetValueW(hKey, NULL, REG_SZ, L"Parse", 0);
	::RegCloseKey(hKey);
	// --- Reg "shell\parse\command" of "TCC_File_Type" in "HKEY_CLASSES_ROOT"
	if (::RegCreateKeyExW(	HKEY_CLASSES_ROOT, L"TCC_File_Type\\shell\\parse\\command", 0, NULL, 
							REG_OPTION_NON_VOLATILE, KEY_WRITE, 
							NULL, &hKey, &dwDisp) != ERROR_SUCCESS)
	{
		return FALSE;
	}
	::RegSetValueW(hKey, NULL, REG_SZ, L"\"" + wcsPath + L"tcax.exe\" \"%L\"", 0);
	::RegCloseKey(hKey);
	// --- Reg "DefaultIcon" of "TCC_File_Type" in "HKEY_CLASSES_ROOT"
	if (::RegCreateKeyExW(	HKEY_CLASSES_ROOT, L"TCC_File_Type\\DefaultIcon", 0, NULL, 
							REG_OPTION_NON_VOLATILE, KEY_WRITE, 
							NULL, &hKey, &dwDisp) != ERROR_SUCCESS)
	{
		return FALSE;
	}
	::RegSetValueW(hKey, NULL, REG_SZ, wcsPath + L"icons\\tcc.ico", 0);
	::RegCloseKey(hKey);

	// --- for ASS file
	// --- Reg ".ass" in "HKEY_CLASSES_ROOT"
	if (::RegCreateKeyExW(	HKEY_CLASSES_ROOT, L".ass", 0, NULL, 
							REG_OPTION_NON_VOLATILE, KEY_WRITE, 
							NULL, &hKey, &dwDisp) != ERROR_SUCCESS)
	{
		return FALSE;
	}
	::RegSetValueW(hKey, NULL, REG_SZ, L"ASS_File_Type", 0);
	::RegCloseKey(hKey);
	// --- Reg "DefaultIcon" of "ASS_File_Type" in "HKEY_CLASSES_ROOT"
	if (::RegCreateKeyExW(	HKEY_CLASSES_ROOT, L"ASS_File_Type\\DefaultIcon", 0, NULL, 
							REG_OPTION_NON_VOLATILE, KEY_WRITE, 
							NULL, &hKey, &dwDisp) != ERROR_SUCCESS)
	{
		return FALSE;
	}
	::RegSetValueW(hKey, NULL, REG_SZ, wcsPath + L"icons\\ass.ico", 0);
	::RegCloseKey(hKey);

	// --- for tcas file
	// --- Reg ".tcas" in "HKEY_CLASSES_ROOT"
	if (::RegCreateKeyExW(	HKEY_CLASSES_ROOT, L".tcas", 0, NULL, 
							REG_OPTION_NON_VOLATILE, KEY_WRITE, 
							NULL, &hKey, &dwDisp) != ERROR_SUCCESS)
	{
		return FALSE;
	}
	::RegSetValueW(hKey, NULL, REG_SZ, L"TCAS_File_Type", 0);
	::RegCloseKey(hKey);
	// --- Reg "shell\open\command" of "TCAS_File_Type" in "HKEY_CLASSES_ROOT"
	if (::RegCreateKeyExW(	HKEY_CLASSES_ROOT, L"TCAS_File_Type\\shell\\open\\command", 0, NULL, 
							REG_OPTION_NON_VOLATILE, KEY_WRITE, 
							NULL, &hKey, &dwDisp) != ERROR_SUCCESS)
	{
		return FALSE;
	}
	::RegSetValueW(hKey, NULL, REG_SZ, L"\"" + wcsPath + L"tools\\timeShift.exe\" \"%L\"", 0);
	::RegCloseKey(hKey);
	// --- Reg "DefaultIcon" of "TCAS_File_Type" in "HKEY_CLASSES_ROOT"
	if (::RegCreateKeyExW(	HKEY_CLASSES_ROOT, L"TCAS_File_Type\\DefaultIcon", 0, NULL, 
							REG_OPTION_NON_VOLATILE, KEY_WRITE, 
							NULL, &hKey, &dwDisp) != ERROR_SUCCESS)
	{
		return FALSE;
	}
	::RegSetValueW(hKey, NULL, REG_SZ, wcsPath + L"icons\\tcas.ico", 0);
	::RegCloseKey(hKey);
	::SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, 0, 0);
    ::MessageBoxW(NULL, L"TCAX file association successfully executed.\n\nTCAX程序文件关联成功执行, 请点确定.", L"TCAX - Info", MB_OK | MB_ICONINFORMATION);
	return TRUE;
}
Exemple #6
0
HRESULT CStreamSwitcherInputPin::CompleteConnect(IPin* pReceivePin)
{
    HRESULT hr = __super::CompleteConnect(pReceivePin);
    if (FAILED(hr)) {
        return hr;
    }

    (static_cast<CStreamSwitcherFilter*>(m_pFilter))->CompleteConnect(PINDIR_INPUT, this, pReceivePin);

    m_fCanBlock = false;
    bool fForkedSomewhere = false;

    CStringW fileName;
    CStringW pinName;

    IPin* pPin = (IPin*)this;
    IBaseFilter* pBF = (IBaseFilter*)m_pFilter;

    pPin = GetUpStreamPin(pBF, pPin);
    if (pPin) {
        pBF = GetFilterFromPin(pPin);
    }
    while (pPin && pBF) {
        if (IsSplitter(pBF)) {
            pinName = GetPinName(pPin);
        }

        CLSID clsid = GetCLSID(pBF);
        if (clsid == CLSID_AviSplitter || clsid == CLSID_OggSplitter) {
            m_fCanBlock = true;
        }

        int nIn, nOut, nInC, nOutC;
        CountPins(pBF, nIn, nOut, nInC, nOutC);
        fForkedSomewhere = fForkedSomewhere || nIn > 1 || nOut > 1;

        DWORD cStreams = 0;
        if (CComQIPtr<IAMStreamSelect> pSSF = pBF) {
            hr = pSSF->Count(&cStreams);
            if (SUCCEEDED(hr)) {
                for (int i = 0; i < (int)cStreams; i++) {
                    AM_MEDIA_TYPE* pmt = nullptr;
                    hr = pSSF->Info(i, &pmt, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
                    if (SUCCEEDED(hr) && pmt && pmt->majortype == MEDIATYPE_Audio) {
                        m_pSSF = pSSF;
                        DeleteMediaType(pmt);
                        break;
                    }
                    DeleteMediaType(pmt);
                }
            }
        }

        if (CComQIPtr<IFileSourceFilter> pFSF = pBF) {
            WCHAR* pszName = nullptr;
            AM_MEDIA_TYPE mt;
            if (SUCCEEDED(pFSF->GetCurFile(&pszName, &mt)) && pszName) {
                fileName = pszName;
                CoTaskMemFree(pszName);

                fileName.Replace('\\', '/');
                CStringW fn = fileName.Mid(fileName.ReverseFind('/') + 1);
                if (!fn.IsEmpty()) {
                    fileName = fn;
                }

                // Haali & LAVFSplitter return only one "Audio" pin name, cause CMainFrame::OnInitMenuPopup lookup find the wrong popmenu,
                // add space at the end to prevent this, internal filter never return "Audio" only.
                if (!pinName.IsEmpty()) {
                    fileName = pinName + L" ";
                }

                WCHAR* pName = DEBUG_NEW WCHAR[fileName.GetLength() + 1];
                if (pName) {
                    wcscpy_s(pName, fileName.GetLength() + 1, fileName);
                    if (m_pName) {
                        delete [] m_pName;
                    }
                    m_pName = pName;
                    if (cStreams == 1) { // Simple external track, no need to use the info from IAMStreamSelect
                        m_pSSF.Release();
                    }
                }
            }

            break;
        }

        pPin = GetFirstPin(pBF);

        pPin = GetUpStreamPin(pBF, pPin);
        if (pPin) {
            pBF = GetFilterFromPin(pPin);
        }
    }

    if (!fForkedSomewhere) {
        m_fCanBlock = true;
    }

    m_hNotifyEvent = nullptr;

    return S_OK;
}
HRESULT CStreamSwitcherInputPin::CompleteConnect(IPin* pReceivePin)
{
	HRESULT hr = __super::CompleteConnect(pReceivePin);
	if(FAILED(hr)) return hr;

    ((CStreamSwitcherFilter*)m_pFilter)->CompleteConnect(PINDIR_INPUT, this, pReceivePin);

	m_fCanBlock = false;
	bool fForkedSomewhere = false;

	CStringW fileName;
	CStringW pinName;

    IPin* pPin = (IPin*)this;
	IBaseFilter* pBF = (IBaseFilter*)m_pFilter;

	while((pPin = GetUpStreamPin(pBF, pPin)) && (pBF = GetFilterFromPin(pPin)))
	{
		if(IsSplitter(pBF))
		{
			pinName = GetPinName(pPin);
		}

		CLSID clsid = GetCLSID(pBF);
		if(clsid == CLSID_AviSplitter || clsid == CLSID_OggSplitter)
			m_fCanBlock = true;

		int nIn, nOut, nInC, nOutC;
		CountPins(pBF, nIn, nOut, nInC, nOutC);
		fForkedSomewhere = fForkedSomewhere || nIn > 1 || nOut > 1;

		if(CComQIPtr<IFileSourceFilter> pFSF = pBF)
		{
			WCHAR* pszName = NULL;
			AM_MEDIA_TYPE mt;
			if(SUCCEEDED(pFSF->GetCurFile(&pszName, &mt)) && pszName)
			{
				fileName = pszName;
				CoTaskMemFree(pszName);

				fileName.Replace('\\', '/');
				CStringW fn = fileName.Mid(fileName.ReverseFind('/')+1);
				if(!fn.IsEmpty()) fileName = fn;

				if(!pinName.IsEmpty()) fileName += L" / " + pinName;

				WCHAR* pName = new WCHAR[fileName.GetLength()+1];
				if(pName)
				{
					wcscpy(pName, fileName);
					if(m_pName) delete [] m_pName;
					m_pName = pName;
				}
			}

			break;
		}

		pPin = GetFirstPin(pBF);
	}

	if(!fForkedSomewhere)
		m_fCanBlock = true;

	m_hNotifyEvent = NULL;

	return S_OK;
}
Exemple #8
0
void TabDoc::DecodeHTML(const char* filename, int scheme)
{
  // Open the file
  CFile htmlFile;
  if (htmlFile.Open(filename,CFile::modeRead) == 0)
    return;

  // Read it into memory
  CString htmlText;
  int len = (int)htmlFile.GetLength();
  htmlFile.Read(htmlText.GetBuffer(len),len);
  htmlText.ReleaseBuffer(len);

  // Convert from UTF-8 to Unicode
  CStringW html = TextFormat::UTF8ToUnicode(htmlText);

  // Get the body text
  int body1 = html.Find(L"<body");
  if (body1 == -1)
    return;
  body1 = html.Find(L">",body1);
  if (body1 == -1)
    return;
  int body2 = html.Find(L"</body>");
  if (body2 <= body1)
    return;
  CStringW bodyHtml = html.Mid(body1+1,body2-body1-1);

  // Create a DocText instance for this file
  DocText* mainDocText = new DocText();
  mainDocText->file = filename;
  mainDocText->colourScheme = scheme;
  m_docTexts.Add(mainDocText);

  // Reserve space for the main text
  len = bodyHtml.GetLength();
  mainDocText->body.Preallocate(len);

  // Scan the text, removing markup
  DocText* docText = mainDocText;
  bool ignore = false;
  bool white = false;
  const wchar_t* p1 = bodyHtml;
  const wchar_t* p2 = p1+len;
  while (p1 < p2)
  {
    // Look for a markup element
    if ((*p1 == L'<') && (iswalpha(*(p1+1)) || (*(p1+1) == L'/')))
    {
      // Check for a closing markup element
      bool closing = false;
      if (*(p1+1) == L'/')
      {
        closing = true;
        p1++;
      }

      // Scan for a known markup element
      bool found = false;
      int i = 0;
      while (!found && (i < sizeof tags / sizeof tags[0]))
      {
        if (wcsncmp(p1+1,tags[i].name,tags[i].len) == 0)
          found = true;
        if (!found)
          i++;
      }
      ASSERT(found);

      // Remove the markup
      if (found && tags[i].remove)
      {
        ASSERT(!closing);

        // Remove everything until the closing element
        CStringW search;
        search.Format(L"</%s>",tags[i].name);
        p1 = wcsstr(p1,search);
        if (p1 != NULL)
          p1 += search.GetLength()-1;
        else
          p1 = p2;
      }
      else
      {
        // Remove just the element
        while ((p1 < p2) && (*p1 != L'>'))
          p1++;
      }
      ASSERT(*p1 == L'>');

      // Add a carriage return for appropriate markup
      if (found && !closing && tags[i].cr && !ignore)
        docText->AddToBody(L'\n');
      white = false;
    }
    else if ((*p1 == L'<') && (*(p1+1) == L'!'))
    {
      // Extract metadata from comments
      wchar_t meta1[256], meta2[256];
      if (swscanf(p1,L"<!-- SEARCH TITLE \"%[^\"]",meta1) == 1)
        docText->title = meta1;
      else if (swscanf(p1,L"<!-- SEARCH SECTION \"%[^\"]",meta1) == 1)
        docText->section = meta1;
      else if (swscanf(p1,L"<!-- SEARCH SORT \"%[^\"]",meta1) == 1)
        docText->sort = meta1;
      else if (swscanf(p1,L"<!-- START EXAMPLE \"%[^\"]\" \"%[^\"]",meta1,meta2) == 2)
      {
        docText = new DocText();
        docText->file = mainDocText->file + "#" + CStringA(meta2);
        docText->colourScheme = mainDocText->colourScheme;
        docText->title = "Example " + CStringA(meta1);
        docText->section = mainDocText->section;
        docText->sort = mainDocText->sort;
        docText->body.Preallocate(len/2);
        m_docTexts.Add(docText);
      }
      else if (wcsncmp(p1,L"<!-- END EXAMPLE -->",20) == 0)
        docText = mainDocText;
      else if (wcsncmp(p1,L"<!-- START IGNORE ",18) == 0)
        ignore = true;
      else if (wcsncmp(p1,L"<!-- END IGNORE -->",19) == 0)
        ignore = false;

      p1 = wcsstr(p1,L"-->");
      if (p1 != NULL)
        p1 += 2;
      else
        p1 = p2;
    }
    else if (*p1 == L'&')
    {
      // Scan for a known literal
      bool found = false;
      int i = 0;
      while (!found && (i < sizeof literals / sizeof literals[0]))
      {
        if (wcsncmp(p1+1,literals[i].name,literals[i].len) == 0)
          found = true;
        if (!found)
          i++;
      }

      // Replace the literal
      if (found)
      {
        if (!ignore)
          docText->AddToBody(literals[i].replace);
        p1 += literals[i].len;
      }
      else
      {
        ASSERT(FALSE);
        if (!ignore)
          docText->AddToBody(*p1);
      }
      white = false;
    }
    else if (iswspace(*p1))
    {
      if (!white && !ignore)
        docText->AddToBody(L' ');
      white = true;
    }
    else
    {
      if (!ignore)
        docText->AddToBody(*p1);
      white = false;
    }
    p1++;
  }

/*
  CString bodyA(docText->body);
  AfxMessageBox(bodyA);
*/
}
Exemple #9
0
ULONG CFormData::ProcessForm()
{
	CStringA startPart = "--" + CStringA(m_sBoundary) + "\r\n";
	Append(startPart);

	BOOL bHasFields = FALSE;

	//STLOG_WRITE("%s(%d): Ponto de apoio", __FUNCTION__, __LINE__);

	// Varrer os fields primeiro
	POSITION p1 = m_items.GetStartPosition();
	while(p1)
	{
		CStringW key1;
		CFormItem *pAttr;
		m_items.GetNextAssoc(p1, key1, pAttr);
		if(!pAttr->m_bFile)
		{
			bHasFields = TRUE;
			CStringW s;
			s.Format(FIELD_BOUND, pAttr->m_name, pAttr->m_value);
			Append(CStringA(s));
		}

		if(p1 != NULL)
		{
			startPart = "--" + CStringA(m_sBoundary) + "\r\n";
			Append(startPart);
		}
	}

	//STLOG_WRITE("%s(%d): Ponto de apoio", __FUNCTION__, __LINE__);

	BOOL bFirst = TRUE;
	// Varrer os files
	p1 = m_items.GetStartPosition();
	while(p1)
	{
		CStringW key1;
		CFormItem *pAttr;
		m_items.GetNextAssoc(p1, key1, pAttr);
		if(pAttr->m_bFile)
		{
			if(bFirst && bHasFields)
			{
				startPart = "--" + CStringA(m_sBoundary) + "\r\n";
				Append(startPart);
				bFirst = FALSE;
			}

			CStringW sFileName = pAttr->m_value;
			if(sFileName.Find('\\') >= 0 || sFileName.Find('/') >= 0)
			{
				int pos = sFileName.ReverseFind('\\');
				if(pos < 0)
					pos = sFileName.ReverseFind('/');

				sFileName = sFileName.Mid(pos+1);
			}

			CStringW s;
			s.Format(FILE_BOUND, pAttr->m_name, sFileName, pAttr->m_mime);
			Append(CStringA(s));

			Append("\r\n");

			AppendFile(pAttr->m_value);

			Append("\r\n");

			if(p1 != NULL)
			{
				startPart = "--" + CStringA(m_sBoundary) + "\r\n";
				Append(startPart);
			}
		}
	}

	startPart = "--" + CStringA(m_sBoundary) + "--\r\n";
	Append(startPart);

	//STLOG_WRITE("%s(%d): Ponto de apoio", __FUNCTION__, __LINE__);
	//STLOG_WRITE("%s(%d): Buffer: %s", __FUNCTION__, __LINE__, m_buffer.GetData());

	return m_buffer.GetCount();
}
//绘制文字
void CxResLibImgList::DrawItemText( int nItem, RECT& rcLabel )
{
	CString strLabel = GetItemText(nItem, 0);

	SolidBrush brushText(m_FontColor);
	CStringW strLabelW;
	strLabelW = strLabel;

	if ( strLabelW.IsEmpty() ) return;

	RectF rcLabelF((float)rcLabel.left, (float)rcLabel.top, (float)rcLabel.right - (float)rcLabel.left
		, (float)rcLabel.bottom - (float)rcLabel.top);

	int nFirstLineCharCount = 1;
	CStringW strLineW;
	RectF rcfText;
	PointF ptfText;
	while ( nFirstLineCharCount < strLabelW.GetLength() )
	{
		strLineW = strLabelW.Mid(0, nFirstLineCharCount);
		m_pGraphics->MeasureString((WCHAR*)(LPCWSTR)strLabelW
			, nFirstLineCharCount
			, m_pFont
			, ptfText
			, &rcfText
			);

		if ( (int)rcLabelF.Width < 1 + rcfText.Width )
		{
			nFirstLineCharCount--;
			if ( nFirstLineCharCount < 0 ) nFirstLineCharCount = 0;
			break;
		}

		nFirstLineCharCount++;
	}

	if ( nFirstLineCharCount != strLabelW.GetLength() && nFirstLineCharCount > 0 )
	{
		//第一行
		RectF rcLine = rcLabelF;
		rcLine.Height = rcfText.Height;
		strLineW = strLabelW.Mid(0, nFirstLineCharCount);

		m_pGraphics->DrawString((LPCWSTR)strLineW
			, -1
			, m_pFont
			, rcLine
			, &m_FontFormat
			, &brushText);

		//第2行
		rcLine.Offset(0, rcLine.Height);
		strLineW = strLabelW.Mid(nFirstLineCharCount, strLabelW.GetLength() - nFirstLineCharCount);

		if ( strLineW.GetLength() > 6 )
		{
			CStringW str = strLineW.Mid( 0, 5 );
			strLineW = str + L"..";
		}

		m_pGraphics->DrawString((LPCWSTR)strLineW
			, -1
			, m_pFont
			, rcLine
			, &m_FontFormat
			, &brushText);
	}
	else
	{
		m_pGraphics->DrawString((LPCWSTR)strLabelW
			, -1
			, m_pFont
			, rcLabelF
			, &m_FontFormat
			, &brushText);
	}
}
Exemple #11
0
void Definition::GetAsNumber(Number<T>& n, StringMapW<T>* n2n)
{
    CStringW str = m_value;
    str.Replace(L" ", L"");

    n.value = 0;
    n.unit = m_unit;
    n.sign = 0;

    if(n2n)
    {
        if(m_status == node) throw Exception(_T("expected value type"));

        if(StringMapW<T>::CPair* p = n2n->Lookup(str))
        {
            n.value = p->m_value;
            return;
        }
    }

    if(m_status != number) throw Exception(_T("expected number"));

    n.sign = str.Find('+') == 0 ? 1 : str.Find('-') == 0 ? -1 : 0;
    str.TrimLeft(L"+-");

    if(str.Find(L"0x") == 0)
    {
        if(n.sign) throw Exception(_T("hex values must be unsigned"));

        n.value = (T)wcstoul(str.Mid(2), NULL, 16);
    }
    else
    {
        CStringW num_string = m_value + m_unit;

        if(m_num_string != num_string)
        {
            Split sa(':', str);
            Split sa2('.', sa ? sa[sa-1] : L"");

            if(sa == 0 || sa2 == 0 || sa2 > 2) throw Exception(_T("invalid number"));

            float f = 0;
            for(size_t i = 0; i < sa; i++)
            {
                f *= 60;
                f += wcstoul(sa[i], NULL, 10);
            }
            if(sa2 > 1) f += (float)wcstoul(sa2[1], NULL, 10) / pow((float)10, sa2[1].GetLength());

            if(n.unit == L"ms")
            {
                f /= 1000;
                n.unit = L"s";
            }
            else if(n.unit == L"m")
            {
                f *= 60;
                n.unit = L"s";
            }
            else if(n.unit == L"h")
            {
                f *= 3600;
                n.unit = L"s";
            }

            m_num.value = f;
            m_num.unit = n.unit;
            m_num_string = num_string;

            n.value = (T)f;
        }
        else
        {
            n.value = (T)m_num.value;
            n.unit = m_num.unit;
        }

        if(n.sign) n.value *= n.sign;
    }
}
HRESULT CStreamSwitcherInputPin::CompleteConnect(IPin* pReceivePin)
{
	HRESULT hr = __super::CompleteConnect(pReceivePin);
	if (FAILED(hr)) {
		return hr;
	}

	(static_cast<CStreamSwitcherFilter*>(m_pFilter))->CompleteConnect(PINDIR_INPUT, this, pReceivePin);

	m_fCanBlock = false;
	bool fForkedSomewhere = false;

	CStringW fileName;
	CStringW pinName;

	IPin* pPin = (IPin*)this;
	IBaseFilter* pBF = (IBaseFilter*)m_pFilter;

	pPin = GetUpStreamPin(pBF, pPin);
	if (pPin) {
		pBF = GetFilterFromPin(pPin);
	}
	while (pPin && pBF) {
		if (IsSplitter(pBF)) {
			pinName = GetPinName(pPin);
		}

		CLSID clsid = GetCLSID(pBF);
		if (clsid == CLSID_AviSplitter || clsid == CLSID_OggSplitter) {
			m_fCanBlock = true;
		}

		int nIn, nOut, nInC, nOutC;
		CountPins(pBF, nIn, nOut, nInC, nOutC);
		fForkedSomewhere = fForkedSomewhere || nIn > 1 || nOut > 1;

		if (CComQIPtr<IFileSourceFilter> pFSF = pBF) {
			WCHAR* pszName = NULL;
			AM_MEDIA_TYPE mt;
			if (SUCCEEDED(pFSF->GetCurFile(&pszName, &mt)) && pszName) {
				fileName = pszName;
				CoTaskMemFree(pszName);

				fileName.Replace('\\', '/');
				CStringW fn = fileName.Mid(fileName.ReverseFind('/')+1);
				if (!fn.IsEmpty()) {
					fileName = fn;
				}

				// Haali & LAVFSplitter return only one "Audio" pin name, cause CMainFrame::OnInitMenuPopup lookup find the wrong popmenu,
				// add space at the end to prevent this, internal filter never return "Audio" only.
				if (!pinName.IsEmpty()) {
					fileName = pinName + L" ";
				}

				WCHAR* pName = DNew WCHAR[fileName.GetLength()+1];
				if (pName) {
					wcscpy_s(pName, fileName.GetLength() + 1, fileName);
					if (m_pName) {
						delete [] m_pName;
					}
					m_pName = pName;
				}
			}

			break;
		}

		pPin = GetFirstPin(pBF);

		pPin = GetUpStreamPin(pBF, pPin);
		if (pPin) {
			pBF = GetFilterFromPin(pPin);
		}
	}

	if (!fForkedSomewhere) {
		m_fCanBlock = true;
	}

	m_hNotifyEvent = NULL;

	return S_OK;
}