12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.IO;
- using System.Runtime.CompilerServices;
- using System.Windows;
- using System.Windows.Forms;
- using Compdfkit_Tools.Common;
- using ComPDFKit.PDFDocument;
- namespace Compdfkit_Tools.PDFControl
- {
- public partial class DecryptionDialog : Window, INotifyPropertyChanged
- {
- private CPDFDocument document;
- private List<string> failedList = new List<string>();
-
- public event PropertyChangedEventHandler PropertyChanged;
- public DecryptionDialog()
- {
- InitializeComponent();
- DataContext = this;
- }
- private void Cancel_Click(object sender, RoutedEventArgs e)
- {
- this.Close();
- }
- private void Remove_Click(object sender, RoutedEventArgs e)
- {
- var dialog = new FolderBrowserDialog();
- dialog.ShowDialog();
- var savePath = dialog.SelectedPath;
- if (string.IsNullOrEmpty(savePath)) return;
-
- foreach (var fileInfoData in FileListControl.FileInfoDataList)
- {
- document = CPDFDocument.InitWithFilePath(fileInfoData.Location);
- if (document.IsLocked)
- {
- PasswordWindow window = new PasswordWindow();
- window.InitWithDocument(document);
- window.Owner = this;
- window.ShowDialog();
- if (document.IsLocked)
- {
- failedList.Add(fileInfoData.Location);
- continue;
- }
- }
- var fullSavePath = savePath + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(fileInfoData.FileName) + "_Encrypted.pdf";
- if(!document.Decrypt(fullSavePath))
- {
- failedList.Add(fileInfoData.Location);
- }
- document.Release();
- }
- if (failedList.Count > 0)
- {
- var message = "Failed to remove password for the following files:\n" + string.Join("\n", failedList);
- System.Windows.MessageBox.Show(message, "Failed to remove password", MessageBoxButton.OK, MessageBoxImage.Warning);
- }
- if(failedList.Count < FileListControl.FileInfoDataList.Count)
- {
- System.Diagnostics.Process.Start(savePath);
- }
- this.Close();
- }
-
- protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
- {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
-
- }
- }
|