App.xaml.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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.Views.Dialog.PageEditDialogs;
  30. using PDF_Office.Helper;
  31. using PDF_Office.Views.Dialog.HomePageToolsDialogs;
  32. using PDF_Office.Views.Dialog.HomePageToolsDialogs.HomePagePrinter;
  33. using PDF_Office.Views.PropertyPanel;
  34. using PDF_Office.Views.Dialog.BOTA;
  35. using PDF_Office.Views.PropertyPanel.AnnotPanel;
  36. using PDF_Office.Views.FillAndSign;
  37. using PDF_Office.Views.FillAndSign.PropertyPanel;
  38. using PDF_Office.Views.PropertyPanel.ViewModular;
  39. using PDF_Office.Views.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
  40. using PDF_Office.Views.Dialog.ConverterDialogs;
  41. using PDF_Office.Helper;
  42. using PDF_Office.Views.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageConverter;
  43. using PDF_Office.Views.EditTools.Watermark;
  44. using PDF_Office.Views.EditTools.Background;
  45. using PDF_Office.Views.EditTools.Bates;
  46. using PDF_Office.Views.EditTools.HeaderFooter;
  47. using PDF_Office.Views.EditTools.Redaction;
  48. using PDF_Office.Views.Form;
  49. using PDF_Office.Views.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageHeaderFooter;
  50. using PDF_Office.Views.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageBates;
  51. using PDF_Office.Views.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageWatermark;
  52. using PDF_Office.Views.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageBackground;
  53. namespace PDF_Office
  54. {
  55. /// <summary>
  56. /// App.xaml 的交互逻辑
  57. /// </summary>
  58. public partial class App : PrismApplication
  59. {
  60. public static string CurrentPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "PDF Office");
  61. public static MainWindowViewModel mainWindowViewModel;
  62. public static List<string> OpenedFileList = new List<string>();
  63. public static CacheFilePath CachePath;
  64. public static bool IsFirstOpen = true;
  65. public static bool IsBookMode = false;
  66. public App()
  67. {
  68. #if !DEBUG
  69. //接入Appcenter后台数据检测
  70. string appkey = "b099dccc-1ca5-4ea1-a2fa-afd4a6e1f8bb"
  71. AppCenter.Start(appkey, typeof(Analytics), typeof(Crashes));
  72. var countryCode = RegionInfo.CurrentRegion.TwoLetterISORegionName;//上传国家信息
  73. AppCenter.SetCountryCode(countryCode);
  74. #endif
  75. }
  76. private void InitSettings()
  77. {
  78. if (Settings.Default.RecentOpenFiles == null)
  79. Settings.Default.RecentOpenFiles = new RecentOpenFiles();
  80. if (Settings.Default.AppProperties == null)
  81. Settings.Default.AppProperties = new PDFSettings.APPSettingProperties();
  82. if (Settings.Default.AllPDFToolsList == null)
  83. Settings.Default.AllPDFToolsList = new PDFSettings.AllPDFToolsList();
  84. if (Settings.Default.QuickPDFToolsList == null)
  85. Settings.Default.QuickPDFToolsList = new PDFSettings.QuickPDFToolsList();
  86. }
  87. protected override void OnStartup(StartupEventArgs e)
  88. {
  89. LicenseVerify();
  90. InitSettings();
  91. CachePath = CacheFilePath.Instance;
  92. //清除临时文件
  93. CacheFilePath.Instance.ClearDeleteFiles();
  94. try
  95. {
  96. DirectoryInfo info = new DirectoryInfo(CurrentPath);
  97. //避免因存在同名文件,导致无法创建文件夹
  98. if (File.Exists(CurrentPath))
  99. {
  100. File.Delete(CurrentPath);
  101. }
  102. if (!info.Exists)
  103. {
  104. info.Create();
  105. }
  106. }
  107. catch (Exception ex)
  108. {
  109. }
  110. base.OnStartup(e);
  111. }
  112. /// <summary>
  113. /// 创建启动窗口
  114. /// </summary>
  115. /// <returns></returns>
  116. protected override Window CreateShell()
  117. {
  118. return Container.Resolve<MainWindow>();
  119. }
  120. protected override void RegisterTypes(IContainerRegistry containerRegistry)
  121. {
  122. #region 注册内容组件
  123. containerRegistry.RegisterForNavigation<HomeContent>();
  124. containerRegistry.RegisterForNavigation<ViewContent>();
  125. containerRegistry.RegisterForNavigation<MainContent>();
  126. containerRegistry.RegisterForNavigation<HomeCloudContent>("Cloud");
  127. containerRegistry.RegisterForNavigation<HomeToolsContent>("Tools");
  128. containerRegistry.RegisterForNavigation<HomeGuidContent>("Guid");
  129. containerRegistry.RegisterForNavigation<BOTAContent>();
  130. containerRegistry.RegisterForNavigation<PropertyPanelContent>();
  131. containerRegistry.RegisterForNavigation<PageEditContent>();
  132. containerRegistry.RegisterForNavigation<BottomToolContent>();
  133. containerRegistry.RegisterForNavigation<ToolsBarContent>();
  134. containerRegistry.RegisterForNavigation<TextEditToolContent>();
  135. containerRegistry.RegisterForNavigation<AnnotToolContent>();
  136. containerRegistry.RegisterForNavigation<BookmarkContent>();
  137. containerRegistry.RegisterForNavigation<SearchContent>();
  138. containerRegistry.RegisterForNavigation<OutLineControl>();
  139. containerRegistry.RegisterForNavigation<ViewModularContent>();
  140. containerRegistry.RegisterForNavigation<SplitScreenContent>();
  141. containerRegistry.RegisterForNavigation<ThemesContent>();
  142. containerRegistry.RegisterForNavigation<ReadModeContent>();
  143. containerRegistry.RegisterForNavigation<AnnotationContent>();
  144. containerRegistry.RegisterForNavigation<ReadViewContent>();
  145. containerRegistry.RegisterForNavigation<HomePagePrinterDocumentContent>();
  146. containerRegistry.RegisterForNavigation<HomePagePrinterModSizeContent>();
  147. containerRegistry.RegisterForNavigation<HomePagePrinterModPosterContent>();
  148. containerRegistry.RegisterForNavigation<HomePagePrinterModMultipleContent>();
  149. containerRegistry.RegisterForNavigation<HomePagePrinterModBookletContent>();
  150. containerRegistry.RegisterForNavigation<HomePageCompressDialog>();
  151. containerRegistry.RegisterForNavigation<HomePageSetPasswordDialog>();
  152. containerRegistry.RegisterForNavigation<HomePageRemoveDialog>();
  153. containerRegistry.RegisterForNavigation<HomePageHeaderFooterDialog>();
  154. containerRegistry.RegisterForNavigation<HomePageHeaderFooterTemplateListContent>();
  155. containerRegistry.RegisterForNavigation<HomePageHeaderFooterCreateContent>();
  156. containerRegistry.RegisterForNavigation<HomePageBatesDialog>();
  157. containerRegistry.RegisterForNavigation<HomePageBatesTemplateListContent>();
  158. containerRegistry.RegisterForNavigation<HomePageBatesCreateContent>();
  159. containerRegistry.RegisterForNavigation<HomePageBackgroundDialog>();
  160. containerRegistry.RegisterForNavigation<HomePageBackgroundTemplateListBaseContent>();
  161. containerRegistry.RegisterForNavigation<HomePageBackgroundTemplateListColorContent>();
  162. containerRegistry.RegisterForNavigation<HomePageBackgroundTemplateListFileContent>();
  163. containerRegistry.RegisterForNavigation<HomePageBackgroundCreateBaseContent>();
  164. containerRegistry.RegisterForNavigation<HomePageBackgroundCreateColorContent>();
  165. containerRegistry.RegisterForNavigation<HomePageBackgroundCreateFileContent>();
  166. containerRegistry.RegisterForNavigation<HomePageWatermarkDialog>();
  167. containerRegistry.RegisterForNavigation<HomePageWatermarkTemplateListBaseContent>();
  168. containerRegistry.RegisterForNavigation<HomePageWatermarkTemplateListTextContent>();
  169. containerRegistry.RegisterForNavigation<HomePageWatermarkTemplateListFileContent>();
  170. containerRegistry.RegisterForNavigation<HomePageWatermarkCreateBaseContent>();
  171. containerRegistry.RegisterForNavigation<HomePageWatermarkCreateTextContent>();
  172. containerRegistry.RegisterForNavigation<HomePageWatermarkCreateFileContent>();
  173. containerRegistry.RegisterForNavigation<ConverterBarContent>();
  174. containerRegistry.RegisterForNavigation<HomePageConverterDialog>();
  175. containerRegistry.RegisterForNavigation<HomePageConverterCSV>();
  176. containerRegistry.RegisterForNavigation<HomePageConverterImg>();
  177. containerRegistry.RegisterForNavigation<HomePageConverterWord>();
  178. containerRegistry.RegisterForNavigation<HomePageConverterExcel>();
  179. containerRegistry.RegisterForNavigation<WatermarkContent>();
  180. containerRegistry.RegisterForNavigation<BackgroundContent>();
  181. containerRegistry.RegisterForNavigation<BackgroundTemplateListBaseContent>();
  182. containerRegistry.RegisterForNavigation<BackgroundTemplateListColorContent>();
  183. containerRegistry.RegisterForNavigation<BackgroundTemplateListFileContent>();
  184. containerRegistry.RegisterForNavigation<BackgroundCreateBaseContent>();
  185. containerRegistry.RegisterForNavigation<BackgroundCreateColorContent>();
  186. containerRegistry.RegisterForNavigation<BackgroundCreateFileContent>();
  187. containerRegistry.RegisterForNavigation<BackgroundDocumentContent>();
  188. containerRegistry.RegisterForNavigation<WatermarkTemplateListBaseContent>();
  189. containerRegistry.RegisterForNavigation<WatermarkTemplateListTextContent>();
  190. containerRegistry.RegisterForNavigation<WatermarkTemplateListFileContent>();
  191. containerRegistry.RegisterForNavigation<WatermarkCreateBaseContent>();
  192. containerRegistry.RegisterForNavigation<WatermarkCreateTextContent>();
  193. containerRegistry.RegisterForNavigation<WatermarkCreateFileContent>();
  194. containerRegistry.RegisterForNavigation<WatermarkDocumentContent>();
  195. containerRegistry.RegisterForNavigation<HomePagePrinterModMultipleContent>();
  196. containerRegistry.RegisterForNavigation<FreehandAnnotProperty>();
  197. containerRegistry.RegisterForNavigation<FreetextAnnotProperty>();
  198. containerRegistry.RegisterForNavigation<ImageAnnotProperty>();
  199. containerRegistry.RegisterForNavigation<LinkAnnotProperty>();
  200. containerRegistry.RegisterForNavigation<SharpsAnnotProperty>();
  201. containerRegistry.RegisterForNavigation<StampAnnotProperty>();
  202. containerRegistry.RegisterForNavigation<SignatureAnnotProperty>();
  203. containerRegistry.RegisterForNavigation<TextAnnotProperty>();
  204. containerRegistry.RegisterForNavigation<TextEditProperty>();
  205. containerRegistry.RegisterForNavigation<BatesContent>();
  206. containerRegistry.RegisterForNavigation<BatesTemplateListContent>();
  207. containerRegistry.RegisterForNavigation<BatesCreateContent>();
  208. containerRegistry.RegisterForNavigation<BatesDocumentContent>();
  209. containerRegistry.RegisterForNavigation<HeaderFooterContent>();
  210. containerRegistry.RegisterForNavigation<HeaderFooterTemplateListContent>();
  211. containerRegistry.RegisterForNavigation<HeaderFooterCreateContent>();
  212. containerRegistry.RegisterForNavigation<HeaderFooterDocumentContent>();
  213. containerRegistry.RegisterForNavigation<RedactionContent>();
  214. containerRegistry.RegisterForNavigation<RedactionDocumentContent>();
  215. //填写与签名
  216. containerRegistry.RegisterForNavigation<FillAndSignContent>();
  217. containerRegistry.RegisterForNavigation<DateFillProperty>();
  218. containerRegistry.RegisterForNavigation<ShapFillProperty>();
  219. containerRegistry.RegisterForNavigation<TextFillProperty>();
  220. //Form表单
  221. containerRegistry.RegisterForNavigation<FormsToolContent>();
  222. containerRegistry.RegisterForNavigation<TextFieldProperty>();
  223. containerRegistry.RegisterForNavigation<ButtonProperty>();
  224. containerRegistry.RegisterForNavigation<CheckBoxProperty>();
  225. containerRegistry.RegisterForNavigation<ListBoxProperty>();
  226. containerRegistry.RegisterForNavigation<RadioButtonProperty>();
  227. containerRegistry.RegisterForNavigation<SignProperty>();
  228. #endregion 注册内容组件
  229. #region 注册弹窗
  230. containerRegistry.RegisterDialog<VerifyPassWordDialog>(DialogNames.VerifyPassWordDialog);
  231. containerRegistry.RegisterDialog<FullScreenWindow>(DialogNames.FullScreenDialog);
  232. containerRegistry.RegisterDialog<CompressDialog>(DialogNames.CompressDialog);
  233. containerRegistry.RegisterDialog<SetPasswordDialog>(DialogNames.SetPasswordDialog);
  234. containerRegistry.RegisterDialog<CheckPasswordDialog>(DialogNames.CheckPasswordDialog);
  235. containerRegistry.RegisterDialog<DeleteSafetySettingsDialog>(DialogNames.DeleteSafetySettingsDialog);
  236. containerRegistry.RegisterDialog<CompressProgressBarDialog, PDF_Office.ViewModels.Dialog.ToolsDialogs.CompressDialogs.CompresProgressBarDialogViewModel>(DialogNames.CompressProgressBarDialog);
  237. containerRegistry.RegisterDialog<InsertDialog>(DialogNames.InsertDialog);
  238. containerRegistry.RegisterDialog<SplitDialog>(DialogNames.SplitDialog);
  239. containerRegistry.RegisterDialog<ExtractDialog>(DialogNames.ExtractDialog);
  240. containerRegistry.RegisterDialog<HomePageExtractDialog>(DialogNames.HomePageExtractDialog);
  241. containerRegistry.RegisterDialog<HomePageInsertDialog>(DialogNames.HomePageInsertDialog);
  242. containerRegistry.RegisterDialog<HomePageSplitDialog>(DialogNames.HomePageSplitDialog);
  243. containerRegistry.RegisterDialog<HomePagePrinterDialog>(DialogNames.HomePagePrinterDialog);
  244. containerRegistry.RegisterDialog<HomePagePrinterPaperSettingsDialog>(DialogNames.HomePagePrinterPaperSettingsDialog);
  245. containerRegistry.RegisterDialog<HomePagePictureToPDFDialog>(DialogNames.HomePagePictureToPDFDialog);
  246. containerRegistry.RegisterDialog<HomePageBatchProcessingDialog>(DialogNames.HomePageBatchProcessingDialog);
  247. containerRegistry.RegisterDialog<DynamicPropertyDialog>(DialogNames.DynamicPropertyDialog);
  248. containerRegistry.RegisterDialog<CustomCreateDialog>(DialogNames.CustomCreateDialog);
  249. containerRegistry.RegisterDialog<SignatureCreateDialog>(DialogNames.SignatureCreateDialog);
  250. containerRegistry.RegisterDialog<ConverterCSVDialog>(DialogNames.ConverterCSVDialog);
  251. containerRegistry.RegisterDialog<ConverterPPTDialog>(DialogNames.ConverterPPTDialog);
  252. containerRegistry.RegisterDialog<ConverterTextDialog>(DialogNames.ConverterTextDialog);
  253. containerRegistry.RegisterDialog<ConverterWordDialog>(DialogNames.ConverterWordDialog);
  254. containerRegistry.RegisterDialog<ConverterHTMLDialog>(DialogNames.ConverterHTMLDialog);
  255. containerRegistry.RegisterDialog<ConverterImgDialog>(DialogNames.ConverterImgDialog);
  256. containerRegistry.RegisterDialog<ConverterRTFDialog>(DialogNames.ConverterRTFDialog);
  257. containerRegistry.RegisterDialog<ConverterExcelDialog>(DialogNames.ConverterExcelDialog);
  258. containerRegistry.RegisterDialog<ConverterProgressBarDialog>(DialogNames.ConverterProgressBarDialog);
  259. containerRegistry.RegisterDialog<ScreenAnnotationDialog>(DialogNames.ScreenAnnotationDialog);
  260. #endregion 注册弹窗
  261. }
  262. protected override void ConfigureRegionAdapterMappings(RegionAdapterMappings regionAdapterMappings)
  263. {
  264. var region = new SingleActiveRegion() { Name = RegionNames.MainRegion };
  265. region.Behaviors.Add(DragablzWindowBehavior.BehaviorKey, new DragablzWindowBehavior());
  266. Container.Resolve<IRegionManager>().Regions.Add(region);
  267. base.ConfigureRegionAdapterMappings(regionAdapterMappings);
  268. }
  269. /// <summary>
  270. /// 验证SDK和转档库密钥
  271. /// </summary>
  272. /// <returns></returns>
  273. private static bool LicenseVerify()
  274. {
  275. bool result = false;
  276. try
  277. {
  278. result = CPDFSDKVerifier.LoadNativeLibrary();
  279. if (!result)
  280. return false;
  281. }
  282. catch { }
  283. SDKLisenceHelper sdkhelper = new SDKLisenceHelper();
  284. string devKey = "";
  285. string devSecret = "";
  286. #if DEBUG
  287. devKey = "ehrnKqkWc1XSEAWyPUt6+95GzCoLEyoKrCbsUuJkCqGmxmP5ozX4bS0R6crHItQVNTFvC5mBZ1M7QjJ6Ekdu4Daj7PM+EDLTBKbFJinK4Ri9E5E2X+a9vF5zSj0TkIscQPVnwj9ikxAFOWGIyybMwQQzwc8a4j1cGOqGXQRDMMY=";
  288. devSecret = "mG0c3O3Mzeu5dkZJW3gpqq9uA7o7EGQveSC38Q8TK4gQurxTxGuBlGAhs0P1mD3X3bHT+AHfcLiymaqE4DY7kTFHoPs9I3tl5ErS+BHdzHRhrp9sGpqfp0B228KI+IMTu4aGVjtYuk+Uxs/kosIBw1367/WkJ00tM7U7tttD6ccHhEu996bvBgqf8Sw8OekQKQq13VBewK5AckaDux4W7SGRhCUNWC4MItkr36JnXMD2tiFQYzMG8C66HYmRGSLh";
  289. devKey = sdkhelper.DevKey;
  290. devSecret = sdkhelper.DevSecret;
  291. #endif
  292. string userKey = sdkhelper.UserKey;
  293. string userSecret = sdkhelper.UserSecret;
  294. try
  295. {
  296. LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(devKey, devSecret);
  297. if (verifyResult != LicenseErrorCode.LICENSE_ERR_SUCCESS)
  298. return false;
  299. }
  300. catch { }
  301. string ConverterDevKey = sdkhelper.ConverterDevKey;
  302. string ConverterDevSecret = sdkhelper.ConverterDevSecret;
  303. string ConverterUserkey = sdkhelper.ConverterUserkey;
  304. string ConverterUserSecret = sdkhelper.ConverterUserSecret;
  305. try
  306. {
  307. /*LicenseError licenseerror = CPDFConverter.SDKLicenseVerify(ConverterDevKey, ConverterDevSecret, ConverterUserkey, ConverterUserSecret);
  308. string resPath = Path.GetDirectoryName(typeof(MainWindow).Assembly.Location) + "\\";
  309. if (licenseerror != LicenseError.ERR_SUCCESS)
  310. {
  311. return false;
  312. }
  313. CPDFConverter.Init(resPath);*/
  314. string resPath = Path.GetDirectoryName(typeof(MainWindow).Assembly.Location) + "\\";
  315. LicenseError licenseerror = CPDFConverter.LicenseVerify(ConverterDevKey, ConverterDevSecret);
  316. if (licenseerror != LicenseError.ERR_SUCCESS)
  317. {
  318. //MessageBox.Show("ComPDFKit Conversion SDK Load Failed!");
  319. return false;
  320. }
  321. CPDFConverter.Init(resPath);
  322. }
  323. catch { }
  324. return result;
  325. }
  326. protected override void OnExit(ExitEventArgs e)
  327. {
  328. Environment.Exit(1);
  329. base.OnExit(e);
  330. }
  331. }
  332. }