Example #1
0
        }                                             // Rip result

        public LogFormat(FormatBase.Model model, Stream stream, string path) : base(model, stream, path)
        {
        }
Example #2
0
            /// <summary>Factory method for various file formats.</summary>
            public static Model Create(Stream fs0, string path,
                                       Hashes hashFlags, Validations validationFlags,
                                       string filter, out FileFormat actual)
            {
                bool isKnown = false;

                actual = null;

                FormatBase.Model model = null;
                var isMisname          = false;
                var ext = System.IO.Path.GetExtension(path);

                if (ext.Length < 2)
                {
                    return(null);
                }
                ext = ext.Substring(1).ToLower();

                var hdr = new byte[0x2C];

                fs0.Read(hdr, 0, hdr.Length);

                using (var scan = KaosDiags.Diags.FileFormats.Items.GetEnumerator())
                {
                    for (FileFormat other = null;;)
                    {
                        if (scan.MoveNext())
                        {
                            if (scan.Current.Names.Contains(ext))
                            {
                                isKnown = true;
                                if (scan.Current.Subname != null && scan.Current.Subname[0] == '*')
                                {
                                    other = scan.Current;
                                }
                                else
                                {
                                    model = scan.Current.ModelFactory(fs0, hdr, path);
                                    if (model != null)
                                    {
                                        actual = scan.Current;
                                        break;
                                    }
                                }
                            }
                            continue;
                        }

                        if (!isKnown && filter == null)
                        {
                            return(null);
                        }

                        if (other != null)
                        {
                            actual = other;
                            if (other.Subname[0] == '*')
                            {
                                return(null);
                            }
                            model = other.ModelFactory(fs0, hdr, path);
                            break;
                        }

                        scan.Reset();
                        do
                        {
                            if (!scan.MoveNext())
                            {
                                var result = new UnknownFormat.Model(fs0, path);
                                result.CalcHashes(hashFlags, validationFlags);
                                return(result);
                            }
                            if (scan.Current.Names.Contains(ext))
                            {
                                continue;
                            }
                            model = scan.Current.ModelFactory(fs0, hdr, path);
                        }while (model == null);

                        actual    = scan.Current;
                        isKnown   = true;
                        isMisname = true;
                        break;
                    }
                }

                FormatBase fmt = model.Data;

                if (!fmt.Issues.HasFatal)
                {
                    if (fmt.mediaPosition < 0)
                    {
                        fmt.mediaPosition = 0;
                        fmt.MediaCount    = fmt.FileSize;
                    }

                    model.CalcHashes(hashFlags, validationFlags);

                    if (isMisname)
                    {
                        // This repair goes last because it must close the file.
                        ++actual.TotalMisnamed;
                        fmt.FfIssue = model.IssueModel.Add
                                          ($"True file format is .{actual.PrimaryName}.", Severity.Warning, 0,
                                          "Rename to extension of ." + actual.PrimaryName, model.RepairWrongExtension, isFinalRepairer: true);
                    }
                }

                return(model);
            }