This repository was archived by the owner on Jan 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathConfigForm.cs
More file actions
91 lines (83 loc) · 3.17 KB
/
ConfigForm.cs
File metadata and controls
91 lines (83 loc) · 3.17 KB
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
using System;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
namespace GoogleImageShell
{
public partial class ConfigForm : Form
{
public ConfigForm()
{
InitializeComponent();
}
private void ConfigForm_Load(object sender, EventArgs e)
{
Version version = Assembly.GetExecutingAssembly().GetName().Version;
Text += $" v{version.Major}.{version.Minor}.{version.Build}";
foreach (object type in Enum.GetValues(typeof(ImageFileType)))
{
fileTypeListBox.Items.Add(type, true);
}
}
private void installButton_Click(object sender, EventArgs e)
{
string menuText = menuTextTextBox.Text;
bool includeFileName = includeFileNameCheckBox.Checked;
bool allUsers = allUsersCheckBox.Checked;
bool resizeOnUpload = resizeOnUploadCheckbox.Checked;
ImageFileType[] types = fileTypeListBox.CheckedItems.Cast<ImageFileType>().ToArray();
Install(menuText, includeFileName, allUsers, resizeOnUpload, types);
}
private void uninstallButton_Click(object sender, EventArgs e)
{
bool allUsers = allUsersCheckBox.Checked;
ImageFileType[] types = fileTypeListBox.CheckedItems.Cast<ImageFileType>().ToArray();
Uninstall(allUsers, types);
}
private static void Install(string menuText, bool includeFileName, bool allUsers, bool resizeOnUpload, ImageFileType[] types)
{
try
{
ShortcutMenu.InstallHandler(menuText, includeFileName, allUsers, resizeOnUpload, types);
}
catch (Exception ex)
{
ErrorMsgBox(
"Installation failed",
"Could not add context menu entries to Windows Explorer.\n\n" +
ex.Message);
return;
}
InfoMsgBox(
"Installation succeeded",
"Context menu entries were added to Windows Explorer. " +
"Remember to reinstall the program if you move or rename it!");
}
private static void Uninstall(bool allUsers, ImageFileType[] types)
{
try
{
ShortcutMenu.UninstallHandler(allUsers, types);
}
catch (Exception ex)
{
ErrorMsgBox(
"Uninstallation failed",
"Could not remove context menu entries from Windows Explorer.\n\n" +
ex.Message);
return;
}
InfoMsgBox(
"Uninstallation succeeded",
"Context menu entries were removed from Windows Explorer.");
}
private static void InfoMsgBox(string title, string message)
{
MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private static void ErrorMsgBox(string title, string message)
{
MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}