App.xaml.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using ComPDFKit.NativeMethod;
  11. using ComPDFKit_Conversion.Converter;
  12. using PDF_Office.CustomControl;
  13. using PDF_Office.CustomControl.SystemControl;
  14. using PDF_Office.ViewModels;
  15. using PDF_Office.Views;
  16. using PDF_Office.Views.BOTA;
  17. using PDF_Office.Views.Dialog;
  18. using PDF_Office.Views.HomePanel;
  19. using Prism.DryIoc;
  20. using Prism.Ioc;
  21. using Prism.Regions;
  22. using PDF_Office.Model;
  23. using PDF_Office.Views.PageEdit;
  24. using PDF_Office.Properties;
  25. using PDFSettings.Settings;
  26. using PDF_Office.Views.Dialog.PageEditDialogs;
  27. namespace PDF_Office
  28. {
  29. /// <summary>
  30. /// App.xaml 的交互逻辑
  31. /// </summary>
  32. public partial class App : PrismApplication
  33. {
  34. public static string CurrentPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "PDF Office");
  35. public static MainWindowViewModel mainWindowViewModel;
  36. public static List<string> OpenedFileList = new List<string>();
  37. public static bool IsFirstOpen = true;
  38. public App()
  39. {
  40. #if !DEBUG
  41. //接入Appcenter后台数据检测
  42. string appkey = "b099dccc-1ca5-4ea1-a2fa-afd4a6e1f8bb"
  43. AppCenter.Start(appkey, typeof(Analytics), typeof(Crashes));
  44. var countryCode = RegionInfo.CurrentRegion.TwoLetterISORegionName;//上传国家信息
  45. AppCenter.SetCountryCode(countryCode);
  46. #endif
  47. LicenseVerify();
  48. if (Settings.Default.RecentOpenFiles == null)
  49. Settings.Default.RecentOpenFiles = new RecentOpenFiles();
  50. try
  51. {
  52. DirectoryInfo info = new DirectoryInfo(CurrentPath);
  53. if (File.Exists(CurrentPath))
  54. File.Delete(CurrentPath);
  55. if (!info.Exists)
  56. {
  57. info.Create();
  58. }
  59. }
  60. catch (Exception ex)
  61. {
  62. }
  63. }
  64. /// <summary>
  65. /// 创建启动窗口
  66. /// </summary>
  67. /// <returns></returns>
  68. protected override Window CreateShell()
  69. {
  70. return Container.Resolve<MainWindow>();
  71. }
  72. protected override void RegisterTypes(IContainerRegistry containerRegistry)
  73. {
  74. //注册内容组件
  75. containerRegistry.RegisterForNavigation<HomeContent>();
  76. containerRegistry.RegisterForNavigation<ViewContent>();
  77. containerRegistry.RegisterForNavigation<MainContent>();
  78. containerRegistry.RegisterForNavigation<HomeCloudContent>("Cloud");
  79. containerRegistry.RegisterForNavigation<HomeToolsContent>("Tools");
  80. containerRegistry.RegisterForNavigation<HomeGuidContent>("Guid");
  81. containerRegistry.RegisterForNavigation<BOTAContent>();
  82. containerRegistry.RegisterForNavigation<PageEditContent>();
  83. //注册弹窗
  84. containerRegistry.RegisterDialog<VerifyPassWordDialog>(DialogNames.VerifyPassWordDialog);
  85. containerRegistry.RegisterDialog<FullScreenWindow>(DialogNames.FullScreenDialog);
  86. containerRegistry.RegisterDialog<InsertDialog>(DialogNames.InsertDialog);
  87. containerRegistry.RegisterDialog<SplitDialog>(DialogNames.SplitDialog);
  88. containerRegistry.RegisterDialog<ExtractDialog>(DialogNames.ExtractDialog);
  89. }
  90. protected override void ConfigureRegionAdapterMappings(RegionAdapterMappings regionAdapterMappings)
  91. {
  92. var region = new SingleActiveRegion() { Name = RegionNames.MainRegion };
  93. region.Behaviors.Add(DragablzWindowBehavior.BehaviorKey, new DragablzWindowBehavior());
  94. Container.Resolve<IRegionManager>().Regions.Add(region);
  95. base.ConfigureRegionAdapterMappings(regionAdapterMappings);
  96. }
  97. private static bool LicenseVerify()
  98. {
  99. bool result = false;
  100. try
  101. {
  102. result = CPDFSDKVerifier.LoadNativeLibrary();
  103. if (!result)
  104. return false;
  105. }
  106. catch{ }
  107. string devKey = "";
  108. string devSecret = "";
  109. #if DEBUG
  110. devKey = "tmqcblSkvVZeNj9k4nMA88G6g1kw4yYH+tPiqK+T91CaGM9urgNlT1+kXiTyv0W1bTQNObS51WgQpfJNl1inRVDKBB3wznw2o7vtKjOKKDNbV7R1ply0PhDKVkKYV040vpAdaT8GZEfllftNlts99uGhscqGvmCLBKmgTsq0HFo=";
  111. devSecret = "mG0c3O3Mzeu5dkZJW3gpqq9uA7o7EGQveSC38Q8TK4iccr16WMBclnQACarlyblNMFa171moVHNuaoPG9eUt/RDYPB4dH12/mo6Nb7CMnoDUShGRobCLus9Vl3Sb80EZvGI/sVnm7Ju0Mhj+L/faMDDsKeheIw8v1IwmcZT3yU2l9MwkobWvR2DRybgSkLGYbFAv+VbVAICHE/17JjUpTkFo+FpaETldwAVsTVNm77oq2xRRteAQmIiZl/ptWMK8";
  112. #endif
  113. string userKey = "iBPRM/Tz8b6Z1G2GQt52X7hiNCGfVYXztnPjalgrgARvqfKV6lFNH8QeScTzBRYI8GGFpwelfgh790Kd9JmL7V4adI1jCiFHUT2DLT7QucxY5Nkgys2aJItQS482Ck2G2Xf8gNgojxYxRt65o/MEzkj93foj8qIdfHagXsSorSs=";
  114. string userSecret = "mG0c3O3Mzeu5dkZJW3gpqq9uA7o7EGQveSC38Q8TK4ivEHOmPIqbfhpDnKKj+7Ymj2rXQvfZRmke06HMV+3tt064G64WjPW8+EbGCNZaAh1hrp9sGpqfp0B228KI+IMTu4aGVjtYuk+Uxs/kosIBw1FKJi6HYB+DuugQyaqI2prfej861QnJrU4s2T/npZK/";
  115. try
  116. {
  117. CPDFSDKVerifier.LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(devKey, devSecret, userKey, userSecret);
  118. if (verifyResult != CPDFSDKVerifier.LicenseErrorCode.LICENSE_ERR_SUCCESS)
  119. return false;
  120. }
  121. catch{ }
  122. string ConverterDevKey = "mDDCTNY5rV2+FUj2JESUBruJ0643Tv7rNuxACu6g3L/0guIw1r8zZB+o3aw3rs4rrOThmxBXpEDcItvyGx096mF/3Ixg7aD6QZk5HvBEScIPerdM3KnhgwMwCjE0DYOSMCRwAhbA2xjXfXgT5VVo7JZroKOGQB5Qmf2kLl5nQuU=";
  123. string ConverterDevSecret = "mG0c3O3Mzeu5dkZJW3gpqq9uA7o7EGQveSC38Q8TK4g3S5AixMY+3TX1FpQaugG9sTsnCq4QxIEDzyAI3s3dWjNe3wDsMrmFq51HtjPa2tSFAoV6NtcUJC8skonXVk7kMv7C2jvq4o0q6sQtN3jR42k0n/LkN5UfbQ5Lfel4OfZrk7dh2/DUR87Ps4vBX1hrYkwcNWVMyYvggPV2rTFvfawopGIC034QzjthmhwwX90=";
  124. string ConverterUserkey = "WLUHzXhndQKyrTJVzvZ+dvPXDQDZeJpcSvklX3GJwRX4+urd8eQskYgbeCf0NXLZ/qJkS/k10x+qGad34i4v5rI/ASFIx901c/Nw5C0YJMH7X87dib141tdAmSmQhnKLO5TBi4FiAidboyvnLFLrYGMmS2kLQOXFPwPj5zQUv5A=";
  125. string ConverterUserSecret = "mG0c3O3Mzeu5dkZJW3gpqq9uA7o7EGQveSC38Q8TK4iK16EcneqBPRe2eKQLuJXpA79IONX9GVI/Ap3uWzMcNWaitc2UB6gDeexJXFPVaXOFAoV6NtcUJC8skonXVk7k/oKTJGcYKLPGdXenrzHolQ==";
  126. try
  127. {
  128. /*LicenseError licenseerror = CPDFConverter.SDKLicenseVerify(ConverterDevKey, ConverterDevSecret, ConverterUserkey, ConverterUserSecret);
  129. string resPath = Path.GetDirectoryName(typeof(MainWindow).Assembly.Location) + "\\";
  130. if (licenseerror != LicenseError.ERR_SUCCESS)
  131. {
  132. return false;
  133. }
  134. CPDFConverter.Init(resPath);*/
  135. string resPath = Path.GetDirectoryName(typeof(MainWindow).Assembly.Location) + "\\";
  136. LicenseError licenseerror = CPDFConverter.LicenseVerify(ConverterDevKey, ConverterDevSecret, ConverterUserkey, ConverterUserSecret);
  137. if (licenseerror != LicenseError.ERR_SUCCESS)
  138. {
  139. //MessageBox.Show("ComPDFKit Conversion SDK Load Failed!");
  140. return false;
  141. }
  142. CPDFConverter.Init(resPath);
  143. }
  144. catch{ }
  145. return result;
  146. }
  147. protected override void OnExit(ExitEventArgs e)
  148. {
  149. Environment.Exit(1);
  150. base.OnExit(e);
  151. }
  152. }
  153. }