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.Windows.Threading; 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 string CurrentCulture = Settings.Default.Cultrue; public static List SupportedCultureList = new List() { "en-US", "zh-CN" }; public static FilePathList OpenedFilePathList = new FilePathList(); public static ResourceManager MainResourceManager = new ResourceManager("PDFViewer.Strings.SettingDialog", Assembly.GetExecutingAssembly()); public App() { this.DispatcherUnhandledException += App_DispatcherUnhandledException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; } private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e) { var ex = e.Exception as Exception; if (ex != null) { MessageBox.Show("发生Task未处理异常:" + ex.Message + "\n" + ex.StackTrace, "系统错误", MessageBoxButton.OK, MessageBoxImage.Error); } } private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { if (e.ExceptionObject is System.Exception) { Exception ex = (System.Exception)e.ExceptionObject; MessageBox.Show("发生非UI线程异常:" + ex.Message + "\n" + ex.StackTrace, "系统错误", MessageBoxButton.OK, MessageBoxImage.Error); } } private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { e.Handled = true; MessageBox.Show("发生UI线程异常:" + e.Exception.Message + "\n" + e.Exception.StackTrace, "系统错误", MessageBoxButton.OK, MessageBoxImage.Error); } protected override void OnStartup(StartupEventArgs e) { if (string.IsNullOrEmpty(CurrentCulture)) { CurrentCulture = CultureInfo.CurrentCulture.Name; if (!SupportedCultureList.Contains(CurrentCulture)) { CurrentCulture = "en-US"; } Settings.Default.Cultrue = CurrentCulture; Settings.Default.Save(); } Thread.CurrentThread.CurrentUICulture = new CultureInfo(CurrentCulture); Thread.CurrentThread.CurrentCulture = new CultureInfo(CurrentCulture); base.OnStartup(e); LicenseVerify(); HistoryFile(@"TestFile\ComPDFKit_Sample_File_Windows.pdf"); FileHistoryHelper.Instance.LoadHistory(); } private static bool LicenseVerify() { if (!CPDFSDKVerifier.LoadNativeLibrary()) return false; string license = "vRK+dzgqDsImQkoKZb2i2WhhdsKYquZ5JJUUuOF6q4xySFETAYvInXOu/f3JAvR9X14z/s4W20EE9WSKsbEum6IvdY8uLoNFy6YM7SyvNC0zVPs5T7GnEBaTQ+qVgnGeV88LA7nbZjPGfQmC75jFLlItpetrbbp75d7LQs6ftq/I8akPBz4Kxc3SSow2MFj5GzH6VbCFYSlUKw/TwA4adwM8uk2g6Kh86i23vTzGejQ4FtQ6stKHXn4HllO0bXpWnFihljcZ3R8PR31pFNwT8UUw4h9NVdFcZxpnGRDbwx9QP9WyHpHZLwbeO48ufCgFCVysJEk1riNSTGTAaAP3FUtTVN6c+2dRhnnKQ9BD2+ZXPq1h0mtlp1NQ+RMIko/jptqMsDODbroq9eCcyCqv15famjsc5QhApxJ66Uir6JIEWg+1gHSh2bjFiiXJAZ6NYxZRbQCMGNWAvkvPL3VOmCcPKDpJojB4dAuUzkjcfNP3FtGWASLlf1sxBLPPUH3/SUjuKo61mV+inIkdPNQcpTuQO57aUzB8KSNTD9t5EApfDx1B3KqboczEI8JHpWmS+IJqLCfsdlZLlGqIVobinsWoWlrK+RCjMLVb1nG6cwgJkaUZSOX6lhqKCVjsk/y/UkMufir2Jr3VOcSskcB2q89CFCFifHHHnhIhHClAv/cmsbjAv8udd4vC2c8/IMyeZDTKE61QPTGv5Web7Veww7UvwzOJJzdEyurazXA+8W54OEFOcXWYSdIgqS/vfVtnuO1kXkGQlSX1V0ead/9e5cgbJBA0v6oCmcgFsdJ19cJWN2eb8XRaylJBvRjCLTfxyhbz5ot00OuvKj41xr9kzFxfdbfnnZIUvdt0DhdKOcq/XESwVIL+pht7hkwzW7dk3HovfUURbW/42AUBTS3P/UNn7rp3eHOhZnTYo6erdzuLfnoMUa8M8nhOhIEkkRTxyCgKfwd4akkqZVJx9r83Hlf9ceP1IoDYgrXYwpetLJ8="; LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(license, false); return (verifyResult == LicenseErrorCode.E_LICENSE_SUCCESS); } 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 FilePathList : List { public new void Add(string item) { base.Add(item); } } 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(); } } }