Skip to content

Commit

Permalink
Divided Window.xml file into Window.xml and Window64.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderPro committed Apr 15, 2022
1 parent b2750e4 commit 8fd9b72
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 32 deletions.
8 changes: 0 additions & 8 deletions Build/Build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
<SmartSystemMenuConfigurationDestFile Include="$(ApplicationPath)\SmartSystemMenu.xml" />
<SmartSystemMenuLanguageSourceFile Include="$(SmartSystemMenuProjectPath)\Language.xml" />
<SmartSystemMenuLanguageDestFile Include="$(ApplicationPath)\Language.xml" />
<SmartSystemMenuWindowSourceFile Include="$(SmartSystemMenuProjectPath)\Window.xml" />
<SmartSystemMenuWindowDestFile Include="$(ApplicationPath)\Window.xml" />
<EmptyTextForFile Include="Empty File" />
</ItemGroup>

Expand All @@ -40,7 +38,6 @@
<CallTarget Targets="Copy_Release_x32_SmartSystemMenu" />
<CallTarget Targets="CopySmartSystemMenuConfigurationFile" />
<CallTarget Targets="CopySmartSystemMenuLanguageFile" />
<CallTarget Targets="CopySmartSystemMenuWindowFile" />
</Target>

<Target Name="Build_Release_x32_SmartSystemMenuHook">
Expand Down Expand Up @@ -110,9 +107,4 @@
<Message Text="Copy $(SmartSystemMenuLanguageSourceFile) to $(SmartSystemMenuProjectName)" />
<Copy SourceFiles="@(SmartSystemMenuLanguageSourceFile)" DestinationFiles="@(SmartSystemMenuLanguageDestFile)" />
</Target>

<Target Name="CopySmartSystemMenuWindowFile">
<Message Text="Copy $(SmartSystemMenuWindowSourceFile) to $(SmartSystemMenuProjectName)" />
<Copy SourceFiles="@(SmartSystemMenuWindowSourceFile)" DestinationFiles="@(SmartSystemMenuWindowDestFile)" />
</Target>
</Project>
18 changes: 13 additions & 5 deletions SmartSystemMenu/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ protected override void OnLoad(EventArgs e)
foreach (var window in _windows)
{
var processPath = window.Process?.GetMainModuleFileName() ?? string.Empty;
var fileName = Path.GetFileName(processPath).ToLower();
if (!string.IsNullOrEmpty(fileName) && _settings.ProcessExclusions.Contains(fileName))
var fileName = Path.GetFileName(processPath);
if (!string.IsNullOrEmpty(fileName) && _settings.ProcessExclusions.Contains(fileName.ToLower()))
{
return;
continue;
}

var isAdded = window.Menu.Create();
Expand Down Expand Up @@ -319,8 +319,8 @@ private void WindowCreated(object sender, WindowEventArgs e)
if (isWriteProcess && !filterTitles.Any(s => window.GetWindowText() == s))
{
var processPath = window.Process?.GetMainModuleFileName() ?? string.Empty;
var fileName = Path.GetFileName(processPath).ToLower();
if (!string.IsNullOrEmpty(fileName) && _settings.ProcessExclusions.Contains(fileName))
var fileName = Path.GetFileName(processPath);
if (!string.IsNullOrEmpty(fileName) && _settings.ProcessExclusions.Contains(fileName.ToLower()))
{
return;
}
Expand Down Expand Up @@ -807,7 +807,11 @@ private void WindowGetMsg(object sender, WndProcEventArgs e)
_windowSettings.Items.Add((WindowState)window.State.Clone());
}

#if WIN32
var fileName = Path.Combine(AssemblyUtils.AssemblyDirectory, "Window.xml");
#else
var fileName = Path.Combine(AssemblyUtils.AssemblyDirectory, "Window64.xml");
#endif
WindowSettings.Save(fileName, _windowSettings);
}
}
Expand All @@ -831,7 +835,11 @@ private void WindowGetMsg(object sender, WndProcEventArgs e)
}

