Example #1
0
        protected void SetValue <T>(IndexTag tag, IndexType type, T[] value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            var collection = new Collection <T>(value);

            IndexRecord record = new IndexRecord()
            {
                Header = new IndexHeader()
                {
                    Count  = collection.Count,
                    Offset = 0,
                    Tag    = (uint)tag,
                    Type   = type
                },
                Value = collection
            };

            if (!this.Package.Header.Records.ContainsKey(tag))
            {
                this.Package.Header.Records.Add(tag, record);
            }
            else
            {
                this.Package.Header.Records[tag] = record;
            }
        }
Example #2
0
        protected char GetDependencyType(IndexTag tag)
        {
            switch (tag)
            {
            case IndexTag.RPMTAG_PROVIDENAME:
                return('P');

            case IndexTag.RPMTAG_REQUIRENAME:
                return('R');

            case IndexTag.RPMTAG_RECOMMENDNAME:
                return('r');

            case IndexTag.RPMTAG_SUGGESTNAME:
                return('S');

            case IndexTag.RPMTAG_SUPPLEMENTNAME:
                return('S');

            case IndexTag.RPMTAG_ENHANCENAME:
                return('e');

            case IndexTag.RPMTAG_CONFLICTNAME:
                return('C');

            case IndexTag.RPMTAG_OBSOLETENAME:
                return('O');

            default:
                throw new ArgumentOutOfRangeException(nameof(tag));
            }
        }
Example #3
0
        protected T GetValue <T>(IndexTag tag, IndexType type)
        {
            if (!this.Package.Header.Records.ContainsKey(tag))
            {
                this.Package.Header.Records.Add(tag,
                                                new IndexRecord()
                {
                    Header = new IndexHeader()
                    {
                        Count  = 0,
                        Offset = -1,
                        Tag    = (uint)tag,
                        Type   = type
                    },
                    Value = default(T)
                });
            }

            var record = this.Package.Header.Records[tag];

            if (record.Header.Type != type)
            {
                throw new ArgumentOutOfRangeException(nameof(tag));
            }

            return((T)record.Value);
        }
        private void AssertTagOffsetEqual(IndexTag tag, RpmPackage originalPackage, RpmPackage package)
        {
            var originalRecord = originalPackage.Header.Records[tag];
            var record         = package.Header.Records[tag];

            Assert.Equal(originalRecord.Header.Offset, record.Header.Offset);
        }
        private void AssertTagEqual(IndexTag tag, RpmPackage originalPackage, RpmPackage package)
        {
            var originalRecord = originalPackage.Header.Records[tag];
            var record         = package.Header.Records[tag];

            Assert.Equal(originalRecord.Value, record.Value);
            Assert.Equal(originalRecord.Header.Count, record.Header.Count);
            Assert.Equal(originalRecord.Header.Tag, record.Header.Tag);
            Assert.Equal(originalRecord.Header.Type, record.Header.Type);
        }
Example #6
0
        protected Collection <int> GetIntArray(IndexTag tag)
        {
            var value = this.GetValue <Collection <int> >(tag, IndexType.RPM_INT32_TYPE);

            if (value == null)
            {
                return(new Collection <int>());
            }
            else
            {
                return(value);
            }
        }
Example #7
0
        protected Collection <string> GetStringArray(IndexTag tag)
        {
            var value = this.GetValue <Collection <string> >(tag, IndexType.RPM_STRING_ARRAY_TYPE);

            if (value == null)
            {
                return(new Collection <string>());
            }
            else
            {
                return(value);
            }
        }
Example #8
0
        protected T GetValue <T>(IndexTag tag, IndexType type)
        {
            if (!this.Package.Header.Records.ContainsKey(tag))
            {
                return(default(T));
            }

            var record = this.Package.Header.Records[tag];

            if (record.Header.Type != type)
            {
                throw new ArgumentOutOfRangeException(nameof(tag));
            }

            return((T)record.Value);
        }
