示例#1
0
//设置配置项的值(字符串)
void CIniFile::SetString(const char* sSectionName, const char* sKeyName, const char* sKeyValue)
{
	int i = GetSectionIndex(0,sSectionName);
	int j;
	if(i < 0)
		i = AddSection(sSectionName);
	if(i >= 0)
		j = GetKeyIndex(i, sKeyName);
	else 
		return;
	
	struct LINE_ITEM *pItem;
	if(j >= 0)
	{
		pItem = (struct LINE_ITEM *)m_arrayOfLine.GetAt(j);
		pItem->sValue = sKeyValue;
	}
	else
	{
		pItem = new struct LINE_ITEM;
		pItem->nType = LINE_TYPE_KEY;
		pItem->sName = sKeyName;
		pItem->sValue = sKeyValue;
		m_arrayOfLine.InsertAt(i + 1, pItem);
		j = i+1;
	}
	if(j >= 0)
		m_bModified = true;
	if(m_bAutoFlush)
		FlushToFile();
}
示例#2
0
PRBool KeyboardLayout::IsPrintableCharKey (PRUint8 aVirtualKey)
{
#ifndef WINCE
  return GetKeyIndex (aVirtualKey) >= 0;
#else
  return PR_FALSE;
#endif
}
示例#3
0
//配置项值操作方法
//取得配置项的值(字符串)
CString CIniFile::GetString(const char* sSectionName, const char* sKeyName)
{
	int i = GetSectionIndex(0,sSectionName);
	if(i >= 0)
		i = GetKeyIndex(i, sKeyName);
	if(i >= 0)
	{
		struct LINE_ITEM *pItem = (struct LINE_ITEM *)m_arrayOfLine.GetAt(i);
		if(pItem)
			return pItem->sValue;
	}

	return "";
}
示例#4
0
void ParseKeyValue(
		const QByteArray &key,
		const QByteArray &value,
		Save &&save) {
	const auto index = GetKeyIndex(QLatin1String(key));
	if (index != kLangKeysCount) {
		ValueParser parser(key, index, value);
		if (parser.parse()) {
			save(index, parser.takeResult());
		}
	} else if (!key.startsWith("cloud_")) {
		DEBUG_LOG(("Lang Warning: Unknown key '%1'"
			).arg(QString::fromLatin1(key)));
	}
}
PRUint32
KeyboardLayout::GetUniCharsWithShiftState(PRUint8 aVirtualKey,
                                          PRUint8 aShiftStates,
                                          PRUnichar* aUniChars,
                                          PRUint32 aMaxChars) const
{
  PRInt32 key = GetKeyIndex(aVirtualKey);
  if (key < 0)
    return 0;
  PRUint8 finalShiftState;
  PRUnichar uniChars[5];
  PRUint32 numOfBaseChars =
    mVirtualKeys[key].GetUniChars(aShiftStates, uniChars, &finalShiftState);
  PRUint32 chars = PR_MIN(numOfBaseChars, aMaxChars);

  memcpy(aUniChars, uniChars, chars * sizeof (PRUnichar));

  return chars;
}
示例#6
0
PRUint32 KeyboardLayout::GetDeadKeyCombinations (PRUint8 aDeadKey, const PBYTE aDeadKeyKbdState,
                                                 PRUint16 aShiftStatesWithBaseChars,
                                                 DeadKeyEntry* aDeadKeyArray, PRUint32 aMaxEntries)
{
  PRBool deadKeyActive = PR_FALSE;
  PRUint32 entries = 0;
  BYTE kbdState [256];
  
  memset (kbdState, 0, sizeof (kbdState));
  
  for (PRUint32 shiftState = 0; shiftState < 16; shiftState++)
  {
    if (!(aShiftStatesWithBaseChars & (1 << shiftState)))
      continue;

    SetShiftState (kbdState, shiftState);

    for (PRUint32 virtualKey = 0; virtualKey < 256; virtualKey++)
    {
      PRInt32 vki = GetKeyIndex (virtualKey);
      
      // Dead-key can pair only with such key that produces exactly one base character.
      if (vki >= 0 && mVirtualKeys [vki].GetNativeUniChars (shiftState) == 1)
      {
        // Ensure dead-key is in active state, when it swallows entered character and waits for the next pressed key.
        if (!deadKeyActive)
          deadKeyActive = EnsureDeadKeyActive (PR_TRUE, aDeadKey, aDeadKeyKbdState);

        // Depending on the character the followed the dead-key, the keyboard driver can produce
        // one composite character, or a dead-key character followed by a second character.
        PRUint16 compositeChars [5];
        PRInt32 rv;

        rv = ::ToUnicodeEx (virtualKey, 0, kbdState, (LPWSTR)compositeChars, NS_ARRAY_LENGTH (compositeChars), 0, mKeyboardLayout);

        switch (rv)
        {
          case 0:
            // This key combination does not produce any characters. The dead-key is still in active state.
            break;

          case 1:
          {
            // Exactly one composite character produced. Now, when dead-key is not active, repeat the last
            // character one more time to determine the base character.
            PRUint16 baseChars [5];

            rv = ::ToUnicodeEx (virtualKey, 0, kbdState, (LPWSTR)baseChars, NS_ARRAY_LENGTH (baseChars), 0, mKeyboardLayout);

            NS_ASSERTION (rv == 1, "One base character expected");

            if (rv == 1 && entries < aMaxEntries)
              if (AddDeadKeyEntry (baseChars [0], compositeChars [0], aDeadKeyArray, entries))
                entries++;
            
            deadKeyActive = PR_FALSE;
            break;
          }

          default:
            // 1. Unexpected dead-key. Dead-key chaining is not supported.
            // 2. More than one character generated. This is not a valid dead-key and base character combination.
            deadKeyActive = PR_FALSE;
            break;
        }
      }
    }
  }

  if (deadKeyActive)
    deadKeyActive = EnsureDeadKeyActive (PR_FALSE, aDeadKey, aDeadKeyKbdState);

  NS_QuickSort (aDeadKeyArray, entries, sizeof (DeadKeyEntry), CompareDeadKeyEntries, nsnull);

  return entries;
}
示例#7
0
void KeyboardLayout::LoadLayout (HKL aLayout)
{
#ifndef WINCE
  PRUint32 shiftState;
  BYTE kbdState [256];
  BYTE originalKbdState [256];
  PRUint16 shiftStatesWithDeadKeys = 0;     // Bitfield with all shift states that have at least one dead-key.
  PRUint16 shiftStatesWithBaseChars = 0;    // Bitfield with all shift states that produce any possible dead-key base characters.

  memset (kbdState, 0, sizeof (kbdState));

  mActiveDeadKey = -1;
  mNumOfChars = 0;
  mKeyboardLayout = aLayout;

  ReleaseDeadKeyTables ();

  ::GetKeyboardState (originalKbdState);

  // For each shift state gather all printable characters that are produced
  // for normal case when no any dead-key is active.
  
  for (shiftState = 0; shiftState < 16; shiftState++)
  {
    SetShiftState (kbdState, shiftState);

    for (PRUint32 virtualKey = 0; virtualKey < 256; virtualKey++)
    {
      PRInt32 vki = GetKeyIndex (virtualKey);
      if (vki < 0)
        continue;

      NS_ASSERTION (vki < NS_ARRAY_LENGTH (mVirtualKeys), "invalid index"); 

      PRUint16 uniChars [5];
      PRInt32 rv;

      rv = ::ToUnicodeEx (virtualKey, 0, kbdState, (LPWSTR)uniChars, NS_ARRAY_LENGTH (uniChars), 0, mKeyboardLayout);

      if (rv < 0)   // dead-key
      {      
        shiftStatesWithDeadKeys |= 1 << shiftState;
        
        // Repeat dead-key to deactivate it and get its character representation.
        PRUint16 deadChar [2];

        rv = ::ToUnicodeEx (virtualKey, 0, kbdState, (LPWSTR)deadChar, NS_ARRAY_LENGTH (deadChar), 0, mKeyboardLayout);

        NS_ASSERTION (rv == 2, "Expecting twice repeated dead-key character");

        mVirtualKeys [vki].SetDeadChar (shiftState, deadChar [0]);
      } else
      {
        if (rv == 1)  // dead-key can pair only with exactly one base character.
          shiftStatesWithBaseChars |= 1 << shiftState;

        mVirtualKeys [vki].SetNormalChars (shiftState, uniChars, rv);
      }
    }
  }

  
  // Now process each dead-key to find all its base characters and resulting composite characters.

  for (shiftState = 0; shiftState < 16; shiftState++)
  {
    if (!(shiftStatesWithDeadKeys & (1 << shiftState)))
      continue;

    SetShiftState (kbdState, shiftState);

    for (PRUint32 virtualKey = 0; virtualKey < 256; virtualKey++)
    {
      PRInt32 vki = GetKeyIndex (virtualKey);
  
      if (vki >= 0 && mVirtualKeys [vki].IsDeadKey (shiftState))
      {      
        DeadKeyEntry deadKeyArray [256];

        PRInt32 n = GetDeadKeyCombinations (virtualKey, kbdState, shiftStatesWithBaseChars, 
                                            deadKeyArray, NS_ARRAY_LENGTH (deadKeyArray));

        const DeadKeyTable* dkt = mVirtualKeys [vki].MatchingDeadKeyTable (deadKeyArray, n);
          
        if (!dkt)
          dkt = AddDeadKeyTable (deadKeyArray, n);
        
        mVirtualKeys [vki].AttachDeadKeyTable (shiftState, dkt);
      }
    }
  }

  ::SetKeyboardState (originalKbdState);
#endif
}
示例#8
0
void KeyboardLayout::OnKeyDown (PRUint8 aVirtualKey)
{
#ifndef WINCE
  mLastVirtualKeyIndex = GetKeyIndex (aVirtualKey);

  if (mLastVirtualKeyIndex < 0)
  {
    // Does not produce any printable characters, but still preserves the dead-key state.
    mNumOfChars = 0;
  } else
  {
    BYTE kbdState [256];

    if (::GetKeyboardState (kbdState))
    {
      mLastShiftState = GetShiftState (kbdState);

      if (mVirtualKeys [mLastVirtualKeyIndex].IsDeadKey (mLastShiftState))
      {
        if (mActiveDeadKey >= 0)
        {
          // Dead-key followed by another dead-key. Reset dead-key state and return both dead-key characters.
          PRInt32 activeDeadKeyIndex = GetKeyIndex (mActiveDeadKey);
          mVirtualKeys [activeDeadKeyIndex].GetUniChars (mDeadKeyShiftState, mChars, mShiftStates);
          mVirtualKeys [mLastVirtualKeyIndex].GetUniChars (mLastShiftState, &mChars [1], &mShiftStates [1]);
          mNumOfChars = 2;
          
          DeactivateDeadKeyState ();
        } else
        {
          // Dead-key state activated. No characters generated.
          mActiveDeadKey = aVirtualKey;
          mDeadKeyShiftState = mLastShiftState;
          mNumOfChars = 0;
        }
      } else
      {
        PRUint8 finalShiftState;
        PRUint16 uniChars [5];
        PRUint32 numOfBaseChars = mVirtualKeys [mLastVirtualKeyIndex].GetUniChars (mLastShiftState, uniChars, &finalShiftState);

        if (mActiveDeadKey >= 0)
        {
          PRInt32 activeDeadKeyIndex = GetKeyIndex (mActiveDeadKey);
          
          // Dead-key was active. See if pressed base character does produce valid composite character.
          PRUint16 compositeChar = (numOfBaseChars == 1 && uniChars [0]) ?
            mVirtualKeys [activeDeadKeyIndex].GetCompositeChar (mDeadKeyShiftState, uniChars [0]) : 0;

          if (compositeChar)
          {
            // Active dead-key and base character does produce exactly one composite character.
            mChars [0] = compositeChar;
            mShiftStates [0] = finalShiftState;
            mNumOfChars = 1;
          } else
          {
            // There is no valid dead-key and base character combination. Return dead-key character followed by base character.
            mVirtualKeys [activeDeadKeyIndex].GetUniChars (mDeadKeyShiftState, mChars, mShiftStates);
            memcpy (&mChars [1], uniChars, numOfBaseChars * sizeof (PRUint16));
            memset (&mShiftStates [1], finalShiftState, numOfBaseChars);
            mNumOfChars = numOfBaseChars + 1;
          }
        
          DeactivateDeadKeyState ();
        } else
        {
          // No dead-keys are active. Just return the produced characters.
          memcpy (mChars, uniChars, numOfBaseChars * sizeof (PRUint16));
          memset (mShiftStates, finalShiftState, numOfBaseChars);
          mNumOfChars = numOfBaseChars;
        }
      }
    }
  }
#endif
}
示例#9
0
ForceInline void main2(int argc, TCHAR **argv)
{
    if (argc < 2)
    {
        _tprintf(_T("%s input_dir\n"), findname(argv[0]));
        return;
    }

    TCHAR  szOutFile[MAX_PATH];
    HANDLE hOut, hHeap;
    DWORD  dwLength, dwEntryCount;
    PAZTYPE PazType;
    TMyPAZEntry *pEntry;

    hHeap = GetProcessHeap();
    ghHeap = hHeap;
    for (int i = 1; i != argc; ++i)
    {
        Char  (*pPazHeader)[sizeof(headers[0])];
        DWORD dwAttributes;

        dwAttributes = GetFileAttributes(argv[i]);
        if (dwAttributes == -1)
        {
            _tprintf(_T("\"%s\" doesn't exist.\n"), argv[i]);
            continue;
        }
        else if ((dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
        {
            _tprintf(_T("%s isn't a directory.\n"), argv[i]);
            continue;
        }

        LPCSTR lpPath;

        lstrcpy(szOutFile, argv[i]);
        dwLength = lstrlen(szOutFile);
        if (szOutFile[dwLength - 1] == '\\')
            szOutFile[dwLength - 1] = 0;
        lstrcat(szOutFile, ".paz");

        lpPath = argv[i];
        PazType = NONE;
        if (i + 2 < argc)
        {
            int j = i + 1;
            if (argv[j][0] == '-' && ((argv[j][1] & 0xDF) == 'T'))
            {
                ++j;
                for (int k = 0; k != countof(szType); ++k)
                {
                    if (!lstrcmpi(szType[k], argv[j]))
                    {
                        i = j;
                        PazType = (PAZTYPE)k;
                        break;
                    }
                }
            }
        }
        else
        {
            PazType = GetPazTypeFromFileName(szOutFile);
        }

        if (PazType == NONE)
        {
            _tprintf(_T("Please specify one PAZ type by -t type or use a special file name.\n")
                _T("Following type is valid: \n\t")
                );
            for (int i = 0; i != countof(szType); ++i)
            {
                printf("%s ", szType[i]);
                if (i == countof(szType) / 2)
                    printf("\n\t");
            }

            break;
        }

        dwKeyIndex = GetKeyIndex(szType[PazType], &GameInfo[dwInfoIndex]);
        if (dwKeyIndex == -1)
        {
            printf("%s: don't know encryption key.\n", szOutFile);
            continue;
        }

        hOut = CreateFile(szOutFile,
                        GENERIC_READ|GENERIC_WRITE,
                        FILE_SHARE_READ|FILE_SHARE_WRITE,
                        NULL,
                        CREATE_ALWAYS,
                        FILE_ATTRIBUTE_NORMAL,
                        NULL);
        if (hOut == INVALID_HANDLE_VALUE)
        {
            _tprintf(_T("Can't create \"%s\"\n"), szOutFile);
            continue;
        }

        g_bIsMovie = IsMovie(szOutFile);
        bIsVoice = IsAudio(szOutFile);
        SetCurrentDirectory(lpPath);
        dwEntryCount = GenerateEntry(&pEntry);
        if (dwEntryCount == 0 || pEntry == NULL)
        {
            _tprintf(_T("There is no file in \"%s\"\n"), argv[i]);
            continue;
        }

        bNeedXor = strnicmp(szType[PazType], "pm", 2) != 0;
        _tprintf(_T("Packing %s ...\n"), szOutFile);
        if (bNeedXor)
        {
            pPazHeader = (Char (*)[32])headers[dwInfoIndex];
        }
        else
            pPazHeader = (Char (*)[32])headers[countof(headers) - 1];

        WriteFile(hOut, pPazHeader, sizeof(*pPazHeader), &dwLength, NULL);
        WriteEntry(hOut, pEntry, dwEntryCount, False);

        WriteFileToPaz(hOut, pEntry, dwEntryCount, PazType);
        WriteEntry(hOut, pEntry, dwEntryCount, True);

//        HeapFree(hHeap, 0, pEntry);
        FreeFileList(pEntry);
        CloseHandle(hOut);
    }
}
PRBool KeyboardLayout::IsPrintableCharKey (PRUint8 aVirtualKey)
{
  return GetKeyIndex (aVirtualKey) >= 0;
}