using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Resources; using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Data; using System.Xml; using ComPDFKit.NativeMethod; using Compdfkit_Tools.Helper; using PDFViewer.Properties; namespace PDFViewer { /// /// Interaction logic for App.xaml /// public partial class App: Application { public static bool DefaultPDFLoaded = false; public static string CurrentLanguage = Settings.Default.Language; public static Dictionary Languages= new Dictionary() { {"English","en-US"}, {"简体中文","zh-CN"} }; public static FilePathList OpenedFilePathList = new FilePathList(); public static ResourceManager MainResourceManager = new ResourceManager("PDFViewer.Strings.SettingDialog", Assembly.GetExecutingAssembly()); protected override void OnStartup(StartupEventArgs e) { string currentCulture; if (string.IsNullOrEmpty(CurrentLanguage)) { currentCulture = CultureInfo.CurrentCulture.Name; CurrentLanguage = Languages.FirstOrDefault(x => x.Value == currentCulture).Key; if (!Languages.ContainsValue(currentCulture)) { CurrentLanguage = "English"; currentCulture = "en-US"; } Settings.Default.Language = CurrentLanguage; Settings.Default.Save(); } else { currentCulture = Languages.TryGetValue(CurrentLanguage, out currentCulture) ? currentCulture : "en-US"; } Thread.CurrentThread.CurrentUICulture = new CultureInfo(currentCulture); Thread.CurrentThread.CurrentCulture = new CultureInfo(currentCulture); base.OnStartup(e); LicenseVerify(); FileHistoryHelper.Instance.LoadHistory(); } private static bool LicenseVerify() { if (!CPDFSDKVerifier.LoadNativeLibrary()) return false; LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify("license_key_windows.txt", true); return (verifyResult != LicenseErrorCode.E_LICENSE_SUCCESS); } } public class FilePathList : List { public new void Add(string item) { base.Add(item); HistoryFile(item); } private void HistoryFile(string item) { PDFFileInfo fileInfo = new PDFFileInfo(); fileInfo.FilePath = item; fileInfo.FileName = Path.GetFileName(item); fileInfo.FileSize = CommonHelper.GetFileSize(fileInfo.FilePath); fileInfo.OpenDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); FileHistoryHelper.Instance.AddHistory(fileInfo); FileHistoryHelper.Instance.SaveHistory(); } } public class ResourceConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (parameter == null || string.IsNullOrEmpty(parameter.ToString())) { return string.Empty; } return App.MainResourceManager.GetString(parameter.ToString()); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotSupportedException(); } } }