Example #9
0
        protected void SetLocalizedString(IndexTag tag, string value)
        {
            if (this.Locales.Count == 0)
            {
                throw new InvalidOperationException();
            }

            var values = new string[this.Locales.Count];

            for (int i = 0; i < values.Length; i++)
            {
                values[i] = value;
            }

            this.SetValue <string>(tag, IndexType.RPM_I18NSTRING_TYPE, values);
        }
Example #10
0
        protected void SetValue <T>(IndexTag tag, IndexType type, T[] value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            // We won't accept empty arrays; rather, we remove the key alltogether.
            // This brings compatibility with newer versions of RPM
            if (value.Length > 0)
            {
                var collection = new Collection <T>(value);

                IndexRecord record = new IndexRecord()
                {
                    Header = new IndexHeader()
                    {
                        Count  = collection.Count,
                        Offset = 0,
                        Tag    = (uint)tag,
                        Type   = type
                    },
                    Value = collection
                };

                if (!this.Package.Header.Records.ContainsKey(tag))
                {
                    this.Package.Header.Records.Add(tag, record);
                }
                else
                {
                    this.Package.Header.Records[tag] = record;
                }
            }
            else
            {
                if (this.Package.Header.Records.ContainsKey(tag))
                {
                    this.Package.Header.Records.Remove(tag);
                }
            }
        }
Example #11
0
        protected void SetSingleValue <T>(IndexTag tag, IndexType type, T value)
        {
            IndexRecord record = new IndexRecord()
            {
                Header = new IndexHeader()
                {
                    Count  = 1,
                    Offset = 0,
                    Tag    = (uint)tag,
                    Type   = type
                },
                Value = value
            };

            if (!this.Package.Header.Records.ContainsKey(tag))
            {
                this.Package.Header.Records.Add(tag, record);
            }
            else
            {
                this.Package.Header.Records[tag] = record;
            }
        }
Example #12
0
 protected string GetString(IndexTag tag)
 {
     return(this.GetValue <string>(tag, IndexType.RPM_STRING_TYPE));
 }
Example #13
0
 protected void SetByteArray(IndexTag tag, byte[] value)
 {
     this.SetValue(tag, IndexType.RPM_BIN_TYPE, value);
 }
Example #14
0
 protected byte[] GetByteArray(IndexTag tag)
 {
     return(this.GetValue <byte[]>(tag, IndexType.RPM_BIN_TYPE));
 }
Example #15
0
 protected void SetShortArray(IndexTag tag, short[] value)
 {
     this.SetValue(tag, IndexType.RPM_INT16_TYPE, value);
 }
Example #16
0
 protected Collection <short> GetShortArray(IndexTag tag)
 {
     return(this.GetValue <Collection <short> >(tag, IndexType.RPM_INT16_TYPE));
 }
Example #17
0
 protected void SetIntArray(IndexTag tag, int[] value)
 {
     this.SetValue(tag, IndexType.RPM_INT32_TYPE, value);
 }
Example #18
0
 protected void SetInt(IndexTag tag, int value)
 {
     this.SetSingleValue(tag, IndexType.RPM_INT32_TYPE, value);
 }
Example #19
0
 protected int GetInt(IndexTag tag)
 {
     return(this.GetValue <int>(tag, IndexType.RPM_INT32_TYPE));
 }
 public void SetIntArrayPublic(IndexTag tag, int[] value)
 {
     this.SetIntArray(tag, value);
 }
Example #21
0
        protected string GetLocalizedString(IndexTag tag)
        {
            var localizedValues = this.GetValue <Collection <string> >(tag, IndexType.RPM_I18NSTRING_TYPE);

            return(localizedValues.First());
        }
Example #22
0
 protected void SetStringArray(IndexTag tag, string[] value)
 {
     this.SetValue(tag, IndexType.RPM_STRING_ARRAY_TYPE, value);
 }
Example #23
0
 protected void SetString(IndexTag tag, string value)
 {
     this.SetSingleValue(tag, IndexType.RPM_STRING_TYPE, value);
 }
 public void SetStringArrayPublic(IndexTag tag, string[] value)
 {
     this.SetStringArray(tag, value);
 }