Example #1
0
        private static void ScanFiles()
        {
            var parsers = new List <Action <BinaryReader, string> >();

            if (_checkAll || _checkTim)
            {
                parsers.Add((binaryReader, fileTitle) =>
                {
                    var timParser = new TIMParser((tmdEntity, fp) =>
                    {
                        AllTextures.Add(tmdEntity);
                        UpdateProgress(fp, $"Found Texture {tmdEntity.Width}x{tmdEntity.Height} {tmdEntity.Bpp}bpp");
                        PreviewForm.ReloadItems();
                    });
                    //Program.Logger.WriteLine("");
                    Program.Logger.WriteLine("Scanning for TIM at file {0}", fileTitle);
                    timParser.LookForTim(binaryReader, fileTitle);
                });
            }

            if (_checkAll || _checkCroc)
            {
                parsers.Add((binaryReader, fileTitle) =>
                {
                    var crocModelReader = new CrocModelReader((tmdEntity, fp) =>
                    {
                        AllEntities.Add(tmdEntity);
                        UpdateProgress(fp, $"Found Model with {tmdEntity.ChildCount} objects");
                        PreviewForm.ReloadItems();
                    });
                    //Program.Logger.WriteLine("");
                    Program.Logger.WriteLine("Scanning for Croc at file {0}", fileTitle);
                    crocModelReader.LookForCrocModel(binaryReader, fileTitle);
                });
            }

            if (_checkAll || _checkBff)
            {
                parsers.Add((binaryReader, fileTitle) =>
                {
                    var crocModelReader = new BFFModelReader((tmdEntity, fp) =>
                    {
                        AllEntities.Add(tmdEntity);
                        UpdateProgress(fp, $"Found Model with {tmdEntity.ChildCount} objects");
                        PreviewForm.ReloadItems();
                    });
                    //Program.Logger.WriteLine("");
                    Program.Logger.WriteLine("Scanning for BFF at file {0}", fileTitle);
                    crocModelReader.LookForBFF(binaryReader, fileTitle);
                });
            }

            if (_checkAll || _checkPsx)
            {
                parsers.Add((binaryReader, fileTitle) =>
                {
                    var psxParser = new PSXParser((tmdEntity, fp) =>
                    {
                        AllEntities.Add(tmdEntity);
                        UpdateProgress(fp, $"Found Model with {tmdEntity.ChildCount} objects");
                        PreviewForm.ReloadItems();
                    });
                    //Program.Logger.WriteLine("");
                    Program.Logger.WriteLine("Scanning for PSX at file {0}", fileTitle);
                    psxParser.LookForPSX(binaryReader, fileTitle);
                });
            }

            if (_checkAll || _checkTmd)
            {
                parsers.Add((binaryReader, fileTitle) =>
                {
                    var tmdParser = new TMDParser((tmdEntity, fp) =>
                    {
                        AllEntities.Add(tmdEntity);
                        UpdateProgress(fp, $"Found Model with {tmdEntity.ChildCount} objects");
                        PreviewForm.ReloadItems();
                    });
                    //Program.Logger.WriteLine("");
                    Program.Logger.WriteLine("Scanning for TMD at file {0}", fileTitle);
                    tmdParser.LookForTmd(binaryReader, fileTitle);
                });
            }

            if (_checkAll || _checkVdf)
            {
                parsers.Add((binaryReader, fileTitle) =>
                {
                    var vdfParser = new VDFParser((vdfEntity, fp) =>
                    {
                        AllAnimations.Add(vdfEntity);
                        UpdateProgress(fp, $"Found Animation with {vdfEntity.ObjectCount} objects");
                        PreviewForm.ReloadItems();
                    });
                    //Program.Logger.WriteLine("");
                    Program.Logger.WriteLine("Scanning for VDF at file {0}", fileTitle);
                    vdfParser.LookForVDF(binaryReader, fileTitle);
                });
            }

            if (_checkAll || _checkAn)
            {
                parsers.Add((binaryReader, fileTitle) =>
                {
                    var anParser = new ANParser((vdfEntity, fp) =>
                    {
                        AllAnimations.Add(vdfEntity);
                        UpdateProgress(fp, $"Found Animation with {vdfEntity.ObjectCount} objects");
                        PreviewForm.ReloadItems();
                    });
                    //Program.Logger.WriteLine("");
                    Program.Logger.WriteLine("Scanning for AN at file {0}", fileTitle);
                    anParser.LookForAN(binaryReader, fileTitle);
                });
            }

            if (_checkAll || _checkPmd)
            {
                parsers.Add((binaryReader, fileTitle) =>
                {
                    var pmdParser = new PMDParser((pmdEntity, fp) =>
                    {
                        AllEntities.Add(pmdEntity);
                        UpdateProgress(fp, $"Found Model with {pmdEntity.ChildCount} objects");
                        PreviewForm.ReloadItems();
                    });
                    //Program.Logger.WriteLine("");
                    Program.Logger.WriteLine("Scanning for PMD at file {0}", fileTitle);
                    pmdParser.LookForPMD(binaryReader, fileTitle);
                });
            }

            if (_checkAll || _checkTod)
            {
                parsers.Add((binaryReader, fileTitle) =>
                {
                    var todParser = new TODParser((todEntity, fp) =>
                    {
                        AllAnimations.Add(todEntity);
                        UpdateProgress(fp, $"Found Animation with {todEntity.ObjectCount} objects and {todEntity.FrameCount} frames");
                        PreviewForm.ReloadItems();
                    });
                    //Program.Logger.WriteLine("");
                    Program.Logger.WriteLine("Scanning for TOD at file {0}", fileTitle);
                    todParser.LookForTOD(binaryReader, fileTitle);
                });
            }

            if (_checkAll || _checkHmd)
            {
                parsers.Add((binaryReader, fileTitle) =>
                {
                    var hmdParser = new HMDParser((hmdEntity, fp) =>
                    {
                        AllEntities.Add(hmdEntity);
                        UpdateProgress(fp, $"Found Model with {hmdEntity.ChildCount} objects");
                        PreviewForm.ReloadItems();
                    }, (hmdAnimation, fp) =>
                    {
                        AllAnimations.Add(hmdAnimation);
                        UpdateProgress(fp, $"Found Animation with {hmdAnimation.ObjectCount} objects and {hmdAnimation.FrameCount} frames");
                        PreviewForm.ReloadItems();
                    }, delegate(Texture texture, long fp)
                    {
                        AllTextures.Add(texture);
                        UpdateProgress(fp, $"Found Texture {texture.Width}x{texture.Height} {texture.Bpp}bpp");
                        PreviewForm.ReloadItems();
                    }
                                                  );
                    //Program.Logger.WriteLine("");
                    Program.Logger.WriteLine("Scanning for HMD at file {0}", fileTitle);
                    hmdParser.LookForHMDEntities(binaryReader, fileTitle);
                });
            }

            if (File.Exists(_path))
            {
                Parallel.ForEach(parsers, parser =>
                {
                    using (var fs = File.Open(_path, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        ProcessFile(fs, _path, parser);
                    }
                });
            }
            else
            {
                ProcessFiles(_path, Filter, parsers);
            }
        }
Example #2
0
        private static void ScanFiles()
        {
            var parsers = new List <Action <BinaryReader, string> >();

            if (_checkAll || _checkTim)
            {
                parsers.Add((binaryReader, fileTitle) =>
                {
                    var timParser = new TIMParser((tmdEntity, fp) =>
                    {
                        AllTextures.Add(tmdEntity);
                        UpdateProgress(fp, $"Found Texture {tmdEntity.Width}x{tmdEntity.Height} {tmdEntity.Bpp}bpp");
                        PreviewForm.ReloadItems();
                    });
                    Logger.WriteLine("");
                    Logger.WriteLine("Scanning for TIM Images at file {0}", fileTitle);
                    timParser.LookForTim(binaryReader, fileTitle);
                });
            }

            if (_checkTimAlt)
            {
                parsers.Add((binaryReader, fileTitle) =>
                {
                    var timParser = new TIMParserOld((tmdEntity, fp) =>
                    {
                        AllTextures.Add(tmdEntity);
                        UpdateProgress(fp, $"Found Texture {tmdEntity.Width}x{tmdEntity.Height} {tmdEntity.Bpp}bpp");
                        PreviewForm.ReloadItems();
                    });
                    Logger.WriteLine("");
                    Logger.WriteLine("Scanning for TIM Images (alt) at file {0}", fileTitle);
                    timParser.LookForTim(binaryReader, fileTitle);
                });
            }

            if (_checkAll || _checkTmd)
            {
                parsers.Add((binaryReader, fileTitle) =>
                {
                    var tmdParser = new TMDParser((tmdEntity, fp) =>
                    {
                        AllEntities.Add(tmdEntity);
                        UpdateProgress(fp, $"Found Model with {tmdEntity.ChildCount} objects");
                        PreviewForm.ReloadItems();
                    });
                    Logger.WriteLine("");
                    Logger.WriteLine("Scanning for TMD Models at file {0}", fileTitle);
                    tmdParser.LookForTmd(binaryReader, fileTitle);
                });
            }

            if (_checkTmdAlt)
            {
                parsers.Add((binaryReader, fileTitle) =>
                {
                    var tmdParser = new TMDParserAlternative((tmdEntity, fp) =>
                    {
                        AllEntities.Add(tmdEntity);
                        UpdateProgress(fp, $"Found Model with {tmdEntity.ChildCount} objects");
                        PreviewForm.ReloadItems();
                    });
                    Logger.WriteLine("");
                    Logger.WriteLine("Scanning for TMD Models (alt) at file {0}", fileTitle);
                    tmdParser.LookForTmd(binaryReader, fileTitle);
                });
            }

            if (_checkAll || _checkPmd)
            {
                parsers.Add((binaryReader, fileTitle) =>
                {
                    var pmdParser = new PMDParser((pmdEntity, fp) =>
                    {
                        AllEntities.Add(pmdEntity);
                        UpdateProgress(fp, $"Found Model with {pmdEntity.ChildCount} objects");
                        PreviewForm.ReloadItems();
                    });
                    Logger.WriteLine("");
                    Logger.WriteLine("Scanning for PMD Models at file {0}", fileTitle);
                    pmdParser.LookForPMD(binaryReader, fileTitle);
                });
            }

            if (_checkAll || _checkTod)
            {
                parsers.Add((binaryReader, fileTitle) =>
                {
                    var todParser = new TODParser((todEntity, fp) =>
                    {
                        AllAnimations.Add(todEntity);
                        UpdateProgress(fp, $"Found Animation with {todEntity.ObjectCount} objects and {todEntity.FrameCount} frames");
                        PreviewForm.ReloadItems();
                    });
                    Logger.WriteLine("");
                    Logger.WriteLine("Scanning for TOD Animations at file {0}", fileTitle);
                    todParser.LookForTOD(binaryReader, fileTitle);
                });
            }

            if (_checkHmdModels)
            {
                parsers.Add((binaryReader, fileTitle) =>
                {
                    var hmdParser = new HMDParser((hmdEntity, fp) =>
                    {
                        AllEntities.Add(hmdEntity);
                        UpdateProgress(fp, $"Found Model with {hmdEntity.ChildCount} objects");
                        PreviewForm.ReloadItems();
                    });
                    Logger.WriteLine("");
                    Logger.WriteLine("Scanning for HMD Models at file {0}", fileTitle);
                    hmdParser.LookForHMDEntities(binaryReader, fileTitle);
                });
            }

            if (_path.ToLowerInvariant().EndsWith(".iso"))
            {
                using (var isoStream = File.Open(_path, FileMode.Open))
                {
                    var cdReader = new CDReader(isoStream, true);
                    var files    = cdReader.GetFiles("", _filter ?? "*.*", SearchOption.AllDirectories);
                    foreach (var file in files)
                    {
                        if (file.ToLowerInvariant().Contains(".str;"))
                        {
                            continue;
                        }
                        var fileInfo = cdReader.GetFileInfo(file);
                        if (fileInfo.Exists)
                        {
                            foreach (var parser in parsers)
                            {
                                using (var stream = fileInfo.OpenRead())
                                {
                                    ProcessFile(stream, file, parser);
                                }
                            }
                        }
                    }
                }
            }
            else if (File.Exists(_path))
            {
                Parallel.ForEach(parsers, parser =>
                {
                    using (var fs = File.Open(_path, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        ProcessFile(fs, _path, parser);
                    }
                });
            }
            else
            {
                ProcessFiles(_path, _filter, parsers);
            }
        }