App.xaml.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. static public bool DefaultPDFLoaded = false;
  37. public static List<string> OpenedFilePathList = new List<string>();
  38. protected override void OnStartup(StartupEventArgs e)
  39. {
  40. string str = this.GetType().Assembly.Location;
  41. base.OnStartup(e);
  42. LicenseVerify();
  43. }
  44. private static bool LicenseVerify()
  45. {
  46. bool result = false;
  47. result = CPDFSDKVerifier.LoadNativeLibrary();
  48. if (!result)
  49. return false;
  50. SDKLicenseHelper sdkLicenseHelper = new SDKLicenseHelper();
  51. LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(sdkLicenseHelper.key, sdkLicenseHelper.secret);
  52. if (verifyResult != LicenseErrorCode.LICENSE_ERR_SUCCESS)
  53. return false;
  54. return result;
  55. }
  56. }
  57. }