コード例 #1
0
ファイル: Library.cs プロジェクト: mloar/wipt
        /// <summary>
        /// Returns all of the products in the Library.
        /// </summary>
        /// <returns>
        /// An array of Product objects, or null if an error occurred.
        /// </returns>
        public static Product[] GetAll()
        {
            if(library == null)
              {
            if(!Load())
            {
              throw new WiptException("Could not load package database.");
            }
              }
              Product[] list = new Product[library.Keys.Count];
              int i = 0;
              foreach(object s in library.Keys)
              {
            list[i++] = (Product)library[s];
              }

              return list;
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: mloar/wipt
 internal static void Upgrade(string[] products, bool ignoretransforms, bool ignorepatches, bool peruser,
     string targetdir, string installlevel, bool reinstall)
 {
     Product[] list = new Product[0];
       if(products.Length == 1 && products[0] == "")
       {
     list = Library.GetAll();
       }
       else
       {
     foreach(string product in products)
     {
       if(product != "")
       {
     Product p = Library.GetProduct(product);
     if(p == null)
     {
       Console.Error.WriteLine("No such product {0}", product);
     }
     else
     {
       Product[] nl = new Product[list.Length + 1];
       Array.Copy(list, nl, list.Length);
       nl[list.Length] = p;
       list = nl;
     }
       }
     }
       }
       foreach(Product p in list)
       {
     if(IsInstalled(p.name) && p.stableVersion != null && !IsInstalled(p.name, p.stableVersion,
      new Version("99.99.9999")))
     {
       Install(p.name + "=" + p.stableVersion.ToString(), ignoretransforms, ignorepatches, peruser, targetdir,
       installlevel, reinstall);
     }
       }
 }
コード例 #3
0
ファイル: Library.cs プロジェクト: mloar/wipt
        /// <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;
        }
コード例 #4
0
ファイル: Main.cs プロジェクト: mloar/wipt
 internal static void List(string[] userlist)
 {
     try
       {
     bool fulldesc = false;
     Product[] list = new Product[0];
     if(userlist.Length > 1 || userlist[0] != "")
     {
       fulldesc = true;
       foreach(string s in userlist)
       {
     if(s == "")
       continue;
     Product[] temp = new Product[list.Length + 1];
     Array.Copy(list, temp, list.Length);
     temp[list.Length] = Library.GetProduct(s);
     if(temp[list.Length] == null)
       Console.Error.WriteLine("Could not find product {0}", s);
     else
       list = temp;
       }
     }
     else
       list = Library.GetAll();
     if(list.Length > 0)
     {
       Array.Sort(list);
       foreach(Product p in list)
       {
     Console.WriteLine(p.name);
     if(fulldesc && p.description != null && p.description != "") Console.WriteLine("  {0}", p.description);
     if(p.packages.Length > 0)
     {
       Array.Sort(p.packages);
       foreach(Package k in p.packages)
       {
         string installstring="";
         if(p.stableVersion != null && p.stableVersion == k.version)
           installstring = "(stable)";
         if(IsInstalled(p.name, k.version, k.version))
           installstring += "(installed)";
         Console.WriteLine("  v{0} {1}", k.version.ToString(), installstring);
       }
     }
     else
     {
       Console.WriteLine("  [No packages found]");
     }
       }
     }
     else
     {
       Console.Error.WriteLine("No products found in database.");
     }
       }
       catch(WiptException e)
       {
     Console.WriteLine(e.Message);
       }
 }