Exemplo n.º 1
0
        private void ProcessUpdateFile(Guid appGuid, string filename, bool isHeroicUpdate = false)
        {
            if (!File.Exists(filename))
            {
                if (isHeroicUpdate)
                {
                    throw new CBLoaderException($"Expected file {filename} not found.");
                }
                return;
            }

            Log.Debug($" - Parsing {Path.GetFileName(filename)}");
            var document = XDocument.Load(filename);

            switch (document.Root.Name.LocalName.ToLower())
            {
            case "applications":
                var applicationTag = document.Root.Elements()
                                     .First(x => x.Name.LocalName == "Application" &&
                                            x.Attribute("ID").Value == appGuid.ToString());
                foreach (var element in applicationTag.Elements())
                {
                    var match = UPDATE_REGEX.Match(element.Name.LocalName);
                    var id    = new Guid(match.Groups[1].Value);
                    var key   = Convert.FromBase64String(element.Value);
                    keyStore.AddKey(id, key);
                }

                if (isHeroicUpdate)
                {
                    keyStore.WriteGuid = new Guid(applicationTag.Attribute("CurrentUpdate").Value);
                }

                break;

            case "cbloaderkeystore":
                var otherStore = (KeyStore)SERIALIZER.Deserialize(new StringReader(document.ToString()));
                foreach (var key in otherStore.UpdateKeys)
                {
                    keyStore.AddKey(key.Id, key.KeyData);
                }
                if (otherStore.WriteGuid != null)
                {
                    keyStore.WriteGuid = otherStore.WriteGuid;
                }
                if (otherStore.FallbackKey != null)
                {
                    keyStore.FallbackKey = otherStore.FallbackKey;
                }
                break;

            default:
                throw new Exception("Unknown key store type.");
            }

            if (isHeroicUpdate && (keyStore.WriteGuid == null || keyStore.Get(keyStore.WriteGuid) == null))
            {
                throw new CBLoaderException($"Key file {filename} is not valid.");
            }
        }