internal bool VerifyFileWithArtifactHash()

in src/Sarif.Viewer.VisualStudio.Core/CodeAnalysisResultManager.cs [990:1039]


        internal bool VerifyFileWithArtifactHash(SarifErrorListItem sarifErrorListItem, string pathFromLogFile, RunDataCache dataCache, string resolvedPath, string embeddedTempFilePath, out string newResolvedPath)
        {
            newResolvedPath = null;

            if (string.IsNullOrEmpty(resolvedPath))
            {
                // cannot find corresponding file in local, then use embedded file
                newResolvedPath = embeddedTempFilePath;
                return true;
            }

            if (!dataCache.FileDetails.TryGetValue(pathFromLogFile, out ArtifactDetailsModel fileData))
            {
                // has no embedded file, return the path resolved till now
                newResolvedPath = resolvedPath;
                return true;
            }

            string fileHash = this.GetFileHash(this._fileSystem, resolvedPath);

            if (fileHash.Equals(fileData.Sha256Hash, StringComparison.OrdinalIgnoreCase))
            {
                // found a file in file system which has same hashcode as embeded content.
                newResolvedPath = resolvedPath;
                return true;
            }

            bool hasEmbeddedContent = !string.IsNullOrEmpty(embeddedTempFilePath);
            ResolveEmbeddedFileDialogResult dialogResult = this._promptForEmbeddedFileDelegate(sarifErrorListItem.LogFilePath, hasEmbeddedContent, this.userDialogPreference);

            switch (dialogResult)
            {
                case ResolveEmbeddedFileDialogResult.None:
                    // dialog is cancelled.
                    newResolvedPath = null;
                    return false;
                case ResolveEmbeddedFileDialogResult.OpenEmbeddedFileContent:
                    newResolvedPath = embeddedTempFilePath;
                    return true;
                case ResolveEmbeddedFileDialogResult.OpenLocalFileFromSolution:
                    newResolvedPath = resolvedPath;
                    return true;
                case ResolveEmbeddedFileDialogResult.BrowseAlternateLocation:
                    // if returns null means user cancelled the open file dialog.
                    newResolvedPath = this._promptForResolvedPathDelegate(sarifErrorListItem, pathFromLogFile);
                    return !string.IsNullOrEmpty(newResolvedPath);
                default:
                    return false;
            }
        }