Ejemplo n.º 1
0
wxString wxFileTypeImpl::GetCommand(const wxString& verb) const
{
    wxString command = wxAssocQueryString(ASSOCSTR_COMMAND, m_ext, verb);
    bool foundFilename = CanonicalizeParams(command);

#if wxUSE_IPC
    wxString ddeCommand = wxAssocQueryString(ASSOCSTR_DDECOMMAND, m_ext);
    wxString ddeTopic = wxAssocQueryString(ASSOCSTR_DDETOPIC, m_ext);

    if ( !ddeCommand.empty() && !ddeTopic.empty() )
    {
        wxString ddeServer = wxAssocQueryString( ASSOCSTR_DDEAPPLICATION, m_ext );

        ddeCommand.Replace(wxT("%1"), wxT("%s"));

        if ( ddeTopic.empty() )
            ddeTopic = wxT("System");

        // HACK: we use a special feature of wxExecute which exists
        //       just because we need it here: it will establish DDE
        //       conversation with the program it just launched
        command.Prepend(wxT("WX_DDE#"));
        command << wxT('#') << ddeServer
                << wxT('#') << ddeTopic
                << wxT('#') << ddeCommand;
    }
    else
#endif // wxUSE_IPC
    if ( !foundFilename && !command.empty() )
    {
        // we didn't find any '%1' - the application doesn't know which
        // file to open (note that we only do it if there is no DDEExec
        // subkey)
        //
        // HACK: append the filename at the end, hope that it will do
        command << wxT(" %s");
    }

    return command;
}
Ejemplo n.º 2
0
wxString wxFileTypeImpl::GetCommand(const wxString& verb) const
{
    // suppress possible error messages
    wxLogNull nolog;
    wxString strKey;

    {
        wxRegKey explorerKey(wxRegKey::HKCU, wxT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\") + m_ext);
        if (explorerKey.Exists())
        {
            if (explorerKey.Open(wxRegKey::Read))
            {
                if (explorerKey.QueryValue(wxT("Progid"), strKey))
                {
                    strKey = wxFileTypeImplGetCurVer(strKey);
                }
            }
        }
    }

    if (!strKey && wxRegKey(wxRegKey::HKCR, m_ext + wxT("\\shell")).Exists())
        strKey = m_ext;

    if ( !strKey && !m_strFileType.empty())
    {
        wxString fileType = wxFileTypeImplGetCurVer(m_strFileType);
        if (wxRegKey(wxRegKey::HKCR, fileType + wxT("\\shell")).Exists())
            strKey = fileType;
    }

    if ( !strKey )
    {
        // no info
        return wxEmptyString;
    }

    strKey << wxT("\\shell\\") << verb;
    wxRegKey key(wxRegKey::HKCR, strKey + wxT("\\command"));
    wxString command;
    if ( key.Open(wxRegKey::Read) ) {
        // it's the default value of the key
        if ( key.QueryValue(wxEmptyString, command) ) {
            bool foundFilename = CanonicalizeParams(command);

#if wxUSE_IPC
            // look whether we must issue some DDE requests to the application
            // (and not just launch it)
            strKey += wxT("\\DDEExec");
            wxRegKey keyDDE(wxRegKey::HKCR, strKey);
            if ( keyDDE.Open(wxRegKey::Read) ) {
                wxString ddeCommand, ddeServer, ddeTopic;
                keyDDE.QueryValue(wxEmptyString, ddeCommand);
                ddeCommand.Replace(wxT("%1"), wxT("%s"));

                wxRegKey keyServer(wxRegKey::HKCR, strKey + wxT("\\Application"));
                keyServer.QueryValue(wxEmptyString, ddeServer);
                wxRegKey keyTopic(wxRegKey::HKCR, strKey + wxT("\\Topic"));
                keyTopic.QueryValue(wxEmptyString, ddeTopic);

                if (ddeTopic.empty())
                    ddeTopic = wxT("System");

                // HACK: we use a special feature of wxExecute which exists
                //       just because we need it here: it will establish DDE
                //       conversation with the program it just launched
                command.Prepend(wxT("WX_DDE#"));
                command << wxT('#') << ddeServer
                        << wxT('#') << ddeTopic
                        << wxT('#') << ddeCommand;
            }
            else
#endif // wxUSE_IPC
            if ( !foundFilename )
            {
                // we didn't find any '%1' - the application doesn't know which
                // file to open (note that we only do it if there is no DDEExec
                // subkey)
                //
                // HACK: append the filename at the end, hope that it will do
                command << wxT(" %s");
            }
        }
    }
    //else: no such file type or no value, will return empty string

    return command;
}
Ejemplo n.º 3
0
wxString wxFileTypeImpl::GetCommand(const wxString& verb) const
{
    // suppress possible error messages
    wxLogNull nolog;
    wxString strKey;

    // Since Windows Vista the association used by Explorer is different from
    // the association information stored in the traditional part of the
    // registry. Unfortunately the new schema doesn't seem to be documented
    // anywhere so using it involves a bit of guesswork:
    //
    // The information is stored under Explorer-specific key whose path is
    // below. The interesting part is UserChoice subkey which is the only one
    // we use so far but there is also OpenWithProgids subkey which can exist
    // even if UserChoice doesn't. However in practice there doesn't seem to be
    // any cases when OpenWithProgids values for the given extension are
    // different from those found directly under HKCR\.ext, so for now we don't
    // bother to use this, apparently the programs registering their file type
    // associations do it in both places. We do use UserChoice because when the
    // association is manually changed by the user it's only recorded there and
    // so must override whatever value was created under HKCR by the setup
    // program.

    {
        wxRegKey explorerKey
                 (
                    wxRegKey::HKCU,
                    wxT("Software\\Microsoft\\Windows\\CurrentVersion\\")
                    wxT("Explorer\\FileExts\\") +
                    m_ext +
                    wxT("\\UserChoice")
                 );
        if ( explorerKey.Open(wxRegKey::Read) &&
                explorerKey.QueryValue(wxT("Progid"), strKey) )
        {
            strKey = wxFileTypeImplGetCurVer(strKey);
        }
    }

    if (!strKey && wxRegKey(wxRegKey::HKCR, m_ext + wxT("\\shell")).Exists())
        strKey = m_ext;

    if ( !strKey && !m_strFileType.empty())
    {
        wxString fileType = wxFileTypeImplGetCurVer(m_strFileType);
        if (wxRegKey(wxRegKey::HKCR, fileType + wxT("\\shell")).Exists())
            strKey = fileType;
    }

    if ( !strKey )
    {
        // no info
        return wxEmptyString;
    }

    strKey << wxT("\\shell\\") << verb;
    wxRegKey key(wxRegKey::HKCR, strKey + wxT("\\command"));
    wxString command;
    if ( key.Open(wxRegKey::Read) ) {
        // it's the default value of the key
        if ( key.QueryValue(wxEmptyString, command) ) {
            bool foundFilename = CanonicalizeParams(command);

#if wxUSE_IPC
            // look whether we must issue some DDE requests to the application
            // (and not just launch it)
            strKey += wxT("\\DDEExec");
            wxRegKey keyDDE(wxRegKey::HKCR, strKey);
            if ( keyDDE.Open(wxRegKey::Read) ) {
                wxString ddeCommand, ddeServer, ddeTopic;
                keyDDE.QueryValue(wxEmptyString, ddeCommand);

                // in some cases "DDEExec" subkey exists but has no value, we
                // shouldn't use DDE in this case
                if ( !ddeCommand.empty() ) {
                    ddeCommand.Replace(wxT("%1"), wxT("%s"));

                    wxRegKey keyServer(wxRegKey::HKCR, strKey + wxT("\\Application"));
                    keyServer.QueryValue(wxEmptyString, ddeServer);
                    wxRegKey keyTopic(wxRegKey::HKCR, strKey + wxT("\\Topic"));
                    keyTopic.QueryValue(wxEmptyString, ddeTopic);

                    if (ddeTopic.empty())
                        ddeTopic = wxT("System");

                    // HACK: we use a special feature of wxExecute which exists
                    //       just because we need it here: it will establish DDE
                    //       conversation with the program it just launched
                    command.Prepend(wxT("WX_DDE#"));
                    command << wxT('#') << ddeServer
                            << wxT('#') << ddeTopic
                            << wxT('#') << ddeCommand;
                }
            }
            else
#endif // wxUSE_IPC
            if ( !foundFilename )
            {
                // we didn't find any '%1' - the application doesn't know which
                // file to open (note that we only do it if there is no DDEExec
                // subkey)
                //
                // HACK: append the filename at the end, hope that it will do
                command << wxT(" %s");
            }
        }
    }
    //else: no such file type or no value, will return empty string

    return command;
}