private static FFTText GetText(Stream iso, Context context, XmlNode doc, BytesFromIso reader, GenericCharMap charmap, BackgroundWorker worker) { IDictionary <Guid, ISerializableFile> files = GetFiles(iso, context, doc, reader, charmap, worker); if (files == null || worker.CancellationPending) { return(null); } var quickEdit = new QuickEdit(files, GetQuickEditLookup(doc.SelectSingleNode("//QuickEdit"), worker)); if (quickEdit == null || worker.CancellationPending) { return(null); } return(new FFTText(context, files, quickEdit)); }
public static FFTText GetFilesXml(XmlNode doc, BackgroundWorker worker) { Context context = (Context)Enum.Parse(typeof(Context), doc.SelectSingleNode("/FFTText/@context").InnerText); XmlNode layoutDoc = context == Context.US_PSP ? Resources.PSP : Resources.PSX; GenericCharMap charmap = (context == Context.US_PSP) ? (GenericCharMap)TextUtilities.PSPMap : (GenericCharMap)TextUtilities.PSXMap; Dictionary <Guid, ISerializableFile> result = new Dictionary <Guid, ISerializableFile>(); foreach (XmlNode fileNode in doc.SelectNodes("//File")) { string guidText = fileNode.SelectSingleNode("Guid").InnerText; Guid guid = new Guid(guidText); if (worker.CancellationPending) { return(null); } FileInfo fi = GetFileInfo(context, layoutDoc.SelectSingleNode(string.Format("//Files/*[Guid='{0}']", guidText))); if (worker.CancellationPending) { return(null); } result.Add( guid, AbstractFile.ConstructFile(fi.FileType, charmap, fi, GetStrings(fileNode.SelectSingleNode("Sections")))); if (worker.CancellationPending) { return(null); } } var quickEdit = new QuickEdit(result, GetQuickEditLookup(layoutDoc.SelectSingleNode("//QuickEdit"), worker)); if (quickEdit == null || worker.CancellationPending) { return(null); } return(new FFTText(context, result, quickEdit)); }
public void RegulateNewlines() { string newNewline = String.Format("{{Newline}}{0}", Environment.NewLine); foreach (IFile file in Files) { if (file is QuickEdit) { QuickEdit quickEdit = (QuickEdit)file; int numSections = quickEdit.NumberOfSections; for (int sectionIndex = 0; sectionIndex < numSections; sectionIndex++) { int numEntries = quickEdit.SectionLengths[sectionIndex]; for (int entryIndex = 0; entryIndex < numEntries; entryIndex++) { if (!string.IsNullOrEmpty(quickEdit[sectionIndex, entryIndex])) { quickEdit.UpdateEntry(sectionIndex, entryIndex, quickEdit[sectionIndex, entryIndex].Replace("\r", "").Replace("\n", "").Replace("{Newline}", newNewline)); } } } } if (file is AbstractFile) { AbstractFile aFile = (AbstractFile)file; foreach (IList <string> section in aFile.Sections) { for (int index = 0; index < section.Count; index++) { if (!string.IsNullOrEmpty(section[index])) { section[index] = section[index].Replace("\r", "").Replace("\n", "").Replace("{Newline}", newNewline); } } } } } }
internal FFTText(Context context, IDictionary <Guid, ISerializableFile> files, QuickEdit quickEdit) { Filetype = context; List <IFile> filesList = new List <IFile>(files.Count + 1); files.ForEach(kvp => filesList.Add(kvp.Value)); filesList.Sort((a, b) => a.DisplayName.CompareTo(b.DisplayName)); filesList.Add(quickEdit); Files = filesList.AsReadOnly(); CharMap = filesList[0].CharMap; }
public static FFTText GetFilesXml(XmlNode doc, BackgroundWorker worker, Set <Guid> guidsToLoadFromIso, Stream iso) { Context context = (Context)Enum.Parse(typeof(Context), doc.SelectSingleNode("/FFTText/@context").InnerText); XmlNode layoutDoc = context == Context.US_PSP ? Resources.PSP : Resources.PSX; GenericCharMap charmap = (context == Context.US_PSP) ? (GenericCharMap)TextUtilities.PSPMap : (GenericCharMap)TextUtilities.PSXMap; Dictionary <Guid, ISerializableFile> result = new Dictionary <Guid, ISerializableFile>(); foreach (XmlNode fileNode in doc.SelectNodes("//File")) { string guidText = fileNode.SelectSingleNode("Guid").InnerText; Guid guid = new Guid(guidText); if (worker.CancellationPending) { return(null); } FileInfo fi = GetFileInfo(context, layoutDoc.SelectSingleNode(string.Format("//Files/*[Guid='{0}']", guidText))); string fileComment = GetFileComment(doc.SelectSingleNode(string.Format("//FFTText/*[Guid='{0}']", guidText))); if (worker.CancellationPending) { return(null); } XmlNode sectionsNode = fileNode.SelectSingleNode("Sections"); result.Add( guid, AbstractFile.ConstructFile(fi.FileType, charmap, fi, GetStrings(sectionsNode), fileComment, GetSectionComments(sectionsNode))); if (worker.CancellationPending) { return(null); } } if (guidsToLoadFromIso != null && guidsToLoadFromIso.Count > 0 && iso != null) { FFTText tempText = null; if (context == Context.US_PSP) { tempText = GetPspText(iso, worker); } else if (context == Context.US_PSX) { tempText = GetPsxText(iso, worker); } Set <IFile> isoFiles = new Set <IFile>( tempText.Files.FindAll(f => f is ISerializableFile).FindAll(g => guidsToLoadFromIso.Contains((g as ISerializableFile).Layout.Guid))); isoFiles.ForEach(f => result.Add((f as ISerializableFile).Layout.Guid, f as ISerializableFile)); } //result.Values.ForEach( f => RemoveUnnecessaryColors( f ) ); XmlNode quickEditNode = layoutDoc.SelectSingleNode("//QuickEdit"); Set <Guid> guids = GetGuidsNeededForQuickEdit(quickEditNode); QuickEdit quickEdit = null; if (guids.TrueForAll(g => result.ContainsKey(g))) { quickEdit = new QuickEdit(context, result, GetQuickEditLookup(layoutDoc.SelectSingleNode("//QuickEdit"), worker)); if (quickEdit == null || worker.CancellationPending) { return(null); } } return(new FFTText(context, result, null, quickEdit)); }
internal FFTText(Context context, IDictionary <Guid, ISerializableFile> files, IList <Glyph> customGlyphs, QuickEdit quickEdit) { this.customGlyphs = customGlyphs; Filetype = context; List <IFile> filesList = new List <IFile>(files.Count + 1); files.ForEach(kvp => filesList.Add(kvp.Value)); filesList.Sort((a, b) => a.DisplayName.CompareTo(b.DisplayName)); if (quickEdit != null) { filesList.Insert(0, quickEdit); } Files = filesList.AsReadOnly(); CharMap = filesList[0].CharMap; }