| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.IO;
- using System.Drawing;
- namespace System.Fire.FilePack.FilePackElements {
- public class FPComment {
- private byte[] _value;
- private FPCommentType _type;
- private UInt16 _fileID;
- //private string LatainBuchstaben = "abcdefghijklmnopqrstuvwxyzáéíóúàèìòùâêîôûABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛ1234567890 ,.-;:_#+*'~!\"§$%&/()=?{[]}^@€<>";
- public FPComment() {
- }
- public FPComment(BinaryReader S) {
- this.Read(S);
- }
- public void Read(BinaryReader S) {
- this._type = (FPCommentType)S.ReadByte();
- UInt16 len = BitConverter.ToUInt16(S.ReadBytes(2) /*new byte[]{S.BaseStream.ReadByte(), S.BaseStream.ReadByte()}*/, 0); // S.BaseStream.ReadByte + (S.ReadByte * 256)
- 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) {
- // Dateibezogen - FileID benötigt
- this._fileID = BitConverter.ToUInt16(S.ReadBytes(2) /*{S.BaseStream.ReadByte, S.BaseStream.ReadByte}*/, 0);
- }
- //ReDim Preserve Me._value(0 To len)
- this._value = new byte[len];
- if(this._type != FPCommentType.Not_Set && len > 0) {
- this._value = S.ReadBytes(len);
- }
- }
- public void Write(BinaryWriter S) {
- S.BaseStream.WriteByte((byte)this._type);
- // Daten-Länge schreiben
- UInt16 lenShort = (UInt16)this._value.Length;
- byte[] len = BitConverter.GetBytes(lenShort);
- S.BaseStream.WriteByte(len[0]);
- S.BaseStream.WriteByte(len[1]);
- // FileID schreiben
- if(this._type == FPCommentType.FileByteArray || this._type == FPCommentType.FileComment || this._type == FPCommentType.FileTag || this._type == FPCommentType.ShortFileComment || this._type == FPCommentType.FileIcon) {
- byte[] fID = BitConverter.GetBytes(this._fileID);
- S.BaseStream.WriteByte(fID[0]);
- S.BaseStream.WriteByte(fID[1]);
- }
- S.Write(this._value);
- }
- public FPCommentType Type {
- get { return this._type; }
- set { this._type = value; }
- }
- public string Caption {
- get {
- UTF8Encoding enc = new UTF8Encoding();
- return enc.GetString(this._value);
- }
- set {
- UTF8Encoding enc = new UTF8Encoding();
- this._value = enc.GetBytes(value);
- }
- }
- public UInt16 FileID {
- get { return this._fileID; }
- set { this._fileID = value; }
- }
- public Bitmap Picture {
- get { return new Bitmap((Image)new ImageConverter().ConvertFrom(this._value)); }
- set { this._value = (byte[])new ImageConverter().ConvertTo(value, typeof(byte[])); }
- }
- public Icon Icon {
- get { return (Icon)new IconConverter().ConvertFrom(this._value); }
- set { this._value = (byte[])new IconConverter().ConvertTo(value, typeof(byte[])); }
- }
- public byte[] Bytes {
- get { return this._value; }
- set { this._value = value; }
- }
- }
- }
|