public bool ReadTdtaItem(BinaryPSDReader r) { this.Name = ""; while (r.BytesToEnd > 0) { char c = r.ReadChar(); if (c == 0x0a) break; this.Name += c; } byte[] buffer = new byte[255]; int bufPos = 0; int nearEndCnt = 0; //Read until a slash or several 0x00 comes along while (r.BytesToEnd > 0) { byte b = r.ReadByte(); buffer[bufPos++] = b; if (b == 0x2f) // slash "/" seems to be the field delimiter break; if (b <= 0x00) { nearEndCnt++; if (nearEndCnt == 12) break; } else nearEndCnt = 0; } if (this.Name.Contains(" ")) { int index = this.Name.IndexOf(" "); string val = this.Name.Substring(index + 1); //Sometimes it's a unicode string (how do I know..? seems to always have parenthesis) Ugly shortcut: if (val[0] == '(' && val[val.Length - 1] == ')') { bool unicode = true; for (int i = 0; i < val.Length; i ++) if (val[i] != 0 && val[i] <= 31) { unicode = false; break; } if (unicode) { string uniVal = ""; for (int i = 2; i < val.Length; i += 2) uniVal += val[i]; val = uniVal; } else { byte[] tmp = new byte[val.Length]; int i = 0; foreach (char ch in val) tmp[i++] = (byte)ch; val = Endogine.Serialization.ReadableBinary.CreateHexEditorString(tmp).Replace("\r\n", " "); } } this.Value = val; this.Name = this.Name.Remove(index); } int endPos = bufPos - nearEndCnt - 1; //See if it's only 0x09's: for (int i = 0; i < endPos; i++) { if (buffer[i] != 0x09) { //TODO: this.Data = Endogine.Serialization.ReadableBinary.CreateHexEditorString(buffer, 0, endPos); break; } } return (nearEndCnt == 0 && r.BytesToEnd > 0); //OK to continue reading values? }
public bool ReadTdtaItem(BinaryPSDReader r) { this.Name = ""; while (r.BytesToEnd > 0) { char c = r.ReadChar(); if (c == 0x0a) { break; } this.Name += c; } byte[] buffer = new byte[255]; int bufPos = 0; int nearEndCnt = 0; //Read until a slash or several 0x00 comes along while (r.BytesToEnd > 0) { byte b = r.ReadByte(); buffer[bufPos++] = b; if (b == 0x2f) // slash "/" seems to be the field delimiter { break; } if (b <= 0x00) { nearEndCnt++; if (nearEndCnt == 12) { break; } } else { nearEndCnt = 0; } } if (this.Name.Contains(" ")) { int index = this.Name.IndexOf(" "); string val = this.Name.Substring(index + 1); //Sometimes it's a unicode string (how do I know..? seems to always have parenthesis) Ugly shortcut: if (val[0] == '(' && val[val.Length - 1] == ')') { bool unicode = true; for (int i = 0; i < val.Length; i++) { if (val[i] != 0 && val[i] <= 31) { unicode = false; break; } } if (unicode) { string uniVal = ""; for (int i = 2; i < val.Length; i += 2) { uniVal += val[i]; } val = uniVal; } else { byte[] tmp = new byte[val.Length]; int i = 0; foreach (char ch in val) { tmp[i++] = (byte)ch; } val = Endogine.Serialization.ReadableBinary.CreateHexEditorString(tmp).Replace("\r\n", " "); } } this.Value = val; this.Name = this.Name.Remove(index); } int endPos = bufPos - nearEndCnt - 1; //See if it's only 0x09's: for (int i = 0; i < endPos; i++) { if (buffer[i] != 0x09) { //TODO: this.Data = Endogine.Serialization.ReadableBinary.CreateHexEditorString(buffer, 0, endPos); break; } } return(nearEndCnt == 0 && r.BytesToEnd > 0); //OK to continue reading values? }