| 1 |
{ |
| 2 |
Double Commander |
| 3 |
------------------------------------------------------------------------- |
| 4 |
BitTorrent archiver plugin |
| 5 |
|
| 6 |
Copyright (C) 2017 Alexander Koblov ([email protected]) |
| 7 |
|
| 8 |
This library is free software; you can redistribute it and/or |
| 9 |
modify it under the terms of the GNU Lesser General Public |
| 10 |
License as published by the Free Software Foundation; either |
| 11 |
version 2.1 of the License, or (at your option) any later version. |
| 12 |
|
| 13 |
This library is distributed in the hope that it will be useful, |
| 14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
Lesser General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU Lesser General Public License |
| 19 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
} |
| 21 |
|
| 22 |
library torrent; |
| 23 |
|
| 24 |
{$mode delphi} |
| 25 |
{$include calling.inc} |
| 26 |
|
| 27 |
uses |
| 28 |
{$IFDEF UNIX} |
| 29 |
cthreads, |
| 30 |
{$ENDIF} |
| 31 |
FPCAdds, |
| 32 |
Classes, SysUtils, TorrentFile, WcxPlugin, DCDateTimeUtils, DCClassesUtf8, |
| 33 |
DCConvertEncoding; |
| 34 |
|
| 35 |
type |
| 36 |
PTorrentHandle = ^TTorrentHandle; |
| 37 |
TTorrentHandle = record |
| 38 |
Index: Integer; |
| 39 |
Torrent: TTorrentFile; |
| 40 |
end; |
| 41 |
|
| 42 |
function OpenArchive(var ArchiveData : tOpenArchiveData) : TArcHandle; dcpcall; |
| 43 |
begin |
| 44 |
Result := 0; |
| 45 |
ArchiveData.OpenResult := E_NOT_SUPPORTED; |
| 46 |
end; |
| 47 |
|
| 48 |
function OpenArchiveW(var ArchiveData : tOpenArchiveDataW) : TArcHandle; dcpcall; |
| 49 |
var |
| 50 |
AFileName: String; |
| 51 |
AStream: TFileStreamEx; |
| 52 |
AHandle: PTorrentHandle = nil; |
| 53 |
begin |
| 54 |
Result:= 0; |
| 55 |
if ArchiveData.OpenMode = PK_OM_EXTRACT then |
| 56 |
begin |
| 57 |
ArchiveData.OpenResult:= E_NOT_SUPPORTED; |
| 58 |
Exit; |
| 59 |
end; |
| 60 |
try |
| 61 |
AFileName := CeUtf16ToUtf8(UnicodeString(ArchiveData.ArcName)); |
| 62 |
AStream:= TFileStreamEx.Create(AFileName, fmOpenRead or fmShareDenyNone); |
| 63 |
try |
| 64 |
New(AHandle); |
| 65 |
AHandle.Index:= 0; |
| 66 |
AHandle.Torrent:= TTorrentFile.Create; |
| 67 |
if not AHandle.Torrent.Load(AStream) then |
| 68 |
raise Exception.Create(EmptyStr); |
| 69 |
Result:= TArcHandle(AHandle); |
| 70 |
finally |
| 71 |
AStream.Free; |
| 72 |
end; |
| 73 |
except |
| 74 |
ArchiveData.OpenResult:= E_EOPEN; |
| 75 |
if Assigned(AHandle) then |
| 76 |
begin |
| 77 |
AHandle.Torrent.Free; |
| 78 |
Dispose(AHandle); |
| 79 |
end; |
| 80 |
end; |
| 81 |
end; |
| 82 |
|
| 83 |
function ReadHeader(hArcData : TArcHandle; var HeaderData: THeaderData) : Integer; dcpcall; |
| 84 |
begin |
| 85 |
Result := E_NOT_SUPPORTED; |
| 86 |
end; |
| 87 |
|
| 88 |
function ReadHeaderExW(hArcData : TArcHandle; var HeaderData: THeaderDataExW) : Integer; dcpcall; |
| 89 |
var |
| 90 |
AFile: TTorrentSubFile; |
| 91 |
AHandle: PTorrentHandle absolute hArcData; |
| 92 |
begin |
| 93 |
if AHandle.Index >= AHandle.Torrent.Files.Count then Exit(E_END_ARCHIVE); |
| 94 |
|
| 95 |
AFile:= TTorrentSubFile(AHandle.Torrent.Files[AHandle.Index]); |
| 96 |
HeaderData.FileTime:= UnixFileTimeToWcxTime(AHandle.Torrent.CreationTime); |
| 97 |
HeaderData.FileName:= CeUtf8ToUtf16(AFile.Path + AFile.Name); |
| 98 |
HeaderData.UnpSize:= Int64Rec(AFile.Length).Lo; |
| 99 |
HeaderData.UnpSizeHigh:= Int64Rec(AFile.Length).Hi; |
| 100 |
HeaderData.PackSize:= HeaderData.UnpSize; |
| 101 |
HeaderData.PackSizeHigh:= HeaderData.UnpSizeHigh; |
| 102 |
Result:= E_SUCCESS; |
| 103 |
end; |
| 104 |
|
| 105 |
function ProcessFile(hArcData : TArcHandle; Operation : Integer; DestPath, DestName : PChar) : Integer; dcpcall; |
| 106 |
begin |
| 107 |
Result := E_NOT_SUPPORTED; |
| 108 |
end; |
| 109 |
|
| 110 |
function ProcessFileW(hArcData : TArcHandle; Operation : Integer; DestPath, DestName : PWideChar) : Integer; dcpcall; |
| 111 |
var |
| 112 |
AHandle: PTorrentHandle absolute hArcData; |
| 113 |
begin |
| 114 |
Inc(AHandle.Index); |
| 115 |
Result:= E_SUCCESS; |
| 116 |
end; |
| 117 |
|
| 118 |
function CloseArchive (hArcData : TArcHandle) : Integer; dcpcall; |
| 119 |
var |
| 120 |
AHandle: PTorrentHandle absolute hArcData; |
| 121 |
begin |
| 122 |
if hArcData <> wcxInvalidHandle then |
| 123 |
begin |
| 124 |
AHandle.Torrent.Free; |
| 125 |
Dispose(AHandle); |
| 126 |
end; |
| 127 |
Result:= E_SUCCESS; |
| 128 |
end; |
| 129 |
|
| 130 |
procedure SetChangeVolProc (hArcData : TArcHandle; pChangeVolProc : TChangeVolProc); dcpcall; |
| 131 |
begin |
| 132 |
|
| 133 |
end; |
| 134 |
|
| 135 |
procedure SetProcessDataProc (hArcData : TArcHandle; pProcessDataProc : TProcessDataProc); dcpcall; |
| 136 |
begin |
| 137 |
|
| 138 |
end; |
| 139 |
|
| 140 |
function GetPackerCaps : Integer;dcpcall; |
| 141 |
begin |
| 142 |
Result := PK_CAPS_MULTIPLE or PK_CAPS_HIDE; |
| 143 |
end; |
| 144 |
|
| 145 |
exports |
| 146 |
OpenArchive, |
| 147 |
OpenArchiveW, |
| 148 |
ReadHeader, |
| 149 |
ReadHeaderExW, |
| 150 |
ProcessFile, |
| 151 |
ProcessFileW, |
| 152 |
CloseArchive, |
| 153 |
SetChangeVolProc, |
| 154 |
SetProcessDataProc, |
| 155 |
GetPackerCaps; |
| 156 |
|
| 157 |
end. |
| 158 |
|