Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
 public void Dispose()
 {
     HeliosInit.OnShutdown();
 }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
 protected override void OnExit(ExitEventArgs e)
 {
     HeliosInit.OnShutdown();
     base.OnExit(e);
 }