Fixed sourceforge download problems

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5325 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
gbamber
2016-11-08 12:33:29 +00:00
parent 30626980e7
commit 3d9a5c0e95

View File

@@ -42,10 +42,12 @@ uses
VersionSupport, inifiles, aboutlazautoupdateunit, uappisrunning, LCLProc;
const
// C_OnlineAppPath =
// 'https://downloads.sourceforge.net/project/%s/files/%s/%s/download';
C_OnlineAppPath =
'http://sourceforge.net/projects/%s/files/%s/%s/download';
'http://downloads.sourceforge.net/project/%s/%s/%s';
// [updatepath,projectname,filename]
C_TLazAutoUpdateComponentVersion = '0.1.27';
C_TLazAutoUpdateComponentVersion = '0.1.28';
C_LAUTRayINI = 'lauimport.ini';
{
@@ -95,7 +97,8 @@ const
V0.1.24:Bugfix to CreateLocalLauImportFile
More checks on PrettyName
V0.1.25:Changed default: CopyTree = TRUE
V0.1.26:??
V0.1.26:Updated uses clause for FileUtils.
V0.1.27: ??
}
C_TThreadedDownloadComponentVersion = '0.0.2';
{
@@ -179,7 +182,7 @@ type
OnlineVersion: string) of object;
TOnDownloaded = procedure(Sender: TObject; ResultCode, BytesDownloaded: integer) of
object;
TOnDebugEvent = procedure(Sender: TObject; MethodName, Message: string) of object;
TOnDebugEvent = procedure(Sender: TObject; lauMethodName, lauMessage: string) of object;
TLazAutoUpdate = class(TAboutLazAutoUpdate)
private
@@ -842,9 +845,17 @@ begin
szURL := Format(C_OnlineAppPath, [fSourceForgeProjectName,
fUpdatesFolder, fVersionsININame]);
if fFireDebugEvent then
fOndebugEvent(Self, 'NewVersionAvailable',
Format('SourceForgeURL is %s', [szURL]));
szTargetPath := AppendPathDelim(ExtractFilePath(fAppFilename)) +
Format(C_TempVersionsININame, [fVersionsININame]);
if fFireDebugEvent then
fOndebugEvent(Self, 'NewVersionAvailable',
Format('Target Path %s', [szTargetPath]));
if fProjectType = auOther then
// fauOtherSourceURL ends with '/'
begin
@@ -863,7 +874,7 @@ begin
except
if fFireDebugEvent then
fOndebugEvent(Self, 'NewVersionAvailable',
Format('Faile to delete old file %s', [szTargetPath]));
Format('Failed to delete old file %s', [szTargetPath]));
// No error if the delete can't be done
end;
with fThreadDownload do
@@ -881,6 +892,13 @@ begin
fParentForm.Caption := C_Checking;
// Start the thread
ThreadDownloadHTTP;
if fFireDebugEvent then
fOndebugEvent(Self, 'NewVersionAvailable',
Format('ThreadDownloadHTTP return Code was %d', [fReturnCode]));
if fFireDebugEvent then
fOndebugEvent(Self, 'NewVersionAvailable',
Format('ThreadDownloadHTTP Last Error was %s', [fLastError]));
cCount := 0;
// Update the GUI during the thread
try
@@ -920,6 +938,9 @@ begin
C_ThreadDownloadCrash);
Exit;
end;
if fFireDebugEvent then
fOndebugEvent(Self, 'NewVersionAvailable',
Format('After Threadfinished: Return Code was %d', [fReturnCode]));
Sleep(1);
fDownloadInprogress := False;
if fDownloadSize > 0 then
@@ -932,7 +953,12 @@ begin
if fFireDebugEvent then
fOndebugEvent(Self, 'NewVersionAvailable',
Format(C_DownloadedBytes, [szTargetPath, fDownloadSize]));
end;
end
else
if fFireDebugEvent then
fOndebugEvent(Self, 'NewVersionAvailable',
Format('DownloadSize was %d', [fDownloadSize]));
end;
end;
if not fSilentMode then
@@ -1897,10 +1923,10 @@ const
Refresh = '<meta http-equiv="refresh"';
URLMarker = 'url=';
var
Counter: integer;
HTMLBody: TStringList;
RefreshStart: integer;
URLStart: integer;
Counter : integer;
HTMLBody : TStringList;
RefreshStart : integer;
URLStart : integer;
begin
HTMLBody := TStringList.Create;
try
@@ -1930,32 +1956,32 @@ begin
end;
function SourceForgeURL(URL: string; fDebugmode: boolean;
var AReturnCode: integer): string;
var AReturnCode: integer): string;
// Detects sourceforge download and tries to deal with
// redirection, and extracting direct download link.
// Thanks to
// Ocye: http://lazarus.freepascal.org/index.php/topic,13425.msg70575.html#msg70575
const
SFProjectPart = '//sourceforge.net/projects/';
SFProjectPart = '//downloads.sourceforge.net/project/';
SFFilesPart = '/files/';
SFDownloadPart = '/download';
var
HTTPSender: THTTPSend;
i, j: integer;
FoundCorrectURL: boolean;
SFDirectory: string; //Sourceforge directory
SFDirectoryBegin: integer;
SFFileBegin: integer;
SFFilename: string; //Sourceforge name of file
SFProject: string;
SFProjectBegin: integer;
HTTPSender : THTTPSend;
i, j : integer;
FoundCorrectURL : boolean;
SFDirectory : string; //Sourceforge directory
SFDirectoryBegin : integer;
SFFileBegin : integer;
SFFilename : string; //Sourceforge name of file
SFProject : string;
SFProjectBegin : integer;
begin
// Detect SourceForge download; e.g. from URL
// 1 2 3 4 5 6 7 8 9
// 1234557890123456789012345578901234567890123455789012345678901234557890123456789012345578901234567890
// http://sourceforge.net/projects/base64decoder/files/base64decoder/version%202.0/b64util.zip/download
// ^^^project^^^ ^^^directory............^^^ ^^^file^^^
FoundCorrectURL := True; //Assume not a SF download
FoundCorrectURL := False; //Assume not a SF download
i := Pos(SFProjectPart, URL);
if i > 0 then
begin
@@ -2002,7 +2028,7 @@ begin
HTTPSender.HTTPMethod('GET', URL);
// SEE: http_ReturnCodes.txt
case HTTPSender.Resultcode of
301, 302, 307:
301, 302, 307: // Redirect
begin
for i := 0 to HTTPSender.Headers.Count - 1 do
if (Pos('Location: ', HTTPSender.Headers.Strings[i]) > 0) or
@@ -2013,7 +2039,7 @@ begin
URL :=
'http://' + RightStr(HTTPSender.Headers.Strings[i],
length(HTTPSender.Headers.Strings[i]) - j - 10) +
'.dl.sourceforge.net/project/' + SFProject +
'.downloads.sourceforge.net/project/' + SFProject +
'/' + SFDirectory + SFFilename
else
URL := StringReplace(HTTPSender.Headers.Strings[i],
@@ -2062,8 +2088,8 @@ begin
Result := URL;
end;
function DownloadHTTP(URL, TargetFile: string;
var ReturnCode, DownloadSize: integer; bIsSourceForge, fDebugmode: boolean): boolean;
function DownloadHTTP(URL, TargetFile: string; var ReturnCode, DownloadSize: integer;
bIsSourceForge, fDebugmode: boolean): boolean;
// Download file; retry if necessary.
// Deals with SourceForge download links
// Could use Synapse HttpGetBinary, but that doesn't deal
@@ -2071,9 +2097,9 @@ function DownloadHTTP(URL, TargetFile: string;
const
MaxRetries = 3;
var
HTTPGetResult: boolean;
HTTPSender: THTTPSend;
RetryAttempt: integer;
HTTPGetResult : boolean;
HTTPSender : THTTPSend;
RetryAttempt : integer;
begin
Result := False;
RetryAttempt := 1;
@@ -2123,8 +2149,7 @@ begin
HTTPSender.Free;
end;
end;
end.