Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        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();
        }