NUtils.pas ( File view )

  • By adm.maniaco 2014-09-01
  • View(s):170
  • Download(s):11
  • Point(s): 2
			unit NUtils;

interface
uses Math, Forms, Types, SysUtils, Graphics, Windows, Classes, NCore;

//-------------------------------------
// Settings
//-------------------------------------
const
 Epsilon   = 1.0E-12;
 
type
  TFileVersionInfo = record
   FCompanyName      : string;
   FFileDescription  : string;
   FFileVersion      : string;
   FInternalName     : string;
   FLegalCopyright   : string;
   FLegalTradeMarks  : string;
   FOriginalFilename : string;
   FProductName      : string;
   FProductVersion   : string;
   FComments         : string;
   FIsRegistered     : string;
  end;

  TScannerMode = record
   Name: String;
   Code: Integer;
  end;

  TArrayOfTScannerMode = array of TScannerMode;

//-------------------------------------
// Functions (external)
//-------------------------------------
function  NSucceeded(Res: Integer): Boolean;
function  NFailed(Res: Integer): Boolean;
procedure NRaiseError(Err: Integer);
procedure NCheck(Res: Integer);

procedure ObtainLicenses(licenses: TArrayOfStrings);
procedure ReleaseLicenses(licenses: TArrayOfStrings);

function  ExtractionStatusToStr(err: TNleExtractionStatus): String;

function  MatchingThresholdToString(value: Integer): string;
function  MatchingThresholdFromString(value: string): Integer;

function  MaximalRotationFromDegrees(value: Integer): Byte;
function  MaximalRotationToDegrees(value: Byte): Integer;

function  QualityToPercent(value: byte): Integer;
function  QualityFromPercent(value: integer) : Byte;

procedure FillScannerModes(var scannerModes: TArrayOfTScannerMode);

function  GetVersionInfo(const FileName: String): TFileVersionInfo;
procedure QuickSort(var A: TArrayOfMatchResult; L, R: Integer; var tmp: TMatchResult);
function  LocalAppDataPath : string;

//-------------------------------------
// Implementation of functions
//-------------------------------------
implementation
 uses NExtractors, NLicensing, SHFolder;

 const
   LicensingConfiguration = 'NLicenses.cfg';

 type
  TListElement = class
    private
      // The data fields of this new class
      _name   : String;
      _value  : String;

    public
      // Properties to read these data values
      property Name : String
          read _name write _name;
      property Value : String
          read _value write _value;

  end;
  
 var _licenseCfg: TList;

procedure Split
   (const Delimiter: Char;
    Input: string;
    const Strings: TStrings) ;
begin
   Assert(Assigned(Strings)) ;
   Strings.Clear;
   Strings.Delimiter := Delimiter;
   Strings.DelimitedText := Input;
end;

function LocalAppDataPath : string;
const
   SHGFP_TYPE_CURRENT = 0;
var
   path: array [0..MAX_PATH] of char;
begin
    SHGetFolderPath(0, CSIDL_LOCAL_APPDATA, 0, SHGFP_TYPE_CURRENT, @path[0]) ;
    Result := path;
end;

procedure loadConfiguration();
 var pathExe: String;
     fileData : TStringList;
     splitted: TStringList;
     i, count: Integer;
     line, trimmed: String;
     el: TListElement;
begin
  pathExe := ExtractFilePath(Application.ExeName) + LicensingConfiguration;
  if (not FileExists(pathExe)) then
     NRaiseError(-1);
  fileData := TStringList.Create;
  fileData.LoadFromFile(pathExe);
  count := fileData.Count;
  _licenseCfg := TList.Create;
  for i := 0 to count - 1 do
  begin
    line := fileData[i];
    
    trimmed := Trim(line);
    if (Length(trimmed) = 0) or (trimmed[1] = '#') then Continue;
    
    splitted := TStringList.Create;
    try
     Split('=', line, splitted);
     if (splitted.Count > 0) then
     begin
      el := TListElement.Create;
      el.Name := Trim(splitted[0]);
      if (splitted.Count > 1) then
        el.Value := Trim(splitted[1]);
      _licenseCfg.Add(el);
     end;
    finally
     splitted.Free;
    end;
  end;
end;

function findKey(key: String): String;
 var i: Integer;
     el: TListElement;
begin
 for i := 0 to _licenseCfg.Count - 1 do
 begin
  el := _licenseCfg[i];
  if (el._name = key) then
  begin
   Result := el._value;
   Exit;
  end;
 end;
 Result := '';
end;

procedure ObtainLicenses(licenses: TArrayOfStrings);
 var i, j, count: Integer;
     obtained: Boolean;
     licenseAddress, licensePort: String;
begin

 if (_licenseCfg = nil) then
 begin
   loadConfiguration();
 end;

 count := Length(licenses);

 for i := 0 to count - 1 do
 begin
   licenses[i] := findKey(licenses[i]);
 end;

 // remove duplicates
 for i := 0 to count - 2 do
 begin
   if (licenses[i] = '') then
    Continue;
   for j := i + 1 to count - 1 do
   begin
    if (licenses[i] = licenses[j]) then
     licenses[j] := '';
   end;
 end;

 licenseAddress := findKey('Address');
 licensePort := findKey('Port');

 for i := 0 to count - 1 do
 begin
  if (licenses[i] ='') then
    continue;

  obtained := NLicenseObtain(licenseAddress, licensePort, licenses[i]);
  if (not obtained) then
   raise Exception.CreateFmt('license for %s was not obtained',
    [licenses[i]]);
 end;
end;

procedure ReleaseLicenses(licenses: TArrayOfStrings);
 var i, count: Integer;
begin
 count := Length(licenses);
 for  i := 0 to count - 1 do
 begin
  if (licenses[i] = '') then
    Continue;
  NLicenseRelease(licenses[i]);
 end;
end;

function MatchingThresholdToString(value: Integer): string;
 var p : double;
     tmp: integer;
     tmp2: Double;
     str: string;
begin
 p := - value / 12.0;
 tmp := Max(0, Ceil(-p) - 2);
 tmp2 := Power(10, p)*100;
 str := '%.'+IntToStr(tmp)+'f';
 str := Format(str,[tmp2]);
 Result := str;
end;

function MatchingThresholdFromString(value: string): Integer;
 var p: double;
begin
 p := Log10(Max(Epsilon,Min(1,StrToFloat(Trim(value))/100)));
 Result := Max(0, Round(-12 * p));
end;

function ExtractionStatusToStr(err: TNleExtractionStatus): String;
begin
  case err of
   nleesNone: Result := 'None.';
   nleesTemplateCreated: Result := 'Template created.';
   nleesFaceNotDetected: Result := 'Face not detected.';
   nleesEyesNotDetected: Result := 'Eyes not detected.';
   nleesFaceTooCloseToImageBorder: Result := 'Face too close to image border.';
   nleesQualityCheckGrayscaleDensityFailed: Result := 'Quality check - grayscale density failed.';
   nleesQualityCheckExposureFailed: Result := 'Quality check - exposure failed.';
   nleesQualityCheckSharpnessFailed: Result := 'Quality check - sharpness failed.';
   nleesLivenessCheckFailed: Result := 'Liveness check failed.';
  else
     Result := 'Unknown.';
 end;
end;

function NSucceeded(Res: Integer): Boolean;
begin
  Result := Res >= 0;
end;

function NFailed(Res: Integer): Boolean;
begin
  Result := Res < 0;
end;

procedure NRaiseError(Err: Integer);
begin
  raise Exception.CreateFmt('Error:'#13#10' Code = %d'#13#10' ' + NErrorGetDefaultMessage(Err),
    [Err]);
end;

function QualityToPercent(value: byte): Integer;
begin
 Result := (2 * value * 100 + 255) div (2 * 255);
end;

function QualityFromPercent(value: integer) : Byte;
begin
 Result := Byte((2 * value * 255 + 100) div (2 * 100));
end;

function MaximalRotationToDegrees(value: Byte): Integer;
begin
 Result := (2*value*360 + 256) div (2*256);
end;

function MaximalRotationFromDegrees(value: Integer): Byte;
begin
  Result := Byte((2 * value * 256 + 360) div (2 * 360));
end;

procedure FillScannerModes(var scannerModes: TArrayOfTScannerMode);
 var ExtractorStruct: TScannerMode;
begin
 SetLength(scannerModes, 22);

 ExtractorStruct.Name := 'General';
 ExtractorStruct.Code := NFE_MODE_GENERAL;
 scannerModes[0] := ExtractorStruct;

 ExtractorStruct.Name := 'Digital Persona UareU';
 ExtractorStruct.Code := NFE_MODE_DIGITALPERSONA_UAREU;
 scannerModes[1] := ExtractorStruct;

 ExtractorStruct.Name := 'Biometrika FX2000';
 ExtractorStruct.Code := NFE_MODE_BIOMETRIKA_FX2000;
 scannerModes[2] := ExtractorStruct;

 ExtractorStruct.Name := 'Biometrika FX3000';
 ExtractorStruct.Code := NFE_MODE_BIOMETRIKA_FX3000;
 scannerModes[3] := ExtractorStruct;

 ExtractorStruct.Name := 'Keytronic Secure Desktop';
 ExtractorStruct.Code := NFE_MODE_KEYTRONIC_SECUREDESKTOP;
 scannerModes[4] := ExtractorStruct;

 ExtractorStruct.Name := 'Identix Touch View';
 ExtractorStruct.Code := NFE_MODE_IDENTIX_TOUCHVIEW;
 scannerModes[5] := ExtractorStruct;

 ExtractorStruct.Name := 'Identix DFR2090';
 ExtractorStruct.Code := NFE_MODE_IDENTIX_DFR2090;
 scannerModes[6] := ExtractorStruct;

 ExtractorStruct.Name := 'Precise Biometrics 100CS';
 ExtractorStruct.Code := NFE_MODE_PRECISEBIOMETRICS_100CS;
 scannerModes[7] := ExtractorStruct;

 ExtractorStruct.Name := 'UPEK TouchChip';
 ExtractorStruct.Code := NFE_MODE_UPEK_TOUCHCHIP;
 scannerModes[8] := ExtractorStruct;

 ExtractorStruct.Name := 'Identicator Technology DF90';
 ExtractorStruct.Code := NFE_MODE_IDENTICATORTECHNOLOGY_DF90;
 scannerModes[9] := ExtractorStruct;

 ExtractorStruct.Name := 'Atmel FingerChip';
 ExtractorStruct.Code := NFE_MODE_ATMEL_FINGERCHIP;
 scannerModes[10] := ExtractorStruct;

 ExtractorStruct.Name := 'BMF BLP100';
 ExtractorStruct.Code := NFE_MODE_BMF_BLP100;
 scannerModes[11] := ExtractorStruct;

 ExtractorStruct.Name := 'Secugen Hamster';
 ExtractorStruct.Code := NFE_MODE_SECUGEN_HAMSTER;
 scannerModes[12] := ExtractorStruct;

 ExtractorStruct.Name := 'Crossmatch Verifier 300';
 ExtractorStruct.Code := NFE_MODE_CROSSMATCH_VERIFIER300;
 scannerModes[13] := ExtractorStruct;

 ExtractorStruct.Name := 'NITGEN Fingkey Hamster';
 ExtractorStruct.Code := NFE_MODE_NITGEN_FINGKEY_HAMSTER;
 scannerModes[14] := ExtractorStruct;

 ExtractorStruct.Name := 'Testech Bio-i';
 ExtractorStruct.Code := NFE_MODE_TESTECH_BIOI;
 scannerModes[15] := ExtractorStruct;

 ExtractorStruct.Name := 'Digent Izzix 1000';
 ExtractorStruct.Code := NFE_MODE_DIGENT_IZZIX;
 scannerModes[16] := ExtractorStruct;

 ExtractorStruct.Name := 'Startek FM200';
 ExtractorStruct.Code := NFE_MODE_STARTEK_FM200;
 scannerModes[17] := ExtractorStruct;

 ExtractorStruct.Name := 'Fujitsu MBF200';
 ExtractorStruct.Code := NFE_MODE_FUJITSU_MB
...
...
(Not finished, please download and read the complete file)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 2

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
Aboutform.dcu7.81 kB29-05-10 03:22
AboutForm.dfm59.86 kB02-04-10 14:37
AboutForm.pas2.79 kB02-04-10 14:37
DataBase.dcu10.72 kB29-05-10 02:56
DataBase.pas7.02 kB02-04-10 14:37
NCore.dcu12.55 kB29-05-10 02:56
NCore.pas11.17 kB02-04-10 14:37
NDeviceManager.dcu24.08 kB29-05-10 02:56
NDeviceManager.pas20.58 kB26-05-10 01:21
NExtractors.dcu26.38 kB29-05-10 02:56
NExtractors.pas22.97 kB02-04-10 14:37
NImages.dcu18.89 kB29-05-10 02:56
NImages.pas16.86 kB02-04-10 14:37
NLicensing.dcu1.73 kB29-05-10 02:56
NLicensing.pas2.27 kB02-04-10 14:37
NMatchers.dcu10.16 kB29-05-10 02:56
NMatchers.pas8.69 kB02-04-10 14:37
NTemplates.dcu13.67 kB29-05-10 02:56
NTemplates.pas10.28 kB02-04-10 14:37
NUtils.dcu17.47 kB29-05-10 02:56
NUtils.pas14.14 kB02-04-10 14:37
SQLite3.dcu10.79 kB29-05-10 02:56
sqlite3.dll493.92 kB02-04-10 14:37
SQLite3.pas13.07 kB02-04-10 14:37
SQLiteTable3.dcu49.60 kB29-05-10 02:56
SQLiteTable3.pas44.43 kB02-04-10 14:37
<SQLite>0.00 B29-05-10 03:00
DataBase.pas.~1~7.02 kB02-04-10 14:37
DataBase.pas.~2~7.02 kB26-05-10 01:49
DataBase.pas.~3~7.03 kB26-05-10 01:51
NDeviceManager.pas.~1~20.57 kB02-04-10 14:37
<__history>0.00 B29-05-10 03:00
<Bibliotecas>0.00 B29-05-10 03:00
CameraForm.dcu7.54 kB29-05-10 03:22
CameraForm.dfm172.63 kB02-04-10 14:37
CameraForm.pas2.57 kB02-04-10 14:37
DataBase.dcu10.98 kB29-05-10 03:22
DataBase.pas7.02 kB02-04-10 14:37
EnrollmentForm.dcu4.85 kB29-05-10 03:22
EnrollmentForm.dfm171.08 kB02-04-10 14:37
EnrollmentForm.pas577.00 B02-04-10 14:37
FacesSamplePas.cfg473.00 B02-04-10 14:37
FacesSamplePas.dof2.57 kB02-04-10 14:37
FacesSamplePas.dpr1.00 kB02-04-10 14:37
FacesSamplePas.dproj5.96 kB29-05-10 03:20
FacesSamplePas.dproj.20074.74 kB02-04-10 14:37
FacesSamplePas.dproj.local62.00 B29-05-10 03:21
FacesSamplePas.identcache1.19 kB29-05-10 03:22
FacesSamplePas.res78.90 kB29-05-10 03:20
fPrincipal.dcu53.36 kB29-05-10 03:13
fPrincipal.dfm176.14 kB29-05-10 03:05
fPrincipal.pas47.37 kB29-05-10 03:05
MainForm.dcu53.56 kB29-05-10 03:22
MainForm.dfm176.34 kB29-05-10 02:38
MainForm.pas47.42 kB29-05-10 02:54
NCore.dcu12.56 kB29-05-10 03:15
NDeviceManager.dcu24.09 kB29-05-10 03:15
Neurotechnology.bmp19.17 kB02-04-10 14:37
Neurotechnology.ico77.80 kB02-04-10 14:37
NExtractors.dcu26.39 kB29-05-10 03:15
NImages.dcu18.90 kB29-05-10 03:15
NLicensing.dcu1.74 kB29-05-10 03:15
NMatchers.dcu10.17 kB29-05-10 03:15
NTemplates.dcu13.68 kB29-05-10 03:15
NUtils.dcu17.48 kB29-05-10 03:15
SettingsForm.dcu15.43 kB29-05-10 03:22
SettingsForm.dfm177.53 kB02-04-10 14:37
SettingsForm.pas7.09 kB02-04-10 14:37
SQLite3.dcu10.80 kB29-05-10 03:15
SQLiteTable3.dcu49.61 kB29-05-10 03:15
FacesSamplePas.dpr.~1~1.00 kB02-04-10 14:37
FacesSamplePas.dpr.~2~1.01 kB29-05-10 03:02
FacesSamplePas.dpr.~3~411.00 B29-05-10 03:02
fPrincipal.dfm.~1~176.34 kB29-05-10 02:38
fPrincipal.dfm.~2~176.35 kB29-05-10 03:02
fPrincipal.dfm.~3~176.32 kB29-05-10 03:04
fPrincipal.pas.~1~47.42 kB29-05-10 03:01
fPrincipal.pas.~2~47.59 kB29-05-10 03:02
fPrincipal.pas.~3~47.58 kB29-05-10 03:04
fPrincipal.pas.~4~47.43 kB29-05-10 03:05
MainForm.dfm.~1~176.32 kB02-04-10 14:37
MainForm.dfm.~2~176.34 kB26-05-10 01:10
MainForm.dfm.~3~176.34 kB26-05-10 01:45
MainForm.dfm.~4~176.35 kB26-05-10 23:51
MainForm.dfm.~5~176.35 kB27-05-10 01:38
MainForm.dfm.~6~176.35 kB29-05-10 01:37
MainForm.pas.~1~45.50 kB02-04-10 14:37
MainForm.pas.~2~45.50 kB26-05-10 01:26
MainForm.pas.~3~45.64 kB26-05-10 01:45
MainForm.pas.~4~47.41 kB27-05-10 00:51
MainForm.pas.~5~47.42 kB27-05-10 01:18
MainForm.pas.~6~47.42 kB29-05-10 01:40
<__history>0.00 B29-05-10 03:16
<Biometria>0.00 B0 0%
...
Sponsored links

NUtils.pas (1.58 MB)

Need 2 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D