protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); Current.Dispatcher.UnhandledException += App_DispatcherUnhandledException; CommandLineOptions options = Util.CommandLineOptions.Parse(new CommandLineOptions(), e.Args, out int exitCode); // react to options or defaults if (options.Profiles.Any()) { StartupFile = options.Profiles.Last(); } // start up Helios string documentPath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), RunningVersion.IsDevelopmentPrototype ? options.DevDocumentPath : options.DocumentPath); HeliosInit.Initialize(documentPath, "ProfileEditor.log", options.LogLevel); // need to defer exit until after we initialize Helios or our main window will crash if (exitCode < 0) { Current.Shutdown(); return; } // note that we started ConfigManager.LogManager.LogInfo("Starting Editor"); }
protected override void OnStartup(StartupEventArgs e) { NLog.LogManager.Setup().SetupExtensions(s => s.RegisterTarget <StatusViewerLogTarget>("StatusViewer") ); base.OnStartup(e); Current.Dispatcher.UnhandledException += App_DispatcherUnhandledException; CommandLineOptions options = Util.CommonCommandLineOptions.Parse(new CommandLineOptions(), e.Args, out int exitCode); // react to options or defaults if (options.Profiles != null && options.Profiles.Any()) { StartupProfile = options.Profiles.Last(); } // start up Helios string documentPath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), RunningVersion.IsDevelopmentPrototype ? options.DevDocumentPath : options.DocumentPath); HeliosInit.Initialize(documentPath, "ControlCenter.log", options.LogLevel, new HeliosApplication { ShowDesignTimeControls = false, ConnectToServers = true, SettingsAreWritable = false }); // need to defer exit until after we initialize Helios or our main window will crash if (exitCode < 0) { Current.Shutdown(); } }
public static void DisplayUnhandledException(DispatcherUnhandledExceptionEventArgs e) { Logger.Error(e.Exception, $"Unhandled exception occurred. {Assembly.GetExecutingAssembly()?.GetName()?.Name ?? "Application"} will exit."); DisplayException(e.Exception); // prepare for exit or crash HeliosInit.OnShutdown(); }
public MinimalHelios() { HeliosInit.Initialize(FindHeliosDocuments(), "", LogLevel.Error, new HeliosApplication { AllowPlugins = false, ConnectToServers = false, SettingsAreWritable = false, ShowDesignTimeControls = false, AllowLogging = false }); // we are not creating an Application object, so we have to at least static initialize this class // so that pack URIs will work _ = PackUriHelper.UriSchemePack; }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); CommandLineOptions options = new CommandLineOptions(); if (CommandLine.Parser.Default.ParseArguments(e.Args, options)) { if (options.Profiles != null && options.Profiles.Count > 0) { StartupProfile = options.Profiles.Last(); } } string documentPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), options.DocumentPath); HeliosInit.Initialize(documentPath, "ProfileEditor.log", options.LogLevel); ConfigManager.LogManager.LogInfo("Starting Editor"); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); HeliosInit.Initialize("d:\\temp\\SampleProgram", "sample.log", LogLevel.Error); }
/// <summary> /// elevated executable to apply patches /// /// currently only supports DCS locations for output /// does not use CommandLine to avoid running third party code as root when possible /// </summary> /// <param name="args"></param> static void Main(string[] args) { try { if (args.Length < 2) { // tell users to go away and not try to use this executable even though it is in the installation folder throw new Exception("Do not execute this program. It is a system process used by Helios Profile Editor."); } if (args.Length < 7) { throw new Exception( "must have at least the following arguments: -o PIPENAME -h HELIOSDOCUMENTS -d DCSROOT COMMAND"); } if (args[0] != "-o") { throw new Exception( "must have the following arguments: -o PIPENAME -h HELIOSDOCUMENTS -d DCSROOT COMMAND"); } if (args[2] != "-h") { throw new Exception( "must have the following arguments: -o PIPENAME -h HELIOSDOCUMENTS -d DCSROOT COMMAND"); } if (args[4] != "-d") { throw new Exception( "must have the following arguments: -o PIPENAME -h HELIOSDOCUMENTS -d DCSROOT COMMAND"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "HeliosPatching Utility Executable"); return; } // start only enough of Helios to support logging and settings file string documentPath = args[3]; HeliosInit.InitializeLogging(documentPath, LogLevel.Info); ConfigManager.DocumentPath = documentPath; HeliosInit.InitializeSettings(false); string pipeName = args[1]; string dcsRoot = args[5]; string verb = args[6]; try { switch (verb) { case "apply": using (ElevatedProcessResponsePipe response = new ElevatedProcessResponsePipe(pipeName)) { DcsApply(response, dcsRoot, args.Skip(5)); response.WaitToDeliver(); } break; case "revert": using (ElevatedProcessResponsePipe response = new ElevatedProcessResponsePipe(pipeName)) { DcsRevert(response, dcsRoot, args.Skip(5)); response.WaitToDeliver(); } break; default: throw new Exception( "must have arguments matching: -o PIPENAME -h HELIOSDOCUMENTS -d DCSROOT apply|revert PATCHFOLDERS..."); } } catch (Exception ex) { ConfigManager.LogManager.LogError("fatal error while performing patch operations as administrator", ex); #if DEBUG // during debugging, we may be running as a console application, so print to console and wait Console.WriteLine(ex); Console.WriteLine(ex.StackTrace); new ManualResetEvent(false).WaitOne(TimeSpan.FromSeconds(30)); #else _ = ex; #endif throw; } }
public void Dispose() { HeliosInit.OnShutdown(); }
private static void EditInstallation(string dcsRootPath, string jsonDirPath) { if (jsonDirPath == null) { if (!FileSystem.TryFindNearestDirectory("Tools\\ToolsCommon\\Data\\Viewports", out jsonDirPath)) { jsonDirPath = FileSystem.FindNearestDirectory("Data\\Viewports"); } } // open DCS installation location if (!InstallationLocation.TryLoadLocation(dcsRootPath, true, out InstallationLocation dcs)) { throw new Exception($"failed to open DCS installation at {dcsRootPath}"); } // pick JSON file from the given ones based on version number string exactName = $"ViewportTemplates_{PatchVersion.SortableString(dcs.Version)}.json"; string versionedJsonPath = ""; foreach (string candidate in Directory.EnumerateFiles(jsonDirPath, "ViewportTemplates_*.json", SearchOption.AllDirectories)) { string candidateName = Path.GetFileName(candidate); if (string.Compare(candidateName, exactName, StringComparison.InvariantCulture) > 0) { continue; } // applies if (string.Compare(candidateName, versionedJsonPath, StringComparison.InvariantCulture) > 0) { // new best match versionedJsonPath = candidate; } } string json = File.ReadAllText(Path.Combine(jsonDirPath, "ViewportTemplates.json")); List <ViewportTemplate> templates = JsonConvert.DeserializeObject <ViewportTemplate[]>(json).ToList(); if (versionedJsonPath == "") { ConfigManager.LogManager.LogInfo($"no ViewportTemplates_*.json file found that is applicable to selected DCS version {dcs.Version}"); } else { // read version specific changes and replace any entries by ModuleId string changesText = File.ReadAllText(versionedJsonPath); List <ViewportTemplate> changes = JsonConvert.DeserializeObject <ViewportTemplate[]>(changesText).ToList(); templates = templates.GroupJoin(changes, t => t.TemplateName, c => c.TemplateName, (original, applicableChanges) => applicableChanges.FirstOrDefault() ?? original).ToList(); } // get DCS location from the Helios utility that manages DCS install locations (have to use Profile Editor to configure it, either running dev build or start with --documents HeliosDev) string documentPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "HeliosDev"); if (!Directory.Exists(documentPath)) { documentPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Helios"); } HeliosInit.Initialize(documentPath, "EditViewports.log", LogLevel.Debug); ConfigManager.LogManager.LogInfo($"Editing viewport in DCS distribution {dcs.Path} of Version {dcs.Version}"); ConfigManager.LogManager.LogInfo($"Selected ViewportTemplates file {versionedJsonPath}"); PatchDestination destination = new PatchDestination(dcs); EditFilesInDestination(templates, destination); HeliosInit.OnShutdown(); }
protected override void OnExit(ExitEventArgs e) { HeliosInit.OnShutdown(); base.OnExit(e); }