App.xaml.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using ComPDFKit.NativeMethod;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Configuration;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Xml;
  11. namespace PDFViewer
  12. {
  13. public class SDKLicenseHelper
  14. {
  15. public string key = string.Empty;
  16. public string secret = string.Empty;
  17. public SDKLicenseHelper()
  18. {
  19. string sdkLicensePath = "SDKLicense.xml";
  20. Assembly assembly = Assembly.GetExecutingAssembly();
  21. XmlDocument xmlDocument = new XmlDocument();
  22. xmlDocument.Load(sdkLicensePath);
  23. var node = xmlDocument.SelectSingleNode("License");
  24. if (node != null)
  25. {
  26. key = node.Attributes["key"].Value;
  27. secret = node.Attributes["secret"].Value;
  28. }
  29. }
  30. }
  31. /// <summary>
  32. /// Interaction logic for App.xaml
  33. /// </summary>
  34. ///
  35. public partial class App : Application
  36. {
  37. static public bool DefaultPDFLoaded = false;
  38. public static List<string> OpenedFilePathList = new List<string>();
  39. protected override void OnStartup(StartupEventArgs e)
  40. {
  41. string str = this.GetType().Assembly.Location;
  42. base.OnStartup(e);
  43. LicenseVerify();
  44. }
  45. private static bool LicenseVerify()
  46. {
  47. bool result = false;
  48. try
  49. {
  50. result = CPDFSDKVerifier.LoadNativeLibrary();
  51. if (!result)
  52. return false;
  53. }
  54. catch
  55. { }
  56. SDKLicenseHelper sdkLicenseHelper = new SDKLicenseHelper();
  57. try
  58. {
  59. LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(sdkLicenseHelper.key, sdkLicenseHelper.secret);
  60. if (verifyResult != LicenseErrorCode.LICENSE_ERR_SUCCESS)
  61. return false;
  62. }
  63. catch { }
  64. return result;
  65. }
  66. }
  67. }