static void Main(string[] args) { var cmd = new CommandlineArguments(args); var aif = AddinInstallerFile.Build(File.ReadAllText(cmd["l"]), null, cmd["a"], null); AddinInstallerFile.Save(aif, new FileStream(cmd["out"], FileMode.OpenOrCreate)); }
void Init() { if (Platform.IsMicrosoft) { HasAdminRights = new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator); } IsWindowsService = Platform.IsMicrosoft && !Environment.UserInteractive; if (IsWindowsService) { // no log console + service run if (!HasAdminRights) { throw new NotSupportedException("Service requires administration rights!"); } LogSystem = new LogEventLog(EventLog, ServiceName); } else { CommandlineArguments = Arguments.FromEnvironment(); // commandline run or linux daemon ? if (!CommandlineArguments.IsOptionPresent("daemon")) { // no daemon -> log console LogConsole = LogConsole.Create(); LogConsole.Title = ServiceName + " v" + VersionInfo.InformalVersion; if (CommandlineArguments.IsOptionPresent("debug")) { LogConsole.Level = LogLevel.Debug; } if (CommandlineArguments.IsOptionPresent("verbose")) { LogConsole.Level = LogLevel.Verbose; } if (LogConsole.Level < LogLevel.Information) { LogConsole.ExceptionMode = LogExceptionMode.Full; } } // on unix do syslog LogSystem = LogConsole; if (Platform.Type == PlatformType.Linux) { LogSystem = LogSyslog.Create(); } } if (LogSystem != null) { LogSystem.ExceptionMode = LogExceptionMode.Full; } log.LogInfo("Service <cyan>{0}<default> initialized!", ServiceName); }
void ParseArguments() { string[] arguments = System.Environment.GetCommandLineArgs(); #if UNITY_EDITOR arguments = editorArgs.Split(' '); #endif args = new CommandlineArguments(); for (int i = 0; i < arguments.Length; i++) { if (arguments[i] == "-iwad") { args.iwad = arguments[i + 1]; } if (arguments[i] == "-file" || (i == 0 && arguments[0] != "" && arguments[0][0] != '-')) { int j = i + 1; while (j < arguments.Length && arguments[j][0] != '-') { args.pwads.Add(arguments[j]); j++; } } if (arguments[i] == "-warp") { args.warp = arguments[i + 1]; } if (arguments[i] == "-soundfont") { args.soundfont = arguments[i + 1]; } if (arguments[i] == "-test") { args.runTests = true; } if (arguments[i] == "-midi") { args.midi = true; } if (arguments[i] == "-nomonsters") { args.nomonsters = true; } } }
public static void Run(string[] args) { var cli = new CommandlineArguments(args); InstallMode mode = InstallMode.Install; var runtimeInfo = Platform.New <IRuntimeInfo>(); if (cli.GetValue <string>("mode") != null) { mode = (InstallMode)Enum.Parse(typeof(InstallMode), cli.GetValue <string>("mode"), true); } else { mode = runtimeInfo.IsApplicationInstalled(Context) ? InstallMode.Uninstall : InstallMode.Install; } Context.Properties.SetProperty("mode", mode); Context.Properties.SetProperty(NamingConstants.Silent, cli.HasOption(NamingConstants.Silent)); if (!cli.HasOption(NamingConstants.Silent)) { //run ui mode AppBuilder.Configure <App>() .UsePlatformDetect() .LogToTrace() .StartWithClassicDesktopLifetime(args); } else { // run cmd mode if (mode == InstallMode.Install) { Context.Pipeline.Install(Context); } else if (mode == InstallMode.Uninstall) { Context.Pipeline.Uninstall(Context); } else if (mode == InstallMode.Upgrade) { Context.Pipeline.Upgrade(Context); } } }
/// <summary>Does a commandline run.</summary> void CommandLineRun() { log.LogInfo("Initializing service <cyan>{0}<default> commandline instance...\nRelease: <magenta>{1}<default>, FileVersion: <magenta>{2}<default>", ServiceName, VersionInfo.AssemblyVersion, VersionInfo.FileVersion); var needAdminRights = false; if (Platform.IsMicrosoft) { foreach (var option in CommandlineArguments.Options) { switch (option.Name) { case "start": case "stop": case "install": case "uninstall": needAdminRights = true; break; } } if (needAdminRights && !HasAdminRights) { if (Debugger.IsAttached) { throw new InvalidOperationException("Please debug this program in administration mode!"); } log.LogNotice("Restarting service with administration rights!"); Logger.Close(); var processStartInfo = new ProcessStartInfo(CommandlineArguments.Command, CommandlineArguments.ToString(false) + " --wait") { UseShellExecute = true, Verb = "runas", }; Process.Start(processStartInfo); return; } if (HasAdminRights) { log.LogInfo("Current user has <green>admin<default> rights."); } else { log.LogInfo("Running in <red>debug<default> mode <red>without admin<default> rights."); } } bool runCommandLine; var wait = CommandlineArguments.IsOptionPresent("wait"); if (Debugger.IsAttached) { runCommandLine = true; log.LogInfo("<red>Debugger<default> attached."); } else { if (CommandlineArguments.Options.Count == 0) { Help(); return; } runCommandLine = CommandlineArguments.IsOptionPresent("run"); } bool isInteractive; if (Platform.IsMicrosoft) { ServiceHelper.ServiceName = ServiceName; isInteractive = Environment.UserInteractive; if (CommandlineArguments.IsHelpOptionFound()) { Help(); return; } foreach (var option in CommandlineArguments.Options) { switch (option.Name) { case "start": if (Debugger.IsAttached || !runCommandLine) { ServiceHelper.StartService(); } else { log.LogError("Ignore <red>start<default> service command, doing commandline run!"); } break; case "stop": if (Debugger.IsAttached || !runCommandLine) { ServiceHelper.StopService(); } else { log.LogError("Ignore <red>stop<default> service command, doing commandline run!"); } break; case "install": if (Debugger.IsAttached || !runCommandLine) { ServiceHelper.InstallService(); } else { log.LogError("Ignore <red>install<default> service command, doing commandline run!"); } break; case "uninstall": if (Debugger.IsAttached || !runCommandLine) { ServiceHelper.UnInstallService(); } else { log.LogError("Ignore <red>uninstall<default> service command, doing commandline run!"); } break; } } } else { isInteractive = !CommandlineArguments.IsOptionPresent("daemon"); runCommandLine = true; } if (runCommandLine) { // --- start service as program ServiceParameters = new ServiceParameters(HasAdminRights, true, isInteractive); try { RunWorker(); } catch (Exception ex) { log.LogError("Error while running service executable in commandline mode.\n" + ex.ToXT()); } // --- exit } Logger.Flush(); if (isInteractive && wait) { SystemConsole.RemoveKeyPressedEvent(); while (SystemConsole.KeyAvailable) { SystemConsole.ReadKey(); } SystemConsole.WriteLine("--- Press <yellow>enter<default> to exit... ---"); while (SystemConsole.ReadKey().Key != ConsoleKey.Enter) { } } }