Skip to content

Commit

Permalink
Merge branch 'fix-metagen-localization' of https://github.com/chacha2…
Browse files Browse the repository at this point in the history
…1/Open-XML-SDK into fix-metagen-localization
  • Loading branch information
chacha21 committed Mar 7, 2024
2 parents dd3b0d8 + 856200b commit 8d773ce
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: dotnet test --no-restore --verbosity normal --collect:"XPlat Code Coverage" --results-directory coverage

- name: ReportGenerator
uses: danielpalme/[email protected].0
uses: danielpalme/[email protected].2
with:
reports: coverage/**/coverage.cobertura.xml
targetdir: coveragereport
Expand Down
8 changes: 8 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,12 @@
<IsBenchmarkProject Condition=" '$(IsBenchmarkProject)' == '' ">false</IsBenchmarkProject>
</PropertyGroup>

<PropertyGroup>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

</Project>
12 changes: 6 additions & 6 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.13.12" />
<PackageVersion Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.13.11" />
<PackageVersion Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.13.12" />
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis" Version="4.8.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
Expand All @@ -14,10 +14,10 @@
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="NSubstitute" Version="5.1.0" />
<PackageVersion Include="NuGet.Common" Version="6.8.0" />
<PackageVersion Include="NuGet.Packaging" Version="6.8.0" />
<PackageVersion Include="NuGet.Packaging.Core" Version="6.8.0" />
<PackageVersion Include="NuGet.Protocol" Version="6.8.0" />
<PackageVersion Include="NuGet.Common" Version="6.9.1" />
<PackageVersion Include="NuGet.Packaging" Version="6.9.1" />
<PackageVersion Include="NuGet.Packaging.Core" Version="6.9.1" />
<PackageVersion Include="NuGet.Protocol" Version="6.9.1" />
<PackageVersion Include="NuGet.Resolver" Version="6.8.0" />
<PackageVersion Include="ObjectLayoutInspector" Version="0.1.4" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
Expand All @@ -29,7 +29,7 @@
<PackageVersion Include="System.Security.Cryptography.Algorithms" Version="4.3.1" />
<PackageVersion Include="System.Xml.ReaderWriter" Version="4.3.1" />
<PackageVersion Include="System.ValueTuple" Version="4.5.0" />
<PackageVersion Include="xunit" Version="2.6.4" />
<PackageVersion Include="xunit" Version="2.7.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.4" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,37 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using DocumentFormat.OpenXml.Features;
using System;
using System.IO;

namespace DocumentFormat.OpenXml.Packaging;

internal static class WriteableStreamExtensions
{
private const int DefaultBufferSize = 4096;

/// <summary>
/// Attempts to replace the underlying stream so that we can modify it even in readonly situations via a copy
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "Disposable is registered with package")]
public static bool EnableWriteableStream(this IFeatureCollection features)
{
if (features.Get<IPackageStreamFeature>() is { Stream: { CanWrite: false, CanSeek: true } } feature &&
features.Get<IPackageFeature>() is { } packageFeature &&
packageFeature.Capabilities.HasFlagFast(PackageCapabilities.Reload))
{
var tempStream = new TemporaryFile();
var tempStream = new FileStream(Path.GetTempFileName(), FileMode.Create, FileAccess.ReadWrite, FileShare.None, DefaultBufferSize, FileOptions.DeleteOnClose);

feature.Stream.Position = 0;
feature.Stream.CopyTo(tempStream.Stream);
feature.Stream.CopyTo(tempStream);

tempStream.Position = 0;

tempStream.Stream.Position = 0;
feature.Stream = tempStream.Stream;
// IPackageStreamFeature will take ownership of the stream it is supplied. Since it has DeleteOnClose, it will be deleted
// when the package is closed.
feature.Stream = tempStream;

return true;
}

return false;
}

private sealed class TemporaryFile : IDisposable
{
private readonly string _path;

public TemporaryFile()
{
_path = Path.GetTempFileName();
Stream = File.Create(_path);
}

public Stream Stream { get; }

public void Dispose()
{
Stream.Dispose();
File.Delete(_path);
}
}
}

0 comments on commit 8d773ce

Please sign in to comment.