using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using ComPDFKit.NativeMethod;
using ComPDFKit_Conversion.Converter;
using PDF_Master.CustomControl;
using PDF_Master.CustomControl.SystemControl;
using PDF_Master.ViewModels;
using PDF_Master.Views;
using PDF_Master.Views.BOTA;
using PDF_Master.Views.Dialog;
using PDF_Master.Views.HomePanel;
using Prism.DryIoc;
using Prism.Ioc;
using Prism.Regions;
using PDF_Master.Model;
using PDF_Master.Views.PageEdit;
using PDF_Master.Properties;
using PDFSettings;
using PDF_Master.Views.Tools;
using PDF_Master.Views.Dialog.ToolsDialogs.SaftyDialogs;
using PDF_Master.Views.Dialog.ToolsDialogs.CompressDialogs;
using PDF_Master.Views.Dialog.PageEditDialogs;
using PDF_Master.Helper;
using PDF_Master.Views.Dialog.HomePageToolsDialogs;
using PDF_Master.Views.Dialog.HomePageToolsDialogs.HomePagePrinter;
using PDF_Master.Views.PropertyPanel;
using PDF_Master.Views.Dialog.BOTA;
using PDF_Master.Views.PropertyPanel.AnnotPanel;
using PDF_Master.Views.FillAndSign;
using PDF_Master.Views.FillAndSign.PropertyPanel;
using PDF_Master.Views.PropertyPanel.ViewModular;
using PDF_Master.Views.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
using PDF_Master.Views.Dialog.ConverterDialogs;
using PDF_Master.Views.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageConverter;
using PDF_Master.Views.EditTools.Watermark;
using PDF_Master.Views.EditTools.Background;
using PDF_Master.Views.EditTools.Bates;
using PDF_Master.Views.EditTools.HeaderFooter;
using PDF_Master.Views.EditTools.Redaction;
using PDF_Master.Views.Form;
using PDF_Master.Views.PropertyPanel.PDFEdit;
using PDF_Master.Views.Dialog.ToolsDialogs;
using PDF_Master.Views.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageHeaderFooter;
using PDF_Master.Views.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageBates;
using PDF_Master.Views.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageWatermark;
using PDF_Master.Views.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageBackground;
using ComDocumentAIKit;
using PDF_Master.Views.PropertyPanel.Scan;
using PDF_Master.Views.Dialog.Redaction;
using PDF_Master.Views.Scan;
using PDF_Master.Views.TipContent;
using System.Windows.Threading;
using PDF_Master.Views.Dialog.ServiceDialog;
using System.Diagnostics;
using System.Resources;
using System.Reflection;
using Microsoft.AppCenter;
using System.Globalization;
using Microsoft.AppCenter.Analytics;
using Microsoft.AppCenter.Crashes;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using Prism.Services.Dialogs;
using NetSparkleUpdater;
using NetSparkleUpdater.SignatureVerifiers;
using System.Threading;
using PDF_Master.Views.HomePanel.PDFTools;
using PDF_Master.Views.HomePanel.ChatGPTAI;
using PDF_Master.Views.Dialog.ChatGPTAIDialogs;
namespace PDF_Master
{
///
/// App.xaml 的交互逻辑
///
public partial class App : PrismApplication
{
///
/// 产品名称
///
public static string Name = "PDF Master";
///
/// 新建文档未保存时,文档的临时命名
///
public static string UntitledFileNmae = "Document.pdf";
public static string CurrentPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), Name);
public static List NeedOpenFilePathList = new List();
///
/// 项目内嵌文档路径 实际打开文档时,会将改文档复制到Document 文件夹下,避免C盘文件无法写入的情况
///
public static string GuidPDFPath;
///
/// 是否需要更新内嵌文档
///
public static bool IsGuidPDFUpdated = false;
///
/// 当前app版本号
///
public static string Version = FileVersionInfo.GetVersionInfo(Process.GetCurrentProcess().MainModule.FileName).ProductVersion;
public static MainWindowViewModel mainWindowViewModel;
///
/// 当前软件已打开的文件路径列表
///
public static List OpenedFileList = new List();
public static CacheFilePath CachePath;
///
/// OCR数据模型所在目录
///
public static string modelFolderPath = null;
public static SparkleUpdater SparkleUpdateDetector;
///
/// 是否是软件的第一个主窗体
///
public static bool IsFirstOpen = true;
///
/// 是否获取了SDK支持的系统字体
///
public static bool IsGetTextFamily = false;
///
/// 激活窗体的原因
///
public static string WebOpencase = "";
public static bool IsBookMode = false;
public static bool UserOpen = false;
public static bool LoginOpen = false;
///
/// 是否使用过高级功能
///
public static bool IsUsedVIP = false;
///
/// 是否已经登陆
///
public static bool IsLogin = false;
///
/// 记录开始拖拽的窗口句柄,用于判断是否为跨窗口拖拽
///
public static MainWindow DropStartWindow = null;
///
/// 双击打开文件通知ID
///
public static uint MsgId;
///
/// 将应用前置通知ID
///
public static uint WakeId;
///
/// 网页查看账单信息token失效唤起
///
public static uint WebopenexpiredId;
//App当前系统语言
public static string CultureLanguage;
///
/// 文案资源管理器 首页
///
public static ResourceManager HomePageLoader = new ResourceManager("PDF_Master.Strings.HomePage.HomePage", Assembly.GetExecutingAssembly());
///
/// 文案资源管理器 阅读页
///
public static ResourceManager MainPageLoader = new ResourceManager("PDF_Master.Strings.MainPage.MainPage", Assembly.GetExecutingAssembly());
///
/// 文案资源管理器 注册相关
///
public static ResourceManager ServiceLoader = new ResourceManager("PDF_Master.Strings.Service.Service", Assembly.GetExecutingAssembly());
public App()
{
#if !DEBUG
//接入Appcenter后台数据检测 PDF Reader Pro Test
string appkey = "260c4a7f-6986-4d5c-b201-cd50a46cc243";
AppCenter.Start(appkey, typeof(Analytics), typeof(Crashes));
var countryCode = RegionInfo.CurrentRegion.TwoLetterISORegionName;//上传国家信息
AppCenter.SetCountryCode(countryCode);
#endif
//增加全局异常捕获
//UI线程异常
this.DispatcherUnhandledException += App_DispatcherUnhandledException;
//非UI线程异常
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
//Task线程内
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
CultureLanguage = System.Globalization.CultureInfo.CurrentUICulture.ToString();
}
private void InitSettings()
{
//是否是更新后
if (Settings.Default.UpdateSettings)
{
//内嵌文档更新时 显示文档到最前方
//每次版本更新留意检查IsGuidPDFUpdated 值,如果没有内嵌文档更新,要设为false
if (Settings.Default.IsGuidPDFUpdated)
{
App.IsGuidPDFUpdated = true;
Settings.Default.IsGuidPDFUpdated = false;
}
Settings.Default.Upgrade();
Settings.Default.UpdateSettings = false;
//重置用于弹窗的记录参数
}
if (Settings.Default.ADDate == null)
{
Settings.Default.ADDate = new PDFSettings.ADDate();
}
if (Settings.Default.PDFEditList == null)
{
Settings.Default.PDFEditList = new PDFSettings.PDFEditList();
}
if (Settings.Default.UserDate == null)
{
Settings.Default.UserDate = new PDFSettings.UserDate();
}
if (Settings.Default.AppProperties == null)
{
Settings.Default.AppProperties = new PDFSettings.APPSettingProperties();
}
if (Settings.Default.RecentOpenFiles == null)
{
Settings.Default.RecentOpenFiles = new RecentOpenFiles();
}
if (Settings.Default.RedactionsSettings == null)
Settings.Default.RedactionsSettings = new PDFSettings.RedactionSettings();
if (Settings.Default.AppProperties == null)
Settings.Default.AppProperties = new PDFSettings.APPSettingProperties();
if (Settings.Default.AllPDFToolsList == null)
Settings.Default.AllPDFToolsList = new PDFSettings.AllPDFToolsList();
if (Settings.Default.QuickPDFToolsList == null)
Settings.Default.QuickPDFToolsList = new PDFSettings.QuickPDFToolsList();
if (Settings.Default.PresetFontList == null)
Settings.Default.PresetFontList = new PDFSettings.PresetFontList();
}
protected override void OnStartup(StartupEventArgs e)
{
MsgId = Win32Helper.RegisterWindowMessage("msgNotify_PDFMaster");
WakeId = Win32Helper.RegisterWindowMessage("msgWake_PDFMaster");
WakeId = Win32Helper.RegisterWindowMessage("webopenexpired_PDFMaster");
Process[] pros = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
//禁止多开程序
if (pros.Length > 1)
{
if (e != null && e.Args != null && e.Args.Length > 0)
{
if (Webgoapp(e.Args)==true)
{
if(WebOpencase=="expired")
{
Win32Helper.PostMessage((IntPtr)0xffff,WebopenexpiredId, IntPtr.Zero, IntPtr.Zero);
IntPtr waitPtr = Win32Helper.CreateEvent(IntPtr.Zero, true, false, "Global\\shareWaitNotify" + Guid.NewGuid());
Win32Helper.WaitForSingleObject(waitPtr, 5000);
Win32Helper.CloseHandle(waitPtr);
}
else
{
Win32Helper.PostMessage((IntPtr)0xffff, WakeId, IntPtr.Zero, IntPtr.Zero);
IntPtr waitPtr = Win32Helper.CreateEvent(IntPtr.Zero, true, false, "Global\\shareWaitNotify" + Guid.NewGuid());
Win32Helper.WaitForSingleObject(waitPtr, 5000);
Win32Helper.CloseHandle(waitPtr);
}
}
else
{
foreach (var filePath in e.Args)
{
if (filePath.ToLower().Contains(".pdf") && Path.GetExtension(filePath).ToLower() == ".pdf")
{
try
{
uint mapSize = 1024;
IntPtr mapHandle = Win32Helper.CreateFileMapping(IntPtr.Zero, IntPtr.Zero, Win32Helper.FileMapProtection.PageReadWrite, 0, mapSize, "Global\\sharePathNotify");
if (mapHandle != IntPtr.Zero)
{
IntPtr writePtr = Win32Helper.MapViewOfFileEx(mapHandle, Win32Helper.FileMapAccessType.Read | Win32Helper.FileMapAccessType.Write, 0, 0, UIntPtr.Zero, IntPtr.Zero);
Marshal.Copy(filePath.ToCharArray(), 0, writePtr, filePath.Length);
MD5 currMd5 = MD5.Create();
byte[] hashArray = currMd5.ComputeHash(Encoding.Default.GetBytes(filePath));
StringBuilder hexBuilder = new StringBuilder();
foreach (byte code in hashArray)
{
hexBuilder.AppendFormat("{0:X2}", code);
}
IntPtr waitPtr = Win32Helper.CreateEvent(IntPtr.Zero, true, false, "Global\\shareWaitNotify" + hexBuilder.ToString());
if (waitPtr != IntPtr.Zero)
{
Win32Helper.PostMessage((IntPtr)0xffff, MsgId, IntPtr.Zero, (IntPtr)filePath.Length);
Win32Helper.WaitForSingleObject(waitPtr, 5000);
Win32Helper.CloseHandle(waitPtr);
}
Win32Helper.UnmapViewOfFile(writePtr);
Win32Helper.CloseHandle(mapHandle);
}
}
catch
{
}
}
}
}
}
else
{
//进程置于前台
Win32Helper.PostMessage((IntPtr)0xffff, WakeId, IntPtr.Zero, IntPtr.Zero);
IntPtr waitPtr = Win32Helper.CreateEvent(IntPtr.Zero, true, false, "Global\\shareWaitNotify" + Guid.NewGuid());
Win32Helper.WaitForSingleObject(waitPtr, 5000);
Win32Helper.CloseHandle(waitPtr);
}
Environment.Exit(1);
return;
}
if (!LicenseVerify())
{
#if !DEBUG
//部分人员没有转档库密钥,为避免弹窗影响正常的功能开发、调试。本弹窗仅在Release模式下弹出,用于正式包
System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
{
AlertsMessage alertsMessage = new AlertsMessage();
alertsMessage.ShowDialog("",App.MainPageLoader.GetString("SDKLoadingFailed"), App.ServiceLoader.GetString("Text_ok"));
Environment.Exit(1);
return;
}));
#endif
}
InitSettings();
#if DEBUG
IsLogin =false;
#endif
CachePath = CacheFilePath.Instance;
//清除临时文件
CacheFilePath.Instance.ClearDeleteFiles();
try
{
DirectoryInfo info = new DirectoryInfo(CurrentPath);
//避免因存在同名文件,导致无法创建文件夹
if (File.Exists(CurrentPath))
{
File.Delete(CurrentPath);
}
if (!info.Exists)
{
info.Create();
}
//复制项目的新手引导文档到Document 目录
string guidfilePath = Path.Combine(CachePath.GuidPDFPath, "Quick Start Guide.pdf");
if (!File.Exists(guidfilePath) || App.IsGuidPDFUpdated)
{
//Document 路径下没有内嵌文档或者内嵌文档版本更新时
File.Copy(Path.Combine(Environment.CurrentDirectory, "Resources\\GuidPDF\\Quick Start Guide.pdf"), guidfilePath, true);
GuidPDFPath = guidfilePath;
}
//如果内嵌文档更新了,记录置顶
if (App.IsGuidPDFUpdated)
{
SettingHelper.SortRecentOpenFiles(GuidPDFPath);
}
//如果如果缓存被清空,但是缓存文档还在时,更新变量
if (string.IsNullOrEmpty(GuidPDFPath))
{
GuidPDFPath = Path.Combine(CachePath.GuidPDFPath, "Quick Start Guide.pdf");
}
}
catch
{
}
#region 设置软件语系
List lang = new List() { "zh-CN", "zh-TW", "en-US" };
CultureInfo cultureInfo = new CultureInfo("en-US");
//if (lang.Contains(Settings.Default.AppProperties.culture))
//{
// cultureInfo = new CultureInfo(Settings.Default.AppProperties.culture);
//}
//以防万一 极少数机器可能报错
try
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo(cultureInfo.Name);
Thread.CurrentThread.CurrentCulture = new CultureInfo(cultureInfo.Name);
}
catch { }
#endregion
//启动循环检查更新线程
CheckUpdate();
//双击文件 打开软件时
foreach (var filePath in e.Args)
{
if (filePath.ToLower().Contains(".pdf"))
{
if (filePath.Substring(filePath.LastIndexOf(".")).ToLower() == ".pdf")
{
NeedOpenFilePathList.Add(filePath);
}
}
}
base.OnStartup(e);
}
///
/// 解析是否带参数启动
///
///
///
public static bool Webgoapp(string[] args)
{
bool flg = false;
if (args.Length > 0)
{
string url = args[0];
string[] urlParts = url.Split(new char[] { '?', '&' });
Dictionary parameters = new Dictionary();
foreach (string part in urlParts.Skip(1))
{
string[] keyValue = part.Split('=');
if (keyValue.Length > 0)
{
flg = true;
string key = keyValue[0];
string value = Uri.UnescapeDataString(keyValue[1]); // 对参数值进行URL解码
WebOpencase = value;
}
}
}
return flg;
}
private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
#if DEBUG
var ex = e.Exception as Exception;
if (ex != null)
{
MessageBox.Show("发生Task未处理异常:" + ex.Message + "\n" + ex.StackTrace, "系统错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
#else
if (e.Exception is System.Exception)
{
Crashes.TrackError(e.Exception as Exception);
}
#endif
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
#if DEBUG
if (e.ExceptionObject is System.Exception)
{
Exception ex = (System.Exception)e.ExceptionObject;
MessageBox.Show("发生非UI线程异常:" + ex.Message + "\n" + ex.StackTrace, "系统错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
#else
if (e.ExceptionObject is System.Exception)
{
Crashes.TrackError(e.ExceptionObject as Exception);
}
#endif
}
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
#if DEBUG
e.Handled = true;
MessageBox.Show("发生UI线程异常:" + e.Exception.Message + "\n" + e.Exception.StackTrace, "系统错误", MessageBoxButton.OK, MessageBoxImage.Error);
#else
e.Handled = true;
Crashes.TrackError(e.Exception);
#endif
}
///
/// 创建启动窗口
///
///
protected override Window CreateShell()
{
return Container.Resolve();
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
#region 注册内容组件
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation("Cloud");
containerRegistry.RegisterForNavigation("Tools");
containerRegistry.RegisterForNavigation("Guid");
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
//填写与签名
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
//Form表单
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
//Tip
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
//轻会员
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
#endregion 注册内容组件
#region 注册弹窗
containerRegistry.RegisterDialog(DialogNames.VerifyPassWordDialog);
containerRegistry.RegisterDialog(DialogNames.FullScreenDialog);
containerRegistry.RegisterDialog(DialogNames.CompressDialog);
containerRegistry.RegisterDialog(DialogNames.MergeDialog);
containerRegistry.RegisterDialog(DialogNames.SetPasswordDialog);
containerRegistry.RegisterDialog(DialogNames.CheckPasswordDialog);
containerRegistry.RegisterDialog(DialogNames.DeleteSafetySettingsDialog);
containerRegistry.RegisterDialog(DialogNames.CompressProgressBarDialog);
containerRegistry.RegisterDialog(DialogNames.InsertDialog);
containerRegistry.RegisterDialog(DialogNames.SplitDialog);
containerRegistry.RegisterDialog(DialogNames.ExtractDialog);
containerRegistry.RegisterDialog(DialogNames.HomePageExtractDialog);
containerRegistry.RegisterDialog(DialogNames.HomePageInsertDialog);
containerRegistry.RegisterDialog(DialogNames.HomePageSplitDialog);
containerRegistry.RegisterDialog(DialogNames.HomePagePrinterDialog);
containerRegistry.RegisterDialog(DialogNames.HomePagePrinterPaperSettingsDialog);
containerRegistry.RegisterDialog(DialogNames.HomePagePictureToPDFDialog);
containerRegistry.RegisterDialog(DialogNames.HomePageBatchProcessingDialog);
containerRegistry.RegisterDialog(DialogNames.DynamicPropertyDialog);
containerRegistry.RegisterDialog(DialogNames.CustomCreateDialog);
containerRegistry.RegisterDialog(DialogNames.SignatureCreateDialog);
containerRegistry.RegisterDialog(DialogNames.ConverterCSVDialog);
containerRegistry.RegisterDialog(DialogNames.ConverterPPTDialog);
containerRegistry.RegisterDialog(DialogNames.ConverterTextDialog);
containerRegistry.RegisterDialog(DialogNames.ConverterWordDialog);
containerRegistry.RegisterDialog(DialogNames.ConverterHTMLDialog);
containerRegistry.RegisterDialog(DialogNames.ConverterImgDialog);
containerRegistry.RegisterDialog(DialogNames.ConverterRTFDialog);
containerRegistry.RegisterDialog(DialogNames.ConverterExcelDialog);
containerRegistry.RegisterDialog(DialogNames.ConverterProgressBarDialog);
containerRegistry.RegisterDialog(DialogNames.ScreenAnnotationDialog);
containerRegistry.RegisterDialog(DialogNames.AddBookmarkDialog);
containerRegistry.RegisterDialog(DialogNames.AddAnnotationDialog);
containerRegistry.RegisterDialog(DialogNames.EditPresetColorsDialog);
containerRegistry.RegisterDialog(DialogNames.CreateFromHtmlDialog);
containerRegistry.RegisterDialog(DialogNames.CreateFromScannerDialogs);
//标记密文弹窗
containerRegistry.RegisterDialog(DialogNames.MarkSettingDialog);
containerRegistry.RegisterDialog(DialogNames.PageMarkDialog);
containerRegistry.RegisterDialog(DialogNames.RepeatMarkDialog);
containerRegistry.RegisterDialog(DialogNames.SettingsDialog);
containerRegistry.RegisterDialog(DialogNames.PropertyDialog);
//轻会员弹窗
containerRegistry.RegisterDialog(DialogNames.RegisterDialog);
containerRegistry.RegisterDialog(DialogNames.LoginDialog);
containerRegistry.RegisterDialog(DialogNames.UserDialog);
containerRegistry.RegisterDialog(DialogNames.UserOutingLogin);
containerRegistry.RegisterDialog(DialogNames.RegisterOKRegion);
containerRegistry.RegisterDialog(DialogNames.SubscriptionDialog);
containerRegistry.RegisterDialog(DialogNames.SubscriptionOKDialog);
containerRegistry.RegisterDialog(DialogNames.LoginoffDialog);
//新手引导弹窗
containerRegistry.RegisterDialog(DialogNames.GuidDialog);
containerRegistry.RegisterDialog(DialogNames.IAPCompareDialog);
//关于弹窗
containerRegistry.RegisterDialog(DialogNames.AboutDialog);
containerRegistry.Register();
//chatgtp
containerRegistry.RegisterDialog(DialogNames.DocumentaryTranslation);
containerRegistry.RegisterDialog(DialogNames.SelectedTranslation);
//OCR下载弹窗
containerRegistry.RegisterDialog(DialogNames.OCRDownloadProgress);
#endregion 注册弹窗
}
protected override void ConfigureRegionAdapterMappings(RegionAdapterMappings regionAdapterMappings)
{
var region = new SingleActiveRegion() { Name = RegionNames.MainRegion };
region.Behaviors.Add(DragablzWindowBehavior.BehaviorKey, new DragablzWindowBehavior());
Container.Resolve().Regions.Add(region);
base.ConfigureRegionAdapterMappings(regionAdapterMappings);
}
///
/// 验证SDK和转档库密钥
///
///
private static bool LicenseVerify()
{
bool result = false;
try
{
result = CPDFSDKVerifier.LoadNativeLibrary();
if (!result)
{
Trace.WriteLine("CPDFSDK Load Failed.\n");
return false;
}
Trace.WriteLine("CPDFSDK Load Success.\n");
}
catch { Trace.WriteLine("CPDFSDK Load Error.\n"); }
SDKLisenceHelper sdkhelper = new SDKLisenceHelper();
string devKey = "";
string devSecret = "";
#if DEBUG
devKey = "ehrnKqkWc1XSEAWyPUt6+95GzCoLEyoKrCbsUuJkCqGmxmP5ozX4bS0R6crHItQVNTFvC5mBZ1M7QjJ6Ekdu4Daj7PM+EDLTBKbFJinK4Ri9E5E2X+a9vF5zSj0TkIscQPVnwj9ikxAFOWGIyybMwQQzwc8a4j1cGOqGXQRDMMY=";
devSecret = "mG0c3O3Mzeu5dkZJW3gpqq9uA7o7EGQveSC38Q8TK4gQurxTxGuBlGAhs0P1mD3X3bHT+AHfcLiymaqE4DY7kTFHoPs9I3tl5ErS+BHdzHRhrp9sGpqfp0B228KI+IMTu4aGVjtYuk+Uxs/kosIBw1367/WkJ00tM7U7tttD6ccHhEu996bvBgqf8Sw8OekQKQq13VBewK5AckaDux4W7SGRhCUNWC4MItkr36JnXMD2tiFQYzMG8C66HYmRGSLh";
#endif
devKey = sdkhelper.DevKey;
devSecret = sdkhelper.DevSecret;
string userKey = sdkhelper.UserKey;
string userSecret = sdkhelper.UserSecret;
try
{
LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(devKey, devSecret);
Trace.WriteLine("CPDFSDK License Code." + verifyResult + "\n");
if (verifyResult != LicenseErrorCode.LICENSE_ERR_SUCCESS)
return false;
}
catch { Trace.WriteLine("CPDFSDK License Code Error \n"); }
string ConverterDevKey = sdkhelper.ConverterDevKey;
string ConverterDevSecret = sdkhelper.ConverterDevSecret;
string ConverterUserkey = sdkhelper.ConverterUserkey;
string ConverterUserSecret = sdkhelper.ConverterUserSecret;
try
{
////加载OCR库
//if (!DocumentAIKitLicenseVerify())
//{
//}
/*LicenseError licenseerror = CPDFConverter.SDKLicenseVerify(ConverterDevKey, ConverterDevSecret, ConverterUserkey, ConverterUserSecret);
string resPath = Path.GetDirectoryName(typeof(MainWindow).Assembly.Location) + "\\";
if (licenseerror != LicenseError.ERR_SUCCESS)
{
return false;
}
CPDFConverter.Init(resPath);*/
string resPath = Path.GetDirectoryName(typeof(MainWindow).Assembly.Location) + "\\";
CPDFConverter.Init(resPath);
LicenseError licenseerror = CPDFConverter.LicenseVerify(ConverterDevKey, ConverterDevSecret);
//初始化ocr库
CPDFConverter.InitOCRLibrary(Path.Combine(resPath, "x64"));
//初始化资源
CPDFConverter.SetOCRModelPath(Path.Combine(resPath, "source"));
if (licenseerror != LicenseError.ERR_SUCCESS)
{
//MessageBox.Show("ComPDFKit Conversion SDK Load Failed!");
Console.WriteLine("CPDFConvert Load Failed.\n");
return false;
}
//之前1.7.0逻辑
//CPDFConverter.Init(resPath);
//CPDFConverter.SetOCRModelFolder(modelFolderPath);
}
catch { }
return result;
}
///
/// 加载,验证DocumentAIKitLicense
/// 目前DocmentAILib暂时移动到X64(原来路径为 string libFolderPath = Path.Combine(exePath, "DocumentAILib");)
/// 含有的库有(ComDocumentAINative.dll,DocumentAI.dll,libiomp5md.dll,mkldnn.dll,mklml.dll,onnxruntime.dll,opencv_world420.dll,opencv_word420d.dll,paddle_inference.dll,paddle2onnx.dll)
///
///
private static bool DocumentAIKitLicenseVerify()
{
Task.Factory.StartNew(() =>
{
string exePath = Path.GetDirectoryName(typeof(MainWindow).Assembly.Location);
exePath = Path.Combine(exePath, "x64");
//string libFolderPath = Path.Combine(exePath, "DocumentAILib");
string libFolderPath = exePath;
modelFolderPath = Path.Combine(exePath, "models");
if (CDocumentAIKit.LoadNativeLibrary(libFolderPath) == false)
return;
CErrorCode error = CDocumentAIKit.LicenseVerify("1F8B0818801DD8F20000636F6D2E636F6D7064666B69742E636F6E76657273696F6E00344136353732364636443635353936313645363700011002EFFDC671954ADECE496F0D96F5C14D82A293CEC71744D0914A388C0FDECA16FC9B6D28694C762AC71F382D9E50B2E9473B431C8FE18D5656A52AB2FF2B06834B7AB87CFB42884BA59110642327D18D77BD13D2AC8EC3A06357000E315956673DC38A02F97AD29B24F421D82D9346A3737BFD806777769DFBA4D50B911E65F4FC674A6DCA1E53FE1F9A4A8DE987B41B143282D2286C22C29F69724A4BCA5C0BD3013DDA2207FFC10A385EF980D4547FD76A4B6EBDE54ACCE68B656621032EC146123B1E8DD9B1EF7F71725917D9CA58431601707A6BB1B41A82049FAF14599B34EAF7D59CD8E6CFEAB24AF5CDDCB2A2236E77710B7E30F10022F2F25EC6586D3B5207378F2CB8B9176EE463B1F2B1D8BD776142E8F9575235BE2A57A63948EDB05DED4649F410CE5941DA5155E6F5A127BFABC5E424F71A1AEB201595ECE8BC8C91DD1C0FF7300A4CB7253B6277CF8B8C5F3CDA5D569E2E27F1609815F9944816AD69550049D94C0FD263D2D3FCF4A3CE685C67F7E27F70E8D9332A45984E7F4D7F5D800BAA58D18715384B98BE310AEDCB4BCF4833E76A5E3860032B3A926DFD247FF426ADA94BA1DA7B11F0451AE506A93DD8B809453E5B51CBE24D572973A55FBD3D25453C3FAD47D30ACAB30500C15FD8714B365AA6F275808C9EB7D5116AC809C91786D6571E2622A5E730D40614061C3B3FC129108AA1360C16151CE38CA03FF3A28FFE7200B4FFA24EF7EDF54B8E9AB207E00810020000");
if (error != CErrorCode.E_DA_SUCCESS)
return;
});
return true;
}
private static void CheckUpdate()
{
try
{
string lang = "en_Us";
//暂时没有多语,固定检测英文环境更新
//lang = Settings.Default.AppProperties.culture;
switch (lang)
{
case "zh-CN":
lang = "zh_Hans";
break;
case "zh-TW":
lang = "zh_Hant";
break;
default:
lang = "en_Us";
break;
}
#if DEBUG
var appcastUrl = string.Format("http://test-pdf-pro.kdan.cn:3021/downloads/pdfmaster_win_{0}.xml", lang);
#else
var appcastUrl = string.Format("https://www.pdfreaderpro.com/downloads/pdfmaster_win_{0}.xml",lang);
#endif
// set icon in project properties!
string manifestModuleName = System.Reflection.Assembly.GetEntryAssembly().ManifestModule.FullyQualifiedName;
var icon = System.Drawing.Icon.ExtractAssociatedIcon(manifestModuleName);
//设为false 则显示立即购买按钮,设为true则不显示立即购买按钮
bool ispurchased = true;
SparkleUpdateDetector = new SparkleUpdater(appcastUrl, new DSAChecker(NetSparkleUpdater.Enums.SecurityMode.Unsafe), ispurchased)
{
UIFactory = new NetSparkleUpdater.UI.WinForms.UIFactory(icon, "PDF Master"),
//RelaunchAfterUpdate = true,
//ShowsUIOnMainThread = true,
//UseNotificationToast = true
};
SparkleUpdateDetector.SecurityProtocolType = System.Net.SecurityProtocolType.Tls12;
SparkleUpdateDetector.CloseApplication += SparkleUpdateDetector_CloseApplication;
SparkleUpdateDetector.StartLoop(true);
}
catch { }
}
private static void SparkleUpdateDetector_CloseApplication()
{
try
{
SparkleUpdateDetector.Dispose();
Current.Dispatcher.Invoke(() =>
{
Current.Shutdown();
});
}
catch
{
}
}
protected override void OnExit(ExitEventArgs e)
{
Environment.Exit(1);
base.OnExit(e);
}
}
}