Subversion Repositories userdetect2

Rev

Rev 70 | Rev 80 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 70 Rev 71
Line 7... Line 7...
7
{$IFEND}
7
{$IFEND}
8
 
8
 
9
{$INCLUDE 'UserDetect2.inc'}
9
{$INCLUDE 'UserDetect2.inc'}
10
 
10
 
11
uses
11
uses
12
  Windows, SysUtils, Classes, IniFiles, Contnrs, Dialogs, UD2_PluginIntf;
12
  Windows, SysUtils, Classes, IniFiles, Contnrs, Dialogs, UD2_PluginIntf,
-
 
13
  UD2_PluginStatus;
13
 
14
 
14
const
15
const
15
  cchBufferSize = 32768;
16
  cchBufferSize = 32768;
16
 
17
 
17
type
18
type
Line 75... Line 76...
75
    function ReadMetatagString(ShortTaskName, MetatagName: string;
76
    function ReadMetatagString(ShortTaskName, MetatagName: string;
76
      DefaultVal: string): string;
77
      DefaultVal: string): string;
77
    function ReadMetatagBool(ShortTaskName, MetatagName: string;
78
    function ReadMetatagBool(ShortTaskName, MetatagName: string;
78
      DefaultVal: string): boolean;
79
      DefaultVal: string): boolean;
79
    function GetTaskName(AShortTaskName: string): string;
80
    function GetTaskName(AShortTaskName: string): string;
80
    class function GenericErrorLookup(dwStatus: UD2_STATUS): string;
81
    class function GenericErrorLookup(grStatus: UD2_STATUS): string;
81
  end;
82
  end;
82
 
83
 
83
implementation
84
implementation
84
 
85
 
85
uses
86
uses
Line 97... Line 98...
97
    Errors: TStringList;
98
    Errors: TStringList;
98
    constructor Create(Suspended: boolean; DLL: string; alngid: LANGID);
99
    constructor Create(Suspended: boolean; DLL: string; alngid: LANGID);
99
    destructor Destroy; override;
100
    destructor Destroy; override;
100
  end;
101
  end;
101
 
102
 
102
class function TUD2.GenericErrorLookup(dwStatus: UD2_STATUS): string;
103
class function TUD2.GenericErrorLookup(grStatus: UD2_STATUS): string;
103
resourcestring
104
resourcestring
104
  LNG_STATUS_OK_UNSPECIFIED            = 'Unspecified generic success';
105
  LNG_STATUS_OK_UNSPECIFIED               = 'Unspecified generic success';
105
  LNG_STATUS_OK_SINGLELINE             = 'Operation successful; one identifier returned';
106
  LNG_STATUS_OK_SINGLELINE                = 'Operation successful; one identifier returned';
106
  LNG_STATUS_OK_MULTILINE              = 'Operation successful; multiple identifiers returned';
107
  LNG_STATUS_OK_MULTILINE                 = 'Operation successful; multiple identifiers returned';
107
 
108
 
108
  LNG_STATUS_NOTAVAIL_UNSPECIFIED      = 'Unspecified generic "not available" status';
109
  LNG_STATUS_NOTAVAIL_UNSPECIFIED         = 'Unspecified generic "not available" status';
109
  LNG_STATUS_NOTAVAIL_OS_NOT_SUPPORTED = 'Operating system not supported';
110
  LNG_STATUS_NOTAVAIL_OS_NOT_SUPPORTED    = 'Operating system not supported';
110
  LNG_STATUS_NOTAVAIL_HW_NOT_SUPPORTED = 'Hardware not supported';
111
  LNG_STATUS_NOTAVAIL_HW_NOT_SUPPORTED    = 'Hardware not supported';
111
  LNG_STATUS_NOTAVAIL_NO_ENTITIES      = 'No entities to identify';
112
  LNG_STATUS_NOTAVAIL_NO_ENTITIES         = 'No entities to identify';
112
  LNG_STATUS_NOTAVAIL_API_CALL_FAILURE = 'An API call failed';
113
  LNG_STATUS_NOTAVAIL_WINAPI_CALL_FAILURE = 'A Windows API call failed. Message: %s';
