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

Added: restart option to in-game Addons menu

This commit is contained in:
Mark van Renswoude 2015-06-17 16:28:18 +00:00
parent 76565a9c5d
commit dfc9255585
8 changed files with 115 additions and 5 deletions

View File

@ -34,6 +34,10 @@ object MainForm: TMainForm
TabOrder = 0
object tsButtons: TTabSheet
Caption = ' Button assignment '
ExplicitLeft = 0
ExplicitTop = 0
ExplicitWidth = 0
ExplicitHeight = 0
DesignSize = (
442
452)
@ -528,6 +532,10 @@ object MainForm: TMainForm
object tsAbout: TTabSheet
Caption = 'About'
ImageIndex = 1
ExplicitLeft = 0
ExplicitTop = 0
ExplicitWidth = 0
ExplicitHeight = 0
object lblVersionCaption: TLabel
Left = 16
Top = 67

View File

@ -22,6 +22,7 @@ uses
X2Log.Intf,
X2UtPersistIntf,
ControlIntf,
FSXSimConnectIntf,
LEDStateConsumer,
Profile,
@ -32,6 +33,7 @@ uses
const
CM_ASKAUTOUPDATE = WM_APP + 1;
CM_PROFILECHANGED = WM_APP + 2;
CM_RESTART = WM_APP + 3;
TM_UPDATE = 1;
TM_NOUPDATE = 2;
@ -53,7 +55,7 @@ type
end;
TMainForm = class(TForm, IProfileObserver)
TMainForm = class(TForm, IProfileObserver, IControlHandler)
imgStateNotFound: TImage;
lblG940Throttle: TLabel;
imgStateFound: TImage;
@ -169,8 +171,12 @@ type
procedure ObserveRemove(AProfile: TProfile);
procedure ObserveActiveChanged(AProfile: TProfile);
{ IControlHandler }
procedure Restart;
procedure WMDeviceChange(var Msg: TMessage); message WM_DEVICECHANGE;
procedure CMProfileChanged(var Msg: TMessage); message CM_PROFILECHANGED;
procedure CMRestart(var Msg: TMessage); message CM_RESTART;
protected
procedure FindLEDControls;
procedure LoadProfiles;
@ -338,11 +344,13 @@ begin
Application.ShowMainForm := False;
RegisterDeviceArrival;
SetControlHandler(Self);
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
SetControlHandler(nil);
FinalizeProfileMenu;
UnregisterDeviceArrival;
@ -811,6 +819,19 @@ begin
end;
procedure TMainForm.Restart;
begin
PostMessage(Self.Handle, CM_RESTART, 0, 0);
end;
procedure TMainForm.CMRestart(var Msg: TMessage);
begin
ShellExecute(0, 'open', PChar(App.FileName), '/restart', PChar(App.Path), SW_SHOWMINNOACTIVE);
Close;
end;
procedure TMainForm.SetDeviceState(const AMessage: string; AFound: Boolean);
begin
Log.Verbose(Format('G940 Throttle state changed (found = %s, status = %s)', [BoolToStr(AFound, True), AMessage]));

View File

@ -36,17 +36,28 @@ uses
ProfileManager in 'Units\ProfileManager.pas',
FSXLEDFunctionProviderIntf in 'Units\FSXLEDFunctionProviderIntf.pas',
SimBaseDocumentXMLBinding in 'Units\SimBaseDocumentXMLBinding.pas',
FSXAutoLaunch in 'Units\FSXAutoLaunch.pas';
FSXAutoLaunch in 'Units\FSXAutoLaunch.pas',
ControlIntf in 'Units\ControlIntf.pas';
{$R *.res}
var
MainForm: TMainForm;
isRestarting: Boolean;
begin
if not SingleInstance('{67D1802F-2AB8-40B9-ADD7-14C9D36903C8}', False, False) then
exit;
isRestarting := FindCmdLineSwitch('restart');
while not SingleInstance('{67D1802F-2AB8-40B9-ADD7-14C9D36903C8}', False, False) do
begin
Instance.Close;
if not isRestarting then
exit;
Sleep(1000);
end;
Application.Initialize;
Application.MainFormOnTaskbar := True;

View File

