You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

324 lines
10 KiB
Plaintext

library PicIsBigLite;
uses
Classes,
Windows,
plugin,
pluginutil,
CallExec,
SysUtils,
Graphics,
Forms,
StrUtils,
My.EncdDecd,
Vcl.Imaging.GIFImg,
idhttp,
RegularExpressions,
setpassform in 'setpassform.pas' {viewpic},
action in 'action.pas' {actfrm},
sett in 'sett.pas' {setfrm},
Signal in 'Signal.pas' {SForm},
clipfrm in 'clipfrm.pas' {clipform};
{$I NoRTTI.inc}
{$R PicIsBigLite.res}
{$R 'icons.res' 'Icons\icons.rc'}
var
startuin, uino, uini, flagso, flagsi, vApiVersion, currentUIN: Integer;
msgpic, msgpicsmall: AnsiString;
when: TDateTime;
startpic: boolean = false;
curcount, allcount: Integer;
procedure SaveBytesToFile(const Data: TBytes; const FileName: string);
var
stream: TMemoryStream;
begin
stream := TMemoryStream.Create;
try
if length(Data) > 0 then
stream.WriteBuffer(Data[0], length(Data));
stream.SaveToFile(FileName);
finally
stream.Free;
end;
end;
type
TTypeFile = (tfBMP, tfICON, tfJPG, tfGIF, tfTIF, tfPNG, tfWEBP, tfUnknown);
const
THeaderFile: array [0 .. 6, 0 .. 6] of Byte = (
{ BMP } ($42, $4D, 0, 0, 0, 0, 2),
{ ICON } (0, 0, 1, 0, 0, 0, 4),
{ JPG } ($FF, $D8, $FF, 0, 0, 0, 3),
{ GIF } ($47, $49, $46, $38, 0, 0, 4),
{ TIF } ($49, $49, $2A, $00, 0, 0, 4),
{ PNG } ($89, $50, $4E, $47, $0D, $0A, 6),
{ WEBP } ($52, $49, $46, $46, 0, 0, 4));
function CheckTypeFile(P: Pointer): TTypeFile;
var
I: Integer;
begin
Result := tfUnknown;
for I := Low(THeaderFile) to High(THeaderFile) do
if CompareMem(P, @THeaderFile[I], THeaderFile[I][High(THeaderFile[0])]) then
begin
Result := TTypeFile(I);
Break;
end;
end;
function pluginFun(Data: Pointer): Pointer; stdcall;
const Base64MaxLength = 72;
var
rcvfile: string;
ext, msgi, msgo: AnsiString;
msgpicbytes: TBytes;
i: Integer;
extnum: string;
sign: Pointer;
msgtype: TTypeFile;
msgsign: TBytes;
fs: TFileStream;
gif: TGIFImage;
winimg: TWICImage;
begin
Result := NIL;
if (Data = NIL) or (_int_at(Data) = 0) then
exit;
case _byte_at(Data, 4) of
PM_EVENT:
case _byte_at(Data, 5) of
PE_INITIALIZE:
begin
RQ__ParseInitString(Data, callback, vApiVersion, andrqPath, userPath, currentUIN);
ListOfForms := TStringList.Create;
viewpic := TViewPic.Create(application);
actfrm := TFormAct.Create(application);
setfrm := TFormSet.Create(application);
clipform := Tclipform.Create(application);
// picfrm := TPicFrm.create(application);
hico := TIcon.Create;
h0 := TIcon.Create;
h1 := TIcon.Create;
hico.Handle := LoadIcon(HInstance, 'PIC1');
userPath := RQ_GetUserPath;
if userPath[length(userPath)] <> '\' then
userPath := userPath + '\';
CreateDir(userPath + 'Snd');
CreateDir(userPath + 'Rcv');
CreateDir(userPath + 'Scr');
ba := RQ_CreateChatButton(@TViewPic.OnButtonClick, hico.Handle, namepl);
Result := str2comm(AnsiChar(PM_DATA) + _istring(namepl) + _int(APIversion));
end;
PE_FINALIZE:
begin
// if MyTimerEnabled then StopMyTimer;
if ba <> 0 then
RQ_DeleteChatButton(ba);
if hico <> nil then
hico.Free;
viewpic.Free;
actfrm.Free;
setfrm.Free;
// picfrm.free;
end;
PE_MSG_SENT:
begin
RQ__ParseMsgSentString(Data, uino, flagso, msgo);
if pos('', msgo) > 0 then
begin
hico.Handle := LoadIcon(HInstance, 'PIC1');
RQ_ChangeChatButton(ba, hico.Handle, namepl + ': <20><> <20><> <20><>: ' +
extractfilename(viewpic.od.FileName));
if pos('\Scr\', viewpic.od.FileName) = 0 then
CopyFile(PWideChar(viewpic.od.FileName), PWideChar(userPath + 'Snd\' + FormatDateTime('hh.mm.ss_dd-mm-yy',
now) + '_' + IntToStr(uino) + ExtractFileExt(viewpic.od.FileName)), false);
viewpic.LoadSaved;
startsendpic := false;
// if length(msg2disp) < 65536 then
Result := str2comm(char(PM_DATA) + _istring(msgo) + _istring(msg2disp));
// else
// result := str2comm(char(PM_DATA)+_istring(msgo)+_istring('[<5B><> <20><> <20><> <20><> ~ 50<35><30>]'));
end;
if startsendpic = true then
Result := str2comm(char(PM_DATA) + _istring(msgo) + _istring(''));
end;
PE_MSG_GOT:
begin
RQ__ParseMsgGotString(Data, uini, flagsi, when, msgi);
if pos('', msgi) > 1 then
begin
allcount := 0;
curcount := 0;
trystrtoint(copy(msgi, 1, pos('', msgi) - 1), allcount);
msgi := copy(msgi, pos('', msgi), length(msgi));
end;
if pos('', msgi) = 1 then
begin
curcount := 0;
startpic := true;
startuin := uini;
msgpic := '';
msgsign := DecodeBase64(copy(replacestr(replacestr(msgi, '', ''), '', ''), 0, 21));
msgtype := tfJPG;
for I := Low(THeaderFile) to High(THeaderFile) do
if CompareMem(@msgsign[0], @THeaderFile[I], THeaderFile[I][High(THeaderFile[0])]) then
msgtype := TTypeFile(I);
case msgtype of
tfBMP:
extnum := 'BMP';
tfJPG:
extnum := 'JPEG';
tfPNG:
extnum := 'PNG';
tfGIF:
extnum := 'GIF';
tfTIF:
extnum := 'TIF';
tfICON:
extnum := 'ICO';
tfWEBP:
extnum := 'WEBP';
else
extnum := 'JPEG';
end;
if setfrm.checkbox4.Checked then
begin
LXSForm := setfrm.ShowWait('<27><> ' + extnum + ' <20><>');
if Assigned(LXSForm) then
begin
LXSForm.label1.Tag := allcount;
LXSForm.procbar.Hide;
LXSForm.proclb.Hide;
LXSForm.procl.Hide;
LXSForm.Label1.Show;
end;
end;
end;
if (startpic = true) and (uini = startuin) then
begin
msgpic := msgpic + msgi;
inc(curcount);
if Assigned(LXSForm) then
LXSForm.label2.Tag := curcount;
end;
if pos('', msgi) > 0 then
begin
if Assigned(LXSForm) then
LXSForm.HideForm;
startpic := false;
msgpicsmall := replacestr(replacestr(msgpic, '', ''), '', '');
msgpic := replacestr(replacestr(msgpic, '', ''), '', '');
rcvfile := userPath + 'Rcv\' + FormatDateTime('hh.mm.ss_dd-mm-yy', now) + '_' + IntToStr(uini);
msgpicbytes := DecodeBase64(msgpic);
SaveBytesToFile(msgpicbytes, rcvfile + '.xxx');
ext := '.jpg';
GetMem(sign, 6);
fs := TFileStream.Create(rcvfile + '.xxx', fmOpenRead);
try
fs.ReadBuffer(sign^, 6);
case CheckTypeFile(sign) of
tfBMP:
ext := '.bmp';
tfJPG:
ext := '.jpg';
tfPNG:
ext := '.png';
tfGIF:
ext := '.gif';
tfTIF:
ext := '.tif';
tfICON:
ext := '.ico';
tfWEBP:
ext := '.webp';
end;
finally
fs.Free;
FreeMem(sign, 6);
end;
RenameFile(rcvfile + '.xxx', rcvfile + ext);
if ext = '.gif' then
begin
gif := TGIFImage.Create;
gif.LoadFromFile(rcvfile + ext);
gif.Animate := false;
try
viewpic.img.Picture.Assign(nil);
viewpic.img.Picture.Assign(gif);
viewpic.img.Refresh;
finally
gif.Free;
end;
end
else if ext = '.webp' then
begin
winimg := TWICImage.Create;
winimg.LoadFromFile(rcvfile + ext);
try
viewpic.img.Picture.Assign(nil);
viewpic.img.Picture.Assign(winimg);
viewpic.img.Refresh;
finally
winimg.Free;
end;
end
else
viewpic.img.Picture.LoadFromFile(rcvfile + ext);
viewpic.LoadSaved;
{
if (ext = '.tif') then
Result := str2comm(char(PM_DATA) +
_istring(AnsiString('[ <20><> <20><> TIFF <20><> <20><> <20><> <20><> <20> <20><>. ]')))
else if (ext = '.ico') then
Result := str2comm(char(PM_DATA) +
_istring(AnsiString('[ <20><> <20><> ICO <20><> <20><> <20><> <20><> <20> <20><>. ]')))
else
}
Result := str2comm(char(PM_DATA) + _istring(msgpicsmall));
end
else if (startpic = true) and (uini = startuin) then
Result := str2comm(char(PM_ABORT));
end;
PE_PREFERENCES:
setfrm.showmodal;
end; // case
end; // case
end; // pluginFun
exports
pluginFun;
end.