Exemplo n.º 1
0
        /// <summary>
        ///     Reads a record from the plugin metadata.
        /// </summary>
        /// <param name="name">The name fo the plugin.</param>
        /// <returns>The plugin record.</returns>
        internal PluginRecord ReadPluginRecord(string name)
        {
            try
            {
                XDocument doc;
                using (LockedFile file = new LockedFile(pluginsFileName, pluginsFileMutex))
                    doc = file.Load();

                var element = doc.Root
                              .Elements()
                              .FirstOrDefault(x => x.Attribute("name").Value == name);

                if (element == null)
                {
                    return(null);
                }

                return(new PluginRecord(
                           uint.Parse(element.Attribute("id").Value),
                           name,
                           new Version(element.Attribute("version").Value)
                           ));
            }
            catch (XmlException)
            {
                logger.Error($"The plugins index file ({pluginsFileName}) was corrupt and could not be loaded. It may be possible to fix this manually by inspecting the file; otherwise, it is likely that you will need to delete the file to force DarkRift to regenerate it, however doing so will cause all plugins to reinstall.");
                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Returns all records in the plugins table.
        /// </summary>
        /// <returns>The records stored.</returns>
        internal IEnumerable <PluginRecord> ReadAllPluginRecords()
        {
            try
            {
                XDocument doc;
                using (LockedFile file = new LockedFile(pluginsFileName, pluginsFileMutex))
                    doc = file.Load();

                return(doc.Root
                       .Elements()
                       .Select(
                           (e) =>
                           new PluginRecord(
                               uint.Parse(e.Attribute("id").Value),
                               e.Attribute("name").Value,
                               new Version(e.Attribute("version").Value)
                               )
                           ));
            }
            catch (XmlException)
            {
                logger.Error($"The plugins index file ({pluginsFileName}) was corrupt and could not be loaded. It may be possible to fix this manually by inspecting the file; otherwise, it is likely that you will need to delete the file to force DarkRift to regenerate it, however doing so will cause all plugins to reinstall.");
                throw;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Atomically reads a plugin record and updates the fields as specified or
        ///     creates a new record if not present.
        /// </summary>
        /// <param name="name">The plugin to read and set.</param>
        /// <param name="version">The version to update the record to.</param>
        internal PluginRecord ReadAndSetPluginRecord(string name, Version version)
        {
            try
            {
                using (LockedFile file = new LockedFile(pluginsFileName, pluginsFileMutex))
                {
                    XDocument doc = file.Load();

                    XElement element = doc.Root
                                       .Elements()
                                       .FirstOrDefault(x => x.Attribute("name").Value == name);

                    //If not there, build it
                    PluginRecord record;
                    if (element == null)
                    {
                        element = new XElement("plugin");

                        var  idAttribute = doc.Root.Attribute("nextID");
                        uint id          = uint.Parse(idAttribute.Value);
                        idAttribute.SetValue(id + 1);

                        element.SetAttributeValue("id", id);
                        element.SetAttributeValue("name", name);

                        doc.Root.Add(element);

                        record = null;
                    }
                    else
                    {
                        record = new PluginRecord(
                            uint.Parse(element.Attribute("id").Value),
                            name,
                            new Version(element.Attribute("version").Value)
                            );
                    }

                    element.SetAttributeValue("version", version);

                    file.Save(doc);

                    return(record);
                }
            }
            catch (XmlException)
            {
                logger.Error($"The plugins index file ({pluginsFileName}) was corrupt and could not be loaded. It may be possible to fix this manually by inspecting the file; otherwise, it is likely that you will need to delete the file to force DarkRift to regenerate it, however doing so will cause all plugins to reinstall.");
                throw;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Deletes a record from the plugin table.
        /// </summary>
        /// <param name="name">The plugin to delete.</param>
        internal void DeletePluginRecord(string name)
        {
            try
            {
                using (LockedFile file = new LockedFile(pluginsFileName, pluginsFileMutex))
                {
                    XDocument doc = file.Load();

                    doc.Root
                    .Elements()
                    .Single(e => e.Attribute("name").Value == name)
                    .Remove();

                    file.Save(doc);
                }
            }
            catch (XmlException)
            {
                logger.Error($"The plugins index file ({pluginsFileName}) was corrupt and could not be loaded. It may be possible to fix this manually by inspecting the file; otherwise, it is likely that you will need to delete the file to force DarkRift to regenerate it, however doing so will cause all plugins to reinstall.");
                throw;
            }
        }