App.xaml.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. Assembly assembly = Assembly.GetExecutingAssembly();
  17. XmlDocument xmlDocument = new XmlDocument();
  18. xmlDocument.Load(sdkLicensePath);
  19. var node = xmlDocument.SelectSingleNode("License");
  20. if (node != null)
  21. {
  22. key = node.Attributes["key"].Value;
  23. secret = node.Attributes["secret"].Value;
  24. }
  25. }
  26. }
  27. /// <summary>
  28. /// Interaction logic for App.xaml
  29. /// </summary>
  30. ///
  31. public partial class App : Application
  32. {
  33. protected override void OnStartup(StartupEventArgs e)
  34. {
  35. string str = this.GetType().Assembly.Location;
  36. base.OnStartup(e);
  37. LicenseVerify();
  38. }
  39. private static bool LicenseVerify()
  40. {
  41. bool result = false;
  42. result = CPDFSDKVerifier.LoadNativeLibrary();
  43. if (!result)
  44. return false;
  45. SDKLicenseHelper sdkLicenseHelper = new SDKLicenseHelper();
  46. LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(sdkLicenseHelper.key, sdkLicenseHelper.secret);
  47. if (verifyResult != LicenseErrorCode.LICENSE_ERR_SUCCESS)
  48. return false;
  49. return result;
  50. }
  51. }
  52. }