Skip to content

Commit

Permalink
updater: fix redirection
Browse files Browse the repository at this point in the history
this should fix multiple redirection
  • Loading branch information
riderkick committed May 9, 2015
1 parent e9440c3 commit da9ace7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
33 changes: 17 additions & 16 deletions updater/uMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -390,20 +390,24 @@ procedure TDownloadThread.Execute;
end;

var
regx :TRegExpr;
i, ctry :Integer;
regx : TRegExpr;
i, ctry : Cardinal;
Sza,
rurl,
fname,
sproject,
sdir,
sfile :String;
st :TStringList;
sfile : String;
st, HTTPHeaders: TStringList;

begin
URL := Trim(URL);
HTTPHeaders := TStringList.Create;
regx := TRegExpr.Create;
try
PrepareHTTP(FHTTP);
FHTTP.Headers.NameValueSeparator := ':';
HTTPHeaders.NameValueSeparator := ':';
regx.ModifierI := True;
if isSFURL then
begin
Expand Down Expand Up @@ -439,11 +443,12 @@ procedure TDownloadThread.Execute;
FileName := 'new_version.7z';
end;

FHTTP.Headers.Text := HTTPHeaders.Text;
//**loading page
UpdateStatus(RS_LoadingPage);
ctry := 0;
while (not FHTTP.HTTPMethod('HEAD', rurl)) or
(FHTTP.ResultCode >= 300) or (FHTTP.ResultCode < 100) do
(FHTTP.ResultCode >= 400) or (FHTTP.ResultCode < 100) do
begin
if Self.Terminated then Break;
if (FHTTP.ResultCode >= 500) or (FHTTP.ResultCode < 100) then
Expand Down Expand Up @@ -473,21 +478,15 @@ procedure TDownloadThread.Execute;
ShowErrorMessage(Format(RS_FileNotFound_mfdatalink, [mf_data_link]));
end;
Break;
end
else
if FHTTP.ResultCode >= 300 then
begin
UpdateStatus(RS_Redirected);
FHTTP.Headers.Add('Referer: ' + rurl);
rurl := HeaderByName(FHTTP.Headers, 'location: ');
end;
FHTTP.Clear;
end;

if (FHTTP.ResultCode >= 300) or isSFURL then
begin
HTTPHeaders.Values['Referer'] := ' ' + rurl;
UpdateStatus(RS_Redirected);
rurl := HeaderByName(FHTTP.Headers, 'location: ');
rurl := Trim(FHTTP.Headers.Values['Location']);
if isSFURL then
begin
if (Pos('use_mirror=', rurl) > 0) then
Expand All @@ -504,10 +503,10 @@ procedure TDownloadThread.Execute;
UpdateStatus(Format(RS_Downloading, [FileName]));
if (FHTTP.ResultCode >= 100) and (FHTTP.ResultCode < 400) then
begin
HTTPHeaders.Values['Accept'] := ' */*';
ctry := 0;
FHTTP.Clear;
FHTTP.Headers.Add('Accept: */*');
FHTTP.Headers.Add('Referer: ' + URL);
FHTTP.Headers.Text := HTTPHeaders.Text;
while (not FHTTP.HTTPMethod('GET', rurl)) or
(FHTTP.ResultCode >= 300) do
begin
Expand Down Expand Up @@ -543,10 +542,11 @@ procedure TDownloadThread.Execute;
else
if FHTTP.ResultCode >= 300 then
begin
FHTTP.Headers.Add('Referer: ' + rurl);
HTTPHeaders.Values['Referer'] := ' ' + rurl;
rurl := HeaderByName(FHTTP.Headers, 'location: ');
end;
FHTTP.Clear;
FHTTP.Headers.Text := HTTPHeaders.Text;
end;
end;

Expand Down Expand Up @@ -629,6 +629,7 @@ procedure TDownloadThread.Execute;
frmMain.ExceptionHandler(Self, E);
end;
regx.Free;
HTTPHeaders.Free;
end;

{ TfrmMain }
Expand Down
2 changes: 1 addition & 1 deletion updater/updater.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<UseVersionInfo Value="True"/>
<MajorVersionNr Value="2"/>
<MinorVersionNr Value="1"/>
<RevisionNr Value="2"/>
<RevisionNr Value="3"/>
<Attributes pvaPrivateBuild="True"/>
<StringTable FileDescription="Updater for Free Manga Downloader" LegalCopyright="©2015 FMD Project Team" OriginalFilename="updater.exe" ProductName="Updater" ProductVersion="$BuildMode()" PrivateBuild="Cholif"/>
</VersionInfo>
Expand Down

0 comments on commit da9ace7

Please sign in to comment.