113
 
114
 
114
  LNG_STATUS_ERROR_UNSPECIFIED         = 'Unspecified generic error';
115
  LNG_STATUS_ERROR_UNSPECIFIED            = 'Unspecified generic error';
115
  LNG_STATUS_ERROR_BUFFER_TOO_SMALL    = 'The provided buffer is too small!';
116
  LNG_STATUS_ERROR_BUFFER_TOO_SMALL       = 'The provided buffer is too small!';
116
  LNG_STATUS_ERROR_INVALID_ARGS        = 'The function received invalid arguments!';
117
  LNG_STATUS_ERROR_INVALID_ARGS           = 'The function received invalid arguments!';
117
  LNG_STATUS_ERROR_PLUGIN_NOT_LICENSED = 'The plugin is not licensed';
118
  LNG_STATUS_ERROR_PLUGIN_NOT_LICENSED    = 'The plugin is not licensed';
118
 
119
 
119
  LNG_UNKNOWN_SUCCESS                  = 'Unknown "success" status code %s';
120
  LNG_UNKNOWN_SUCCESS                     = 'Unknown "success" status code %s';
120
  LNG_UNKNOWN_NOTAVAIL                 = 'Unknown "not available" status code %s';
121
  LNG_UNKNOWN_NOTAVAIL                    = 'Unknown "not available" status code %s';
121
  LNG_UNKNOWN_FAILED                   = 'Unknown "failed" status code %s';
122
  LNG_UNKNOWN_FAILED                      = 'Unknown "failure" status code %s';
122
  LNG_UNKNOWN_STATUS                   = 'Unknown status code with unexpected category: %s';
123
  LNG_UNKNOWN_STATUS                      = 'Unknown status code with unexpected category: %s';
123
begin
124
begin
124
       if dwStatus = UD2_STATUS_OK_UNSPECIFIED            then result := LNG_STATUS_OK_UNSPECIFIED
125
       if UD2_STATUS_Equal(grStatus, UD2_STATUS_OK_UNSPECIFIED, false)               then result := LNG_STATUS_OK_UNSPECIFIED
125
  else if dwStatus = UD2_STATUS_OK_SINGLELINE             then result := LNG_STATUS_OK_SINGLELINE
126
  else if UD2_STATUS_Equal(grStatus, UD2_STATUS_OK_SINGLELINE, false)                then result := LNG_STATUS_OK_SINGLELINE
126
  else if dwStatus = UD2_STATUS_OK_MULTILINE              then result := LNG_STATUS_OK_MULTILINE
127
  else if UD2_STATUS_Equal(grStatus, UD2_STATUS_OK_MULTILINE, false)                 then result := LNG_STATUS_OK_MULTILINE
127
 
128
 
128
  else if dwStatus = UD2_STATUS_NOTAVAIL_UNSPECIFIED      then result := LNG_STATUS_NOTAVAIL_UNSPECIFIED
129
  else if UD2_STATUS_Equal(grStatus, UD2_STATUS_NOTAVAIL_UNSPECIFIED, false)         then result := LNG_STATUS_NOTAVAIL_UNSPECIFIED
129
  else if dwStatus = UD2_STATUS_NOTAVAIL_OS_NOT_SUPPORTED then result := LNG_STATUS_NOTAVAIL_OS_NOT_SUPPORTED
130
  else if UD2_STATUS_Equal(grStatus, UD2_STATUS_NOTAVAIL_OS_NOT_SUPPORTED, false)    then result := LNG_STATUS_NOTAVAIL_OS_NOT_SUPPORTED
130
  else if dwStatus = UD2_STATUS_NOTAVAIL_HW_NOT_SUPPORTED then result := LNG_STATUS_NOTAVAIL_HW_NOT_SUPPORTED
131
  else if UD2_STATUS_Equal(grStatus, UD2_STATUS_NOTAVAIL_HW_NOT_SUPPORTED, false)    then result := LNG_STATUS_NOTAVAIL_HW_NOT_SUPPORTED
131
  else if dwStatus = UD2_STATUS_NOTAVAIL_NO_ENTITIES      then result := LNG_STATUS_NOTAVAIL_NO_ENTITIES
