Prechádzať zdrojové kódy

分包下载OCR-基本逻辑

liyijie 1 rok pred
rodič
commit
b0d80b3329

+ 6 - 4
PDF Office/Helper/FileComparisonHelper.cs

@@ -69,9 +69,11 @@ namespace PDF_Master.Helper
         public static bool OCRModelItExist()
         {
 
-            string folderPath = System.IO.Path.Combine(App.CurrentPath, "model");
+            string folderPath = System.IO.Path.Combine(App.CurrentPath, "OCREngine");
             if (Directory.Exists(folderPath))
             {
+                Settings.Default.AppProperties.OCRmodelMD5 = "65d21a699138c194f06a8640dd40a901";
+                Settings.Default.AppProperties.OCRFile_Url = "http://test-pdf-pro.kdan.cn:3021/downloads/OCREngine.zip";
                 if (!Getpdfreaderprocast())
                 {
                     return false;
@@ -100,12 +102,12 @@ namespace PDF_Master.Helper
         {
             try
             {
-                string folderPath = System.IO.Path.Combine(App.CurrentPath, "model");
+                string folderPath = System.IO.Path.Combine(App.CurrentPath, "OCREngine");
                 if (Directory.Exists(folderPath))
                 {
                     Directory.Delete(folderPath, true);
                 }
-                string folderzipPath = System.IO.Path.Combine(App.CurrentPath, "modelzip");
+                string folderzipPath = System.IO.Path.Combine(App.CurrentPath, "OCREnginezip");
                 if (Directory.Exists(folderzipPath))
                 {
                     Directory.Delete(folderzipPath, true);
@@ -173,7 +175,7 @@ namespace PDF_Master.Helper
                             return true;
                         }
                     }
-                    //return true;
+                    return false;
                 }
                 catch { return false; }
             }

+ 49 - 3
PDF Office/ViewModels/Dialog/ConverterDialogs/ConverterExcelDialogViewModel.cs

@@ -1,6 +1,8 @@
 using ComDocumentAIKit;
+using ComPDFKit_Conversion.Converter;
 using ComPDFKit_Conversion.Options;
 using ComPDFKitViewer.PdfViewer;
+using ImageMagick;
 using Microsoft.Office.Interop.Excel;
 using PDF_Master.CustomControl;
 using PDF_Master.Helper;
@@ -337,11 +339,13 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
         public DelegateCommand BatchConverterCommand { get; set; }
 
         public DelegateCommand<object> PreviewCancelDownCommand { get; set; }
-       
+
         public DelegateCommand SetCustomPageRangeCommand { get; set; }
 
         public DelegateCommand UnlockMouseDownCommand { get; set; }
 
+        public DelegateCommand OpenOCRCommand { get; set; }
+
         #endregion
 
         public ConverterExcelDialogViewModel(IDialogService dialogService)
@@ -356,11 +360,53 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
             PreviewCancelDownCommand = new DelegateCommand<object>(PreviewCancelDown);
             BatchConverterCommand = new DelegateCommand(BatchConverter);
             UnlockMouseDownCommand = new DelegateCommand(UnlockMouseDown);
-
+            OpenOCRCommand = new DelegateCommand(openOCR);
             dialogs = dialogService;
         }
         #region 逻辑函数
 
+        private void openOCR()
+        {
+            if (OCRCheckBoxIsCheckBox == true)
+            {
+                bool folderMD5 = FileComparisonHelper.OCRModelItExist();
+                if (folderMD5)
+                {
+                    string folderPath = System.IO.Path.Combine(App.CurrentPath, "OCREngine");
+                    CPDFConverter.InitOcrLibrary(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "x64"));
+                    CPDFConverter.SetOCRModelPath(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "source", "models"));
+                }
+                else
+                {
+                    AlertsMessage alertsMessage = new AlertsMessage();
+                    alertsMessage.ShowDialog("想用OCR,就去下载吧!", "", "取消", "确定");
+                    if (alertsMessage.result == ContentResult.Ok)
+                    {
+                        FileComparisonHelper.RemoveOCRModel();
+                        DialogParameters oCRDownloadProgress = new DialogParameters();
+                        dialogs.ShowDialog(DialogNames.OCRDownloadProgress, oCRDownloadProgress, e =>
+                        {
+
+                            if (e.Result == Prism.Services.Dialogs.ButtonResult.OK)
+                            {
+                                string folderPath = System.IO.Path.Combine(App.CurrentPath, "OCREngine");
+                                CPDFConverter.InitOcrLibrary(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "x64"));
+                                CPDFConverter.SetOCRModelPath(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "source", "models"));
+                            }
+                            else
+                            {
+                                OCRCheckBoxIsCheckBox = false;
+                            }
+                        });
+                    }
+                    else
+                    {
+                        OCRCheckBoxIsCheckBox = false;
+                    }
+                }
+            }
+        }
+
         public void SetCustomPageRange()
         {
             if (PageRangeSelectIndex == CheckPageSelect["4"])
@@ -664,7 +710,7 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
 
         private void SelectLanguage(int SelectedIndex)
         {
-       
+
             switch (SelectedIndex)
             {
                 case 0:

+ 47 - 0
PDF Office/ViewModels/Dialog/ConverterDialogs/ConverterHTMLDialogViewModel.cs

@@ -1,4 +1,5 @@
 using ComDocumentAIKit;
+using ComPDFKit_Conversion.Converter;
 using ComPDFKitViewer.PdfViewer;
 using PDF_Master.CustomControl;
 using PDF_Master.Helper;
@@ -165,6 +166,8 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
         public DelegateCommand BatchConverterCommand { get; set; }
 
         public DelegateCommand UnlockMouseDownCommand { get; set; }
+
+        public DelegateCommand OpenOCRCommand { get; set; }
         #endregion
 
         public ConverterHTMLDialogViewModel(IDialogService dialogService)
@@ -178,10 +181,54 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
             PreviewCancelDownCommand = new DelegateCommand<object>(PreviewCancelDown);
             BatchConverterCommand = new DelegateCommand(BatchConverter);
             UnlockMouseDownCommand = new DelegateCommand(UnlockMouseDown);
+            OpenOCRCommand = new DelegateCommand(openOCR);
             dialogs = dialogService;
 
         }
         #region 逻辑函数
+
+        private void openOCR()
+        {
+            if (OCRCheckBoxIsCheckBox == true)
+            {
+                bool folderMD5 = FileComparisonHelper.OCRModelItExist();
+                if (folderMD5)
+                {
+                    string folderPath = System.IO.Path.Combine(App.CurrentPath, "OCREngine");
+                    CPDFConverter.InitOcrLibrary(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "x64"));
+                    CPDFConverter.SetOCRModelPath(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "source", "models"));
+                }
+                else
+                {
+                    AlertsMessage alertsMessage = new AlertsMessage();
+                    alertsMessage.ShowDialog("想用OCR,就去下载吧!", "", "取消", "确定");
+                    if (alertsMessage.result == ContentResult.Ok)
+                    {
+                        FileComparisonHelper.RemoveOCRModel();
+                        DialogParameters oCRDownloadProgress = new DialogParameters();
+                        dialogs.ShowDialog(DialogNames.OCRDownloadProgress, oCRDownloadProgress, e =>
+                        {
+
+                            if (e.Result == Prism.Services.Dialogs.ButtonResult.OK)
+                            {
+                                string folderPath = System.IO.Path.Combine(App.CurrentPath, "OCREngine");
+                                CPDFConverter.InitOcrLibrary(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "x64"));
+                                CPDFConverter.SetOCRModelPath(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "source", "models"));
+                            }
+                            else
+                            {
+                                OCRCheckBoxIsCheckBox = false;
+                            }
+                        });
+                    }
+                    else
+                    {
+                        OCRCheckBoxIsCheckBox = false;
+                    }
+                }
+            }
+        }
+
         public void SetCustomPageRange()
         {
             if (PageRangeSelectIndex == "4")

+ 47 - 0
PDF Office/ViewModels/Dialog/ConverterDialogs/ConverterPPTDialogViewModel.cs

@@ -1,5 +1,7 @@
 using ComDocumentAIKit;
+using ComPDFKit_Conversion.Converter;
 using ComPDFKitViewer.PdfViewer;
+using ImageMagick;
 using PDF_Master.CustomControl;
 using PDF_Master.Helper;
 using PDF_Master.Model;
@@ -193,6 +195,8 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
         public DelegateCommand BatchConverterCommand { get; set; }
 
         public DelegateCommand UnlockMouseDownCommand { get; set; }
+
+        public DelegateCommand OpenOCRCommand { get; set; }
         #endregion
 
         public ConverterPPTDialogViewModel(IDialogService dialogService)
@@ -205,11 +209,54 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
             PreviewCancelDownCommand = new DelegateCommand<object>(PreviewCancelDown);
             BatchConverterCommand = new DelegateCommand(BatchConverter);
             UnlockMouseDownCommand = new DelegateCommand(UnlockMouseDown);
+            OpenOCRCommand = new DelegateCommand(openOCR);
             dialogs = dialogService;
             IntString();
         }
         #region 逻辑函数
 
