Skip to content

Commit 786183b

Browse files
committed
Issues #131 Added "ignoreHook" attribute to the "processName" element in the SmartSystemMenu.xml
1 parent 69cb937 commit 786183b

File tree

8 files changed

+90
-62
lines changed

8 files changed

+90
-62
lines changed

SmartSystemMenu/Forms/MainForm.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ protected override void OnLoad(EventArgs e)
127127
{
128128
var processPath = window.Process?.GetMainModuleFileName() ?? string.Empty;
129129
var fileName = Path.GetFileName(processPath);
130-
if (!string.IsNullOrEmpty(fileName) && _settings.ExcludedProcessNames.Contains(fileName.ToLower()) || _settings.InitEventProcessNames.Contains(fileName.ToLower()))
130+
if (!string.IsNullOrEmpty(fileName) && _settings.ExcludedProcessItems.Select(x => x.Name).Contains(fileName.ToLower()) || _settings.InitEventProcessNames.Contains(fileName.ToLower()))
131131
{
132132
continue;
133133
}
@@ -405,7 +405,7 @@ private void WindowCreated(object sender, WindowEventArgs e)
405405
var processPath = process?.GetMainModuleFileName() ?? string.Empty;
406406
var fileName = Path.GetFileName(processPath);
407407
if (!string.IsNullOrEmpty(fileName) &&
408-
_settings.ExcludedProcessNames.Contains(fileName.ToLower()) || _settings.InitEventProcessNames.Contains(fileName.ToLower()))
408+
_settings.ExcludedProcessItems.Select(x => x.Name).Contains(fileName.ToLower()) || _settings.InitEventProcessNames.Contains(fileName.ToLower()))
409409
{
410410
return;
411411
}
@@ -424,7 +424,7 @@ private void InitMenu(object sender, SysCommandEventArgs e)
424424
var processPath = process?.GetMainModuleFileName() ?? string.Empty;
425425
var fileName = Path.GetFileName(processPath);
426426
if (!string.IsNullOrEmpty(fileName) &&
427-
_settings.ExcludedProcessNames.Contains(fileName.ToLower()) || !_settings.InitEventProcessNames.Contains(fileName.ToLower()))
427+
_settings.ExcludedProcessItems.Select(x => x.Name).Contains(fileName.ToLower()) || !_settings.InitEventProcessNames.Contains(fileName.ToLower()))
428428
{
429429
return;
430430
}
@@ -1187,7 +1187,7 @@ private void HotKeyHooked(object sender, HotKeyEventArgs e)
11871187
{
11881188
}
11891189

