diff --git a/G940LEDControl/Forms/MainFrm.dfm b/G940LEDControl/Forms/MainFrm.dfm index 2a0cc17..f7f6373 100644 --- a/G940LEDControl/Forms/MainFrm.dfm +++ b/G940LEDControl/Forms/MainFrm.dfm @@ -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 diff --git a/G940LEDControl/Forms/MainFrm.pas b/G940LEDControl/Forms/MainFrm.pas index 251d7f5..5ecabc1 100644 --- a/G940LEDControl/Forms/MainFrm.pas +++ b/G940LEDControl/Forms/MainFrm.pas @@ -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])); diff --git a/G940LEDControl/G940LEDControl.dpr b/G940LEDControl/G940LEDControl.dpr index 23be35d..787d154 100644 --- a/G940LEDControl/G940LEDControl.dpr +++ b/G940LEDControl/G940LEDControl.dpr @@ -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; diff --git a/G940LEDControl/G940LEDControl.dproj b/G940LEDControl/G940LEDControl.dproj index 77e5e2b..8266d6f 100644 --- a/G940LEDControl/G940LEDControl.dproj +++ b/G940LEDControl/G940LEDControl.dproj @@ -49,6 +49,7 @@ true + 1 1 rtl;dbrtl;$(DCC_UsePackage) Lib @@ -58,7 +59,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.1.0.0;InternalName=;LegalCopyright=© 2011 - 2015 X²Software;LegalTrademarks=;OriginalFilename=G940LEDControl.exe;ProductName=G940 LED Control;ProductVersion=1.1;Comments= + 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= 1033 @@ -94,6 +95,7 @@ False + /restart false CompanyName=;FileDescription=;FileVersion=0.2.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=0.2;Comments= $(BDS)\bin\default_app.manifest @@ -139,6 +141,7 @@ + Cfg_2 Base diff --git a/G940LEDControl/G940LEDControl.res b/G940LEDControl/G940LEDControl.res index daf3e06..a7a0acd 100644 Binary files a/G940LEDControl/G940LEDControl.res and b/G940LEDControl/G940LEDControl.res differ diff --git a/G940LEDControl/Units/ControlIntf.pas b/G940LEDControl/Units/ControlIntf.pas new file mode 100644 index 0000000..7d024ce --- /dev/null +++ b/G940LEDControl/Units/ControlIntf.pas @@ -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. diff --git a/G940LEDControl/Units/FSXResources.pas b/G940LEDControl/Units/FSXResources.pas index 7399447..a8d68d0 100644 --- a/G940LEDControl/Units/FSXResources.pas +++ b/G940LEDControl/Units/FSXResources.pas @@ -282,6 +282,8 @@ const FSXMenuProfileFormat = 'G940: %s'; FSXMenuProfileFormatCascaded = '%s'; + FSXMenuRestart = 'Restart G940LEDControl'; + implementation diff --git a/G940LEDControl/Units/FSXSimConnectClient.pas b/G940LEDControl/Units/FSXSimConnectClient.pas index 6a209aa..6446d78 100644 --- a/G940LEDControl/Units/FSXSimConnectClient.pas +++ b/G940LEDControl/Units/FSXSimConnectClient.pas @@ -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;