Procházet zdrojové kódy

安全-解密功能(现有接口)

liuaoran před 2 roky
rodič
revize
70ec14a471

+ 3 - 2
PDF Office/App.xaml.cs

@@ -25,7 +25,8 @@ using PDF_Office.Properties;
 using PDFSettings.Settings;
 using PDF_Office.Views.Tools; 
 using PDF_Office.Views.Dialog.ToolsDialogs.SaftyDialogs;
-using PDF_Office.Views.Dialog.ToolsDialogs.CompressDialogs; 
+using PDF_Office.Views.Dialog.ToolsDialogs.CompressDialogs;
+using PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs;
 
 namespace PDF_Office
 {
@@ -87,7 +88,7 @@ namespace PDF_Office
             containerRegistry.RegisterDialog<CompressDialog>(DialogNames.CompressDialog);
             containerRegistry.RegisterDialog<SetPasswordDialog>(DialogNames.SetPasswordDialog);
             containerRegistry.RegisterDialog<CheckPasswordDialog>(DialogNames.CheckPasswordDialog);
-            containerRegistry.RegisterDialog<CancelPasswordDialog>(DialogNames.CancelPasswordDialog);
+            containerRegistry.RegisterDialog<DeleteSafetySettingsDialog>(DialogNames.DeleteSafetySettingsDialog);
             containerRegistry.RegisterDialog<CompressProgressBarDialog, PDF_Office.ViewModels.Dialog.ToolsDialogs.CompressDialogs.CompresProgressBarDialogViewModel>(DialogNames.CompressProgressBarDialog);
         }
 

+ 13 - 0
PDF Office/Model/Dialog/ToolsDialogs/SaftyDialogs/CheckPasswordDialogModel.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs
+{
+    internal class CheckPasswordDialogModel
+    {
+        static public string Password = "";
+    }
+}

+ 19 - 0
PDF Office/Model/Dialog/ToolsDialogs/SaftyDialogs/DeleteSafetySettintgsModel.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs
+{
+    public class DeleteSafetySettintgsModel
+    {
+      
+        public enum EnumNeedPassword
+        {
+            CannotDecrypt,
+            VerifyPassword,
+            DirectDescrypt
+        }
+    }
+}

+ 16 - 16
PDF Office/Model/Dialog/ToolsDialogs/SaftyDialogs/SetPasswordDialogModel.cs

