Beispiel #1
0
 public static FFTText GetPsxText(Stream iso, Stream tblStream, BackgroundWorker worker)
 {
     return(GetPsxText(iso, DTE.GenerateCharMap(tblStream), worker));
 }
Beispiel #2
0
        private IList <PatchedByteArray> DoDteCrap(IList <ISerializableFile> dteFiles, BackgroundWorker worker, DoWorkEventArgs args, out IDictionary <byte, string> dteMapping)
        {
            List <PatchedByteArray> patches = new List <PatchedByteArray>();

            dteMapping = null;
            if (worker.CancellationPending)
            {
                args.Cancel = true;
                return(null);
            }

            dteFiles.Sort((x, y) => (y.ToCDByteArray().Length - y.Layout.Size).CompareTo(x.ToCDByteArray().Length - x.Layout.Size));
            if (worker.CancellationPending)
            {
                args.Cancel = true;
                return(null);
            }

            IDictionary <ISerializableFile, Set <KeyValuePair <string, byte> > > filePreferredPairs = null;
            Set <KeyValuePair <string, byte> > currentPairs = null;

            DteResult result = DteResult.Empty;

            if (dteFiles.Count > 0)
            {
                int tries = dteFiles.Count;
                //DteResult result = DoDteForFiles( dteFiles, worker, args, out filePreferredPairs, out currentPairs );
                do
                {
                    result = DoDteForFiles(dteFiles, worker, args, out filePreferredPairs, out currentPairs);
                    switch (result.ResultCode)
                    {
                    case DteResult.Result.Cancelled:
                        args.Cancel = true;
                        return(null);

                    case DteResult.Result.Fail:
                        var failedFile = result.FailedFile;
                        if (dteFiles[0] == failedFile)
                        {
                            // Failed on the first file... this is hopeless
                            throw new FFTPatcher.TextEditor.DTE.DteException(failedFile);
                        }

                        // Bump the failed file to the top of the list
                        dteFiles.Remove(failedFile);
                        dteFiles.Insert(0, failedFile);
                        break;

                    case DteResult.Result.Success:
                        // do nothing
                        break;
                    }
                } while (result.ResultCode != DteResult.Result.Success && --tries >= 0);
            }

            switch (result.ResultCode)
            {
            case DteResult.Result.Fail:
                throw new FFTPatcher.TextEditor.DTE.DteException(dteFiles[0]);

            case DteResult.Result.Cancelled:
                args.Cancel = true;
                return(null);
            }

            foreach (var file in dteFiles)
            {
                worker.ReportProgress(0,
                                      new ProgressForm.FileProgress {
                    File = file, State = ProgressForm.TaskState.Starting, Task = ProgressForm.Task.GeneratePatch
                });
                var currentFileEncoding = PatcherLib.Utilities.Utilities.DictionaryFromKVPs(filePreferredPairs[file]);
                patches.AddRange(file.GetDtePatches(currentFileEncoding));
                worker.ReportProgress(0,
                                      new ProgressForm.FileProgress {
                    File = file, State = ProgressForm.TaskState.Done, Task = ProgressForm.Task.GeneratePatch
                });
                if (worker.CancellationPending)
                {
                    args.Cancel = true;
                    return(null);
                }
            }

            var myDteMapping = new Dictionary <byte, string>();

            currentPairs.ForEach(kvp => myDteMapping[kvp.Value] = kvp.Key);
            dteMapping = myDteMapping;

            patches.AddRange(DTE.GenerateDtePatches(this.Filetype, currentPairs));
            return(patches.AsReadOnly());
        }