Esempio n. 1
0
        private void BatchExtract(CacheBase cache, List <TreeNode> parents, Settings settings, string dest, BackgroundWorker worker)
        {
            foreach (TreeNode parent in parents)
            {
                foreach (TreeNode child in parent.Nodes)
                {
                    if (worker.CancellationPending)
                    {
                        return;
                    }

                    if (child.Nodes.Count > 0)
                    {
                        BatchExtract(cache, new List <TreeNode>()
                        {
                            child
                        }, settings, dest, worker);
                        continue;
                    }

                    var tag   = child.Tag as CacheBase.IndexItem;
                    var fName = dest + ((settings.Flags.HasFlag(SettingsFlags.OutputByType)) ? "\\" + tag.ClassName : "") + "\\" + tag.Filename;
                    var tName = tag.Filename + "." + tag.ClassCode;

                    switch (tag.ClassCode)
                    {
                        #region bink
                    case "bink":
                        try
                        {
                            //only supports H4R
                            if (cache.Version < DefinitionSet.Halo4Retail)
                            {
                                continue;
                            }

                            fName += ".bik";

                            //AddLine("Extracting " + tName + "...");
                            if (settings.Flags.HasFlag(SettingsFlags.OverwriteTags) || !File.Exists(fName))
                            {
                                BinkExtractor.SaveBink(fName, cache, tag);
                                AddLine("Extracted " + tName + ".");
                                tagsExtracted++;
                            }
                        }

                        catch (Exception ex)
                        {
                            AddLine("Error extracting " + tName + ":");
                            AddLine("--" + ex.Message.Replace("\r\n", " "));
                            tagsMissed++;
                        }
                        break;

                        #endregion
                        #region bitm
                    case "bitm":
                        try
                        {
                            switch (settings.BitmFormat)
                            {
                            case BitmapFormat.TIF:
                                fName += ".tif";
                                break;

                            case BitmapFormat.DDS:
                                fName += ".dds";
                                break;

                            case BitmapFormat.RAW:
                                fName += ".bin";
                                break;
                            }

                            if (settings.Flags.HasFlag(SettingsFlags.OverwriteTags) || !File.Exists(fName))
                            {
                                BitmapExtractor.SaveAllImages(fName, cache, tag, settings.BitmFormat, settings.Flags.HasFlag(SettingsFlags.BitmapAlpha));
                                AddLine("Extracted " + tName + ".");
                                tagsExtracted++;
                            }
                        }
                        catch (Exception ex)
                        {
                            AddLine("Error extracting " + tName + ":");
                            AddLine("--" + ex.Message.Replace("\r\n", " "));
                            tagsMissed++;
                        }
                        break;

                        #endregion
                        #region mode
                    case "mode":
                    case "mod2":
                        try
                        {
                            switch (settings.ModeFormat)
                            {
                            case ModelFormat.EMF:
                                fName += ".emf";
                                break;

                            case ModelFormat.JMS:
                                fName += ".jms";
                                break;

                            case ModelFormat.OBJ:
                                fName += ".obj";
                                break;

                            case ModelFormat.AMF:
                                fName += ".amf";
                                break;
                            }

                            if (settings.Flags.HasFlag(SettingsFlags.OverwriteTags) || !File.Exists(fName))
                            {
                                ModelExtractor.SaveAllModelParts(fName, cache, tag, settings.ModeFormat, settings.Flags.HasFlag(SettingsFlags.SplitMeshes));
                                AddLine("Extracted " + tName + ".");
                                tagsExtracted++;
                            }
                        }
                        catch (Exception ex)
                        {
                            AddLine("Error extracting " + tName + ":");
                            AddLine("--" + ex.Message.Replace("\r\n", " "));
                            tagsMissed++;
                        }
                        break;

                        #endregion
                        #region sbsp
                    case "sbsp":
                        try
                        {
                            //AddLine("Extracting " + tName + "...");
                            switch (settings.ModeFormat)
                            {
                            case ModelFormat.EMF:
                                fName += ".emf";
                                break;

                            case ModelFormat.OBJ:
                                fName += ".obj";
                                break;

                            case ModelFormat.AMF:
                            case ModelFormat.JMS:
                                fName += ".amf";
                                break;
                            }

                            if (settings.Flags.HasFlag(SettingsFlags.OverwriteTags) || !File.Exists(fName))
                            {
                                BSPExtractor.SaveAllBSPParts(fName, cache, tag, settings.ModeFormat);
                                AddLine("Extracted " + tName + ".");
                                tagsExtracted++;
                            }
                        }
                        catch (Exception ex)
                        {
                            AddLine("Error extracting " + tName + ":");
                            AddLine("--" + ex.Message.Replace("\r\n", " "));
                            tagsMissed++;
                        }
                        break;

                        #endregion
                        #region snd!
                    case "snd!":
                        try
                        {
                            //H2, H3B not supported
                            if (cache.Version <= DefinitionSet.Halo3Beta)
                            {
                                continue;
                            }

                            //AddLine("Extracting " + tName + "...");
                            if (cache.Version < DefinitionSet.Halo4Retail)
                            {
                                SoundExtractor.SaveAllAsSeparate(dest + tag.Filename, cache, tag, settings.Snd_Format, settings.Flags.HasFlag(SettingsFlags.OverwriteTags));
                            }
                            else
                            {
                                (new SoundExtractorH4()).SaveAllAsSeparate(dest + tag.Filename, cache, tag, settings.Snd_Format, settings.Flags.HasFlag(SettingsFlags.OverwriteTags));
                            }

                            //SoundExtractor.SaveAllAsSingle(fName, cache, tag, settings.Snd_Format);
                            AddLine("Extracted " + tag.Filename + "." + tag.ClassCode + ".");
                            tagsExtracted++;
                        }
                        catch (Exception ex)
                        {
                            AddLine("Error extracting " + tName + ":");
                            AddLine("--" + ex.Message.Replace("\r\n", " "));
                            tagsMissed++;
                        }
                        break;

                        #endregion
                        #region unic
                    case "unic":
                        try
                        {
                            //H2 not supported
                            if (cache.Version < DefinitionSet.Halo3Beta)
                            {
                                continue;
                            }

                            fName += ".txt";

                            //AddLine("Extracting " + tName + "...");
                            if (settings.Flags.HasFlag(SettingsFlags.OverwriteTags) || !File.Exists(fName))
                            {
                                StringsViewer.SaveUnicStrings(fName, cache, tag, settings.Language);
                                AddLine("Extracted " + tName + ".");
                                tagsExtracted++;
                            }
                        }
                        catch (Exception ex)
                        {
                            AddLine("Error extracting " + tName + ":");
                            AddLine("--" + ex.Message.Replace("\r\n", " "));
                            tagsMissed++;
                        }
                        break;
                        #endregion
                    }
                }
            }
        }