+        private void openOCR()
+        {
+            if (OCRCheckBoxIsCheckBox == true)
+            {
+                bool folderMD5 = FileComparisonHelper.OCRModelItExist();
+                if (folderMD5)
+                {
+                    string folderPath = System.IO.Path.Combine(App.CurrentPath, "OCREngine");
+                    CPDFConverter.InitOcrLibrary(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "x64"));
+                    CPDFConverter.SetOCRModelPath(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "source", "models"));
+                }
+                else
+                {
+                    AlertsMessage alertsMessage = new AlertsMessage();
+                    alertsMessage.ShowDialog("想用OCR,就去下载吧!", "", "取消", "确定");
+                    if (alertsMessage.result == ContentResult.Ok)
+                    {
+                        FileComparisonHelper.RemoveOCRModel();
+                        DialogParameters oCRDownloadProgress = new DialogParameters();
+                        dialogs.ShowDialog(DialogNames.OCRDownloadProgress, oCRDownloadProgress, e =>
+                        {
+
+                            if (e.Result == Prism.Services.Dialogs.ButtonResult.OK)
+                            {
+                                string folderPath = System.IO.Path.Combine(App.CurrentPath, "OCREngine");
+                                CPDFConverter.InitOcrLibrary(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "x64"));
+                                CPDFConverter.SetOCRModelPath(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "source", "models"));
+                            }
+                            else
+                            {
+                                OCRCheckBoxIsCheckBox = false;
+                            }
+                        });
+                    }
+                    else
+                    {
+                        OCRCheckBoxIsCheckBox = false;
+                    }
+                }
+            }
+        }
+
         public void SetCustomPageRange()
         {
             if (PageRangeSelectIndex == CheckPageSelect["4"])

+ 47 - 0
PDF Office/ViewModels/Dialog/ConverterDialogs/ConverterRTFDialogViewModel.cs

@@ -1,4 +1,5 @@
 using ComDocumentAIKit;
+using ComPDFKit_Conversion.Converter;
 using ComPDFKitViewer.PdfViewer;
 using PDF_Master.CustomControl;
 using PDF_Master.Helper;
@@ -165,6 +166,8 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
         public DelegateCommand BatchConverterCommand { get; set; }
 
         public DelegateCommand UnlockMouseDownCommand { get; set; }
+
+        public DelegateCommand OpenOCRCommand { get; set; }
         #endregion
 
         public ConverterRTFDialogViewModel(IDialogService dialogService)
@@ -177,11 +180,55 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
             PreviewCancelDownCommand = new DelegateCommand<object>(PreviewCancelDown);
             BatchConverterCommand = new DelegateCommand(BatchConverter);
             UnlockMouseDownCommand = new DelegateCommand(UnlockMouseDown);
+            OpenOCRCommand = new DelegateCommand(openOCR);
             dialogs = dialogService;
             IntString();
         }
 
         #region 逻辑函数
