fix #21 - update checker needs to be updated to use gitlab api

This commit is contained in:
Basile Burg 2020-04-07 23:22:34 +02:00
parent 7e5ffba6e7
commit 088ca3cb99
2 changed files with 24 additions and 14 deletions

View File

@ -2007,11 +2007,12 @@ end;
function checkForUpdate: string;
const
updURL = 'https://api.github.com/repos/Basile-z/dexed/releases/latest';
updURL = 'https://gitlab.com/api/v4/projects/15908229/repository/tags';
var
arr: TJSONArray = nil;
dat: TJSONData = nil;
tgg: TJSONData = nil;
url: TJSONData = nil;
url: string;
str: string = '';
lst: TStringList = nil;
res: TResourceStream = nil;
@ -2019,13 +2020,18 @@ var
sva: TSemVer;
begin
result := '';
if simpleGet(updURL, dat) then
if simpleGet(updURL, dat) and (dat.JSONType = jtArray) then
begin
try
url := dat.FindPath('html_url');
tgg := dat.FindPath('tag_name');
if url.isNotNil and tgg.isNotNil then
arr := TJSONArray(dat);
if (arr.Count > 0) and (arr.Items[0].JSONType = jtObject) then
begin
dat := arr.Objects[0];
tgg := dat.FindPath('name');
end;
if tgg.isNotNil then
begin
url := 'https://gitlab.com/basile.b/dexed/-/releases/' + tgg.AsString;
res:= TResourceStream.Create(HINSTANCE, 'VERSION', RT_RCDATA);
lst := TstringList.Create;
lst.LoadFromStream(res);
@ -2034,7 +2040,7 @@ begin
str := tgg.AsString;
svo.init(str, false);
if svo.valid and sva.valid and (svo > sva) then
result := url.AsString
result := url
else
dlgOkInfo('No new release available');
end;

View File

@ -5,11 +5,15 @@ unit u_simpleget;
interface
uses
classes, {$ifdef posix}libcurl,{$else} fphttpclient,{$endif} fpjson, jsonparser, jsonscanner;
classes, {$ifdef UNIX}libcurl,{$else} fphttpclient,{$endif} fpjson, jsonparser, jsonscanner;
type
PStream = ^TStream;
{$ifdef VER3_2_0}
{$Warning 'workarounds to avoid SSL context errors may be unecessary starting from FCL 3.2.0'}
{$endif}
// Get the content of 'url' in the string 'data'
function simpleGet(url: string; var data: string): boolean; overload;
// Get the content of 'url' in the stream 'data'
@ -25,7 +29,7 @@ const
implementation
{$ifdef posix}
{$ifdef UNIX}
var
fCurlHandle: CURL = nil;
@ -62,13 +66,13 @@ end;
{$endif}
function simpleGet(url: string; var data: string): boolean; overload;
{$ifdef posix}
{$ifdef UNIX}
var
c: CURLcode;
h: CURL;
{$endif}
begin
{$ifdef posix}
{$ifdef UNIX}
h := curlHandle();
if not assigned(h) then
exit(false);
@ -103,13 +107,13 @@ begin
end;
function simpleGet(url: string; data: TStream): boolean; overload;
{$ifdef posix}
{$ifdef UNIX}
var
c: CURLcode;
h: CURL;
{$endif}
begin
{$ifdef posix}
{$ifdef UNIX}
h := curlHandle();
if not assigned(h) then
exit(false);
@ -163,7 +167,7 @@ begin
end;
finalization
{$ifdef posix}
{$ifdef UNIX}
if assigned(fCurlHandle) then
curl_easy_cleanup(fCurlHandle);
{$endif}