diff --git a/G940LEDControl/Bin/FSX-SE-SimConnect.dll b/G940LEDControl/Bin/FSX-SE-SimConnect.dll
new file mode 100644
index 0000000..a70883d
Binary files /dev/null and b/G940LEDControl/Bin/FSX-SE-SimConnect.dll differ
diff --git a/G940LEDControl/Bin/SimConnect.dll b/G940LEDControl/Bin/FSX-SimConnect.dll
similarity index 100%
rename from G940LEDControl/Bin/SimConnect.dll
rename to G940LEDControl/Bin/FSX-SimConnect.dll
diff --git a/G940LEDControl/Forms/MainFrm.dfm b/G940LEDControl/Forms/MainFrm.dfm
index fafff6d..2a0cc17 100644
--- a/G940LEDControl/Forms/MainFrm.dfm
+++ b/G940LEDControl/Forms/MainFrm.dfm
@@ -379,7 +379,7 @@ object MainForm: TMainForm
452)
object lblProfileSwitching: TLabel
Left = 11
- Top = 187
+ Top = 239
Width = 92
Height = 13
Caption = 'Profile switching'
@@ -392,7 +392,7 @@ object MainForm: TMainForm
end
object bvlProfileSwitching: TBevel
Left = 124
- Top = 194
+ Top = 246
Width = 305
Height = 13
Anchors = [akLeft, akTop, akRight]
@@ -400,7 +400,7 @@ object MainForm: TMainForm
end
object lblLaunch: TLabel
Left = 11
- Top = 122
+ Top = 134
Width = 40
Height = 13
Caption = 'Launch'
@@ -413,7 +413,7 @@ object MainForm: TMainForm
end
object bvlLaunch: TBevel
Left = 80
- Top = 129
+ Top = 141
Width = 353
Height = 13
Anchors = [akLeft, akTop, akRight]
@@ -442,7 +442,7 @@ object MainForm: TMainForm
end
object cbProfileMenu: TCheckBox
Left = 11
- Top = 212
+ Top = 264
Width = 409
Height = 17
Caption = ' Add profile selection to FSX/Prepar3D "Add-ons" menu'
@@ -453,7 +453,7 @@ object MainForm: TMainForm
end
object cbProfileMenuCascaded: TCheckBox
Left = 31
- Top = 235
+ Top = 287
Width = 389
Height = 17
Caption = ' Cascaded menu (profiles in "G940 Profile" submenu)'
@@ -462,7 +462,7 @@ object MainForm: TMainForm
end
object cbFSXAutoLaunch: TCheckBox
Left = 11
- Top = 147
+ Top = 159
Width = 409
Height = 17
Caption = ' Automatically start G940 LED Control when FSX launches'
@@ -511,6 +511,19 @@ object MainForm: TMainForm
TabOrder = 6
OnClick = btnLogClick
end
+ object cbFSXSEAutoLaunch: TCheckBox
+ Left = 11
+ Top = 182
+ Width = 409
+ Height = 17
+ Caption =
+ ' Automatically start G940 LED Control when FSX- Steam Edition la' +
+ 'unches'
+ Checked = True
+ State = cbChecked
+ TabOrder = 7
+ OnClick = cbFSXSEAutoLaunchClick
+ end
end
object tsAbout: TTabSheet
Caption = 'About'
diff --git a/G940LEDControl/Forms/MainFrm.pas b/G940LEDControl/Forms/MainFrm.pas
index 13f0736..251d7f5 100644
--- a/G940LEDControl/Forms/MainFrm.pas
+++ b/G940LEDControl/Forms/MainFrm.pas
@@ -124,6 +124,7 @@ type
btnLog: TButton;
TrayIcon: TTrayIcon;
ApplicationEvents: TApplicationEvents;
+ cbFSXSEAutoLaunch: TCheckBox;
procedure FormCreate(Sender: TObject);
procedure lblLinkLinkClick(Sender: TObject; const Link: string; LinkType: TSysLinkType);
@@ -143,6 +144,7 @@ type
procedure btnLogClick(Sender: TObject);
procedure ApplicationEventsMinimize(Sender: TObject);
procedure TrayIconClick(Sender: TObject);
+ procedure cbFSXSEAutoLaunchClick(Sender: TObject);
private
FLog: IX2Log;
FLEDControls: array[0..LED_COUNT - 1] of TLEDControls;
@@ -231,6 +233,7 @@ uses
ButtonFunctionFrm,
ConfigConversion,
+ FSXAutoLaunch,
FSXLEDFunctionProviderIntf,
FSXResources,
FSXSimConnectStateMonitor,
@@ -345,6 +348,7 @@ begin
UnregisterDeviceArrival;
TProfileManager.Detach(Self);
+ TX2LogObserverMonitorForm.CloseInstance(TX2GlobalLog.Instance);
TX2LogObserverMonitorForm.UnlockInstance(TX2GlobalLog.Instance);
end;
@@ -609,6 +613,8 @@ begin
cbMinimizeToTray.Checked := Settings.MinimizeToTray;
cbLaunchMinimized.Checked := Settings.LaunchMinimized;
+ cbFSXAutoLaunch.Checked := TFSXAutoLaunch.IsEnabled(fsxStandard);
+ cbFSXSEAutoLaunch.Checked := TFSXAutoLaunch.IsEnabled(fsxSteamEdition);
cbProfileMenu.Checked := Settings.ProfileMenu;
cbProfileMenuCascaded.Checked := Settings.ProfileMenuCascaded;
@@ -1104,7 +1110,29 @@ end;
procedure TMainForm.cbFSXAutoLaunchClick(Sender: TObject);
begin
- //
+ if FLoadingSettings then
+ exit;
+
+ FLoadingSettings := True;
+ try
+ cbFSXAutoLaunch.Checked := TFSXAutoLaunch.SetEnabled(fsxStandard, cbFSXAutoLaunch.Checked);
+ finally
+ FLoadingSettings := False;
+ end;
+end;
+
+
+procedure TMainForm.cbFSXSEAutoLaunchClick(Sender: TObject);
+begin
+ if FLoadingSettings then
+ exit;
+
+ FLoadingSettings := True;
+ try
+ cbFSXSEAutoLaunch.Checked := TFSXAutoLaunch.SetEnabled(fsxSteamEdition, cbFSXSEAutoLaunch.Checked);
+ finally
+ FLoadingSettings := False;
+ end;
end;
diff --git a/G940LEDControl/G940LEDControl.dpr b/G940LEDControl/G940LEDControl.dpr
index 2a4566d..23be35d 100644
--- a/G940LEDControl/G940LEDControl.dpr
+++ b/G940LEDControl/G940LEDControl.dpr
@@ -3,6 +3,7 @@ program G940LEDControl;
uses
Forms,
SysUtils,
+ X2UtSingleInstance,
MainFrm in 'Forms\MainFrm.pas' {MainForm},
LogiJoystickDLL in '..\Shared\LogiJoystickDLL.pas',
SimConnect in '..\Shared\SimConnect.pas',
@@ -34,7 +35,8 @@ uses
FSXSimConnectStateMonitor in 'Units\FSXSimConnectStateMonitor.pas',
ProfileManager in 'Units\ProfileManager.pas',
FSXLEDFunctionProviderIntf in 'Units\FSXLEDFunctionProviderIntf.pas',
- SimBaseDocumentXMLBinding in 'Units\SimBaseDocumentXMLBinding.pas';
+ SimBaseDocumentXMLBinding in 'Units\SimBaseDocumentXMLBinding.pas',
+ FSXAutoLaunch in 'Units\FSXAutoLaunch.pas';
{$R *.res}
@@ -43,6 +45,9 @@ var
MainForm: TMainForm;
begin
+ if not SingleInstance('{67D1802F-2AB8-40B9-ADD7-14C9D36903C8}', False, False) then
+ exit;
+
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.Title := 'G940 LED Control';
diff --git a/G940LEDControl/G940LEDControl.dproj b/G940LEDControl/G940LEDControl.dproj
index fb93de6..77e5e2b 100644
--- a/G940LEDControl/G940LEDControl.dproj
+++ b/G940LEDControl/G940LEDControl.dproj
@@ -8,7 +8,7 @@
VCL
13.4
True
- Debug
+ Release
Win32
1
Application
@@ -49,7 +49,7 @@
true
- 8
+ 1
rtl;dbrtl;$(DCC_UsePackage)
Lib
Bin
@@ -58,7 +58,7 @@
None
G940LEDControl_Icon.ico
Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;System;Xml;Data;Datasnap;Web;Soap;Winapi;System.Win;$(DCC_Namespace)
- CompanyName=X²Software;FileDescription=G940 LED Control;FileVersion=1.0.8.0;InternalName=;LegalCopyright=© 2011 - 2015 X²Software;LegalTrademarks=;OriginalFilename=G940LEDControl.exe;ProductName=G940 LED Control;ProductVersion=1.0;Comments=
+ CompanyName=X²Software;FileDescription=G940 LED Control;FileVersion=1.1.0.0;InternalName=;LegalCopyright=© 2011 - 2015 X²Software;LegalTrademarks=;OriginalFilename=G940LEDControl.exe;ProductName=G940 LED Control;ProductVersion=1.1;Comments=
1033
@@ -138,6 +138,7 @@
+
Cfg_2
Base
diff --git a/G940LEDControl/G940LEDControl.res b/G940LEDControl/G940LEDControl.res
index 4ed79be..daf3e06 100644
Binary files a/G940LEDControl/G940LEDControl.res and b/G940LEDControl/G940LEDControl.res differ
diff --git a/G940LEDControl/Units/FSXAutoLaunch.pas b/G940LEDControl/Units/FSXAutoLaunch.pas
new file mode 100644
index 0000000..8f355ac
--- /dev/null
+++ b/G940LEDControl/Units/FSXAutoLaunch.pas
@@ -0,0 +1,129 @@
+unit FSXAutoLaunch;
+
+interface
+type
+ TFSXVersion = (fsxStandard, fsxSteamEdition);
+
+ TFSXAutoLaunch = class(TObject)
+ protected
+ class function GetLaunchFileName(AVersion: TFSXVersion): string;
+ public
+ class function IsEnabled(AVersion: TFSXVersion): Boolean;
+ class function SetEnabled(AVersion: TFSXVersion; AValue: Boolean): Boolean;
+ end;
+
+
+implementation
+uses
+ System.SysUtils,
+ Xml.XMLIntf,
+
+ X2UtApp,
+
+ SimBaseDocumentXMLBinding;
+
+
+const
+ FSXEXELaunchFileName = 'exe.xml';
+ AddonName = 'G940LEDControl';
+
+
+
+{ TFSXAutoLaunch }
+class function TFSXAutoLaunch.GetLaunchFileName(AVersion: TFSXVersion): string;
+const
+ VersionPath: array[TFSXVersion] of string = ('FSX', 'FSX-SE');
+
+begin
+ Result := App.UserPath + 'Microsoft\' + VersionPath[AVersion] + '\' + FSXEXELaunchFileName;
+end;
+
+
+class function TFSXAutoLaunch.IsEnabled(AVersion: TFSXVersion): Boolean;
+var
+ launch: IXMLSimBaseDocument;
+ addon: IXMLLaunchAddon;
+
+begin
+ Result := False;
+ if not FileExists(GetLaunchFileName(AVersion)) then
+ exit;
+
+ try
+ launch := LoadSimBaseDocument(GetLaunchFileName(AVersion));
+
+ for addon in launch do
+ begin
+ if addon.Name = AddonName then
+ begin
+ Result := True;
+ break;
+ end;
+ end;
+ except
+ Result := False;
+ end;
+end;
+
+
+class function TFSXAutoLaunch.SetEnabled(AVersion: TFSXVersion; AValue: Boolean): Boolean;
+var
+ launch: IXMLSimBaseDocument;
+ findAddon: IXMLLaunchAddon;
+ addon: IXMLLaunchAddon;
+
+begin
+ if not FileExists(GetLaunchFileName(AVersion)) then
+ begin
+ launch := NewSimBaseDocument;
+ launch.OwnerDocument.Encoding := 'Windows-1252';
+ launch.OwnerDocument.Options := launch.OwnerDocument.Options + [doNodeAutoIndent];
+
+ launch._Type := 'Launch';
+ launch.version := '1,0';
+
+ launch.Descr := 'Launch';
+ launch.Filename := FSXEXELaunchFileName;
+ launch.Disabled := SimBaseBoolean_False;
+ launch.LaunchManualLoad := SimBaseBoolean_False;
+ end else
+ begin
+ launch := LoadSimBaseDocument(GetLaunchFileName(AVersion));
+ launch.OwnerDocument.Options := launch.OwnerDocument.Options + [doNodeAutoIndent];
+ end;
+
+ addon := nil;
+ for findAddon in launch do
+ begin
+ if findAddon.Name = AddonName then
+ begin
+ addon := findAddon;
+ break;
+ end;
+ end;
+
+ if AValue then
+ begin
+ if not Assigned(addon) then
+ begin
+ addon := launch.Add;
+ addon.Name := AddonName;
+ end;
+
+ addon.Disabled := SimBaseBoolean_False;
+ addon.ManualLoad := SimBaseBoolean_False;
+ addon.Path := App.FileName;
+ launch.OwnerDocument.SaveToFile(GetLaunchFileName(AVersion));
+ end else
+ begin
+ if Assigned(addon) then
+ begin
+ launch.Remove(addon);
+ launch.OwnerDocument.SaveToFile(GetLaunchFileName(AVersion));
+ end;
+ end;
+
+ Result := AValue;
+end;
+
+end.
diff --git a/G940LEDControl/Units/FSXSimConnectClient.pas b/G940LEDControl/Units/FSXSimConnectClient.pas
index f39d183..6a209aa 100644
--- a/G940LEDControl/Units/FSXSimConnectClient.pas
+++ b/G940LEDControl/Units/FSXSimConnectClient.pas
@@ -59,6 +59,7 @@ uses
OtlComm,
OtlCommon,
SimConnect,
+ X2UtApp,
FSXResources,
FSXSimConnectStateMonitor;
@@ -137,7 +138,8 @@ type
function Initialize: Boolean; override;
procedure Cleanup; override;
- procedure TrySimConnect;
+ procedure TrySimConnect; overload;
+ procedure TrySimConnect(const ALibraryName: string); overload;
procedure RegisterDefinitions;
procedure RegisterDefinition(ADefinitionID: Cardinal; ADefinition: IFSXSimConnectDefinitionAccess);
@@ -427,16 +429,35 @@ end;
procedure TFSXSimConnectClient.TrySimConnect;
-var
- eventHandle: THandle;
-
begin
if SimConnectHandle <> 0 then
exit;
- Log.Info('Attempting to connect to SimConnect');
+ TrySimConnect('FSX-SimConnect.dll');
+ if SimConnectHandle = 0 then
+ TrySimConnect('FSX-SE-SimConnect.dll');
- if InitSimConnect then
+ if SimConnectHandle = 0 then
+ begin
+ Log.Info(Format('FSX SimConnect: Connection failed, trying again in %d seconds', [INTERVAL_TRYSIMCONNECT div 1000]));
+ TFSXSimConnectStateMonitor.SetCurrentState(scsFailed);
+
+ Task.SetTimer(TIMER_TRYSIMCONNECT, INTERVAL_TRYSIMCONNECT, TM_TRYSIMCONNECT);
+ {$IFNDEF SCUSEEVENT}
+ Task.ClearTimer(TIMER_PROCESSMESSAGES);
+ {$ENDIF}
+ end;
+end;
+
+
+procedure TFSXSimConnectClient.TrySimConnect(const ALibraryName: string);
+var
+ eventHandle: THandle;
+
+begin
+ Log.Info('Attempting to connect to SimConnect using ' + ALibraryName);
+
+ if InitSimConnectFromLibrary(App.Path + ALibraryName) then
begin
{$IFDEF SCUSEEVENT}
eventHandle := SimConnectDataEvent.Handle;
@@ -456,18 +477,8 @@ begin
{$IFNDEF SCUSEEVENT}
Task.SetTimer(TIMER_PROCESSMESSAGES, INTERVAL_PROCESSMESSAGES, TM_PROCESSMESSAGES);
{$ENDIF}
- end;
- end;
-
- if SimConnectHandle = 0 then
- begin
- Log.Info(Format('FSX SimConnect: Connection failed, trying again in %d seconds', [INTERVAL_TRYSIMCONNECT div 1000]));
- TFSXSimConnectStateMonitor.SetCurrentState(scsFailed);
-
- Task.SetTimer(TIMER_TRYSIMCONNECT, INTERVAL_TRYSIMCONNECT, TM_TRYSIMCONNECT);
- {$IFNDEF SCUSEEVENT}
- Task.ClearTimer(TIMER_PROCESSMESSAGES);
- {$ENDIF}
+ end else
+ FSimConnectHandle := 0;
end;
end;
diff --git a/Setup/G940LEDControl.iss b/Setup/G940LEDControl.iss
index 57d5b1b..fe9f7c4 100644
--- a/Setup/G940LEDControl.iss
+++ b/Setup/G940LEDControl.iss
@@ -30,7 +30,8 @@ Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{
[Files]
Source: "..\G940LEDControl\Bin\{#AppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\G940LEDControl\Bin\LogiJoystickDLL.dll"; DestDir: "{app}"; Flags: ignoreversion
-Source: "..\G940LEDControl\Bin\SimConnect.dll"; DestDir: "{app}"; Flags: ignoreversion
+Source: "..\G940LEDControl\Bin\FSX-SimConnect.dll"; DestDir: "{app}"; Flags: ignoreversion
+Source: "..\G940LEDControl\Bin\FSX-SE-SimConnect.dll"; DestDir: "{app}"; Flags: ignoreversion
[Icons]
Name: "{group}\{#AppName}"; Filename: "{app}\{#AppExeName}"
diff --git a/Shared/SimConnect.pas b/Shared/SimConnect.pas
index bb3498e..6156562 100644
--- a/Shared/SimConnect.pas
+++ b/Shared/SimConnect.pas
@@ -662,6 +662,7 @@ type
// Additional procedures to support dynamic loading
function InitSimConnect: boolean;
+function InitSimConnectFromLibrary(Name: string): boolean;
procedure CloseSimConnect;
function IsSimConnectInitialized: Boolean;