Cleaned & Updated Program.cs

This commit is contained in:
2026-08-17 10:29:45 +10:00
parent a8eb857f55
commit 1d6e8e23a8

View File

@@ -1,44 +1,66 @@
using System.Configuration.Install; using System;
using System.Reflection; using System.Configuration.Install;
using System.ServiceProcess; using System.Reflection;
using System.ServiceProcess;
namespace smtpproxy.net;
namespace smtpproxy.net
internal static class Program {
{ internal static class Program
private static void Main(string[] args) {
{ private static void Main(string[] args)
SMTPProxy sMTPProxy = new SMTPProxy(); {
ServiceBase[] services = new ServiceBase[1] { sMTPProxy }; SMTPProxy smtpProxy = new SMTPProxy();
if (args.Length != 0)
{ if (args.Length != 0)
switch (args[0]) {
{ string command = args[0].ToLowerInvariant();
case "-install":
ManagedInstallerClass.InstallHelper(new string[1] { Assembly.GetExecutingAssembly().Location }); switch (command)
break; {
case "-uninstall": case "-install":
ManagedInstallerClass.InstallHelper(new string[2] Console.WriteLine("Installing SMTPProxy Windows Service...");
{ ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
"/u", Console.WriteLine("Service installed successfully.");
Assembly.GetExecutingAssembly().Location break;
});
break; case "-uninstall":
case "-console": Console.WriteLine("Uninstalling SMTPProxy Windows Service...");
if (args.Length > 1 && args[1] == "-reload") ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
{ Console.WriteLine("Service uninstalled successfully.");
sMTPProxy.Reload(args[2]); break;
}
else case "-console":
{ if (args.Length > 1 && args[1].Equals("-reload", StringComparison.OrdinalIgnoreCase))
sMTPProxy.Start(); {
} if (args.Length > 2)
break; {
} Console.WriteLine(string.Format("Reloading queued emails from: {0}", args[2]));
} smtpProxy.Reload(args[2]);
else }
{ else
ServiceBase.Run(services); {
} Console.WriteLine("Error: Missing target folder path for -reload. Usage: -console -reload <folder>");
} }
} }
else
{
Console.WriteLine("Starting SMTPProxy in Interactive Console Mode...");
Console.WriteLine("Press [Enter] or [Ctrl+C] to stop the proxy.");
smtpProxy.Start();
Console.ReadLine();
}
break;
default:
Console.WriteLine("Unknown parameter. Valid options: -install, -uninstall, -console, -console -reload <path>");
break;
}
}
else
{
ServiceBase[] servicesToRun = new ServiceBase[] { smtpProxy };
ServiceBase.Run(servicesToRun);
}
}
}
}