Using new configuration system.
parent
05b6cea2e2
commit
603fece45e
|
@ -72,63 +72,57 @@ USAGE
|
|||
{
|
||||
Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
||||
|
||||
if (args.Length == 0 && Debugger.IsAttached)
|
||||
if (!Configuration.OptionsSet && Debugger.IsAttached)
|
||||
{
|
||||
args = new[] { "/console" };
|
||||
Configuration.SetOptions( new[] { "--console" } );
|
||||
}
|
||||
|
||||
if (args.Length == 0)
|
||||
{
|
||||
Console.WriteLine(HelpTextPattern, Path.GetFileName(GetType().Assembly.CodeBase));
|
||||
else if (!Configuration.OptionsSet) {
|
||||
Configuration.SetOptions(new[] { "-h" });
|
||||
}
|
||||
else
|
||||
|
||||
|
||||
switch ((string)Configuration.GetOption("operating_mode"))
|
||||
{
|
||||
switch (args[0].ToLower())
|
||||
{
|
||||
case "/service":
|
||||
ServiceExecutionMode = ServiceExecutionMode.Service;
|
||||
Run(new[] { this });
|
||||
break;
|
||||
case "service":
|
||||
ServiceExecutionMode = ServiceExecutionMode.Service;
|
||||
Run(new[] { this });
|
||||
break;
|
||||
|
||||
case "/setupservice":
|
||||
ServiceExecutionMode = ServiceExecutionMode.Install;
|
||||
SetupService();
|
||||
break;
|
||||
case "setupservice":
|
||||
ServiceExecutionMode = ServiceExecutionMode.Install;
|
||||
SetupService();
|
||||
break;
|
||||
|
||||
case "/console":
|
||||
ServiceExecutionMode = ServiceExecutionMode.Console;
|
||||
Console.WriteLine("Starting Service...");
|
||||
OnStart(args);
|
||||
OnStartCommandLine();
|
||||
OnStop();
|
||||
break;
|
||||
case "console":
|
||||
ServiceExecutionMode = ServiceExecutionMode.Console;
|
||||
Console.WriteLine("Starting Service...");
|
||||
OnStart(args);
|
||||
OnStartCommandLine();
|
||||
OnStop();
|
||||
break;
|
||||
|
||||
case "/install":
|
||||
ServiceExecutionMode = ServiceExecutionMode.Install;
|
||||
InstallService();
|
||||
break;
|
||||
case "install":
|
||||
ServiceExecutionMode = ServiceExecutionMode.Install;
|
||||
InstallService();
|
||||
break;
|
||||
|
||||
case "/uninstall":
|
||||
ServiceExecutionMode = ServiceExecutionMode.Uninstall;
|
||||
case "uninstall":
|
||||
ServiceExecutionMode = ServiceExecutionMode.Uninstall;
|
||||
UninstallService();
|
||||
break;
|
||||
|
||||
case "uninstallprompt":
|
||||
ServiceExecutionMode = ServiceExecutionMode.Uninstall;
|
||||
if (ConfirmUninstall())
|
||||
{
|
||||
UninstallService();
|
||||
break;
|
||||
InformUninstalled();
|
||||
}
|
||||
break;
|
||||
|
||||
case "/uninstallprompt":
|
||||
ServiceExecutionMode = ServiceExecutionMode.Uninstall;
|
||||
if (ConfirmUninstall())
|
||||
{
|
||||
UninstallService();
|
||||
InformUninstalled();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (!OnCustomCommandLine(args))
|
||||
{
|
||||
Console.WriteLine(HelpTextPattern, Path.GetFileName(GetType().Assembly.CodeBase));
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
Configuration.SetOptions(new[] { "-h" });
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
using System.Linq;
|
||||
using System;
|
||||
|
||||
using WifiSitter;
|
||||
|
||||
namespace WifiSitter
|
||||
{
|
||||
class Program
|
||||
|
@ -14,6 +16,7 @@ namespace WifiSitter
|
|||
Environment.Exit(7);
|
||||
}
|
||||
else {
|
||||
Configuration.SetOptions(args);
|
||||
(new WifiSitter()).Run(args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -207,6 +207,26 @@ namespace WifiSitter
|
|||
LogLine(ConsoleColor.White, msg);
|
||||
}
|
||||
|
||||
public static void LogLine(LogType type, params string[] msg) {
|
||||
ConsoleColor color = Console.ForegroundColor;
|
||||
switch (type) {
|
||||
case LogType.error:
|
||||
color = ConsoleColor.Red;
|
||||
break;
|
||||
case LogType.warn:
|
||||
color = ConsoleColor.Yellow;
|
||||
break;
|
||||
case LogType.success:
|
||||
color = ConsoleColor.Green;
|
||||
break;
|
||||
default:
|
||||
// Do nothing
|
||||
break;
|
||||
}
|
||||
|
||||
LogLine(color, msg);
|
||||
}
|
||||
|
||||
public static void LogLine(ConsoleColor color, params string[] msg) {
|
||||
if (msg.Length == 0) return;
|
||||
string log = msg.Length > 0 ? String.Format(msg[0], msg.Skip(1).ToArray()) : msg[0];
|
||||
|
@ -523,16 +543,16 @@ namespace WifiSitter
|
|||
_mainLoopThread.IsBackground = true;
|
||||
_mainLoopThread.Start();
|
||||
|
||||
|
||||
|
||||
// Setup IPC, 0mq messaging thread
|
||||
// TODO make this tunable, cmd argument?
|
||||
LogLine("Initializing IPC...");
|
||||
|
||||
_mqServerThread = new Thread(ZeroMQRouterRun);
|
||||
_mqServerThread.Name = "0MQ Server Thread";
|
||||
_mqServerThread.IsBackground = true;
|
||||
_mqServerThread.Start();
|
||||
if ((bool)Configuration.GetOption("enable_ipc")) {
|
||||
LogLine(LogType.warn, "Initializing IPC...");
|
||||
|
||||
_mqServerThread = new Thread(ZeroMQRouterRun);
|
||||
_mqServerThread.Name = "0MQ Server Thread";
|
||||
_mqServerThread.IsBackground = true;
|
||||
_mqServerThread.Start();
|
||||
}
|
||||
else { WriteLog(LogType.warn, "IPC not initialized. May not communicate with GUI agent."); }
|
||||
}
|
||||
catch (Exception e) {
|
||||
WriteLog(LogType.error, e.Source + " {0}", e.Message);
|
||||
|
|
|
@ -114,6 +114,7 @@
|
|||
<Compile Include="Helpers\NativeWifi.cs" />
|
||||
<Compile Include="Helpers\NetshHelper.cs" />
|
||||
<Compile Include="Helpers\Options.cs" />
|
||||
<Compile Include="Configuration.cs" />
|
||||
<Compile Include="Model\NetworkState.cs" />
|
||||
<Compile Include="Model\SimpleNetworkState.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
|
@ -164,7 +165,7 @@
|
|||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_BuildVersioningStyle="None.None.None.Increment" BuildVersion_UpdateFileVersion="False" />
|
||||
<UserProperties BuildVersion_UpdateFileVersion="False" BuildVersion_BuildVersioningStyle="None.None.None.Increment" BuildVersion_StartDate="2000/1/1" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
<Import Project="..\packages\Fody.1.29.4\build\dotnet\Fody.targets" Condition="Exists('..\packages\Fody.1.29.4\build\dotnet\Fody.targets')" />
|
||||
|
|
Loading…
Reference in New Issue