コード例 #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;
            HashList <ulong> knownHashes = null;

            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;
            }

            Console.WriteLine("Searching for archives...");
            var archivePaths = new List <string>();

            archivePaths.AddRange(Directory.GetFiles(installPath, "*.a", SearchOption.AllDirectories));
            archivePaths.RemoveAll(p => p.Contains("_unpack") == true);

            var outputPaths = new List <string>();

            var breakdown = new Breakdown();
            var tracking  = new Tracking();

            Console.WriteLine("Processing...");
            for (int i = 0; i < archivePaths.Count; i++)
            {
                var archivePath = archivePaths[i];

                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";
                }

                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);

                    knownHashes = manager.LoadListsFileNames();
                    if (knownHashes == null)
                    {
                        throw new InvalidOperationException();
                    }

                    HandleEntries(archive.Entries.Select(e => e.NameHash).Distinct(),
                                  knownHashes,
                                  tracking,
                                  breakdown,
                                  outputPath);
                }
            }

            using (var output = new StreamWriter(Path.Combine(Path.Combine(listsPath, "files"), "status.txt")))
            {
                output.WriteLine(
                    "{0}",
                    new Breakdown()
                {
                    Known = tracking.Names.Distinct().Count(),
                    Total = tracking.Hashes.Distinct().Count(),
                });
            }
        }
コード例 #2
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);
            }
        }