App.xaml.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Xml;
  11. using ComPDFKit.NativeMethod;
  12. using Compdfkit_Tools.Helper;
  13. namespace PDFViewer
  14. {
  15. /// <summary>
  16. /// Interaction logic for App.xaml
  17. /// </summary>
  18. public partial class App: Application
  19. {
  20. static public bool DefaultPDFLoaded = false;
  21. public static FilePathList OpenedFilePathList = new FilePathList();
  22. protected override void OnStartup(StartupEventArgs e)
  23. {
  24. string str = this.GetType().Assembly.Location;
  25. base.OnStartup(e);
  26. LicenseVerify();
  27. FileHistoryHelper<PDFFileInfo>.Instance.LoadHistory();
  28. }
  29. private static bool LicenseVerify()
  30. {
  31. bool result = false;
  32. result = CPDFSDKVerifier.LoadNativeLibrary();
  33. if (!result)
  34. return false;
  35. SDKLicenseHelper sdkLicenseHelper = new SDKLicenseHelper();
  36. LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(sdkLicenseHelper.key, sdkLicenseHelper.secret);
  37. if (verifyResult != LicenseErrorCode.LICENSE_ERR_SUCCESS)
  38. return false;
  39. return result;
  40. }
  41. }
  42. public class FilePathList : List<string>
  43. {
  44. public new void Add(string item)
  45. {
  46. base.Add(item);
  47. YourCustomFunction(item);
  48. }
  49. private void YourCustomFunction(string item)
  50. {
  51. PDFFileInfo fileInfo = new PDFFileInfo();
  52. fileInfo.FilePath = item;
  53. fileInfo.FileName = Path.GetFileName(item);
  54. fileInfo.FileSize = CommonHelper.GetFileSize(fileInfo.FilePath);
  55. fileInfo.OpenDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  56. FileHistoryHelper<PDFFileInfo>.Instance.AddHistory(fileInfo);
  57. FileHistoryHelper<PDFFileInfo>.Instance.SaveHistory();
  58. }
  59. }
  60. }