Esempio n. 1
0
        static void Main(string[] args)
        {
            if (args.Count() < 2)
            {
                PrintUsage();
                return;
            }

            var vpkDirFileName = args.First();
            var filesToExtract = args.Skip(1);

            if (filesToExtract.FirstOrDefault() == "-l")
            {
                if (args.Count() != 3)
                {
                    PrintUsage();
                    return;
                }

                var files = new List<string>();
                using (var listReader = File.OpenText(args[2]))
                {
                    string line;
                    while ((line = listReader.ReadLine()) != null)
                    {
                        if (!string.IsNullOrWhiteSpace(line))
                        {
                            files.Add(line);
                        }
                    }
                }

                filesToExtract = files.AsEnumerable();
            }

            using (var vpk = new VpkFile(vpkDirFileName))
            {
                vpk.Open();
                Console.WriteLine("Got VPK version {0}", vpk.Version);

                foreach (var fileToExtract in filesToExtract)
                {
                    var fileNode = vpk.GetFile(fileToExtract);
                    if (fileNode == null)
                    {
                        var dirContents = vpk.GetAllFilesInDirectoryAndSubdirectories(fileToExtract);
                        if (dirContents.Count() == 0)
                        {
                            Console.WriteLine("Entry not found: {0}", fileToExtract);
                        }
                        else
                        {
                            foreach (var node in dirContents)
                            {
                                DoExtractFile(vpkDirFileName, node);
                            }
                        }
                    }
                    else
                    {
                        DoExtractFile(vpkDirFileName, fileNode);
                    }
                }
            }
        }
Esempio n. 2
0
        static void Main2(string[] args)
        {
            if (args.Count() < 2)
            {
                PrintUsage();
                return;
            }

            var vpkDirFileName = args.First();
            var filesToExtract = args.Skip(1);

            // third param here is path to a text file full of file paths.
            if (filesToExtract.FirstOrDefault() == "-l")
            {
                if (args.Count() != 3)
                {
                    PrintUsage();
                    return;
                }

                var files = new List <string>();
                using (var listReader = File.OpenText(args[2]))
                {
                    string line;
                    while ((line = listReader.ReadLine()) != null)
                    {
                        if (!string.IsNullOrWhiteSpace(line))
                        {
                            files.Add(line);
                        }
                    }
                }

                filesToExtract = files.AsEnumerable();
            }

            using (var vpk = new VpkFile(vpkDirFileName))
            {
                vpk.Open();
                Console.WriteLine("Got VPK version {0}", vpk.Version);

                foreach (var fileToExtract in filesToExtract)
                {
                    var fileNode = vpk.GetFile(fileToExtract);
                    if (fileNode == null)
                    {
                        var dirContents = vpk.GetAllFilesInDirectoryAndSubdirectories(fileToExtract);
                        if (dirContents.Count() == 0)
                        {
                            Console.WriteLine("Entry not found: {0}", fileToExtract);
                        }
                        else
                        {
                            foreach (var node in dirContents)
                            {
                                DoExtractFile(vpkDirFileName, node);
                            }
                        }
                    }
                    else
                    {
                        DoExtractFile(vpkDirFileName, fileNode);
                    }
                }
            }
        }