Exemplo n.º 1
0
        public void RestoreFile(System.IO.Stream iso)
        {
            IList <byte> bytes = null;

            if (Layout.Context == Context.US_PSX)
            {
                KeyValuePair <Enum, int> sect = Layout.Sectors[SectorType.Sector][0];
                bytes = PsxIso.ReadFile(iso, (PsxIso.Sectors)sect.Key, sect.Value, Layout.Size);
            }
            else if (Layout.Context == Context.US_PSP)
            {
                PatcherLib.Iso.PspIso.PspIsoInfo info = PatcherLib.Iso.PspIso.PspIsoInfo.GetPspIsoInfo(iso);
                if (Layout.Sectors.ContainsKey(SectorType.BootBin))
                {
                    KeyValuePair <Enum, int> sect = Layout.Sectors[SectorType.BootBin][0];
                    bytes = PspIso.GetFile(iso, info, (PspIso.Sectors)sect.Key, sect.Value, Layout.Size);
                }
                else if (Layout.Sectors.ContainsKey(SectorType.FFTPack))
                {
                    KeyValuePair <Enum, int> sect = Layout.Sectors[SectorType.FFTPack][0];
                    bytes = PspIso.GetFile(iso, info, (FFTPack.Files)sect.Key, sect.Value, Layout.Size);
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
            else
            {
                throw new InvalidOperationException();
            }
            AbstractFile tempFile = ConstructFile(
                Layout.FileType,
                CharMap,
                Layout,
                bytes);

            this.Sections = tempFile.Sections;
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        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));
        }