예제 #1
0
        /// <summary>
        /// Checks if the current file is ok to install
        /// </summary>
        /// <param name="file"></param>
        /// <returns>The package that is using the file if it cannot be installed, null if it can be installed</returns>
        private static Package IsFileOkToInstall(string file)
        {
            PackageCollection packages = PackageSettings.Get().Packages;

            if (packages != null)
            {
                foreach (Package p in packages)
                {
                    if (p.Files != null)
                    {
                        string temp = p.Files.Find(
                            delegate(string s)
                        {
                            return(s == file);
                        });

                        if (!String.IsNullOrEmpty(temp))
                        {
                            return(p);
                        }
                    }
                }
            }

            return(null);
        }
예제 #2
0
        public static bool RemovePackage(string packageName)
        {
            PackageSettings pSettings = Get();

            Package temp = pSettings.Packages.Find(
                delegate(Package p) { return(p.Name == packageName); });

            if (temp != null)
            {
                RemoveFilesAndFolders(temp);
                pSettings.Packages.Remove(temp);
                pSettings.Save();
                return(true);
            }

            return(false);
        }
예제 #3
0
        public static string ToDisk(string xml, bool overwrite, string overrideThemeName)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);

            XmlNode node = doc.SelectSingleNode("/package");

            if (!String.IsNullOrEmpty(overrideThemeName))
            {
                node.Attributes["name"].Value = overrideThemeName;
            }

            string name     = node.Attributes["name"].Value;
            string unpackTo = node.Attributes["location"].Value;
            string version  = null;

            if (node.Attributes["version"] != null)
            {
                version = node.Attributes["version"].Value;
            }

            if (!unpackTo.StartsWith("/"))
            {
                unpackTo = "/" + unpackTo;
            }

            PackageSettings pkgSettings = PackageSettings.Get();

            if (pkgSettings.Packages == null)
            {
                pkgSettings.Packages = new PackageCollection();
            }

            // check for duplicates
            Package temp = pkgSettings.Packages.Find(
                delegate(Package p)
            {
                return(p.Name == name);
            });

            if (temp != null)
            {
                throw new Exception("A package with this name already exist.");
            }

            Package pkg = new Package();

            pkg.Name = name;

            if (version != null)
            {
                pkg.Version = version;
            }

            pkg.DateInstalled = DateTime.Today;

            ProcessFolderNode(node, unpackTo, overwrite, pkg, true);

            pkgSettings.Packages.Add(pkg);

            pkgSettings.Save();

            return(name);
        }