1
0
mirror of synced 2024-11-05 02:59:16 +00:00

Compatibility with FSX - Steam Edition

AutoLaunch feature
This commit is contained in:
Mark van Renswoude 2015-04-18 11:42:15 +00:00
parent 20350cfdd7
commit 76565a9c5d
11 changed files with 220 additions and 31 deletions

Binary file not shown.

View File

@ -379,7 +379,7 @@ object MainForm: TMainForm
452) 452)
object lblProfileSwitching: TLabel object lblProfileSwitching: TLabel
Left = 11 Left = 11
Top = 187 Top = 239
Width = 92 Width = 92
Height = 13 Height = 13
Caption = 'Profile switching' Caption = 'Profile switching'
@ -392,7 +392,7 @@ object MainForm: TMainForm
end end
object bvlProfileSwitching: TBevel object bvlProfileSwitching: TBevel
Left = 124 Left = 124
Top = 194 Top = 246
Width = 305 Width = 305
Height = 13 Height = 13
Anchors = [akLeft, akTop, akRight] Anchors = [akLeft, akTop, akRight]
@ -400,7 +400,7 @@ object MainForm: TMainForm
end end
object lblLaunch: TLabel object lblLaunch: TLabel
Left = 11 Left = 11
Top = 122 Top = 134
Width = 40 Width = 40
Height = 13 Height = 13
Caption = 'Launch' Caption = 'Launch'
@ -413,7 +413,7 @@ object MainForm: TMainForm
end end
object bvlLaunch: TBevel object bvlLaunch: TBevel
Left = 80 Left = 80
Top = 129 Top = 141
Width = 353 Width = 353
Height = 13 Height = 13
Anchors = [akLeft, akTop, akRight] Anchors = [akLeft, akTop, akRight]
@ -442,7 +442,7 @@ object MainForm: TMainForm
end end
object cbProfileMenu: TCheckBox object cbProfileMenu: TCheckBox
Left = 11 Left = 11
Top = 212 Top = 264
Width = 409 Width = 409
Height = 17 Height = 17
Caption = ' Add profile selection to FSX/Prepar3D "Add-ons" menu' Caption = ' Add profile selection to FSX/Prepar3D "Add-ons" menu'
@ -453,7 +453,7 @@ object MainForm: TMainForm
end end
object cbProfileMenuCascaded: TCheckBox object cbProfileMenuCascaded: TCheckBox
Left = 31 Left = 31
Top = 235 Top = 287
Width = 389 Width = 389
Height = 17 Height = 17
Caption = ' Cascaded menu (profiles in "G940 Profile" submenu)' Caption = ' Cascaded menu (profiles in "G940 Profile" submenu)'
@ -462,7 +462,7 @@ object MainForm: TMainForm
end end
object cbFSXAutoLaunch: TCheckBox object cbFSXAutoLaunch: TCheckBox
Left = 11 Left = 11
Top = 147 Top = 159
Width = 409 Width = 409
Height = 17 Height = 17
Caption = ' Automatically start G940 LED Control when FSX launches' Caption = ' Automatically start G940 LED Control when FSX launches'
@ -511,6 +511,19 @@ object MainForm: TMainForm
TabOrder = 6 TabOrder = 6
OnClick = btnLogClick OnClick = btnLogClick
end 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 end
object tsAbout: TTabSheet object tsAbout: TTabSheet
Caption = 'About' Caption = 'About'

View File

