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