Skip to content

Commit

Permalink
Add Magnet Link by Hash Only #1090
Browse files Browse the repository at this point in the history
Added the possiblity of add a magnet only by the hash.
  • Loading branch information
antekgla committed Mar 10, 2018
1 parent 6e19127 commit 6e5cb4c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,21 @@ function WndCallback(Ahwnd: HWND; uMsg: UINT; wParam: WParam; lParam: LParam):LR

{$endif windows}

function IsHash(Hash: String): boolean;
var i: integer;
begin
if Hash = '' then exit;
if Length(Hash) = 32 then // possible base32 encoded hash
try
Hash:=StrToHex(Base32Decode(UpperCase(Hash)));
except
exit;
end;
if Length(Hash) <> 40 then exit;
Result := true;
for i := 1 to 40 do if not (Hash[i] in ['a' .. 'f', 'A'..'F', '0'..'9']) then Result := false;
end;

procedure TMainForm.ReadLocalFolderWatch;
var
sr: TSearchRec;
Expand Down Expand Up @@ -2213,7 +2228,10 @@ procedure TMainForm.acAddLinkExecute(Sender: TObject);
try
AppNormal;
if ShowModal = mrOk then
DoAddTorrent(edLink.Text);
begin
if isHash(edLink.Text) then edLink.Text := 'magnet:?xt=urn:btih:'+ edLink.Text;
DoAddTorrent(edLink.Text);
end;
finally
Free;
end;
Expand Down Expand Up @@ -7608,6 +7626,7 @@ procedure TMainForm.CheckClipboardLink;
if s = FLastClipboardLink then
exit;
FLastClipboardLink:=s;
if isHash(s) then s := 'magnet:?xt=urn:btih:' + s;
if not IsProtocolSupported(s) then
exit;
if (Pos('magnet:', LazUTF8.UTF8LowerCase(s)) <> 1) and (LazUTF8.UTF8LowerCase(Copy(s, Length(s) - Length(strTorrentExt) + 1, MaxInt)) <> strTorrentExt) then
Expand Down

0 comments on commit 6e5cb4c

Please sign in to comment.