FPCommentType.cs 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.IO;
  5. using System.Drawing;
  6. namespace System.Fire.FilePack.FilePackElements {
  7. public class FPComment {
  8. private byte[] _value;
  9. private FPCommentType _type;
  10. private UInt16 _fileID;
  11. //private string LatainBuchstaben = "abcdefghijklmnopqrstuvwxyzáéíóúàèìòùâêîôûABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛ1234567890 ,.-;:_#+*'~!\"§$%&/()=?{[]}^@€<>";
  12. public FPComment() {
  13. }
  14. public FPComment(BinaryReader S) {
  15. this.Read(S);
  16. }
  17. public void Read(BinaryReader S) {
  18. this._type = (FPCommentType)S.ReadByte();
  19. UInt16 len = BitConverter.ToUInt16(S.ReadBytes(2) /*new byte[]{S.BaseStream.ReadByte(), S.BaseStream.ReadByte()}*/, 0); // S.BaseStream.ReadByte + (S.ReadByte * 256)
  20. if(this._type == FPCommentType.FileByteArray || this._type == FPCommentType.FileComment || this._type == FPCommentType.FileTag || this._type == FPCommentType.ShortFileComment || this._type == FPCommentType.FileIcon || this._type == FPCommentType.FileImage) {
  21. // Dateibezogen - FileID benötigt
  22. this._fileID = BitConverter.ToUInt16(S.ReadBytes(2) /*{S.BaseStream.ReadByte, S.BaseStream.ReadByte}*/, 0);
  23. }
  24. //ReDim Preserve Me._value(0 To len)
  25. this._value = new byte[len];
  26. if(this._type != FPCommentType.Not_Set && len > 0) {
  27. this._value = S.ReadBytes(len);
  28. }
  29. }
  30. public void Write(BinaryWriter S) {
  31. S.BaseStream.WriteByte((byte)this._type);
  32. // Daten-Länge schreiben
  33. UInt16 lenShort = (UInt16)this._value.Length;
  34. byte[] len = BitConverter.GetBytes(lenShort);
  35. S.BaseStream.WriteByte(len[0]);
  36. S.BaseStream.WriteByte(len[1]);
  37. // FileID schreiben
  38. if(this._type == FPCommentType.FileByteArray || this._type == FPCommentType.FileComment || this._type == FPCommentType.FileTag || this._type == FPCommentType.ShortFileComment || this._type == FPCommentType.FileIcon) {
  39. byte[] fID = BitConverter.GetBytes(this._fileID);
  40. S.BaseStream.WriteByte(fID[0]);
  41. S.BaseStream.WriteByte(fID[1]);
  42. }
  43. S.Write(this._value);
  44. }
  45. public FPCommentType Type {
  46. get { return this._type; }
  47. set { this._type = value; }
  48. }
  49. public string Caption {
  50. get {
  51. UTF8Encoding enc = new UTF8Encoding();
  52. return enc.GetString(this._value);
  53. }
  54. set {
  55. UTF8Encoding enc = new UTF8Encoding();
  56. this._value = enc.GetBytes(value);
  57. }
  58. }
  59. public UInt16 FileID {
  60. get { return this._fileID; }
  61. set { this._fileID = value; }
  62. }
  63. public Bitmap Picture {
  64. get { return new Bitmap((Image)new ImageConverter().ConvertFrom(this._value)); }
  65. set { this._value = (byte[])new ImageConverter().ConvertTo(value, typeof(byte[])); }
  66. }
  67. public Icon Icon {
  68. get { return (Icon)new IconConverter().ConvertFrom(this._value); }
  69. set { this._value = (byte[])new IconConverter().ConvertTo(value, typeof(byte[])); }
  70. }
  71. public byte[] Bytes {
  72. get { return this._value; }
  73. set { this._value = value; }
  74. }
  75. }
  76. }