summaryrefslogtreecommitdiff
path: root/plugins/ImportTXT/BqhfIP.inc
diff options
context:
space:
mode:
authorAlexey Kulakov <panda75@bk.ru>2012-07-03 07:22:09 +0000
committerAlexey Kulakov <panda75@bk.ru>2012-07-03 07:22:09 +0000
commit8b8845c8e142c2e70bc0c2785ddf3a91ad3f84bd (patch)
tree58d80918e28651c678069aa2ee768f801eca74db /plugins/ImportTXT/BqhfIP.inc
parent980bcaff693a86971750d6e9ffc8ba1e561b8b3a (diff)
New core adaptation (Delphi 7 normal compilation)
API headers update git-svn-id: http://svn.miranda-ng.org/main/trunk@731 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/ImportTXT/BqhfIP.inc')
-rw-r--r--plugins/ImportTXT/BqhfIP.inc231
1 files changed, 123 insertions, 108 deletions
diff --git a/plugins/ImportTXT/BqhfIP.inc b/plugins/ImportTXT/BqhfIP.inc
index 236a37de0b..26f8737b7f 100644
--- a/plugins/ImportTXT/BqhfIP.inc
+++ b/plugins/ImportTXT/BqhfIP.inc
@@ -1,131 +1,146 @@
-{$ifdef BIN_IMPORT_}
+{$IFDEF BIN_IMPORT_}
+
var
- qhfver:byte;
- szMsgHd:word;
- UIDstr:UTF8String;
- UIDLen,NickLen:word;
- NickStr:UTF8String;
+ qhfver: byte;
+ szMsgHd: word;
+ UIDstr: UTF8String;
+ UIDLen, NickLen: word;
+ NickStr: UTF8String;
-function DecodeQHFMsg(ver:byte; adr:integer; cSize:word):string;
+function DecodeQHFMsg(ver: byte; adr: integer; cSize: word): AnsiString;
-function get1(c: char): byte;
-begin
- if ShortInt(c)>=0 then Result:=Byte(c)
- else Result := Byte(c)+256;
-end;
+ function get1(c: AnsiChar): byte;
+ begin
+ if ShortInt(c) >= 0 then
+ Result := byte(c)
+ else
+ Result := byte(c) + 256;
+ end;
-function get2(b:byte): char;
-begin
- if b<128 then result:=Char(b)
- else result:=Char(b-256);
-end;
+ function get2(b: byte): AnsiChar;
+ begin
+ if b < 128 then
+ Result := AnsiChar(b)
+ else
+ Result := AnsiChar(b - 256);
+ end;
-var i:integer;
+var
+ i: integer;
begin
- SetLength(Result,cSize);
- for i:=1 to cSize do
+ SetLength(Result, cSize);
+ for i := 1 to cSize do
begin
- Result[i]:=PChar(adr+i-1)^;
- if ver<>$01 then
+ Result[i] := PAnsiChar(adr + i - 1)^;
+ if ver <> $01 then
begin
- inc(Result[i],i);
- Result[i]:=get2(255-get1(Result[i]));
+ inc(Result[i], i);
+ Result[i] := get2(255 - get1(Result[i]));
end
end;
end;
-{$else}
+{$ELSE}
+
begin
- pt:=integer(pFileText);
- if FileLen>=$2E then
- if (PChar(pt)^='Q') and (PChar(pt+1)^='H') and (PChar(pt+2)^='F') then
+ pt := uint_ptr(pFileText);
+ if FileLen >= $2E then
+ if (PAnsiChar(pt)^ = 'Q') and (PAnsiChar(pt + 1)^ = 'H') and (PAnsiChar(pt + 2)^ = 'F') then
begin
- qhfver:=PByte(pt+3)^;
- if qhfver>=$03 then szMsgHd:=$23
- else szMsgHd:=$21;
- fsz:=RLInteger(pt+$04);
- UIDLen:=RLWord(pt+$2C);
- SetLength(UIDstr,UIDLen);
- if qhfver<=2 then lstrcpynA(PChar(UIDstr),PChar(pt+$2E),UIDLen)
- else lstrcpynA(PChar(UIDstr),PChar(pt+$2E),UIDLen+1);
- NickLen:=RLWord(pt+$2E+UIDLen);
- SetLength(NickStr,NickLen);
- if qhfver<=2 then lstrcpynA(PChar(NickStr),PChar(pt+$2E+UIDLen+2),UIDLen)
- else lstrcpynA(PChar(NickStr),PChar(pt+$2E+UIDLen+2),UIDLen+1);
- inc(pt,$2E+UIDLen+2+NickLen);
- if fsz<>FileLen-($2E+UIDLen+2+NickLen) then fsz:= FileLen-($2E+UIDLen+2+NickLen);
- if (DContact.hContact=0) or (DContact.hContact=INVALID_HANDLE_VALUE) then
+ qhfver := PByte(pt + 3)^;
+ if qhfver >= $03 then
+ szMsgHd := $23
+ else
+ szMsgHd := $21;
+ fsz := RLInteger(pt + $04);
+
+ UIDLen := RLWord(pt + $2C);
+ SetLength(UIDstr, UIDLen);
+ if qhfver <= 2 then
+ lstrcpynA(PAnsiChar(UIDstr), PAnsiChar(pt + $2E), UIDLen)
+ else
+ lstrcpynA(PAnsiChar(UIDstr), PAnsiChar(pt + $2E), UIDLen + 1);
+
+ NickLen := RLWord(pt + $2E + UIDLen);
+ SetLength(NickStr, NickLen);
+ if qhfver <= 2 then
+ lstrcpynA(PAnsiChar(NickStr), PAnsiChar(pt + $2E + UIDLen + 2), UIDLen)
+ else
+ lstrcpynA(PAnsiChar(NickStr), PAnsiChar(pt + $2E + UIDLen + 2), UIDLen + 1);
+
+ inc(pt, $2E + UIDLen + 2 + NickLen);
+ if fsz <> FileLen - ($2E + UIDLen + 2 + NickLen) then
+ fsz := FileLen - ($2E + UIDLen + 2 + NickLen);
+
+ if (DContact.hContact = 0) or (DContact.hContact = INVALID_HANDLE_VALUE)
+ then
begin
- if IsMirandaUnicode then DContact.ContactUID:=UIDstr
- else
- begin
- tempstr:=UTF8ToANSI(PChar(UIDstr),tempstr,cp);
- DContact.ContactUID:=tempstr;
- FreeMem(tempstr);
- end;
- if IsMirandaUnicode then DContact.ContactNick:=NickStr
- else
- begin
- tempstr:=UTF8ToANSI(PChar(NickStr),tempstr,cp);
- DContact.ContactNick:=tempstr;
- FreeMem(tempstr);
- end;
- TryDetermContact(DContact);
+ DContact.ContactUID := UIDstr;
+ DContact.ContactNick := UTF8Decode{UTF8ToWideString}(NickStr);
+ TryDetermContact(DContact);
end;
- if (DContact.hContact=0) or (DContact.hContact=INVALID_HANDLE_VALUE) then
- if (fContact.hContact<>0) and (fContact.hContact<>INVALID_HANDLE_VALUE) then
- DContact:=fContact;
- if (DContact.hContact<>0) and (DContact.hContact<>INVALID_HANDLE_VALUE) then
- begin
- proto:=GetContactProto(DContact.hContact);
- DoMessage(ITXT_THREAD_DEST_CONTACT,DContact.hContact,0);
- DoMessage(ITXT_THREAD_START,0,0);
- DoMessage(ITXT_THREAD_MAXPROGRESS,0,fsz);
- i:=0;
- while i<fsz do
- begin
- with dbei do
- begin
- fillchar(dbei,sizeof(dbei),0);
- cbSize:=sizeof(dbei);
- szModule:=PChar(proto);
- timestamp:=RLInteger(pt+i+$12);
- timestamp:=timestamp-(PluginLink.CallService(MS_DB_TIME_TIMESTAMPTOLOCAL,timestamp,0)-timestamp);//приводим к GMT
- if PByte(pt+i+$1A)^=$00 then flags:=0
- else flags:=DBEF_SENT;
- flags:=flags or DBEF_READ or DBEF_UTF; //в файлах лежат в utf8 и импортируются без изменений
- eventType:= EVENTTYPE_MESSAGE;
- cbBlob:=RLWord(pt+i+szMsgHd-2)+1; //размер текста сообщения с #0
- pBlob:=AllocMem(cbBlob);
- end;
- try
- Move(DecodeQHFMsg(qhfver,pt+i+szMsgHd,dbei.cbBlob-1)[1],dbei.pBlob^,dbei.cbBlob-1);
- if not IsDuplicateEvent(DContact.hContact,dbei) then
- if pluginLink^.CallService(MS_DB_EVENT_ADD, wParam(DContact.hContact), lParam(@dbei))<>0 then Inc(AddedMessages)
- else begin
- s:= 'Error adding message to DB';
- DoMessage(ITXT_THREAD_ERROR,integer(PWideChar(s)),0); break; end
+ if (DContact.hContact = 0) or (DContact.hContact = INVALID_HANDLE_VALUE) then
+ if (fContact.hContact <> 0) and (fContact.hContact <> INVALID_HANDLE_VALUE) then
+ DContact := fContact;
+ if (DContact.hContact <> 0) and (DContact.hContact <> INVALID_HANDLE_VALUE) then
+ begin
+ proto := GetContactProto(DContact.hContact);
+ DoMessage(ITXT_THREAD_DEST_CONTACT, DContact.hContact, 0);
+ DoMessage(ITXT_THREAD_START, 0, 0);
+ DoMessage(ITXT_THREAD_MAXPROGRESS, 0, fsz);
+ i := 0;
+ while Cardinal(i) < fsz do
+ begin
+ fillchar(dbei, sizeof(dbei), 0);
+ dbei.cbSize := sizeof(dbei);
+ dbei.szModule := PAnsiChar(proto);
+ dbei.timestamp := RLInteger(pt + i + $12);
+ dbei.timestamp := dbei.timestamp -
+ (Cardinal(CallService(MS_DB_TIME_TIMESTAMPTOLOCAL, dbei.timestamp, 0)) - dbei.timestamp); // приводим к GMT
+ if PByte(pt + i + $1A)^ = $00 then
+ dbei.flags := DBEF_READ or DBEF_UTF
+ else
+ dbei.flags := DBEF_READ or DBEF_UTF or DBEF_SENT;
+ // в файлах лежат в utf8 и импортируются без изменений
+ dbei.eventType := EVENTTYPE_MESSAGE;
+ dbei.cbBlob := RLWord(pt + i + szMsgHd - 2) + 1;
+ // размер текста сообщения с #0
+ dbei.pBlob := AllocMem(dbei.cbBlob);
+
+ try
+ Move(DecodeQHFMsg(qhfver, pt + i + szMsgHd, dbei.cbBlob - 1)[1],
+ dbei.pBlob^, dbei.cbBlob - 1);
+ if not IsDuplicateEvent(DContact.hContact, dbei) then
+ if CallService(MS_DB_EVENT_ADD, wParam(DContact.hContact), lParam(@dbei))<>0 then
+ inc(AddedMessages)
+ else
+ begin
+ s := 'Error adding message to DB';
+ DoMessage(ITXT_THREAD_ERROR, wparam(PWideChar(s)), 0);
+ break;
+ end
- else Inc(Duplicates);
+ else
+ inc(Duplicates);
- finally
- inc(i,szMsgHd+dbei.cbBlob-1);
- FreeMem(dbei.pBlob);
+ finally
+ inc(i, szMsgHd + dbei.cbBlob - 1);
+ FreeMem(dbei.pBlob);
+ end;
+ DoMessage(ITXT_THREAD_PROGRESS, i, 0);
end;
- DoMessage(ITXT_THREAD_PROGRESS,i,0);
- end;
- end
- else
- begin
- s:=TranslateWideString('Can''t determine destination contact');
- DoMessage(ITXT_THREAD_ERROR,integer(PWideChar(s)),0);
- end;
+ end
+ else
+ begin
+ s := TranslateWideString('Can''t determine destination contact');
+ DoMessage(ITXT_THREAD_ERROR, wparam(PWideChar(s)), 0);
+ end;
end
- else
+ else
begin
- s:=WideFormat(TranslateWideString('Its not %s file'),['QHF']);
- DoMessage(ITXT_THREAD_ERROR,integer(PWideChar(s)),0);
+ s := WideFormat(TranslateWideString('Its not %s file'), ['QHF']);
+ DoMessage(ITXT_THREAD_ERROR, wparam(PWideChar(s)), 0);
end
- else //file len
+ else // file len
end;
-{$endif} \ No newline at end of file
+{$ENDIF}