Exemple #1
0
/// Loads a list of message IDs that should be passed on to the AOIA application
void LoadMessageFilter(HKEY hKeyParent, LPCTSTR lpszKeyName)
{
    g_messageFilter.empty();

    ATL::CRegKey reg;
    if (reg.Open(hKeyParent, lpszKeyName, KEY_READ) == ERROR_SUCCESS)
    {
        TCHAR subkey[256];
        DWORD skLength = 256;
        DWORD dw;
        int index = 0;

        while (true)
        {
            if (reg.EnumKey(index, subkey, &skLength) == ERROR_SUCCESS)
            {
                index++;
                if (reg.QueryDWORDValue(subkey, dw) == ERROR_SUCCESS)
                {
                    g_messageFilter.insert(dw);
                }
            }
            else
            {
                break;
            }
        }
    }
    else
    {
        LOG("Unable to open key: " << lpszKeyName)
    }
}
void CFileTypesForm::OnBnClickedButtonReload()
{
    for (DWORD i=0; i<pageCount; i++)
    {
        if (pages[i])
        {
            pages[i]->info.Clear();
            pages[i]->UpdateTree();
        }
    }

    DSUtil::FilterTemplates filters;
    filters.EnumerateAllRegisteredFilters();

    // search for registered protocols
    if (page_protocols)
    {
        ATL::CRegKey rkRoot(HKEY_CLASSES_ROOT);
        // only real protocols => not something like "WMP11.AssocProtocol.MMS"
        // faster, because i don't need to search in every entry for "Source Filter"
        TCHAR szName[10] = {0};
        DWORD szNameLength = 10;
        DWORD i = 0;
        long ret = 0;
        while (ERROR_NO_MORE_ITEMS != (ret = rkRoot.EnumKey(i++, szName, &szNameLength)))
        {
            if (ret != ERROR_SUCCESS)
                continue;

            CRegKey rkKey;
            if(ERROR_SUCCESS == rkKey.Open(HKEY_CLASSES_ROOT, szName, KEY_READ))
            {
                TCHAR szSourceFilterGuid[40] = {0};
                DWORD szLength = 40;
                if (ERROR_SUCCESS == rkKey.QueryStringValue(_T("Source Filter"), szSourceFilterGuid, &szLength))
                {
                    GraphStudio::PropItem* group = new GraphStudio::PropItem(CString(szName));

                    CString strClsid = szSourceFilterGuid;
                    GUID clsid = {0};
                    CLSIDFromString((LPOLESTR)strClsid.GetBuffer(), &clsid);

                    group->AddItem(new GraphStudio::PropItem(_T("CLSID"), CString(szSourceFilterGuid), false));

                    DSUtil::FilterTemplate ft;
		            if (filters.FindTemplateByCLSID(clsid, &ft))
                    {
                        group->AddItem(new GraphStudio::PropItem(_T("Name"), CString(ft.name), false));
                        group->AddItem(new GraphStudio::PropItem(_T("File"), CString(ft.file), false));
                    }

                    // last Change of this key
                    FILETIME timeMod = {0};
                    if (ERROR_SUCCESS == RegQueryInfoKey(rkKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &timeMod))
                        group->AddItem(new GraphStudio::PropItem(_T("Modified"), CTime(timeMod)));

                    page_protocols->info.AddItem(group);
                }
            }
            rkKey.Close();
            szNameLength = 10;
        }
        page_protocols->UpdateTree();
        rkRoot.Close();
    }

    // search for registered extensions
    if (page_extensions)
    {
        ATL::CRegKey rkRoot;
        CString strRoot = _T("Media Type\\Extensions");
        if (ERROR_SUCCESS == rkRoot.Open(HKEY_CLASSES_ROOT, strRoot, KEY_READ))
        {
            // {7DF62B50-6843-11D2-9EEB-006008039E37}
            static const GUID CLSID_StillVideo = {0x7DF62B50, 0x6843, 0x11D2, { 0x9E, 0xEB, 0x00, 0x60, 0x08, 0x03, 0x9E, 0x37} };

            TCHAR szName[50] = {0};
            DWORD szNameLength = 50;
            DWORD i = 0;
            while (ERROR_NO_MORE_ITEMS != rkRoot.EnumKey(i++, szName, &szNameLength))
            {
                CString strKey = strRoot;
                strKey.Append(_T("\\"));
                strKey.Append(szName);
                CRegKey rkKey;
                if(ERROR_SUCCESS == rkKey.Open(HKEY_CLASSES_ROOT, strKey, KEY_READ))
                {
                    GraphStudio::PropItem* group = new GraphStudio::PropItem(CString(szName));

                    TCHAR szGuid[40] = {0};
                    DWORD szLength = 40;
                    if (ERROR_SUCCESS == rkKey.QueryStringValue(_T("Source Filter"), szGuid, &szLength))
                    {
                        CString strClsid = szGuid;
                        GUID clsid = {0};
                        CLSIDFromString((LPOLESTR)strClsid.GetBuffer(), &clsid);
                        group->AddItem(new GraphStudio::PropItem(_T("CLSID"), CString(szGuid), false));

                        DSUtil::FilterTemplate ft;
		                if (filters.FindTemplateByCLSID(clsid, &ft))
                        {
                            group->AddItem(new GraphStudio::PropItem(_T("Name"), CString(ft.name), false));
                            group->AddItem(new GraphStudio::PropItem(_T("File"), CString(ft.file), false));
                        }
                        else if (clsid == CLSID_StillVideo)
                        {
                            group->AddItem(new GraphStudio::PropItem(_T("Name"), _T("Generate Still Video"), false));
                        }
                    }

                    szLength = 40;
                    if (ERROR_SUCCESS == rkKey.QueryStringValue(_T("Media Type"), szGuid, &szLength))
                    {
                        CString strMT;
                        GUID clsidMT = {0};
                        CLSIDFromString((LPOLESTR)strMT.GetBuffer(), &clsidMT);
                        GraphStudio::NameGuid(clsidMT,strMT,CgraphstudioApp::g_showGuidsOfKnownTypes);
                        group->AddItem(new GraphStudio::PropItem(_T("MediaType"), strMT, false));
                    }

                    szLength = 40;
                    if (ERROR_SUCCESS == rkKey.QueryStringValue(_T("SubType"), szGuid, &szLength))
                    {
                        CString strST = szGuid;
                        GUID clsidST = {0};
                        CLSIDFromString((LPOLESTR)strST.GetBuffer(), &clsidST);
                        GraphStudio::NameGuid(clsidST,strST,CgraphstudioApp::g_showGuidsOfKnownTypes);
                        group->AddItem(new GraphStudio::PropItem(_T("SubType"), strST, false));
                    }

                    // last Change of this key
                    FILETIME timeMod = {0};
                    if (ERROR_SUCCESS == RegQueryInfoKey(rkKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &timeMod))
                        group->AddItem(new GraphStudio::PropItem(_T("Modified"), CTime(timeMod)));

                    page_extensions->info.AddItem(group);
                }
                rkKey.Close();
                szNameLength = 50;
            }
            page_extensions->UpdateTree();
        }
        rkRoot.Close();
    }

    // search for registered byte pattern
    if (page_bytes)
    {
        ATL::CRegKey rkRoot;
        CString strRoot = _T("Media Type");
        if (ERROR_SUCCESS == rkRoot.Open(HKEY_CLASSES_ROOT, strRoot, KEY_READ))
        {
            TCHAR szMTName[40] = {0};
            DWORD szMTNameLength = 40;
            DWORD i = 0;
            while (ERROR_NO_MORE_ITEMS != rkRoot.EnumKey(i++, szMTName, &szMTNameLength))
            {
                CString strMT = szMTName;
                GUID clsidMT = {0};
                if(NOERROR == CLSIDFromString((LPOLESTR)strMT.GetBuffer(), &clsidMT))
                {
                    GraphStudio::NameGuid(clsidMT,strMT,false);

                    CString strKeyMT = strRoot;
                    strKeyMT.Append(_T("\\"));
                    strKeyMT.Append(szMTName);
                    CRegKey rkKeyMT;
                    if(ERROR_SUCCESS == rkKeyMT.Open(HKEY_CLASSES_ROOT, strKeyMT, KEY_READ))
                    {
                        TCHAR szSTName[40] = {0};
                        DWORD szSTNameLength = 40;
                        DWORD j = 0;
                        while (ERROR_NO_MORE_ITEMS != rkKeyMT.EnumKey(j++, szSTName, &szSTNameLength))
                        {
                            CString strST = szSTName;
                            GUID clsidST = {0};
                            if(NOERROR == CLSIDFromString((LPOLESTR)strST.GetBuffer(), &clsidST))
                            {
                                GraphStudio::NameGuid(clsidST,strST,false);

                                CString strKeyST = strKeyMT;
                                strKeyST.Append(_T("\\"));
                                strKeyST.Append(szSTName);
                                CRegKey rkKeyST;

                                if(ERROR_SUCCESS == rkKeyST.Open(HKEY_CLASSES_ROOT, strKeyST, KEY_READ))
                                {
                                    TCHAR szGuid[40] = {0};
                                    DWORD szLength = 40;
                                    if (ERROR_SUCCESS == rkKeyST.QueryStringValue(_T("Source Filter"), szGuid, &szLength))
                                    {
                                        CString groupName = strMT;
                                        groupName.Append(_T("\\"));
                                        groupName.Append(strST);
                                        GraphStudio::PropItem* group = new GraphStudio::PropItem(groupName);

                                        CString strClsid = szGuid;
                                        GUID clsid = {0};
                                        CLSIDFromString((LPOLESTR)strClsid.GetBuffer(), &clsid);
                                        group->AddItem(new GraphStudio::PropItem(_T("CLSID"), CString(szGuid), false));

                                        DSUtil::FilterTemplate ft;
		                                if (filters.FindTemplateByCLSID(clsid, &ft))
                                        {
                                            group->AddItem(new GraphStudio::PropItem(_T("Name"), CString(ft.name), false));
                                            group->AddItem(new GraphStudio::PropItem(_T("File"), CString(ft.file), false));
                                        }

                                        // Enumerate the values
                                        TCHAR szValueName[5] = {0};
                                        DWORD szValueNameLength = 5;
                                        DWORD dwRegType;
                                        DWORD k = 0;
                                        long ret = 0;
                                        while (ERROR_NO_MORE_ITEMS != (ret = RegEnumValue(rkKeyST, k++, szValueName, &szValueNameLength, NULL, &dwRegType, NULL, NULL)))
                                        {
                                            if (dwRegType == REG_SZ && ret == ERROR_SUCCESS)
                                            {
                                                TCHAR szValue[255] = {0};
                                                DWORD szValueLength = 255;
                                                if (ERROR_SUCCESS == rkKeyST.QueryStringValue(szValueName, szValue, &szValueLength))
                                                {
                                                    CString strValue = szValue;
                                                    CStringArray arValues;
                                                    DSUtil::Tokenizer(strValue, _T(","), arValues);
                                                    
                                                    CString strResultValue;
                                                    bool lastTokenWasEmpty = false;
                                                    for (int i=0; i<arValues.GetCount(); i++)
                                                    {
                                                        CString strToken = arValues.GetAt(i);
                                                        strToken = strToken.Trim();

                                                        switch (i % 4)
                                                        {
                                                            case 0:
                                                                if (i > 0) strResultValue.Append(_T(" && ["));
                                                                else strResultValue.Append(_T("["));
                                                                strResultValue.Append(strToken);
                                                                break;

                                                            case 1:
                                                                strResultValue.Append(_T(","));
                                                                strResultValue.Append(strToken);
                                                                break;

                                                            case 2:
                                                                strResultValue.Append(_T("] => ("));
                                                                strResultValue.Append(ByteFormatString(strToken));
                                                                break;

                                                            case 3:
                                                                if (!lastTokenWasEmpty) strResultValue.Append(_T(" = "));
                                                                strResultValue.Append(ByteFormatString(strToken));
                                                                strResultValue.Append(_T(")"));
                                                                break;
                                                        }

                                                        lastTokenWasEmpty = strToken.IsEmpty();
                                                    }

                                                    group->AddItem(new GraphStudio::PropItem(CString(szValueName), strResultValue, false));
                                                    // TODO maybe better format of the byte string
                                                }
                                            }
                                            szValueNameLength = 5;
                                        }

                                        // last Change of this key
                                        FILETIME timeMod = {0};
                                        if (ERROR_SUCCESS == RegQueryInfoKey(rkKeyST, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &timeMod))
                                            group->AddItem(new GraphStudio::PropItem(_T("Modified"), CTime(timeMod)));

                                        page_bytes->info.AddItem(group);
                                    }
                                }
                                rkKeyST.Close();
                            }
                            szSTNameLength = 40;
                        }
                    }
                    rkKeyMT.Close();
                }
                szMTNameLength = 40;
            }
            page_bytes->UpdateTree();
        }
        rkRoot.Close();
    }
}