App.xaml.cs 8.4 KB

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