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; } }
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)); } }
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); }
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); } }
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); } }
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); }
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); }
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); } } }
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; } }
protected string GetString(IndexTag tag) { return(this.GetValue <string>(tag, IndexType.RPM_STRING_TYPE)); }
protected void SetByteArray(IndexTag tag, byte[] value) { this.SetValue(tag, IndexType.RPM_BIN_TYPE, value); }
protected byte[] GetByteArray(IndexTag tag) { return(this.GetValue <byte[]>(tag, IndexType.RPM_BIN_TYPE)); }
protected void SetShortArray(IndexTag tag, short[] value) { this.SetValue(tag, IndexType.RPM_INT16_TYPE, value); }
protected Collection <short> GetShortArray(IndexTag tag) { return(this.GetValue <Collection <short> >(tag, IndexType.RPM_INT16_TYPE)); }
protected void SetIntArray(IndexTag tag, int[] value) { this.SetValue(tag, IndexType.RPM_INT32_TYPE, value); }
protected void SetInt(IndexTag tag, int value) { this.SetSingleValue(tag, IndexType.RPM_INT32_TYPE, value); }
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); }
protected string GetLocalizedString(IndexTag tag) { var localizedValues = this.GetValue <Collection <string> >(tag, IndexType.RPM_I18NSTRING_TYPE); return(localizedValues.First()); }
protected void SetStringArray(IndexTag tag, string[] value) { this.SetValue(tag, IndexType.RPM_STRING_ARRAY_TYPE, value); }
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); }