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.
892 lines
24 KiB
Plaintext
892 lines
24 KiB
Plaintext
{
|
|
This file is part of R&Q.
|
|
Under same license
|
|
}
|
|
unit usersDlg;
|
|
{$I RnQConfig.inc}
|
|
|
|
interface
|
|
|
|
uses
|
|
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, ExtCtrls, StdCtrls,
|
|
VirtualTrees, RnQButtons, RnQDialogs, ICQCommon, ICQSession, globalLib;
|
|
|
|
{$I NoRTTI.inc}
|
|
|
|
type
|
|
TusersFrm = class(TForm)
|
|
UsersBox: TVirtualDrawTree;
|
|
Label1: TLabel;
|
|
Bevel: TBevel;
|
|
deleteuserBtn: TRnQButton;
|
|
newaccountBtn: TRnQButton;
|
|
newuserBtn: TRnQButton;
|
|
okBtn: TRnQButton;
|
|
PntBox: TPaintBox;
|
|
procedure UsersBoxCompareNodes(Sender: TBaseVirtualTree; Node1, Node2: PVirtualNode; Column: TColumnIndex;
|
|
var Result: Integer);
|
|
procedure UsersBoxDrawNode(Sender: TBaseVirtualTree; const PaintInfo: TVTPaintInfo);
|
|
procedure usersBoxDblClick(Sender: TObject);
|
|
procedure newuserBtnClick(Sender: TObject);
|
|
procedure FormShow(Sender: TObject);
|
|
procedure usersBoxKeyPress(Sender: TObject; var Key: Char);
|
|
procedure newaccountBtnClick(Sender: TObject);
|
|
procedure deleteuserBtnClick(Sender: TObject);
|
|
procedure okBtnClick(Sender: TObject);
|
|
procedure usersBoxClick(Sender: TObject);
|
|
procedure FormCreate(Sender: TObject);
|
|
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
|
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
|
procedure L1Click(Sender: TObject);
|
|
procedure L1MouseEnter(Sender: TObject);
|
|
procedure L1MouseLeave(Sender: TObject);
|
|
procedure UsersBoxFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
|
|
procedure UsersBoxFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex);
|
|
procedure UsersBoxFocusChanging(Sender: TBaseVirtualTree; OldNode, NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
|
|
var Allowed: Boolean);
|
|
procedure PntBoxPaint(Sender: TObject);
|
|
private
|
|
selected: Boolean;
|
|
RnQVer, RnQVer0, RnQVerT: String;
|
|
MouseOnLabel: Boolean;
|
|
function CheckPass: Boolean;
|
|
public
|
|
startIt: Boolean;
|
|
resAccPass: String;
|
|
procedure refreshUsers;
|
|
function doSelect: TUID;
|
|
function selectUIN(const uin: TUID): Boolean;
|
|
function uinAt(idx: Integer): TUID;
|
|
procedure newuser(const uin: TUID);
|
|
end;
|
|
|
|
function findInAvailableUsers(const uin: TUID): integer;
|
|
procedure clearAvailableUsers;
|
|
procedure refreshAvailableUsers;
|
|
function getUserAutoStart(var pass: String): TUID;
|
|
|
|
var
|
|
usersFrm: TusersFrm;
|
|
availableUsers: array of TRnQUser;
|
|
|
|
implementation
|
|
|
|
{$R *.DFM}
|
|
|
|
uses
|
|
UxTheme, DwmApi, Themes, StrUtils, ShlObj, NewAccount,
|
|
{$IFDEF UNICODE}
|
|
AnsiStrings,
|
|
{$ENDIF UNICODE}
|
|
ICQConsts, ICQContacts,
|
|
RnQZip, RDUtils, RnQSysUtils, RnQGlobal, RnQLangs, RQUtil,
|
|
mainDlg, utilLib, langLib, iniLib, RDGlobal, RDFileUtil;
|
|
|
|
const
|
|
Have2Sel = 'You have to select a user to delete it';
|
|
|
|
var
|
|
deletedMe: Boolean;
|
|
|
|
procedure TusersFrm.refreshUsers;
|
|
var
|
|
// toSelect:integer;
|
|
i: Integer;
|
|
ur: PRnQUser;
|
|
n, s: PVirtualNode;
|
|
begin
|
|
UsersBox.clear;
|
|
// toSelect:=-1;
|
|
s := nil;
|
|
for i := 0 to length(availableUsers) - 1 do
|
|
with availableUsers[i] do
|
|
begin
|
|
n := UsersBox.AddChild(nil);
|
|
ur := UsersBox.GetNodeData(n);
|
|
ur^ := availableUsers[i];
|
|
// ur.name := name;
|
|
// ur.uinStr :=
|
|
// usersBox.items.add(uinStr+' '+name);
|
|
if LowerCase(uin) = lastUser then
|
|
begin
|
|
// toSelect:=i;
|
|
s := n;
|
|
end;
|
|
end;
|
|
// UsersBox.Sort;
|
|
// if toSelect >= 0 then
|
|
if Assigned(s) then
|
|
begin
|
|
UsersBox.selected[s] := True;
|
|
UsersBox.FocusedNode := s;
|
|
// usersBox.itemIndex:=toSelect;
|
|
okBtn.enabled := True;
|
|
end;
|
|
{ else
|
|
if usersBox.items.count > 0 then
|
|
begin
|
|
usersBox.itemIndex:=0;
|
|
okBtn.enabled:=TRUE;
|
|
end
|
|
else
|
|
begin
|
|
usersBox.itemIndex:=-1;
|
|
okBtn.enabled:=FALSE;
|
|
end; }
|
|
if UsersBox.GetLast = nil then
|
|
okBtn.enabled := FALSE;
|
|
|
|
end; // refreshUsers
|
|
|
|
function TusersFrm.doSelect: TUID;
|
|
begin
|
|
startIt := FALSE;
|
|
resAccPass := '';
|
|
showModal;
|
|
if not selected and not startIt then
|
|
Result := ''
|
|
else if UsersBox.FocusedNode <> NIL then
|
|
Result := TRnQUser(PRnQUser(UsersBox.GetNodeData(UsersBox.FocusedNode))^).uin
|
|
else
|
|
Result := '';
|
|
// if Result > '' then
|
|
// masterUseSSI := ssiChk.Checked;
|
|
end; // doSelect
|
|
|
|
procedure TusersFrm.usersBoxDblClick(Sender: TObject);
|
|
begin
|
|
okBtnClick(Sender)
|
|
end;
|
|
|
|
procedure TusersFrm.UsersBoxDrawNode(Sender: TBaseVirtualTree; const PaintInfo: TVTPaintInfo);
|
|
var
|
|
s: String;
|
|
x: Integer;
|
|
begin
|
|
PaintInfo.Canvas.Font.Assign(Application.DefaultFont);
|
|
with TRnQUser(PRnQUser(UsersBox.GetNodeData(PaintInfo.Node))^) do
|
|
begin
|
|
s := prefix + uin + ' ' + name;
|
|
if encr then
|
|
s := s + ' *KEY*'
|
|
end;
|
|
if vsSelected in PaintInfo.Node.States then
|
|
begin
|
|
if Sender.Focused then
|
|
PaintInfo.Canvas.Font.Color := clHighlightText
|
|
else
|
|
PaintInfo.Canvas.Font.Color := clWindowText;
|
|
end
|
|
else
|
|
PaintInfo.Canvas.Font.Color := clWindowText;
|
|
x := PaintInfo.ContentRect.Left;
|
|
// inc(x, theme.drawPic(PaintInfo.Canvas, PaintInfo.ContentRect.Left +3, 0,
|
|
// TlogItem(PLogItem(LogList.getnodedata(PaintInfo.Node)^)^).Img).cx+6);
|
|
SetBkMode(PaintInfo.Canvas.Handle, TRANSPARENT);
|
|
// PaintInfo.Canvas.textout(PaintInfo.ContentRect.Left +x,2, s);
|
|
PaintInfo.Canvas.textout(x, 2, s);
|
|
end;
|
|
|
|
procedure TusersFrm.UsersBoxFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex);
|
|
begin
|
|
{ if ssiChk.Enabled then
|
|
if Node <> NIL then
|
|
with TRnQUser(PRnQUser(Sender.getnodedata(Node))^) do
|
|
ssiChk.Checked := SSI; }
|
|
okBtn.enabled := UsersBox.FocusedNode <> NIL
|
|
end;
|
|
|
|
procedure TusersFrm.UsersBoxFocusChanging(Sender: TBaseVirtualTree; OldNode, NewNode: PVirtualNode;
|
|
OldColumn, NewColumn: TColumnIndex; var Allowed: Boolean);
|
|
begin
|
|
{ if ssiChk.Enabled then
|
|
if OldNode <> NIL then
|
|
with TRnQUser(PRnQUser(Sender.getnodedata(OldNode))^) do
|
|
SSI := ssiChk.Checked; }
|
|
okBtn.enabled := UsersBox.FocusedNode <> NIL
|
|
end;
|
|
|
|
procedure TusersFrm.UsersBoxFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
|
|
begin
|
|
with TRnQUser(PRnQUser(UsersBox.GetNodeData(Node))^) do
|
|
begin
|
|
SetLength(name, 0);
|
|
// SetLength(uinStr, 0);
|
|
SetLength(SubPath, 0);
|
|
SetLength(path, 0);
|
|
SetLength(uin, 0);
|
|
end;
|
|
end;
|
|
|
|
procedure TusersFrm.newaccountBtnClick(Sender: TObject);
|
|
begin
|
|
openURL('https://icq.com/join/');
|
|
end;
|
|
|
|
procedure TusersFrm.newuserBtnClick(Sender: TObject);
|
|
var
|
|
uin: TUID;
|
|
NewAccDlg: TNewAccFrm;
|
|
begin
|
|
uin := '';
|
|
NewAccDlg := TNewAccFrm.create(Application);
|
|
translateWindow(NewAccDlg);
|
|
if NewAccDlg.showModal = mrOk then
|
|
newuser(NewAccDlg.AccEdit.Text);
|
|
NewAccDlg.Free;
|
|
// if enterUINdlg(NIL, uin,'New user UIN') then
|
|
// newUser(uin);
|
|
if okBtn.enabled then
|
|
okBtn.SetFocus;
|
|
// okBtn.
|
|
end;
|
|
|
|
procedure TusersFrm.FormShow(Sender: TObject);
|
|
begin
|
|
// applyTaskButton(self);
|
|
selected := FALSE;
|
|
// hideTaskButtonIfUhave2;
|
|
// ActiveControl := UsersBox;
|
|
|
|
if UsersBox.ChildCount[UsersBox.RootNode] = 0 then
|
|
newuserBtn.SetFocus;
|
|
end;
|
|
|
|
procedure TusersFrm.L1Click(Sender: TObject);
|
|
begin
|
|
// openURL(rnqSite);
|
|
exec(rnqSite);
|
|
end;
|
|
|
|
procedure TusersFrm.L1MouseEnter(Sender: TObject);
|
|
begin
|
|
// with (sender as Tlabel).font do Style:=Style+[fsUnderline]
|
|
if not MouseOnLabel then
|
|
begin
|
|
MouseOnLabel := True;
|
|
PntBox.Repaint;
|
|
end;
|
|
end;
|
|
|
|
procedure TusersFrm.L1MouseLeave(Sender: TObject);
|
|
begin
|
|
// with (sender as Tlabel).font do Style:=Style-[fsUnderline]
|
|
if MouseOnLabel then
|
|
begin
|
|
MouseOnLabel := False;
|
|
PntBox.Repaint;
|
|
end;
|
|
end;
|
|
|
|
procedure TusersFrm.usersBoxKeyPress(Sender: TObject; var Key: Char);
|
|
begin
|
|
if Key = #13 then
|
|
begin
|
|
selected := UsersBox.FocusedNode <> NIL;
|
|
if selected then
|
|
close
|
|
else
|
|
newuserBtnClick(nil);
|
|
end;
|
|
end;
|
|
|
|
function TusersFrm.selectUIN(const uin: TUID): Boolean;
|
|
var
|
|
n: PVirtualNode;
|
|
begin
|
|
Result := False;
|
|
n := UsersBox.GetFirst;
|
|
while n <> nil do
|
|
begin
|
|
if TRnQUser(PRnQUser(UsersBox.GetNodeData(n))^).uin = uin then
|
|
begin
|
|
UsersBox.Selected[n] := True;
|
|
okBtn.Enabled := True;
|
|
Result := True;
|
|
Exit;
|
|
end;
|
|
n := UsersBox.GetNext(n);
|
|
end;
|
|
end;
|
|
|
|
function TusersFrm.uinAt(idx: Integer): TUID;
|
|
begin
|
|
if idx >= length(availableUsers) then
|
|
Result := ''
|
|
else
|
|
Result := availableUsers[idx].uin;
|
|
end;
|
|
|
|
procedure TusersFrm.deleteuserBtnClick(Sender: TObject);
|
|
var
|
|
UINtoDelete: TUID;
|
|
path: String;
|
|
itsme: Boolean;
|
|
continue: Boolean;
|
|
u: TRnQUser;
|
|
begin
|
|
// if usersBox.itemIndex < 0 then
|
|
if UsersBox.FocusedNode = NIL then
|
|
msgDlg(Have2Sel, True, mtInformation)
|
|
else
|
|
begin
|
|
u := TRnQUser(PRnQUser(UsersBox.GetNodeData(UsersBox.FocusedNode))^);
|
|
UINtoDelete := u.uin;
|
|
// path := u.path + u.uinStr;
|
|
path := u.path + u.SubPath;
|
|
// uinAt(usersBox.ItemIndex);
|
|
if UINtoDelete = '' then
|
|
begin
|
|
msgDlg(Have2Sel, True, mtInformation);
|
|
exit;
|
|
end;
|
|
itsme := Assigned(Account.AccProto) and (Account.AccProto.getMyInfo <> NIL) and
|
|
(Account.AccProto.getMyInfo.equals(UINtoDelete));
|
|
if itsme then
|
|
begin
|
|
continue := messageDlg
|
|
(getTranslation
|
|
('The user you are trying to delete is the one in use right now.\nIt will be closed to be deleted. Continue?',
|
|
[UINtoDelete]), mtConfirmation, [mbYes, mbNo], 0) = mrYes;
|
|
deletedMe := continue;
|
|
if continue then
|
|
quitUser;
|
|
end
|
|
else
|
|
continue := messageDlg(getTranslation('Are you sure you want to delete %s ?', [UINtoDelete]), mtConfirmation, [mbYes, mbNo],
|
|
0) = mrYes;
|
|
if continue then
|
|
// if delSUBtree(UINtoDelete) then
|
|
if delTree(path) then
|
|
begin
|
|
refreshAvailableUsers;
|
|
refreshUsers;
|
|
msgDlg('User deleted!', True, mtInformation)
|
|
end
|
|
else
|
|
msgDlg('Error deleting this user!', True, mtError);
|
|
end
|
|
end;
|
|
|
|
procedure TusersFrm.okBtnClick(Sender: TObject);
|
|
begin
|
|
// if usersBox.itemIndex < 0 then exit;
|
|
if UsersBox.FocusedNode = NIL then
|
|
exit;
|
|
if not CheckPass then
|
|
begin
|
|
ModalResult := mrNone;
|
|
exit;
|
|
end;
|
|
selected := True;
|
|
close;
|
|
end;
|
|
|
|
procedure TusersFrm.PntBoxPaint(Sender: TObject);
|
|
const
|
|
sizeM: Integer = 48;
|
|
var
|
|
cnv: Tcanvas;
|
|
TextRect, R: TRect;
|
|
MemDC: HDC;
|
|
PaintBuffer: HPAINTBUFFER;
|
|
oldF: HFONT;
|
|
ico: HICON;
|
|
sz: TSize;
|
|
begin
|
|
cnv := (Sender as TPaintBox).Canvas;
|
|
R := (Sender as TPaintBox).ClientRect;
|
|
PaintBuffer := 0;
|
|
TextRect := R; // rect(r.left,r.Top+2,r.Left+round((r.right-r.left)*progLogon),r.bottom-2);
|
|
// cnv.font.color:=clHighlightText;
|
|
if MouseOnLabel then
|
|
cnv.Font.Color := clGray
|
|
else
|
|
cnv.Font.Color := clInfoText;
|
|
MemDC := cnv.Handle;
|
|
TextRect := R;
|
|
inc(TextRect.Top, 15);
|
|
dec(TextRect.bottom, (Sender as TPaintBox).Height - sizeM - 5);
|
|
SetBkMode(MemDC, TRANSPARENT);
|
|
oldF := SelectObject(MemDC, cnv.Font.Handle);
|
|
SetTextAlign(MemDC, GetTextAlign(MemDC) or (TA_CENTER) or VTA_CENTER);
|
|
GetTextExtentPoint32(cnv.Handle, PChar(RnQVer0), length(RnQVer0), sz);
|
|
ExtTextOut(MemDC, (TextRect.Right + TextRect.Left) shr 1, (TextRect.Top + TextRect.bottom) shr 1 - sz.cy, ETO_CLIPPED,
|
|
@TextRect, PChar(RnQVer0), length(RnQVer0), NIL);
|
|
if RnQVerT > '' then
|
|
ExtTextOut(MemDC, (TextRect.Right + TextRect.Left) shr 1, (TextRect.Top + TextRect.bottom) shr 1, ETO_CLIPPED,
|
|
@TextRect, PChar(RnQVerT), length(RnQVerT), NIL);
|
|
SelectObject(MemDC, oldF);
|
|
ico := CopyImage(Application.Icon.Handle, IMAGE_ICON, sizeM, sizeM, LR_COPYFROMRESOURCE);
|
|
DrawIconEx(MemDC, (R.Left + R.Right - sizeM) shr 1, R.bottom - sizeM - 5, ico, sizeM, sizeM, 0, 0, DI_NORMAL);
|
|
DestroyIcon(ico);
|
|
end;
|
|
|
|
procedure TusersFrm.usersBoxClick(Sender: TObject);
|
|
begin
|
|
okBtn.Enabled := Assigned(UsersBox.FocusedNode)
|
|
end;
|
|
|
|
procedure TusersFrm.UsersBoxCompareNodes(Sender: TBaseVirtualTree; Node1, Node2: PVirtualNode; Column: TColumnIndex;
|
|
var Result: Integer);
|
|
var
|
|
i: Int64;
|
|
u1, u2: TUID;
|
|
begin
|
|
u1 := TRnQUser(PRnQUser(Sender.GetNodeData(Node1))^).uin;
|
|
u2 := TRnQUser(PRnQUser(Sender.GetNodeData(Node2))^).uin;
|
|
// if Column = 0 then
|
|
if TryStrToInt64(u1, i) or TryStrToInt64(u2, i) then
|
|
Result := compareInt(StrToIntDef(u1, MaxInt), StrToIntDef(u2, MaxInt))
|
|
else
|
|
Result := CompareText(u1, u2)
|
|
// else
|
|
// result:= -CompareText(Tcontact(sender.getnodedata(Node1)^).displayed,
|
|
// Tcontact(Sender.getnodedata(Node2)^).displayed);
|
|
end;
|
|
|
|
procedure TusersFrm.newuser(const uin: TUID);
|
|
var
|
|
// s:string;
|
|
// i, k:integer;
|
|
tUserPath: String;
|
|
b: Boolean;
|
|
u: PRnQUser;
|
|
n: PVirtualNode;
|
|
onlyUID: TUID;
|
|
begin
|
|
// s:= uin;
|
|
if cmdLinePar.userPath > '' then
|
|
tUserPath := cmdLinePar.userPath
|
|
else
|
|
tUserPath := myPath + accountsPath;
|
|
// prCl := NIL;
|
|
// if cls = NIL then
|
|
begin
|
|
onlyUID := uin;
|
|
b := TICQSession._IsProtoUid(onlyUID);
|
|
if TICQSession._IsValidUid(onlyUID) then
|
|
onlyUID := TICQContact.TrimUID(onlyUID);
|
|
|
|
// val(uin, k, i);
|
|
if not b then
|
|
begin
|
|
MsgDlg('Not a valid user identifier', True, mtError);
|
|
Exit;
|
|
end;
|
|
if SelectUIN(onlyUID) then
|
|
begin
|
|
MsgDlg(GetTranslation('%s already exists', [uin]), False, mtError);
|
|
Exit;
|
|
end;
|
|
// if isOnlyDigits(onlyUID) then
|
|
tUserPath := tUserPath + onlyUID + PathDelim;
|
|
// else
|
|
// tUserPath := tUserPath + 'ICQ_' + onlyUID + PathDelim;
|
|
IOresult;
|
|
ForceDirectories(tUserPath);
|
|
IOresult;
|
|
UsersBox.BeginUpdate;
|
|
n := UsersBox.AddChild(nil);
|
|
u := UsersBox.GetNodeData(n);
|
|
u.uin := onlyUID;
|
|
u.name := '';
|
|
u.SubPath := '';
|
|
u.path := tUserPath;
|
|
UsersBox.EndUpdate;
|
|
lastUser := onlyUID;
|
|
refreshAvailableUsers;
|
|
refreshUsers;
|
|
usersBoxClick(nil);
|
|
end;
|
|
end; // newuser
|
|
|
|
procedure TusersFrm.FormCreate(Sender: TObject);
|
|
begin
|
|
RnQVer := IntTOStr(RnQBuild) + ' ' + getTranslation('Build %d', [RnQBuildCustom]);
|
|
{$IFDEF CPUX64}
|
|
RnQVer := RnQVer + ' x64';
|
|
{$ENDIF CPUX64}
|
|
RnQVer0 := RnQVer;
|
|
RnQVerT := '';
|
|
RnQVer := RnQVer + RnQVerT;
|
|
|
|
UsersBox.NodeDataSize := SizeOf(TRnQUser);
|
|
newaccountBtn.enabled := True;
|
|
newaccountBtn.OnClick := newaccountBtnClick;
|
|
refreshAvailableUsers;
|
|
refreshUsers;
|
|
// L1.DoubleBuffered := True;
|
|
// self.DoubleBuffered := True;
|
|
// UsersBox.DoubleBuffered := True;
|
|
// PrefsPnl.DoubleBuffered := True;
|
|
// Panel1.DoubleBuffered := True;
|
|
end;
|
|
|
|
procedure TusersFrm.FormClose(Sender: TObject; var Action: TCloseAction);
|
|
begin
|
|
if not Assigned(Account.AccProto) and not selected then
|
|
Application.Terminate;
|
|
if deletedMe and not selected then
|
|
begin
|
|
hideForm(RnQmain);
|
|
quit;
|
|
end;
|
|
end;
|
|
|
|
procedure TusersFrm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
|
begin
|
|
case Key of
|
|
VK_ESCAPE:
|
|
close;
|
|
VK_DELETE:
|
|
deleteuserBtnClick(nil);
|
|
VK_INSERT:
|
|
newuserBtnClick(nil);
|
|
end;
|
|
end;
|
|
|
|
function TusersFrm.CheckPass: Boolean;
|
|
var
|
|
// a : Boolean;
|
|
pt: String;
|
|
// newAccPass : AnsiString;
|
|
begin
|
|
Result := True;
|
|
if UsersBox.FocusedNode <> NIL then
|
|
with TRnQUser(PRnQUser(UsersBox.GetNodeData(UsersBox.FocusedNode))^) do
|
|
begin
|
|
Result := not encr;
|
|
if Result then
|
|
exit;
|
|
// pt := path+ uinStr+ PathDelim + dbFilename + '5';
|
|
pt := path + SubPath + PathDelim + dbFilename + '5';
|
|
|
|
Result := CheckAccPas(uin, pt, resAccPass);
|
|
{ newAccPass := '';
|
|
if enterPwdDlg(newAccPass, getTranslation('Password') + ' (' + uinStr + ')', 16) then
|
|
if CheckZipFilePass(pt, dbFilename, newAccPass) then
|
|
begin
|
|
resAccPass := newAccPass;
|
|
Result := True
|
|
end
|
|
else
|
|
begin
|
|
Result := False;
|
|
msgDlg('Wrong password', True, mtWarning)
|
|
end
|
|
else
|
|
msgDlg('Please enter password', True, mtWarning);
|
|
}
|
|
end;
|
|
end;
|
|
|
|
function findInAvailableUsers(const uin: TUID): integer;
|
|
begin
|
|
for Result := 0 to length(availableusers) - 1 do
|
|
if availableusers[result].uin = uin then
|
|
Exit;
|
|
Result := -1;
|
|
end; // findInAvailableUsers
|
|
|
|
procedure clearAvailableUsers;
|
|
var
|
|
i: Integer;
|
|
begin
|
|
for i := 0 to Length(availableUsers)-1 do
|
|
begin
|
|
SetLength(availableUsers[i].name, 0);
|
|
// SetLength(availableUsers[i].uinStr, 0);
|
|
SetLength(availableUsers[i].SubPath, 0);
|
|
SetLength(availableUsers[i].path, 0);
|
|
SetLength(availableUsers[i].uin, 0);
|
|
SetLength(availableUsers[i].Prefix, 0);
|
|
end;
|
|
SetLength(availableUsers, 0);
|
|
end;
|
|
|
|
procedure refreshAvailableUsers;
|
|
function getNick_SSI(const path: string; const uid: TUID;
|
|
var nick: String; var isEncripted: Boolean): Boolean;
|
|
function yesno(const l: String): boolean;
|
|
begin result := LowerCase(l)='yes' end;
|
|
var
|
|
db: TRnQCList;
|
|
ini: TStrings;
|
|
zf: TZipFile;
|
|
s: AnsiString;
|
|
cf: String;
|
|
i: Integer;
|
|
// cnt: TRnQcontact;
|
|
save: Boolean;
|
|
begin
|
|
Result := False;
|
|
nick := '';
|
|
save := False;
|
|
isEncripted := False;
|
|
ini := TStringList.create;
|
|
db := nil;
|
|
cf := path + PathDelim + dbFileName + '5';
|
|
if not FileExists(cf) then
|
|
cf := path + PathDelim + dbFileName + '4';
|
|
if FileExists(cf) then
|
|
begin
|
|
zf := TZipFile.Create;
|
|
try
|
|
zf.LoadFromFile(cf);
|
|
i := zf.IndexOf('about.txt');
|
|
if i >= 0 then
|
|
begin
|
|
isEncripted := zf.IsEncrypted(i);
|
|
Result := True;
|
|
if not isEncripted then
|
|
begin
|
|
ini.Text := zf.data[i];
|
|
s := ini.values['account-name'];
|
|
nick := UnUTF(s);
|
|
end;
|
|
end;
|
|
|
|
if not Result then
|
|
begin
|
|
i := zf.IndexOf(configFileName);
|
|
if i >=0 then
|
|
begin
|
|
isEncripted := zf.IsEncrypted(i);
|
|
Result := True;
|
|
if not isEncripted then
|
|
begin
|
|
ini.Text := zf.data[i];
|
|
s := ini.values['account-name'];
|
|
nick := UnUTF(s);
|
|
end;
|
|
end;
|
|
end;
|
|
{
|
|
if not Result then
|
|
begin
|
|
i := zf.IndexOf(dbFileName);
|
|
if i >=0 then
|
|
begin
|
|
isEncripted := zf.IsEncrypted(i);
|
|
Result := True;
|
|
if not isEncripted then
|
|
begin
|
|
s := zf.data[i];
|
|
db := str2db(protoClass._getContactClass, s);
|
|
cnt := db.get(protoClass._getContactClass, uid);
|
|
if Assigned(cnt) then
|
|
nick := cnt.nick;
|
|
freeDB(db);
|
|
end;
|
|
end;
|
|
end;
|
|
}
|
|
except
|
|
s := '';
|
|
end;
|
|
zf.Free;
|
|
end;
|
|
|
|
if not Result then
|
|
begin
|
|
cf := path + PathDelim + configFileName;
|
|
if fileExists(cf) then
|
|
begin
|
|
save := True;
|
|
Result := True;
|
|
try
|
|
ini.LoadFromFile(cf);
|
|
except
|
|
ini.Clear;
|
|
end;
|
|
nick := UnUTF(ini.values['account-name']);
|
|
end
|
|
else
|
|
begin
|
|
cf := path + PathDelim +OldconfigFileName;
|
|
if fileExists(cf) then
|
|
begin
|
|
Result := True;
|
|
save := True;
|
|
ini.LoadFromFile(cf);
|
|
nick := ini.values['account-name'];
|
|
end
|
|
end;
|
|
end;
|
|
|
|
if not Result then
|
|
begin
|
|
// loadDB(path+ PathDelim, db)
|
|
begin
|
|
zf := TZipFile.Create;
|
|
try
|
|
if FileExists(path + PathDelim + dbFileName + '3') then
|
|
zf.LoadFromFile(path + PathDelim + dbFileName + '3');
|
|
i := zf.IndexOf(dbFileName);
|
|
if i >=0 then
|
|
s := zf.data[i];
|
|
except
|
|
s := '';
|
|
end;
|
|
zf.Free;
|
|
end;
|
|
if s = '' then
|
|
s := loadFileA(path+ PathDelim +dbFileName);
|
|
{
|
|
if s > '' then
|
|
begin
|
|
Result := True;
|
|
db:=str2db(protoClass._getContactClass, s);
|
|
cnt := db.get(protoClass._getContactClass, uid);
|
|
if Assigned(cnt) then
|
|
nick := cnt.nick;
|
|
end;
|
|
}
|
|
// if not result then
|
|
// nick := ' ';
|
|
if save then
|
|
begin
|
|
ini.values['account-name']:= UTF(nick);
|
|
ini.saveToFile(cf);
|
|
end;
|
|
freeDB(db);
|
|
end;
|
|
ini.free;
|
|
end; // getNick
|
|
|
|
procedure addAvailableUser(const UID: TUID; const pPath, pPrefix: String);
|
|
var
|
|
n: Integer;
|
|
begin
|
|
n := length(availableUsers);
|
|
setlength(availableUsers, n + 1);
|
|
// with availableUsers[n] do
|
|
begin
|
|
// availableUsers[n].uinStr:=extractFileName(pPath);
|
|
with availableUsers[n] do
|
|
begin
|
|
// if copy(uinStr, 1, 4) = AIMprefix then
|
|
// uinStr := copy(uinStr, 5, length(uinStr));
|
|
// uinStr:=extractFileName(pPath);
|
|
SubPath := extractFileName(pPath);
|
|
// uinStr := UID;
|
|
uin := UID;
|
|
// uid := uinStr;
|
|
getNick_SSI(pPath, UID, name, encr);
|
|
Prefix := pPrefix;
|
|
path:= ExtractFilePath(pPath);
|
|
end;
|
|
end;
|
|
end; // addAvailableUser
|
|
|
|
procedure searchIn(path: String; const Prefix: String = '');
|
|
var
|
|
sr: TsearchRec;
|
|
s: String;
|
|
s2: TUID;
|
|
begin
|
|
path := includeTrailingPathDelimiter(path);
|
|
ZeroMemory(@sr.FindData, SizeOf(TWin32FindData));
|
|
if FindFirst(path + '*', faDirectory, sr) = 0 then
|
|
repeat
|
|
if (sr.Attr and faDirectory > 0) and (sr.name <> '.')and (sr.name <> '..') then
|
|
begin
|
|
s := ExtractFileName(sr.name);
|
|
s2 := s;
|
|
if TICQSession._isProtoUid(s2) then
|
|
addAvailableUser(s2, path + sr.name, Prefix);
|
|
end;
|
|
until FindNext(sr) > 0;
|
|
FindClose(sr);
|
|
end;
|
|
|
|
var
|
|
s: String;
|
|
i, j, n: Integer;
|
|
found: Boolean;
|
|
ss: TUID;
|
|
// uid: AnsiString;
|
|
begin
|
|
clearAvailableUsers;
|
|
searchIn(myPath);
|
|
if RnQMainPath > '' then
|
|
searchIn(myPath + RnQMainPath);
|
|
|
|
// s := getSpecialFolder('AppData') + 'R&Q\';
|
|
s := getSpecialFolder(CSIDL_APPDATA) + 'R&Q\';
|
|
searchIn(s, 'App\');
|
|
|
|
if (cmdLinePar.userPath > '') and not AnsiSameText(cmdLinePar.userPath, usersPath) then
|
|
if LowerCase(s) <> LowerCase(cmdLinePar.userPath) then
|
|
searchIn(cmdLinePar.userPath, 'User\');
|
|
|
|
s := usersPath;
|
|
while s > '' do
|
|
searchIn(chop(';',s), 'Users path\');
|
|
|
|
s := mypath + accountsPath;
|
|
if s <> usersPath then
|
|
while s>'' do
|
|
searchIn(chop(';',s));
|
|
|
|
if cmdLinePar.startUser > '' then
|
|
begin
|
|
found := False;
|
|
for n := 0 to length(availableUsers) - 1 do
|
|
begin
|
|
ss := cmdLinePar.startUser;
|
|
if TICQSession._isProtoUid(ss) and (availableUsers[n].uin = ss) then
|
|
found := True;
|
|
end;
|
|
if not found then
|
|
begin
|
|
// fantomWork := True;
|
|
addAvailableUser(cmdLinePar.startUser, myPath + cmdLinePar.startUser, 'CMD\');
|
|
end;
|
|
end;
|
|
|
|
n := length(availableUsers);
|
|
for i := 0 to n - 2 do
|
|
for j := i + 1 to n - 1 do
|
|
swap4(availableUsers[i], availableUsers[j], sizeOf(availableUsers[i]), availableUsers[i].uin > availableUsers[j].uin);
|
|
end; // refreshAvailableUsers
|
|
|
|
function getUserAutoStart(var pass: String): TUID;
|
|
var
|
|
i: Integer;
|
|
begin
|
|
refreshAvailableUsers;
|
|
Result := '';
|
|
// AccPass := '';
|
|
pass := '';
|
|
// needCheckPass := True;
|
|
if cmdlinepar.startUser > '' then
|
|
Result := extractFileName(cmdlinepar.startuser)
|
|
else
|
|
begin
|
|
i := findInAvailableUsers(autostartUIN);
|
|
if i >= 0 then
|
|
Result := autostartUIN
|
|
else if length(availableusers) = 1 then
|
|
Result := availableusers[0].uin;
|
|
end;
|
|
if Result > '' then
|
|
begin
|
|
i := findInAvailableUsers(Result);
|
|
if i >=0 then
|
|
begin
|
|
// if needCheckPass then
|
|
with availableUsers[i] do
|
|
if encr and not CheckAccPas(uin, path+ SubPath + PathDelim + dbFilename + '5', pass) then
|
|
begin
|
|
// halt(0);
|
|
Result := '';
|
|
end;
|
|
end else
|
|
Result := '';
|
|
end;
|
|
end;
|
|
|
|
end.
|