Aggiunta cleanup registro vecchie icone

This commit is contained in:
Samuele Locatelli
2024-09-26 10:58:28 +02:00
parent 8a97bfe6bf
commit 6af8564ef3
2 changed files with 47 additions and 4 deletions
+2 -2
View File
@@ -50,7 +50,7 @@
//
notifyIcon1.ContextMenuStrip = trayMenu;
notifyIcon1.Icon = (Icon)resources.GetObject("notifyIcon1.Icon");
notifyIcon1.Text = "notifyIcon1";
notifyIcon1.Text = "EgwControlCenter.App";
notifyIcon1.Visible = true;
notifyIcon1.BalloonTipClicked += NotifyIcon1_BalloonTipClicked;
notifyIcon1.DoubleClick += notifyIcon1_DoubleClick;
@@ -77,7 +77,7 @@
MaximizeBox = false;
Name = "BlazorForm";
ShowInTaskbar = false;
Text = "EgalWare's AppControlCenter";
Text = "EgalWare AppControlCenter";
FormClosing += BlazorForm_FormClosing;
Load += BlazorForm_Load;
Resize += BlazorForm_Resize;
+45 -2
View File
@@ -3,6 +3,7 @@ using EgwControlCenter.Core;
using Microsoft.AspNetCore.Components.WebView.WindowsForms;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualBasic.Logging;
using Microsoft.Win32;
using NLog;
using System.Data;
using System.Reflection;
@@ -17,11 +18,50 @@ namespace EgwControlCenter.App
public BlazorForm()
{
InitializeComponent();
FormInit();
ServiceInit();
CleanOldTrayIcons();
InitBlazorView();
StartTimer();
ForceReload();
}
private void CleanOldTrayIcons()
{
string registryPath = @"HKEY_CURRENT_USER\Control Panel\NotifyIconSettings";
Assembly assembly = Assembly.GetExecutingAssembly();
string startDir = Path.GetDirectoryName(assembly.Location)!;
string appPath = assembly.ManifestModule.FullyQualifiedName.Replace("dll", "exe");
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\NotifyIconSettings", true);
if (key != null)
{
foreach (string subKeyName in key.GetSubKeyNames())
{
RegistryKey subKey = key.OpenSubKey(subKeyName);
if (subKey != null)
{
string executablePath = subKey.GetValue("ExecutablePath") as string;
// cerco solo le chaivi di EgwControlCenter.App.exe
if (!string.IsNullOrEmpty(executablePath))
{
if (executablePath.EndsWith("EgwControlCenter.App.exe") || executablePath.Contains("EgwControlCenter"))
{
// se il path NON E' quello da cui sta girando il software --> elimino chiave registro...
if (!executablePath.Equals(appPath))
{
key.DeleteSubKey(subKeyName);
}
}
}
}
}
}
else
{
Console.WriteLine("NotifyIconSettings key not found.");
}
}
#endregion Public Constructors
#region Private Fields
@@ -130,10 +170,13 @@ namespace EgwControlCenter.App
MainAppControlService.DoFullCheck(true);
}
private void FormInit()
private void ServiceInit()
{
//init preliminare servizio controllo
MainAppControlService = new AppControlService();
}
private void StartTimer()
{
timerCheck.Interval = (MainAppControlService.RefreshPeriod * 1000);
MainAppControlService.EA_StatusUpdated += MainAppControlService_EA_StatusUpdated;
// sistemo timer