1190-
if (!_settings.ExcludedProcessNames.Contains(processName.ToLower()))
1190+
if (!_settings.ExcludedProcessItems.Select(x => x.Name).Contains(processName.ToLower()))
11911191
{
11921192
PostMessage(handle, WM_SYSCOMMAND, (uint)e.MenuItemId, 0);
11931193
e.Succeeded = true;

SmartSystemMenu/Forms/SettingsForm.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,12 @@ private void InitializeControls(ApplicationSettings settings)
9797
btnCancel.Text = settings.Language.GetValue("settings_btn_cancel");
9898
Text = settings.Language.GetValue("settings_form");
9999

100-
foreach (var processExclusion in settings.ExcludedProcessNames)
100+
foreach (var processItem in settings.ExcludedProcessItems)
101101
{
102102
var index = gvProcessExclusions.Rows.Add();
103103
var row = gvProcessExclusions.Rows[index];
104-
row.Cells[0].Value = processExclusion;
104+
row.Cells[0].Value = processItem.Name;
105+
row.Cells[0].Tag = processItem.IgnoreHook;
105106
row.Cells[1].ToolTipText = settings.Language.GetValue("clm_process_exclusion_edit");
106107
row.Cells[2].ToolTipText = settings.Language.GetValue("clm_process_exclusion_delete");
107108
}
@@ -546,7 +547,13 @@ private void ButtonApplyClick(object sender, EventArgs e)
546547

547548
foreach (DataGridViewRow row in gvProcessExclusions.Rows)
548549
{
549-
settings.ExcludedProcessNames.Add(row.Cells[0].Value.ToString());
550+
var processItem = new ExcludedProcessItem
551+
{
552+
Name = row.Cells[0].Value.ToString(),
553+
IgnoreHook = row.Cells[0].Tag != null && row.Cells[0].Tag.ToString().ToLower() == "true"
554+
};
555+
556+
settings.ExcludedProcessItems.Add(processItem);
550557
}
551558

552559
foreach (DataGridViewRow row in gvWindowSize.Rows)

SmartSystemMenu/Settings/ApplicationSettings.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace SmartSystemMenu.Settings
55
{
66
public class ApplicationSettings : ICloneable
77
{
8-
public IList<string> ExcludedProcessNames { get; set; }
8+
public IList<ExcludedProcessItem> ExcludedProcessItems { get; set; }
99

1010
public IList<string> InitEventProcessNames { get; set; }
1111

@@ -32,7 +32,7 @@ public class ApplicationSettings : ICloneable
3232

3333
public ApplicationSettings()
3434
{
35-
ExcludedProcessNames = new List<string>();
35+
ExcludedProcessItems = new List<ExcludedProcessItem>();
3636
InitEventProcessNames = new List<string>();
3737
NoRestoreMenuProcessNames = new List<string>();
3838
MenuItems = new MenuItems();
@@ -50,9 +50,9 @@ public object Clone()
5050
{
5151
var settings = new ApplicationSettings();
5252

53-
foreach (var processName in ExcludedProcessNames)
53+
foreach (var processItem in ExcludedProcessItems)
5454
{
55-
settings.ExcludedProcessNames.Add(processName);
55+
settings.ExcludedProcessItems.Add((ExcludedProcessItem)processItem.Clone());
5656
}
5757

5858
foreach (var processName in InitEventProcessNames)
@@ -132,7 +132,7 @@ public bool Equals(ApplicationSettings other)
132132
return false;
133133
}
134134

135-
if (ExcludedProcessNames.Count != other.ExcludedProcessNames.Count)
135+
if (ExcludedProcessItems.Count != other.ExcludedProcessItems.Count)
136136
{
137137
return false;
138138
}
@@ -162,9 +162,10 @@ public bool Equals(ApplicationSettings other)
162162
return false;
163163
}
164164

165-
for (var i = 0; i < ExcludedProcessNames.Count; i++)
165+
for (var i = 0; i < ExcludedProcessItems.Count; i++)
166166
{
167-
if (string.Compare(ExcludedProcessNames[i], other.ExcludedProcessNames[i], StringComparison.CurrentCultureIgnoreCase) != 0)
167+
if (string.Compare(ExcludedProcessItems[i].Name, other.ExcludedProcessItems[i].Name, StringComparison.CurrentCultureIgnoreCase) != 0 ||
168+
ExcludedProcessItems[i].IgnoreHook != other.ExcludedProcessItems[i].IgnoreHook)
168169
{
169170
return false;
170171
}
@@ -297,9 +298,9 @@ public override int GetHashCode()
297298
{
298299
var hashCode = 0;
299300

300-
foreach (var processName in ExcludedProcessNames)
301+
foreach (var processItem in ExcludedProcessItems)
301302
{
302-
hashCode ^= processName.GetHashCode();
303+
hashCode ^= processItem.Name.GetHashCode() ^ processItem.IgnoreHook.GetHashCode();
303304
}
304305

305306
foreach (var processName in InitEventProcessNames)

SmartSystemMenu/Settings/ApplicationSettingsFile.cs

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ public static ApplicationSettings Read(string fileName, string languageFileName)
1717
var document = XDocument.Load(fileName);
1818
var languageDocument = XDocument.Load(languageFileName);
1919

20-
settings.ExcludedProcessNames = document
20+
settings.ExcludedProcessItems = document
2121
.XPathSelectElements("/smartSystemMenu/processExclusions/processName")
2222
.Where(x => !string.IsNullOrWhiteSpace(x.Value))
23-
.Select(x => x.Value.ToLower())
23+
.Select(x => new ExcludedProcessItem
24+
{
25+
Name = x.Value.ToLower(),
26+
IgnoreHook = x.Attribute("ignoreHook") != null && x.Attribute("ignoreHook").Value.ToLower() == "true",
27+
})
2428
.ToList();
2529

2630
settings.InitEventProcessNames = document
@@ -39,7 +43,7 @@ public static ApplicationSettings Read(string fileName, string languageFileName)
3943
.XPathSelectElements("/smartSystemMenu/menuItems/windowSizeItems/item")
4044
.Select(x => new WindowSizeMenuItem
4145
{
42-
Title = x.Attribute("title") != null ? x.Attribute("title").Value : "",
46+
Title = x.Attribute("title") != null ? x.Attribute("title").Value : string.Empty,
4347
Left = !string.IsNullOrEmpty(x.Attribute("left").Value) ? int.Parse(x.Attribute("left").Value) : null,
4448
Top = !string.IsNullOrEmpty(x.Attribute("top").Value) ? int.Parse(x.Attribute("top").Value) : null,
4549
Width = !string.IsNullOrEmpty(x.Attribute("width").Value) ? int.Parse(x.Attribute("width").Value) : null,
@@ -54,11 +58,11 @@ public static ApplicationSettings Read(string fileName, string languageFileName)
5458
.XPathSelectElements("/smartSystemMenu/menuItems/startProgramItems/item")
5559
.Select(x => new StartProgramMenuItem
5660
{
57-
Title = x.Attribute("title") != null ? x.Attribute("title").Value : "",
58-
FileName = x.Attribute("fileName") != null ? x.Attribute("fileName").Value : "",
59-
Arguments = x.Attribute("arguments") != null ? x.Attribute("arguments").Value : "",
60-
BeginParameter = x.Attribute("beginParameter") != null ? x.Attribute("beginParameter").Value : "",
61-
EndParameter = x.Attribute("endParameter") != null ? x.Attribute("endParameter").Value : "",
61+
Title = x.Attribute("title") != null ? x.Attribute("title").Value : string.Empty,
62+
FileName = x.Attribute("fileName") != null ? x.Attribute("fileName").Value : string.Empty,
63+
Arguments = x.Attribute("arguments") != null ? x.Attribute("arguments").Value : string.Empty,
64+
BeginParameter = x.Attribute("beginParameter") != null ? x.Attribute("beginParameter").Value : string.Empty,
65+
EndParameter = x.Attribute("endParameter") != null ? x.Attribute("endParameter").Value : string.Empty,
6266
RunAs = x.Attribute("runAs") != null && !string.IsNullOrEmpty(x.Attribute("runAs").Value) ? (UserType)Enum.Parse(typeof(UserType), x.Attribute("runAs").Value, true) : UserType.Normal,
6367
ShowWindow = x.Attribute("showWindow") == null || string.IsNullOrEmpty(x.Attribute("showWindow").Value) || x.Attribute("showWindow").Value.ToLower() == "true",
6468
UseWindowWorkingDirectory = x.Attribute("useWindowWorkingDirectory") != null && !string.IsNullOrEmpty(x.Attribute("useWindowWorkingDirectory").Value) && x.Attribute("useWindowWorkingDirectory").Value.ToLower() == "true"
@@ -70,7 +74,7 @@ public static ApplicationSettings Read(string fileName, string languageFileName)
7074
.Select(x => {
7175
var menuItem = new MenuItem
7276
{
73-
Name = x.Attribute("name") != null ? x.Attribute("name").Value : "",
77+
Name = x.Attribute("name") != null ? x.Attribute("name").Value : string.Empty,
7478
Show = x.Attribute("show") != null ? x.Attribute("show").Value.ToLower() != "false" : true,
7579
Type = x.Attribute("type") != null && !string.IsNullOrEmpty(x.Attribute("type").Value) ? (MenuItemType)Enum.Parse(typeof(MenuItemType), x.Attribute("type").Value, true) : MenuItemType.Item,
7680
Key1 = x.Attribute("key1") != null && !string.IsNullOrEmpty(x.Attribute("key1").Value) ? (VirtualKeyModifier)int.Parse(x.Attribute("key1").Value) : VirtualKeyModifier.None,
@@ -81,7 +85,7 @@ public static ApplicationSettings Read(string fileName, string languageFileName)
8185
x.XPathSelectElements("./items/item")
8286
.Select(y => new MenuItem
8387
{
84-
Name = y.Attribute("name") != null ? y.Attribute("name").Value : "",
88+
Name = y.Attribute("name") != null ? y.Attribute("name").Value : string.Empty,
8589
Show = y.Attribute("show") != null ? y.Attribute("show").Value.ToLower() != "false" : true,
8690
Type = y.Attribute("type") != null && !string.IsNullOrEmpty(y.Attribute("type").Value) ? (MenuItemType)Enum.Parse(typeof(MenuItemType), y.Attribute("type").Value, true) : MenuItemType.Item,
8791
Key1 = y.Attribute("key1") != null && !string.IsNullOrEmpty(y.Attribute("key1").Value) ? (VirtualKeyModifier)int.Parse(y.Attribute("key1").Value) : VirtualKeyModifier.None,
@@ -168,34 +172,35 @@ public static void Save(string fileName, ApplicationSettings settings)
168172
{
169173
var document = new XDocument();
170174
document.Add(new XElement("smartSystemMenu",
171-
new XElement("processExclusions", settings.ExcludedProcessNames.Select(x => new XElement("processName", x))),
175+
new XElement("processExclusions", settings.ExcludedProcessItems.Select(x => new XElement("processName",
176+
x.IgnoreHook ? new XAttribute("ignoreHook", x.IgnoreHook.ToString().ToLower()) : null, x.Name))),
172177
new XElement("createMenuOnInitEvent", settings.InitEventProcessNames.Select(x => new XElement("processName", x))),
173178
new XElement("noRestoreMenuOnExit", settings.NoRestoreMenuProcessNames.Select(x => new XElement("processName", x))),
174179
new XElement("menuItems",
175180
new XElement("items", settings.MenuItems.Items.Select(x => new XElement("item",
176181
new XAttribute("type", x.Type.ToString()),
177182
x.Type == MenuItemType.Item || x.Type == MenuItemType.Group ? new XAttribute("name", x.Name) : null,
178183
x.Show == false ? new XAttribute("show", x.Show.ToString().ToLower()) : null,
179-
x.Type == MenuItemType.Item ? new XAttribute("key1", x.Key1 == VirtualKeyModifier.None ? "" : ((int)x.Key1).ToString()) : null,
180-
x.Type == MenuItemType.Item ? new XAttribute("key2", x.Key2 == VirtualKeyModifier.None ? "" : ((int)x.Key2).ToString()) : null,
181-
x.Type == MenuItemType.Item ? new XAttribute("key3", x.Key3 == VirtualKey.None ? "" : ((int)x.Key3).ToString()) : null,
184+
x.Type == MenuItemType.Item ? new XAttribute("key1", x.Key1 == VirtualKeyModifier.None ? string.Empty : ((int)x.Key1).ToString()) : null,
185+
x.Type == MenuItemType.Item ? new XAttribute("key2", x.Key2 == VirtualKeyModifier.None ? string.Empty : ((int)x.Key2).ToString()) : null,
186+
x.Type == MenuItemType.Item ? new XAttribute("key3", x.Key3 == VirtualKey.None ? string.Empty : ((int)x.Key3).ToString()) : null,
182187
x.Items.Any() ?
183188
new XElement("items", x.Items.Select(y => new XElement("item",
184189
new XAttribute("type", y.Type.ToString()),
185190
y.Type == MenuItemType.Item || y.Type == MenuItemType.Group ? new XAttribute("name", y.Name) : null,
186191
y.Show == false ? new XAttribute("show", y.Show.ToString().ToLower()) : null,
187-
y.Type == MenuItemType.Item ? new XAttribute("key1", y.Key1 == VirtualKeyModifier.None ? "" : ((int)y.Key1).ToString()) : null,
188-
y.Type == MenuItemType.Item ? new XAttribute("key2", y.Key2 == VirtualKeyModifier.None ? "" : ((int)y.Key2).ToString()) : null,
189-
y.Type == MenuItemType.Item ? new XAttribute("key3", y.Key3 == VirtualKey.None ? "" : ((int)y.Key3).ToString()) : null))) : null))),
192+
y.Type == MenuItemType.Item ? new XAttribute("key1", y.Key1 == VirtualKeyModifier.None ? string.Empty : ((int)y.Key1).ToString()) : null,
193+
y.Type == MenuItemType.Item ? new XAttribute("key2", y.Key2 == VirtualKeyModifier.None ? string.Empty : ((int)y.Key2).ToString()) : null,
194+
y.Type == MenuItemType.Item ? new XAttribute("key3", y.Key3 == VirtualKey.None ? string.Empty : ((int)y.Key3).ToString()) : null))) : null))),
190195
new XElement("windowSizeItems", settings.MenuItems.WindowSizeItems.Select(x => new XElement("item",
191196
new XAttribute("title", x.Title),
192-
new XAttribute("left", x.Left == null ? "" : x.Left.Value.ToString()),
193-
new XAttribute("top", x.Top == null ? "" : x.Top.Value.ToString()),
194-
new XAttribute("width", x.Width == null ? "" : x.Width.ToString()),
195-
new XAttribute("height", x.Height == null ? "" : x.Height.ToString()),
196-
new XAttribute("key1", x.Key1 == VirtualKeyModifier.None ? "" : ((int)x.Key1).ToString()),
197-
new XAttribute("key2", x.Key2 == VirtualKeyModifier.None ? "" : ((int)x.Key2).ToString()),
198-
new XAttribute("key3", x.Key3 == VirtualKey.None ? "" : ((int)x.Key3).ToString())))),
197+
new XAttribute("left", x.Left == null ? string.Empty : x.Left.Value.ToString()),
198+
new XAttribute("top", x.Top == null ? string.Empty : x.Top.Value.ToString()),
199+
new XAttribute("width", x.Width == null ? string.Empty : x.Width.ToString()),
200+
new XAttribute("height", x.Height == null ? string.Empty : x.Height.ToString()),
201+
new XAttribute("key1", x.Key1 == VirtualKeyModifier.None ? string.Empty : ((int)x.Key1).ToString()),
202+
new XAttribute("key2", x.Key2 == VirtualKeyModifier.None ? string.Empty : ((int)x.Key2).ToString()),
203+
new XAttribute("key3", x.Key3 == VirtualKey.None ? string.Empty : ((int)x.Key3).ToString())))),
199204
new XElement("startProgramItems", settings.MenuItems.StartProgramItems.Select(x => new XElement("item",
200205
new XAttribute("title", x.Title),
201206
new XAttribute("fileName", x.FileName),
@@ -207,9 +212,9 @@ public static void Save(string fileName, ApplicationSettings settings)
207212
new XAttribute("endParameter", x.EndParameter))))),
208213
new XElement("closer",
209214
new XAttribute("type", ((int)settings.Closer.Type).ToString()),
210-
new XAttribute("key1", settings.Closer.Key1 == VirtualKeyModifier.None ? "" : ((int)settings.Closer.Key1).ToString()),
211-
new XAttribute("key2", settings.Closer.Key2 == VirtualKeyModifier.None ? "" : ((int)settings.Closer.Key2).ToString()),
212-
new XAttribute("mouseButton", settings.Closer.MouseButton == MouseButton.None ? "" : ((int)settings.Closer.MouseButton).ToString())
215+
new XAttribute("key1", settings.Closer.Key1 == VirtualKeyModifier.None ? string.Empty : ((int)settings.Closer.Key1).ToString()),
216+
new XAttribute("key2", settings.Closer.Key2 == VirtualKeyModifier.None ? string.Empty : ((int)settings.Closer.Key2).ToString()),
217+
new XAttribute("mouseButton", settings.Closer.MouseButton == MouseButton.None ? string.Empty : ((int)settings.Closer.MouseButton).ToString())
213218
),
214219
new XElement("dimmer",
215220
new XAttribute("color", settings.Dimmer.Color),

0 commit comments

Comments
 (0)