diff --git a/Helios/ComponentModel/HeliosInterfaceAttribute.cs b/Helios/ComponentModel/HeliosInterfaceAttribute.cs index 3aa1c2b0c..c3aee553d 100644 --- a/Helios/ComponentModel/HeliosInterfaceAttribute.cs +++ b/Helios/ComponentModel/HeliosInterfaceAttribute.cs @@ -30,6 +30,8 @@ public class HeliosInterfaceAttribute : Attribute /// Unique identifier used for persistance. /// Recommended to follow conventions of {module name}.{interface}. Helios.* is reserved for helios's included controls. /// Display name used for this interface in the ui. + /// Instance factory for interface editor dialog. + /// public HeliosInterfaceAttribute(string typeIdentifier, string name, Type interfaceEditor) : this(typeIdentifier, name, interfaceEditor, typeof(HeliosInterfaceFactory)) { } @@ -37,6 +39,7 @@ public HeliosInterfaceAttribute(string typeIdentifier, string name, Type interfa /// Unique identifier used for persistance. /// Recommended to follow conventions of {module name}.{interface}. Helios.* is reserved for helios's included controls. /// Display name used for this interface in the ui. + /// Instance factory for interface editor dialog. /// Instance factory used to populate new interface dialog. /// public HeliosInterfaceAttribute(string typeIdentifier, string name, Type interfaceEditor, Type factory) diff --git a/Helios/Helios.csproj b/Helios/Helios.csproj index 1df838b7e..70ebe059e 100644 --- a/Helios/Helios.csproj +++ b/Helios/Helios.csproj @@ -163,6 +163,9 @@ + + DCSInterfaceEditor.xaml + @@ -620,9 +623,6 @@ F14BInterfaceEditor.xaml - - FA18CInterfaceEditor.xaml - AV8BInterfaceEditor.xaml @@ -3011,11 +3011,10 @@ MSBuild:Compile Designer - - MSBuild:Compile - Designer + + XamlIntelliSenseFileGenerator - + MSBuild:Compile Designer diff --git a/Helios/Interfaces/DCS/Common/DCSInterfaceEditor.xaml b/Helios/Interfaces/DCS/Common/DCSInterfaceEditor.xaml new file mode 100644 index 000000000..ca05518f4 --- /dev/null +++ b/Helios/Interfaces/DCS/Common/DCSInterfaceEditor.xaml @@ -0,0 +1,172 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Cannot find game install. + + + + + Your DCS configuration is up to date. + + + + + + In order for Helios to interface with DCS, an updated Export.lua file must be installed. This will back up an existing Export.lua file and deploy the necessary Helios configuration. + + + + + + + \ No newline at end of file diff --git a/Helios/Interfaces/DCS/Common/DCSInterfaceEditor.xaml.cs b/Helios/Interfaces/DCS/Common/DCSInterfaceEditor.xaml.cs new file mode 100644 index 000000000..707dba106 --- /dev/null +++ b/Helios/Interfaces/DCS/Common/DCSInterfaceEditor.xaml.cs @@ -0,0 +1,233 @@ +// Copyright 2014 Craig Courtney +// +// Helios is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Helios is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +namespace GadrocsWorkshop.Helios.Interfaces.DCS.Common +{ + using GadrocsWorkshop.Helios.UDPInterface; + using GadrocsWorkshop.Helios.Windows.Controls; + using Microsoft.Win32; + using System; + using System.Windows; + using System.Windows.Controls; + using System.Windows.Input; + + /// + /// Interaction logic for DCSInterfaceEditor.xaml + /// + /// This DCS Interface editor can be used by descendants of DCSInterface that do not want to add any specific options. + /// Using this class will avoid duplicating the XAML. + /// + /// TODO: implement a content container into which specific options can be added. + /// + public partial class DCSInterfaceEditor : HeliosInterfaceEditor + { + static DCSInterfaceEditor() + { + Type ownerType = typeof(DCSInterfaceEditor); + + CommandManager.RegisterClassCommandBinding(ownerType, new CommandBinding(DCSConfigurator.AddDoFile, AddDoFile_Executed)); + CommandManager.RegisterClassCommandBinding(ownerType, new CommandBinding(DCSConfigurator.RemoveDoFile, RemoveDoFile_Executed)); + } + + private static void AddDoFile_Executed(object target, ExecutedRoutedEventArgs e) + { + DCSInterfaceEditor editor = target as DCSInterfaceEditor; + string file = e.Parameter as string; + if (editor != null && !string.IsNullOrWhiteSpace(file) && !editor.Configuration.DoFiles.Contains(file)) + { + editor.Configuration.DoFiles.Add((string)e.Parameter); + editor.NewDoFile.Text = ""; + } + } + + private static void RemoveDoFile_Executed(object target, ExecutedRoutedEventArgs e) + { + DCSInterfaceEditor editor = target as DCSInterfaceEditor; + string file = e.Parameter as string; + if (editor != null && !string.IsNullOrWhiteSpace(file) && editor.Configuration.DoFiles.Contains(file)) + { + editor.Configuration.DoFiles.Remove(file); + } + } + + private string _dcsPath = null; + private uint _bestDCSInstallType = 0; + + public DCSInterfaceEditor() + { + InitializeComponent(); + _bestDCSInstallType = 3; + Configuration = new DCSConfigurator("DCS F/A-18C", DCSPath); + Configuration.ExportConfigPath = "Config\\Export"; + switch (_bestDCSInstallType) + { + case 3: + Configuration.DCSInstallType = "GA"; + Configuration.InstallTypeGA = true; + break; + case 2: + Configuration.DCSInstallType = "OpenBeta"; + Configuration.InstallTypeBeta = true; + break; + case 1: + Configuration.DCSInstallType = "OpenAlpha"; + Configuration.InstallTypeAlpha = true; + break; + default: + Configuration.DCSInstallType = ""; + Configuration.InstallTypeGA = false; + Configuration.InstallTypeBeta = false; + Configuration.InstallTypeAlpha = false; + break; + } + } + + #region Properties + + public DCSConfigurator Configuration + { + get { return (DCSConfigurator)GetValue(ConfigurationProperty); } + set { SetValue(ConfigurationProperty, value); } + } + + // Using a DependencyProperty as the backing store for Configuration. This enables animation, styling, binding, etc... + public static readonly DependencyProperty ConfigurationProperty = + DependencyProperty.Register("Configuration", typeof(DCSConfigurator), typeof(DCSInterfaceEditor), new PropertyMetadata(null)); + + public string DCSPath + { + get + { + + if (_dcsPath == null) + { + RegistryKey pathKey = Registry.CurrentUser.OpenSubKey(@"Software\Eagle Dynamics\DCS World"); + if (pathKey == null) + { + --_bestDCSInstallType; + pathKey = Registry.CurrentUser.OpenSubKey(@"Software\Eagle Dynamics\DCS World OpenBeta"); + } + if (pathKey == null) + { + --_bestDCSInstallType; + pathKey = Registry.CurrentUser.OpenSubKey(@"Software\Eagle Dynamics\DCS World OpenAlpha"); + } + if (pathKey == null) + { + --_bestDCSInstallType; + pathKey = Registry.CurrentUser.OpenSubKey(@"Software\Eagle Dynamics\DCS DCS"); + } + + if (pathKey != null) + { + _dcsPath = (string)pathKey.GetValue("Path"); + pathKey.Close(); + ConfigManager.LogManager.LogDebug("DCS F/A-18C Interface Editor - Found DCS Path (Path=\"" + _dcsPath + "\")"); + } + else + { + ConfigManager.LogManager.LogDebug("DCS F/A-18C Interface Editor - No DCS Installation Paths Found in registry"); + _bestDCSInstallType = 0; + _dcsPath = ""; + } + } + return _dcsPath; + } + set + { + _dcsPath = value; + } + } + public void ForceDCSPath() + { + RegistryKey pathKey = null; + if (Configuration.InstallTypeGA) + { + pathKey = Registry.CurrentUser.OpenSubKey(@"Software\Eagle Dynamics\DCS World"); + } + else if (Configuration.InstallTypeBeta) + { + pathKey = Registry.CurrentUser.OpenSubKey(@"Software\Eagle Dynamics\DCS World OpenBeta"); + } + else if (Configuration.InstallTypeAlpha) + { + pathKey = Registry.CurrentUser.OpenSubKey(@"Software\Eagle Dynamics\DCS World OpenAlpha"); + } + + if (pathKey != null) + { + _dcsPath = (string)pathKey.GetValue("Path"); + Configuration.AppPath = _dcsPath; + pathKey.Close(); + ConfigManager.LogManager.LogDebug("DCS F/A-18C Interface Editor - Found DCS Path (Path=\"" + _dcsPath + "\")"); + } + else + { + _dcsPath = ""; + Configuration.AppPath = ""; + ConfigManager.LogManager.LogDebug("DCS F/A-18C Interface Editor - Forced DCS Install Type Path not found (Installation Type=\"" + Configuration.DCSInstallType + "\")"); + } + } + + #endregion + + protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) + { + if (e.Property == InterfaceProperty) + { + Configuration.UDPInterface = Interface as BaseUDPInterface; + } + + base.OnPropertyChanged(e); + } + + private void Configure_Click(object sender, RoutedEventArgs e) + { + if (Configuration.UpdateExportConfig()) + { + MessageBox.Show(Window.GetWindow(this), "DCS F/A-18C has been configured."); + } + else + { + MessageBox.Show(Window.GetWindow(this), "Error updating DCS F/A-18C configuration. Please do one of the following and try again:\n\nOption 1) Run Helios as Administrator\nOption 2) Install DCS outside the Program Files Directory\nOption 3) Disable UAC."); + } + } + + private void ResetPath(object sender, RoutedEventArgs e) + { + if (Configuration != null) + { + Configuration.AppPath = DCSPath; + } + } + + private void Remove_Click(object sender, RoutedEventArgs e) + { + Configuration.RestoreConfig(); + } + + private void RadioButton_Checked(object sender, RoutedEventArgs e) + { + RadioButton _rb = (RadioButton)sender; + if (_rb.GroupName == "DCSInstallTypeGroup") + { + // an override for the installation type has been declared + Configuration.DCSInstallType = (string)_rb.Tag; + ForceDCSPath(); + } + } + + } +} diff --git a/Helios/Interfaces/DCS/FA18C/FA18CInterface.cs b/Helios/Interfaces/DCS/FA18C/FA18CInterface.cs index 0951340ef..d276a112c 100644 --- a/Helios/Interfaces/DCS/FA18C/FA18CInterface.cs +++ b/Helios/Interfaces/DCS/FA18C/FA18CInterface.cs @@ -23,7 +23,7 @@ namespace GadrocsWorkshop.Helios.Interfaces.DCS.FA18C using Microsoft.Win32; using System; - [HeliosInterface("Helios.FA18C", "DCS F/A-18C", typeof(FA18CInterfaceEditor), typeof(UniqueHeliosInterfaceFactory))] + [HeliosInterface("Helios.FA18C", "DCS F/A-18C", typeof(FA18CInterface.Editor), typeof(UniqueHeliosInterfaceFactory))] public class FA18CInterface : BaseUDPInterface { private string _dcsPath; @@ -34,6 +34,14 @@ public class FA18CInterface : BaseUDPInterface private long _nextCheck = 0; + public class Editor: DCSInterfaceEditor + { + public Editor() + { + Configuration.ExportFunctionsPath = "pack://application:,,,/Helios;component/Interfaces/DCS/FA18C/ExportFunctions.lua"; + } + } + #region Devices // From devices.lua - DCS seem to want this to remain constant which is great private const string FM_PROXY = "1";