Example #1
0
CString
CKeyMap::formatKey(KeyID key, KeyModifierMask mask)
{
	// initialize tables
	initKeyNameMaps();

	CString x;
	for (SInt32 i = 0; i < kKeyModifierNumBits; ++i) {
		KeyModifierMask mod = (1u << i);
		if ((mask & mod) != 0 && s_modifierToNameMap->count(mod) > 0) {
			x += s_modifierToNameMap->find(mod)->second;
			x += "+";
		}
	}
	if (key != kKeyNone) {
		if (s_keyToNameMap->count(key) > 0) {
			x += s_keyToNameMap->find(key)->second;
		}
		// XXX -- we're assuming ASCII here
		else if (key >= 33 && key < 127) {
			x += (char)key;
		}
		else {
			x += CStringUtil::print("\\u%04x", key);
		}
	}
	else if (!x.empty()) {
		// remove trailing '+'
		x.erase(x.size() - 1);
	}
	return x;
}
Example #2
0
	bool DecryptChannel(const CString & sChan, CString & sBuffer)
	{
		CString sChannel = GetPath(sChan);
		CString sFile;
		sBuffer = "";

		CFile File(sChannel);

		if (sChannel.empty() || !File.Open() || !File.ReadFile(sFile))
			 return(true); // gonna be successful here

		File.Close();

		if (!sFile.empty())
		{
			CBlowfish c(m_sPassword, BF_DECRYPT);
			sBuffer = c.Crypt(sFile);

			if (sBuffer.Left(strlen(CRYPT_VERIFICATION_TOKEN)) != CRYPT_VERIFICATION_TOKEN)
			{
				// failed to decode :(
				PutModule("Unable to decode Encrypted file [" + sChannel + "]");
				return(false);
			}
			sBuffer.erase(0, strlen(CRYPT_VERIFICATION_TOKEN));
		}
		return(true);
	}
