Beispiel #1
0
        private static int index; // initialized to 0 by runtime

        #endregion Fields

        #region Methods

        internal static bool ApplyPatches(Patch[] patches, Guid productCode)
        {
            bool success = true;
              if(patches != null && patches.Length > 0)
              {
            foreach(Patch patch in patches)
            {
              if(patch.productCodes.Length == 0)
              {
            patch.productCodes = new Guid[1];
            patch.productCodes[0] = productCode;
              }
              foreach(Guid code in patch.productCodes)
              {
            if(code == productCode)
            {
              Console.Write("Applying patch "+ patch.name + "... ");
              uint ret = WindowsInstaller.ApplyPatch(patch.Url, "{" + productCode.ToString().ToUpper() + "}",
                  WindowsInstaller.MsiInstallType.SingleInstance, "");
              Console.Write("\x08");
              Console.WriteLine(getErrorMessage(ret));
              if(ret != 0)
                success = false;
              break;
            }
              }
            }
              }
              return success;
        }
Beispiel #2
0
        /// <summary>
        /// Used internally by the Library to update the package list for a single
        /// repository.
        /// </summary>
        /// <param name="Url">
        /// URL of the package file.
        /// </param>
        /// <returns>
        /// A boolean value indicating whether the update succeeded.
        /// </returns>
        /// <exception cref="WiptException">
        /// An exception is thrown if two product names match, but the upgrade
        /// codes differ.
        /// </exception>
        private static bool Update(string Url)
        {
            WebRequest req = WebRequest.Create(new Uri(Url));
              Stream i;

              try
              {
            i = req.GetResponse().GetResponseStream();

            XmlDocument repository = LoadRepository(i);
            i.Close();

            foreach(XmlLinkedNode FirstLevel in repository.ChildNodes)
            {
              if(FirstLevel.Name == "Repository")
              {
            foreach(XmlElement curNode in FirstLevel.ChildNodes)
            {
              if(curNode.Name == "Product")
              {
                Product p;

                if(library.ContainsKey(curNode.GetAttribute("Name").ToLower()))
                {
                  p = (Product)library[curNode.GetAttribute("Name").ToLower()];
                  if(p.upgradeCode !=
                      new Guid(curNode.GetAttribute("UpgradeCode")))
                  {
                    throw new WiptException("Product name collision on "
                        + p.name);
                  }
                }
                else
                {
                  p = new Product(curNode.GetAttribute("Name"), curNode.GetAttribute("Publisher"),
                      curNode.GetAttribute("SupportURL"));
                  p.upgradeCode = new Guid(curNode.GetAttribute("UpgradeCode"));
                  library.Add(curNode.GetAttribute("Name").ToLower(), p);
                }

                foreach(XmlElement e in curNode.ChildNodes)
                {
                  switch(e.Name)
                  {
                    case "StableVersion":
                      p.stableVersion = new Version(
                          e.GetAttribute("Major") + "." +
                          e.GetAttribute("Minor") + "." +
                          e.GetAttribute("Build")
                          );
                    break;
                    case "Description":
                      p.description = e.InnerText;
                    break;
                    case "Transform":
                      Transform q = new Transform();
                    foreach(XmlElement n in e.ChildNodes)
                    {
                      switch(n.Name)
                      {
                        case "MinVersion":
                          q.minVersion = new Version(
                              n.GetAttribute("Major") + "." +
                              n.GetAttribute("Minor") + "." +
                              n.GetAttribute("Build"));
                        break;
                        case "MaxVersion":
                          q.maxVersion = new Version(
                              n.GetAttribute("Major") + "." +
                              n.GetAttribute("Minor") + "." +
                              n.GetAttribute("Build"));
                        break;
                        case "URL":
                          q.Url = n.InnerText;
                        break;
                      }
                    }

                    Transform[] tmp = new Transform[p.transforms.Length + 1];
                    Array.Copy(p.transforms, tmp, p.transforms.Length);
                    tmp[p.transforms.Length] = q;
                    p.transforms = tmp;

                    break;
                    case "Patch":
                      Patch g = new Patch(new Guid(e.GetAttribute("PatchCode")), e.GetAttribute("Name"));
                    foreach(XmlElement v in e.ChildNodes)
                    {
                      if(v.Name == "URL")
                      {
                        g.Url = v.InnerText;
                      }
                      else if(v.Name == "ProductCode")
                      {
                        Guid[] nm = new Guid[g.productCodes.Length + 1];
                        Array.Copy(g.productCodes, nm, g.productCodes.Length);
                        nm[g.productCodes.Length] = new Guid(v.InnerText);
                        g.productCodes = nm;
                      }
                    }

                    {
                      Patch[] nm = new Patch[p.patches.Length + 1];
                      Array.Copy(p.patches, nm, p.patches.Length);
                      nm[p.patches.Length] = g;
                      p.patches = nm;
                    }

                    break;
                    case "Package":
                      Package a = new Package(e.GetAttribute("ProductCode"));

                      Package[] np = new Package[p.packages.Length + 1];
                      Array.Copy(p.packages, np, p.packages.Length);
                      np[p.packages.Length] = a;
                      p.packages = np;

                      foreach(XmlNode y in e.ChildNodes)
                      {
                        if(y is XmlElement)
                        {
                          XmlElement t = (XmlElement)y;

                          switch(t.Name)
                          {
                            case "Version":
                              a.version = new Version(
                                t.GetAttribute("Major") + "." +
                                t.GetAttribute("Minor") + "." +
                                t.GetAttribute("Build")
                                );
                            break;
                            case "URL":
                              a.Url = t.InnerText;
                            break;
                          }
                        }
                      }
                    break;
                  }
                }
              }
            }
              }
            }
              }
              catch(System.Net.WebException)
              {
            return false;
              }

              return true;
        }
Beispiel #3
0
        internal static bool IsPatchApplied(Patch patch, Guid productCode)
        {
            Guid[] codes = WindowsInstaller.EnumPatches(productCode);
              foreach(Guid code in codes)
              {
            if(patch.patchCode == code)
              return true;
              }

              return false;
        }