Cleaned & Updated Program.cs
This commit is contained in:
@@ -1,44 +1,66 @@
|
|||||||
|
using System;
|
||||||
using System.Configuration.Install;
|
using System.Configuration.Install;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.ServiceProcess;
|
using System.ServiceProcess;
|
||||||
|
|
||||||
namespace smtpproxy.net;
|
namespace smtpproxy.net
|
||||||
|
|
||||||
internal static class Program
|
|
||||||
{
|
{
|
||||||
private static void Main(string[] args)
|
internal static class Program
|
||||||
{
|
{
|
||||||
SMTPProxy sMTPProxy = new SMTPProxy();
|
private static void Main(string[] args)
|
||||||
ServiceBase[] services = new ServiceBase[1] { sMTPProxy };
|
{
|
||||||
if (args.Length != 0)
|
SMTPProxy smtpProxy = new SMTPProxy();
|
||||||
{
|
|
||||||
switch (args[0])
|
if (args.Length != 0)
|
||||||
{
|
{
|
||||||
case "-install":
|
string command = args[0].ToLowerInvariant();
|
||||||
ManagedInstallerClass.InstallHelper(new string[1] { Assembly.GetExecutingAssembly().Location });
|
|
||||||
break;
|
switch (command)
|
||||||
case "-uninstall":
|
{
|
||||||
ManagedInstallerClass.InstallHelper(new string[2]
|
case "-install":
|
||||||
{
|
Console.WriteLine("Installing SMTPProxy Windows Service...");
|
||||||
"/u",
|
ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
|
||||||
Assembly.GetExecutingAssembly().Location
|
Console.WriteLine("Service installed successfully.");
|
||||||
});
|
break;
|
||||||
break;
|
|
||||||
case "-console":
|
case "-uninstall":
|
||||||
if (args.Length > 1 && args[1] == "-reload")
|
Console.WriteLine("Uninstalling SMTPProxy Windows Service...");
|
||||||
{
|
ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
|
||||||
sMTPProxy.Reload(args[2]);
|
Console.WriteLine("Service uninstalled successfully.");
|
||||||
}
|
break;
|
||||||
else
|
|
||||||
{
|
case "-console":
|
||||||
sMTPProxy.Start();
|
if (args.Length > 1 && args[1].Equals("-reload", StringComparison.OrdinalIgnoreCase))
|
||||||
}
|
{
|
||||||
break;
|
if (args.Length > 2)
|
||||||
}
|
{
|
||||||
}
|
Console.WriteLine(string.Format("Reloading queued emails from: {0}", args[2]));
|
||||||
else
|
smtpProxy.Reload(args[2]);
|
||||||
{
|
}
|
||||||
ServiceBase.Run(services);
|
else
|
||||||
}
|
{
|
||||||
}
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user