示例#1
0
    public static void BuildVersions(string outputPath, string[] bundles, int version)
    {
        var path = outputPath + "/" + Filename;

        if (File.Exists(path))
        {
            File.Delete(path);
        }

        var dataPath = outputPath + "/" + Dataname;

        if (File.Exists(dataPath))
        {
            File.Delete(dataPath);
        }

        var disk = new VDisk();

        foreach (var file in bundles)
        {
            using (var fs = File.OpenRead(outputPath + "/" + file))
            {
                disk.AddFile(file, fs.Length, Utility.GetCRC32Hash(fs));
            }
        }

        disk.name = dataPath;
        disk.Save();

        using (var stream = File.OpenWrite(path))
        {
            var writer = new BinaryWriter(stream);
            writer.Write(version);
            writer.Write(disk.files.Count + 1);
            using (var fs = File.OpenRead(dataPath))
            {
                var file = new VFile {
                    name = Dataname, len = fs.Length, hash = Utility.GetCRC32Hash(fs)
                };
                file.Serialize(writer);
            }
            foreach (var file in disk.files)
            {
                file.Serialize(writer);
            }
        }
    }