Ejemplo n.º 1
0
        private Update compileUpdate(UpdateNode node, XDocument xml)
        {
            Update update = new Update(node);
            if (isDead()) {
                return update;
            }

            try {
                var root = from item in xml.Descendants("Update")
                    select new {
                        changelog = item.Descendants("Changelog"),
                        files = item.Descendants("File"),
                        archives = item.Descendants("Archive"),
                        name = item.Attribute("name"),
                        baseType = item.Attribute("base")
                    };

                foreach (var data in root) {

                    // Set Attributes
                    update.setName(data.name.Value);
                    if (data.baseType != null) {
                        update.setBaseType(data.baseType.Value);
                    }

                    // Add the changelog data
                    foreach (var clog in data.changelog) {
                        Changelog changelog = new Changelog(update.getVersion());
                        foreach (var log in clog.Descendants("Log")) {
                            changelog.addLog(new Changelog.Log(log.Value.Trim()));
                        }
                        update.setChangelog(changelog);
                        break;
                    }

                    // Add the file data
                    foreach (var f in data.files) {
                        String name = Xml.getAttributeValue(f.Attribute("name"));
                        String destination = Xml.getAttributeValue(f.Attribute("destination"));
                        String mime = Xml.getAttributeValue(f.Attribute("mime"), "none");

                        update.addFile(new GhostFile(name, destination, mime,
                            new Uri(url + "/" + node.getDir() + "/" + name)));
                    }

                    // Add the archive data
                    foreach (var f in data.archives) {
                        String name = Xml.getAttributeValue(f.Attribute("name"));
                        String extractTo = Xml.getAttributeValue(f.Attribute("extractTo"));
                        String mime = Xml.getAttributeValue(f.Attribute("mime"), "none");

                        Boolean cleanDirs = false;
                        if (f.Attribute("cleanDirs") != null) {
                            cleanDirs = Convert.ToBoolean(f.Attribute("cleanDirs").Value.Trim());
                        }

                        update.addFile(new Archive(name, extractTo, mime,
                            new Uri(url + "/" + node.getDir() + "/" + name), cleanDirs));
                    }
                }
            }
            catch (Exception ex) {
                Logger.log(Logger.TYPE.ERROR, "Problem while compiling updates "
                    + ex.Message + ex.StackTrace);
            }

            return update;
        }
Ejemplo n.º 2
0
        protected void assignTempDirs(Update update)
        {
            Logger.log(Logger.TYPE.DEBUG, "Assign temporary directories.");

            String path = Path.Combine(getTempPath(), Convert.ToString(update.getVersion()));
            if (Directory.Exists(path)) {
                try {
                    Directory.Delete(path, true);
                } catch(IOException ex) {
                    Logger.log(Logger.TYPE.FATAL, "Unable to delete temp dir: " + ex.Message + ex.StackTrace);
                }
            }
            update.setTempDir(Directory.CreateDirectory(path));

            foreach(GhostFile file in update.getFiles()) {
                file.setTempDir(Directory.CreateDirectory(Path.Combine(
                    path, file.getDestination())));
            }
        }
Ejemplo n.º 3
0
 public ImageListBoxItem getLogItem(Update update, ImageListBox listBox)
 {
     ImageListBoxItem item = null;
     foreach(ImageListBoxItem it in listBox.Items) {
         if (it.Text.Contains("[" + update.getVersion() + update.getBaseType() + "]")) {
             item = it;
             break;
         }
     }
     return item;
 }
Ejemplo n.º 4
0
        public void stampUpdate(Update update)
        {
            // Use the current updateXML object, do not repull
            XDocument doc = updateXML.get();

            XElement updateElement = getUpdateElement(update, doc);
            if (updateElement != null) {
                updateElement.Remove();
            }

            StringBuilder sb = new StringBuilder();
            XmlWriterSettings xws = new XmlWriterSettings();
            xws.OmitXmlDeclaration = true;
            xws.Indent = true;

            using (XmlWriter xw = XmlWriter.Create(sb, xws)) {
                try {
                    doc.Element("Updates").AddFirst(update.getXML());
                    doc.Element("Updates").SetAttributeValue("latest", update.getVersion());

                    doc.WriteTo(xw);
                    doc.Save(file);
                }
                catch (Exception e) {
                    Logger.log(Logger.TYPE.FATAL, "Could not stamp the updates: "
                        + e.Message + e.StackTrace);
                }
            }
        }
Ejemplo n.º 5
0
        public XElement getUpdateElement(Update update, XDocument doc)
        {
            var root = from item in doc.Descendants("Updates")
                select new {
                    updates = item.Descendants("Update")
                };

            XElement element = null;
            try {
                foreach (var data in root) {
                    foreach (var u in data.updates) {
                        if(update.getVersion() == Convert.ToDouble(
                                u.Attribute("version").Value)) {
                            element = u;
                            break;
                        }
                    }
                }
            }
            catch(FormatException e) {
                Logger.log(Logger.TYPE.ERROR, "Could not convert latest version: " + e.Message);
            }

            return element;
        }
Ejemplo n.º 6
0
        public List<Update> getPreviousUpdates()
        {
            XDocument xml = getUpdateXML();

            List<Update> updates = new List<Update>();
            var root = from item in updateXML.get().Descendants("Updates")
                select new {
                    updates = item.Descendants("Update")
                };

            try {
                foreach (var data in root) {
                    var udates = from item in data.updates
                        select new {
                            name = item.Attribute("name"),
                            version = item.Attribute("version"),
                            url = item.Attribute("url"),
                            baseType = item.Attribute("base"),
                            changelogs = item.Descendants("Changelog")
                        };

                    foreach (var u in udates) {
                        Update update = new Update();
                        update.setName(u.name.Value);
                        update.setVersion(Convert.ToDouble(u.version.Value));
                        update.setUrl(u.url.Value);

                        XAttribute baseType = u.baseType;
                        if (baseType != null) {
                            update.setBaseType(baseType.Value);
                        }

                        Changelog changelog = new Changelog(update.getVersion());
                        foreach (var clog in u.changelogs) {
                            foreach(var log in clog.Descendants("Log")) {
                                changelog.addLog(new Changelog.Log(log.Value));
                            }
                            update.setChangelog(changelog);
                            break;
                        }
                        update.setChangelog(changelog);

                        updates.Add(update);
                    }
                }
            }
            catch (Exception e) {
                Logger.log(Logger.TYPE.ERROR, "Failed to get previous updates "
                    + e.Message + e.StackTrace);
            }

            return updates;
        }