132
  else if UD2_STATUS_Equal(grStatus, UD2_STATUS_NOTAVAIL_NO_ENTITIES, false)         then result := LNG_STATUS_NOTAVAIL_NO_ENTITIES
132
  else if dwStatus = UD2_STATUS_NOTAVAIL_API_CALL_FAILURE then result := LNG_STATUS_NOTAVAIL_API_CALL_FAILURE
133
  else if UD2_STATUS_Equal(grStatus, UD2_STATUS_NOTAVAIL_WINAPI_CALL_FAILURE, false) then result := Format(LNG_STATUS_NOTAVAIL_WINAPI_CALL_FAILURE, [FormatOSError(grStatus.dwExtraInfo)])
133
 
134
 
134
  else if dwStatus = UD2_STATUS_ERROR_UNSPECIFIED         then result := LNG_STATUS_ERROR_UNSPECIFIED
135
  else if UD2_STATUS_Equal(grStatus, UD2_STATUS_FAILURE_UNSPECIFIED, false)          then result := LNG_STATUS_ERROR_UNSPECIFIED
135
  else if dwStatus = UD2_STATUS_ERROR_BUFFER_TOO_SMALL    then result := LNG_STATUS_ERROR_BUFFER_TOO_SMALL
136
  else if UD2_STATUS_Equal(grStatus, UD2_STATUS_FAILURE_BUFFER_TOO_SMALL, false)     then result := LNG_STATUS_ERROR_BUFFER_TOO_SMALL
136
  else if dwStatus = UD2_STATUS_ERROR_INVALID_ARGS        then result := LNG_STATUS_ERROR_INVALID_ARGS
137
  else if UD2_STATUS_Equal(grStatus, UD2_STATUS_FAILURE_INVALID_ARGS, false)         then result := LNG_STATUS_ERROR_INVALID_ARGS
137
  else if dwStatus = UD2_STATUS_ERROR_PLUGIN_NOT_LICENSED then result := LNG_STATUS_ERROR_PLUGIN_NOT_LICENSED
138
  else if UD2_STATUS_Equal(grStatus, UD2_STATUS_FAILURE_PLUGIN_NOT_LICENSED, false)  then result := LNG_STATUS_ERROR_PLUGIN_NOT_LICENSED
138
 
139
 
139
  else if UD2_STATUS_Successful(dwStatus) then result := Format(LNG_UNKNOWN_SUCCESS,  [UD2_STATUS_FormatStatusCode(dwStatus)])
140
  else if grStatus.wCategory = UD2_STATUSCAT_SUCCESS   then result := Format(LNG_UNKNOWN_SUCCESS,  [UD2_STATUS_FormatStatusCode(grStatus)])
140
  else if UD2_STATUS_NotAvail(dwStatus)   then result := Format(LNG_UNKNOWN_NOTAVAIL, [UD2_STATUS_FormatStatusCode(dwStatus)])
141
  else if grStatus.wCategory = UD2_STATUSCAT_NOT_AVAIL then result := Format(LNG_UNKNOWN_NOTAVAIL, [UD2_STATUS_FormatStatusCode(grStatus)])
141
  else if UD2_STATUS_Failed(dwStatus)     then result := Format(LNG_UNKNOWN_FAILED,   [UD2_STATUS_FormatStatusCode(dwStatus)])
142
  else if grStatus.wCategory = UD2_STATUSCAT_FAILED    then result := Format(LNG_UNKNOWN_FAILED,   [UD2_STATUS_FormatStatusCode(grStatus)])
142
  else                                         result := Format(LNG_UNKNOWN_STATUS,   [UD2_STATUS_FormatStatusCode(dwStatus)]);
143
  else                                                      result := Format(LNG_UNKNOWN_STATUS,   [UD2_STATUS_FormatStatusCode(grStatus)]);
143
end;
144
end;
144
 
145
 
145
{ TUD2Plugin }
146
{ TUD2Plugin }
146
 
147
 
147
function TUD2Plugin.PluginGUIDString: string;
148
function TUD2Plugin.PluginGUIDString: string;
Line 569... Line 570...
569
      end;
