-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathfrmSettings.cs
143 lines (121 loc) · 4.71 KB
/
frmSettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace PDFEncrypt
{
public partial class frmSettings : Form
{
public frmSettings()
{
InitializeComponent();
}
private void frmSettings_Load(object sender, EventArgs e)
{
// Show program version
lblVersion.Text = "Version: " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
// Load encryption types: (Thanks https://stackoverflow.com/a/11745699/1502289)
Dictionary<int, string> encryption_types = new Dictionary<int, string>
{
{ (int)Settings.EncryptionType.AES_256, "AES-256 (Adobe Reader 8+) [recommended]" },
{ (int)Settings.EncryptionType.AES_128, "AES-128 (Adobe Reader 7+" },
{ (int)Settings.EncryptionType.RC4_128, "RC4-128 (Adobe Reader 6+)" },
{ (int)Settings.EncryptionType.RC4_40, "RC4-40 (Adobe Reader 3+) [not recommended]" }
};
// Attach datasource to combo box.
cboEncryptionType.DataSource = new BindingSource(encryption_types, null);
cboEncryptionType.DisplayMember = "Value";
cboEncryptionType.ValueMember = "Key";
// Load settings:
Settings.load(); // Load settings from registry.
// Populate settings to form controls
chkRun.Checked = Settings.run_after;
txtRun.Text = Settings.run_after_file;
txtArguments.Text = Settings.run_after_arguments;
chkPasswordConfirmation.Checked = Settings.password_confirm;
chkCloseAfterCompletion.Checked = Settings.close_after;
chkShowFolder.Checked = Settings.show_folder_after;
chkOpen.Checked = Settings.open_after;
// Encryption options:
cboEncryptionType.SelectedIndex = cboEncryptionType.FindStringExact(encryption_types[(int)Settings.encryption_type]);
chkEncryptMetadata.Checked = Settings.encrypt_metadata;
chkPrinting.Checked = Settings.allow_printing;
chkDegradedPrinting.Checked= Settings.allow_degraded_printing;
chkModifying.Checked = Settings.allow_modifying;
chkNotations.Checked = Settings.allow_modifying_annotations;
chkCopying.Checked = Settings.allow_copying;
chkForms.Checked = Settings.allow_form_fill;
chkAssembly.Checked = Settings.allow_assembly;
chkScreenreaders.Checked = Settings.allow_screenreaders;
}
private void chkRun_CheckedChanged(object sender, EventArgs e)
{
txtRun.Enabled = chkRun.Checked;
btnRunBrowse.Enabled = chkRun.Checked;
}
private void btnRunBrowse_Click(object sender, EventArgs e)
{
var result = dlgOpen.ShowDialog();
if(result == DialogResult.Cancel) { return; }
txtRun.Text = dlgOpen.FileName;
}
private void btnOK_Click(object sender, EventArgs e)
{
// Save settings
// Validate RUN file
if (chkRun.Checked)
{
if (!File.Exists(txtRun.Text))
{
MessageBox.Show("The file to run does not exist.");
txtRun.Focus();
txtRun.SelectAll();
return;
}
}
// Save settings
Settings.run_after = chkRun.Checked;
Settings.run_after_file = txtRun.Text;
Settings.run_after_arguments = txtArguments.Text;
Settings.password_confirm = chkPasswordConfirmation.Checked;
Settings.close_after = chkCloseAfterCompletion.Checked;
Settings.show_folder_after = chkShowFolder.Checked;
Settings.open_after = chkOpen.Checked;
// Encryption options
Settings.encryption_type = (Settings.EncryptionType)cboEncryptionType.SelectedValue;
Settings.encrypt_metadata = chkEncryptMetadata.Checked;
Settings.allow_printing = chkPrinting.Checked;
Settings.allow_degraded_printing = chkDegradedPrinting.Checked;
Settings.allow_modifying = chkModifying.Checked;
Settings.allow_modifying_annotations = chkNotations.Checked;
Settings.allow_copying = chkCopying.Checked;
Settings.allow_form_fill = chkForms.Checked;
Settings.allow_assembly = chkAssembly.Checked;
Settings.allow_screenreaders = chkScreenreaders.Checked;
Settings.save();
// Close settings window
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void lblVisitSite_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("https://pdfencrypt.net");
}
private void chkRun_CheckedChanged_1(object sender, EventArgs e)
{
}
private void linkDonate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("https://www.paypal.com/donate?hosted_button_id=KBE8SENS5JCSG");
}
}
}