/// <summary>Load an Effe file from a text filestream /// <remarks>Use first the constructor</remarks> /// </summary> /// <param name="amount">Amount of Effects</param> /// <param name="fs">FileStream to read from</param> /// <returns>Amount of models read</returns> public UInt32 LoadTxt(UInt32 amount, FileStream fs) { UInt32 effectsRead = 0; // Only for debug Int32 lineCount = 0; // Only for debug String commentLines = null; String line = null; List<String> comments = new List<String>(); List<String> currentEffect = new List<String>(); PARSE_COMMENTS_STATE commentsState = PARSE_COMMENTS_STATE.NotCommentLine; // Simplified Chinese encoding using (StreamReader sr = new StreamReader(fs, Common.enc, false)) lock (Data) { while ((line = sr.ReadLine()) != null) { lineCount++; // Check if comments or empty line if ((commentsState = IniCommon.ParseLineComments(line, commentsState)) >= 0) { // Add to comments if not inside an effect (or skip) if (currentEffect.Count == 0) { comments.Add(line); } } // Check if starting to read a new effect else if (line.StartsWith("[")) { // If we already have an effect read if (currentEffect.Count != 0) { // Join with "\r\n" all comment lines until // last not empty, as last empty was just a // separator between effects // TODO: improve this method commentLines = Common.ConcatenateAllUntilLastNotEmpty(comments); // current effect + comments -> add to collection Effect e = new Effect(currentEffect.ToArray()); e.AddComments(commentLines); Data.Add(e.AniTitle, e); effectsRead++; // reset comments comments.Clear(); } // new effect currentEffect.Clear(); // add line to effect currentEffect.Add(line); } else { // Add data to the current effect currentEffect.Add(line); } } // EOF: Check if pending to save current effect if (currentEffect.Count != 0) { Effect e = new Effect(currentEffect.ToArray()); e.AddComments(commentLines); Data.Add(e.AniTitle, e); effectsRead++; } } return effectsRead; }
/// <summary>Load an Effe file from a binary filestream /// <remarks>Use first the constructor.</remarks> /// </summary> /// <param name="amount">Amount of Effects</param> /// <param name="fs">FileStream to read from</param> /// <returns>Amount of bytes read</returns> public UInt32 LoadBin(UInt32 amount, FileStream fs) { UInt32 bytesRead = 0; fs.Seek(0, SeekOrigin.Begin); using (BinaryReader br = new BinaryReader(fs)) lock (Data) { UInt16 frameAmount; Byte[] b = new Byte[34]; // Skip Magic Header and amount as it must be already known br.Read(b, 0, 8); bytesRead += 8; // Read every Effect for (int i = 0; i < Amount; i++) { // Read AniTitle and Effect Parts amount br.Read(b, 0, 34); bytesRead += 34; frameAmount = BitConverter.ToUInt16(b, 32); Byte[] fullEffect = new Byte[16 * frameAmount + 34]; Buffer.BlockCopy(b, 0, fullEffect, 0, 34); // Read all frames in this Effect br.Read(fullEffect, 34, fullEffect.Length); bytesRead += (uint)16 * frameAmount; // Add the effect to the collection Effect e = new Effect(fullEffect); Data.Add(e.AniTitle, e); } } return bytesRead; }
/// <summary>Check if provided instance has the same values, /// except comments</summary> /// <returns>Return true if same values</returns> public Boolean Equals(Effect E) { if (E.AniTitle != this.AniTitle) return false; for (int i = 0; i < Amount; i++) { if (!E.Part[i].Equals(this.Part[i])) return false; } if (E.Part != this.Part) return false; if (E.Delay != this.Delay) return false; if (E.LoopTime != this.LoopTime) return false; if (E.FrameInterval != this.FrameInterval) return false; if (E.LoopInterval != this.LoopInterval) return false; if (E.OffsetX != this.OffsetX) return false; if (E.OffsetY != this.OffsetY) return false; if (E.OffsetZ != this.OffsetZ) return false; if (E.Billboard != this.Billboard) return false; if (E.ColorEnable != this.ColorEnable) return false; if (E.Level != this.Level) return false; if (E.Unknown != this.Unknown) return false; return true; }