From d7dc233fb0f288aa0bce110f3b3834664623711f Mon Sep 17 00:00:00 2001 From: bgermann Date: Mon, 6 Aug 2018 11:55:27 +0200 Subject: [PATCH 1/2] Replace wget with HttpClient [DEVELOPMENT ENVIRONMENT] * OPT: Replace wget with HttpClient to download documentation --- app/src/gambas3/.src/Help/MHelp.module | 15 ++++++--- app/src/gambas3/.src/Options/FOption.class | 36 +++++++++------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/app/src/gambas3/.src/Help/MHelp.module b/app/src/gambas3/.src/Help/MHelp.module index d3a418bcf..245470cc3 100644 --- a/app/src/gambas3/.src/Help/MHelp.module +++ b/app/src/gambas3/.src/Help/MHelp.module @@ -12,7 +12,7 @@ Public Const TYPE_SPECIAL As Integer = 6 Public Const TYPE_COMPONENT As Integer = 7 Public Const TYPE_FILE As Integer = 8 -Public Enum OFFLINE_NO_NETWORK, OFFLINE_NOT_AVAILABLE, OFFLINE_UP_TO_DATE, OFFLINE_NEW_AVAILABLE, OFFLINE_NO_WGET +Public Enum OFFLINE_NO_NETWORK, OFFLINE_NOT_AVAILABLE, OFFLINE_UP_TO_DATE, OFFLINE_NEW_AVAILABLE Public $PopupHelpCache As Collection @@ -860,17 +860,24 @@ End Public Sub GetOfflineState() As Integer + Dim hClient As HttpClient Dim sTimestamp As String Dim sDir As String Dim sDate As String If Not Desktop.NetworkAvailable Then Return OFFLINE_NO_NETWORK - - If Not System.Exist("wget") Then Return OFFLINE_NO_WGET Inc Application.Busy - Exec ["wget", "-q", "-O", "-", "http://gambaswiki.org/timestamp"] To sTimestamp + hClient = New HttpClient As "hClient" + hClient.Async = False + hClient.Timeout = 20 + + hClient.URL = "http://gambaswiki.org/timestamp" + hClient.Get + If hClient.Status >= 0 Then + If Lof(hClient) Then sTimestamp = Read #hClient, Lof(hClient) + End If Dec Application.Busy diff --git a/app/src/gambas3/.src/Options/FOption.class b/app/src/gambas3/.src/Options/FOption.class index 7950e71ee..eef373dd9 100644 --- a/app/src/gambas3/.src/Options/FOption.class +++ b/app/src/gambas3/.src/Options/FOption.class @@ -1175,6 +1175,8 @@ End Public Sub btnDownloadHelp_Click() + Dim hClient As HttpClient + Dim sHeaders As New String[0] Dim sMsg As String Dim sFile As String Dim sDir As String @@ -1183,22 +1185,9 @@ Public Sub btnDownloadHelp_Click() Inc Application.Busy - sMsg = Project.RequireProgram(["wget", "tar"]) + sMsg = Project.RequireProgram(["tar"]) If sMsg Then Goto FAIL - ' Exec ["wget", "-q", "-O", "-", "http://gambaswiki.org/timestamp"] To sTimestamp - ' sTimestamp = Trim(sTimestamp) - ' If Not sTimestamp Then - ' sMsg = ("The documentation is not available at the moment. Try again later.") - ' Goto FAIL - ' Endif - ' - ' Try dDate = Stat(MHelp.GetOfflineDir()).LastModified - ' If dDate And If Format(dDate, "yyyymmdd") >= sTimestamp Then - ' sMsg = ("The documentation is up to date.") - ' Goto FAIL - ' Endif - sDir = MHelp.GetOfflineDir() sParentDir = File.Dir(sDir) @@ -1206,9 +1195,19 @@ Public Sub btnDownloadHelp_Click() sFile = sParentDir &/ "wiki.tar.bz2" Try Kill sFile - Exec ["wget", "-q", "-O", "-", "http://gambaswiki.org/timestamp"] To sTimestamp + hClient = New HttpClient As "hClient" + hClient.Async = False + hClient.Timeout = 20 + + hClient.URL = "http://gambaswiki.org/timestamp" + hClient.Get + If hClient.Status >= 0 Then + If Lof(hClient) Then sTimestamp = Read #hClient, Lof(hClient) + End If - Exec ["wget", "-q", "-O", sFile, "http://gambaswiki.org/gambas-wiki.tar.bz2"] Wait + hClient.URL = "http://gambaswiki.org/gambas-wiki.tar.bz2" + hClient.Get(sHeaders, sFile) + If Not Exist(sFile) Then sMsg = ("Unable to download documentation.") Goto FAIL @@ -1263,11 +1262,6 @@ Private Sub UpdateDocumentationState() lblDocumentation.Foreground = Color.Foreground btnDownloadHelp.Enabled = False - Case MHelp.OFFLINE_NO_WGET - lblDocumentation.Text = ("'wget' is not found.") - lblDocumentation.Foreground = Color.Foreground - btnDownloadHelp.Enabled = False - Case MHelp.OFFLINE_NEW_AVAILABLE lblDocumentation.Text = ("A new documentation is available!") lblDocumentation.Foreground = Color.Red From 574a8a7f514831134109bf13221027dda332187b Mon Sep 17 00:00:00 2001 From: bgermann Date: Fri, 10 Aug 2018 11:59:13 +0200 Subject: [PATCH 2/2] Use HttpClient.Download for timestamp download --- app/src/gambas3/.src/Help/MHelp.module | 13 +------------ app/src/gambas3/.src/Options/FOption.class | 12 +++--------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/app/src/gambas3/.src/Help/MHelp.module b/app/src/gambas3/.src/Help/MHelp.module index 245470cc3..3e1c72c84 100644 --- a/app/src/gambas3/.src/Help/MHelp.module +++ b/app/src/gambas3/.src/Help/MHelp.module @@ -860,7 +860,6 @@ End Public Sub GetOfflineState() As Integer - Dim hClient As HttpClient Dim sTimestamp As String Dim sDir As String Dim sDate As String @@ -868,17 +867,7 @@ Public Sub GetOfflineState() As Integer If Not Desktop.NetworkAvailable Then Return OFFLINE_NO_NETWORK Inc Application.Busy - - hClient = New HttpClient As "hClient" - hClient.Async = False - hClient.Timeout = 20 - - hClient.URL = "http://gambaswiki.org/timestamp" - hClient.Get - If hClient.Status >= 0 Then - If Lof(hClient) Then sTimestamp = Read #hClient, Lof(hClient) - End If - + sTimestamp = HttpClient.Download("http://gambaswiki.org/timestamp") Dec Application.Busy sTimestamp = Trim(sTimestamp) diff --git a/app/src/gambas3/.src/Options/FOption.class b/app/src/gambas3/.src/Options/FOption.class index eef373dd9..200981bc3 100644 --- a/app/src/gambas3/.src/Options/FOption.class +++ b/app/src/gambas3/.src/Options/FOption.class @@ -1176,7 +1176,6 @@ End Public Sub btnDownloadHelp_Click() Dim hClient As HttpClient - Dim sHeaders As New String[0] Dim sMsg As String Dim sFile As String Dim sDir As String @@ -1195,18 +1194,13 @@ Public Sub btnDownloadHelp_Click() sFile = sParentDir &/ "wiki.tar.bz2" Try Kill sFile + sTimestamp = HttpClient.Download("http://gambaswiki.org/timestamp") + hClient = New HttpClient As "hClient" hClient.Async = False hClient.Timeout = 20 - - hClient.URL = "http://gambaswiki.org/timestamp" - hClient.Get - If hClient.Status >= 0 Then - If Lof(hClient) Then sTimestamp = Read #hClient, Lof(hClient) - End If - hClient.URL = "http://gambaswiki.org/gambas-wiki.tar.bz2" - hClient.Get(sHeaders, sFile) + hClient.Get([], sFile) If Not Exist(sFile) Then sMsg = ("Unable to download documentation.")