コード例 #1
0
 public InstallationDomain ToDomain()
 => new InstallationDomain(Id,
                           ExternalId,
                           IsAirly,
                           InstallationLocation.Create(Latitude, Longitude, Elevation),
                           Address.ToDomain(),
                           Sponsor.ToDomain());
コード例 #2
0
 /// <summary>
 /// set up the application of patches to a specific location in DCS-specific way
 /// </summary>
 /// <param name="location"></param>
 /// <returns></returns>
 internal PatchApplication CreatePatchDestination(InstallationLocation location) =>
 new PatchApplication(
     new PatchDestination(location),
     location.IsEnabled,
     !location.Writable,
     PatchSet,
     // load user-provided patches from documents folder
     System.IO.Path.Combine(ConfigManager.DocumentPath, "Patches", "DCS"),
     // then load pre-installed patches from Helios installation folder
     System.IO.Path.Combine(ConfigManager.ApplicationPath, "Plugins", "Patches", "DCS"));
コード例 #3
0
 public async static Task DeleteInstallationLocation(InstallationLocation itemPara)
 {
     using (var db = new SalesContext())
     {
         db.Entry(itemPara).State = EntityState.Unchanged;   //NOT DELETE - IMPORTANT
         InstallationLocations.Remove(itemPara);
         db.Entry(itemPara).State = EntityState.Deleted;     // must be executed after deleted it in InstallationLocations
         await UpdateDatabase(db);
     }
 }
コード例 #4
0
        public async static Task AddInstallationLocation(InstallationLocation itemPara)
        {
            using (var db = new SalesContext())
            {
                db.InstallationLocations.Add(itemPara);
                await UpdateDatabase(db);

                InstallationLocations.Add(itemPara);
            }
        }
コード例 #5
0
 public StatusReportItem InstallFile(InstallationLocation location, string name, string directoryPath,
                                     string filePath, string correctContents)
 {
     Directory.CreateDirectory(directoryPath);
     File.WriteAllText(filePath, correctContents);
     return(new StatusReportItem
     {
         Status = $"generated monitor setup file '{name}' in {location.DescribeMonitorSetupPath}",
         Flags = StatusReportItem.StatusFlags.ConfigurationUpToDate
     });
 }
コード例 #6
0
 public async static Task SaveInstallationLocation(InstallationLocation itemPara, InstallationLocation oldItem)
 {
     using (var db = new SalesContext())
     {
         db.Entry(oldItem).State = EntityState.Unchanged;
         var query = db.InstallationLocations.Find(itemPara.Id);
         CopyProperties(typeof(InstallationLocation), query, itemPara);
         db.Entry(query).State = EntityState.Modified;
         await UpdateDatabase(db);
     }
 }
コード例 #7
0
        private StatusReportItem ReportResolutionSelected(InstallationLocation location, DCSOptions options)
        {
            string status = $"{location.DescribeOptionsPath} has 'Resolution' set to {options.Graphics.Width}x{options.Graphics.Height}";

            if ((long)Math.Round(_parent.Rendered.Width) == options.Graphics.Width &&
                (long)Math.Round(_parent.Rendered.Height) == options.Graphics.Height)
            {
                // exact match
                return(new StatusReportItem
                {
                    Status = status,
                    Flags = StatusReportItem.StatusFlags.ConfigurationUpToDate
                });
            }

            if (_parent.MonitorLayoutMode != MonitorLayoutMode.FromTopLeftCorner)
            {
                // inexact match is not permitted in any of these modes
                return(new StatusReportItem
                {
                    Status = status,
                    Recommendation =
                        $"Using DCS, please make sure the 'Resolution' in the 'System' options is set to {_parent.Rendered.Width}x{_parent.Rendered.Height}",
                    // not a warning, because the user may simply not have configured DCS yet.  once we do that automatically,
                    // this can be an out of date warning
                    Flags = StatusReportItem.StatusFlags.ConfigurationUpToDate
                });
            }

            if (_parent.Rendered.Width > options.Graphics.Width ||
                _parent.Rendered.Height > options.Graphics.Height)
            {
                return(new StatusReportItem
                {
                    Status = status,
                    Recommendation =
                        $"Using DCS, choose a 'Resolution' in the 'System' options that is at least {_parent.Rendered.Width} pixels wide and at least {_parent.Rendered.Height} pixels high",
                    // not a warning, because the user may simply not have configured DCS yet.  once we do that automatically,
                    // this can be an out of date warning
                    Flags = StatusReportItem.StatusFlags.ConfigurationUpToDate
                });
            }

            return(new StatusReportItem
            {
                Status = status,
                Flags = StatusReportItem.StatusFlags.ConfigurationUpToDate
            });
        }
コード例 #8
0
        private static void DcsRevert(ElevatedProcessResponsePipe response, string outputRoot, IEnumerable <string> patchFolders)
        {
            PatchList patches = LoadPatches(patchFolders);

            if (!InstallationLocation.TryLoadLocation(outputRoot, true, out InstallationLocation location))
            {
                ReportBadLocation(response, outputRoot);
                return;
            }
            PatchDestination         dcs             = new PatchDestination(location);
            HashSet <string>         patchExclusions = PatchInstallation.LoadPatchExclusions();
            IList <StatusReportItem> results         = patches.Revert(dcs, patchExclusions).ToList();

            response.SendReport(results);
        }
コード例 #9
0
        private static void Add_Executed(object target, ExecutedRoutedEventArgs e)
        {
            List <string> guesses = InstallationLocations.GenerateDcsRootDirectoryGuesses();

            string guessName = InstallationLocation.AUTO_UPDATE_CONFIG;

            Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog
            {
                Title            = $"Navigate to DCS Installation and select {InstallationLocation.AUTO_UPDATE_CONFIG} or {InstallationLocation.DCS_EXE} file",
                InitialDirectory = "",
                FileName         = guessName,
                DefaultExt       = ".cfg",
                CheckPathExists  = true,
                DereferenceLinks = true,
                Multiselect      = false,
                ValidateNames    = true,
                Filter           = $"DCS|{InstallationLocation.AUTO_UPDATE_CONFIG};{InstallationLocation.DCS_EXE}",
                CheckFileExists  = true
            };

            foreach (string guess in guesses)
            {
                if (openFileDialog.InitialDirectory == "")
                {
                    openFileDialog.InitialDirectory = guesses[0];
                }
                else
                {
                    openFileDialog.CustomPlaces.Add(new Microsoft.Win32.FileDialogCustomPlace(guess));
                }
            }

            if (openFileDialog.ShowDialog() == true)
            {
                if (InstallationLocation.TryBrowseLocation(openFileDialog.FileName, out InstallationLocation location))
                {
                    // silently ignore duplicates
                    _ = InstallationLocations.Singleton.TryAdd(location);
                }
            }
            ((InstallationLocationsControl)target).UpdateStatus();
        }
コード例 #10
0
        private StatusReportItem ReportMonitorSetupSelected(InstallationLocation location, DCSOptions options, string monitorSetupName)
        {
            string status = $"{location.DescribeOptionsPath} has 'Monitors' set to '{options.Graphics.MultiMonitorSetup}'";

            if (options.Graphics.MultiMonitorSetup.Equals(monitorSetupName, StringComparison.InvariantCultureIgnoreCase))
            {
                // selection is correct for current profile
                return(new StatusReportItem
                {
                    Status = status,
                    Flags = StatusReportItem.StatusFlags.ConfigurationUpToDate
                });
            }

            return(new StatusReportItem
            {
                Status = status,
                Recommendation =
                    $"Using DCS, please make sure 'Monitors' in the 'System' options is set to '{monitorSetupName}'",
                // not a warning, because the user may simply not have configured DCS yet.  once we do that automatically,
                // this can be an out of date warning
                Flags = StatusReportItem.StatusFlags.ConfigurationUpToDate
            });
        }
コード例 #11
0
        public StatusReportItem CheckSetupFile(InstallationLocation location, string name,
                                               string _, string filePath, string correctContents)
        {
            if (!File.Exists(filePath))
            {
                return(new StatusReportItem
                {
                    Status =
                        $"{location.DescribeMonitorSetupPath} does not contain the monitor setup file '{name}'",
                    Recommendation = $"Configure {_parent.Name}",
                    Link = StatusReportItem.ProfileEditor,
                    Severity = StatusReportItem.SeverityCode.Warning
                });
            }

            string contents = File.ReadAllText(filePath);

            if (contents != correctContents)
            {
                return(new StatusReportItem
                {
                    Status =
                        $"monitor setup file '{name}' in {location.DescribeMonitorSetupPath} does not match configuration",
                    Recommendation = $"Configure {_parent.Name}",
                    Link = StatusReportItem.ProfileEditor,
                    Severity = StatusReportItem.SeverityCode.Warning
                });
            }

            return(new StatusReportItem
            {
                Status =
                    $"monitor setup file '{name}' in {location.DescribeMonitorSetupPath} is up to date",
                Flags = StatusReportItem.StatusFlags.ConfigurationUpToDate
            });
        }
コード例 #12
0
 public InstallationLocation ToDomain()
 => InstallationLocation.Create(_latitude, _longitude, _elevation);
コード例 #13
0
ファイル: PatchDestination.cs プロジェクト: appsou/Helios
 public PatchDestination(InstallationLocation location)
 {
     _dcsRoot       = location.Path;
     Version        = PatchVersion.SortableString(location.Version);
     DisplayVersion = location.Version;
 }
コード例 #14
0
ファイル: EditViewports.cs プロジェクト: appsou/Helios
        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();
        }
コード例 #15
0
 public static InstallationLocationDto FromDomain(InstallationLocation domain)
 => new InstallationLocationDto(domain.Latitude, domain.Longitude, domain.Elevation);