+
+        private void openOCR()
+        {
+            if (OCRCheckBoxIsCheckBox == true)
+            {
+                bool folderMD5 = FileComparisonHelper.OCRModelItExist();
+                if (folderMD5)
+                {
+                    string folderPath = System.IO.Path.Combine(App.CurrentPath, "OCREngine");
+                    CPDFConverter.InitOcrLibrary(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "x64"));
+                    CPDFConverter.SetOCRModelPath(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "source", "models"));
+                }
+                else
+                {
+                    AlertsMessage alertsMessage = new AlertsMessage();
+                    alertsMessage.ShowDialog("想用OCR,就去下载吧!", "", "取消", "确定");
+                    if (alertsMessage.result == ContentResult.Ok)
+                    {
+                        FileComparisonHelper.RemoveOCRModel();
+                        DialogParameters oCRDownloadProgress = new DialogParameters();
+                        dialogs.ShowDialog(DialogNames.OCRDownloadProgress, oCRDownloadProgress, e =>
+                        {
+
+                            if (e.Result == Prism.Services.Dialogs.ButtonResult.OK)
+                            {
+                                string folderPath = System.IO.Path.Combine(App.CurrentPath, "OCREngine");
+                                CPDFConverter.InitOcrLibrary(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "x64"));
+                                CPDFConverter.SetOCRModelPath(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "source", "models"));
+                            }
+                            else
+                            {
+                                OCRCheckBoxIsCheckBox = false;
+                            }
+                        });
+                    }
+                    else
+                    {
+                        OCRCheckBoxIsCheckBox = false;
+                    }
+                }
+            }
+        }
+
         public void SetCustomPageRange()
         {
             if (PageRangeSelectIndex == "4")

+ 52 - 3
PDF Office/ViewModels/Dialog/ConverterDialogs/ConverterTextDialogViewModel.cs

@@ -1,4 +1,5 @@
 using ComDocumentAIKit;
+using ComPDFKit_Conversion.Converter;
 using ComPDFKitViewer.PdfViewer;
 using PDF_Master.CustomControl;
 using PDF_Master.Helper;
@@ -167,6 +168,8 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
         public DelegateCommand BatchConverterCommand { get; set; }
 
         public DelegateCommand UnlockMouseDownCommand { get; set; }
+
+        public DelegateCommand OpenOCRCommand { get; set; }
         #endregion
 
         public ConverterTextDialogViewModel(IDialogService dialogService)
@@ -180,9 +183,55 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
             PreviewCancelDownCommand = new DelegateCommand<object>(PreviewCancelDown);
             BatchConverterCommand = new DelegateCommand(BatchConverter);
             UnlockMouseDownCommand = new DelegateCommand(UnlockMouseDown);
+            OpenOCRCommand = new DelegateCommand(openOCR);
             dialogs = dialogService;
         }
         #region 逻辑函数
