Bläddra i källkod

安全 - 密码相关Tip

liuaoran 2 år sedan
förälder
incheckning
68de67dcbb
24 ändrade filer med 510 tillägg och 117 borttagningar
  1. 4 0
      PDF Office/App.xaml.cs
  2. 25 0
      PDF Office/EventAggregators/ShowTipEvent.cs
  3. 50 31
      PDF Office/Helper/SecurityHelper.cs
  4. 2 0
      PDF Office/Model/ParameterNames.cs
  5. 8 0
      PDF Office/Model/RegionNames.cs
  6. 19 0
      PDF Office/PDF Office.csproj
  7. 38 46
      PDF Office/ViewModels/Dialog/ToolsDialogs/SaftyDialogs/SetPasswordDialogViewModel.cs
  8. 5 5
      PDF Office/ViewModels/EditTools/Background/BackgroundCreateFileContentViewModel.cs
  9. 16 0
      PDF Office/ViewModels/FileRestrictedTipViewModel.cs
  10. 18 20
      PDF Office/ViewModels/MainContentViewModel.cs
  11. 1 1
      PDF Office/ViewModels/PropertyPanel/AnnotPanel/LinkAnnotPropertyViewModel.cs
  12. 16 0
      PDF Office/ViewModels/SetPasswordSuccessfullyTipViewModel.cs
  13. 77 0
      PDF Office/ViewModels/TipContent/FileRestrictedTipViewModel.cs
  14. 1 1
      PDF Office/ViewModels/TipContent/LinkAnnotTipViewModel.cs
  15. 47 0
      PDF Office/ViewModels/TipContent/SetPasswordSuccessfullyTipViewModel.cs
  16. 14 6
      PDF Office/ViewModels/Tools/ToolsBarContentViewModel.cs
  17. 57 2
      PDF Office/ViewModels/ViewContentViewModel.cs
  18. 3 3
      PDF Office/Views/Dialog/ToolsDialogs/SaftyDialogs/SetPasswordDialog.xaml
  19. 34 0
      PDF Office/Views/TipContent/FileRestrictedTip.xaml
  20. 15 0
      PDF Office/Views/TipContent/FileRestrictedTip.xaml.cs
  21. 37 0
      PDF Office/Views/TipContent/SetPasswordSuccessfullyTip.xaml
  22. 15 0
      PDF Office/Views/TipContent/SetPasswordSuccessfullyTip.xaml.cs
  23. 1 1
      PDF Office/Views/Tools/ToolsBarContent.xaml
  24. 7 1
      PDF Office/Views/ViewContent.xaml

+ 4 - 0
PDF Office/App.xaml.cs

@@ -273,6 +273,10 @@ namespace PDF_Office
             containerRegistry.RegisterForNavigation<SignProperty>();
             containerRegistry.RegisterForNavigation<LinkAnnotTip>();
 
+            //Tip
+            containerRegistry.RegisterForNavigation<SetPasswordSuccessfullyTip>();
+            containerRegistry.RegisterForNavigation<FileRestrictedTip>();
+
             #endregion 注册内容组件
 
             #region 注册弹窗

+ 25 - 0
PDF Office/EventAggregators/ShowTipEvent.cs

@@ -0,0 +1,25 @@
+using Prism.Events;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PDF_Office.EventAggregators
+{
+    public enum EnumTipKind
+    {
+        StatusNone,
+        StatusFileRestricted,
+        StatusSetPasswordSuccessfully
+    }  
+
+    public class ShowTipEventArgs
+    {
+        public EnumTipKind enumTipKind;
+        public string Unicode;
+    }
+    public class ShowTipEvent:PubSubEvent<ShowTipEventArgs>
+    {
+    }
+}

+ 50 - 31
PDF Office/Helper/SecurityHelper.cs

@@ -67,37 +67,31 @@ namespace PDF_Office.Helper
             return true;
         }
 
-        public static bool VerifyPasswordOnlyBool(CPDFDocument document ,EnumPasswordKind enumPasswordKind, IDialogService dialogService)
-        {
-            if (enumPasswordKind == EnumPasswordKind.StatusOpenPassword)
-            {
-                if (!document.IsLocked)
-                {
-                    return true;
-                }
-            }
-            else if(enumPasswordKind == EnumPasswordKind.StatusPermissionsPassword)
-            {
-                if (!document.IsLocked)
-                {
-                    if (CheckHaveAllPermissions(document))
-                    {
-                        return true;
-                    }
-                }
-            }
-            string password = "";
-            DialogParameters value = new DialogParameters();
-            value.Add(ParameterNames.PasswordKind, EnumPasswordKind.StatusPermissionsPassword);
-            value.Add(ParameterNames.PDFDocument, document);
-            bool isDiscryptied = false;
-            dialogService.ShowDialog(DialogNames.CheckPasswordDialog, value, e => { 
-                isDiscryptied = e.Parameters.GetValue<bool>(ParameterNames.PasswordResult);
-                password = e.Parameters.GetValue<string>(ParameterNames.Password);
-            });
-            return isDiscryptied;
-        }
-
+        /// <summary>
+        /// 该函数根据需要的密码类型进行验证
+        /// </summary>
+        /// <param name="document">文档对象</param>
+        /// <param name="enumPasswordKind">密码类型枚举EnumPasswordKind</param>
+        /// <param name="dialogService">该ViewModel的IDialogService对象</param>
+        /// <returns>
+        ///<para>
+        ///返回值结构体状态:
+        /// </para>
+        /// <para>
+        /// IsDiscryptied == true
+        /// Password == null
+        /// 已解锁且无需密码提权
+        /// </para>
+        /// <para>
+        ///IsDiscryptied == true
+        ///Password != null
+        ///可解锁且密码存储在Password中
+        /// </para>
+        /// <para>
+        /// IsDiscrypited == false
+        /// 密码错误且不可解锁
+        /// </para>
+        /// </returns>
         public static VerifyPasswordResult VerifyPasswordByPasswordKind(CPDFDocument document, EnumPasswordKind enumPasswordKind, IDialogService dialogService)
         {
             VerifyPasswordResult verifyPasswordResult  = new VerifyPasswordResult();
@@ -120,6 +114,31 @@ namespace PDF_Office.Helper
             return verifyPasswordResult;
         }
 
+        /// <summary>
+        /// 该函数根据需要的权限类型子集进行验证
+        /// </summary>
+        /// <param name="document">文档对象</param>
+        /// <param name="enumPermissionsSet">权限类型枚举子集EnumPermissionsSet,当权限为空时退化到开启密码</param>
+        /// <param name="dialogService">该ViewModel的IDialogService对象</param>
+        /// <returns>
+        ///<para>
+        ///返回值结构体状态:
+        /// </para>
+        /// <para>
+        /// IsDiscryptied == true
+        /// Password == null
+        /// 已解锁且无需密码提权
+        /// </para>
+        /// <para>
+        ///IsDiscryptied == true
+        ///Password != null
+        ///可解锁且密码存储在Password中
+        /// </para>
+        /// <para>
+        /// IsDiscrypited == false
+        /// 密码错误且不可解锁
+        /// </para>
+        /// </returns>
         public static VerifyPasswordResult VerifyPasswordForSelectedPermissions(CPDFDocument document, EnumPermissionsSet enumPermissionsSet, IDialogService dialogService)
         {
             VerifyPasswordResult verifyPasswordResult = new VerifyPasswordResult();

+ 2 - 0
PDF Office/Model/ParameterNames.cs

@@ -40,6 +40,8 @@ namespace PDF_Office.Model
 
         public static string BatchProcessing_Name = "BatchProcessing_Name";
 
+        public static string Unicode = "Unicode";
+
         /// <summary>
         /// 页码集合
         /// </summary>

+ 8 - 0
PDF Office/Model/RegionNames.cs

@@ -62,6 +62,14 @@ namespace PDF_Office.Model
             }
         }
 
+        public static string LeftTipContentRegionName
+        {
+            get
+            {
+                return GetRegionName("LeftTipContentRegionName");
+            }
+        }
+
         public static string ReadRegionName
         {
             get

+ 19 - 0
PDF Office/PDF Office.csproj

@@ -313,6 +313,7 @@
     <Compile Include="EventAggregators\RedactionCommandEvent.cs" />
     <Compile Include="EventAggregators\ScanEvent.cs" />
     <Compile Include="EventAggregators\SendPrintInfoEvent.cs" />
+    <Compile Include="EventAggregators\ShowTipEvent.cs" />
     <Compile Include="EventAggregators\SplitEvent.cs" />
     <Compile Include="Helper\CacheFilePath.cs" />
     <Compile Include="Helper\ConverterHelper.cs" />
@@ -461,6 +462,7 @@
     <Compile Include="ViewModels\EditTools\HeaderFooter\HeaderFooterDocumentContentViewModel.cs" />
     <Compile Include="ViewModels\EditTools\HeaderFooter\HeaderFooterTemplateListContentViewModel.cs" />
     <Compile Include="ViewModels\EditTools\Redaction\RedactionContentViewModel.cs" />
+    <Compile Include="ViewModels\FileRestrictedTipViewModel.cs" />
     <Compile Include="ViewModels\Form\ButtonPropertyViewModel.cs" />
     <Compile Include="ViewModels\Form\CheckBoxPropertyViewModel.cs" />
     <Compile Include="ViewModels\Form\ComboxPropertyViewModel.cs" />
@@ -511,7 +513,10 @@
     <Compile Include="ViewModels\Dialog\DynamicPropertyDialogViewModel.cs" />
     <Compile Include="ViewModels\PropertyPanel\ViewModular\PageContentViewModel.cs" />
     <Compile Include="ViewModels\Scan\ScanViwerViewModel.cs" />
+    <Compile Include="ViewModels\SetPasswordSuccessfullyTipViewModel.cs" />
+    <Compile Include="ViewModels\TipContent\FileRestrictedTipViewModel.cs" />
     <Compile Include="ViewModels\TipContent\LinkAnnotTipViewModel.cs" />
+    <Compile Include="ViewModels\TipContent\SetPasswordSuccessfullyTipViewModel.cs" />
     <Compile Include="ViewModels\Tools\AnnotToolContentViewModel.Command.cs" />
     <Compile Include="ViewModels\Tools\AnnotToolContentViewModel.Layout.cs" />
     <Compile Include="ViewModels\Tools\ConverterBarContentViewModel.cs" />
@@ -1071,9 +1076,15 @@
     <Compile Include="Views\Scan\ScanViwer.xaml.cs">
       <DependentUpon>ScanViwer.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Views\TipContent\FileRestrictedTip.xaml.cs">
+      <DependentUpon>FileRestrictedTip.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Views\TipContent\LinkAnnotTip.xaml.cs">
       <DependentUpon>LinkAnnotTip.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Views\TipContent\SetPasswordSuccessfullyTip.xaml.cs">
+      <DependentUpon>SetPasswordSuccessfullyTip.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Views\Tools\AnnotToolContent.xaml.cs">
       <DependentUpon>AnnotToolContent.xaml</DependentUpon>
     </Compile>
@@ -1947,10 +1958,18 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Views\TipContent\FileRestrictedTip.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Views\TipContent\LinkAnnotTip.xaml">
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </Page>
+    <Page Include="Views\TipContent\SetPasswordSuccessfullyTip.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Views\Tools\AnnotToolContent.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>

+ 38 - 46
PDF Office/ViewModels/Dialog/ToolsDialogs/SaftyDialogs/SetPasswordDialogViewModel.cs

@@ -16,6 +16,9 @@ using CheckBox = System.Windows.Controls.CheckBox;
 using System.Drawing.Printing;
 using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.SetPasswordDialogModel;
 using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
+using ComPDFKitViewer.PdfViewer;
+using Prism.Regions;
+using PDF_Office.Helper;
 
 namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
 {
@@ -23,9 +26,9 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
     {
         #region 参数和属性
         private SetPasswordDialogModel setPasswordDialogModel = new SetPasswordDialogModel();
-        private CPDFDocument document;
+        private CPDFViewer cPDFViewer;
         public IDialogService dialogs;
-
+        private ViewContentViewModel viewContentViewModel;
         private EnumPermissionsMod enumPermissionsMod = EnumPermissionsMod.StatusUnknown | EnumPermissionsMod.StatusRestrictPrinting | EnumPermissionsMod.StatusRestrictCopying;
 
         private bool _enableConfirm = false;
@@ -318,9 +321,9 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
         {
             DialogParameters setPasswordpdf = new DialogParameters();
             setPasswordpdf.Add(ParameterNames.BatchProcessing_Name, "2");
-            HomePageBatchProcessingDialogModel.FilePaths = new List<string> { document.FilePath.ToString() };
+            HomePageBatchProcessingDialogModel.FilePaths = new List<string> { cPDFViewer.Document.FilePath.ToString() };
             HomePageBatchProcessingDialogModel.BatchProcessingIndex = 2;
-            setPasswordpdf.Add(ParameterNames.FilePath, new string[] { document.FilePath.ToString() });
+            setPasswordpdf.Add(ParameterNames.FilePath, new string[] { cPDFViewer.Document.FilePath.ToString() });
             dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, setPasswordpdf, e => { });
         }
 
@@ -330,48 +333,41 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
 
             string openPassword = "";
             string permissionsPassword = "";
-            FolderBrowserDialog folderDialog = new FolderBrowserDialog();
-            System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
-            /*
-             *设置这个对话框的起始保存路径
-             */
-            sfd.InitialDirectory = document.FilePath;
-            /*
-             *设置保存的文件的类型,注意过滤器的语法 例子:“文件类型|*.后缀名;*.后缀名;”
-             */
-            sfd.Filter = "PDF|*.pdf;";
-            /*
-             *调用ShowDialog()方法显示该对话框,该方法的返回值代表用户是否点击了确定按钮
-             **/
-            sfd.FileName = document.FileName + "_SetPassword.pdf";
-            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
-            {
-                CPDFPermissionsInfo permissionsInfo = null;
 
-                if (NeedOpenPassword)
-                {
-                    if (!string.IsNullOrEmpty(OpenPassword))
-                    {
-                        openPassword = OpenPassword;
-                    }
-                }
-                if (NeedPermissionsPassword && (!string.IsNullOrEmpty(PermissionsPassword)))
-                {
-                    permissionsPassword = PermissionsPassword;
-                    permissionsInfo = CreatePermissionsInfo(enumPermissionsMod);
-                }
-                else
+            CPDFPermissionsInfo permissionsInfo = null;
+
+            if (NeedOpenPassword)
+            {
+                if (!string.IsNullOrEmpty(OpenPassword))
                 {
-                    permissionsInfo = CreateDefaultPermissionsInfo();
+                    openPassword = OpenPassword;
                 }
-
-                document.Encrypt(openPassword, permissionsPassword, permissionsInfo);
-                document.WriteToFilePath(sfd.FileName);
-                MessageBoxEx.Show(sfd.FileName + " 保存成功");
-                RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
             }
+            if (NeedPermissionsPassword && (!string.IsNullOrEmpty(PermissionsPassword)))
+            {
+                permissionsPassword = PermissionsPassword;
+                permissionsInfo = CreatePermissionsInfo(enumPermissionsMod);
+            }
+            else
+            {
+                permissionsInfo = CreateDefaultPermissionsInfo();
+            }
+            cPDFViewer.Document.Encrypt(openPassword, permissionsPassword, permissionsInfo);
+           //cPDFViewer.ReloadDocument();
+            if (!string.IsNullOrEmpty(permissionsPassword) )
+            {
+                cPDFViewer.Document.UnlockWithPassword(permissionsPassword);
+                SecurityHelper.CheckHaveAllPermissions(cPDFViewer.Document);
+            }
+            else
+            {
+                cPDFViewer.Document.UnlockWithPassword(openPassword);
+            }
+            viewContentViewModel.PDFViewer.UndoManager.CanSave = true;
+            RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
         }
 
+
         public void CancelEncrypt() => RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
 
         #endregion
@@ -390,12 +386,8 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
 
         public void OnDialogOpened(IDialogParameters parameters)
         {
-            CPDFDocument doc = null;
-            parameters.TryGetValue<CPDFDocument>(ParameterNames.PDFDocument, out doc);
-            if (doc != null)
-            {
-                document = doc;
-            }
+            parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out cPDFViewer);
+            parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
         }
         #endregion
     }

+ 5 - 5
PDF Office/ViewModels/EditTools/Background/BackgroundCreateFileContentViewModel.cs

@@ -399,14 +399,14 @@ namespace PDF_Office.ViewModels.EditTools.Background
 
         public async void GetBitmapFromDocment(string filePath)
         {
-            CPDFDocument document = CPDFDocument.InitWithFilePath(filePath);
             CPDFViewer cPDFViewer = new CPDFViewer();
-            VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(document, EnumPasswordKind.StatusOpenPassword, dialogs);
+            cPDFViewer.InitDocument(filePath);
+            VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(cPDFViewer.Document, EnumPasswordKind.StatusOpenPassword, dialogs);
             if (result.IsDiscryptied)
             {
                 if (result.Password != null)
                 {
-
+                    cPDFViewer.Document.Release();
                     cPDFViewer.InitDocument(filePath);
                     cPDFViewer.Document.UnlockWithPassword(result.Password);
                 }
@@ -421,8 +421,8 @@ namespace PDF_Office.ViewModels.EditTools.Background
                 BackgroundInfo.ImageArray = bmp_data;
                 BackgroundInfo.ImageWidth = (int)page.PageSize.Width;
                 BackgroundInfo.ImageHeight = (int)page.PageSize.Height;
-                document.ReleasePages();
-                document.Release();
+                cPDFViewer.Document.ReleasePages();
+                cPDFViewer.Document.Release();
             }
         }
 

+ 16 - 0
PDF Office/ViewModels/FileRestrictedTipViewModel.cs

@@ -0,0 +1,16 @@
+using Prism.Commands;
+using Prism.Mvvm;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace PDF_Office.ViewModels
+{
+    public class FileRestrictedTipViewModel : BindableBase
+    {
+        public FileRestrictedTipViewModel()
+        {
+
+        }
+    }
+}

+ 18 - 20
PDF Office/ViewModels/MainContentViewModel.cs

@@ -24,6 +24,7 @@ using System.Drawing;
 using System.IO;
 using System.Drawing.Imaging;
 using ComPDFKit.PDFDocument;
+using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
 
 namespace PDF_Office.ViewModels
 {
@@ -254,30 +255,27 @@ namespace PDF_Office.ViewModels
             }
             else
             {
-                if (PDFViewer.Document.IsLocked)
+                VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusOpenPassword, dialogs);
+                if (result.IsDiscryptied)
                 {
-                    DialogParameters value = new DialogParameters();
-                    value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
-                    dialogs.ShowDialog(DialogNames.VerifyPassWordDialog, value, e =>
+                    if (result.Password != null)
                     {
-                        if (e.Result == ButtonResult.OK)
-                        {
-                            if (e.Parameters.ContainsKey(ParameterNames.PassWord) && e.Parameters.GetValue<string>(ParameterNames.PassWord) != null)
-                            {
-                                PDFViewer.Tag = e.Parameters.GetValue<string>(ParameterNames.PassWord).ToString();
-                            }
-                        }
-                    });
-
-                    if (PDFViewer.Document.IsLocked)
-                    {
-                        //未成功解密文档时,释放Document对象,返回
-                        PDFViewer.Document.Release();
-                        return false;
+                        string filePath = PDFViewer.Document.FilePath;
+                        PDFViewer.Document.UnlockWithPassword(result.Password);
                     }
+                    ///TODO:
+                    ///此处填入需要执行的代码
+                }
+                 
+                if (result.IsDiscryptied == false)
+                {
+                    //未成功解密文档时,释放Document对象,返回
+                    PDFViewer.Document.Release();
+                    return false;
                 }
             }
 
+
             PDFViewer.Load();
 
             if (App.mainWindowViewModel != null)
@@ -497,7 +495,7 @@ namespace PDF_Office.ViewModels
                 FileChanged = Visibility.Visible;
                 PDFViewer.SetFormFieldHighlight(true);
 
-                await  System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
+                await System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
                 {
                     NavigateToViewContent();
                 }));
@@ -608,7 +606,7 @@ namespace PDF_Office.ViewModels
             }
 
 
-          
+
 
         }
 

+ 1 - 1
PDF Office/ViewModels/PropertyPanel/AnnotPanel/LinkAnnotPropertyViewModel.cs

@@ -671,7 +671,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
         /// <summary>
         /// 定位目标范围
         /// </summary>
-        /// <param name="obj"></param>
+        /// <param name="obj"></param> 
         private void LocationPage(object obj)
         {
             pdfViewer.EnableDrawSelectArea(true);

+ 16 - 0
PDF Office/ViewModels/SetPasswordSuccessfullyTipViewModel.cs

@@ -0,0 +1,16 @@
+using Prism.Commands;
+using Prism.Mvvm;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace PDF_Office.ViewModels
+{
+    public class SetPasswordSuccessfullyTipViewModel : BindableBase
+    {
+        public SetPasswordSuccessfullyTipViewModel()
+        {
+
+        }
+    }
+}

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

@@ -0,0 +1,77 @@
+using ComPDFKitViewer.PdfViewer;
+using PDF_Office.EventAggregators;
+using PDF_Office.Helper;
+using PDF_Office.Model;
+using Prism.Commands;
+using Prism.Events;
+using Prism.Mvvm;
+using Prism.Regions;
+using Prism.Services.Dialogs;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using static Dropbox.Api.Files.ThumbnailMode;
+using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
+
+namespace PDF_Office.ViewModels.TipContent
+{
+    public class FileRestrictedTipViewModel : BindableBase, INavigationAware
+    {
+        public string unicode = null;
+        public IEventAggregator eventAggregator;
+        public IDialogService DialogService;
+
+        private CPDFViewer PDFViewer;
+
+        public DelegateCommand CloseTipCommand { get; set; }
+        public DelegateCommand RestrictCommand { get; set; }
+        public FileRestrictedTipViewModel(IEventAggregator eventAggregator, IDialogService dialogService)
+        {
+            this.eventAggregator = eventAggregator;
+            this.DialogService = dialogService;
+            unicode = App.mainWindowViewModel.SelectedItem.Unicode;
+            CloseTipCommand = new DelegateCommand(CloseTip);
+            RestrictCommand = new DelegateCommand(Restrict);
+        }
+
+        public void CloseTip()
+        {
+            this.eventAggregator.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusNone, Unicode = unicode });
+        }
+
+        public void Restrict()
+        {
+            VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, DialogService);
+            if (result.IsDiscryptied)
+            {
+                if (result.Password != null)
+                {
+                    string filePath = PDFViewer.Document.FilePath;
+                    PDFViewer.ReloadDocument();
+                    PDFViewer.Document.UnlockWithPassword(result.Password);
+                }
+                ///TODO:
+                ///此处填入需要执行的代码
+            this.eventAggregator.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusNone, Unicode = unicode });
+
+            }
+        }
+
+        public bool IsNavigationTarget(NavigationContext navigationContext)
+        {
+            return true;
+        }
+
+        public void OnNavigatedFrom(NavigationContext navigationContext)
+        {
+        }
+
+        public void OnNavigatedTo(NavigationContext navigationContext)
+        {
+            navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
+        }
+    }
+}

+ 1 - 1
PDF Office/ViewModels/TipContent/LinkAnnotTipViewModel.cs

@@ -8,7 +8,7 @@ using System.Threading.Tasks;
 
 namespace PDF_Office.ViewModels.TipContent
 {
-    internal class LinkAnnotTipViewModel : BindableBase, INavigationAware
+    public class LinkAnnotTipViewModel : BindableBase, INavigationAware
     {
         public bool IsNavigationTarget(NavigationContext navigationContext)
         {

+ 47 - 0
PDF Office/ViewModels/TipContent/SetPasswordSuccessfullyTipViewModel.cs

@@ -0,0 +1,47 @@
+using PDF_Office.EventAggregators;
+using Prism.Commands;
+using Prism.Events;
+using Prism.Mvvm;
+using Prism.Regions;
+using Prism.Services.Dialogs;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PDF_Office.ViewModels.TipContent
+{
+    public class SetPasswordSuccessfullyTipViewModel:BindableBase,INavigationAware
+    {
+        public string unicode = null;
+        public IEventAggregator eventAggregator;
+
+        public DelegateCommand CloseTipCommand { get; set; }
+
+        public SetPasswordSuccessfullyTipViewModel(IEventAggregator eventAggregator)
+        {
+            this.eventAggregator = eventAggregator;
+            unicode = App.mainWindowViewModel.SelectedItem.Unicode;
+            CloseTipCommand = new DelegateCommand(CloseTip);
+        }
+
+        public void CloseTip()
+        {
+            this.eventAggregator.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusNone, Unicode = unicode });
+        }
+
+        public bool IsNavigationTarget(NavigationContext navigationContext)
+        {
+            return true;
+        }
+
+        public void OnNavigatedFrom(NavigationContext navigationContext)
+        {
+        }
+
+        public void OnNavigatedTo(NavigationContext navigationContext)
+        {
+        }
+    }
+}

+ 14 - 6
PDF Office/ViewModels/Tools/ToolsBarContentViewModel.cs

@@ -160,19 +160,27 @@ namespace PDF_Office.ViewModels.Tools
 
         private void OpenSetPasswordDialog()
         {
-            VerifyPasswordResult result = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, EnumPermissionsSet.StatusAllowsPrinting|EnumPermissionsSet.StatusAllowsHighQualityPrinting, dialogs);
+            PDFViewer.ReloadDocument();
+            bool a =  PDFViewer.Document.UnlockWithPassword("321");
+            VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
             if (result.IsDiscryptied)
             {
                 if (result.Password != null)
                 {
-                    string filePath = PDFViewer.Document.FilePath;
-                    PDFViewer.Document.Release();
-                    PDFViewer.InitDocument(filePath);
+                    PDFViewer.ReloadDocument();
                     PDFViewer.Document.UnlockWithPassword(result.Password);
                 }
                 DialogParameters value = new DialogParameters();
-                value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
-                dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e => { });
+                value.Add(ParameterNames.PDFViewer,  this.PDFViewer);
+                value.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
+
+                dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e =>
+                {
+                    if(e.Result == ButtonResult.OK)
+                    {
+                        this.eventAggregator.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusSetPasswordSuccessfully,  Unicode = unicode})  ;
+                    }
+                });
             }
         }
 

+ 57 - 2
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -73,6 +73,8 @@ namespace PDF_Office.ViewModels
         /// </summary>
         public string TipContentRegionName { get; set; }
 
+        public string LeftTipContentRegionName { get; set; }
+
         public string ReadModeRegionName { get; set; }
 
         public string ConverterBarContentRegionName { get; set; }
@@ -99,6 +101,16 @@ namespace PDF_Office.ViewModels
             }
         }
 
+        private Visibility leftTipVisible = Visibility.Collapsed;
+        public Visibility LeftTipVisible
+        {
+            get { return leftTipVisible; }
+            set
+            {
+                SetProperty(ref leftTipVisible, value);
+            }
+        }
+
         private Visibility readModelTip = Visibility.Collapsed;
 
         public Visibility ReadModelTip
@@ -536,6 +548,7 @@ namespace PDF_Office.ViewModels
             OCRContentVisible = Visibility.Visible;
             TipVisible = Visibility.Visible;
             TipContentRegionName = RegionNames.TipContentRegionName;
+            LeftTipContentRegionName = RegionNames.LeftTipContentRegionName;
             OCRViewerRegionName = RegionNames.OCRViewerRegionName;
             ToolContentRegionName = Guid.NewGuid().ToString();
             ToolsBarContentRegionName = Guid.NewGuid().ToString();
@@ -553,12 +566,14 @@ namespace PDF_Office.ViewModels
 
             eventAggregator.GetEvent<EnterSelectedEditToolEvent>().Subscribe(EnterEditTools, e => e.Unicode == unicode);
             eventAggregator.GetEvent<CloseEditToolEvent>().Subscribe(CloseEditTool, e => e.Unicode == unicode);
+            eventAggregator.GetEvent<ShowTipEvent>().Subscribe(ShowSelectedTip, e => e.Unicode == unicode);
 
             //TODO:根据缓存 选择用户上次选择的菜单
             EnterSelectedBar("TabItemAnnotation");
         }
 
 
+
         /// <summary>
         /// 设置Tip状态栏的显示状态
         /// </summary>
@@ -575,6 +590,47 @@ namespace PDF_Office.ViewModels
             }
         }
 
+        /// <summary>
+        /// 设置LeftTip状态栏的显示状态
+        /// </summary>
+        /// <param name="show">是否显示</param>
+        public void ShowLeftTip(bool show)
+        {
+            if (show)
+            {
+                LeftTipVisible = Visibility.Visible;
+            }
+            else
+            {
+                LeftTipVisible = Visibility.Collapsed;
+            }
+        }
+
+        public void CheckHaveAllPermission()
+        {
+            if (!SecurityHelper.CheckHaveAllPermissions(PDFViewer.Document))
+            {
+                ShowLeftTip(true);
+                NavigationParameters param = new NavigationParameters();
+                param.Add(ParameterNames.PDFViewer, PDFViewer);
+                region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
+            }
+        }
+        public void ShowSelectedTip(ShowTipEventArgs showTipEventArgs)  
+        {
+            switch (showTipEventArgs.enumTipKind)
+            {
+                case EnumTipKind.StatusNone:
+                    ShowLeftTip(false);
+                    break;
+                case EnumTipKind.StatusSetPasswordSuccessfully:
+                    ShowLeftTip(true);
+                    region.RequestNavigate(LeftTipContentRegionName, "SetPasswordSuccessfullyTip");
+                    break;
+                default: break;
+            }
+        }
+
         /// <summary>
         /// 右键菜单创建链接
         /// </summary>
@@ -946,8 +1002,8 @@ namespace PDF_Office.ViewModels
                     PassWord = pdfview.Tag.ToString();
                 }
                 loadFile();
+                CheckHaveAllPermission();
             }
-
             isOpenFile = true;
         }
 
@@ -1396,7 +1452,6 @@ namespace PDF_Office.ViewModels
                 isInPageEdit = false;
             }
         }
-
         #endregion 方法
     }
 }

+ 3 - 3
PDF Office/Views/Dialog/ToolsDialogs/SaftyDialogs/SetPasswordDialog.xaml

@@ -278,13 +278,13 @@
         </cus:DialogContent.Content>
         <cus:DialogContent.BottmBar>
             <Grid Width="400">
-                <Button  Width="80"  Height="32"  HorizontalAlignment="Left" Command="{Binding BatchSetPasswordCommand}">
+                <Button Style="{StaticResource btn.ghost}"  Width="80"  Height="32"  HorizontalAlignment="Left" Command="{Binding BatchSetPasswordCommand}">
                     <TextBlock Text="Batch"></TextBlock>
                 </Button>
-                <Button  Width="80"  Height="32"  Margin="0,0,96,0"  HorizontalAlignment="Right" Command="{Binding EncryptCommand}"  IsEnabled="{Binding EnableConfirm, Mode=TwoWay}" RenderTransformOrigin="1.5,1192508.3">
+                <Button Style="{StaticResource Btn.cta}"  Width="80"  Height="32"  Margin="0,0,96,0"  HorizontalAlignment="Right" Command="{Binding EncryptCommand}"  IsEnabled="{Binding EnableConfirm, Mode=TwoWay}" RenderTransformOrigin="1.5,1192508.3">
                     <TextBlock Text="Encrypt"></TextBlock>
                 </Button>
-                <Button  Width="80" Height="32" HorizontalAlignment="Right" Command="{Binding CancelEncryptCommand}">
+                <Button Style="{StaticResource btn.ghost}"  Width="80" Height="32" HorizontalAlignment="Right" Command="{Binding CancelEncryptCommand}">
                     <TextBlock Text="Cancel"></TextBlock>
                 </Button>
             </Grid>

+ 34 - 0
PDF Office/Views/TipContent/FileRestrictedTip.xaml

@@ -0,0 +1,34 @@
+<UserControl x:Class="PDF_Office.Views.TipContent.FileRestrictedTip"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:prism="http://prismlibrary.com/"             
+             prism:ViewModelLocator.AutoWireViewModel="True"
+                           Height="176" Width="379">
+    <Border CornerRadius="8" Background="{StaticResource color.sys.layout.state.note}">
+        <Grid Margin="16">
+            <Grid.RowDefinitions>
+                <RowDefinition Height="24"></RowDefinition>
+                <RowDefinition Height="72"></RowDefinition>
+                <RowDefinition Height="48"></RowDefinition>
+            </Grid.RowDefinitions>
+            <Grid>
+                <Grid.ColumnDefinitions>
+                    <ColumnDefinition></ColumnDefinition>
+                    <ColumnDefinition Width="24"></ColumnDefinition>
+                </Grid.ColumnDefinitions>
+                <StackPanel Orientation="Horizontal">
+                    <TextBlock Text="File Restricted" FontSize="14" VerticalAlignment="Center" FontFamily="Segoe UI" FontWeight="Medium" ></TextBlock>
+                </StackPanel>
+                <Button Background="Transparent" BorderBrush="Transparent" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Right" Command="{Binding CloseTipCommand}">
+                    <Path Data="M6.00006 7.06066L9.46973 10.5303L10.5304 9.46967L7.06072 6L10.5304 2.53033L9.46973 1.46967L6.00006 4.93934L2.53039 1.46967L1.46973 2.53033L4.9394 6L1.46973 9.46967L2.53039 10.5303L6.00006 7.06066Z" Fill="#94989C"></Path>
+                </Button>
+            </Grid>
+
+            <TextBlock Grid.Row="1" TextWrapping="Wrap"  Text="Files are password protected. Restricted features need to be unlocked to use" Foreground="{StaticResource color.sys.text.neutral.lv2}" Margin="0,8,16,0" FontFamily="Segoe UI" FontSize="14"></TextBlock>
+            <Button Grid.Row="2" Height="32"  Width="151" HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="Transparent" BorderThickness="1" Command="{Binding RestrictCommand}">
+                <TextBlock Text="Release restrictions" FontSize="14"></TextBlock>
+            </Button>
+        </Grid>
+    </Border>
+</UserControl>
+

+ 15 - 0
PDF Office/Views/TipContent/FileRestrictedTip.xaml.cs

@@ -0,0 +1,15 @@
+using System.Windows.Controls;
+
+namespace PDF_Office.Views.TipContent
+{
+    /// <summary>
+    /// Interaction logic for FileRestrictedTip
+    /// </summary>
+    public partial class FileRestrictedTip : UserControl
+    {
+        public FileRestrictedTip()
+        {
+            InitializeComponent();
+        }
+    }
+}

+ 37 - 0
PDF Office/Views/TipContent/SetPasswordSuccessfullyTip.xaml

@@ -0,0 +1,37 @@
+<UserControl x:Class="PDF_Office.Views.TipContent.SetPasswordSuccessfullyTip"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:prism="http://prismlibrary.com/"             
+             prism:ViewModelLocator.AutoWireViewModel="True"
+                           Height="176" Width="379">
+    <Border CornerRadius="8" Background="{StaticResource color.sys.layout.state.note}">
+        <Grid Margin="16">
+            <Grid.RowDefinitions>
+                <RowDefinition Height="24"></RowDefinition>
+                <RowDefinition Height="72"></RowDefinition>
+                <RowDefinition Height="48"></RowDefinition>
+            </Grid.RowDefinitions>
+            <Grid>
+                <Grid.ColumnDefinitions>
+                    <ColumnDefinition></ColumnDefinition>
+                    <ColumnDefinition Width="24"></ColumnDefinition>
+                </Grid.ColumnDefinitions>
+                <StackPanel Orientation="Horizontal">
+                    <Grid>
+                        <Ellipse Height="20" Width="20" Fill="#1AD598" Margin="2"></Ellipse>
+                        <Path Fill="White" Data="M18.7527 7.99163L11.1738 16.6583C10.9906 16.8677 10.7285 16.9914 10.4504 16.9996C10.1722 17.0077 9.90329 16.8997 9.70816 16.7013L5.28711 12.2075L6.71282 10.8049L10.3779 14.5303L17.2472 6.67505L18.7527 7.99163Z"></Path>
+                    </Grid>
+                    <TextBlock Text="Set password successfully" FontSize="14" VerticalAlignment="Center" FontFamily="Segoe UI" FontWeight="Medium" ></TextBlock>
+                </StackPanel>
+                <Button Background="Transparent" BorderBrush="Transparent" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Right" Command="{Binding CloseTipCommand}">
+                    <Path Data="M6.00006 7.06066L9.46973 10.5303L10.5304 9.46967L7.06072 6L10.5304 2.53033L9.46973 1.46967L6.00006 4.93934L2.53039 1.46967L1.46973 2.53033L4.9394 6L1.46973 9.46967L2.53039 10.5303L6.00006 7.06066Z" Fill="#94989C"></Path>
+                </Button>
+            </Grid>
+
+            <TextBlock Grid.Row="1" TextWrapping="Wrap"  Text="The security settings do not take effect until the document is saved. You can change the security settings before closing the file." Foreground="{StaticResource color.sys.text.neutral.lv2}" Margin="32,8,16,0" FontFamily="Segoe UI" FontSize="14"></TextBlock>
+            <Button Grid.Row="2" Height="32"  Width="67" HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="Transparent" BorderThickness="1" Command="{Binding CloseTipCommand}">
+                <TextBlock Text="Got it" FontSize="14"></TextBlock>
+            </Button>
+        </Grid>
+    </Border>
+</UserControl>

+ 15 - 0
PDF Office/Views/TipContent/SetPasswordSuccessfullyTip.xaml.cs

@@ -0,0 +1,15 @@
+using System.Windows.Controls;
+
+namespace PDF_Office.Views.TipContent
+{
+    /// <summary>
+    /// Interaction logic for SetPasswordSuccessfullyTip
+    /// </summary>
+    public partial class SetPasswordSuccessfullyTip : UserControl
+    {
+        public SetPasswordSuccessfullyTip()
+        {
+            InitializeComponent();
+        }
+    }
+}

+ 1 - 1
PDF Office/Views/Tools/ToolsBarContent.xaml

@@ -57,7 +57,7 @@
                         <TextBlock VerticalAlignment="Center" Text="文件对比" />
                     </StackPanel>
                 </Button>
-                <Menu Background="White">
+                <Menu Background="Transparent">
                     <MenuItem
                         x:Name="btnPassword"
                         Width="auto"

+ 7 - 1
PDF Office/Views/ViewContent.xaml

@@ -372,7 +372,13 @@
                 VerticalAlignment="Top"
                 prism:RegionManager.RegionName="{Binding TipContentRegionName}"
                 Visibility="{Binding TipVisible}" />
-
+            <!-- 阅读页顶部侧面提示区域 -->
+            <ContentControl
+                Grid.Column="2"
+                VerticalAlignment="Top"
+                HorizontalAlignment="Right"
+                prism:RegionManager.RegionName="{Binding LeftTipContentRegionName}"
+                Visibility="{Binding LeftTipVisible}"  Margin="16,8"/>
             <Border
                 Grid.Column="2"
                 Width="145"