App.xaml.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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_Tools.Helper;
  16. using PDFViewer.Properties;
  17. namespace PDFViewer
  18. {
  19. /// <summary>
  20. /// Interaction logic for App.xaml
  21. /// </summary>
  22. public partial class App : Application
  23. {
  24. public static string CurrentCulture = Settings.Default.Cultrue;
  25. public static List<string> SupportedCultureList = new List<string>()
  26. {
  27. "en-US", "zh-CN"
  28. };
  29. public static FilePathList OpenedFilePathList = new FilePathList();
  30. public static ResourceManager MainResourceManager = new ResourceManager("PDFViewer.Strings.SettingDialog", Assembly.GetExecutingAssembly());
  31. public static bool LicenseVerify()
  32. {
  33. if (!CPDFSDKVerifier.LoadNativeLibrary())
  34. {
  35. return false;
  36. }
  37. LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(SDKLicenseHelper.ParseLicenseXML(), false);
  38. return (verifyResult == LicenseErrorCode.E_LICENSE_SUCCESS);
  39. }
  40. protected override void OnStartup(StartupEventArgs e)
  41. {
  42. if (string.IsNullOrEmpty(CurrentCulture))
  43. {
  44. CurrentCulture = CultureInfo.CurrentCulture.Name;
  45. if (!SupportedCultureList.Contains(CurrentCulture))
  46. {
  47. CurrentCulture = "en-US";
  48. }
  49. Settings.Default.Cultrue = CurrentCulture;
  50. Settings.Default.Save();
  51. }
  52. Thread.CurrentThread.CurrentUICulture = new CultureInfo(CurrentCulture);
  53. Thread.CurrentThread.CurrentCulture = new CultureInfo(CurrentCulture);
  54. base.OnStartup(e);
  55. LicenseVerify();
  56. CPDFSDKVerifier.PrintPermissions();
  57. //CPDFSDKVerifier.LicenseRefreshed -= CPDFSDKVerifier_LicenseRefreshed;
  58. //CPDFSDKVerifier.LicenseRefreshed += CPDFSDKVerifier_LicenseRefreshed;
  59. HistoryFile(@"TestFile\ComPDFKit_Sample_File_Windows.pdf");
  60. FileHistoryHelper<PDFFileInfo>.Instance.LoadHistory();
  61. }
  62. //private void CPDFSDKVerifier_LicenseRefreshed(object sender, ResponseModel e)
  63. //{
  64. // if(e != null)
  65. // {
  66. // string message = string.Format("{0} {1}", e.Code, e.Message);
  67. // Trace.WriteLine(message);
  68. // }
  69. // else
  70. // {
  71. // Trace.WriteLine("Network not connected.");
  72. // }
  73. //}
  74. private void HistoryFile(string item)
  75. {
  76. PDFFileInfo fileInfo = new PDFFileInfo();
  77. fileInfo.FilePath = item;
  78. fileInfo.FileName = Path.GetFileName(item);
  79. fileInfo.FileSize = CommonHelper.GetFileSize(fileInfo.FilePath);
  80. fileInfo.OpenDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  81. FileHistoryHelper<PDFFileInfo>.Instance.AddHistory(fileInfo);
  82. FileHistoryHelper<PDFFileInfo>.Instance.SaveHistory();
  83. }
  84. }
  85. public class FilePathList : List<string>
  86. {
  87. public new void Add(string item)
  88. {
  89. base.Add(item);
  90. }
  91. }
  92. public class ResourceConverter : IValueConverter
  93. {
  94. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  95. {
  96. if (parameter == null || string.IsNullOrEmpty(parameter.ToString()))
  97. {
  98. return string.Empty;
  99. }
  100. return App.MainResourceManager.GetString(parameter.ToString());
  101. }
  102. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  103. {
  104. throw new NotSupportedException();
  105. }
  106. }
  107. }