@ -124,6 +124,7 @@ type
btnLog: TButton; btnLog: TButton;
TrayIcon: TTrayIcon; TrayIcon: TTrayIcon;
ApplicationEvents: TApplicationEvents; ApplicationEvents: TApplicationEvents;
cbFSXSEAutoLaunch: TCheckBox;
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure lblLinkLinkClick(Sender: TObject; const Link: string; LinkType: TSysLinkType); procedure lblLinkLinkClick(Sender: TObject; const Link: string; LinkType: TSysLinkType);
@ -143,6 +144,7 @@ type
procedure btnLogClick(Sender: TObject); procedure btnLogClick(Sender: TObject);
procedure ApplicationEventsMinimize(Sender: TObject); procedure ApplicationEventsMinimize(Sender: TObject);
procedure TrayIconClick(Sender: TObject); procedure TrayIconClick(Sender: TObject);
procedure cbFSXSEAutoLaunchClick(Sender: TObject);
private private
FLog: IX2Log; FLog: IX2Log;
FLEDControls: array[0..LED_COUNT - 1] of TLEDControls; FLEDControls: array[0..LED_COUNT - 1] of TLEDControls;
@ -231,6 +233,7 @@ uses
ButtonFunctionFrm, ButtonFunctionFrm,
ConfigConversion, ConfigConversion,
FSXAutoLaunch,
FSXLEDFunctionProviderIntf, FSXLEDFunctionProviderIntf,
FSXResources, FSXResources,
FSXSimConnectStateMonitor, FSXSimConnectStateMonitor,
@ -345,6 +348,7 @@ begin
UnregisterDeviceArrival; UnregisterDeviceArrival;
TProfileManager.Detach(Self); TProfileManager.Detach(Self);
TX2LogObserverMonitorForm.CloseInstance(TX2GlobalLog.Instance);
TX2LogObserverMonitorForm.UnlockInstance(TX2GlobalLog.Instance); TX2LogObserverMonitorForm.UnlockInstance(TX2GlobalLog.Instance);
end; end;
@ -609,6 +613,8 @@ begin
cbMinimizeToTray.Checked := Settings.MinimizeToTray; cbMinimizeToTray.Checked := Settings.MinimizeToTray;
cbLaunchMinimized.Checked := Settings.LaunchMinimized; cbLaunchMinimized.Checked := Settings.LaunchMinimized;
cbFSXAutoLaunch.Checked := TFSXAutoLaunch.IsEnabled(fsxStandard);
cbFSXSEAutoLaunch.Checked := TFSXAutoLaunch.IsEnabled(fsxSteamEdition);
cbProfileMenu.Checked := Settings.ProfileMenu; cbProfileMenu.Checked := Settings.ProfileMenu;
cbProfileMenuCascaded.Checked := Settings.ProfileMenuCascaded; cbProfileMenuCascaded.Checked := Settings.ProfileMenuCascaded;
@ -1104,7 +1110,29 @@ end;
procedure TMainForm.cbFSXAutoLaunchClick(Sender: TObject); procedure TMainForm.cbFSXAutoLaunchClick(Sender: TObject);
begin 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; end;

View File

@ -3,6 +3,7 @@ program G940LEDControl;
uses uses
Forms, Forms,
SysUtils, SysUtils,
X2UtSingleInstance,
MainFrm in 'Forms\MainFrm.pas' {MainForm}, MainFrm in 'Forms\MainFrm.pas' {MainForm},
LogiJoystickDLL in '..\Shared\LogiJoystickDLL.pas', LogiJoystickDLL in '..\Shared\LogiJoystickDLL.pas',
SimConnect in '..\Shared\SimConnect.pas', SimConnect in '..\Shared\SimConnect.pas',
@ -34,7 +35,8 @@ uses
FSXSimConnectStateMonitor in 'Units\FSXSimConnectStateMonitor.pas', FSXSimConnectStateMonitor in 'Units\FSXSimConnectStateMonitor.pas',
ProfileManager in 'Units\ProfileManager.pas', ProfileManager in 'Units\ProfileManager.pas',
FSXLEDFunctionProviderIntf in 'Units\FSXLEDFunctionProviderIntf.pas', FSXLEDFunctionProviderIntf in 'Units\FSXLEDFunctionProviderIntf.pas',
SimBaseDocumentXMLBinding in 'Units\SimBaseDocumentXMLBinding.pas'; SimBaseDocumentXMLBinding in 'Units\SimBaseDocumentXMLBinding.pas',
FSXAutoLaunch in 'Units\FSXAutoLaunch.pas';
{$R *.res} {$R *.res}
@ -43,6 +45,9 @@ var
MainForm: TMainForm; MainForm: TMainForm;
begin begin
if not SingleInstance('{67D1802F-2AB8-40B9-ADD7-14C9D36903C8}', False, False) then
exit;
Application.Initialize; Application.Initialize;
Application.MainFormOnTaskbar := True; Application.MainFormOnTaskbar := True;
Application.Title := 'G940 LED Control'; Application.Title := 'G940 LED Control';

View File

