App.xaml.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Globalization;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Resources;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Data;
  14. using System.Xml;
  15. using ComPDFKit.NativeMethod;
  16. using Compdfkit_Tools.Helper;
  17. using PDFViewer.Properties;
  18. namespace PDFViewer
  19. {
  20. /// <summary>
  21. /// Interaction logic for App.xaml
  22. /// </summary>
  23. public partial class App: Application
  24. {
  25. public static string CurrentCulture = Settings.Default.Cultrue;
  26. public static List<string> SupportedCultureList= new List<string>()
  27. {
  28. "en-US", "zh-CN"
  29. };
  30. public static FilePathList OpenedFilePathList = new FilePathList();
  31. public static ResourceManager MainResourceManager = new ResourceManager("PDFViewer.Strings.SettingDialog", Assembly.GetExecutingAssembly());
  32. protected override void OnStartup(StartupEventArgs e)
  33. {
  34. if (string.IsNullOrEmpty(CurrentCulture))
  35. {
  36. CurrentCulture = CultureInfo.CurrentCulture.Name;
  37. if (!SupportedCultureList.Contains(CurrentCulture))
  38. {
  39. CurrentCulture = "en-US";
  40. }
  41. Settings.Default.Cultrue = CurrentCulture;
  42. Settings.Default.Save();
  43. }
  44. Thread.CurrentThread.CurrentUICulture = new CultureInfo(CurrentCulture);
  45. Thread.CurrentThread.CurrentCulture = new CultureInfo(CurrentCulture);
  46. base.OnStartup(e);
  47. LicenseVerify();
  48. HistoryFile(@"TestFile\ComPDFKit_Sample_File_Windows.pdf");
  49. FileHistoryHelper<PDFFileInfo>.Instance.LoadHistory();
  50. }
  51. private static bool LicenseVerify()
  52. {
  53. if (!CPDFSDKVerifier.LoadNativeLibrary())
  54. return false;
  55. LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify("license_key_windows.txt", true);
  56. return (verifyResult == LicenseErrorCode.E_LICENSE_SUCCESS);
  57. }
  58. private void HistoryFile(string item)
  59. {
  60. PDFFileInfo fileInfo = new PDFFileInfo();
  61. fileInfo.FilePath = item;
  62. fileInfo.FileName = Path.GetFileName(item);
  63. fileInfo.FileSize = CommonHelper.GetFileSize(fileInfo.FilePath);
  64. fileInfo.OpenDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  65. FileHistoryHelper<PDFFileInfo>.Instance.AddHistory(fileInfo);
  66. FileHistoryHelper<PDFFileInfo>.Instance.SaveHistory();
  67. }
  68. }
  69. public class FilePathList : List<string>
  70. {
  71. public new void Add(string item)
  72. {
  73. base.Add(item);
  74. }
  75. }
  76. public class ResourceConverter : IValueConverter
  77. {
  78. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  79. {
  80. if (parameter == null || string.IsNullOrEmpty(parameter.ToString()))
  81. {
  82. return string.Empty;
  83. }
  84. return App.MainResourceManager.GetString(parameter.ToString());
  85. }
  86. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  87. {
  88. throw new NotSupportedException();
  89. }
  90. }
  91. }