Exemplo n.º 1
0
        /// <summary>
        ///     Creates a new patch if the files have been updated
        /// </summary>
        public void CreatePatch()
        {
            if (!Directory.Exists(PatchDir))
            {
                Directory.CreateDirectory(PatchDir);
            }

            var files       = new List <Asset>();
            var fingerprint = Resources.Fingerprint;

            foreach (var dir in Directory.GetDirectories(BaseDir))
            {
                if (dir.Contains("update"))
                {
                    continue;
                }

                var newDir = dir.Replace(BaseDir, TempDir) + "/";

                if (!Directory.Exists(newDir))
                {
                    Directory.CreateDirectory(newDir);
                }

                foreach (var updatedFile in Directory.GetFiles(dir))
                {
                    var data = updatedFile.Contains("sc")
                        ? File.ReadAllBytes(updatedFile)
                        : ServerUtils.CompressData(File.ReadAllBytes(updatedFile)); // only compress csv
                    var name    = Path.GetFileName(updatedFile);
                    var newPath = newDir + name;

                    files.Add(new Asset
                    {
                        File = dir.Split('/').Last() + "/" + name,
                        Sha  = ServerUtils.GetChecksum(data)
                    });

                    File.WriteAllBytes(newPath, data);
                }
            }

            fingerprint.Files = files;
            fingerprint.Version[2]++;

            fingerprint.Sha = ServerUtils.GetChecksum(fingerprint.GetVersion);
            fingerprint.Save();

            Directory.Move(TempDir, PatchDir + fingerprint.Sha);
        }