private static bool HandleCommandLinePatch(string[] args) { System.Collections.Generic.KeyValuePair <string, string> patchFilepaths = PatcherLib.Utilities.Utilities.GetPatchFilepaths(args, ".ffttext", new string[3] { ".bin", ".iso", ".img" }); if ((string.IsNullOrEmpty(patchFilepaths.Key)) || (string.IsNullOrEmpty(patchFilepaths.Value))) { return(false); } else { System.IO.Directory.SetCurrentDirectory(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)); try { FFTText fftText = FFTTextFactory.GetFilesXml(patchFilepaths.Key); fftText.PatchISOSimple(patchFilepaths.Value); } catch (Exception ex) { AttachConsole(ATTACH_PARENT_PROCESS); Console.WriteLine("Error: " + ex.Message); } return(true); } }
private void LoadFile(FFTText file) { MethodInvoker whatever = delegate() { internalFile = file; textMenuItem.MenuItems.Clear(); foreach (IFile ifile in file.Files) { MenuItem mi = new MenuItem(ifile.DisplayName, fileClick); mi.Tag = ifile; textMenuItem.MenuItems.Add(mi); } fileClick(textMenuItem.MenuItems[0], EventArgs.Empty); textMenuItem.Enabled = true; saveMenuItem.Enabled = true; menuItem2.Enabled = true; allowedSymbolsMenuItem.Enabled = true; }; if (this.InvokeRequired) { Invoke(whatever); } else { whatever(); } }
public static void WriteXml(FFTText text, string filename) { using (Stream stream = File.Open(filename, FileMode.Create, FileAccess.ReadWrite)) { WriteXml(text, stream); } }
public void DoWork( IWin32Window parent, BackgroundWorker worker, FFTText.PatchIsoArgs args ) { this.worker = worker; worker.ProgressChanged += new ProgressChangedEventHandler( worker_ProgressChanged ); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler( worker_RunWorkerCompleted ); worker.RunWorkerAsync( args ); this.ShowDialog( parent ); }
public static void WriteXml(FFTText text, Stream output) { XmlTextWriter writer = new XmlTextWriter(output, Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.Indentation = 3; writer.IndentChar = ' '; writer.WriteStartDocument(); writer.WriteStartElement("FFTText"); writer.WriteAttributeString("context", text.Filetype.ToString()); IList <ISerializableFile> files = new List <ISerializableFile>(text.Files.Count); text.Files.FindAll(f => f is ISerializableFile).ForEach(s => files.Add(s as ISerializableFile)); files.ForEach(f => WriteFileXml(f, writer)); writer.WriteEndElement(); // FFTText writer.WriteEndDocument(); writer.Flush(); }
private void LoadFile(LoadType loadType, string filename, Stream isoStream, Stream tblStream) { BackgroundWorker worker = new BackgroundWorker(); worker.WorkerSupportsCancellation = true; worker.WorkerReportsProgress = true; DialogResult missingFilesResult = DialogResult.No; string missingFilesIsoFilename = null; MethodInvoker missingPrompt = null; missingPrompt = delegate() { var res = MyMessageBox.Show(this, "Some files are missing." + Environment.NewLine + "Load missing files from ISO?", "Files missing", MessageBoxButtons.YesNoCancel); if (res == DialogResult.Yes) { openFileDialog.Filter = "ISO files (*.iso, *.bin, *.img)|*.iso;*.bin;*.img"; openFileDialog.FileName = string.Empty; if (openFileDialog.ShowDialog(this) == DialogResult.OK) { missingFilesIsoFilename = openFileDialog.FileName; } else { missingPrompt(); } } missingFilesResult = res; }; worker.DoWork += delegate(object sender, DoWorkEventArgs args) { FFTText text = null; switch (loadType) { case LoadType.Open: Set <Guid> missing = FFTTextFactory.DetectMissingGuids(filename); if (missing.Count > 0) { if (InvokeRequired) { Invoke(missingPrompt); } else { missingPrompt(); } if (missingFilesResult == DialogResult.Yes) { using (Stream missingStream = File.OpenRead(missingFilesIsoFilename)) { text = FFTTextFactory.GetFilesXml(filename, worker, missing, missingStream); } } else if (missingFilesResult == DialogResult.Cancel) { text = null; } else if (missingFilesResult == DialogResult.No) { text = FFTTextFactory.GetFilesXml(filename, worker); } } else { text = FFTTextFactory.GetFilesXml(filename, worker); } break; case LoadType.PspFilename: text = FFTText.ReadPSPIso(filename, worker); break; case LoadType.PsxFilename: text = FFTText.ReadPSXIso(filename, worker); break; } if (text == null || worker.CancellationPending) { args.Cancel = true; return; } LoadFile(text); }; MethodInvoker enableForm = delegate() { fileMenuItem.Enabled = true; isoMenuItem.Enabled = true; textMenuItem.Enabled = true; fileEditor1.Enabled = true; helpMenuItem.Enabled = true; Cursor = Cursors.Default; }; worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs args) { if (args.Error != null) { MyMessageBox.Show(this, "Error loading file: " + args.Error.Message, "Error", MessageBoxButtons.OK); } if (InvokeRequired) { Invoke(enableForm); } else { enableForm(); } }; fileMenuItem.Enabled = false; isoMenuItem.Enabled = false; textMenuItem.Enabled = false; fileEditor1.Enabled = false; helpMenuItem.Enabled = false; Cursor = Cursors.WaitCursor; worker.RunWorkerAsync(); }
private void LoadFile(LoadType loadType, string filename, Stream isoStream, Stream tblStream) { BackgroundWorker worker = new BackgroundWorker(); worker.WorkerSupportsCancellation = true; worker.WorkerReportsProgress = true; worker.DoWork += delegate(object sender, DoWorkEventArgs args) { FFTText text = null; switch (loadType) { case LoadType.Open: text = FFTTextFactory.GetFilesXml(filename, worker); break; case LoadType.PspFilename: text = FFTText.ReadPSPIso(filename, worker); break; case LoadType.PsxFilename: text = FFTText.ReadPSXIso(filename, worker); break; case LoadType.PspStreamAndTable: text = FFTTextFactory.GetPspText(isoStream, tblStream, worker); break; case LoadType.PsxStreamAndTable: text = FFTTextFactory.GetPsxText(isoStream, tblStream, worker); break; } if (text == null || worker.CancellationPending) { args.Cancel = true; return; } LoadFile(text); }; MethodInvoker enableForm = delegate() { fileMenuItem.Enabled = true; isoMenuItem.Enabled = true; textMenuItem.Enabled = true; fileEditor1.Enabled = true; helpMenuItem.Enabled = true; Cursor = Cursors.Default; }; worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs args) { if (args.Error != null) { MessageBox.Show(this, "Error loading file: " + args.Error.Message, "Error", MessageBoxButtons.OK); } if (InvokeRequired) { Invoke(enableForm); } else { enableForm(); } }; fileMenuItem.Enabled = false; isoMenuItem.Enabled = false; textMenuItem.Enabled = false; fileEditor1.Enabled = false; helpMenuItem.Enabled = false; Cursor = Cursors.WaitCursor; worker.RunWorkerAsync(); }
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)); }
public static void WriteXml( FFTText text, Stream output ) { XmlTextWriter writer = new XmlTextWriter( output, Encoding.UTF8 ); writer.Formatting = Formatting.Indented; writer.Indentation = 3; writer.IndentChar = ' '; writer.WriteStartDocument(); writer.WriteStartElement( "FFTText" ); writer.WriteAttributeString( "context", text.Filetype.ToString() ); IList<ISerializableFile> files = new List<ISerializableFile>( text.Files.Count ); text.Files.FindAll( f => f is ISerializableFile ).ForEach( s => files.Add( s as ISerializableFile ) ); files.ForEach( f => WriteFileXml( f, writer ) ); writer.WriteEndElement(); // FFTText writer.WriteEndDocument(); writer.Flush(); }
public static void WriteXml( FFTText text, string filename ) { using ( Stream stream = File.Open( filename, FileMode.Create, FileAccess.ReadWrite ) ) { WriteXml( text, stream ); } }
private void LoadFile( FFTText file ) { MethodInvoker whatever = delegate() { internalFile = file; textMenuItem.MenuItems.Clear(); foreach ( IFile ifile in file.Files ) { MenuItem mi = new MenuItem( ifile.DisplayName, fileClick ); mi.Tag = ifile; textMenuItem.MenuItems.Add( mi ); } fileClick( textMenuItem.MenuItems[0], EventArgs.Empty ); textMenuItem.Enabled = true; saveMenuItem.Enabled = true; menuItem2.Enabled = true; allowedSymbolsMenuItem.Enabled = true; }; if ( this.InvokeRequired ) { Invoke( whatever ); } else { whatever(); } }