570
      end;
570
      pl.PluginGUID := fPluginIdentifier();
571
      pl.PluginGUID := fPluginIdentifier();
571
    end;
572
    end;
572
 
573
 
573
    statusCode := fCheckLicense(nil);
574
    statusCode := fCheckLicense(nil);
574
    if UD2_STATUS_Failed(statusCode) then
575
    if statusCode.wCategory = UD2_STATUSCAT_FAILED then
575
    begin
576
    begin
576
      Errors.Add(Format(LNG_METHOD_FAILURE, [_ErrorLookup(statusCode), mnCheckLicense, dllFile]));
577
      Errors.Add(Format(LNG_METHOD_FAILURE, [_ErrorLookup(statusCode), mnCheckLicense, dllFile]));
577
      Exit;
578
      Exit;
578
    end;
579
    end;
579
 
580
 
580
    statusCode := fPluginNameW(@buf, cchBufferSize, lngID);
581
    statusCode := fPluginNameW(@buf, cchBufferSize, lngID);
581
         if UD2_STATUS_Successful(statusCode) then pl.PluginName := PWideChar(@buf)
582
         if statusCode.wCategory = UD2_STATUSCAT_SUCCESS   then pl.PluginName := PWideChar(@buf)
582
    else if UD2_STATUS_NotAvail(statusCode)   then pl.PluginName := ''
583
    else if statusCode.wCategory = UD2_STATUSCAT_NOT_AVAIL then pl.PluginName := ''
583
    else
584
    else
584
    begin
585
    begin
585
      Errors.Add(Format(LNG_METHOD_FAILURE, [_ErrorLookup(statusCode), mnPluginNameW, dllFile]));
586
      Errors.Add(Format(LNG_METHOD_FAILURE, [_ErrorLookup(statusCode), mnPluginNameW, dllFile]));
586
      Exit;
587
      Exit;
587
    end;
588
    end;
588
 
589
 
589
    statusCode := fPluginVendorW(@buf, cchBufferSize, lngID);
590
    statusCode := fPluginVendorW(@buf, cchBufferSize, lngID);
590
         if UD2_STATUS_Successful(statusCode) then pl.PluginVendor := PWideChar(@buf)
591
         if statusCode.wCategory = UD2_STATUSCAT_SUCCESS   then pl.PluginVendor := PWideChar(@buf)
591
    else if UD2_STATUS_NotAvail(statusCode)   then pl.PluginVendor := ''
592
    else if statusCode.wCategory = UD2_STATUSCAT_NOT_AVAIL then pl.PluginVendor := ''
592
    else
593
    else
593
    begin
594
    begin
594
      Errors.Add(Format(LNG_METHOD_FAILURE, [_ErrorLookup(statusCode), mnPluginVendorW, dllFile]));
595
      Errors.Add(Format(LNG_METHOD_FAILURE, [_ErrorLookup(statusCode), mnPluginVendorW, dllFile]));
595
      Exit;
596
      Exit;
596
    end;
597
    end;
597
 
598
 
598
    statusCode := fPluginVersionW(@buf, cchBufferSize, lngID);
599
    statusCode := fPluginVersionW(@buf, cchBufferSize, lngID);
599
         if UD2_STATUS_Successful(statusCode) then pl.PluginVersion := PWideChar(@buf)
600
         if statusCode.wCategory = UD2_STATUSCAT_SUCCESS   then pl.PluginVersion := PWideChar(@buf)
600
    else if UD2_STATUS_NotAvail(statusCode)   then pl.PluginVersion := ''
601
    else if statusCode.wCategory = UD2_STATUSCAT_NOT_AVAIL then pl.PluginVersion := ''
601
    else
602
    else
602
    begin
603
    begin
603
      Errors.Add(Format(LNG_METHOD_FAILURE, [_ErrorLookup(statusCode), mnPluginVersionW, dllFile]));
604
      Errors.Add(Format(LNG_METHOD_FAILURE, [_ErrorLookup(statusCode), mnPluginVersionW, dllFile]));
604
      Exit;
605
      Exit;
605
    end;
606
    end;
