Subversion Repositories userdetect2

Rev

Rev 81 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 81 Rev 82
1
unit UD2_PluginUtils;
1
unit UD2_PluginUtils;
2
 
2
 
3
interface
3
interface
4
 
4
 
5
{$IF CompilerVersion >= 25.0}
5
{$IF CompilerVersion >= 25.0}
6
{$LEGACYIFEND ON}
6
{$LEGACYIFEND ON}
7
{$IFEND}
7
{$IFEND}
8
 
8
 
9
{$WARN UNSAFE_CODE OFF}
-
 
10
{$WARN UNSAFE_TYPE OFF}
-
 
11
 
-
 
12
uses
9
uses
13
  Windows, Classes, UD2_PluginIntf, UD2_PluginStatus;
10
  Windows, Classes, UD2_PluginIntf, UD2_PluginStatus;
14
 
11
 
15
function UD2_WritePascalStringToPointerW(lpDestination: LPWSTR; cchSize: DWORD; stSource: WideString): UD2_STATUS;
12
function UD2_WritePascalStringToPointerW(lpDestination: LPWSTR; cchSize: DWORD; stSource: WideString): UD2_STATUS;
16
 
13
 
17
function UD2_WriteStringListToPointerW(lpDestination: LPWSTR; cchSize: DWORD; slSource: TStrings): UD2_STATUS;
14
function UD2_WriteStringListToPointerW(lpDestination: LPWSTR; cchSize: DWORD; slSource: TStrings): UD2_STATUS;
18
 
15
 
19
implementation
16
implementation
20
 
17
 
21
uses
18
uses
22
  Math;
19
  Math;
23
 
20
 
24
function UD2_IsMultiLineW(s: WideString): boolean;
21
function UD2_IsMultiLineW(s: WideString): boolean;
25
var
22
var
26
  i: integer;
23
  i: integer;
27
  c: WideChar;
24
  c: WideChar;
28
begin
25
begin
29
  for i := 1 to Length(s) do
26
  for i := 1 to Length(s) do
30
  begin
27
  begin
31
    c := s[i];
28
    c := s[i];
32
    if c = UD2_MULTIPLE_ITEMS_DELIMITER then //if (c = #10) or (c = #13) then
29
    if c = UD2_MULTIPLE_ITEMS_DELIMITER then //if (c = #10) or (c = #13) then
33
    begin
30
    begin
34
      Result := true;
31
      Result := true;
35
      Exit;
32
      Exit;
36
    end;
33
    end;
37
  end;
34
  end;
38
  Result := false;
35
  Result := false;
39
end;
36
end;
40
 
37
 
41
function UD2_WritePascalStringToPointerW(lpDestination: LPWSTR; cchSize: DWORD;
38
function UD2_WritePascalStringToPointerW(lpDestination: LPWSTR; cchSize: DWORD;
42
  stSource: WideString): UD2_STATUS;
39
  stSource: WideString): UD2_STATUS;
43
var
40
var
44
  cchSource: DWORD;
41
  cchSource: DWORD;
45
  cchCopy: DWORD;
42
  cchCopy: DWORD;
46
begin
43
begin
47
  if cchSize = 0 then
44
  if cchSize = 0 then
48
  begin
45
  begin
49
    result := UD2_STATUS_FAILURE_INVALID_ARGS;
46
    result := UD2_STATUS_FAILURE_INVALID_ARGS;
50
    Exit;
47
    Exit;
51
  end;
48
  end;
52
 
49
 
53
  cchSource := Cardinal(Length(stSource));
50
  cchSource := Cardinal(Length(stSource));
54
  cchCopy   := Cardinal(Min(cchSource, cchSize));
51
  cchCopy   := Cardinal(Min(cchSource, cchSize));
55
  if cchCopy > 0 then
52
  if cchCopy > 0 then
56
  begin
53
  begin
57
    CopyMemory(lpDestination, @stSource[1], cchCopy*SizeOf(WideChar));
54
    CopyMemory(lpDestination, @stSource[1], cchCopy*SizeOf(WideChar));
58
  end;
55
  end;
59
  lpDestination[cchCopy] := #0;
56
  lpDestination[cchCopy] := #0;
60
 
57
 
61
  if cchSource >= cchSize then
58
  if cchSource >= cchSize then
62
    result := UD2_STATUS_FAILURE_BUFFER_TOO_SMALL
59
    result := UD2_STATUS_FAILURE_BUFFER_TOO_SMALL
63
  else if stSource = '' then
60
  else if stSource = '' then
64
    result := UD2_STATUS_NOTAVAIL_UNSPECIFIED
61
    result := UD2_STATUS_NOTAVAIL_UNSPECIFIED
65
  else if UD2_IsMultiLineW(stSource) then
62
  else if UD2_IsMultiLineW(stSource) then
66
    result := UD2_STATUS_OK_MULTILINE
63
    result := UD2_STATUS_OK_MULTILINE
67
  else
64
  else
68
    result := UD2_STATUS_OK_SINGLELINE;
65
    result := UD2_STATUS_OK_SINGLELINE;
69
end;
66
end;
70
 
67
 
71
function UD2_WriteStringListToPointerW(lpDestination: LPWSTR; cchSize: DWORD;
68
function UD2_WriteStringListToPointerW(lpDestination: LPWSTR; cchSize: DWORD;
72
  slSource: TStrings): UD2_STATUS;
69
  slSource: TStrings): UD2_STATUS;
73
var
70
var
74
  stSource: WideString;
71
  stSource: WideString;
75
  i: integer;
72
  i: integer;
76
begin
73
begin
77
  stSource := '';
74
  stSource := '';
78
  for i := 0 to slSource.Count-1 do
75
  for i := 0 to slSource.Count-1 do
79
  begin
76
  begin
80
    if i > 0 then stSource := stSource + UD2_MULTIPLE_ITEMS_DELIMITER;
77
    if i > 0 then stSource := stSource + UD2_MULTIPLE_ITEMS_DELIMITER;
81
    stSource := stSource + slSource.Strings[i];
78
    stSource := stSource + slSource.Strings[i];
82
  end;
79
  end;
83
  result := UD2_WritePascalStringToPointerW(lpDestination, cchSize, stSource);
80
  result := UD2_WritePascalStringToPointerW(lpDestination, cchSize, stSource);
84
end;
81
end;
85
 
82
 
86
end.
83
end.
87
 
84