@@ -39,16 +39,16 @@ namespace PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs
             switch (printMod)
             {
                 case PrintMod.None:
-                    permissionsInfo.AllowsPrinting= false;
-                    permissionsInfo.AllowsHighQualityPrinting= false;
+                    permissionsInfo.AllowsPrinting = false;
+                    permissionsInfo.AllowsHighQualityPrinting = false;
                     break;
                 case PrintMod.LowDpi:
-                    permissionsInfo.AllowsPrinting= true;
+                    permissionsInfo.AllowsPrinting = true;
                     permissionsInfo.AllowsHighQualityPrinting = false;
                     break;
-                case PrintMod.HighDpi: 
-                    permissionsInfo.AllowsHighQualityPrinting= true;
-                    permissionsInfo.AllowsPrinting=true;
+                case PrintMod.HighDpi:
+                    permissionsInfo.AllowsHighQualityPrinting = true;
+                    permissionsInfo.AllowsPrinting = true;
                     break;
                 default:
                     break;
@@ -56,18 +56,18 @@ namespace PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs
             switch (changeMod)
             {
                 case ChangeMod.None:
-                    permissionsInfo.AllowsCopying= false;
-                    permissionsInfo.AllowsDocumentAssembly= false;
-                    permissionsInfo.AllowsCommenting= false;
-                    permissionsInfo.AllowsDocumentChanges= false;
-                    permissionsInfo.AllowsFormFieldEntry= false;
+                    permissionsInfo.AllowsCopying = false;
+                    permissionsInfo.AllowsDocumentAssembly = false;
+                    permissionsInfo.AllowsCommenting = false;
+                    permissionsInfo.AllowsDocumentChanges = false;
+                    permissionsInfo.AllowsFormFieldEntry = false;
                     break;
                 case ChangeMod.ChangePage:
-                    permissionsInfo.AllowsCopying= false;
-                    permissionsInfo.AllowsDocumentAssembly= true;
-                    permissionsInfo.AllowsCommenting= false;
-                    permissionsInfo.AllowsDocumentChanges= false;
-                    permissionsInfo.AllowsFormFieldEntry= false;
+                    permissionsInfo.AllowsCopying = false;
+                    permissionsInfo.AllowsDocumentAssembly = true;
+                    permissionsInfo.AllowsCommenting = false;
+                    permissionsInfo.AllowsDocumentChanges = false;
+                    permissionsInfo.AllowsFormFieldEntry = false;
                     break;
                 case ChangeMod.FormAndSignature:
                     permissionsInfo.AllowsCopying = false;

+ 2 - 2
PDF Office/Model/DialogNames.cs

@@ -37,9 +37,9 @@ namespace PDF_Office.Model
         public static string CheckPasswordDialog = "CheckPasswordDialog";
 
         /// <summary>
-        /// 解压缩弹窗
+        /// 删除安全性设置
         /// </summary>
-        public static string CancelPasswordDialog = "CancelPasswordDialog";
+        public static string DeleteSafetySettingsDialog = "DeleteSafetySettingsDialog";
 
         /// <summary>
         /// 进度条

+ 8 - 6
PDF Office/PDF Office.csproj

@@ -126,6 +126,8 @@
       <DependentUpon>LoadingControl.xaml</DependentUpon>
     </Compile>
     <Compile Include="Model\Dialog\ToolsDialogs\CompressDialogModel\CompressDialogModel.cs" />
+    <Compile Include="Model\Dialog\ToolsDialogs\SaftyDialogs\CheckPasswordDialogModel.cs" />
+    <Compile Include="Model\Dialog\ToolsDialogs\SaftyDialogs\DeleteSafetySettintgsModel.cs" />
     <Compile Include="Model\Dialog\ToolsDialogs\SaftyDialogs\SetPasswordDialogModel.cs" />
     <Compile Include="Model\PageEdit\PageEditItem.cs" />
     <Compile Include="Model\ParameterNames.cs" />
@@ -146,7 +148,7 @@
     <Compile Include="ViewModels\Dialog\PageEditDialogs\SplitDialogViewModel.cs" />
     <Compile Include="ViewModels\Dialog\ToolsDialogs\CompressDialogs\CompressDialogViewModel.cs" />
     <Compile Include="ViewModels\Dialog\ToolsDialogs\CompressDialogs\CompressProgressBarDialogViewModel.cs" />
-    <Compile Include="ViewModels\Dialog\ToolsDialogs\SaftyDialogs\CancelPasswordDialogViewModel.cs" />
+    <Compile Include="ViewModels\Dialog\ToolsDialogs\SaftyDialogs\DeleteSafetySettingsDialogViewModel.cs" />
     <Compile Include="ViewModels\Dialog\ToolsDialogs\SaftyDialogs\CheckPasswordDialogViewModel.cs" />
     <Compile Include="ViewModels\Dialog\ToolsDialogs\SaftyDialogs\SetPasswordDialogViewModel.cs" />
     <Compile Include="ViewModels\Dialog\VerifyPassWordDialogViewModel.cs" />
@@ -180,12 +182,12 @@
     <Compile Include="Views\Dialog\ToolsDialogs\CompressDialogs\CompressProgressBarDialog.xaml.cs">
       <DependentUpon>CompressProgressBarDialog.xaml</DependentUpon>
     </Compile>
-    <Compile Include="Views\Dialog\ToolsDialogs\SaftyDialogs\CancelPasswordDialog.xaml.cs">
-      <DependentUpon>CancelPasswordDialog.xaml</DependentUpon>
-    </Compile>
     <Compile Include="Views\Dialog\ToolsDialogs\SaftyDialogs\CheckPasswordDialog.xaml.cs">
       <DependentUpon>CheckPasswordDialog.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Views\Dialog\ToolsDialogs\SaftyDialogs\DeleteSafetySettingsDialog.xaml.cs">
+      <DependentUpon>DeleteSafetySettingsDialog.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Views\Dialog\ToolsDialogs\SaftyDialogs\SetPasswordDialog.xaml.cs">
       <DependentUpon>SetPasswordDialog.xaml</DependentUpon>
     </Compile>
@@ -306,11 +308,11 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
-    <Page Include="Views\Dialog\ToolsDialogs\SaftyDialogs\CancelPasswordDialog.xaml">
+    <Page Include="Views\Dialog\ToolsDialogs\SaftyDialogs\CheckPasswordDialog.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
-    <Page Include="Views\Dialog\ToolsDialogs\SaftyDialogs\CheckPasswordDialog.xaml">
+    <Page Include="Views\Dialog\ToolsDialogs\SaftyDialogs\DeleteSafetySettingsDialog.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>

+ 3 - 1
PDF Office/ViewModels/Dialog/ToolsDialogs/CompressDialogs/CompressDialogViewModel.cs

@@ -158,7 +158,9 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.CompressDialogs
                 value.Add(ParameterNames.FilePath, sfd.FileName);
                 value.Add("compressDialogModel.CompressQuality", (int)compressDialogModel.CompressQuality);
                 RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
-                dialogs.ShowDialog(DialogNames.CompressProgressBarDialog, value, e => { }); 
+                dialogs.ShowDialog(DialogNames.CompressProgressBarDialog, value, e => {
+                
+                }); 
             }
             else
             {

+ 0 - 62
PDF Office/ViewModels/Dialog/ToolsDialogs/SaftyDialogs/CancelPasswordDialogViewModel.cs

@@ -1,62 +0,0 @@
-using ComPDFKit.PDFDocument;
-using PDF_Office.Model;
-using Prism.Commands;
-using Prism.Mvvm;
-using Prism.Services.Dialogs;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-
-namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
-{
-
-    public class CancelPasswordDialogViewModel : BindableBase,IDialogAware
-    {
-        
-
-        public IDialogService dialogs;
-
-        private CPDFDocument document;
-        
-        public DelegateCommand CheckPasswordCommand { get; set; }
-
-        public CancelPasswordDialogViewModel(IDialogService dialogService)
-        {
-            dialogs = dialogService;
-            CheckPasswordCommand = new DelegateCommand(OpenCheckPassword);
-        }
-
-        private void OpenCheckPassword()
-        {
-            DialogParameters value = new DialogParameters(); 
-            value.Add("1", 1);
-            RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
-            dialogs.ShowDialog(DialogNames.CheckPasswordDialog, value, e => {
-            }); 
-        }
-
-        public string Title => "";
-
-        public event Action<IDialogResult> RequestClose;
-
-        public bool CanCloseDialog()
-        {
-            return true;
-        }
-
-        public void OnDialogClosed()
-        {
-        }
-
-        public void OnDialogOpened(IDialogParameters parameters)
-        {
-            CPDFDocument doc = null;
-            parameters.TryGetValue<CPDFDocument>(ParameterNames.PDFDocument, out doc);
-            if (doc != null)
-            {
-                document = doc;
-            }
-        }
-    }
-}

+ 19 - 5
PDF Office/ViewModels/Dialog/ToolsDialogs/SaftyDialogs/CheckPasswordDialogViewModel.cs

@@ -1,5 +1,6 @@
 using ComPDFKit.PDFDocument;
 using PDF_Office.Model;
+using PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs;
 using Prism.Commands;
 using Prism.Mvvm;
 using Prism.Services.Dialogs;
@@ -13,18 +14,31 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
     public class CheckPasswordDialogViewModel : BindableBase,IDialogAware
     {
         private CPDFDocument document;
-        public DelegateCommand DeletePasswordCommand { get; set; }
+        public DelegateCommand DelegateConfirmCheckPasswordCommand { get; set; }
+        public DelegateCommand DelegateCancelCheckPasswordCommand { get; set; }
         public CheckPasswordDialogViewModel()
         {
-            DeletePasswordCommand = new DelegateCommand(DeletePassword);
+            CheckPasswordDialogModel.Password = "";
+            DelegateConfirmCheckPasswordCommand = new DelegateCommand(ConfirmCheckPassword);
+            DelegateCancelCheckPasswordCommand = new DelegateCommand(CancelCheckPassword);
         }
 
-        private void DeletePassword()
+        private void ConfirmCheckPassword()
         {
-            if (document.IsEncrypted)
+            if (false)//预留接口
             {
-
+                 
             }
+            var dialogResult = new DialogResult(ButtonResult.OK);
+            dialogResult.Parameters.Add("CheckPassword", true);
+            RequestClose.Invoke(dialogResult);
+        }
+
+        private void CancelCheckPassword()
+        {
+            var dialogResult = new DialogResult(ButtonResult.Cancel);
+            dialogResult.Parameters.Add("CheckPassword", false);
+            RequestClose.Invoke(dialogResult);
         }
 
         public string Title =>"";

+ 131 - 0
PDF Office/ViewModels/Dialog/ToolsDialogs/SaftyDialogs/DeleteSafetySettingsDialogViewModel.cs

@@ -0,0 +1,131 @@
+using ComPDFKit.PDFDocument;
+using PDF_Office.Model;
+using PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs;
+using Prism.Commands;
+using Prism.Mvvm;
+using Prism.Services.Dialogs;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Windows.Forms;
+
+namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
+{
+
+    public class DeleteSafetySettingsDialogViewModel : BindableBase, IDialogAware
+    {
+
+        DeleteSafetySettintgsModel deleteSafetySettintgsModel;
+        public IDialogService dialogs;
+
+        private CPDFDocument document;
+
+        public DelegateCommand CheckPasswordCommand { get; set; }
+
+        public DeleteSafetySettingsDialogViewModel(IDialogService dialogService)
+        {
+            dialogs = dialogService;
+            CheckPasswordCommand = new DelegateCommand(OpenCheckPassword);
+        }
+
+        private DeleteSafetySettintgsModel.EnumNeedPassword CheckNeedPassword()
+        {
+            if (document.IsLocked)
+            {
+                return DeleteSafetySettintgsModel.EnumNeedPassword.VerifyPassword;
+            }
+            else { }
+            if (document.IsEncrypted)
+            {
+                return DeleteSafetySettintgsModel.EnumNeedPassword.VerifyPassword;
+            }
+            else
+            {
+                return DeleteSafetySettintgsModel.EnumNeedPassword.CannotDecrypt;
+            }
+        }
+
+        private void OpenCheckPassword()
+        {
+            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 + "_CompressFile.pdf";
+            /*
+             * 做一些工作
+             */
+            if (CheckNeedPassword() == DeleteSafetySettintgsModel.EnumNeedPassword.VerifyPassword)
+            {
+                bool IfDiscryptied = false;
+                DialogParameters value = new DialogParameters();
+                RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
+                dialogs.ShowDialog(DialogNames.CheckPasswordDialog, value, e => { IfDiscryptied = e.Parameters.GetValue<bool>("CheckPassword"); });
+
+                if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+                {
+                    if (IfDiscryptied)
+                    {
+                        document.Descrypt(sfd.FileName);
+                    }
+                    else { }
+                    MessageBox.Show("保存成功");
+                    RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
+                }
+                else
+                {
+                    MessageBox.Show("取消保存");
+                }
+            }
+            else if (CheckNeedPassword() == DeleteSafetySettintgsModel.EnumNeedPassword.DirectDescrypt)
+            {
+                if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+                {
+                    document.Descrypt(sfd.FileName);
+                    MessageBox.Show("Ok");
+                    RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
+                }
+                else
+                {
+                    MessageBox.Show("取消保存");
+                }
+            }
+            else { MessageBox.Show("无可用安全性设置"); }
+            RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
+
+        }
+
+        public string Title => "";
+
+        public event Action<IDialogResult> RequestClose;
+
+        public bool CanCloseDialog()
+        {
+            return true;
+        }
+
+        public void OnDialogClosed()
+        {
+        }
+
+        public void OnDialogOpened(IDialogParameters parameters)
+        {
+            CPDFDocument doc = null;
+            parameters.TryGetValue<CPDFDocument>(ParameterNames.PDFDocument, out doc);
+            if (doc != null)
+            {
+                document = doc;
+            }
+        }
+    }
+}

+ 1 - 1
PDF Office/ViewModels/Tools/ToolsBarContentViewModel.cs

@@ -57,7 +57,7 @@ namespace PDF_Office.ViewModels.Tools
         {
             DialogParameters value = new DialogParameters();
             value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
-            dialogs.ShowDialog(DialogNames.CancelPasswordDialog, value, e => { });
+            dialogs.ShowDialog(DialogNames.DeleteSafetySettingsDialog, value, e => { });
         }
 
         public bool IsNavigationTarget(NavigationContext navigationContext)

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

@@ -10,15 +10,15 @@
         </Grid.RowDefinitions>
         <StackPanel Grid.Row="0" Orientation="Vertical" VerticalAlignment="Center" Margin="20" Width="320">
             <TextBlock  Text="该文件已开启权限保护,请输入密码" FontSize="14" Margin="0,0,0,15"/>
-            <TextBox/>
+            <PasswordBox Name="ForCheckPasswordBox" PasswordChanged="ForCheckPasswordBox_PasswordChanged"></PasswordBox>
         </StackPanel>
         <StackPanel Grid.Row="1"  Orientation="Horizontal" HorizontalAlignment="Right" >
-            <Button Background="WhiteSmoke" Width="100" Height="25" Margin="40,0,20,0" Command="{Binding CheckPasswordCommand}">
+            <Button Background="WhiteSmoke" Width="100" Height="25" Margin="40,0,20,0" Command="{Binding  DelegateConfirmCheckPasswordCommand}">
                 <Border>
                     <TextBlock Text="确定" ></TextBlock>
                 </Border>
             </Button>
-            <Button Background="WhiteSmoke" Width="100" Height="25" Margin="0,0,10,0" >
+            <Button Background="WhiteSmoke" Width="100" Height="25" Margin="0,0,10,0" Command="{Binding DelegateCancelCheckPasswordCommand}">
                 <Border>
                     <TextBlock Text="取消" ></TextBlock>
                 </Border>

+ 9 - 1
PDF Office/Views/Dialog/ToolsDialogs/SaftyDialogs/CheckPasswordDialog.xaml.cs

@@ -1,4 +1,6 @@
-using System.Windows.Controls;
+using PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs;
+using PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs;
+using System.Windows.Controls;
 
 namespace PDF_Office.Views.Dialog.ToolsDialogs.SaftyDialogs
 {
@@ -10,6 +12,12 @@ namespace PDF_Office.Views.Dialog.ToolsDialogs.SaftyDialogs
         public CheckPasswordDialog()
         {
             InitializeComponent();
+            CheckPasswordDialogModel.Password=ForCheckPasswordBox.Password;
+        }
+
+        private void ForCheckPasswordBox_PasswordChanged(object sender, System.Windows.RoutedEventArgs e)
+        {
+            CheckPasswordDialogModel.Password = ForCheckPasswordBox.Password;
         }
     }
 }

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

@@ -1,9 +1,9 @@
-<UserControl x:Class="PDF_Office.Views.Dialog.ToolsDialogs.SaftyDialogs.CancelPasswordDialog"
+<UserControl x:Class="PDF_Office.Views.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettingsDialog"
              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"
              xmlns:prism="http://prismlibrary.com/"             
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"           
              prism:ViewModelLocator.AutoWireViewModel="True"
              d:DesignHeight="168"
              d:DesignWidth="340"
@@ -28,3 +28,4 @@
         </StackPanel>
     </Grid>
 </UserControl>
+

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

@@ -3,11 +3,11 @@
 namespace PDF_Office.Views.Dialog.ToolsDialogs.SaftyDialogs
 {
     /// <summary>
-    /// Interaction logic for CancelPasswordDialog
+    /// Interaction logic for DeleteSafetySettingsDialog
     /// </summary>
-    public partial class CancelPasswordDialog : UserControl
+    public partial class DeleteSafetySettingsDialog : UserControl
     {
-        public CancelPasswordDialog()
+        public DeleteSafetySettingsDialog()
         {
             InitializeComponent();
         }