Reperire informazioni DirectX e XNA framework c#

Con risposta Reperire informazioni DirectX e XNA framework c#

  • lunedì 6 agosto 2012 11:41
     
     
    Ho una domanda. Come faccio a verificare se xna framework è installato sul comupter da codice e eventualmente reperire anche una sua versione. Stessa cosa, come faccio a verificare quale versione directx è installata sul pc sempre da codice? grazie

Tutte le risposte

  • lunedì 6 agosto 2012 14:31
     
     

    per XNA pensavo di verificare tramite valore nel registro HKLM\\SOFTWARE\\Microsoft\\XNA\\4.0 se esiste vuol dire che è installato altrimenti no. Questo posso farlo anche per la directx in HKLM\\SOFTWARE\\Microsoft\\DirectX\\Version.

    Entrambi i casi sembrano funzionare bene. Sicuramente non sono affidabili al 100%. magari potrebbe mancare un informazione sul registro però potrebbero essere installate quindi non so se ci sono altri metodi magari qualcche funzione in c# che utilizzi l'environment o qualcosa di integrato a VS.

  • mercoledì 8 agosto 2012 14:26
     
     Con risposta Contiene codice

    per ora ho risolto in questo modo:

    private bool GetXNAFramework(RegistryKey registryEntry)
            {
                bool find = true;
                using (RegistryKey registryXNA = registryEntry.OpenSubKey("SOFTWARE\\Microsoft\\XNA\\Framework\\v4.0"))
                {
                    if (registryXNA != null) 
                    {
                        try
                        {
                            string XNAVersion = (string)registryXNA.GetValue("ProductVersion", "null");
                            if (!XNAVersion.Equals("null"))
                            {
                                if (XNAVersion.Length > 3) { XNAVersion = XNAVersion.Remove(3, XNAVersion.Length - 3); }
                                if (Convert.ToDouble(XNAVersion) < 4.0f) { find = false; }
                            }
                            else { find = false; }
                        }
                        catch (Exception) { find = false; }
                    }
                    else { find = false; }
                }
                return find;
            }
    
    
    private bool GetDirectXVersion(RegistryKey registryEntry)
            {
                bool find = true;
                using (RegistryKey registryDirectX = registryEntry.OpenSubKey("SOFTWARE\\Microsoft\\DirectX"))
                {
                    if (registryDirectX != null)
                    {
                        try
                        {
                            string DirectXVersion = (string)registryDirectX.GetValue("Version", "null");
                            if (!DirectXVersion.Equals("null"))
                            {
                                if (DirectXVersion.Length > 3) { DirectXVersion = DirectXVersion.Remove(3, DirectXVersion.Length - 3); }
                                if (Convert.ToDouble(DirectXVersion) < 4.0f) { find = false; }
                            }
                            else { find = false; }
                        }
                        catch (Exception) { find = false; }
                    }
                    else { find = false; }
                }
                return find;
            }

    in questo modo (testato da me) funziona come dovrebbe. Ma sono un po titubante sull'utilizzo di questo algoritmo da me sviluppato. Se ce un'altro modo più facile senza fare giri strani e piu affidabile magari fatemelo sapere. Grazie :)