LanguageModel.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System; 6 using System.IO; 7 using System.IO.Abstractions; 8 using System.Text.Json; 9 10 namespace Microsoft.PowerToys.Settings.UI.Library 11 { 12 public class LanguageModel 13 { 14 public const string SettingsFilePath = "\\Microsoft\\PowerToys\\"; 15 public const string SettingsFile = "language.json"; 16 17 public string Tag { get; set; } 18 19 public string ResourceID { get; set; } 20 21 public string Language { get; set; } 22 23 public static string LoadSetting() 24 { 25 FileSystem fileSystem = new FileSystem(); 26 var localAppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); 27 var file = localAppDataDir + SettingsFilePath + SettingsFile; 28 29 if (fileSystem.File.Exists(file)) 30 { 31 try 32 { 33 FileSystemStream inputStream = fileSystem.File.Open(file, FileMode.Open); 34 StreamReader reader = new StreamReader(inputStream); 35 string data = reader.ReadToEnd(); 36 inputStream.Close(); 37 reader.Dispose(); 38 39 return JsonSerializer.Deserialize<OutGoingLanguageSettings>(data).LanguageTag; 40 } 41 catch (Exception) 42 { 43 } 44 } 45 46 return string.Empty; 47 } 48 } 49 }