Skip to content

Commit

Permalink
fixes #3494 (Import: not possible to import mContats files)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehazan committed Apr 21, 2023
1 parent 0b305d1 commit 497feba
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
8 changes: 4 additions & 4 deletions plugins/HistoryPlusPlus/HistoryForm.pas
Expand Up @@ -3820,18 +3820,18 @@ procedure THistoryFrm.hgMCData(Sender: TObject; Index: Integer; var Item: TMCIte
hDBEvent := History[GridIndexToHistory(Index)];
if hDBEvent <> 0 then
begin
DBEventInfo.d := GetEventInfo(hDBEvent);
DBEventInfo.d.szModule := nil;
DBEventInfo := GetOldEventInfo(hDBEvent);
DBEventInfo.szModule := nil;
DBEventInfo.cbSize := sizeof(DBEventInfo);

Item.Size := sizeof(DBEventInfo) + Cardinal(DBEventInfo.d.cbBlob);
Item.Size := sizeof(DBEventInfo) + Cardinal(DBEventInfo.cbBlob);
end;
if Item.Size > 0 then
begin
GetMem(Item.Buffer, Item.Size);
DataOffset := PAnsiChar(Item.Buffer) + sizeof(DBEventInfo);
Move(DBEventInfo, Item.Buffer^, sizeof(DBEventInfo));
Move(DBEventInfo.d.pBlob^, DataOffset^, DBEventInfo.d.cbBlob);
Move(DBEventInfo.pBlob^, DataOffset^, DBEventInfo.cbBlob);
end;
end
else if Stage = ssDone then
Expand Down
35 changes: 35 additions & 0 deletions plugins/HistoryPlusPlus/hpp_events.pas
Expand Up @@ -101,6 +101,7 @@ function TimestampToDateTime(const Timestamp: DWord): TDateTime;
function TimestampToString(const Timestamp: DWord): String;
// general routine
function ReadEvent(hDBEvent: THandle; UseCP: Cardinal = CP_ACP): THistoryItem;
function GetOldEventInfo(hDBEvent: THANDLE): TOldDBEventInfo;
function GetEventInfo(hDBEvent: THANDLE): TDBEventInfo;
function GetEventTimestamp(hDBEvent: THandle): DWord;
function GetEventMessageType(hDBEvent: THandle): TMessageTypes;
Expand Down Expand Up @@ -405,6 +406,40 @@ function GetEventInfo(hDBEvent: THANDLE): TDBEventInfo;
Result.cbBlob := 0;
end;

function GetOldEventInfo(hDBEvent: THANDLE): TOldDBEventInfo;
var
BlobSize: integer;
dbei: TDBEventInfo;
begin
ZeroMemory(@Result, SizeOf(Result));
BlobSize := db_event_getBlobSize(hDBEvent);
if BlobSize > 0 then
begin
EventBuffer.Allocate(BlobSize+2); // cheat, for possible crash avoid
Result.pBlob := EventBuffer.Buffer;
end
else
BlobSize := 0;

dbei.cbBlob := BlobSize;
dbei.pBlob := Result.pBlob;
if db_event_get(hDBEvent, @dbei) = 0 then
begin
Result.cbBlob := BlobSize;
if BlobSize > 0 then
begin
PAnsiChar(Result.pBlob)[BlobSize ]:=#0;
PAnsiChar(Result.pBlob)[BlobSize+1]:=#0;
end;
end
else
Result.cbBlob := 0;

Result.flags := dbei.flags;
Result.timestamp := dbei.timestamp;
Result.eventType := dbei.eventType;
end;

function GetMessageType(EventInfo: TDBEventInfo; var EventIndex: Integer): TMessageTypes;
var
i: Integer;
Expand Down
22 changes: 11 additions & 11 deletions plugins/HistoryPlusPlus/hpp_externalgrid.pas
Expand Up @@ -1226,33 +1226,33 @@ procedure TExternalGrid.GridMCData(Sender: TObject; Index: Integer; var Item: TM
begin
ZeroMemory(@DBEventInfo, SizeOf(DBEventInfo));
DBEventInfo.cbSize := SizeOf(DBEventInfo);
DBEventInfo.d.timestamp := Items[Index].CustomEvent.Time;
DBEventInfo.d.flags := DBEF_READ or DBEF_UTF;
DBEventInfo.timestamp := Items[Index].CustomEvent.Time;
DBEventInfo.flags := DBEF_READ or DBEF_UTF;
if Items[Index].CustomEvent.Sent then
DBEventInfo.d.flags := DBEventInfo.d.flags or DBEF_SENT;
DBEventInfo.d.EventType := EVENTTYPE_MESSAGE;
DBEventInfo.flags := DBEventInfo.flags or DBEF_SENT;
DBEventInfo.EventType := EVENTTYPE_MESSAGE;
TextUTF := Items[Index].CustomEvent.Text + #0;
DBEventInfo.d.cbBlob := Length(TextUTF) + 1;
DBEventInfo.d.pBlob := Pointer(TextUTF);
Item.Size := Cardinal(DBEventInfo.cbSize) + Cardinal(DBEventInfo.d.cbBlob);
DBEventInfo.cbBlob := Length(TextUTF) + 1;
DBEventInfo.pBlob := Pointer(TextUTF);
Item.Size := Cardinal(DBEventInfo.cbSize) + Cardinal(DBEventInfo.cbBlob);
end
else
begin
hDBEvent := Items[Index].hDBEvent;
if hDBEvent <> 0 then
begin
DBEventInfo.cbSize := SizeOf(DBEventInfo);
DBEventInfo.d := GetEventInfo(hDBEvent);
DBEventInfo.d.szModule := nil;
Item.Size := Cardinal(DBEventInfo.cbSize) + Cardinal(DBEventInfo.d.cbBlob);
DBEventInfo := GetOldEventInfo(hDBEvent);
DBEventInfo.szModule := nil;
Item.Size := Cardinal(DBEventInfo.cbSize) + Cardinal(DBEventInfo.cbBlob);
end;
end;
if Item.Size > 0 then
begin
GetMem(Item.Buffer, Item.Size);
DataOffset := PAnsiChar(Item.Buffer) + DBEventInfo.cbSize;
Move(DBEventInfo, Item.Buffer^, DBEventInfo.cbSize);
Move(DBEventInfo.d.pBlob^, DataOffset^, DBEventInfo.d.cbBlob);
Move(DBEventInfo.pBlob^, DataOffset^, DBEventInfo.cbBlob);
end;
end
else if Stage = ssDone then
Expand Down
7 changes: 6 additions & 1 deletion plugins/HistoryPlusPlus/hpp_global.pas
Expand Up @@ -75,7 +75,12 @@ interface

TOldDBEventInfo = record
cbSize : dword;
d : TDBEventInfo;
szModule : PAnsiChar; // module that 'owns' this event and controls the data format
timestamp: dword; // timestamp in UNIX time
flags : dword; // the DBEF_* flags above
eventType: word; // event type, such as message, can be module defined
cbBlob : dword; // size in bytes of pBlob^
pBlob : PByte; // pointer to buffer containing the module defined event data
end;

PHistoryItem = ^THistoryItem;
Expand Down

0 comments on commit 497feba

Please sign in to comment.