606
 
607
 
607
    statusCode := fIdentificationMethodNameW(@buf, cchBufferSize);
608
    statusCode := fIdentificationMethodNameW(@buf, cchBufferSize);
608
         if UD2_STATUS_Successful(statusCode) then pl.IdentificationMethodName := PWideChar(@buf)
609
         if statusCode.wCategory = UD2_STATUSCAT_SUCCESS   then pl.IdentificationMethodName := PWideChar(@buf)
609
    else if UD2_STATUS_NotAvail(statusCode)   then pl.IdentificationMethodName := ''
610
    else if statusCode.wCategory = UD2_STATUSCAT_NOT_AVAIL then pl.IdentificationMethodName := ''
610
    else
611
    else
611
    begin
612
    begin
612
      Errors.Add(Format(LNG_METHOD_FAILURE, [_ErrorLookup(statusCode), mnIdentificationMethodNameW, dllFile]));
613
      Errors.Add(Format(LNG_METHOD_FAILURE, [_ErrorLookup(statusCode), mnIdentificationMethodNameW, dllFile]));
613
      Exit;
614
      Exit;
614
    end;
615
    end;
615
 
616
 
616
    statusCode := fIdentificationStringW(@buf, cchBufferSize);
617
    statusCode := fIdentificationStringW(@buf, cchBufferSize);
617
    pl.IdentificationProcedureStatusCode := statusCode;
618
    pl.IdentificationProcedureStatusCode := statusCode;
618
    pl.IdentificationProcedureStatusCodeDescribed := _ErrorLookup(statusCode);
619
    pl.IdentificationProcedureStatusCodeDescribed := _ErrorLookup(statusCode);
619
    if UD2_STATUS_Successful(statusCode) then
620
    if statusCode.wCategory = UD2_STATUSCAT_SUCCESS then
620
    begin
621
    begin
621
      sIdentifier := PWideChar(@buf);
622
      sIdentifier := PWideChar(@buf);
622
      if statusCode = UD2_STATUS_OK_MULTILINE then
623
      if UD2_STATUS_Equal(statusCode, UD2_STATUS_OK_MULTILINE, false) then
623
      begin
624
      begin
624
        // Multiple identifiers (e.g. multiple MAC addresses are delimited via UD2_MULTIPLE_ITEMS_DELIMITER)
625
        // Multiple identifiers (e.g. multiple MAC addresses are delimited via UD2_MULTIPLE_ITEMS_DELIMITER)
625
        SetLength(sIdentifiers, 0);
626
        SetLength(sIdentifiers, 0);
626
        sIdentifiers := SplitString(UD2_MULTIPLE_ITEMS_DELIMITER, sIdentifier);
627
        sIdentifiers := SplitString(UD2_MULTIPLE_ITEMS_DELIMITER, sIdentifier);
627
        for i := Low(sIdentifiers) to High(sIdentifiers) do
628
        for i := Low(sIdentifiers) to High(sIdentifiers) do
Line 632... Line 633...
632
      else
633
      else
633
      begin
634
      begin
634
        pl.AddIdentification(sIdentifier);
635
        pl.AddIdentification(sIdentifier);
635
      end;
636
      end;
636
    end
637
    end
637
    else if not UD2_STATUS_NotAvail(statusCode) then
638
    else if statusCode.wCategory <> UD2_STATUSCAT_NOT_AVAIL then
638
    begin
639
    begin
639
      // Errors.Add(Format(LNG_METHOD_FAILURE, [_ErrorLookup(statusCode), mnIdentificationStringW, dllFile]));
640
      // Errors.Add(Format(LNG_METHOD_FAILURE, [_ErrorLookup(statusCode), mnIdentificationStringW, dllFile]));
640
      Errors.Add(Format(LNG_METHOD_FAILURE, [pl.IdentificationProcedureStatusCodeDescribed, mnIdentificationStringW, dllFile]));
641
      Errors.Add(Format(LNG_METHOD_FAILURE, [pl.IdentificationProcedureStatusCodeDescribed, mnIdentificationStringW, dllFile]));
641
      Exit;
642
      Exit;
642
    end;
643
    end;