+
+        private void openOCR()
+        {
+            if (OCRCheckBoxIsCheckBox == true)
+            {
+                bool folderMD5 = FileComparisonHelper.OCRModelItExist();
+                if (folderMD5)
+                {
+                    string folderPath = System.IO.Path.Combine(App.CurrentPath, "OCREngine");
+                    CPDFConverter.InitOcrLibrary(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "x64"));
+                    CPDFConverter.SetOCRModelPath(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "source", "models"));
+                }
+                else
+                {
+                    AlertsMessage alertsMessage = new AlertsMessage();
+                    alertsMessage.ShowDialog("想用OCR,就去下载吧!", "", "取消", "确定");
+                    if (alertsMessage.result == ContentResult.Ok)
+                    {
+                        FileComparisonHelper.RemoveOCRModel();
+                        DialogParameters oCRDownloadProgress = new DialogParameters();
+                        dialogs.ShowDialog(DialogNames.OCRDownloadProgress, oCRDownloadProgress, e =>
+                        {
+
+                            if (e.Result == Prism.Services.Dialogs.ButtonResult.OK)
+                            {
+                                string folderPath = System.IO.Path.Combine(App.CurrentPath, "OCREngine");
+                                CPDFConverter.InitOcrLibrary(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "x64"));
+                                CPDFConverter.SetOCRModelPath(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "source", "models"));
+                            }
+                            else
+                            {
+                                OCRCheckBoxIsCheckBox = false;
+                            }
+                        });
+                    }
+                    else
+                    {
+                        OCRCheckBoxIsCheckBox = false;
+                    }
+                }
+
+            }
+
+        }
+
         public void SetCustomPageRange()
         {
             if (PageRangeSelectIndex == "4")
@@ -224,7 +273,7 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
             }
         }
 
