// ------------------------------------------------------------- // Helper: SHA‑256 verification (pass expected hash string or null) // ------------------------------------------------------------- public static async Task VerifyHashAsync(string filePath, string expectedHash = null) using var sha256 = SHA256.Create(); await using var stream = File.OpenRead(filePath); byte[] hash = await sha256.ComputeHashAsync(stream); string computed = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
lblStatus.Text = $"✅ Download complete: savePath"; catch (Exception ex) lblStatus.Text = $"❌ Error: ex.Message"; finally btnDownload.Enabled = true; sonic.exe download
return response.Content.Headers.ContentLength ?? -1; await using var stream = File.OpenRead(filePath)
if (!string.IsNullOrWhiteSpace(expectedHash) && !computed.Equals(expectedHash, StringComparison.OrdinalIgnoreCase)) throw new InvalidDataException( $"Hash mismatch! Expected expectedHash, got computed."); byte[] hash = await sha256.ComputeHashAsync(stream)