コード例 #1
0
        public static void Main(string[] args)
        {
            bool   showHelp       = false;
            string currentProject = null;

            var options = new OptionSet()
            {
                { "h|help", "show this message and exit", v => showHelp = v != null },
                { "p|project=", "override current project", v => currentProject = v },
            };

            List <string> extras;

            try
            {
                extras = options.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write("{0}: ", GetExecutableName());
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `{0} --help' for more information.", GetExecutableName());
                return;
            }

            if (extras.Count != 0 || showHelp == true)
            {
                Console.WriteLine("Usage: {0} [OPTIONS]+", GetExecutableName());
                Console.WriteLine();
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return;
            }

            Console.WriteLine("Loading project...");

            var manager = Manager.Load(currentProject);

            if (manager.ActiveProject == null)
            {
                Console.WriteLine("Nothing to do: no active project loaded.");
                return;
            }

            var project = manager.ActiveProject;

            var installPath = project.InstallPath;
            var listsPath   = project.ListsPath;

            if (installPath == null)
            {
                Console.WriteLine("Could not detect install path.");
                return;
            }

            if (listsPath == null)
            {
                Console.WriteLine("Could not detect lists path.");
                return;
            }

            var knownHashes = manager.LoadListsAnimationNames();

            var archivePaths = new List <string>();

            archivePaths.Add(Path.Combine(installPath, "afterbirth.a"));
            archivePaths.Add(Path.Combine(installPath, "animations.a"));

            var outputPaths = new List <string>();

            var nameHash = ArchiveFile.ComputeNameHash("resources/animations.b");

            for (int i = 0; i < archivePaths.Count; i++)
            {
                var archivePath = archivePaths[i];
                if (File.Exists(archivePath) == false)
                {
                    continue;
                }

                var outputPath = GetListPath(installPath, archivePath);
                if (outputPath == null)
                {
                    throw new InvalidOperationException();
                }

                Console.WriteLine(outputPath);
                outputPath = Path.Combine(listsPath, outputPath);

                if (outputPaths.Contains(outputPath) == true)
                {
                    throw new InvalidOperationException();
                }

                outputPaths.Add(outputPath);

                if (File.Exists(archivePath + ".bak") == true)
                {
                    archivePath += ".bak";
                }

                var hashes = new List <uint>();

                using (var input = File.OpenRead(archivePath))
                {
                    IArchiveFile archive;

                    if (ArchiveFile.IsValid(input) == true)
                    {
                        archive = new ArchiveFile();
                    }
                    else if (Gibbed.Antibirth.FileFormats.ArchiveFile.IsValid(input) == true)
                    {
                        archive = new Gibbed.Antibirth.FileFormats.ArchiveFile();
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }

                    archive.Deserialize(input);

                    var entry = archive.Entries.FirstOrDefault(e => e.NameHash == nameHash);
                    if (entry == null)
                    {
                        continue;
                    }

                    input.Seek(entry.Offset, SeekOrigin.Begin);
                    using (var data = entry.Read(input, archive))
                    {
                        var cache = new AnimationCacheBinaryFile();
                        cache.Deserialize(data);
                        hashes.AddRange(cache.AnimatedActors.Keys);
                    }
                }

                HandleEntries(hashes, knownHashes, outputPath);
            }
        }