From ae5514afd62b8f0d4dd73bb9109961292f4dbd59 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Mon, 4 Feb 2019 18:46:36 +0100 Subject: [PATCH] Fix loading of rating files --- .../Emby.Server.Implementations.csproj | 2 +- .../Localization/LocalizationManager.cs | 38 ++++++++++++------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/Emby.Server.Implementations/Emby.Server.Implementations.csproj b/Emby.Server.Implementations/Emby.Server.Implementations.csproj index 92e3172f1..af01001a5 100644 --- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj +++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj @@ -43,7 +43,7 @@ - + diff --git a/Emby.Server.Implementations/Localization/LocalizationManager.cs b/Emby.Server.Implementations/Localization/LocalizationManager.cs index 262ca24ec..8651a7dad 100644 --- a/Emby.Server.Implementations/Localization/LocalizationManager.cs +++ b/Emby.Server.Implementations/Localization/LocalizationManager.cs @@ -60,29 +60,35 @@ namespace Emby.Server.Implementations.Localization public async Task LoadAll() { - const string ratingsResource = "Emby.Server.Implementations.Ratings."; + const string ratingsResource = "Emby.Server.Implementations.Localization.Ratings."; Directory.CreateDirectory(LocalizationPath); var existingFiles = GetRatingsFiles(LocalizationPath).Select(Path.GetFileName); // Extract from the assembly - foreach (var resource in _assembly.GetManifestResourceNames() - .Where(i => i.StartsWith(ratingsResource))) + foreach (var resource in _assembly.GetManifestResourceNames()) { + if (!resource.StartsWith(ratingsResource)) + { + continue; + } + string filename = "ratings-" + resource.Substring(ratingsResource.Length); - if (!existingFiles.Contains(filename)) + if (existingFiles.Contains(filename)) { - using (var stream = _assembly.GetManifestResourceStream(resource)) - { - string target = Path.Combine(LocalizationPath, filename); - _logger.LogInformation("Extracting ratings to {0}", target); + continue; + } - using (var fs = _fileSystem.GetFileStream(target, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read)) - { - await stream.CopyToAsync(fs); - } + using (var stream = _assembly.GetManifestResourceStream(resource)) + { + string target = Path.Combine(LocalizationPath, filename); + _logger.LogInformation("Extracting ratings to {0}", target); + + using (var fs = _fileSystem.GetFileStream(target, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read)) + { + await stream.CopyToAsync(fs); } } } @@ -289,7 +295,8 @@ namespace Emby.Server.Implementations.Localization /// Dictionary{System.StringParentalRating}. private async Task LoadRatings(string file) { - Dictionary dict = new Dictionary(StringComparer.OrdinalIgnoreCase); + Dictionary dict + = new Dictionary(StringComparer.OrdinalIgnoreCase); using (var str = File.OpenRead(file)) using (var reader = new StreamReader(str)) @@ -309,7 +316,10 @@ namespace Emby.Server.Implementations.Localization dict.Add(parts[0], (new ParentalRating { Name = parts[0], Value = value })); } #if DEBUG - _logger.LogWarning("Misformed line in {Path}", file); + else + { + _logger.LogWarning("Misformed line in {Path}", file); + } #endif } }