App.xaml.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using ComPDFKit.NativeMethod;
  2. using System.IO;
  3. using System.Reflection;
  4. using System.Windows;
  5. using System.Xml;
  6. using static ComPDFKit.NativeMethod.CPDFSDKVerifier;
  7. namespace Viewer
  8. {
  9. public class SDKLicenseHelper
  10. {
  11. public string key = string.Empty;
  12. public string secret = string.Empty;
  13. public SDKLicenseHelper()
  14. {
  15. string sdkLicensePath = "license_key_win.xml";
  16. XmlDocument xmlDocument = new XmlDocument();
  17. xmlDocument.Load(sdkLicensePath);
  18. var node = xmlDocument.SelectSingleNode("License");
  19. if (node != null)
  20. {
  21. key = node.Attributes["key"].Value;
  22. secret = node.Attributes["secret"].Value;
  23. }
  24. }
  25. }
  26. /// <summary>
  27. /// Interaction logic for App.xaml
  28. /// </summary>
  29. ///
  30. public partial class App : Application
  31. {
  32. protected override void OnStartup(StartupEventArgs e)
  33. {
  34. string str = this.GetType().Assembly.Location;
  35. base.OnStartup(e);
  36. LicenseVerify();
  37. }
  38. private static bool LicenseVerify()
  39. {
  40. bool result = false;
  41. result = CPDFSDKVerifier.LoadNativeLibrary();
  42. if (!result)
  43. return false;
  44. SDKLicenseHelper sdkLicenseHelper = new SDKLicenseHelper();
  45. LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(sdkLicenseHelper.key, sdkLicenseHelper.secret);
  46. if (verifyResult != LicenseErrorCode.LICENSE_ERR_SUCCESS)
  47. return false;
  48. return result;
  49. }
  50. }
  51. }