2
0
Эх сурвалжийг харах

Backport pull request #12550 from jellyfin/release-10.9.z

Create and use FormattingStreamWriter

Original-merge: cd2f2ca17800f71c8d94a6e043b49b7c4200e254

Merged-by: Bond-009 <bond.009@outlook.com>

Backported-by: Joshua M. Boniface <joshua@boniface.me>
Bond-009 8 сар өмнө
parent
commit
7631956451

+ 1 - 4
MediaBrowser.Controller/Entities/TV/Episode.cs

@@ -180,10 +180,7 @@ namespace MediaBrowser.Controller.Entities.TV
         }
 
         public string FindSeriesPresentationUniqueKey()
-        {
-            var series = Series;
-            return series is null ? null : series.PresentationUniqueKey;
-        }
+            => Series?.PresentationUniqueKey;
 
         public string FindSeasonName()
         {

+ 0 - 2
MediaBrowser.Controller/Entities/UserViewBuilder.cs

@@ -430,8 +430,6 @@ namespace MediaBrowser.Controller.Entities
             InternalItemsQuery query,
             ILibraryManager libraryManager)
         {
-            var user = query.User;
-
             // This must be the last filter
             if (!query.AdjacentTo.IsNullOrEmpty())
             {

+ 1 - 1
MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs

@@ -1206,7 +1206,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
 
             // Generate concat configuration entries for each file and write to file
             Directory.CreateDirectory(Path.GetDirectoryName(concatFilePath));
-            using StreamWriter sw = new StreamWriter(concatFilePath);
+            using StreamWriter sw = new FormattingStreamWriter(concatFilePath, CultureInfo.InvariantCulture);
             foreach (var path in files)
             {
                 var mediaInfoResult = GetMediaInfo(

+ 38 - 0
src/Jellyfin.Extensions/FormattingStreamWriter.cs

@@ -0,0 +1,38 @@
+using System;
+using System.IO;
+
+namespace Jellyfin.Extensions;
+
+/// <summary>
+/// A custom StreamWriter which supports setting a IFormatProvider.
+/// </summary>
+public class FormattingStreamWriter : StreamWriter
+{
+    private readonly IFormatProvider _formatProvider;
+
+    /// <summary>
+    /// Initializes a new instance of the <see cref="FormattingStreamWriter"/> class.
+    /// </summary>
+    /// <param name="stream">The stream to write to.</param>
+    /// <param name="formatProvider">The format provider to use.</param>
+    public FormattingStreamWriter(Stream stream, IFormatProvider formatProvider)
+        : base(stream)
+    {
+        _formatProvider = formatProvider;
+    }
+
+    /// <summary>
+    /// Initializes a new instance of the <see cref="FormattingStreamWriter"/> class.
+    /// </summary>
+    /// <param name="path">The complete file path to write to.</param>
+    /// <param name="formatProvider">The format provider to use.</param>
+    public FormattingStreamWriter(string path, IFormatProvider formatProvider)
+        : base(path)
+    {
+        _formatProvider = formatProvider;
+    }
+
+    /// <inheritdoc />
+    public override IFormatProvider FormatProvider
+        => _formatProvider;
+}

+ 23 - 0
tests/Jellyfin.Extensions.Tests/FormattingStreamWriterTests.cs

@@ -0,0 +1,23 @@
+using System.Globalization;
+using System.IO;
+using System.Text;
+using System.Threading;
+using Xunit;
+
+namespace Jellyfin.Extensions.Tests;
+
+public static class FormattingStreamWriterTests
+{
+    [Fact]
+    public static void Shuffle_Valid_Correct()
+    {
+        Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE", false);
+        using (var ms = new MemoryStream())
+        using (var txt = new FormattingStreamWriter(ms, CultureInfo.InvariantCulture))
+        {
+            txt.Write("{0}", 3.14159);
+            txt.Close();
+            Assert.Equal("3.14159", Encoding.UTF8.GetString(ms.ToArray()));
+        }
+    }
+}