App.xaml.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Xml;
  10. using ComPDFKit.NativeMethod;
  11. namespace PDFViewer_new
  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 = "license_key_win.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. public partial class App: Application
  35. {
  36. protected override void OnStartup(StartupEventArgs e)
  37. {
  38. string str = this.GetType().Assembly.Location;
  39. base.OnStartup(e);
  40. LicenseVerify();
  41. }
  42. private static bool LicenseVerify()
  43. {
  44. bool result = false;
  45. result = CPDFSDKVerifier.LoadNativeLibrary();
  46. if (!result)
  47. return false;
  48. SDKLicenseHelper sdkLicenseHelper = new SDKLicenseHelper();
  49. LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(sdkLicenseHelper.key, sdkLicenseHelper.secret);
  50. if (verifyResult != LicenseErrorCode.LICENSE_ERR_SUCCESS)
  51. return false;
  52. return result;
  53. }
  54. }
  55. }