App.xaml.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Globalization;
  5. using System.IO;
  6. using System.Reflection;
  7. using System.Resources;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Data;
  12. using System.Windows.Threading;
  13. using System.Xml;
  14. using ComPDFKit.NativeMethod;
  15. using ComPDFKit.PDFDocument;
  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. public static bool LicenseVerify()
  33. {
  34. if (!CPDFSDKVerifier.LoadNativeLibrary())
  35. {
  36. return false;
  37. }
  38. LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(SDKLicenseHelper.ParseLicenseXML(), false);
  39. return (verifyResult == LicenseErrorCode.E_LICENSE_SUCCESS);
  40. }
  41. protected override void OnStartup(StartupEventArgs e)
  42. {
  43. if (string.IsNullOrEmpty(CurrentCulture))
  44. {
  45. CurrentCulture = CultureInfo.CurrentCulture.Name;
  46. if (!SupportedCultureList.Contains(CurrentCulture))
  47. {
  48. CurrentCulture = "en-US";
  49. }
  50. Settings.Default.Cultrue = CurrentCulture;
  51. Settings.Default.Save();
  52. }
  53. Thread.CurrentThread.CurrentUICulture = new CultureInfo(CurrentCulture);
  54. Thread.CurrentThread.CurrentCulture = new CultureInfo(CurrentCulture);
  55. base.OnStartup(e);
  56. LicenseVerify();
  57. //CPDFSDKVerifier.PrintPermissions();
  58. //CPDFSDKVerifier.LicenseRefreshed -= CPDFSDKVerifier_LicenseRefreshed;
  59. //CPDFSDKVerifier.LicenseRefreshed += CPDFSDKVerifier_LicenseRefreshed;
  60. HistoryFile(@"TestFile\ComPDFKit_Sample_File_Windows.pdf");
  61. FileHistoryHelper<PDFFileInfo>.Instance.LoadHistory();
  62. }
  63. //private void CPDFSDKVerifier_LicenseRefreshed(object sender, ResponseModel e)
  64. //{
  65. // if(e != null)
  66. // {
  67. // string message = string.Format("{0} {1}", e.Code, e.Message);
  68. // Trace.WriteLine(message);
  69. // }
  70. // else
  71. // {
  72. // Trace.WriteLine("Network not connected.");
  73. // }
  74. //}
  75. private void HistoryFile(string item)
  76. {
  77. PDFFileInfo fileInfo = new PDFFileInfo();
  78. fileInfo.FilePath = item;
  79. fileInfo.FileName = Path.GetFileName(item);
  80. fileInfo.FileSize = CommonHelper.GetFileSize(fileInfo.FilePath);
  81. fileInfo.OpenDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  82. FileHistoryHelper<PDFFileInfo>.Instance.AddHistory(fileInfo);
  83. FileHistoryHelper<PDFFileInfo>.Instance.SaveHistory();
  84. }
  85. }
  86. public class FilePathList : List<string>
  87. {
  88. public new void Add(string item)
  89. {
  90. base.Add(item);
  91. }
  92. }
  93. public class ResourceConverter : IValueConverter
  94. {
  95. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  96. {
  97. if (parameter == null || string.IsNullOrEmpty(parameter.ToString()))
  98. {
  99. return string.Empty;
  100. }
  101. return App.MainResourceManager.GetString(parameter.ToString());
  102. }
  103. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  104. {
  105. throw new NotSupportedException();
  106. }
  107. }
  108. }