Selaa lähdekoodia

安全 - 部分bug修复

liuaoran 2 vuotta sitten
vanhempi
commit
c0cf99d35e

+ 1 - 1
PDF Office/Helper/SecurityHelper.cs

@@ -33,7 +33,7 @@ namespace PDF_Office.Helper
                 permissionsInfo.AllowsCopying &&
                 permissionsInfo.AllowsDocumentAssembly &&
                 permissionsInfo.AllowsFormFieldEntry &&
-                permissionsInfo.AllowsCommenting)
+                permissionsInfo.AllowsCommenting||string.IsNullOrEmpty(document.FilePath) )
             {
                 return true;
             }

+ 6 - 2
PDF Office/ViewModels/Dialog/ToolsDialogs/SaftyDialogs/SetPasswordDialogViewModel.cs

@@ -19,6 +19,7 @@ using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
 using ComPDFKitViewer.PdfViewer;
 using Prism.Regions;
 using PDF_Office.Helper;
+using System.Diagnostics;
 
 namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
 {
@@ -401,9 +402,12 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
                 if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                 {
                     cPDFViewer.Document.Encrypt(openPassword, permissionsPassword, permissionsInfo);
-                    cPDFViewer.Document.WriteToFilePath(sfd.FileName);
+                    cPDFViewer.Document.WriteToFilePath(sfd.FileName);  
+
                     MessageBoxEx.Show("保存成功");
-                    RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
+                    DialogParameters dialogParameters = new DialogParameters();
+                    dialogParameters.Add("FilePath", sfd.FileName);
+                    RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK, dialogParameters));
                 }
                 else
                 {

+ 9 - 4
PDF Office/ViewModels/HomePanel/PDFTools/QuickToolsContentViewModel.cs

@@ -1,9 +1,11 @@
 using ComPDFKitViewer.PdfViewer;
+using Microsoft.Office.Core;
 using PDF_Office.Helper;
 using PDF_Office.Model;
 using PDF_Office.Model.Dialog.ConverterDialogs;
 using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
 using PDF_Office.Model.Dialog.ToolsDialogs;
+using PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs;
 using PDF_Office.Model.PDFTool;
 using PDF_Office.Views;
 using PDFSettings;
@@ -208,9 +210,6 @@ namespace PDF_Office.ViewModels.HomePanel.PDFTools
                         {
                             if (result.Password != null)
                             {
-                                string filePath = cPDFViewer.Document.FilePath;
-                                cPDFViewer.CloseDocument();
-                                cPDFViewer.InitDocument(filePath);
                                 cPDFViewer.Document.UnlockWithPassword(result.Password);
                             }
                             ///TODO:
@@ -218,7 +217,13 @@ namespace PDF_Office.ViewModels.HomePanel.PDFTools
                             ///
                             DialogParameters param = new DialogParameters();
                             param.Add(ParameterNames.PDFViewer, cPDFViewer);
-                            dialogs.ShowDialog(DialogNames.SetPasswordDialog, param, e => { });
+                            dialogs.ShowDialog(DialogNames.SetPasswordDialog, param, e => {
+                                string FilePath;
+                                if (e.Parameters.TryGetValue("FilePath",out FilePath))
+                                {
+                                    CommonHelper.ShowFileBrowser(FilePath);
+                                }
+                            });
                         }
 
                         break;

+ 3 - 1
PDF Office/ViewModels/MainContentViewModel.cs

@@ -25,6 +25,7 @@ using System.IO;
 using System.Drawing.Imaging;
 using ComPDFKit.PDFDocument;
 using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
+using PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs;
 
 namespace PDF_Office.ViewModels
 {
@@ -164,7 +165,7 @@ namespace PDF_Office.ViewModels
         //关闭页签
         private void unload()
         {
-            if(PDFViewer!=null)
+            if (PDFViewer != null)
             {
                 PDFViewer.CloseDocument();
             }
@@ -316,6 +317,7 @@ namespace PDF_Office.ViewModels
         {
             PDFViewer = new CPDFViewer();
             PDFViewer.CreateDocument();
+
             PDFViewer.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
             if (PDFViewer.Document == null)
             {

+ 0 - 1
PDF Office/ViewModels/TipContent/FileRestrictedTipViewModel.cs

@@ -18,7 +18,6 @@ namespace PDF_Office.ViewModels.TipContent
         public IDialogService DialogService;
 
         private CPDFViewer PDFViewer;
-
         public DelegateCommand CloseTipCommand { get; set; }
         public DelegateCommand RestrictCommand { get; set; }
         public FileRestrictedTipViewModel(IEventAggregator eventAggregator, IDialogService dialogService)

+ 59 - 14
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -1498,7 +1498,7 @@ namespace PDF_Office.ViewModels
                         cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
                     }
                     //方案一
-                    if (true)
+                    if (false)
                     {
                         PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
                         AlertsMessage alertsMessage = new AlertsMessage();
@@ -1508,25 +1508,69 @@ namespace PDF_Office.ViewModels
                         else
                             return false;
                     }
-                    else
+                    else if (false)
                     {
                         //方案二
-                        string currentPath = PDFViewer.Document.FilePath;
-                        string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
+                        try
+                        {
+                            string currentPath = PDFViewer.Document.FilePath;
+                            string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
+                            //PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
+                            PDFViewer.Document.WriteToFilePath(tempPath);
+                            PDFViewer.CloseDocument();
+                            PDFViewer.InitDocument(tempPath);
+                            PDFViewer.Document.UnlockWithPassword(permissionsPassword);
+                            PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
+                            PDFViewer.Document.WriteToFilePath(currentPath);
+                            PDFViewer.CloseDocument();
+                            PDFViewer.InitDocument(currentPath);
+                            System.IO.File.Delete(tempPath);
+                            PDFViewer.Document.UnlockWithPassword(permissionsPassword);
+                            CanSave = false;
+                            return true;
+                        }
+                        catch
+                        {
+                            return false;
+                        }
+
+                    }
+                    else if(false)
+                    {
+                        //方案三
                         PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
-                        PDFViewer.Document.WriteToFilePath(tempPath);
-                        PDFViewer.InitDocument(tempPath);
-                        //PDFViewer.Document.UnlockWithPassword(permissionsPassword);
-                        //PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
-                        PDFViewer.Document.WriteToFilePath(currentPath);
-                        System.IO.File.Delete(tempPath);
-                        PDFViewer.CloseDocument();
-                        PDFViewer.InitDocument(currentPath);
-                        PDFViewer.Document.UnlockWithPassword(permissionsPassword);
+                        if (PDFViewer.Document.WriteToFilePath(PDFViewer.Document.FilePath))
+                        {
+                            DoAfterSaveAs(PDFViewer.Document.FilePath);
+                            return true;
+                        }
+                        else
+                        {
+                            return false;
+                        }
                     }
                 }
 
-                bool result = PDFViewer.Document.WriteToLoadedPath();
+                bool result;
+                if (SecurityInfo.IsPasswordChanged)
+                {
+                    string openPassword = null;
+                    string permissionsPassword = null;
+                    CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
+                    if (SecurityInfo.NeedOpenPassword)
+                    {
+                        openPassword = SecurityInfo.OpenPassword;
+                    }
+
+                    if (SecurityInfo.NeedPermissionsPassword)
+                    {
+                        permissionsPassword = SecurityInfo.PermissionsPassword;
+                        cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
+                    }
+                    PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
+                }
+                //result = PDFViewer.Document.WriteToLoadedPath();
+                result = PDFViewer.Document.WriteToFilePath(PDFViewer.Document.FilePath);
                 if (result)
                 {
                     PDFViewer.UndoManager.CanSave = false;
@@ -1573,6 +1617,7 @@ namespace PDF_Office.ViewModels
                                           SettingHelper.SetFileInfo(info);
                                       }
                                   });
+                    PDFViewer.ReloadDocument();
                 }
                 else
                 {

+ 0 - 2
PDF Office/Views/HomePanel/RecentFiles/DocItemControl.xaml.cs

@@ -49,9 +49,7 @@ namespace PDF_Office.Views.HomePanel.RecentFiles
                     CoverImage.Source = ToolMethod.GetFileThumbImg("pack://application:,,,/Resources//FilesType/ic_propertybar_file_png_Large.png");
                     tempdoc.Release();
                 }
-                  
             }
         }
-
     }
 }