From 3d698f9f68cd8baa82415ea13aec1667ffac348c Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Wed, 31 Jan 2018 18:25:12 +0100 Subject: [PATCH] Disable SSH tunnel connections on Windows 10 S, as a requirement for publishing HeidiSQL in the Windows App store, #60. --- out/locale/en/LC_MESSAGES/default.po | 6 ++++++ source/apphelpers.pas | 19 ++++++++++++++++++- source/connections.pas | 11 ++++++++--- source/dbconnection.pas | 14 ++++++++++++++ 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/out/locale/en/LC_MESSAGES/default.po b/out/locale/en/LC_MESSAGES/default.po index 8ca1348b..9f869a02 100644 --- a/out/locale/en/LC_MESSAGES/default.po +++ b/out/locale/en/LC_MESSAGES/default.po @@ -6325,3 +6325,9 @@ msgstr "Go to tab 5" msgid "Reached maximum number of result tabs (%d). To display more results, increase setting in Preferences > SQL" msgstr "Reached maximum number of result tabs (%d). To display more results, increase setting in Preferences > SQL" + +msgid "Does not work on Windows 10 S" +msgstr "Does not work on Windows 10 S" + +msgid "The network type defined for this session is not compatible to your Windows 10 S" +msgstr "The network type defined for this session is not compatible to your Windows 10 S" diff --git a/source/apphelpers.pas b/source/apphelpers.pas index 7f2c161b..b9ebab75 100644 --- a/source/apphelpers.pas +++ b/source/apphelpers.pas @@ -338,7 +338,8 @@ type procedure Help(Sender: TObject; Anchor: String); function PortOpen(Port: Word): Boolean; function IsValidFilePath(FilePath: String): Boolean; - + function GetProductInfo(dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion, dwSpMinorVersion: DWORD; out pdwReturnedProductType: DWORD): BOOL stdcall; external kernel32 delayed; + function RunningOnWindows10S: Boolean; var AppSettings: TAppSettings; @@ -2834,6 +2835,22 @@ begin end; +function RunningOnWindows10S: Boolean; +const + PRODUCT_CLOUD = $000000B2; //* Windows 10 S + PRODUCT_CLOUDN = $000000B3; //* Windows 10 S N + PRODUCT_CORE = $00000065; //* Windows 10 Home +var + pdwReturnedProductType: DWORD; +begin + // Detect if we're running on Windows 10 S + // Taken from https://forums.embarcadero.com/message.jspa?messageID=900804 + Result := False; + if GetProductInfo(10, 10, 0, 0, pdwReturnedProductType) then begin + Result := (pdwReturnedProductType = PRODUCT_CLOUD) OR (pdwReturnedProductType = PRODUCT_CLOUDN); + end; +end; + { Threading stuff } diff --git a/source/connections.pas b/source/connections.pas index 415c6a37..8a992125 100644 --- a/source/connections.pas +++ b/source/connections.pas @@ -214,7 +214,7 @@ end; procedure Tconnform.FormCreate(Sender: TObject); var - LastActiveSession: String; + LastActiveSession, NetTypeStr: String; LastSessions: TStringList; PSess: PConnectionParameters; nt: TNetType; @@ -244,8 +244,13 @@ begin comboNetType.Clear; Params := TConnectionParameters.Create; - for nt:=Low(nt) to High(nt) do - comboNetType.Items.Add(Params.NetTypeName(nt, True)); + for nt:=Low(nt) to High(nt) do begin + NetTypeStr := Params.NetTypeName(nt, True); + if RunningOnWindows10S and (not Params.IsCompatibleToWin10S(nt)) then begin + NetTypeStr := NetTypeStr + ' ['+_('Does not work on Windows 10 S')+']'; + end; + comboNetType.Items.Add(NetTypeStr); + end; Params.Free; // Init sessions tree diff --git a/source/dbconnection.pas b/source/dbconnection.pas index f94eb5a6..302a5144 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -221,6 +221,7 @@ type function CreateConnection(AOwner: TComponent): TDBConnection; function CreateQuery(AOwner: TComponent): TDBQuery; function NetTypeName(NetType: TNetType; LongFormat: Boolean): String; + class function IsCompatibleToWin10S(NetType: TNetType): Boolean; function GetNetTypeGroup: TNetTypeGroup; function IsMySQL: Boolean; function IsMSSQL: Boolean; @@ -1277,6 +1278,13 @@ begin end; +class function TConnectionParameters.IsCompatibleToWin10S(NetType: TNetType): Boolean; +begin + // Using plink on 10S is not possible + Result := NetType <> ntMySQL_SSHtunnel; +end; + + function TConnectionParameters.GetNetTypeGroup: TNetTypeGroup; begin case FNetType of @@ -1622,6 +1630,12 @@ var PasswordChangeDialog: TfrmPasswordChange; begin if Value and (FHandle = nil) then begin + + // Die if trying to run plink on Win10S + if RunningOnWindows10S and (not FParameters.IsCompatibleToWin10S(FParameters.NetType)) then begin + raise EDatabaseError.Create(_('The network type defined for this session is not compatible to your Windows 10 S')); + end; + DoBeforeConnect; // Get handle