@ -8,7 +8,7 @@
<FrameworkType>VCL</FrameworkType> <FrameworkType>VCL</FrameworkType>
<ProjectVersion>13.4</ProjectVersion> <ProjectVersion>13.4</ProjectVersion>
<Base>True</Base> <Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config> <Config Condition="'$(Config)'==''">Release</Config>
<Platform Condition="'$(Platform)'==''">Win32</Platform> <Platform Condition="'$(Platform)'==''">Win32</Platform>
<TargetedPlatforms>1</TargetedPlatforms> <TargetedPlatforms>1</TargetedPlatforms>
<AppType>Application</AppType> <AppType>Application</AppType>
@ -49,7 +49,7 @@
<Base>true</Base> <Base>true</Base>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Base)'!=''"> <PropertyGroup Condition="'$(Base)'!=''">
<VerInfo_Release>8</VerInfo_Release> <VerInfo_MinorVer>1</VerInfo_MinorVer>
<DCC_UsePackage>rtl;dbrtl;$(DCC_UsePackage)</DCC_UsePackage> <DCC_UsePackage>rtl;dbrtl;$(DCC_UsePackage)</DCC_UsePackage>
<DCC_DcuOutput>Lib</DCC_DcuOutput> <DCC_DcuOutput>Lib</DCC_DcuOutput>
<DCC_ExeOutput>Bin</DCC_ExeOutput> <DCC_ExeOutput>Bin</DCC_ExeOutput>
@ -58,7 +58,7 @@
<Manifest_File>None</Manifest_File> <Manifest_File>None</Manifest_File>
<Icon_MainIcon>G940LEDControl_Icon.ico</Icon_MainIcon> <Icon_MainIcon>G940LEDControl_Icon.ico</Icon_MainIcon>
<DCC_Namespace>Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;System;Xml;Data;Datasnap;Web;Soap;Winapi;System.Win;$(DCC_Namespace)</DCC_Namespace> <DCC_Namespace>Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;System;Xml;Data;Datasnap;Web;Soap;Winapi;System.Win;$(DCC_Namespace)</DCC_Namespace>
<VerInfo_Keys>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=</VerInfo_Keys> <VerInfo_Keys>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=</VerInfo_Keys>
<VerInfo_Locale>1033</VerInfo_Locale> <VerInfo_Locale>1033</VerInfo_Locale>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Base_Win64)'!=''"> <PropertyGroup Condition="'$(Base_Win64)'!=''">
@ -138,6 +138,7 @@
<DCCReference Include="Units\ProfileManager.pas"/> <DCCReference Include="Units\ProfileManager.pas"/>
<DCCReference Include="Units\FSXLEDFunctionProviderIntf.pas"/> <DCCReference Include="Units\FSXLEDFunctionProviderIntf.pas"/>
<DCCReference Include="Units\SimBaseDocumentXMLBinding.pas"/> <DCCReference Include="Units\SimBaseDocumentXMLBinding.pas"/>
<DCCReference Include="Units\FSXAutoLaunch.pas"/>
<BuildConfiguration Include="Debug"> <BuildConfiguration Include="Debug">
<Key>Cfg_2</Key> <Key>Cfg_2</Key>
<CfgParent>Base</CfgParent> <CfgParent>Base</CfgParent>

Binary file not shown.

View File

@ -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.

View File

@ -59,6 +59,7 @@ uses
OtlComm, OtlComm,
OtlCommon, OtlCommon,
SimConnect, SimConnect,
X2UtApp,
FSXResources, FSXResources,
FSXSimConnectStateMonitor; FSXSimConnectStateMonitor;
@ -137,7 +138,8 @@ type
function Initialize: Boolean; override; function Initialize: Boolean; override;
procedure Cleanup; override; procedure Cleanup; override;
procedure TrySimConnect; procedure TrySimConnect; overload;
procedure TrySimConnect(const ALibraryName: string); overload;
procedure RegisterDefinitions; procedure RegisterDefinitions;
procedure RegisterDefinition(ADefinitionID: Cardinal; ADefinition: IFSXSimConnectDefinitionAccess); procedure RegisterDefinition(ADefinitionID: Cardinal; ADefinition: IFSXSimConnectDefinitionAccess);
@ -427,16 +429,35 @@ end;
procedure TFSXSimConnectClient.TrySimConnect; procedure TFSXSimConnectClient.TrySimConnect;
var
eventHandle: THandle;
begin begin
if SimConnectHandle <> 0 then if SimConnectHandle <> 0 then
exit; 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 begin
{$IFDEF SCUSEEVENT} {$IFDEF SCUSEEVENT}
eventHandle := SimConnectDataEvent.Handle; eventHandle := SimConnectDataEvent.Handle;
@ -456,18 +477,8 @@ begin
{$IFNDEF SCUSEEVENT} {$IFNDEF SCUSEEVENT}
Task.SetTimer(TIMER_PROCESSMESSAGES, INTERVAL_PROCESSMESSAGES, TM_PROCESSMESSAGES); Task.SetTimer(TIMER_PROCESSMESSAGES, INTERVAL_PROCESSMESSAGES, TM_PROCESSMESSAGES);
{$ENDIF} {$ENDIF}
end; end else
end; FSimConnectHandle := 0;
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;
end; end;

View File

@ -30,7 +30,8 @@ Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{
[Files] [Files]
Source: "..\G940LEDControl\Bin\{#AppExeName}"; DestDir: "{app}"; Flags: ignoreversion Source: "..\G940LEDControl\Bin\{#AppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\G940LEDControl\Bin\LogiJoystickDLL.dll"; 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] [Icons]
Name: "{group}\{#AppName}"; Filename: "{app}\{#AppExeName}" Name: "{group}\{#AppName}"; Filename: "{app}\{#AppExeName}"

View File

@ -662,6 +662,7 @@ type
// Additional procedures to support dynamic loading // Additional procedures to support dynamic loading
function InitSimConnect: boolean; function InitSimConnect: boolean;
function InitSimConnectFromLibrary(Name: string): boolean;
procedure CloseSimConnect; procedure CloseSimConnect;
function IsSimConnectInitialized: Boolean; function IsSimConnectInitialized: Boolean;