// WebSocket Callbacks
void IEDiagnosticsAdapter::OnHttp(websocketpp::connection_hdl hdl)
{
    server::connection_ptr con = m_server.get_con_from_hdl(hdl);

    stringstream ss;
    if (con->get_resource() == "/")
    {
        // Load and return the html selection page
        CString inspect;
        HRESULT hr = Helpers::ReadFileFromModule(MAKEINTRESOURCE(IDR_INSPECTHTML), inspect);
        if (hr == S_OK)
        {
            CStringA page(inspect);
            ss << page;
        }
    }
    else if (con->get_resource() == "/json" || con->get_resource() == "/json/list")
    {
        // Enumerate the running IE instances
        this->PopulateIEInstances();

        // Return a json array describing the instances
        size_t index = 0;
        ss << "[";
        for (auto& it : m_instances)
        {
            CStringA url(it.second.url);
            url.Replace('\\', '/');
            url.Replace(" ", "%20");
            url.Replace("file://", "file:///");
            CStringA title = Helpers::EscapeJsonString(it.second.title);
            CStringA fileName = Helpers::EscapeJsonString(::PathFindFileNameW(it.second.filePath));
            CComBSTR guidBSTR(it.second.guid);
            CStringA guid(guidBSTR);
            guid = guid.Mid(1, guid.GetLength() - 2);

            ss << "{" << endl;
            ss << "   \"description\" : \"" << fileName.MakeLower() << "\"," << endl;
            ss << "   \"devtoolsFrontendUrl\" : \"\"," << endl;
            ss << "   \"id\" : \"" << guid << "\"," << endl;
            ss << "   \"title\" : \"" << title << "\"," << endl;
            ss << "   \"type\" : \"page\"," << endl;
            ss << "   \"url\" : \"" << url << "\"," << endl;
            ss << "   \"webSocketDebuggerUrl\" : \"ws://" << con->get_host() << ":" << con->get_port() << "/devtools/page/" << guid << "\"" << endl;
            ss << "}";

            if (index < m_instances.size() - 1)
            {
                ss << ", ";
            }
            index++;
        }
        ss << "]";
    }

    con->set_body(ss.str());
    con->set_status(websocketpp::http::status_code::ok);
}
CStringA CUrlSrcGetFromSvrSocket::GetUrlPath()
{
	if (::IsBadReadPtr(m_pMgr, sizeof(CUrlSrcFromSvrMgr)))
		return "";

	CStringA	strUrlPath;
	CStringA	strHash;
	CStringA	strSize;
	CStringA	strFileName;
	CStringA	strEncodedFileName;

	if( NULL==m_pMgr->m_pAssocPartFile )
		return "";

	try
	{
		//	Hash
		strHash = md4str(m_pMgr->m_pAssocPartFile->GetFileHash());
		strHash.MakeLower();		//必须都为小写。

		//	Size
		char szSize[1024];
		_i64toa(m_pMgr->m_pAssocPartFile->GetFileSize(), szSize,10);
		strSize = szSize;

		//strHash = "48F8220C4FF02D4E5AD11DD5E1E305CB";
		//strHash.MakeLower();
		//strSize = "125753277";
		//lptszFileName = _T("PopKart_Setup_P092.exe");

		//	FileName
		strEncodedFileName = EncodeUrlUtf8(m_pMgr->m_pAssocPartFile->GetFileName());

		//	construct UrlPath
		//strUrlPath.Format("http://client.stat.verycd.com/dl/%s%s/%s/start", strHash, strSize, strEncodedFileName);

		if (m_bStart)
			strUrlPath.Format("/dl/%s%s/%s/start", strHash, strSize, strEncodedFileName);
		else
			strUrlPath.Format("/dl/%s%s/%s/finished", strHash, strSize, strEncodedFileName);

		return strUrlPath;
	}
	catch ( ... ) 
	{
		return "";
	}
}
Esempio n. 3
0
bool SVNAdminDir::IsAdminDirName(const CString& name) const
{
    CStringA nameA = CUnicodeUtils::GetUTF8(name);
    try
    {
        nameA.MakeLower();
    }
    // catch everything: with MFC, an CInvalidArgException is thrown,
    // but with ATL only an CAtlException is thrown - and those
    // two exceptions are incompatible
    catch(...)
    {
        return false;
    }
    return !!svn_wc_is_adm_dir(nameA, m_pool);
}
Esempio n. 4
0
void CloHttpCurl::UpdateProxy(LPCSTR lpszRequestURL)
{
	//// a code snippet ///
	CStringA strURL = CStringA(lpszRequestURL);
	strURL.MakeLower();

	if( !m_pAssoc->m_curlHandle )
		return ;
	
	if( strURL.Find("https://") == 0 )
	{
		curl_easy_setopt(m_pAssoc->m_curlHandle, CURLOPT_SSL_VERIFYPEER, 0L);
		curl_easy_setopt(m_pAssoc->m_curlHandle, CURLOPT_SSL_VERIFYHOST, 1L);
	}

	if( m_pAssoc->m_ProxyInfo.nProxyType != E_PROXYTYPE_NONE && strlen(m_pAssoc->m_ProxyInfo.cServer) > 0 )
	{
		char buf[1024];
		buf[0] = '\0';
		sprintf_s( buf, 1024, "%s:%d", m_pAssoc->m_ProxyInfo.cServer, m_pAssoc->m_ProxyInfo.wPort );

		curl_easy_setopt(m_pAssoc->m_curlHandle, CURLOPT_PROXY, buf);
		switch(m_pAssoc->m_ProxyInfo.nProxyType)
		{
		case E_PROXYTYPE_HTTP:
			curl_easy_setopt(m_pAssoc->m_curlHandle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
			break;
		case E_PROXYTYPE_SOCKS4:
			curl_easy_setopt(m_pAssoc->m_curlHandle, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
			break;
		case E_PROXYTYPE_SOCKS5:
			curl_easy_setopt(m_pAssoc->m_curlHandle, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
			break;
		}

		if( strlen(m_pAssoc->m_ProxyInfo.cUser) > 0 )
		{
			curl_easy_setopt(m_pAssoc->m_curlHandle, CURLOPT_PROXYUSERNAME, m_pAssoc->m_ProxyInfo.cUser);
			curl_easy_setopt(m_pAssoc->m_curlHandle, CURLOPT_PROXYPASSWORD, m_pAssoc->m_ProxyInfo.cPassword);
		}
	}
}
Esempio n. 5
0
BOOL CHttpRecvParser::SetValueByName(CStringA strName,CStringA strValue)
{
	BOOL bRes = FALSE;
	if ( strName.GetLength() == 0 )
	{
		return bRes;
	}
	strName.MakeLower();

	for (RESPONSE_LIST_PTR it = m_ResponseList.begin();it!=m_ResponseList.end();it++)
	{
		if (CStringA(it->strResponseName).MakeLower() == strName)
		{
			it->strResponseValue = strValue;
			bRes = TRUE;
			break;
		}
	}
	return bRes;
}
Esempio n. 6
0
bool CPlayerTaskSocket::ParseHttpReq(CStringA strHtml, CStringA & rHashId, int & rnRange)
{
	rnRange = 0;
	rHashId.Empty();

	//  Not http GET command
	if(strnicmp(strHtml, "GET ", 4)!=0)
		return false;

	strHtml.Delete(0, 4);
	if(strHtml.GetAt(0)=='/')
		strHtml.Delete(0);

	int i;
	i=strHtml.Find("/");
	if(i<0) return false;

	rHashId = strHtml.Mid(0, i);
	strHtml.MakeLower();
	int n=strHtml.Find("range:");
	if(n>0)
	{
		n+=6;
		int iRangeEnd=strHtml.Find("\r\n", n);
		CStringA strRange=strHtml.Mid(n, iRangeEnd-n);
		while(! strRange.IsEmpty())
		{
			if(!isdigit(strRange.GetAt(0)))
				strRange.Delete(0);
			else break;
		}

		if(strRange.GetAt(strRange.GetLength()-1)=='-')
			strRange.Delete(strRange.GetLength()-1);

		strRange.Trim();

		rnRange = atol(strRange);
	}
	return true;
}
Esempio n. 7
0
BOOL CUrlParser::SetParamValueByName(CStringA strName,CStringA strValue)
{
	BOOL bRes = FALSE;
	if(strName.GetLength() == 0)
	{
		return bRes;
	}
	strName.MakeLower();

	for (ParamListPtr it = m_ParamList.begin();it!=m_ParamList.end();it++)
	{
		if ( CStringA(it->strParamName).MakeLower() == strName )
		{
			it->strParamValue = strValue;
			bRes = TRUE;
			break;
		}
	}

	return bRes;;
}
Esempio n. 8
0
CStringA CHttpRecvParser::GetValueByName(CStringA strName)
{
	CStringA strValue;

	if ( strName.GetLength() == 0 )
	{
		return strValue;
	}

	strName.MakeLower();


	for (RESPONSE_LIST_PTR it = m_ResponseList.begin();it!=m_ResponseList.end();it++)
	{
		if (CStringA(it->strResponseName).MakeLower() == strName)
		{
			strValue = it->strResponseValue;
			break;
		}
	}

	return strValue;
}
Esempio n. 9
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. 10
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. 11
0
bool ScintillaEditor::ReadProperties(const CString& fileName, const CString& forcedExt)
{
	delete m_props;
	m_props = NULL;

	CStringA fileNameForExtension;
	if (forcedExt.IsEmpty())
	{
		int dotPos = fileName.ReverseFind('.');
		if (dotPos != -1)
		{
			fileNameForExtension = fileName.Mid(dotPos + 1);
			fileNameForExtension.MakeLower();
		}
	}
	else
		fileNameForExtension = forcedExt;

	TCHAR moduleFileNameBuffer[_MAX_PATH];
	GetModuleFileName(GetModuleHandle(NULL), moduleFileNameBuffer, _MAX_PATH);
	CStringA modulePath = moduleFileNameBuffer;
	int slashPos = modulePath.ReverseFind('\\');
	modulePath = modulePath.Left(slashPos + 1);
	
	m_props = new ScintillaPropertiesFile;


	m_props->Parse(modulePath + "SciTEGlobal.properties");
	m_props->Parse(modulePath + fileNameForExtension + ".properties");

	ScintillaPropertiesFile& props = *m_props;

	const CStringA& language = props.Get("lexer.*." + fileNameForExtension);

	int lexLanguage;
	if (language == "python") {
		lexLanguage = SCLEX_PYTHON;
	} else if (language == "cpp") {
		lexLanguage = SCLEX_CPP;
	} else if (language == "hypertext") {
		lexLanguage = SCLEX_HTML;
	} else if (language == "xml") {
		lexLanguage = SCLEX_XML;
	} else if (language == "perl") {
		lexLanguage = SCLEX_PERL;
	} else if (language == "sql") {
		lexLanguage = SCLEX_SQL;
	} else if (language == "vb") {
		lexLanguage = SCLEX_VB;
	} else if (language == "props") {
		lexLanguage = SCLEX_PROPERTIES;
	} else if (language == "errorlist") {
		lexLanguage = SCLEX_ERRORLIST;
	} else if (language == "makefile") {
		lexLanguage = SCLEX_MAKEFILE;
	} else if (language == "batch") {
		lexLanguage = SCLEX_BATCH;
	} else if (language == "latex") {
		lexLanguage = SCLEX_LATEX;
	} else if (language == "lua") {
		lexLanguage = SCLEX_LUA;
	} else if (language == "diff") {
		lexLanguage = SCLEX_DIFF;
	} else if (language == "container") {
		lexLanguage = SCLEX_CONTAINER;
	} else if (language == "conf") {
		lexLanguage = SCLEX_CONF;
	} else if (language == "pascal") {
		lexLanguage = SCLEX_PASCAL;
	} else if (language == "ave") {
		lexLanguage = SCLEX_AVE;
	} else {
		lexLanguage = SCLEX_NULL;
	}

	if ((lexLanguage == SCLEX_HTML) || (lexLanguage == SCLEX_XML))
		SendEditor(SCI_SETSTYLEBITS, 7);
	else
		SendEditor(SCI_SETSTYLEBITS, 5);

	SendEditor(SCI_SETLEXER, lexLanguage);
//	SendOutput(SCI_SETLEXER, SCLEX_ERRORLIST);

//	apis.Clear();

	CStringA kw0 = props.Get("keywords.*." + fileNameForExtension);
	SendEditorString(SCI_SETKEYWORDS, 0, kw0);
	CStringA kw1 = props.Get("keywords2.*." + fileNameForExtension);
	SendEditorString(SCI_SETKEYWORDS, 1, kw1);
	CStringA kw2 = props.Get("keywords3.*." + fileNameForExtension);
	SendEditorString(SCI_SETKEYWORDS, 2, kw2);
	CStringA kw3 = props.Get("keywords4.*." + fileNameForExtension);
	SendEditorString(SCI_SETKEYWORDS, 3, kw3);
	CStringA kw4 = props.Get("keywords5.*." + fileNameForExtension);
	SendEditorString(SCI_SETKEYWORDS, 4, kw4);

//	char homepath[MAX_PATH + 20];
//	if (GetSciteDefaultHome(homepath, sizeof(homepath))) {
//		props.Set("SciteDefaultHome", homepath);
//	}
//	if (GetSciteUserHome(homepath, sizeof(homepath))) {
//		props.Set("SciteUserHome", homepath);
//	}

	ForwardPropertyToEditor("fold");
	ForwardPropertyToEditor("fold.compact");
	ForwardPropertyToEditor("fold.comment");
	ForwardPropertyToEditor("fold.html");
	ForwardPropertyToEditor("styling.within.preprocessor");
	ForwardPropertyToEditor("tab.timmy.whinge.level");

/*	CStringA apifilename = props.Get("api.", fileNameForExtension);
	if (apifilename.GetLength()) {
		FILE *fp = fopen(apifilename, fileRead);
		if (fp) {
			fseek(fp, 0, SEEK_END);
			int len = ftell(fp);
			char *buffer = apis.Allocate(len);
			if (buffer) {
				fseek(fp, 0, SEEK_SET);
				fread(buffer, 1, len, fp);
				apis.SetFromAllocated();
			}
			fclose(fp);
			//Platform::DebugPrintf("Finished api file %d\n", len);
		}

	}
*/
	if (!props.GetInt("eol.auto")) {
		CStringA eol_mode = props.Get("eol.mode");
		if (eol_mode == "LF") {
			SendEditor(SCI_SETEOLMODE, SC_EOL_LF);
		} else if (eol_mode == "CR") {
			SendEditor(SCI_SETEOLMODE, SC_EOL_CR);
		} else if (eol_mode == "CRLF") {
			SendEditor(SCI_SETEOLMODE, SC_EOL_CRLF);
		}
	}

//	codePage = props.GetInt("code.page");
//	SendEditor(SCI_SETCODEPAGE, codePage);

//	characterSet = props.GetInt("character.set");

	CStringA colour;
	colour = props.Get("caret.fore");
	if (colour.GetLength()) {
		SendEditor(SCI_SETCARETFORE, ScintillaPropertiesFile::ColourFromString(colour));
	}

	SendEditor(SCI_SETCARETWIDTH, props.GetInt("caret.width", 1));
//	SendOutput(SCI_SETCARETWIDTH, props.GetInt("caret.width", 1));

	colour = props.Get("calltip.back");
	if (colour.GetLength()) {
		SendEditor(SCI_CALLTIPSETBACK, ScintillaPropertiesFile::ColourFromString(colour));
	}

	CStringA caretPeriod = props.Get("caret.period");
	if (caretPeriod.GetLength()) {
		SendEditor(SCI_SETCARETPERIOD, value(caretPeriod));
//		SendOutput(SCI_SETCARETPERIOD, caretPeriod.value());
	}

	int caretStrict = props.GetInt("caret.policy.strict") ? CARET_STRICT : 0;
	int caretSlop = props.GetInt("caret.policy.slop", 1) ? CARET_SLOP : 0;
	int caretLines = props.GetInt("caret.policy.lines");
	SendEditor(SCI_SETCARETPOLICY, caretStrict | caretSlop, caretLines);

	int visibleStrict = props.GetInt("visible.policy.strict") ? VISIBLE_STRICT : 0;
	int visibleSlop = props.GetInt("visible.policy.slop", 1) ? VISIBLE_SLOP : 0;
	int visibleLines = props.GetInt("visible.policy.lines");
	SendEditor(SCI_SETVISIBLEPOLICY, visibleStrict | visibleSlop, visibleLines);

	SendEditor(SCI_SETEDGECOLUMN, props.GetInt("edge.column", 0));
	SendEditor(SCI_SETEDGEMODE, props.GetInt("edge.mode", EDGE_NONE));
	colour = props.Get("edge.colour");
	if (colour.GetLength()) {
		SendEditor(SCI_SETEDGECOLOUR, ScintillaPropertiesFile::ColourFromString(colour));
	}

	CStringA selfore = props.Get("selection.fore");
	if (selfore.GetLength()) {
		SendEditor(SCI_SETSELFORE, 1, ScintillaPropertiesFile::ColourFromString(selfore));
	} else {
		SendEditor(SCI_SETSELFORE, 0, 0);
	}
	colour = props.Get("selection.back");
	if (colour.GetLength()) {
		SendEditor(SCI_SETSELBACK, 1, ScintillaPropertiesFile::ColourFromString(colour));
	} else {
		if (selfore.GetLength())
			SendEditor(SCI_SETSELBACK, 0, 0);
		else	// Have to show selection somehow
			SendEditor(SCI_SETSELBACK, 1, RGB(0xC0, 0xC0, 0xC0));
	}

	char bracesStyleKey[200];
	sprintf(bracesStyleKey, "braces.%s.style", language);
	int bracesStyle = props.GetInt(bracesStyleKey, 0);

	char key[200];
	CStringA sval;

	sprintf(key, "calltip.%s.ignorecase", "*");
	sval = props.Get(key);
	bool callTipIgnoreCase = sval == "1";
	sprintf(key, "calltip.%s.ignorecase", language);
	sval = props.Get(key);
	if (sval != "")
		callTipIgnoreCase = sval == "1";

	sprintf(key, "autocomplete.%s.ignorecase", "*");
	sval = props.Get(key);
	bool autoCompleteIgnoreCase = sval == "1";
	sprintf(key, "autocomplete.%s.ignorecase", language);
	sval = props.Get(key);
	if (sval != "")
		autoCompleteIgnoreCase = sval == "1";
	SendEditor(SCI_AUTOCSETIGNORECASE, autoCompleteIgnoreCase ? 1 : 0);

	int autoCChooseSingle = props.GetInt("autocomplete.choose.single");
	SendEditor(SCI_AUTOCSETCHOOSESINGLE, autoCChooseSingle),

	// Set styles
	// For each window set the global default style, then the language default style, then the other global styles, then the other language styles

	SendEditor(SCI_STYLERESETDEFAULT, 0, 0);
//	SendOutput(SCI_STYLERESETDEFAULT, 0, 0);

	sprintf(key, "style.%s.%0d", "*", STYLE_DEFAULT);
	sval = props.Get(key);
	SetOneStyle(STYLE_DEFAULT, sval);
//	SetOneStyle(wOutput, STYLE_DEFAULT, sval);

	sprintf(key, "style.%s.%0d", language, STYLE_DEFAULT);
	sval = props.Get(key);
	SetOneStyle(STYLE_DEFAULT, sval);

	SendEditor(SCI_STYLECLEARALL, 0, 0);

	SetStyleFor("*");
	SetStyleFor(language);

//	SendOutput(SCI_STYLECLEARALL, 0, 0);

//	sprintf(key, "style.%s.%0d", "errorlist", STYLE_DEFAULT);
//	sval = props.Get(key, "");
//	SetOneStyle(wOutput, STYLE_DEFAULT, sval);

//	SendOutput(SCI_STYLECLEARALL, 0, 0);

//	SetStyleFor(wOutput, "*");
//	SetStyleFor(wOutput, "errorlist");

//	if (firstPropertiesRead) {
		ReadPropertiesInitial();
//	}

	SendEditor(SCI_SETUSEPALETTE, props.GetInt("use.palette"));
	SendEditor(SCI_SETPRINTMAGNIFICATION, props.GetInt("print.magnification"));
	SendEditor(SCI_SETPRINTCOLOURMODE, props.GetInt("print.colour.mode"));

	int clearBeforeExecute = props.GetInt("clear.before.execute");

	int blankMarginLeft = props.GetInt("blank.margin.left", 1);
	int blankMarginRight = props.GetInt("blank.margin.right", 1);
	//long marginCombined = Platform::LongFromTwoShorts(blankMarginLeft, blankMarginRight);
	SendEditor(SCI_SETMARGINLEFT, 0, blankMarginLeft);
	SendEditor(SCI_SETMARGINRIGHT, 0, blankMarginRight);
//	SendOutput(SCI_SETMARGINLEFT, 0, blankMarginLeft);
//	SendOutput(SCI_SETMARGINRIGHT, 0, blankMarginRight);

	SendEditor(SCI_SETMARGINWIDTHN, 1, margin ? marginWidth : 0);
//	SendEditor(SCI_SETMARGINWIDTHN, 0, lineNumbers ? lineNumbersWidth : 0);

	int bufferedDraw = props.GetInt("buffered.draw", 1);
	SendEditor(SCI_SETBUFFEREDDRAW, bufferedDraw);

	int bracesCheck = props.GetInt("braces.check");
	int bracesSloppy = props.GetInt("braces.sloppy");

	CStringA wordCharacters = props.Get("word.characters." + fileNameForExtension);
	if (wordCharacters.GetLength()) {
		SendEditorString(SCI_SETWORDCHARS, 0, wordCharacters);
	} else {
		SendEditor(SCI_SETWORDCHARS, 0, 0);
	}

	SendEditor(SCI_SETUSETABS, props.GetInt("use.tabs", 1));
	int tabSize = props.GetInt("tabsize");
	if (tabSize) {
		SendEditor(SCI_SETTABWIDTH, tabSize);
	}
	int indentSize = props.GetInt("indent.size");
	SendEditor(SCI_SETINDENT, indentSize);
	int indentOpening = props.GetInt("indent.opening");
	int indentClosing = props.GetInt("indent.closing");
	CStringA lookback = props.Get("statement.lookback." + fileNameForExtension);
	int statementLookback = value(lookback);
/*	statementIndent = GetStyleAndWords("statement.indent.");
	statementEnd = GetStyleAndWords("statement.end.");
	blockStart = GetStyleAndWords("block.start.");
	blockEnd = GetStyleAndWords("block.end.");
*/
/*	if (props.GetInt("vc.home.key", 1)) {
		AssignKey(SCK_HOME, 0, SCI_VCHOME);
		AssignKey(SCK_HOME, SCMOD_SHIFT, SCI_VCHOMEEXTEND);
	} else {
		AssignKey(SCK_HOME, 0, SCI_HOME);
		AssignKey(SCK_HOME, SCMOD_SHIFT, SCI_HOMEEXTEND);
	}
	AssignKey('L', SCMOD_SHIFT | SCMOD_CTRL, SCI_LINEDELETE);
*/
	SendEditor(SCI_SETHSCROLLBAR, props.GetInt("horizontal.scrollbar", 1));
//	SendOutput(SCI_SETHSCROLLBAR, props.GetInt("output.horizontal.scrollbar", 1));

	int tabHideOne = props.GetInt("tabbar.hide.one");

//	SetToolsMenu();

	SendEditor(SCI_SETFOLDFLAGS, props.GetInt("fold.flags"));

	// To put the folder markers in the line number region
	//SendEditor(SCI_SETMARGINMASKN, 0, SC_MASK_FOLDERS);

	SendEditor(SCI_SETMODEVENTMASK, SC_MOD_CHANGEFOLD);

	// Create a margin column for the folding symbols
	SendEditor(SCI_SETMARGINTYPEN, 2, SC_MARGIN_SYMBOL);

	SendEditor(SCI_SETMARGINWIDTHN, 2, foldMargin ? foldMarginWidth : 0);

	SendEditor(SCI_SETMARGINMASKN, 2, SC_MASK_FOLDERS);
	SendEditor(SCI_SETMARGINSENSITIVEN, 2, 1);

	if (props.GetInt("fold.use.plus")) {
		SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_MINUS);
		SendEditor(SCI_MARKERSETFORE, SC_MARKNUM_FOLDEROPEN, RGB(0xff, 0xff, 0xff));
		SendEditor(SCI_MARKERSETBACK, SC_MARKNUM_FOLDEROPEN, RGB(0, 0, 0));
		SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_PLUS);
		SendEditor(SCI_MARKERSETFORE, SC_MARKNUM_FOLDER, RGB(0xff, 0xff, 0xff));
		SendEditor(SCI_MARKERSETBACK, SC_MARKNUM_FOLDER, RGB(0, 0, 0));
	} else {
		SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_ARROWDOWN);
		SendEditor(SCI_MARKERSETFORE, SC_MARKNUM_FOLDEROPEN, RGB(0, 0, 0));
		SendEditor(SCI_MARKERSETBACK, SC_MARKNUM_FOLDEROPEN, RGB(0, 0, 0));
		SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_ARROW);
		SendEditor(SCI_MARKERSETFORE, SC_MARKNUM_FOLDER, RGB(0, 0, 0));
		SendEditor(SCI_MARKERSETBACK, SC_MARKNUM_FOLDER, RGB(0, 0, 0));
	}
/*	if (extender) {
		extender->Clear();

		char defaultDir[MAX_PATH];
		GetDefaultDirectory(defaultDir, sizeof(defaultDir));
		char scriptPath[MAX_PATH];
		if (Exists(defaultDir, "SciTEGlobal.lua", scriptPath)) {
			// Found fglobal file in global directory
			extender->Load(scriptPath);
		}

		// Check for an extension script
		CStringA extensionFile = props.Get("extension.", fileNameForExtension);
		if (extensionFile.GetLength()) {
			// find file in local directory
			char docDir[MAX_PATH];
			GetDocumentDirectory(docDir, sizeof(docDir));
			if (Exists(docDir, extensionFile, scriptPath)) {
				// Found file in document directory
				extender->Load(scriptPath);
			} else if (Exists(defaultDir, extensionFile, scriptPath)) {
				// Found file in global directory
				extender->Load(scriptPath);
			} else if (Exists("", extensionFile, scriptPath)) {
				// Found as completely specified file name
				extender->Load(scriptPath);
			}
		}
	}
*/
//	firstPropertiesRead = false;
	//DWORD dwEnd = timeGetTime();
	//Platform::DebugPrintf("Properties read took %d\n", dwEnd - dwStart);

	return true;
}
Esempio n. 12
0
BOOL CFCacheImpl::Query(
    IFCacheQueryback* piQueryback,
    FCacheQueryType queryType,
    void* pParam1,
    void* pParam2
    )
{
    BOOL retval = FALSE;
    int nRetCode;
    char* szError = NULL;
    CStringA strSql;
    sqlite3_stmt* pStmt = NULL;

    if (!m_pDbConnect)
        goto clean0;

    if (!piQueryback)
        goto clean0;

    if (enumFQT_Top == queryType)
    {
        if (!pParam1)
            goto clean0;

        strSql.Format("select path, size from top100 order by size desc limit %d", *(ULONG*)pParam1);
        nRetCode = sqlite3_prepare(m_pDbConnect, strSql, -1, &pStmt, 0);
        if (nRetCode)
            goto clean0;

        nRetCode = sqlite3_step(pStmt);
        if (SQLITE_ROW == nRetCode)
            goto get_data;

        sqlite3_finalize(pStmt);
        pStmt = NULL;

        strSql = "delete from top100";
        nRetCode = sqlite3_exec(m_pDbConnect, strSql, NULL, NULL, &szError);

        strSql = "insert into top100(path, size) select path, size from files order by size desc limit 500";
        nRetCode = sqlite3_exec(m_pDbConnect, strSql, NULL, NULL, &szError);
        if (nRetCode)
            goto clean0;

        strSql.Format("select path, size from top100 order by size desc limit %d", *(ULONG*)pParam1);
    }
    else if (enumFQT_Ext == queryType)
    {
        CStringA strExt;

        if (!pParam1)
            goto clean0;

        if (*(char*)pParam1 == '.')
        {
            strExt = (char*)pParam1;
        }
        else
        {
            strExt = ".";
            strExt += (char*)pParam1;
        }

        strSql.Format("select path, size from files where ext = '%s' order by size desc", strExt);
    }
    else if (enumFQT_Zone == queryType)
    {
        ULONGLONG qwFrom, qwTo;

        if (!pParam1 || !pParam2)
            goto clean0;

        qwFrom = *(ULONGLONG*)pParam1;
        qwTo = *(ULONGLONG*)pParam2;

        strSql.Format("select path, size from files where size >= %I64d and size <= %I64d order by size desc",
                      qwFrom,
                      qwTo);
    }
    else if (enumFQT_Word == queryType)
    {
        CStringW strWord;

        if (!pParam1)
            goto clean0;

        strWord = (const wchar_t*)pParam1;

        strSql.Format("select path, size from files where path like '%s%s%s' order by size desc",
                      "%",
                      KUTF16_To_UTF8(strWord),
                      "%");
    }

    strSql.MakeLower();
    nRetCode = sqlite3_prepare(m_pDbConnect, strSql, -1, &pStmt, 0);
    if (nRetCode)
        goto clean0;

    nRetCode = sqlite3_step(pStmt);
    if (nRetCode != SQLITE_ROW)
        goto clean0;

get_data:
    while (SQLITE_ROW == nRetCode)
    {
        CStringA strFilePath = (char*)sqlite3_column_text(pStmt, 0);
        ULONGLONG qwFileSize = sqlite3_column_int64(pStmt, 1);

        piQueryback->OnData(queryType, KUTF8_To_UTF16(strFilePath), qwFileSize);

        nRetCode = sqlite3_step(pStmt);
    }

    retval = TRUE;

clean0:
    if (pStmt)
    {
        sqlite3_finalize(pStmt);
        pStmt = NULL;
    }

    return retval;
}