_windowSettings.Items.Add((WindowState)window.State.Clone());
#if WIN32
var fileName = Path.Combine(AssemblyUtils.AssemblyDirectory, "Window.xml");
#else
var fileName = Path.Combine(AssemblyUtils.AssemblyDirectory, "Window64.xml");
#endif
WindowSettings.Save(fileName, _windowSettings);
}
}
Expand Down
5 changes: 5 additions & 0 deletions SmartSystemMenu/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ static void Main(string[] args)
{
var settingsFileName = Path.Combine(AssemblyUtils.AssemblyDirectory, "SmartSystemMenu.xml");
var languageFileName = Path.Combine(AssemblyUtils.AssemblyDirectory, "Language.xml");
#if WIN32
var windowFileName = Path.Combine(AssemblyUtils.AssemblyDirectory, "Window.xml");
#else
var windowFileName = Path.Combine(AssemblyUtils.AssemblyDirectory, "Window64.xml");
#endif

var settings = File.Exists(settingsFileName) && File.Exists(languageFileName) ? SmartSystemMenuSettings.Read(settingsFileName, languageFileName) : new SmartSystemMenuSettings();
var windowSettings = File.Exists(windowFileName) ? WindowSettings.Read(windowFileName) : new WindowSettings();

Expand Down
3 changes: 0 additions & 3 deletions SmartSystemMenu/SmartSystemMenu.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,6 @@
</Compile>
</ItemGroup>
<ItemGroup>
<Content Include="Window.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<EmbeddedResource Include="SmartSystemMenu64.exe" />
<Content Include="ArrowDown.png" />
<Content Include="ArrowUp.png" />
Expand Down
Binary file modified SmartSystemMenu/SmartSystemMenu64.exe
Binary file not shown.
38 changes: 24 additions & 14 deletions SmartSystemMenu/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,6 @@ public Window(IntPtr windowHandle, MenuItems menuItems, LanguageSettings languag
_menuItemClose.Name = $"miClose_{Handle}";
_menuItemClose.Text = languageSettings.GetValue("mi_close");
_menuItemClose.Click += _menuItemClose_Click;
var components = new Container();
_systemTrayMenu = new ContextMenuStrip(components);
_systemTrayMenu.Items.AddRange(new ToolStripItem[] { _menuItemRestore, _menuItemClose });
_systemTrayMenu.Name = $"systemTrayMenu_{Handle}";
_systemTrayMenu.Size = new Size(176, 80);
Menu = new SystemMenu(windowHandle, menuItems, languageSettings);

//Menu.Create();
Expand Down Expand Up @@ -875,8 +870,10 @@ private void RestoreFromSystemTray()
}

_systemTrayIcon.Visible = false;
_systemTrayIcon.Dispose();
_systemTrayIcon = null;
/*_systemTrayMenu?.Dispose();
_systemTrayIcon?.Dispose();
_systemTrayMenu = null;
_systemTrayIcon = null;*/

NativeMethods.ShowWindowAsync(Handle, (int)WindowShowStyle.Show);
NativeMethods.ShowWindowAsync(Handle, (int)WindowShowStyle.Restore);
Expand Down Expand Up @@ -929,13 +926,8 @@ private Icon GetWindowIcon()

private void CreateIconInSystemTray()
{
if (_systemTrayIcon == null)
{
_systemTrayIcon = new NotifyIcon();
_systemTrayIcon.ContextMenuStrip = _systemTrayMenu;
_systemTrayIcon.MouseClick += SystemTrayIconClick;
}

_systemTrayMenu = _systemTrayMenu ?? CreateSystemTrayMenu();
_systemTrayIcon = _systemTrayIcon ?? CreateNotifyIcon(_systemTrayMenu);
_systemTrayIcon.Icon = GetWindowIcon();
var windowText = GetWindowText();
_systemTrayIcon.Text = windowText.Length > 63 ? windowText.Substring(0, 60).PadRight(63, '.') : windowText;
Expand Down Expand Up @@ -1013,5 +1005,23 @@ public Rect GetSystemMargins()
Bottom = Size.Bottom - withMargin.Bottom
};
}

private ContextMenuStrip CreateSystemTrayMenu()
{
var components = new Container();
var menu = new ContextMenuStrip(components);
menu.Items.AddRange(new ToolStripItem[] { _menuItemRestore, _menuItemClose });
menu.Name = $"systemTrayMenu_{Handle}";
menu.Size = new Size(176, 80);
return menu;
}

private NotifyIcon CreateNotifyIcon(ContextMenuStrip contextMenuStrip)
{
var icon = new NotifyIcon();
icon.ContextMenuStrip = contextMenuStrip;
icon.MouseClick += SystemTrayIconClick;
return icon;
}
}
}
2 changes: 0 additions & 2 deletions SmartSystemMenu/Window.xml

This file was deleted.

0 comments on commit 8fd9b72

Please sign in to comment.