public PartitionedFile(GenericCharMap map, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, IList <byte> bytes) : base(map, layout, false) { PartitionSize = layout.Size / NumberOfSections; List <IList <string> > sections = new List <IList <string> >(NumberOfSections); for (int i = 0; i < NumberOfSections; i++) { sections.Add(TextUtilities.ProcessList(bytes.Sub(i * PartitionSize, (i + 1) * PartitionSize - 1), map)); if (sections[i].Count < SectionLengths[i]) { string[] newSection = new string[SectionLengths[i]]; sections[i].CopyTo(newSection, 0); new string[SectionLengths[i] - sections[i].Count].CopyTo(newSection, sections[i].Count); sections[i] = newSection; } else if (sections[i].Count > SectionLengths[i]) { sections[i] = sections[i].Sub(0, SectionLengths[i] - 1); } System.Diagnostics.Debug.Assert(sections[i].Count == SectionLengths[i]); } Sections = sections.AsReadOnly(); PopulateDisallowedSections(); }
public SectionedFile(GenericCharMap map, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, IList <byte> bytes, string fileComments, IList <string> sectionComments, bool compressible) : base(map, layout, fileComments, sectionComments, compressible) { List <IList <string> > sections = new List <IList <string> >(NumberOfSections); for (int i = 0; i < NumberOfSections; i++) { uint start = PatcherLib.Utilities.Utilities.BytesToUInt32(bytes.Sub(i * 4, (i + 1) * 4 - 1)); uint stop = PatcherLib.Utilities.Utilities.BytesToUInt32(bytes.Sub((i + 1) * 4, (i + 2) * 4 - 1)) - 1; if (i == NumberOfSections - 1) { stop = (uint)bytes.Count - 1 - (uint)DataStart; } IList <byte> thisSection = bytes.Sub((int)(start + DataStart), (int)(stop + DataStart)); if (compressible) { thisSection = TextUtilities.Decompress(bytes, thisSection, (int)(start + DataStart)); } GenericCharMap processCharMap = DteAllowed[i] ? CharMap : GetContextCharmap(layout.Context); sections.Add(TextUtilities.ProcessList(thisSection, layout.AllowedTerminators[0], processCharMap)); if (sections[i].Count < SectionLengths[i]) { string[] newSection = new string[SectionLengths[i]]; sections[i].CopyTo(newSection, 0); new string[SectionLengths[i] - sections[i].Count].CopyTo(newSection, sections[i].Count); sections[i] = newSection; } else if (sections[i].Count > SectionLengths[i]) { sections[i] = sections[i].Sub(0, SectionLengths[i] - 1); } } Sections = sections.AsReadOnly(); PopulateDisallowedSections(); }
public ATCHELP( GenericCharMap map, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, IList <byte> bytes, string fileComments, IList <string> sectionComments) : base(map, layout, bytes, fileComments, sectionComments) { }
public PartitionedFile(GenericCharMap map, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, IList <byte> bytes, string fileComments, IList <string> sectionComments) : base(map, layout, fileComments, sectionComments, false) { PartitionSize = layout.Size / NumberOfSections; List <IList <string> > sections = new List <IList <string> >(NumberOfSections); StringBuilder sbMessage = new StringBuilder(); for (int i = 0; i < NumberOfSections; i++) { GenericCharMap processCharMap = DteAllowed[i] ? map : GetContextCharmap(layout.Context); sections.Add(TextUtilities.ProcessList(bytes.Sub(i * PartitionSize, (i + 1) * PartitionSize - 1), layout.AllowedTerminators, processCharMap)); if (sections[i].Count < SectionLengths[i]) { string[] newSection = new string[SectionLengths[i]]; sections[i].CopyTo(newSection, 0); new string[SectionLengths[i] - sections[i].Count].CopyTo(newSection, sections[i].Count); sections[i] = newSection; } else if (sections[i].Count > SectionLengths[i]) { if ((sections[i].Count - SectionLengths[i]) > 1) { sbMessage.AppendLine(string.Format("File {0} (section {1}): Section length decreased from {2} to {3}.", layout.DisplayName, i, sections[i].Count, SectionLengths[i])); } sections[i] = sections[i].Sub(0, SectionLengths[i] - 1); } /* * if (layout.AllowedTerminators.Count > 1) * { * Dictionary<byte, int> counts = new Dictionary<byte, int>(); * layout.AllowedTerminators.ForEach(b => counts[b] = 0); * * bytes.FindAll(b => layout.AllowedTerminators.Contains(b)).ForEach(b => counts[b]++); * List<KeyValuePair<byte, int>> countList = new List<KeyValuePair<byte, int>>(counts); * countList.Sort((a, b) => b.Value.CompareTo(a.Value)); * this.SelectedTerminator = countList[0].Key; * } */ this.SelectedTerminator = 0xFE; //System.Diagnostics.Debug.Assert(sections[i].Count == SectionLengths[i]); } // <DEBUG> //string message = sbMessage.ToString(); //if (!string.IsNullOrEmpty(message)) // PatcherLib.MyMessageBox.Show(message); Sections = sections.AsReadOnly(); PopulateDisallowedSections(); }
protected AbstractFile(GenericCharMap charmap, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, bool compressible) { NumberOfSections = layout.SectionLengths.Count; Layout = layout; CharMap = charmap; EntryNames = layout.EntryNames.AsReadOnly(); SectionLengths = layout.SectionLengths.AsReadOnly(); SectionNames = layout.SectionNames.AsReadOnly(); DisplayName = layout.DisplayName; Compressible = compressible; CompressionAllowed = layout.CompressionAllowed.AsReadOnly(); DteAllowed = layout.DteAllowed.AsReadOnly(); }
public SectionedFile(GenericCharMap map, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, IList <byte> bytes, string fileComments, IList <string> sectionComments, bool compressible) : base(map, layout, fileComments, sectionComments, compressible) { List <IList <string> > sections = new List <IList <string> >(NumberOfSections); System.Text.StringBuilder sbMessage = new System.Text.StringBuilder(); for (int i = 0; i < NumberOfSections; i++) { uint start = PatcherLib.Utilities.Utilities.BytesToUInt32(bytes.Sub(i * 4, (i + 1) * 4 - 1)); uint stop = PatcherLib.Utilities.Utilities.BytesToUInt32(bytes.Sub((i + 1) * 4, (i + 2) * 4 - 1)) - 1; if (i == NumberOfSections - 1) { stop = (uint)bytes.Count - 1 - (uint)DataStart; } IList <byte> thisSection = bytes.Sub((int)(start + DataStart), (int)(stop + DataStart)); if (compressible) { thisSection = TextUtilities.Decompress(bytes, thisSection, (int)(start + DataStart)); } GenericCharMap processCharMap = DteAllowed[i] ? CharMap : GetContextCharmap(layout.Context); //sections.Add(TextUtilities.ProcessList(thisSection, layout.AllowedTerminators[0], processCharMap)); sections.Add(TextUtilities.ProcessList(thisSection, layout.AllowedTerminators, processCharMap)); if (sections[i].Count < SectionLengths[i]) { string[] newSection = new string[SectionLengths[i]]; sections[i].CopyTo(newSection, 0); new string[SectionLengths[i] - sections[i].Count].CopyTo(newSection, sections[i].Count); sections[i] = newSection; } else if (sections[i].Count > SectionLengths[i]) { if ((sections[i].Count - SectionLengths[i]) > 1) { sbMessage.AppendLine(string.Format("File {0} (section {1}): Section length decreased from {2} to {3}.", layout.DisplayName, i, sections[i].Count, SectionLengths[i])); } sections[i] = sections[i].Sub(0, SectionLengths[i] - 1); } } // <DEBUG> //string message = sbMessage.ToString(); //if (!string.IsNullOrEmpty(message)) // PatcherLib.MyMessageBox.Show(message); Sections = sections.AsReadOnly(); PopulateDisallowedSections(); }
public CompressibleOneShotFile(GenericCharMap map, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, IList <byte> bytes, string fileComments, IList <string> sectionComments) : base(map, layout, fileComments, sectionComments, true) { List <IList <string> > sections = new List <IList <string> >(NumberOfSections); System.Diagnostics.Debug.Assert(NumberOfSections == 1); for (int i = 0; i < NumberOfSections; i++) { sections.Add(TextUtilities.ProcessList(TextUtilities.Decompress(bytes, bytes, 0), layout.AllowedTerminators, map)); if (sections[i].Count < SectionLengths[i]) { string[] newSection = new string[SectionLengths[i]]; sections[i].CopyTo(newSection, 0); new string[SectionLengths[i] - sections[i].Count].CopyTo(newSection, sections[i].Count); sections[i] = newSection; } } Sections = sections.AsReadOnly(); }
protected AbstractFile(GenericCharMap charmap, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, string fileComments, IList <string> sectionComments, bool compressible) { System.Diagnostics.Debug.Assert(sectionComments.Count == layout.SectionNames.Count); FileComments = fileComments ?? string.Empty; SectionComments = new string[sectionComments.Count]; sectionComments.CopyTo(SectionComments, 0); NumberOfSections = layout.SectionLengths.Count; Layout = layout; CharMap = charmap; SelectedTerminator = layout.AllowedTerminators[0]; EntryNames = layout.EntryNames.AsReadOnly(); SectionLengths = layout.SectionLengths.AsReadOnly(); SectionNames = layout.SectionNames.AsReadOnly(); HiddenEntries = layout.Hidden.AsReadOnly(); DisplayName = layout.DisplayName; Compressible = compressible; CompressionAllowed = layout.CompressionAllowed.AsReadOnly(); DteAllowed = layout.DteAllowed.AsReadOnly(); }
public PartitionedFile(GenericCharMap map, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, IList <byte> bytes, string fileComments, IList <string> sectionComments) : base(map, layout, fileComments, sectionComments, false) { PartitionSize = layout.Size / NumberOfSections; List <IList <string> > sections = new List <IList <string> >(NumberOfSections); for (int i = 0; i < NumberOfSections; i++) { GenericCharMap processCharMap = DteAllowed[i] ? map : GetContextCharmap(layout.Context); sections.Add(TextUtilities.ProcessList(bytes.Sub(i * PartitionSize, (i + 1) * PartitionSize - 1), layout.AllowedTerminators, processCharMap)); if (sections[i].Count < SectionLengths[i]) { string[] newSection = new string[SectionLengths[i]]; sections[i].CopyTo(newSection, 0); new string[SectionLengths[i] - sections[i].Count].CopyTo(newSection, sections[i].Count); sections[i] = newSection; } else if (sections[i].Count > SectionLengths[i]) { sections[i] = sections[i].Sub(0, SectionLengths[i] - 1); } if (layout.AllowedTerminators.Count > 1) { Dictionary <byte, int> counts = new Dictionary <byte, int>(); layout.AllowedTerminators.ForEach(b => counts[b] = 0); bytes.FindAll(b => layout.AllowedTerminators.Contains(b)).ForEach(b => counts[b]++); List <KeyValuePair <byte, int> > countList = new List <KeyValuePair <byte, int> >(counts); countList.Sort((a, b) => b.Value.CompareTo(a.Value)); this.SelectedTerminator = countList[0].Key; } System.Diagnostics.Debug.Assert(sections[i].Count == SectionLengths[i]); } Sections = sections.AsReadOnly(); PopulateDisallowedSections(); }
public SectionedFile(GenericCharMap map, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, IList <byte> bytes, bool compressible) : base(map, layout, compressible) { List <IList <string> > sections = new List <IList <string> >(NumberOfSections); for (int i = 0; i < NumberOfSections; i++) { uint start = PatcherLib.Utilities.Utilities.BytesToUInt32(bytes.Sub(i * 4, (i + 1) * 4 - 1)); uint stop = PatcherLib.Utilities.Utilities.BytesToUInt32(bytes.Sub((i + 1) * 4, (i + 2) * 4 - 1)) - 1; if (i == NumberOfSections - 1) { stop = (uint)bytes.Count - 1 - (uint)DataStart; } IList <byte> thisSection = bytes.Sub((int)(start + DataStart), (int)(stop + DataStart)); if (compressible) { thisSection = TextUtilities.Decompress(bytes, thisSection, (int)(start + DataStart)); } sections.Add(TextUtilities.ProcessList(thisSection, CharMap)); } Sections = sections.AsReadOnly(); PopulateDisallowedSections(); }
public CompressibleOneShotFile(GenericCharMap map, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, IList <byte> bytes, string fileComments, IList <string> sectionComments) : base(map, layout, fileComments, sectionComments, true) { List <IList <string> > sections = new List <IList <string> >(NumberOfSections); System.Diagnostics.Debug.Assert(NumberOfSections == 1); System.Text.StringBuilder sbMessage = new System.Text.StringBuilder(); for (int i = 0; i < NumberOfSections; i++) { GenericCharMap processCharMap = DteAllowed[i] ? map : GetContextCharmap(layout.Context); sections.Add(TextUtilities.ProcessList(TextUtilities.Decompress(bytes, bytes, 0), layout.AllowedTerminators, processCharMap)); if (sections[i].Count < SectionLengths[i]) { string[] newSection = new string[SectionLengths[i]]; sections[i].CopyTo(newSection, 0); new string[SectionLengths[i] - sections[i].Count].CopyTo(newSection, sections[i].Count); sections[i] = newSection; } else if (sections[i].Count > SectionLengths[i]) { if ((sections[i].Count - SectionLengths[i]) > 1) { sbMessage.AppendLine(string.Format("File {0} (section {1}): Section length decreased from {2} to {3}.", layout.DisplayName, i, sections[i].Count, SectionLengths[i])); } sections[i] = sections[i].Sub(0, SectionLengths[i] - 1); } } // <DEBUG> //string message = sbMessage.ToString(); //if (!string.IsNullOrEmpty(message)) // PatcherLib.MyMessageBox.Show(message); Sections = sections.AsReadOnly(); }
public SectionedFile(GenericCharMap map, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, IList <byte> bytes, string fileComments, IList <string> sectionComments) : this(map, layout, bytes, fileComments, sectionComments, false) { }
public static AbstractFile ConstructFile(FileType type, GenericCharMap charmap, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, IList <IList <string> > strings, string fileComments, IList <string> sectionComments) { switch (type) { case FileType.CompressedFile: return(new SectionedFile(charmap, layout, strings, fileComments, sectionComments, true)); case FileType.SectionedFile: return(new SectionedFile(charmap, layout, strings, fileComments, sectionComments, false)); case FileType.CompressibleOneShotFile: return(new CompressibleOneShotFile(charmap, layout, strings, fileComments, sectionComments)); case FileType.OneShotFile: case FileType.PartitionedFile: return(new PartitionedFile(charmap, layout, strings, fileComments, sectionComments)); } return(null); }
public static AbstractFile ConstructFile(FileType type, GenericCharMap charmap, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, IList <byte> bytes) { switch (type) { case FileType.CompressedFile: return(new SectionedFile(charmap, layout, bytes, string.Empty, new string[layout.SectionNames.Count], true)); case FileType.SectionedFile: return(new SectionedFile(charmap, layout, bytes, string.Empty, new string[layout.SectionNames.Count], false)); case FileType.OneShotFile: case FileType.PartitionedFile: return(new PartitionedFile(charmap, layout, bytes, string.Empty, new string[layout.SectionNames.Count])); } return(null); }
public SectionedFile(GenericCharMap map, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, IList <byte> bytes) : this(map, layout, bytes, false) { }