The Free Software Media System - Server Backend & API
Merge branch 'master' into locale
Bond-0092a1f6361a5fe
diff --cc Emby.Server.Implementations/Localization/LocalizationManager.csindex 682fbb6aa7,7af8cf18cc..3a70525954--- a/Emby.Server.Implementations/Localization/LocalizationManager.cs+++ b/Emby.Server.Implementations/Localization/LocalizationManager.cs@@@ -56,21 -57,31 +56,21 @@@ namespace Emby.Server.Implementations.L_fileSystem = fileSystem;_jsonSerializer = jsonSerializer;_logger = loggerFactory.CreateLogger(nameof(LocalizationManager));- _assemblyInfo = assemblyInfo;- _textLocalizer = textLocalizer;-- ExtractAll();}- private void ExtractAll()+ public async Task LoadAll(){- var type = GetType();- var resourcePath = type.Namespace + ".Ratings.";-- var localizationPath = LocalizationPath;+ const string ratingsResource = "Emby.Server.Implementations.Ratings.";- Directory.CreateDirectory(LocalizationPath);+ Directory.CreateDirectory(localizationPath);- var existingFiles = GetRatingsFiles(localizationPath)- .Select(Path.GetFileName)- .ToList();+ var existingFiles = GetRatingsFiles(LocalizationPath).Select(Path.GetFileName);// Extract from the assembly- foreach (var resource in _assemblyInfo- .GetManifestResourceNames(type)- .Where(i => i.StartsWith(resourcePath)))+ foreach (var resource in _assembly.GetManifestResourceNames()+ .Where(i => i.StartsWith(ratingsResource))){- var filename = "ratings-" + resource.Substring(resourcePath.Length);+ string filename = "ratings-" + resource.Substring(ratingsResource.Length);if (!existingFiles.Contains(filename)){@@@ -289,33 -314,32 +289,34 @@@/// </summary>/// <param name="file">The file.</param>/// <returns>Dictionary{System.StringParentalRating}.</returns>- private void LoadRatings(string file)+ private async Task LoadRatings(string file){- var dict = File.ReadAllLines(file).Select(i =>+ Dictionary<string, ParentalRating> dict = new Dictionary<string, ParentalRating>(StringComparer.OrdinalIgnoreCase);+++ using (var str = File.OpenRead(file))+ using (var reader = new StreamReader(str)){- if (!string.IsNullOrWhiteSpace(i))+ string line;+ while ((line = await reader.ReadLineAsync()) != null){- var parts = i.Split(',');+ if (string.IsNullOrWhiteSpace(line))+ {+ continue;+ }- if (parts.Length == 2)+ string[] parts = line.Split(',');+ if (parts.Length == 2+ && int.TryParse(parts[1], NumberStyles.Integer, UsCulture, out var value)){- if (int.TryParse(parts[1], NumberStyles.Integer, UsCulture, out var value))- {- return new ParentalRating { Name = parts[0], Value = value };- }+ dict.Add(parts[0], (new ParentalRating { Name = parts[0], Value = value }));}+#if DEBUG+ _logger.LogWarning("Misformed line in {Path}", file);+#endif}+ }- return null;-- })- .Where(i => i != null)- .ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase);-- var countryCode = Path.GetFileNameWithoutExtension(file)- .Split('-')- .Last();+ var countryCode = Path.GetFileNameWithoutExtension(file).Split('-')[1];_allParentalRatings[countryCode] = dict;}