App.xaml.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 = "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. ///
  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. result = CPDFSDKVerifier.LoadNativeLibrary();
  49. if (!result)
  50. return false;
  51. SDKLicenseHelper sdkLicenseHelper = new SDKLicenseHelper();
  52. LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(sdkLicenseHelper.key, sdkLicenseHelper.secret);
  53. if (verifyResult != LicenseErrorCode.LICENSE_ERR_SUCCESS)
  54. return false;
  55. return result;
  56. }
  57. }
  58. }