-        private  void converter()
+        private void converter()
         {
             if (PageRangeSelectIndex == "4")
             {
@@ -282,7 +331,7 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
             {
                 return;
             }
-            HomePageEditHelper.GetPagerange(PageRangeSelectIndex, currentViewer, ref ConverterTextModel.PageRange, PageRangeText,true, CurrentPageIndex);
+            HomePageEditHelper.GetPagerange(PageRangeSelectIndex, currentViewer, ref ConverterTextModel.PageRange, PageRangeText, true, CurrentPageIndex);
             if (ConverterTextModel.PageRange == "")
             {
                 Trace.WriteLine("输入不对");
@@ -468,7 +517,7 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
                 if (currentViewer.Tag != null) { ConverterTextModel.Pawssword = currentViewer.Tag.ToString(); }
                 ConverterTextModel.InputPath = pdfViewer.Document.FilePath;
                 FileInfo fileinfo = new FileInfo(ConverterTextModel.InputPath);
-                ConverterTextModel.OutputPath=fileinfo.DirectoryName;
+                ConverterTextModel.OutputPath = fileinfo.DirectoryName;
                 if (Settings.Default.UserDate.subscribestatus != 1)
                 {
                     LimitationsConvertVisible = Visibility.Visible;

+ 53 - 6
PDF Office/ViewModels/Dialog/ConverterDialogs/ConverterWordDialogViewModel.cs

@@ -2,6 +2,7 @@
 using ComPDFKit_Conversion.Converter;
 using ComPDFKit_Conversion.Options;
 using ComPDFKitViewer.PdfViewer;
+using ImageMagick;
 using PDF_Master.CustomControl;
 using PDF_Master.EventAggregators;
 using PDF_Master.Helper;
@@ -125,9 +126,6 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
             set
             {
                 SetProperty(ref oCRCheckBoxIsCheckBox, value);
-                //测试代码,到时候需要去除
-                //CPDFConverter.InitOcrLibrary(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\ConvertAndOCRSource", "x64"));
-                //CPDFConverter.SetOCRModelPath(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\ConvertAndOCRSource", "source", "models"));
                 ConverterWordModel.Options.IsAllowOCR = oCRCheckBoxIsCheckBox;
             }
         }
@@ -201,6 +199,8 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
 
         public DelegateCommand UnlockMouseDownCommand { get; set; }
 
+        public DelegateCommand OpenOCRCommand { get; set; }
+
         #endregion
 
         public ConverterWordDialogViewModel(IDialogService dialogService)
@@ -214,11 +214,57 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
             BatchConverterCommand = new DelegateCommand(BatchConverter);
             PreviewCancelDownCommand = new DelegateCommand<object>(PreviewCancelDown);
             UnlockMouseDownCommand = new DelegateCommand(UnlockMouseDown);
+            OpenOCRCommand = new DelegateCommand(openOCR);
             dialogs = dialogService;
             IntString();
         }
         #region 逻辑函数
 
+
+        private void openOCR()
+        {
+            if (OCRCheckBoxIsCheckBox == true)
+            {
+                bool folderMD5 = FileComparisonHelper.OCRModelItExist();
+                if (folderMD5)
+                {
+                    string folderPath = System.IO.Path.Combine(App.CurrentPath, "OCREngine");
+                    CPDFConverter.InitOcrLibrary(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "x64"));
+                    CPDFConverter.SetOCRModelPath(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "source", "models"));
+                }
+                else
+                {
+                    AlertsMessage alertsMessage = new AlertsMessage();
+                    alertsMessage.ShowDialog("想用OCR,就去下载吧!", "", "取消", "确定");
+                    if (alertsMessage.result == ContentResult.Ok)
+                    {
+                        FileComparisonHelper.RemoveOCRModel();
+                        DialogParameters oCRDownloadProgress = new DialogParameters();
+                        dialogs.ShowDialog(DialogNames.OCRDownloadProgress, oCRDownloadProgress, e =>
+                        {
+
+                            if (e.Result == Prism.Services.Dialogs.ButtonResult.OK)
+                            {
+                                string folderPath = System.IO.Path.Combine(App.CurrentPath, "OCREngine");
+                                CPDFConverter.InitOcrLibrary(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "x64"));
+                                CPDFConverter.SetOCRModelPath(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\OCREngine", "source", "models"));
+                            }
+                            else
+                            {
+                                OCRCheckBoxIsCheckBox = false;
+                            }
+                        });
+                    }
+                    else
+                    {
+                        OCRCheckBoxIsCheckBox = false;
+                    }
+                }
+
+            }
+
+        }
+
         public void SetCustomPageRange()
         {
             if (PageRangeSelectIndex == CheckPageSelect["4"])
@@ -311,13 +357,14 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
             if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
             {
                 ConverterWordModel.OutputPath = sfd.FileName;
-                try {if(File.Exists(ConverterWordModel.OutputPath)) File.Delete(ConverterWordModel.OutputPath); }
-                catch {
+                try { if (File.Exists(ConverterWordModel.OutputPath)) File.Delete(ConverterWordModel.OutputPath); }
+                catch
+                {
                     AlertsMessage alertsMessage = new AlertsMessage();
                     alertsMessage.ShowDialog("", App.MainPageLoader.GetString("FileNotExistWarning"), App.ServiceLoader.GetString("Text_ok"));
                     return;
                 }
-               
+
             }
             else
             {

+ 19 - 63
PDF Office/ViewModels/Dialog/ConverterDialogs/OCRDownloadProgressViewModel.cs

@@ -2,6 +2,7 @@
 using Microsoft.Office.Interop.Excel;
 using PDF_Master.CustomControl;
 using PDF_Master.Helper;
+using PDF_Master.Model;
 using PDF_Master.Properties;
 using PDF_Master.Strings.MainPage;
 using Prism.Commands;
@@ -72,7 +73,7 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
             T_ProgressBarName = App.MainPageLoader.GetString("OCR_Downloading");
             T_tryAgainBtn = App.MainPageLoader.GetString("OCR_DownloadRedownload");
             T_ErrorTextBlock = App.MainPageLoader.GetString("OCR_DownloadError");
-            T_CancelBtn= App.MainPageLoader.GetString("OCR_CancelDownload");
+            T_CancelBtn = App.MainPageLoader.GetString("OCR_CancelDownload");
 
         }
 
@@ -116,11 +117,7 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
 
         private double currentSize;
 
-        //home 是false
-        private bool SelectHomeOrmain = false;
-
-
-        private string progressBarCurrentSizeValue="0 MB";
+        private string progressBarCurrentSizeValue = "0 MB";
 
         public string ProgressBarCurrentSizeValue
         {
@@ -131,7 +128,7 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
             }
         }
 
-        private string progressBarFileSize="0 MB";
+        private string progressBarFileSize = "0 MB";
 
         public string ProgressBarFileSize
         {
@@ -163,11 +160,11 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
 
         public OCRDownloadProgressViewModel()
         {
-            CancelCommand= new DelegateCommand(cancel);
-            TryAgainCommnad= new DelegateCommand(tryAgain);
+            CancelCommand = new DelegateCommand(cancel);
+            TryAgainCommnad = new DelegateCommand(tryAgain);
         }
 
-        private async void  tryAgain()
+        private async void tryAgain()
         {
             try
             {
@@ -200,9 +197,9 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
                 await Task.Run(() =>
                 {
 
-                    string folder = System.IO.Path.Combine(App.CurrentPath, "modelzip");
+                    string folder = System.IO.Path.Combine(App.CurrentPath, "OCREnginezip");
 
-                    FileNameComPDFKit = folder + "\\" + "model" + ".zip";
+                    FileNameComPDFKit = folder + "\\" + "OCREngine" + ".zip";
                     long fileSize = 0;
                     if (!Directory.Exists(folder))
                     {
@@ -250,7 +247,7 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
             string folderPath = App.CurrentPath;
             //解压转档资源文件,intiRes
             string folderModelPath = App.CurrentPath;
-            if (!Directory.Exists(folderModelPath + "//model"))
+            if (!Directory.Exists(folderModelPath + "//OCREngine"))
             {
                 ExtractWithProgress(FileNameComPDFKit, folderModelPath);
             }
@@ -303,39 +300,21 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
                     {
                         ProgressBarCurrentValue = 0;
                         ProgressBarCurrentSizeValue = (currentSize * (ProgressBarCurrentValue / 100)).ToString("0.00") + " MB";
-                        string folderzipPath = System.IO.Path.Combine(App.CurrentPath, "modelzip");
+                        string folderzipPath = System.IO.Path.Combine(App.CurrentPath, "OCREnginezip");
                         if (Directory.Exists(folderzipPath))
                         {
                             Directory.Delete(folderzipPath, true);
                         }
-                        //Close();
+                        //Close()
                         if (FileComparisonHelper.OCRModelItExist())
                         {
-                            if (SelectHomeOrmain)
-                            {
-                                if (mainPage != null)
-                                {
-                                    //mainPage.ShowOCRDialog(isItemClieck);
-                                }
-
-                            }
-                            else
-                            {
-                                //新OCR弹窗
-                                //ConvertOCRNewDialog convertOCRNewDialog = new ConvertOCRNewDialog();
-                                //convertOCRNewDialog.InitBeforeShow(Pdfviewer, password);
-                                //convertOCRNewDialog.Owner = App.Current.MainWindow;
-                                //convertOCRNewDialog.ShowDialog();
-                                //ConvertOCRDialog dialog = new ConvertOCRDialog();
-                                //dialog.InitBeforeShow(Pdfviewer, password);
-                                //dialog.StartPosition = FormStartPosition.CenterScreen;
-                                //dialog.ShowDialog();
-
-                            }
+                            var dialogresult = new DialogResult(ButtonResult.OK);
+                            //dialogresult.Parameters.Add(ParameterNames.ConverterType, "Img");
+                            RequestClose.Invoke(dialogresult);
                         }
                         else
                         {
-                            string folderPath = System.IO.Path.Combine(App.CurrentPath, "model");
+                            string folderPath = System.IO.Path.Combine(App.CurrentPath, "OCREngine");
                             if (Directory.Exists(folderPath))
                             {
                                 Directory.Delete(folderPath, true);
@@ -397,30 +376,6 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
             }
         }
 
-        public bool? ShowDialog(MainPage mainPage, bool isItemClieck)
-        {
-            this.mainPage = mainPage;
-            this.isItemClieck = isItemClieck;
-            SelectHomeOrmain = true;
-            return false;
-            //return base.ShowDialog();
-        }
-
-        public bool? ShowDialog(CPDFViewer kmpdfviewer, string password)
-        {
-            Pdfviewer = kmpdfviewer;
-            this.password = password;
-            SelectHomeOrmain = false;
-            return false;
-        }
-
-        private async void Window_Loaded(object sender, RoutedEventArgs e)
-        {
-
-            await DownloadOCR();
-        }
-
-
         public event Action<IDialogResult> RequestClose;
 
         public bool CanCloseDialog()
@@ -430,11 +385,12 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
 
         public void OnDialogClosed()
         {
+
         }
 
-        public void OnDialogOpened(IDialogParameters parameters)
+        public async void OnDialogOpened(IDialogParameters parameters)
         {
-
+            await DownloadOCR();
         }
     }
 }

+ 1 - 0
PDF Office/Views/Dialog/ConverterDialogs/ConverterExcelDialog.xaml

@@ -102,6 +102,7 @@
                                     Name="OCRCheckBox"
                                     Margin="0,10,0,0"
                                     Padding="8,0,0,0"
+                                    Command="{Binding OpenOCRCommand}"
                                     IsChecked="{Binding OCRCheckBoxIsCheckBox}">
                                     <TextBlock Text="Recognize text if needed" />
                                 </CheckBox>

+ 1 - 0
PDF Office/Views/Dialog/ConverterDialogs/ConverterHTMLDialog.xaml

@@ -40,6 +40,7 @@
                                 Name="OCRCheckBox"
                                 Margin="0,8,0,0"
                                 Padding="8,0,0,0"
+                                Command="{Binding OpenOCRCommand}"
                                 IsChecked="{Binding OCRCheckBoxIsCheckBox}">
                                 <TextBlock Text="Recognize text if needed" />
                             </CheckBox>

+ 1 - 0
PDF Office/Views/Dialog/ConverterDialogs/ConverterPPTDialog.xaml

@@ -40,6 +40,7 @@
                                 Name="OCRCheckBox"
                                 Margin="0,10,0,0"
                                 Padding="8,0,0,0"
+                                Command="{Binding OpenOCRCommand}"
                                 IsChecked="{Binding OCRCheckBoxIsCheckBox}">
                                 <TextBlock Text="Recognize text if needed" />
                             </CheckBox>

+ 1 - 1
PDF Office/Views/Dialog/ConverterDialogs/ConverterRTFDialog.xaml

@@ -30,7 +30,7 @@
                     <StackPanel Orientation="Vertical"  Margin="0,2,0,0">
                         <StackPanel Orientation="Vertical" Visibility="Visible">
                             <TextBlock Text="RTF Recognition Settings" HorizontalAlignment="Left"  Style="{StaticResource PropertyHeaderLv2}" Height="20"/>
-                            <CheckBox Name="OCRCheckBox"  Margin="0,10,0,0" IsChecked="{Binding OCRCheckBoxIsCheckBox}" Padding="8,0,0,0">
+                            <CheckBox Name="OCRCheckBox"  Margin="0,10,0,0" Command="{Binding OpenOCRCommand}" IsChecked="{Binding OCRCheckBoxIsCheckBox}" Padding="8,0,0,0">
                                 <TextBlock Text="Recognize text if needed"/>
                             </CheckBox>
                             <ComboBox IsEnabled="{Binding ElementName=OCRCheckBox,Path=IsChecked}" Margin="0,8,0,8" Width="208" Height="32" HorizontalAlignment="Left" SelectedIndex="{Binding LanguageSelectedIndex}">

+ 1 - 0
PDF Office/Views/Dialog/ConverterDialogs/ConverterTextDialog.xaml

@@ -40,6 +40,7 @@
                                 Name="OCRCheckBox"
                                 Margin="0,10,0,0"
                                 Padding="8,0,0,0"
+                                Command="{Binding OpenOCRCommand}"
                                 IsChecked="{Binding OCRCheckBoxIsCheckBox}">
                                 <TextBlock Text="Recognize text if needed" />
                             </CheckBox>

+ 1 - 0
PDF Office/Views/Dialog/ConverterDialogs/ConverterWordDialog.xaml

@@ -68,6 +68,7 @@
                                     Name="OCRCheckBox"
                                     Margin="0,8,0,0"
                                     Padding="8,0,0,0"
+                                    Command="{Binding OpenOCRCommand}"
                                     IsChecked="{Binding OCRCheckBoxIsCheckBox}">
                                     <TextBlock Text="Recognize text if needed" />
                                 </CheckBox>

+ 15 - 7
PDF Office/Views/Dialog/ConverterDialogs/OCRDownloadProgress.xaml

@@ -1,11 +1,19 @@
 <UserControl x:Class="PDF_Master.Views.Dialog.ConverterDialogs.OCRDownloadProgress"
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
-        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
-        mc:Ignorable="d"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:cus="clr-namespace:PDF_Master.CustomControl"
+    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+    xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
+    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+    xmlns:pageeditdialogs="clr-namespace:PDF_Master.ViewModels.Dialog.PageEditDialogs"
+    xmlns:prism="http://prismlibrary.com/"
         Background="Transparent" Width="374"
-                Height="120" >
+                Height="120" d:DesignHeight="120"
+    d:DesignWidth="374"
+    prism:Dialog.WindowStyle="{StaticResource DialogWindowStyle}"
+             Loaded="UserControl_Loaded"
+    prism:ViewModelLocator.AutoWireViewModel="True"
+    mc:Ignorable="d">
     <Grid>
         <Border
               Name="ProgressVisible"  Panel.ZIndex="1" Background="Transparent" Visibility="Visible">
@@ -54,7 +62,7 @@
                         BorderThickness="0"
                         Background="Transparent"
                         Command="{Binding CancelCommand}"
-                        Visibility="Visible">
+                        Visibility="Collapsed">
                             <Path Data="M6.00006 7.06072L9.46973 10.5304L10.5304 9.46973L7.06072 6.00006L10.5304 2.53039L9.46973 1.46973L6.00006 4.9394L2.53039 1.46973L1.46973 2.53039L4.9394 6.00006L1.46973 9.46973L2.53039 10.5304L6.00006 7.06072Z" Fill="#CED0D4" />
                         </Button>
                         <StackPanel Orientation="Horizontal" 
@@ -85,7 +93,7 @@
                         <TextBlock Name="ErrorTextBlock" Text="{Binding T_ErrorTextBlock}" Foreground="#F3465B"  FontSize="11" VerticalAlignment="Center"></TextBlock>
                     </StackPanel>
                     <StackPanel  Orientation="Horizontal" VerticalAlignment="Bottom" Visibility="Visible" HorizontalAlignment="Right" Margin="16,13">
-                        <Button Name="tryAgainBtn" Width="60" Height="24" Margin="0,0,8,0" Content="{Binding T_TryAgainBtn}"  Style="{StaticResource Btn.cta}"  Command="{Binding TryAgainCommnad}"   Visibility="{Binding tryAgainBtnVisible}"></Button>
+                        <Button Name="tryAgainBtn" Width="60" Height="24" Margin="0,0,8,0" Content="{Binding T_TryAgainBtn}"  Style="{StaticResource Btn.cta}"  Command="{Binding TryAgainCommnad}"   Visibility="{Binding TryAgainBtnVisible}"></Button>
                         <Button Name="CancelBtn" Width="60" Height="24" Content="{Binding T_CancelBtn}" Style="{StaticResource btn.sec}"  Command="{Binding CancelCommand}"  BorderThickness="1" ></Button>
                     </StackPanel>
                 </Grid>

+ 5 - 0
PDF Office/Views/Dialog/ConverterDialogs/OCRDownloadProgress.xaml.cs

@@ -11,5 +11,10 @@ namespace PDF_Master.Views.Dialog.ConverterDialogs
         {
             InitializeComponent();
         }
+
+        private void UserControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
+        {
+
+        }
     }
 }