/// <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) : CompressionUtils.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); }
public async Task <bool> HasFileChanged() { var path = Path.Combine(UpdateManager.BaseDir, File); if (!System.IO.File.Exists(path)) { return(false); } var expression = Path.GetExtension(File).Replace(".", string.Empty); switch (expression) { case "csv": { var rawData = await System.IO.File.ReadAllBytesAsync(path); var compressedData = CompressionUtils.CompressData(rawData); var sha = ServerUtils.GetChecksum(compressedData); return(sha != Sha); } case "sc": { var compressedData = await System.IO.File.ReadAllBytesAsync(path); var sha = ServerUtils.GetChecksum(compressedData); return(sha != Sha); } default: { Logger.Log($"Unknown file expression {expression}", GetType(), ErrorLevel.Warning); break; } } return(false); }
/// <summary> /// Creates a new patch if the files have been updated /// </summary> public async Task CreatePatch() { if (!Directory.Exists(PatchDir)) { Directory.CreateDirectory(PatchDir); } var fingerprint = Resources.Fingerprint; foreach (var asset in fingerprint.Files) { var path = Path.Combine(BaseDir, asset.File); if (!File.Exists(path)) { return; } var expression = Path.GetExtension(asset.File).Replace(".", string.Empty); var newPath = Path.Combine(TempDir, asset.File); var newDir = Path.GetDirectoryName(newPath); if (!Directory.Exists(newDir)) { Directory.CreateDirectory(newDir); } switch (expression) { case "csv": { var rawData = await File.ReadAllBytesAsync(path); var compressedData = CompressionUtils.CompressData(rawData); var sha = ServerUtils.GetChecksum(compressedData); asset.Sha = sha; await File.WriteAllBytesAsync(newPath, compressedData); break; } case "sc": { var compressedData = await File.ReadAllBytesAsync(path); var sha = ServerUtils.GetChecksum(compressedData); asset.Sha = sha; await File.WriteAllBytesAsync(newPath, compressedData); break; } default: { Logger.Log($"Unknown file expression {expression}", GetType(), ErrorLevel.Warning); break; } } } fingerprint.Version[2]++; fingerprint.Sha = ServerUtils.GetChecksum(fingerprint.GetVersion); fingerprint.Save(); Directory.Move(TempDir, Path.Combine(PatchDir, fingerprint.Sha)); File.Copy(Path.Combine(BaseDir, "fingerprint.json"), Path.Combine(PatchDir, fingerprint.Sha, "fingerprint.json"), true); }