close #206, use CURL ti check for updates until SSL 1.1 supported

This commit is contained in:
Basile Burg 2017-12-06 21:36:39 +01:00
parent 993a31575e
commit 6a20a54f06
1 changed files with 56 additions and 28 deletions

View File

@ -618,7 +618,7 @@ implementation
{$R *.lfm} {$R *.lfm}
uses uses
SynMacroRecorder, ce_dcd; SynMacroRecorder, ce_dcd, openssl, dynlibs;
{$REGION TCERunnableOptions ----------------------------------------------------} {$REGION TCERunnableOptions ----------------------------------------------------}
constructor TCERunnableOptions.create(aOwner: TComponent); constructor TCERunnableOptions.create(aOwner: TComponent);
@ -1755,53 +1755,81 @@ begin
end; end;
function checkForUpdate: string; function checkForUpdate: string;
const
updURL = 'https://api.github.com/repos/BBasile/Coedit/releases/latest';
var var
prs: TJSONParser = nil; prs: TJSONParser = nil;
dat: TJSONData = nil; dat: TJSONData = nil;
tgg: TJSONData = nil; tgg: TJSONData = nil;
url: TJSONData = nil; url: TJSONData = nil;
str: string; str: string = '';
cli: TFPHTTPClient; cli: TFPHTTPClient = nil;
lst: TStringList = nil; lst: TStringList = nil;
res: TResourceStream = nil; res: TResourceStream = nil;
svo: TSemVer; svo: TSemVer;
sva: TSemVer; sva: TSemVer;
begin begin
result := ''; result := '';
cli := TFPHTTPClient.Create(nil);
try if openssl.IsSSLloaded then
begin
try try
cli.AddHeader('User-Agent','Mozilla/5.0 (compatible; fpweb)'); cli := TFPHTTPClient.Create(nil);
str := cli.Get('https://api.github.com/repos/BBasile/Coedit/releases/latest'); try
prs := TJSONParser.Create(str, [joUTF8, joIgnoreTrailingComma]); cli.AllowRedirect:=true;
dat := prs.Parse; cli.AddHeader('User-Agent','Mozilla/5.0 (compatible; fpweb)');
if dat.isNotNil then str := cli.Get(updURL);
begin finally
url := dat.FindPath('html_url'); cli.free;
tgg := dat.FindPath('tag_name');
if url.isNotNil and tgg.isNotNil then
begin
res:= TResourceStream.Create(HINSTANCE, 'VERSION', RT_RCDATA);
lst := TstringList.Create;
lst.LoadFromStream(res);
str := lst.Text;
sva.init(str, false);
str := tgg.AsString;
svo.init(str, false);
if svo.valid and sva.valid and (svo > sva) then
result := url.AsString;
end;
end; end;
except except
dlgOkError('The latest release cannot be determined'); dlgOkError('The latest release cannot be determined (HTTP client)');
end;
end
else if not openssl.IsSSLloaded and exeFullName('curl').isNotEmpty then
begin
if not process.RunCommand('curl', [updURL], str) then
begin
dlgOkError('The latest release cannot be determined (CURL)');
exit;
end
end
else
begin
dlgOkInfo('No suitable tool can be used to determine the latest version.' +
'Install at least CURL as a command line tool, visible in the PATH.' +
'Newest OpenSSL versions (>= 1.1) are currently not supported');
exit;
end;
prs := TJSONParser.Create(str, [joUTF8, joIgnoreTrailingComma]);
try
dat := prs.Parse;
if dat.isNotNil then
begin
url := dat.FindPath('html_url');
tgg := dat.FindPath('tag_name');
if url.isNotNil and tgg.isNotNil and (tgg.AsString <> '3_update_5') then
begin
res:= TResourceStream.Create(HINSTANCE, 'VERSION', RT_RCDATA);
lst := TstringList.Create;
lst.LoadFromStream(res);
str := lst.Text;
sva.init(str, false);
str := tgg.AsString;
svo.init(str, false);
if svo.valid and sva.valid and (svo > sva) then
result := url.AsString;
end;
end; end;
finally finally
cli.free; prs.Free;
prs.free;
dat.free; dat.free;
lst.free; lst.free;
res.free; res.free;
end; end;
end; end;
procedure TCEMainForm.DoFirstShow; procedure TCEMainForm.DoFirstShow;