@ -49,6 +49,7 @@
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Base)'!=''">
<VerInfo_Release>1</VerInfo_Release>
<VerInfo_MinorVer>1</VerInfo_MinorVer>
<DCC_UsePackage>rtl;dbrtl;$(DCC_UsePackage)</DCC_UsePackage>
<DCC_DcuOutput>Lib</DCC_DcuOutput>
@ -58,7 +59,7 @@
<Manifest_File>None</Manifest_File>
<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>
<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_Keys>CompanyName=X²Software;FileDescription=G940 LED Control;FileVersion=1.1.1.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>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Win64)'!=''">
@ -94,6 +95,7 @@
<DCC_UNIT_PLATFORM>False</DCC_UNIT_PLATFORM>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
<Debugger_RunParams>/restart</Debugger_RunParams>
<VerInfo_IncludeVerInfo>false</VerInfo_IncludeVerInfo>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=0.2.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=0.2;Comments=</VerInfo_Keys>
<Manifest_File>$(BDS)\bin\default_app.manifest</Manifest_File>
@ -139,6 +141,7 @@
<DCCReference Include="Units\FSXLEDFunctionProviderIntf.pas"/>
<DCCReference Include="Units\SimBaseDocumentXMLBinding.pas"/>
<DCCReference Include="Units\FSXAutoLaunch.pas"/>
<DCCReference Include="Units\ControlIntf.pas"/>
<BuildConfiguration Include="Debug">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>

Binary file not shown.

View File

@ -0,0 +1,48 @@
unit ControlIntf;
interface
type
IControlHandler = interface
['{209A2DC9-D79C-4DC5-B515-AD4D14C44E37}']
procedure Restart;
end;
procedure SetControlHandler(AControlHandler: IControlHandler);
function GetControlHandler: IControlHandler;
implementation
var
ControlHandler: IControlHandler;
type
TNullControlHandler = class(TInterfacedObject, IControlHandler)
public
{ IControlHandler }
procedure Restart;
end;
procedure SetControlHandler(AControlHandler: IControlHandler);
begin
ControlHandler := AControlHandler;
end;
function GetControlHandler: IControlHandler;
begin
if Assigned(ControlHandler) then
Result := ControlHandler
else
Result := TNullControlHandler.Create;
end;
{ TNullControlHandler }
procedure TNullControlHandler.Restart;
begin
end;
end.

View File

@ -282,6 +282,8 @@ const
FSXMenuProfileFormat = 'G940: %s';
FSXMenuProfileFormatCascaded = '%s';
FSXMenuRestart = 'Restart G940LEDControl';
implementation

View File

@ -61,6 +61,7 @@ uses
SimConnect,
X2UtApp,
ControlIntf,
FSXResources,
FSXSimConnectStateMonitor;
@ -81,6 +82,8 @@ const
INTERVAL_PROCESSMESSAGES = 50;
{$ENDIF}
MENU_RESTART = 65536;
type
TFSXSimConnectDefinitionRef = class(TObject)
@ -571,6 +574,13 @@ var
profile: TProfile;
begin
if AEventID = MENU_RESTART then
begin
GetControlHandler.Restart;
exit;
end;
if (AEventID <= 0) or (AEventID > FMenuProfiles.Count) then
exit;
@ -697,10 +707,13 @@ begin
SimConnect_MenuDeleteSubItem(SimConnectHandle, 1, Cardinal(FMenuProfiles.Objects[menuIndex]));
SimConnect_MenuDeleteItem(SimConnectHandle, 1);
SimConnect_MenuDeleteItem(SimConnectHandle, 2);
end else
begin
for menuIndex := Pred(FMenuProfiles.Count) downto 0 do
SimConnect_MenuDeleteItem(SimConnectHandle, Cardinal(FMenuProfiles.Objects[menuIndex]));
SimConnect_MenuDeleteItem(SimConnectHandle, MENU_RESTART);
end;
FMenuProfiles.Clear;
@ -725,6 +738,8 @@ begin
SimConnect_MenuAddSubItem(SimConnectHandle, 1, PAnsiChar(AnsiString(profileName)), Succ(profileIndex), Succ(profileIndex));
FMenuProfiles.Objects[profileIndex] := TObject(Succ(profileIndex));
end;
SimConnect_MenuAddItem(SimConnectHandle, FSXMenuRestart, MENU_RESTART, 0);
end else
begin
for profileIndex := 0 to Pred(FMenuProfiles.Count) do
@ -734,6 +749,8 @@ begin
SimConnect_MenuAddItem(SimConnectHandle, PAnsiChar(AnsiString(profileName)), Succ(profileIndex), Succ(profileIndex));
FMenuProfiles.Objects[profileIndex] := TObject(Succ(profileIndex));
end;
SimConnect_MenuAddItem(SimConnectHandle, FSXMenuRestart, MENU_RESTART, 0);
end;
FMenuWasCascaded := ProfileMenuCascaded;