фикс утечек
This commit is contained in:
parent
71cdcc9909
commit
04b5259737
161
uGeneral.pas
161
uGeneral.pas
|
|
@ -191,52 +191,46 @@ end;
|
||||||
|
|
||||||
procedure TTTW_Bot.ReadDB;
|
procedure TTTW_Bot.ReadDB;
|
||||||
|
|
||||||
function XorDecryptToStrings(const InputFile, Key: string): TStrings;
|
function XorDecryptToStrings(const InputFile, Key: string): TStrings;
|
||||||
var
|
var
|
||||||
InStream: TFileStream;
|
InStream: TFileStream;
|
||||||
MemStream: TMemoryStream;
|
MemStream: TMemoryStream;
|
||||||
KeyBytes: TBytes;
|
KeyBytes: TBytes;
|
||||||
KeyLen, KeyIndex: integer;
|
KeyLen, KeyIndex: integer;
|
||||||
B: Byte;
|
B: Byte;
|
||||||
begin
|
begin
|
||||||
// Ïðåîáðàçóåì êëþ÷ â áàéòû ñ èñïîëüçîâàíèåì ANSI êîäèðîâêè
|
KeyBytes := TEncoding.ANSI.GetBytes(Key);
|
||||||
KeyBytes := TEncoding.ANSI.GetBytes(Key);
|
KeyLen := Length(KeyBytes);
|
||||||
KeyLen := Length(KeyBytes);
|
if KeyLen = 0 then
|
||||||
if KeyLen = 0 then
|
raise Exception.Create('Êëþ÷ íå ìîæåò áûòü ïóñòûì');
|
||||||
raise Exception.Create('Êëþ÷ íå ìîæåò áûòü ïóñòûì');
|
|
||||||
|
|
||||||
InStream := TFileStream.Create(InputFile, fmOpenRead);
|
InStream := TFileStream.Create(InputFile, fmOpenRead);
|
||||||
|
try
|
||||||
|
MemStream := TMemoryStream.Create;
|
||||||
try
|
try
|
||||||
MemStream := TMemoryStream.Create;
|
KeyIndex := 0;
|
||||||
|
while InStream.Position < InStream.Size do
|
||||||
|
begin
|
||||||
|
InStream.ReadBuffer(B, 1);
|
||||||
|
B := B xor KeyBytes[KeyIndex];
|
||||||
|
MemStream.WriteBuffer(B, 1);
|
||||||
|
KeyIndex := (KeyIndex + 1) mod KeyLen;
|
||||||
|
end;
|
||||||
|
MemStream.Position := 0;
|
||||||
|
Result := TStringList.Create;
|
||||||
try
|
try
|
||||||
KeyIndex := 0;
|
Result.LoadFromStream(MemStream, TEncoding.ANSI);
|
||||||
// Ðàñøèôðîâûâàåì äàííûå è çàïèñûâàåì â ïîòîê â ïàìÿòè
|
except
|
||||||
while InStream.Position < InStream.Size do
|
Result.Free; // Îñâîáîæäàåì ïðè îøèáêå çàãðóçêè
|
||||||
begin
|
raise;
|
||||||
InStream.ReadBuffer(B, 1);
|
|
||||||
B := B xor KeyBytes[KeyIndex];
|
|
||||||
MemStream.WriteBuffer(B, 1);
|
|
||||||
KeyIndex := (KeyIndex + 1) mod KeyLen;
|
|
||||||
end;
|
|
||||||
// Ïðåîáðàçóåì äàííûå èç ïîòîêà â TStrings
|
|
||||||
MemStream.Position := 0; // Ñáðàñûâàåì ïîçèöèþ äëÿ ÷òåíèÿ
|
|
||||||
Result := TStringList.Create;
|
|
||||||
try
|
|
||||||
// Èñïîëüçóåì ANSI êîäèðîâêó äëÿ ïðåîáðàçîâàíèÿ áàéòîâ â ñòðîêó
|
|
||||||
Result.LoadFromStream(MemStream, TEncoding.ANSI);
|
|
||||||
except
|
|
||||||
//  ñëó÷àå îøèáêè îñâîáîæäàåì ðåñóðñû è ïðîáðàñûâàåì èñêëþ÷åíèå
|
|
||||||
Result.Free;
|
|
||||||
raise;
|
|
||||||
end;
|
|
||||||
finally
|
|
||||||
MemStream.Free;
|
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
InStream.Free;
|
MemStream.Free;
|
||||||
end;
|
end;
|
||||||
|
finally
|
||||||
|
InStream.Free;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
// Çàãðóçêà êîìïîíåíòîâ íàñòðîåê (TEdit, TCheckBox)
|
// Çàãðóçêà êîìïîíåíòîâ íàñòðîåê (TEdit, TCheckBox)
|
||||||
procedure LoadSettingsComponents;
|
procedure LoadSettingsComponents;
|
||||||
var
|
var
|
||||||
|
|
@ -274,58 +268,55 @@ procedure TTTW_Bot.ReadDB;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Çàãðóçêà çàøèôðîâàííîãî êîíôèãà
|
// Çàãðóçêà çàøèôðîâàííîãî êîíôèãà
|
||||||
procedure LoadEncryptedConfig;
|
procedure LoadEncryptedConfig;
|
||||||
var
|
var
|
||||||
sl: TStringList;
|
tempList: TStrings; // Âðåìåííûé ñïèñîê äëÿ ðåçóëüòàòà
|
||||||
I: integer;
|
I: integer;
|
||||||
begin
|
begin
|
||||||
if not FileExists(myConst.cfg1) then
|
if not FileExists(myConst.cfg1) then
|
||||||
Exit;
|
Exit;
|
||||||
|
|
||||||
sl := TStringList.Create;
|
tempList := nil; // Èíèöèàëèçàöèÿ
|
||||||
try
|
try
|
||||||
sl.Assign(XorDecryptToStrings(myConst.cfg1, 'fgvasrgEFAXFAFAS'));
|
tempList := XorDecryptToStrings(myConst.cfg1, 'fgvasrgEFAXFAFAS');
|
||||||
for I := 0 to sl.Count - 1 do
|
|
||||||
|
for I := 0 to tempList.Count - 1 do
|
||||||
|
begin
|
||||||
|
var eqPos := Pos('=', tempList[I]);
|
||||||
|
if eqPos > 0 then
|
||||||
begin
|
begin
|
||||||
var
|
var Key := Trim(Copy(tempList[I], 1, eqPos - 1));
|
||||||
eqPos := Pos('=', sl[I]);
|
var Value := Trim(Copy(tempList[I], eqPos + 1, MaxInt));
|
||||||
if eqPos > 0 then
|
|
||||||
begin
|
|
||||||
var
|
|
||||||
Key := Trim(Copy(sl[I], 1, eqPos - 1));
|
|
||||||
var
|
|
||||||
Value := Trim(Copy(sl[I], eqPos + 1, MaxInt));
|
|
||||||
|
|
||||||
if Key = 'k1' then
|
if Key = 'k1' then
|
||||||
appconst.TTV_ClientID := Value
|
appconst.TTV_ClientID := Value
|
||||||
else if Key = 'k2' then
|
else if Key = 'k2' then
|
||||||
appconst.AI_GigaChat_AC := Value
|
appconst.AI_GigaChat_AC := Value
|
||||||
else if Key = 'k3' then
|
else if Key = 'k3' then
|
||||||
appconst.AI_GigaChat_ClientID := Value
|
appconst.AI_GigaChat_ClientID := Value
|
||||||
else if Key = 'k4' then
|
else if Key = 'k4' then
|
||||||
appconst.AI_ChatGPT_Token := Value
|
appconst.AI_ChatGPT_Token := Value
|
||||||
else if Key = 'k5' then
|
else if Key = 'k5' then
|
||||||
appconst.AI_DeepSeec_Token := Value
|
appconst.AI_DeepSeec_Token := Value
|
||||||
else if Key = 'k6' then
|
else if Key = 'k6' then
|
||||||
appconst.DA_ClientID := Value
|
appconst.DA_ClientID := Value
|
||||||
else if Key = 'k7' then
|
else if Key = 'k7' then
|
||||||
appconst.DA_Sicret := Value
|
appconst.DA_Sicret := Value
|
||||||
else if Key = 'k8' then
|
else if Key = 'k8' then
|
||||||
appconst.DA_URL := Value;
|
appconst.DA_URL := Value;
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
frSettings1.btnGetClientID.Visible := (appconst.TTV_ClientID <> '');
|
|
||||||
frAI1.btnGetAIDef.Visible := ((appconst.AI_GigaChat_AC <> '') and
|
|
||||||
(appconst.AI_GigaChat_ClientID <> '')) or
|
|
||||||
(appconst.AI_ChatGPT_Token <> '') or (appconst.AI_DeepSeec_Token <> '');
|
|
||||||
frSettings1.btnGetDADef.Visible := (appconst.DA_ClientID <> '') and
|
|
||||||
(appconst.DA_Sicret <> '') and (appconst.DA_URL <> '');
|
|
||||||
finally
|
|
||||||
sl.Free;
|
|
||||||
end;
|
end;
|
||||||
end;
|
|
||||||
|
|
||||||
|
frSettings1.btnGetClientID.Visible := (appconst.TTV_ClientID <> '');
|
||||||
|
frAI1.btnGetAIDef.Visible := ((appconst.AI_GigaChat_AC <> '') and
|
||||||
|
(appconst.AI_GigaChat_ClientID <> '')) or
|
||||||
|
(appconst.AI_ChatGPT_Token <> '') or (appconst.AI_DeepSeec_Token <> '');
|
||||||
|
frSettings1.btnGetDADef.Visible := (appconst.DA_ClientID <> '') and
|
||||||
|
(appconst.DA_Sicret <> '') and (appconst.DA_URL <> '');
|
||||||
|
finally
|
||||||
|
tempList.Free; // Âàæíî: îñâîáîæäàåì âðåìåííûé ñïèñîê!
|
||||||
|
end;
|
||||||
|
end;
|
||||||
// Çàãðóçêà íàñòðîåê óâåäîìëåíèé
|
// Çàãðóçêà íàñòðîåê óâåäîìëåíèé
|
||||||
procedure LoadNotifySettings;
|
procedure LoadNotifySettings;
|
||||||
var
|
var
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue