Ejemplo n.º 1
0
        internal Game(System.Management.ManagementBaseObject game)
        {
            this.name = game.GetPropertyValue("Name") as string;
            this.instanceID = game.GetPropertyValue("InstanceID") as string;
            this.gameID = game.GetPropertyValue("GameID") as string;
            this.gdfPath = game.GetPropertyValue("GDFBinaryPath") as string;
            string str1 = this.gdfPath;
            this.installPath = game.GetPropertyValue("GameInstallPath") as string;
            this.gdfResourceID = game.GetPropertyValue("ResourceIDForGDFInfo") as string;
            this.installScope = (Game.GameInstallScope)game.GetPropertyValue("InstallScope");
            this.RefreshTasks();
            if (this.gdfPath != null)
            {
                try
                {
                    using (UnmanagedLibrary unmanagedLibrary = new UnmanagedLibrary(this.gdfPath))
                    {
                        try
                        {
                            byte[] bytes = ResourceExtensions.GetBytes(unmanagedLibrary.GetResource("__GDF_THUMBNAIL", (object)"DATA"));
                            if (bytes != null)
                            {
                                try
                                {
                                    this.image = (ImageSource)BitmapDecoder.Create((Stream)new MemoryStream(bytes), BitmapCreateOptions.None, BitmapCacheOption.Default).Frames[0];
                                }
                                catch (Exception ex)
                                {
                                    Trace.TraceWarning("Image for " + this.name + "could not be loaded: " + ex .Message);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Trace.TraceWarning("Error attempting to get image resource for " + this.name + "could not be loaded: " + ex.Message);
                        }
                        using (RegistryKey registryKey1 = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\GameUX\\"))
                        {
                            if (registryKey1 != null)
                            {
                                foreach (object obj in registryKey1.GetSubKeyNames())
                                {
                                    string name = string.Format("{0}\\{1}", obj, (object)this.instanceID);
                                    RegistryKey registryKey2 = registryKey1.OpenSubKey(name);
                                    if (registryKey2 != null)
                                    {
                                        using (registryKey2)
                                        {
                                            if (this.image == null)
                                            {
                                                string uriString = registryKey2.GetValue("BoxArt") as string;
                                                if (uriString != null)
                                                {
                                                    try
                                                    {
                                                        this.image = (ImageSource)BitmapDecoder.Create(new Uri(uriString), BitmapCreateOptions.None, BitmapCacheOption.Default).Frames[0];
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Trace.TraceWarning("Image for legacy game " + this.name + "could not be loaded: " + ex.Message);
                                                    }
                                                }
                                            }
                                            this.description = registryKey2.GetValue("Description") as string;
                                            if (this.playTasks.Count == 0)
                                            {
                                                string str2 = registryKey2.GetValue("AppExePath") as string;
                                                if (str2 != null)
                                                {
                                                    this.playTasks.Add(str2);
                                                    str1 = str2;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        string name1 = this.gdfResourceID ?? "__GDF_XML";
                        byte[] bytes1 = ResourceExtensions.GetBytes(unmanagedLibrary.GetResource(name1, (object)"DATA"));
                        if (bytes1 != null)
                        {
                            XmlDocument xmlDocument = new XmlDocument();
                            xmlDocument.Load((XmlReader)new XmlTextReader((Stream)new MemoryStream(bytes1)));
                            foreach (XmlNode xmlNode in xmlDocument.DocumentElement.FirstChild.ChildNodes)
                            {
                                XmlElement xmlElement = xmlNode as XmlElement;
                                if (xmlElement != null && xmlElement.Name == "Description")
                                    this.description = xmlElement.InnerXml;
                            }
                        }
                        else
                            Trace.TraceWarning("GDF resource not found for " + this.Name + ".");
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceWarning("Error getting GDF data for " + this.name + "could not be loaded: " + ex.Message);
                }
            }
            if (this.playTasks.Count == 0)
            {
                this.IsValid = false;
                this.InvalidReason = "Could not find a play task for " + this.name + ".";
                return;
            }
            if (this.image != null)
                return;
            string filename = (string)null;
            if (this.playTasks.Count > 0)
            {
                try
                {
                    WshShell shell = new WshShell();
                    filename = ((IWshShortcut)shell.CreateShortcut(this.playTasks[0])).TargetPath;
                }
                catch
                {

                }
            }
            if (string.IsNullOrEmpty(filename))
                filename = str1;
            if (string.IsNullOrEmpty(filename))
                return;
            this.image = Shell.GenerateThumbnail(filename);
        }
Ejemplo n.º 2
0
        internal Game(System.Management.ManagementBaseObject game)
        {
            this.name       = game.GetPropertyValue("Name") as string;
            this.instanceID = game.GetPropertyValue("InstanceID") as string;
            this.gameID     = game.GetPropertyValue("GameID") as string;
            this.gdfPath    = game.GetPropertyValue("GDFBinaryPath") as string;
            string str1 = this.gdfPath;

            this.installPath   = game.GetPropertyValue("GameInstallPath") as string;
            this.gdfResourceID = game.GetPropertyValue("ResourceIDForGDFInfo") as string;
            this.installScope  = (Game.GameInstallScope)game.GetPropertyValue("InstallScope");
            this.RefreshTasks();
            if (this.gdfPath != null)
            {
                try
                {
                    using (UnmanagedLibrary unmanagedLibrary = new UnmanagedLibrary(this.gdfPath))
                    {
                        try
                        {
                            byte[] bytes = ResourceExtensions.GetBytes(unmanagedLibrary.GetResource("__GDF_THUMBNAIL", (object)"DATA"));
                            if (bytes != null)
                            {
                                try
                                {
                                    this.image = (ImageSource)BitmapDecoder.Create((Stream) new MemoryStream(bytes), BitmapCreateOptions.None, BitmapCacheOption.Default).Frames[0];
                                }
                                catch (Exception ex)
                                {
                                    Trace.TraceWarning("Image for " + this.name + "could not be loaded: " + ex.Message);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Trace.TraceWarning("Error attempting to get image resource for " + this.name + "could not be loaded: " + ex.Message);
                        }
                        using (RegistryKey registryKey1 = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\GameUX\\"))
                        {
                            if (registryKey1 != null)
                            {
                                foreach (object obj in registryKey1.GetSubKeyNames())
                                {
                                    string      name         = string.Format("{0}\\{1}", obj, (object)this.instanceID);
                                    RegistryKey registryKey2 = registryKey1.OpenSubKey(name);
                                    if (registryKey2 != null)
                                    {
                                        using (registryKey2)
                                        {
                                            if (this.image == null)
                                            {
                                                string uriString = registryKey2.GetValue("BoxArt") as string;
                                                if (uriString != null)
                                                {
                                                    try
                                                    {
                                                        this.image = (ImageSource)BitmapDecoder.Create(new Uri(uriString), BitmapCreateOptions.None, BitmapCacheOption.Default).Frames[0];
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Trace.TraceWarning("Image for legacy game " + this.name + "could not be loaded: " + ex.Message);
                                                    }
                                                }
                                            }
                                            this.description = registryKey2.GetValue("Description") as string;
                                            if (this.playTasks.Count == 0)
                                            {
                                                string str2 = registryKey2.GetValue("AppExePath") as string;
                                                if (str2 != null)
                                                {
                                                    this.playTasks.Add(str2);
                                                    str1 = str2;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        string name1  = this.gdfResourceID ?? "__GDF_XML";
                        byte[] bytes1 = ResourceExtensions.GetBytes(unmanagedLibrary.GetResource(name1, (object)"DATA"));
                        if (bytes1 != null)
                        {
                            XmlDocument xmlDocument = new XmlDocument();
                            xmlDocument.Load((XmlReader) new XmlTextReader((Stream) new MemoryStream(bytes1)));
                            foreach (XmlNode xmlNode in xmlDocument.DocumentElement.FirstChild.ChildNodes)
                            {
                                XmlElement xmlElement = xmlNode as XmlElement;
                                if (xmlElement != null && xmlElement.Name == "Description")
                                {
                                    this.description = xmlElement.InnerXml;
                                }
                            }
                        }
                        else
                        {
                            Trace.TraceWarning("GDF resource not found for " + this.Name + ".");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceWarning("Error getting GDF data for " + this.name + "could not be loaded: " + ex.Message);
                }
            }
            if (this.playTasks.Count == 0)
            {
                this.IsValid       = false;
                this.InvalidReason = "Could not find a play task for " + this.name + ".";
                return;
            }
            if (this.image != null)
            {
                return;
            }
            string filename = (string)null;

            if (this.playTasks.Count > 0)
            {
                try
                {
                    WshShell shell = new WshShell();
                    filename = ((IWshShortcut)shell.CreateShortcut(this.playTasks[0])).TargetPath;
                }
                catch
                {
                }
            }
            if (string.IsNullOrEmpty(filename))
            {
                filename = str1;
            }
            if (string.IsNullOrEmpty(filename))
            {
                return;
            }
            this.image = Shell.GenerateThumbnail(filename);
        }