Esempio n. 1
0
void CChunkRenderText::StoreSamples(const std::vector<const CDSample*> &Samples)
{
	// Store DPCM samples in file, assembly format
	CStringA str;
	str.Format("\n; DPCM samples (located at DPCM segment)\n");
	WriteFileString(str, m_pFile);

	if (Samples.size() > 0) {
		str.Format("\n\t.segment \"DPCM\"\n");
		WriteFileString(str, m_pFile);
	}

	unsigned int Address = CCompiler::PAGE_SAMPLES;
	for (size_t i = 0; i < Samples.size(); ++i) {
		const CDSample *pDSample = Samples[i];
		const unsigned int SampleSize = pDSample->GetSize();
		const char *pData = pDSample->GetData();
		
		CStringA label;
		label.Format(CCompiler::LABEL_SAMPLE, i);
		str.Format("%s: ; %s\n", LPCSTR(label), pDSample->GetName());
		StoreByteString(pData, SampleSize, str, DEFAULT_LINE_BREAK);
		Address += SampleSize;

		// Adjust if necessary
		if ((Address & 0x3F) > 0) {
			int PadSize = 0x40 - (Address & 0x3F);
			Address	+= PadSize;
			str.Append("\n\t.align 64\n");
		}

		str.Append("\n");
		WriteFileString(str, m_pFile);
	}
}
Esempio n. 2
0
void CChunkRenderText::StoreWavesChunk(CChunk *pChunk, CFile *pFile)
{
	CStringA str;
	int len = pChunk->GetLength();

//				int waves = pChunk->GetData(0);
	int wave_len = 16;//(len - 1) / waves;

	// Namco waves
	str.Format("%s:\n", pChunk->GetLabel());
//				str.AppendFormat("\t.byte %i\n", waves);
	
	str.Append("\t.byte ");

	for (int i = 0; i < len; ++i) {
		str.AppendFormat("$%02X", pChunk->GetData(i));
		if ((i % wave_len == (wave_len - 1)) && (i < len - 1))
			str.Append("\n\t.byte ");
		else {
			if (i < len - 1)
				str.Append(", ");
		}
	}

	str.Append("\n");

	m_wavesStrings.Add(str);
}
Esempio n. 3
0
void KEditDialogImpl::_DrawSelRect(CStringA& strNowXml)
{
    if (m_pNowComp != NULL)
    {
        CStringA strTmp;
        CRect rect;
        m_pNowComp->GetCompRect(rect);

        // top
        strTmp.Format("<hr class=\"line_style\" pos=\"%d,%d,%d,%d\"/>", 
            rect.left, rect.top, rect.right, rect.top);
        strNowXml.Append(strTmp);

        // bottom
        strTmp.Format("<hr class=\"line_style\" pos=\"%d,%d,%d,%d\"/>", 
            rect.left, rect.bottom, rect.right, rect.bottom);
        strNowXml.Append(strTmp);

        // left
        strTmp.Format("<hr class=\"line_style\" pos=\"%d,%d,%d,%d\"/>", 
            rect.left, rect.top, rect.left, rect.bottom);
        strNowXml.Append(strTmp);

        // right
        strTmp.Format("<hr class=\"line_style\" pos=\"%d,%d,%d,%d\"/>", 
            rect.right, rect.top, rect.right, rect.bottom);

        strNowXml.Append(strTmp);
    }
}
Esempio n. 4
0
void CChunkRenderText::StoreByteString(const char *pData, int Len, CStringA &str, int LineBreak) const
{	
	str.Append("\t.byte ");

	for (int i = 0; i < Len; ++i) {
		str.AppendFormat("$%02X", (unsigned char)pData[i]);

		if ((i % LineBreak == (LineBreak - 1)) && (i < Len - 1))
			str.Append("\n\t.byte ");
		else if (i < Len - 1)
			str.Append(", ");
	}

	str.Append("\n");
}
Esempio n. 5
0
void CWinLogFile::Log(DWORD dwLogLevel, LPCWSTR lpszText)
{
    if (!IsLevelEnabled(dwLogLevel))
        return;

    if (!CAtlFile::m_h || INVALID_HANDLE_VALUE == CAtlFile::m_h)
        return;

    CStringA strLogLine;

    
    SYSTEMTIME  localTime;
    ::GetLocalTime(&localTime);
    strLogLine.AppendFormat(
        "[%04hu-%02hu-%02hu %02hu:%02hu:%02hu.%03hu] ",
        localTime.wYear,
        localTime.wMonth,
        localTime.wDay,
        localTime.wHour,
        localTime.wMinute,
        localTime.wSecond,
        localTime.wMilliseconds);

    
    strLogLine.AppendFormat("[%lu] ", GetCurrentThreadId());

    
    strLogLine.AppendFormat("[%s] ", GetLogLevelNameA(dwLogLevel));

    
    strLogLine.Append(": ");
    strLogLine.Append(CW2A(lpszText));

    
    CHAR chLast = strLogLine[strLogLine.GetLength() - 1];
    if ('\r' != chLast && '\n' != chLast)
    {
        strLogLine.Append("\r\n");
    }


    
    {
        CObjGuard guard(m_queueLock);

        HRESULT hr = CAtlFile::Write(strLogLine, strLogLine.GetLength());
    }
}
Esempio n. 6
0
void CChunkRenderText::StoreFrameChunk(CChunk *pChunk, CFile *pFile)
{
	CStringA str;
	int len = pChunk->GetLength();

	// Frame list
	str.Format("%s:\n\t.word ", pChunk->GetLabel());

	for (int i = 0, j = 0; i < len; ++i) {
		if (pChunk->IsDataReference(i))
			str.AppendFormat("%s%s", (j++ > 0) ? _T(", ") : _T(""), pChunk->GetDataRefName(i));
	}

	// Bank values
	for (int i = 0, j = 0; i < len; ++i) {
		if (pChunk->IsDataBank(i)) {
			if (j == 0) {
				str.AppendFormat("\n\t.byte ", pChunk->GetLabel());
			}
			str.AppendFormat("%s$%02X", (j++ > 0) ? _T(", ") : _T(""), pChunk->GetData(i));
		}
	}

	str.Append("\n");

	m_songDataStrings.Add(str);
}
Esempio n. 7
0
void CChunkRenderText::StorePatternChunk(CChunk *pChunk, CFile *pFile)
{
	CStringA str;
	int len = pChunk->GetLength();

	// Patterns
	str.Format("; Bank %i\n", pChunk->GetBank());
	str.AppendFormat("%s:\n", pChunk->GetLabel());

	const std::vector<char> &vec = pChunk->GetStringData(0);
	len = vec.size();

	StoreByteString(&vec.front(), vec.size(), str, DEFAULT_LINE_BREAK);
/*
	for (int i = 0; i < len; ++i) {
		str.AppendFormat("$%02X", (unsigned char)vec[i]);
		if ((i % 20 == 19) && (i < len - 1))
			str.Append("\n\t.byte ");
		else {
			if (i < len - 1)
				str.Append(", ");
		}
	}
*/
	str.Append("\n");

	m_songDataStrings.Add(str);
}
Esempio n. 8
0
DWORD CALLBACK CRichEditStream::StreamOutCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
	CStringA* pStreamBuffA = (CStringA*)dwCookie;
	pStreamBuffA->Append((LPCSTR)pbBuff, cb);
	*pcb = cb;
	return 0;
}
Esempio n. 9
0
void CChunkRenderText::StoreInstrumentChunk(CChunk *pChunk, CFile *pFile)
{
	CStringA str;
	int len = pChunk->GetLength();

	str.Format("%s:\n\t.byte %i\n", pChunk->GetLabel(), pChunk->GetData(0));

	for (int i = 1; i < len; ++i) {
		if (pChunk->IsDataReference(i)) {
			str.AppendFormat("\t.word %s\n", pChunk->GetDataRefName(i));
		}
		else {
			if (pChunk->GetDataSize(i) == 1) {
				str.AppendFormat("\t.byte $%02X\n", pChunk->GetData(i));
			}
			else {
				str.AppendFormat("\t.word $%04X\n", pChunk->GetData(i));
			}
		}
	}

	str.Append("\n");

	m_instrumentStrings.Add(str);
}
Esempio n. 10
0
void CSendGetUrlReqSocket::OnConnect(int nErrorCode)
{
	if (0 != nErrorCode)
	{
		if (thePrefs.GetVerbose())
		{
			CString		strUrlPath(GetUrlPath());
			CString		strServer(GetServer());

			strUrlPath.Replace(_T("%"), _T("%%"));
			AddDebugLogLine(false, _T("将要取%s,但连接%s返回失败。"), strUrlPath, strServer);
		}

		return;
	}

	CStringA strHttpRequest;
	strHttpRequest.AppendFormat("%s %s HTTP/1.0\r\n", m_bIsPost ? "POST" : "GET", GetUrlPath());
	strHttpRequest.AppendFormat("Host: %s\r\n", GetServer());
	strHttpRequest.AppendFormat("Accept: */*\r\n");
	if(m_bIsPost)
	{
		strHttpRequest.AppendFormat("Accept-Encoding: none\r\n");
		strHttpRequest.AppendFormat("Content-Type: application/x-www-form-urlencoded\r\n");
		strHttpRequest.AppendFormat("Content-Length: %d\r\n", m_strPost.GetLength());
	}
	//strHttpRequest.AppendFormat("Connection: Keep-Alive\r\n");
	strHttpRequest.Append("\r\n");
	if(m_bIsPost)
	{
		strHttpRequest.Append(m_strPost);
	}

	if (thePrefs.GetVerbose())
	{
		CString		strRequest(strHttpRequest);
		strRequest.Replace(_T("%"), _T("%%"));

		AddDebugLogLine(false, _T("与服务器 %s 连接成功,准备发送:"), CString(GetServer()));
		AddDebugLogLine(false, strRequest);
	}


	CRawPacket* pHttpPacket = new CRawPacket(strHttpRequest);
	SendPacket(pHttpPacket);
	SetHttpState(HttpStateRecvExpected);
}
Esempio n. 11
0
void CChunkRenderText::StoreByteString(const CChunk *pChunk, CStringA &str, int LineBreak) const
{
	int len = pChunk->GetLength();
	
	str.Append("\t.byte ");

	for (int i = 0; i < len; ++i) {
		str.AppendFormat("$%02X", pChunk->GetData(i));

		if ((i % LineBreak == (LineBreak - 1)) && (i < len - 1))
			str.Append("\n\t.byte ");
		else if (i < len - 1)
			str.Append(", ");
	}

	str.Append("\n");
}
Esempio n. 12
0
void CChunkRenderText::StoreSamplePointersChunk(CChunk *pChunk, CFile *pFile)
{
	CStringA str;
	int len = pChunk->GetLength();

	// Store sample pointer
	str.Format("%s:\n", pChunk->GetLabel());

	if (len > 0) {
		str.Append("\t.byte ");

		int len = pChunk->GetLength();
		for (int i = 0; i < len; ++i) {
			str.AppendFormat("%i%s", pChunk->GetData(i), (i < len - 1) && (i % 3 != 2) ? ", " : "");
			if (i % 3 == 2 && i < (len - 1))
				str.Append("\n\t.byte ");
		}
	}

	str.Append("\n");

	m_samplePointersStrings.Add(str);
}
Esempio n. 13
0
CStringA urlencode(CStringA str)
{
    CStringA escaped;
	int max = str.GetLength();
    for(int i=0; i<max; i++)
    {
		const char chr = str.GetAt(i);
        if ( (48 <= chr && chr <= 57) ||//0-9
             (65 <= chr && chr <= 90) ||//abc...xyz
             (97 <= chr && chr <= 122) || //ABC...XYZ
             (chr=='~' || chr=='!' || chr=='*' || chr=='(' || chr==')' || chr=='\'')
        )
        {
			escaped.AppendFormat("%c",chr);
        }
        else
        {
            escaped.Append("%");
            escaped.Append(char2hex(chr));//converts char 255 to string "ff"
        }
    }
    return escaped;
}
Esempio n. 14
0
void CChunkRenderText::StoreWavetableChunk(CChunk *pChunk, CFile *pFile)
{
	CStringA str;
	int len = pChunk->GetLength();

	// FDS waves
	str.Format("%s:\n", pChunk->GetLabel());
	str.Append("\t.byte ");

	for (int i = 0; i < len; ++i) {
		str.AppendFormat("$%02X", pChunk->GetData(i));
		if ((i % 64 == 63) && (i < len - 1))
			str.Append("\n\t.byte ");
		else {
			if (i < len - 1)
				str.Append(", ");
		}
	}

	str.Append("\n");

	m_wavetableStrings.Add(str);
}
Esempio n. 15
0
void CSubtitleDlDlg::OnOK()
{
	SetStatus(ResStr(IDS_SUBDL_DLG_DOWNLOADING));

	for (int i = 0; i < m_list.GetItemCount(); ++i) {
		if (m_list.GetCheck(i)) {
			m_selsubs.AddTail(*reinterpret_cast<isdb_subtitle*>(m_list.GetItemData(i)));
		}
	}

	m_fReplaceSubs = IsDlgButtonChecked(IDC_CHECK1) == BST_CHECKED;

	CMainFrame* pMF = static_cast<CMainFrame*>(GetParentFrame());

	if (m_fReplaceSubs) {
		pMF->m_pSubStreams.RemoveAll();
	}

	CComPtr<ISubStream> pSubStreamToSet;

	POSITION pos = m_selsubs.GetHeadPosition();

	while (pos) {
		const isdb_subtitle& sub = m_selsubs.GetNext(pos);
		AppSettings& s = AfxGetAppSettings();
		CInternetSession is;
		CStringA url = "http://" + s.strISDb + "/dl.php?";
		CStringA args, ticket, str;
		args.Format("id=%d&ticket=%s", sub.id, UrlEncode(ticket), true);
		url.Append(args);

		if (OpenUrl(is, CString(url), str)) {
			CAutoPtr<CRenderedTextSubtitle> pRTS(DNew CRenderedTextSubtitle(&pMF->m_csSubLock, &s.subdefstyle, s.fUseDefaultSubtitlesStyle));
			if (pRTS && pRTS->Open((BYTE*)(LPCSTR)str, str.GetLength(), DEFAULT_CHARSET, CString(sub.name)) && pRTS->GetStreamCount() > 0) {
				CComPtr<ISubStream> pSubStream = pRTS.Detach();
				pMF->m_pSubStreams.AddTail(pSubStream);

				if (!pSubStreamToSet) {
					pSubStreamToSet = pSubStream;
				}
			}
		}
	}

	if (pSubStreamToSet) {
		pMF->SetSubtitle(pSubStreamToSet);
	}

	__super::OnOK();
}
static CStringA RegexEscape(CStringA str)
{
	CStringA result;
	for (int i = 0; i < str.GetLength(); ++i)
	{
		char c = str[i];
		switch (c)
		{
			case '\\': case '*': case '+': case '?': case '|':
			case '{': case '[': case '(': case ')': case '^':
			case '$': case '.': case '#': case ' ':
				result.AppendChar('\\');
				result.AppendChar(c);
				break;
			case '\t': result.Append("\\t"); break;
			case '\n': result.Append("\\n"); break;
			case '\r': result.Append("\\r"); break;
			case '\f': result.Append("\\f"); break;
			default: result.AppendChar(c); break;
		}
	}

	return result;
}
Esempio n. 17
0
inline CStringA ZLStrConv::w2a( LPCWSTR lpBuf, UINT uCodePage, int nBufLen )
{
    CStringA sRetA;
    int nDstLen = ::WideCharToMultiByte( uCodePage, 0, lpBuf, nBufLen, NULL, 0, NULL, NULL );
    if (nDstLen > 0)
    {
        char* pResult = new char[nDstLen];
        BOOL bSuc = (0 < ::WideCharToMultiByte( uCodePage, 0, lpBuf, nBufLen, pResult, nDstLen, NULL, NULL ));
        if (bSuc)
        {
            sRetA.Append(pResult, nDstLen - 1);
        }
        delete[] pResult;
    }
    return sRetA;
}
Esempio n. 18
0
STDMETHODIMP CBHttpRequest::Open(BSTR strMethod, BSTR strUrl, VARIANT_BOOL bAsync, VARIANT varUser, VARIANT varPassword)
{
    CUrl url;
    CStringA strObject;
    CStringA strUser;
    CStringA strPassword;

    Abort();

    s_cs.Enter();
    s_dwReqID ++;
    m_dwReqID = s_dwReqID;
    s_mapReq.SetAt(m_dwReqID, this);
    s_cs.Leave();

    url.CrackUrl(CBStringA(strUrl));
    m_bAsync = (bAsync != VARIANT_FALSE);

    strObject = url.GetUrlPath();
    strObject.Append(url.GetExtraInfo());

    if(varUser.vt != VT_ERROR)
    {
        HRESULT hr = varGetString(varUser, strUser);
        if(FAILED(hr))return hr;
    }

    if(varPassword.vt != VT_ERROR)
    {
        HRESULT hr = varGetString(varPassword, strPassword);
        if(FAILED(hr))return hr;
    }

    m_hConnection = InternetConnect(m_hSession, url.GetHostName(), url.GetPortNumber(),
                                    strUser.IsEmpty() ? NULL : (LPCSTR)strUser, strPassword.IsEmpty() ? NULL : (LPCSTR)strPassword,
                                    INTERNET_SERVICE_HTTP, 0, m_dwReqID);
    if(m_hConnection == NULL)
        return GetErrorResult();

    m_hFile = HttpOpenRequest(m_hConnection, CBStringA(strMethod), strObject, NULL, NULL, NULL, m_dwFlags, m_dwReqID);
    if(m_hFile == NULL)
        return GetErrorResult();

    m_eventComplete.Set();

    return S_OK;
}
Esempio n. 19
0
void CChunkRenderText::StoreSongChunk(CChunk *pChunk, CFile *pFile)
{
	CStringA str;

	str.Format("%s:\n", pChunk->GetLabel());

	for (int i = 0; i < pChunk->GetLength();) {
		str.AppendFormat("\t.word %s\n", pChunk->GetDataRefName(i++));
		str.AppendFormat("\t.byte %i\t; frame count\n", pChunk->GetData(i++));
		str.AppendFormat("\t.byte %i\t; pattern length\n", pChunk->GetData(i++));
		str.AppendFormat("\t.byte %i\t; speed\n", pChunk->GetData(i++));
		str.AppendFormat("\t.byte %i\t; tempo\n", pChunk->GetData(i++));
		str.AppendFormat("\t.byte %i\t; initial bank\n", pChunk->GetData(i++));
	}

	str.Append("\n");

	m_songStrings.Add(str);
}
Esempio n. 20
0
void GetNetworkInterfaces(CStringArray & interfaces, bool includeNames)
{
  // Get interfaces
  BYTE * buffer = NULL;
  ULONG size = 0;
  DWORD error = GetIpAddrTable(NULL, &size, FALSE);
  if (error == ERROR_INSUFFICIENT_BUFFER) {
    buffer = new BYTE[size];
    if (buffer != NULL)
      error = GetIpAddrTable((MIB_IPADDRTABLE *)buffer, &size, FALSE);
  }

  if (error == ERROR_SUCCESS) {
    const MIB_IPADDRTABLE * ipaddr = (const MIB_IPADDRTABLE *)buffer;
    for (unsigned i = 0; i < ipaddr->dwNumEntries; ++i) {
      in_addr ip;
      ip.S_un.S_addr = ipaddr->table[i].dwAddr;
      if (ntohl(ip.S_un.S_addr) != INADDR_LOOPBACK) {
        CStringA iface;
        if (ip.S_un.S_addr != INADDR_ANY)
          iface = inet_ntoa(ip);

        if (includeNames) {
          MIB_IFROW info;
          info.dwIndex = ipaddr->table[i].dwIndex;
          if (GetIfEntry(&info) == NO_ERROR && info.dwDescrLen > 0) {
            iface += '%';
            iface.Append((const char *)info.bDescr, info.dwDescrLen);
          }
        }

        if (!iface.IsEmpty())
          interfaces.Add(CString(iface));
      }
    }
  }
  delete [] buffer;
}
Esempio n. 21
0
bool netbios_name::GetRealSender (UCHAR lsn, CStringA& sRealFrom) const
{
	sRealFrom.Empty ();

	SESSION_INFO_BLOCK sibSession = {};
	UCHAR dwInfoRes = pluginNetBIOS.Stat( *this, &sibSession );
	if ( dwInfoRes == NRC_GOODRET )
	{
		for ( int i = 0; i < sibSession.sib_header.num_sess; i++ )
		{
			if ( sibSession.sib_Names [i].lsn == lsn )
			{
				// Наша сессия
				const char* n = (const char*)sibSession.sib_Names [i].remote_name;
				BYTE j = NCBNAMSZ - 2;
				for ( ; j && ( n [ j ] == ' ' ); --j );
				sRealFrom.Append( n, j + 1 );
				sRealFrom.OemToAnsi();
				return true;
			}
		}
	}
	return false;
}
Esempio n. 22
0
BOOL CFileTextLines::Save(const CString& sFilePath, bool bSaveAsUTF8, DWORD dwIgnoreWhitespaces /*=0*/, BOOL bIgnoreCase /*= FALSE*/, bool bBlame /*= false*/)
{
	try
	{
		CString destPath = sFilePath;
		// now make sure that the destination directory exists
		int ind = 0;
		while (destPath.Find('\\', ind)>=2)
		{
			if (!PathIsDirectory(destPath.Left(destPath.Find('\\', ind))))
			{
				if (!CreateDirectory(destPath.Left(destPath.Find('\\', ind)), NULL))
					return FALSE;
			}
			ind = destPath.Find('\\', ind)+1;
		}

		CStdioFile file;			// Hugely faster than CFile for big file writes - because it uses buffering
		if (!file.Open(sFilePath, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary))
		{
			m_sErrorString.Format(IDS_ERR_FILE_OPEN, (LPCTSTR)sFilePath);
			return FALSE;
		}
		if ((!bSaveAsUTF8)&&(m_UnicodeType == CFileTextLines::UNICODE_LE))
		{
			//first write the BOM
			UINT16 wBOM = 0xFEFF;
			file.Write(&wBOM, 2);
			for (int i=0; i<GetCount(); i++)
			{
				CString sLine = GetAt(i);
				EOL ending = GetLineEnding(i);
				StripWhiteSpace(sLine,dwIgnoreWhitespaces, bBlame);
				if (bIgnoreCase)
					sLine = sLine.MakeLower();
				file.Write((LPCTSTR)sLine, sLine.GetLength()*sizeof(TCHAR));
				if (ending == EOL_AUTOLINE)
					ending = m_LineEndings;
				switch (ending)
				{
				case EOL_CR:
					sLine = _T("\x0d");
					break;
				case EOL_CRLF:
				case EOL_AUTOLINE:
					sLine = _T("\x0d\x0a");
					break;
				case EOL_LF:
					sLine = _T("\x0a");
					break;
				case EOL_LFCR:
					sLine = _T("\x0a\x0d");
					break;
				default:
					sLine.Empty();
					break;
				}
				if ((m_bReturnAtEnd)||(i != GetCount()-1))
					file.Write((LPCTSTR)sLine, sLine.GetLength()*sizeof(TCHAR));
			}
		}
		else if ((!bSaveAsUTF8)&&((m_UnicodeType == CFileTextLines::ASCII)||(m_UnicodeType == CFileTextLines::AUTOTYPE)))
		{
			for (int i=0; i< GetCount(); i++)
			{
				// Copy CString to 8 bit without conversion
				CString sLineT = GetAt(i);
				CStringA sLine = CStringA(sLineT);
				EOL ending = GetLineEnding(i);

				StripAsciiWhiteSpace(sLine,dwIgnoreWhitespaces, bBlame);
				if (bIgnoreCase)
					sLine = sLine.MakeLower();
				if ((m_bReturnAtEnd)||(i != GetCount()-1))
				{
					if (ending == EOL_AUTOLINE)
						ending = m_LineEndings;
					switch (ending)
					{
					case EOL_CR:
						sLine += '\x0d';
						break;
					case EOL_CRLF:
					case EOL_AUTOLINE:
						sLine.Append("\x0d\x0a", 2);
						break;
					case EOL_LF:
						sLine += '\x0a';
						break;
					case EOL_LFCR:
						sLine.Append("\x0a\x0d", 2);
						break;
					}
				}
				file.Write((LPCSTR)sLine, sLine.GetLength());
			}
		}
		else if ((bSaveAsUTF8)||((m_UnicodeType == CFileTextLines::UTF8BOM)||(m_UnicodeType == CFileTextLines::UTF8)))
		{
			if (m_UnicodeType == CFileTextLines::UTF8BOM)
			{
				//first write the BOM
				UINT16 wBOM = 0xBBEF;
				file.Write(&wBOM, 2);
				UINT8 uBOM = 0xBF;
				file.Write(&uBOM, 1);
			}
			for (int i=0; i<GetCount(); i++)
			{
				CStringA sLine = CUnicodeUtils::GetUTF8(GetAt(i));
				EOL ending = GetLineEnding(i);
				StripAsciiWhiteSpace(sLine,dwIgnoreWhitespaces, bBlame);
				if (bIgnoreCase)
					sLine = sLine.MakeLower();

				if ((m_bReturnAtEnd)||(i != GetCount()-1))
				{
					if (ending == EOL_AUTOLINE)
						ending = m_LineEndings;
					switch (ending)
					{
					case EOL_CR:
						sLine += '\x0d';
						break;
					case EOL_CRLF:
					case EOL_AUTOLINE:
						sLine.Append("\x0d\x0a",2);
						break;
					case EOL_LF:
						sLine += '\x0a';
						break;
					case EOL_LFCR:
						sLine.Append("\x0a\x0d",2);
						break;
					}
				}
				file.Write((LPCSTR)sLine, sLine.GetLength());
			}
		}
		file.Close();
	}
	catch (CException * e)
	{
		e->GetErrorMessage(m_sErrorString.GetBuffer(4096), 4096);
		m_sErrorString.ReleaseBuffer();
		e->Delete();
		return FALSE;
	}
	return TRUE;
}
Esempio n. 23
0
void CpeepmBrowser::OnBnClickedBrowserButton()
{
    CStringA tmp = "http://";
    tmp.Append(Server);
    CString server(tmp);

    CString content = _T("");
    m_Edit.GetWindowText(content);
    if (content.GetLength() > 0 && content.Find(server) > -1)
    {
        TCHAR tmp[1024] = {0};
        GetModuleFileName(NULL, tmp, sizeof(tmp));
        CString path = tmp;
        path = path.Left(path.ReverseFind('\\'));
        path.Append(_T("\\"));

        CFileDialog open(TRUE);
        open.m_ofn.lpstrTitle = _T("选择账号");
        open.m_ofn.lpstrInitialDir = path;
        INT_PTR resp = open.DoModal();
        if (resp == IDOK)
        {
            CString path = open.GetPathName();

            char* url = CpeepmUtil::WideCharToChar(content, content.GetLength());
            if (url == NULL)
                return;

            char* p = CpeepmUtil::WideCharToChar(path, path.GetLength());

            CpeepmDlg* parent = (CpeepmDlg*)GetParent();
            m_ThreadMax = 1;
            DWORD delay = parent->GetDelay();

            BOOL* success = new BOOL;
            *success = FALSE;
            CCriticalSection* section = new CCriticalSection();
            CEvent* event = new CEvent(FALSE, TRUE, NULL, NULL);
            PeepmBrowser* browser = new PeepmBrowser();
            browser->path = p;
            browser->username = NULL;
            browser->password = NULL;
            browser->next = NULL;
            browser->use = FALSE;
            browser->section = NULL;

            m_Crack = new CpeepmCrack*[m_ThreadMax];

            for (UINT i = 0; i < m_ThreadMax; i++)
            {
                CpeepmCrack* crack = new CUrlBrowser(browser, url, success, i, m_ThreadMax, delay, section, event, NULL, *this);
                m_Crack[i] = crack;
                CWinThread* thread = AfxBeginThread(CpeepmCrack::OnThread, crack);
                crack->SetThread(thread);
            }

            CWinThread* thread = AfxBeginThread(CUrlBrowser::InitAccount, m_Crack[0]);
            m_Button.EnableWindow(FALSE);
        }
    }
}
Esempio n. 24
0
int CBoxScript::ParseScriptText(LPCSTR pstrText, int nCount, CStringA& strScriptText, int nIncludeFlagIndex)
{
	CStringA strTempText;
	if(nCount >= 2 && (BYTE)pstrText[0] == 0xff && (BYTE)pstrText[1] == 0xfe)
	{
/*		int _nTempCount = WideCharToMultiByte(_AtlGetConversionACP(), 0, LPWSTR(pstrText + 2), (nCount - 2) / 2, NULL, 0, NULL, NULL);
		LPSTR _pstr = strTempText.GetBuffer(_nTempCount);

		WideCharToMultiByte(_AtlGetConversionACP(), 0, LPWSTR(pstrText + 2), (nCount - 2) / 2, _pstr, _nTempCount, NULL, NULL);
		strTempText.ReleaseBuffer(_nTempCount);
*/

//发现是Unicode则检查是否已经存在CodePage,存在就转换到当前CodePage,否则转换成UTF8同时设定m_CodePage为65001
		if (m_uiCodePage == 0)
			m_uiCodePage = CP_UTF8;

		int _nTempCount = WideCharToMultiByte(m_uiCodePage, 0, LPWSTR(pstrText + 2), (nCount - 2) / 2, NULL, 0, NULL, NULL);
		LPSTR _pstr = strTempText.GetBuffer(_nTempCount);

		WideCharToMultiByte(m_uiCodePage, 0, LPWSTR(pstrText + 2), (nCount - 2) / 2, _pstr, _nTempCount, NULL, NULL);
		strTempText.ReleaseBuffer(_nTempCount);

		pstrText = strTempText;
		nCount = strTempText.GetLength();
	}
	else if(nCount >= 3 && (BYTE)pstrText[0] == 0xEF && (BYTE)pstrText[1] == 0xBB && (BYTE)pstrText[2] == 0xBF)
	{
		pstrText += 3;
		nCount -= 3;

		if (m_uiCodePage && m_uiCodePage != CP_UTF8)
		{
			CStringW strTempTextW;
			int _nTempCount = MultiByteToWideChar(CP_UTF8, 0, pstrText, nCount, NULL, 0);
			LPWSTR _pstrW = strTempTextW.GetBuffer(_nTempCount);

			MultiByteToWideChar(CP_UTF8, 0, pstrText, nCount, _pstrW, _nTempCount);
			strTempTextW.ReleaseBuffer(_nTempCount);
			
			_nTempCount = WideCharToMultiByte(m_uiCodePage, 0, strTempTextW, strTempTextW.GetLength(), NULL, 0, NULL, NULL);
			LPSTR _pstr = strTempText.GetBuffer(_nTempCount);

			WideCharToMultiByte(m_uiCodePage, 0, strTempTextW, strTempTextW.GetLength(), _pstr, _nTempCount, NULL, NULL);
			strTempText.ReleaseBuffer(_nTempCount);

			pstrText = strTempText;
			nCount = strTempText.GetLength();
		}
		else
			m_uiCodePage = CP_UTF8;
	}
	else
	{
		UINT uiCodePage = ParseScriptTextCodePage(pstrText, nCount);
		if (uiCodePage == 0)
			uiCodePage = GetACP();

		//if (m_uiCodePage == 0)
		//	m_uiCodePage = CP_UTF8;

		if (m_uiCodePage && m_uiCodePage != uiCodePage)
		{
			CStringW strTempTextW;
			int _nTempCount = MultiByteToWideChar(uiCodePage, 0, pstrText, nCount, NULL, 0);
			LPWSTR _pstrW = strTempTextW.GetBuffer(_nTempCount);

			MultiByteToWideChar(uiCodePage, 0, pstrText, nCount, _pstrW, _nTempCount);
			strTempTextW.ReleaseBuffer(_nTempCount);
			
			_nTempCount = WideCharToMultiByte(m_uiCodePage, 0, strTempTextW, strTempTextW.GetLength(), NULL, 0, NULL, NULL);
			LPSTR _pstr = strTempText.GetBuffer(_nTempCount);

			WideCharToMultiByte(m_uiCodePage, 0, strTempTextW, strTempTextW.GetLength(), _pstr, _nTempCount, NULL, NULL);
			strTempText.ReleaseBuffer(_nTempCount);

			pstrText = strTempText;
			nCount = strTempText.GetLength();
		}
		else
		{
			m_uiCodePage = uiCodePage;
		}
	}

	static struct
	{
		char *pstrName;
		int nSize;
	}CmdName[] =
	{
		{"#include", 8},
		{"#language", 9},
		{"#debug", 6},
		{"#timeout", 8},
		{"#transaction", 12},
		{"#codepage", 9}
	};
	#define CMD_COUNT (sizeof(CmdName) / sizeof(CmdName[0]))
	int i;
	LPCSTR pstrTemp, pstrTemp1;
	int nTempCount;
	int nLineCount = 1;

	while(nCount > 0 && IsBlank(pstrText[0]))
	{
		if(pstrText[0] == '\n')
			nLineCount ++;

		pstrText ++;
		nCount --;
	}

	while(nCount > 0 && pstrText[0] == '#')
	{
		for(i = 0; i < CMD_COUNT; i ++)
			if(nCount > CmdName[i].nSize &&
				!_strnicmp(pstrText, CmdName[i].pstrName, CmdName[i].nSize) &&
				IsBlankChar(pstrText[CmdName[i].nSize]))
				break;

		if(i == CMD_COUNT)
			break;

		pstrText += CmdName[i].nSize;
		nCount -= CmdName[i].nSize;

		while(nCount > 0 && IsBlankChar(pstrText[0]))
		{
			pstrText ++;
			nCount --;
		}

		if(nCount > 0 && pstrText[0] == '\"')
		{
			pstrText ++;
			nCount --;
		}

		pstrTemp = pstrText;
		nTempCount = nCount;
		while(nTempCount > 0 && !IsLineChar(pstrTemp[0]))
		{
			pstrTemp ++;
			nTempCount --;
		}

		pstrTemp1 = pstrTemp;
		while(pstrTemp1 > pstrText && IsBlankChar(pstrTemp1[0]))
			pstrTemp1 --;

		if(pstrTemp1 > pstrText && pstrTemp1[-1] == '\"')
			pstrTemp1 --;

		CStringA strValue;

		strValue.SetString(pstrText, (int)(pstrTemp1 - pstrText));

		pstrText = pstrTemp;
		nCount = nTempCount;

		switch(i)
		{
		case 0:
			strValue.MakeLower();
			if(LoadScriptFile(BOX_CA2CT(strValue), strScriptText, nLineCount))
				return 500;
			break;
		case 1:
			m_strLanguage = strValue;
			break;
		case 2:
			m_bEnableDebug = !strValue.CompareNoCase("on") || !strValue.CompareNoCase("true");
			if(!strValue.CompareNoCase("step"))
				m_bStepDebug = TRUE;
			break;
		case 3:
			m_pHost->m_nTimeout = atoi(strValue);
			break;
		case 4:
			if(!strValue.CompareNoCase("Required"))
                m_nTransaction = 3;
			else if(!strValue.CompareNoCase("Requires_New"))
				m_nTransaction = 2;
			else if(!strValue.CompareNoCase("Supported"))
				m_nTransaction = 1;
			else if(!strValue.CompareNoCase("Not_Supported"))
				m_nTransaction = 0;
			break;
		case 5:
			//(uiCodePage)
			break;
		}

		while(nCount > 0 && IsBlank(pstrText[0]))
		{
			if(pstrText[0] == '\n')
				nLineCount ++;

			pstrText ++;
			nCount --;
		}
	}

	AddLineMap(nIncludeFlagIndex, nLineCount);

	strScriptText.Append(pstrText, nCount);
	strScriptText += _T("\r\n");

	m_nScriptLine ++;

	pstrTemp = pstrText;
	nTempCount = nCount;
	while(nTempCount > 0)
	{
		if(pstrTemp[0] == '\n')
			m_nScriptLine ++;

		pstrTemp ++;
		nTempCount --;
	}

	return 0;
}
Esempio n. 25
0
HRESULT CPixelShaderCompiler::InternalCompile(
    LPCSTR pSrcData,
    SIZE_T SrcDataSize,
    LPCSTR pSourceName,
    LPCSTR pEntrypoint,
    LPCSTR pProfile,
    DWORD Flags,
    IDirect3DPixelShader9** ppPixelShader,
    CString* pDisasm,
    CString* pErrMsg)
{
    if (!m_pD3DCompile) {
        return E_FAIL;
    }

    if (pDisasm && !m_pD3DDisassemble) {
        return E_FAIL;
    }

    if (ppPixelShader && !m_pD3DDev) {
        return E_FAIL;
    }

    LPCSTR pSelProfile = pProfile;
    if (!pSelProfile || *pSelProfile == '\0') {
        D3DCAPS9 caps;
        if (m_pD3DDev && m_pD3DDev->GetDeviceCaps(&caps) == D3D_OK) {
            switch (D3DSHADER_VERSION_MAJOR(caps.PixelShaderVersion)) {
                case 2:
                    if (caps.PS20Caps.NumInstructionSlots < 512) {
                        pSelProfile = "ps_2_0";
                    } else if (caps.PS20Caps.Caps > 0) {
                        pSelProfile = "ps_2_a";
                    } else {
                        pSelProfile = "ps_2_b";
                    }
                    break;
                case 3:
                    pSelProfile = "ps_3_0";
                    break;
            }
        } else {
            ASSERT(FALSE);
        }
    }

    if (!pSelProfile || *pSelProfile == '\0') {
        return E_FAIL;
    }

    LPCSTR defProfile = "MPC_HC_SHADER_PROFILE";
    LPCSTR defProfileVal;
    if (!strcmp(pSelProfile, "ps_2_0")) {
        defProfileVal = "0";
    } else if (!strcmp(pSelProfile, "ps_2_b")) {
        defProfileVal = "1";
    } else if (!strcmp(pSelProfile, "ps_2_a") || !strcmp(pSelProfile, "ps_2_sw")) {
        defProfileVal = "2";
    } else if (!strcmp(pSelProfile, "ps_3_0") || !strcmp(pSelProfile, "ps_3_sw")) {
        defProfileVal = "3";
    } else {
        defProfileVal = "-1";
    }

    if (ppPixelShader && SUCCEEDED(m_Cache.CreatePixelShader(defProfileVal, pSrcData, SrcDataSize, ppPixelShader))) {
        return S_OK;
    }

    D3D_SHADER_MACRO macros[] = { { defProfile, defProfileVal }, { 0 } };

    CComPtr<ID3DBlob> pShaderBlob, pErrorBlob;
    HRESULT hr = m_pD3DCompile(pSrcData, SrcDataSize, pSourceName, macros, nullptr, pEntrypoint,
                               pSelProfile, Flags, 0, &pShaderBlob, &pErrorBlob);

    if (pErrMsg) {
        CStringA msg;
        if (pErrorBlob) {
            auto len = pErrorBlob->GetBufferSize();
            VERIFY(memcpy_s(msg.GetBufferSetLength((int)len), len, pErrorBlob->GetBufferPointer(), len) == 0);
            msg.ReleaseBuffer((int)len);
        }
        *pErrMsg = msg;
    }

    if (FAILED(hr)) {
        return hr;
    }

    if (ppPixelShader) {
        hr = m_pD3DDev->CreatePixelShader((DWORD*)pShaderBlob->GetBufferPointer(), ppPixelShader);
        if (FAILED(hr)) {
            return hr;
        }

        m_Cache.SavePixelShader(defProfileVal, pSrcData, SrcDataSize,
                                (void*)pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize());
    }

    if (pDisasm) {
        CComPtr<ID3DBlob> pDisasmBlob;
        CStringA defs;
        for (auto pMacro = macros; pMacro && pMacro->Name && pMacro->Definition; pMacro++) {
            defs.Append("// #define ");
            defs.Append(pMacro->Name);
            defs.Append(" ");
            defs.Append(pMacro->Definition);
            defs.Append("\n");
        }
        hr = m_pD3DDisassemble(pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(),
                               0, defs, &pDisasmBlob);
        if (SUCCEEDED(hr)) {
            CStringA disasm;
            auto len = pDisasmBlob->GetBufferSize();
            VERIFY(memcpy_s(disasm.GetBufferSetLength((int)len), len, pDisasmBlob->GetBufferPointer(), len) == 0);
            disasm.ReleaseBuffer((int)len);
            *pDisasm = disasm;
        }
    }

    return S_OK;
}
Esempio n. 26
0
void CSubtitleDlDlg::OnOK()
{
	SetStatus(ResStr(IDS_SUBDL_DLG_DOWNLOADING));

	for (int i = 0; i < m_list.GetItemCount(); ++i) {
		if (m_list.GetCheck(i)) {
			m_selsubs.AddTail(*reinterpret_cast<isdb_subtitle*>(m_list.GetItemData(i)));
		}
	}

	m_fReplaceSubs = IsDlgButtonChecked(IDC_CHECK1) == BST_CHECKED;

	CMainFrame* pMF = static_cast<CMainFrame*>(GetParentFrame());

	if (m_fReplaceSubs) {
		pMF->m_pSubStreams.RemoveAll();
	}

	CComPtr<ISubStream> pSubStreamToSet;

	POSITION pos = m_selsubs.GetHeadPosition();

	while (pos) {
		const isdb_subtitle& sub = m_selsubs.GetNext(pos);
		AppSettings& s = AfxGetAppSettings();
		CInternetSession is;
		CStringA url = "http://" + s.strISDb + "/dl.php?";
		CStringA args, ticket, str;
		args.Format("id=%d&ticket=%s", sub.id, UrlEncode(ticket));
		url.Append(args);

		if (OpenUrl(is, CString(url), str)) {

			if (pMF->b_UseVSFilter) {
				if (CComQIPtr<IDirectVobSub> pDVS = pMF->GetVSFilter()) {
					TCHAR lpszTempPath[_MAX_PATH] = { 0 };
					if (::GetTempPath(_MAX_PATH, lpszTempPath)) {
						CString subFileName(lpszTempPath);
						subFileName.Append(CString(sub.name));
						if (::PathFileExists(subFileName)) {
							::DeleteFile(subFileName);
						}

						CFile cf;
						if (cf.Open(subFileName, CFile::modeCreate|CFile::modeWrite|CFile::shareDenyNone)) {
							cf.Write(str.GetString(), str.GetLength());
							cf.Close();

							if (SUCCEEDED(pDVS->put_FileName((LPWSTR)(LPCWSTR)subFileName))) {
								pDVS->put_SelectedLanguage(0);
								pDVS->put_HideSubtitles(true);
								pDVS->put_HideSubtitles(false);
							}

							::DeleteFile(subFileName);
						}
					}

					__super::OnOK();
					return;
				}
			}

			CAutoPtr<CRenderedTextSubtitle> pRTS(DNew CRenderedTextSubtitle(&pMF->m_csSubLock, &s.subdefstyle, s.fUseDefaultSubtitlesStyle));
			if (pRTS && pRTS->Open((BYTE*)(LPCSTR)str, str.GetLength(), DEFAULT_CHARSET, CString(sub.name)) && pRTS->GetStreamCount() > 0) {
				CComPtr<ISubStream> pSubStream = pRTS.Detach();
				pMF->m_pSubStreams.AddTail(pSubStream);

				if (!pSubStreamToSet) {
					pSubStreamToSet = pSubStream;
				}
			}
		}
	}

	if (pSubStreamToSet) {
		pMF->SetSubtitle(pSubStreamToSet);

		AfxGetAppSettings().fEnableSubtitles = true;
	}

	__super::OnOK();
}
Esempio n. 27
0
BOOL COSMCtrlMapOperationsDlg::ForceMapnikRerenderHelper()
{
  //Validate our parameters
  AFXASSUME(m_pOSMCtrl != NULL);

  //Next get the server to connect to
  COSMCtrlMapnikTileProvider MapnikTileProvider;
  CStringW sServer(MapnikTileProvider.GetDownloadServer());

  //Accumulate how many tiles we have request to rerender and which ones indicated a failure to rerender
  int nTilesRerendered = 0;
  int nTilesNotRerendered = 0;

  //Next create the WinHTTP session object
  CWinHTTPSession session;
  HRESULT hr = m_pOSMCtrl->CreateSession(session, 0);
  if (SUCCEEDED(hr))
  {
    //Now create the connection object from the session object
    CWinHTTPConnection connection;
    hr = connection.Initialize(session, sServer, MapnikTileProvider.GetDownloadPort());
    if (SUCCEEDED(hr))
    {
      //Iterate across the array of tiles to download
      BOOL bSuccess = TRUE;
      for (std::vector<COSMCtrlMapOperationsDlgTile>::size_type i=0; i<m_Tiles.size() && bSuccess; i++)
      {
        //Pull out the next tile to download
        const COSMCtrlMapOperationsDlgTile& tile = m_Tiles[i];

        //Now issue the request to rerender
        COSMCtrlMapOperationsDlgEvent dlgEvent;
        dlgEvent.m_bSuccess = false;
        LPCWSTR pwszAcceptTypes[2];
        pwszAcceptTypes[0] = L"*/*";
        pwszAcceptTypes[1] = NULL;
        CSyncWinHTTPDownloader winHttpRequest;
        //winHttpRequest.m_sFileToDownloadInto = sFile;
        CString sObject(MapnikTileProvider.GetDownloadObject(tile.m_nZoom, tile.m_nTileX, tile.m_nTileY) + _T("/dirty"));
        hr = winHttpRequest.Initialize(connection, CStringW(sObject), NULL, NULL, NULL, pwszAcceptTypes, WINHTTP_FLAG_REFRESH);
        if (FAILED(hr))
        {
          //report the error
          TRACE(_T("COSMCtrlMapOperationsDlg::ForceMapnikRerenderHelper, Failed to create request for object \"%s\", Error:%08X\n"), sObject.operator LPCTSTR(), hr);
            
          //Update the stats
          ++nTilesNotRerendered;
        }
        else
        {
          hr = winHttpRequest.SendRequestSync();
          if (FAILED(hr))
          {
            //report the error
            TRACE(_T("COSMCtrlMapOperationsDlg::ForceMapnikRerenderHelper, Failed to send request for object \"%s\", Error:%08X\n"), sObject.operator LPCTSTR(), hr);
            
            //Update the stats
            ++nTilesNotRerendered;
          }
          else
          {
            CStringA sResponse;
            sResponse.Append(reinterpret_cast<LPCSTR>(winHttpRequest.m_Response.GetData()), static_cast<int>(winHttpRequest.m_Response.GetSize()));
            if (sResponse.Find("Tile submitted for rendering") != -1)
            {
              //Update the stats
              ++nTilesRerendered;
              dlgEvent.m_bSuccess = true;
            }
            else
            {
              //Update the stats
              ++nTilesNotRerendered;
            }  
          }
        }

        //Update the UI          
        dlgEvent.m_Event = COSMCtrlMapOperationsDlgEvent::SimpleStringStatus;
        dlgEvent.m_sString = sObject;
        dlgEvent.m_nItemData = i + 1;
        AddEvent(dlgEvent);

        //Check if we have been cancelled before we loop around
        bSuccess = (WaitForSingleObject(m_WorkerTerminateEvent, 0) == WAIT_TIMEOUT);
      }
    }
  }

  //Finally add a event about how many items have been downloaded
  COSMCtrlMapOperationsDlgEvent dlgEvent;
  dlgEvent.m_Event = COSMCtrlMapOperationsDlgEvent::SimpleStringStatus;
  CString sTilesRerendered;
  sTilesRerendered.Format(_T("%d"), nTilesRerendered);
  CString sTilesNotRerendered;
  sTilesNotRerendered.Format(_T("%d"), nTilesNotRerendered);
  AfxFormatString2(dlgEvent.m_sString, IDS_OSMCTRL_RERENDER_TILES_STATS, sTilesRerendered, sTilesNotRerendered);
  AddEvent(dlgEvent);

  return TRUE;
}