Example #3
0
bool getline(CString &_str, CString &line){
  if(_str.size()==0)  return false;
  CString::size_type pLeft=0, pRight = _str.find('\n');
  line = _str.substr( pLeft, pRight );
  _str = _str.erase(0,pRight+1);
  return true;
};
Example #4
0
void CFileTreeCtrl::setSelectedFullPath(const std::wstring &sPath)
{
    populate();

    SetRedraw(FALSE);
    SetCursor(LoadCursor(NULL, IDC_WAIT));

    SelectItem(m_hRoot);
    Expand(m_hRoot, TVE_EXPAND);

    // Traverse Tree
    HTREEITEM hItem = m_hRoot;
    HTREEITEM hChildItem;
    HTREEITEM hNextItem;

    std::vector<std::wstring> tokens;
    std::vector<std::wstring>::const_iterator iterToken;
    Utils::tokenize(sPath, tokens, L"\\/");

    CString sItemValue;
    for(iterToken = tokens.begin(); iterToken != tokens.end(); ++iterToken)
    {
        hChildItem = GetChildItem(hItem);

        while (hChildItem != NULL)
        {
            hNextItem = GetNextItem(hChildItem, TVGN_NEXT);

            std::wstring sItemValue = GetItemText(hChildItem);
            std::wstring::size_type pos = sItemValue.find(L"\\", 0);
            if(pos != std::wstring::npos)
                sItemValue.erase(pos);

            if(sItemValue == *iterToken)
            {
                break;
            }

            hChildItem = hNextItem;
        }

        hItem = hChildItem;

        if(hItem != NULL)
        {
            // Found a matching item, select it and force expansion to populate tree
            SelectItem(hItem);
            Expand(hItem, TVE_EXPAND);
        }
        else
        {
            // Didn't find a matching item
            break;
        }
    }

    SetCursor(LoadCursor (NULL, IDC_ARROW));
    SetRedraw(TRUE);
}
Example #5
0
bool
CKeyMap::parseModifiers(CString& x, KeyModifierMask& mask)
{
	// initialize tables
	initKeyNameMaps();

	mask = 0;
	CString::size_type tb = x.find_first_not_of(" \t", 0);
	while (tb != CString::npos) {
		// get next component
		CString::size_type te = x.find_first_of(" \t+)", tb);
		if (te == CString::npos) {
			te = x.size();
		}
		CString c = x.substr(tb, te - tb);
		if (c.empty()) {
			// missing component
			return false;
		}

		if (s_nameToModifierMap->count(c) > 0) {
			KeyModifierMask mod = s_nameToModifierMap->find(c)->second;
			if ((mask & mod) != 0) {
				// modifier appears twice
				return false;
			}
			mask |= mod;
		}
		else {
			// unknown string
			x.erase(0, tb);
			CString::size_type tb = x.find_first_not_of(" \t");
			CString::size_type te = x.find_last_not_of(" \t");
			if (tb == CString::npos) {
				x = "";
			}
			else {
				x = x.substr(tb, te - tb + 1);
			}
			return true;
		}

		// check for '+' or end of string
		tb = x.find_first_not_of(" \t", te);
		if (tb != CString::npos) {
			if (x[tb] != '+') {
				// expected '+'
				return false;
			}
			tb = x.find_first_not_of(" \t", tb + 1);
		}
	}

	// parsed the whole thing
	x = "";
	return true;
}
Example #6
0
CString Font::GetFontName( CString sFileName )
{
	CString sOrig = sFileName;

	CString sDir, sFName, sExt;
	splitpath( sFileName, sDir, sFName, sExt );
	sFileName = sFName;

	/* If it ends in an extension, remove it. */
	static Regex drop_ext( "\\....$" );
	if( drop_ext.Compare(sFileName) )
		sFileName.erase( sFileName.size()-4 );

	/* If it ends in a resolution spec, remove it. */
	CStringArray asMatch;
	static Regex ResSpec( "( \\(res [0-9]+x[0-9]+\\))$" );
	if( ResSpec.Compare(sFileName, asMatch) )
		sFileName.erase(sFileName.size()-asMatch[0].size());

	/* If it ends in a dimension spec, remove it. */
	static Regex DimSpec( "( [0-9]+x[0-9]+)$" );
	if( DimSpec.Compare(sFileName, asMatch) )
		sFileName.erase( sFileName.size()-asMatch[0].size() );

	/* If it ends in texture hints, remove them. */
	static Regex Hints( "( \\([^\\)]+\\))$" );
	if( Hints.Compare(sFileName, asMatch) )
		sFileName.erase( sFileName.size()-asMatch[0].size() );

	/* If it ends in a page name, remove it. */
	static Regex PageName("( \\[.+\\])$");
	if( PageName.Compare( sFileName, asMatch ) )
		sFileName.erase( sFileName.size()-asMatch[0].size() );

	TrimRight( sFileName );

	if( sFileName.empty() )
		RageException::Throw( "Can't parse font filename \"%s\"", sOrig.c_str() );

	sFileName.MakeLower();
	return sFileName;
}
Example #7
0
	CString CDataStream::GetLine()
	{
		// keep looping while not hitting delimiter
		int nReadCount;
		char szTmpBuf[MAX_PATH];
		CString szRet;
		while ( (nReadCount = Read(szTmpBuf, MAX_PATH - 1)) != 0)
		{
			// Terminate string
			szTmpBuf[nReadCount] = '\0';

			char *p = strchr(szTmpBuf, '\n');
			if (p != 0)
			{
				// reposition backwards
				Skip((long)(p + 1 - szTmpBuf - nReadCount));
				*p = '\0';
			}

			szRet = szTmpBuf;

			if (p != 0)
			{
				// trim off trailing cr if this was a cr/lf entry
				if (szRet.length() && szRet[szRet.length() - 1] == '\r')
				{
					szRet.erase(szRet.length() - 1, 1);
				}

				// found terminator, break out
				break;
			}
		}

		CStringUtil::Trim(szRet);

		return szRet;
	}