private static void ComputeAndWriteChecksum(CanvasDocument app, ChecksumMaker checksum, ZipArchive z, ErrorContainer errors, bool isValidation) { var hash = checksum.GetChecksum(); if (app._checksum != null && hash.wholeChecksum != app._checksum.ClientStampedChecksum) { // These warnings are Debug only. Throwing a bunch of warning messages at the customer could lead to them ignoring real errors. #if DEBUG if (app._checksum.ClientPerFileChecksums != null) { foreach (var file in app._checksum.ClientPerFileChecksums) { if (!hash.perFileChecksum.TryGetValue(file.Key, out var fileChecksum)) { errors.ChecksumMismatch("Missing file " + file.Key); } else if (fileChecksum != file.Value) { errors.ChecksumMismatch($"File {file.Key} checksum does not match on extract"); } } foreach (var file in hash.perFileChecksum) { if (!app._checksum.ClientPerFileChecksums.ContainsKey(file.Key)) { errors.ChecksumMismatch("Extra file " + file.Key); } } } #endif #if !DEBUG // These are the non-debug warnings, if it's unpack this was a serious error, on -pack it's most likely not if (isValidation) { errors.PostUnpackValidationFailed(); throw new DocumentException(); } #endif errors.ChecksumMismatch("Checksum indicates that sources have been edited since they were unpacked. If this was intentional, ignore this warning."); } var checksumJson = new ChecksumJson { ClientStampedChecksum = hash.wholeChecksum, ClientPerFileChecksums = hash.perFileChecksum, ServerStampedChecksum = app._checksum?.ServerStampedChecksum, ServerPerFileChecksums = app._checksum?.ServerPerFileChecksums, }; var entry = ToFile(FileKind.Checksum, checksumJson); var e = z.CreateEntry(entry.Name.ToMsAppPath()); using (var dest = e.Open()) { dest.Write(entry.RawBytes, 0, entry.RawBytes.Length); } }
internal CanvasDocument(CanvasDocument other) { foreach (var kvp in other._unknownFiles) { _unknownFiles.Add(kvp.Key, new FileEntry(kvp.Value)); } foreach (var kvp in other._assetFiles) { _assetFiles.Add(kvp.Key, new FileEntry(kvp.Value)); } foreach (var kvp in other._screens) { _screens.Add(kvp.Key, kvp.Value.Clone()); } foreach (var kvp in other._components) { _components.Add(kvp.Key, kvp.Value.Clone()); } _editorStateStore = new EditorStateStore(other._editorStateStore); _templateStore = new TemplateStore(other._templateStore); _dataSources = other._dataSources.JsonClone(); _screenOrder = new List <string>(other._screenOrder); _header = other._header.JsonClone(); _properties = other._properties.JsonClone(); _parameterSchema = other._parameterSchema.JsonClone(); _publishInfo = other._publishInfo.JsonClone(); _templates = other._templates.JsonClone(); _themes = other._themes.JsonClone(); _resourcesJson = other._resourcesJson.JsonClone(); _appCheckerResultJson = other._appCheckerResultJson.JsonClone(); _pcfControls = other._pcfControls.JsonClone(); _appInsights = other._appInsights.JsonClone(); _connections = other._connections.JsonClone(); _dataSourceReferences = other._dataSourceReferences.JsonClone(); _libraryReferences = other._libraryReferences.JsonClone(); _logoFile = other._logoFile != null ? new FileEntry(other._logoFile) : null; _entropy = other._entropy.JsonClone(); _checksum = other._checksum.JsonClone(); this._idRestorer = new UniqueIdRestorer(this._entropy); _localAssetInfoJson = other._localAssetInfoJson.JsonClone(); }
private static void ComputeAndWriteChecksum(CanvasDocument app, ChecksumMaker checksum, ZipArchive z, ErrorContainer errors) { var hash = checksum.GetChecksum(); if (hash.wholeChecksum != app._checksum.ClientStampedChecksum) { if (app._checksum.ClientPerFileChecksums != null) { // We had offline edits! errors.ChecksumMismatch("Sources have changed since when they were unpacked."); foreach (var file in app._checksum.ClientPerFileChecksums) { if (!hash.perFileChecksum.TryGetValue(file.Key, out var fileChecksum)) { errors.ChecksumMismatch("Missing file " + file.Key); } if (fileChecksum != file.Value) { errors.ChecksumMismatch($"File {file.Key} checksum does not match on extract"); } } foreach (var file in hash.perFileChecksum) { if (!app._checksum.ClientPerFileChecksums.ContainsKey(file.Key)) { errors.ChecksumMismatch("Extra file " + file.Key); } } } } var checksumJson = new ChecksumJson { ClientStampedChecksum = hash.wholeChecksum, ClientPerFileChecksums = hash.perFileChecksum, ServerStampedChecksum = app._checksum.ServerStampedChecksum, ServerPerFileChecksums = app._checksum.ServerPerFileChecksums, }; var entry = ToFile(FileKind.Checksum, checksumJson); var e = z.CreateEntry(entry.Name); using (var dest = e.Open()) { dest.Write(entry.RawBytes, 0, entry.RawBytes.Length); } }