Esempio n. 1
2
 static void DoExtractFile(string vpkDirFileName, VpkNode node)
 {
     if (node.ArchiveIndex == VpkNode.DirectoryArchiveIndex)
     {
         Console.WriteLine("Found entry: {0}", node.FilePath);
     }
     else
     {
         Console.WriteLine("Found entry: {0} in VPK {1}", node.FilePath, node.ArchiveIndex);
     }
     ExtractFile(vpkDirFileName, node);
 }
Esempio n. 2
0
 static void DoExtractFile(string vpkDirFileName, VpkNode node)
 {
     if (node.ArchiveIndex == VpkNode.DirectoryArchiveIndex)
     {
         Console.WriteLine("Found entry: {0}", node.FilePath);
     }
     else
     {
         Console.WriteLine("Found entry: {0} in VPK {1}", node.FilePath, node.ArchiveIndex);
     }
     ExtractFile(vpkDirFileName, node);
 }
Esempio n. 3
0
		public static Stream GetInputStream(string vpkDirFileName, VpkNode node) {
			if (node.EntryLength == 0 && node.PreloadBytes > 0) {
				return new MemoryStream(node.PreloadData);
			} else if (node.PreloadBytes == 0) {
				var prefix = new string(Enumerable.Repeat('0', 3 - node.ArchiveIndex.ToString().Length).ToArray());
				var dataPakFilename = vpkDirFileName.Replace("_dir.vpk", "_" + prefix + node.ArchiveIndex + ".vpk");

				var fsin = new FileStream(dataPakFilename, FileMode.Open);
				fsin.Seek(node.EntryOffset, SeekOrigin.Begin);
				return fsin;
			} else {
				throw new NotSupportedException("Unable to get entry data: Both EntryLength and PreloadBytes specified.");
			}
		}
Esempio n. 4
0
		static VpkNode[] LoadNodeChildren(BinaryReader reader, VpkNode parent)
		{
			var nodes = new List<VpkNode>();

			VpkNode newNode = null;
			while (newNode == null || !string.IsNullOrEmpty(newNode.Name))
			{
				newNode = new VpkNode(parent);
				newNode.Load(reader);
				if (!string.IsNullOrEmpty(newNode.Name))
				{
					nodes.Add(newNode);
					newNode.Children = LoadNodeFileChildren(reader, newNode);
				}
			}

			return nodes.ToArray();
		}
Esempio n. 5
0
		static List<VpkNode> LoadRootNodes(BinaryReader reader)
		{
			var nodes = new List<VpkNode>();

			VpkNode newNode = null;
			while (newNode == null || !string.IsNullOrEmpty(newNode.Name))
			{
				newNode = new VpkNode();
				newNode.Load(reader);
				if (!string.IsNullOrEmpty(newNode.Name))
				{
					nodes.Add(newNode);
					newNode.Children = LoadNodeChildren(reader, newNode);
				}
			}

			return nodes;
		}
Esempio n. 6
0
        static VpkNode[] LoadNodeFileChildren(BinaryReader reader, VpkNode parent)
        {
            var nodes = new List <VpkNode>();

            VpkNode newNode = null;

            while (newNode == null || !string.IsNullOrEmpty(newNode.Name))
            {
                newNode = new VpkNode(parent);
                newNode.LoadFileInfo(reader);
                if (!string.IsNullOrEmpty(newNode.Name))
                {
                    nodes.Add(newNode);
                }
            }

            return(nodes.ToArray());
        }
Esempio n. 7
0
        static List <VpkNode> LoadRootNodes(BinaryReader reader)
        {
            var nodes = new List <VpkNode>();

            VpkNode newNode = null;

            while (newNode == null || !string.IsNullOrEmpty(newNode.Name))
            {
                newNode = new VpkNode();
                newNode.Load(reader);
                if (!string.IsNullOrEmpty(newNode.Name))
                {
                    nodes.Add(newNode);
                    newNode.Children = LoadNodeChildren(reader, newNode);
                }
            }

            return(nodes);
        }
Esempio n. 8
0
        public static Stream GetInputStream(string vpkDirFileName, VpkNode node)
        {
            if (node.EntryLength == 0 && node.PreloadBytes > 0)
            {
                return(new MemoryStream(node.PreloadData));
            }
            else if (node.PreloadBytes == 0)
            {
                var prefix          = new string(Enumerable.Repeat('0', 3 - node.ArchiveIndex.ToString().Length).ToArray());
                var dataPakFilename = vpkDirFileName.Replace("_dir.vpk", "_" + prefix + node.ArchiveIndex + ".vpk");

                var fsin = new FileStream(dataPakFilename, FileMode.Open);
                fsin.Seek(node.EntryOffset, SeekOrigin.Begin);
                return(fsin);
            }
            else
            {
                throw new NotSupportedException("Unable to get entry data: Both EntryLength and PreloadBytes specified.");
            }
        }
Esempio n. 9
0
        static void ExtractFile(string vpkDirFileName, VpkNode node)
        {
            using (var inputStream = GetInputStream(vpkDirFileName, node))
            {
                var pathPieces = node.FilePath.Split('/');
                var directory = pathPieces.Take(pathPieces.Count() - 1);
                var fileName = pathPieces.Last();

                EnsureDirectoryExists(Path.Combine(directory.ToArray()));

                using (var fsout = File.OpenWrite(Path.Combine(pathPieces)))
                {
                    var buffer = new byte[1024];
                    int amtToRead = (int)node.EntryLength;
                    int read;

                    while ((read = inputStream.Read(buffer, 0, buffer.Length)) > 0 && amtToRead > 0)
                    {
                        fsout.Write(buffer, 0, Math.Min(amtToRead, read));
                        amtToRead -= read;
                    }
                }
            }
        }
Esempio n. 10
0
        static void ExtractFile(string vpkDirFileName, VpkNode node)
        {
            using (var inputStream = GetInputStream(vpkDirFileName, node))
            {
                var pathPieces = node.FilePath.Split('/');
                var directory  = pathPieces.Take(pathPieces.Count() - 1);
                var fileName   = pathPieces.Last();

                EnsureDirectoryExists(Path.Combine(directory.ToArray()));

                using (var fsout = File.OpenWrite(Path.Combine(pathPieces)))
                {
                    var buffer    = new byte[1024];
                    int amtToRead = (int)node.EntryLength;
                    int read;

                    while ((read = inputStream.Read(buffer, 0, buffer.Length)) > 0 && amtToRead > 0)
                    {
                        fsout.Write(buffer, 0, Math.Min(amtToRead, read));
                        amtToRead -= read;
                    }
                }
            }
        }
Esempio n. 11
0
		public VpkNode(VpkNode parent)
		{
			this.parent = parent;
		}
Esempio n. 12
0
 public VpkNode(VpkNode parent)
 {
     this.parent = parent;
 }