Read() public method

public Read ( ) : Package
return Package
 public void UncompressPackage(string packagePath, string outputPath, Func <AbstractFileInfo, bool> filter = null)
 {
     ProgressUpdate("Reading package headers ...", 0, 1, null);
     using (var reader = new PackageReader(packagePath))
     {
         Package package = reader.Read();
         UncompressPackage(package, outputPath, filter);
     }
 }
示例#2
0
        private void DiscoverBuiltinPackages(string gameDataPath)
        {
            // List of packages we won't ever load
            // These packages don't contain any mod resources, but have a large
            // file table that makes loading unneccessarily slow.
            HashSet <string> packageBlacklist = new HashSet <string>
            {
                "Assets.pak",
                "Effects.pak",
                "Engine.pak",
                "EngineShaders.pak",
                "Game.pak",
                "GamePlatform.pak",
                "Gustav_Textures.pak",
                "Icons.pak",
                "LowTex.pak",
                "Materials.pak",
                "Minimaps.pak",
                "Models.pak",
                "SharedSoundBanks.pak",
                "SharedSounds.pak",
                "Textures.pak",
                "VirtualTextures.pak"
            };

            // Collect priority value from headers
            var packagePriorities = new List <Tuple <string, int> >();

            foreach (var path in Directory.GetFiles(gameDataPath, "*.pak"))
            {
                var baseName = Path.GetFileName(path);
                if (!packageBlacklist.Contains(baseName)
                    // Don't load 2nd, 3rd, ... parts of a multi-part archive
                    && !archivePartRe.IsMatch(baseName))
                {
                    var reader  = new PackageReader(path, true);
                    var package = reader.Read();
                    packagePriorities.Add(new Tuple <string, int>(path, package.Metadata.Priority));
                }
            }

            packagePriorities.Sort(
                delegate(Tuple <string, int> a, Tuple <string, int> b)
            {
                return(a.Item2.CompareTo(b.Item2));
            }
                );

            // Load non-patch packages first
            foreach (var package in packagePriorities)
            {
                DiscoverPackage(package.Item1);
            }
        }
示例#3
0
        public void DiscoverPackage(string packagePath)
        {
            var reader = new PackageReader(packagePath);

            Resources.LoadedPackages.Add(reader);
            var package = reader.Read();

            foreach (var file in package.Files)
            {
                DiscoverPackagedFile(file);
            }
        }
示例#4
0
        public void UncompressPackage(string packagePath, string outputPath)
        {
            if (outputPath.Length > 0 && !outputPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
            {
                outputPath += Path.DirectorySeparatorChar;
            }

            ProgressUpdate("Reading package headers ...", 0, 1, null);
            var     reader  = new PackageReader(packagePath);
            Package package = reader.Read();

            long totalSize   = package.Files.Sum(p => (long)p.Size());
            long currentSize = 0;

            var buffer = new byte[32768];

            foreach (AbstractFileInfo file in package.Files)
            {
                ProgressUpdate(file.Name, currentSize, totalSize, file);
                currentSize += file.Size();

                string outPath = outputPath + file.Name;

                FileManager.TryToCreateDirectory(outPath);

                Stream inStream = file.MakeStream();

                try
                {
                    using (var inReader = new BinaryReader(inStream))
                    {
                        using (var outFile = File.Open(outPath, FileMode.Create, FileAccess.Write))
                        {
                            int read;
                            while ((read = inReader.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                outFile.Write(buffer, 0, read);
                            }
                        }
                    }
                }
                finally
                {
                    file.ReleaseStream();
                }
            }

            reader.Dispose();
        }
示例#5
0
        public void UncompressPackage(string packagePath, string outputPath)
        {
            if (outputPath.Length > 0 && outputPath.Last() != '/' && outputPath.Last() != '\\')
            {
                outputPath += "/";
            }

            this.progressUpdate("Reading package headers ...", 0, 1);
            var reader  = new PackageReader(packagePath);
            var package = reader.Read();

            long totalSize   = package.Files.Sum(p => (long)p.Size());
            long currentSize = 0;

            foreach (var file in package.Files)
            {
                this.progressUpdate(file.Name, currentSize, totalSize);
                currentSize += file.Size();

                var outPath = outputPath + file.Name;
                var dirName = Path.GetDirectoryName(outPath);
                if (!Directory.Exists(dirName))
                {
                    Directory.CreateDirectory(dirName);
                }

                var inReader = file.MakeReader();
                var outFile  = new FileStream(outPath, FileMode.Create, FileAccess.Write);

                if (inReader != null)
                {
                    byte[] buffer = new byte[32768];
                    int    read;
                    while ((read = inReader.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        outFile.Write(buffer, 0, read);
                    }

                    inReader.Dispose();
                }

                outFile.Dispose();
            }

            reader.Dispose();
        }
示例#6
0
        public void UncompressPackage(string packagePath, string outputPath)
        {
            if (outputPath.Length > 0 && outputPath.Last() != '/' && outputPath.Last() != '\\')
                outputPath += "/";

            this.progressUpdate("Reading package headers ...", 0, 1);
            var reader = new PackageReader(packagePath);
            var package = reader.Read();

            long totalSize = package.Files.Sum(p => (long)p.Size());
            long currentSize = 0;

            foreach (var file in package.Files)
            {
                this.progressUpdate(file.Name, currentSize, totalSize);
                currentSize += file.Size();

                var outPath = outputPath + file.Name;
                var dirName = Path.GetDirectoryName(outPath);
                if (!Directory.Exists(dirName))
                {
                    Directory.CreateDirectory(dirName);
                }

                var inReader = file.MakeReader();
                var outFile = new FileStream(outPath, FileMode.Create, FileAccess.Write);

                if (inReader != null)
                {
                    byte[] buffer = new byte[32768];
                    int read;
                    while ((read = inReader.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        outFile.Write(buffer, 0, read);
                    }

                    inReader.Dispose();
                }

                outFile.Dispose();
            }

            reader.Dispose();
        }