Guest User

ADR

a guest
Jan 8th, 2012
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 45.77 KB | None | 0 0
  1. unit ForumPoster;
  2.  
  3. interface
  4.  
  5. uses
  6.   Classes, SysUtils, FPExceptions, FPResourceString, AdrStringUtils, OleCtrls,
  7.   SHDocVw, Forms, ActiveX, Generics.Collections, Generics.Defaults, windows,
  8.   Dialogs, Diagnostics, Controls, IniFiles;
  9.  
  10. type
  11.   TTegsList = Class
  12.   private
  13.     FTegsList: TStringList;
  14.     function GetTegs: string;
  15.     procedure SetTegs(const Value: string);
  16.     function GetCount: integer;
  17.   public
  18.     constructor Create(Sorted:boolean=true);
  19.     destructor Destroy; override;
  20.     procedure Add(const Teg: string); overload;
  21.     procedure Add(const Tegs: TTegsList); overload; //AddRange
  22.     procedure DeleteTegs(const Tegs: TTegsList);  overload;
  23.     procedure DeleteTegs(const Tegs:String);  overload;
  24.     procedure Clear;
  25.  
  26.     function TegInList(const Tegs: string): boolean;
  27.     function TegsInList(Tegs: TTegsList): boolean;
  28.     function NotTegsinList(Tegs: TTegsList): boolean;
  29.  
  30.     property Count: integer read GetCount;
  31.     property TegsStr: string read GetTegs write SetTegs;
  32.     property TegsList: TStringList read FTegsList;
  33.   end;
  34.  
  35.   // ------------------------------------------------------------------------------
  36. const
  37.   arIdentExists = -1;         //код помилки функи Add()
  38.   arSubIdentExists = -2;
  39. type
  40.  
  41.   TCustomConfList<T> = class (TList<T>)
  42.   private
  43.     FModified: boolean;
  44.   public
  45.     function Add(const Value: T): Integer; virtual;
  46.     procedure AddRange(const Values: array of T;
  47.       out Logs:TArray<Integer>); overload;
  48.     procedure AddRange(const Values: array of T);  overload;
  49.     function IndexOf(const Value: T): Integer;
  50.     procedure Delete(Index: Integer);
  51.     procedure Clear;
  52.  
  53.     property Modified:boolean read FModified write FModified;
  54.   end;
  55.  
  56.   TEngineConf = record
  57.     Name: string;
  58.     Coment: string;
  59.     Tegs: TTegsList;
  60.     LogUser: string;
  61.     LogPass: string;
  62.     MsgTitle: string;
  63.     MsgMess: string;
  64.     TopicTitle: string;
  65.     TopicMsg: string;
  66.   end;
  67.   TEngineConfArray = array of TEngineConf;
  68.   TEngineConfList = class;
  69.  
  70.  
  71.   TBookmarkConf = record
  72.     Name: string;
  73.     URI: string;
  74.     Tegs: TTegsList;
  75.     isMsg: boolean;
  76.   end;
  77.   TBookmarkConfArray = array of TBookmarkConf;
  78.   TBookmarkConfList = class;
  79.  
  80.   TForumConf = record
  81.     Name: string;
  82.     Coment: string;
  83.     Tegs: TTegsList;
  84.     LogName: string; // log
  85.     LogPass: string; // pass
  86.     LogURI: string;
  87.     LogBtn: string;
  88.     MsgBtn: string;
  89.     TopicBtn: string;
  90.     EngineName: string;
  91.   end;
  92.   TForumConfArray = array of TForumConf;
  93.   TForumConfList = class;
  94.  
  95.   TEngineConfList = class (TCustomConfList<TEngineConf>)
  96.   private
  97.     FTegsList: TTegsList;
  98.     function Comparison(const Left, Right: TEngineConf): Integer;
  99.     function GetItems(Name: string): TEngineConf;
  100.     procedure SetItems(Name: string; const Value: TEngineConf);
  101.   public
  102.     constructor Create;
  103.  
  104.     function Add(const Value: TEngineConf): Integer;  override;
  105.     procedure Delete(const Name: string); overload;
  106.     function Contains(const Name: string): Boolean; overload;
  107.     function IndexOf(const Name: string): integer;
  108.  
  109.     function ListOfNames: string;
  110.     function GetTegsList: TTegsList;
  111.  
  112.     property ItemsFromName[Name: string]:TEngineConf read GetItems write SetItems;
  113.   end;
  114.  
  115.   TForumConfList = class (TCustomConfList<TForumConf>)
  116.   private type
  117.     TDomainRec = TPair<string,Integer>;
  118.     TDomainRecArray = array of TDomainRec;
  119.   private
  120.     FTegsList: TTegsList;
  121.     FDomainArray: TDomainRecArray;
  122.     FDomainComparer: IComparer<TDomainRec>;
  123.     function Comparison(const Left, Right: TForumConf): Integer;
  124.     function ComparisonDomain(const Left,Right:TDomainRec):integer;
  125.     function GetItems(Name: string): TForumConf;
  126.     procedure SetItems(Name: string; const Value: TForumConf);
  127.     procedure MakeDomainArray;
  128.     function GetURIItems(URI: string): TForumConf;
  129.     procedure SetURIItems(URI: string; const Value: TForumConf);
  130.   public
  131.     constructor Create;
  132.  
  133.     function Add(const Value: TForumConf): Integer; override;
  134.     procedure Delete(const Name: string); overload;
  135.     function Contains(const Name: string): Boolean; overload;
  136.     function IndexOf(const Name: string): integer;
  137.     function ContainsFromURI(const URI:string): boolean;
  138.     function IndexOfFromURI(const URI: string): integer;
  139.  
  140.     function ListOfNames: string;
  141.     function ListOfURI: string;
  142.     function GetTegsList:  TTegsList;
  143.  
  144.     property ItemsFromURI[URI: string]:TForumConf read GetURIItems write SetURIItems;
  145.     property ItemsFromName[Name: string]:TForumConf read GetItems write SetItems;
  146.   end;
  147.  
  148.   TBookmarkConfList = class (TCustomConfList<TBookmarkConf>)
  149.   private
  150.     FTegsList: TTegsList;
  151.     function Comparison(const Left, Right: TBookmarkConf): Integer;
  152.     function GetItems(URI: string): TBookmarkConf;
  153.     procedure SetItems(URI: string; const Value: TBookmarkConf);
  154.   public
  155.     constructor Create;
  156.  
  157.     function Add(const Value: TBookmarkConf): Integer; override;
  158.     procedure Delete(const URI: string); overload;
  159.     function Contains(const URI: string): Boolean; overload;
  160.     function IndexOf(const URI: string ): integer;
  161.  
  162.     function ListOfURI: string;
  163.     function GetTegsList:  TTegsList;
  164.  
  165.     property ItemsFromURI[URI: string]:TBookmarkConf read GetItems write SetItems;
  166.   end;
  167.  
  168.  
  169.   // ========{Request}=============================================================
  170.  
  171.   TRqtPrmItem = record
  172.     URI: string;
  173.     Prm: array [0..1,0..1] of string;
  174.     Btn: string;
  175.     ErrIf: string; //умова при якій вважають що запит був невдалий
  176.     Captcha: string
  177.   end;
  178.   TRqtParam = array [0..1] of TRqtPrmItem;
  179.   TRqtParamList = TList<TRqtParam>;
  180.  
  181.   // ==============================================================================
  182.  
  183.   TTegsArray = array [0..2,0..1] of TTegsList;
  184.  
  185.   TFPConfDB = class
  186.   type
  187.     TConfType = (ctUnknown, ctEngine, ctForum, ctBookmark);
  188.   private
  189.     FForumList: TForumConfList;
  190.     FEngineList: TEngineConfList;
  191.     FBookmarkList: TBookmarkConfList;
  192.     FForumPath: string;
  193.     FEnginePath: string;
  194.     FBookPath: string;
  195.  
  196.     FEngineTegs: TTegsList;
  197.     FForumTegs: TTegsList;
  198.     FBookTegs: TTegsList;
  199.     FStrings: TStrings;
  200.  
  201.     const EngineTypeIdent  = 'EngineConf';
  202.     const ForumTypeIdent   = 'ForumConf';
  203.     const BookmarkTypeIdent= 'BookmarkConf';
  204.  
  205.     const MetadataSection = 'Metadata';
  206.     const ItemTypeIdent   = 'ItemType';
  207.     const ItemsCount      = 'ItemsCount';
  208.     const VersionIdent    = 'Version';
  209.   public
  210.     constructor Create;
  211.     destructor Destroy; override;
  212.  
  213.     const EngineVersion   :Double= 0.1;
  214.     const ForumVersion    :Double= 0.1;
  215.     const BookmarkVersion :Double= 0.1;
  216.  
  217.     property Forums: TForumConfList read FForumList write FForumList;
  218.     property Engines: TEngineConfList read FEngineList write FEngineList;
  219.     property Bookmarks: TBookmarkConfList read FBookmarkList write FBookmarkList;
  220.  
  221.     procedure LoadFromFile;
  222.     procedure SaveToFile;
  223.  
  224.     class function CheckConfType(const FileName: string): TConfType;
  225.     class function CheckConfVersion(const FileName: string): Double;
  226.     class function LoadEngine(const FileName: string): TEngineConfArray;
  227.     class function LoadForum(const FileName: string): TForumConfArray;
  228.     class function LoadBookmark(const FileName: string): TBookmarkConfArray;
  229.     class procedure SaveEngine(const FileName: string; const AEngineList: TEngineConfList);
  230.     class procedure SaveForum(const FileName: string; const AForumList: TForumConfList);
  231.     class procedure SaveBook(const FileName: string; const ABookmarkList: TBookmarkConfList);
  232.  
  233.     function BookToRqtPrm(const Book:TBookmarkConf; out Conf:TRqtParam;
  234.       const Title,Msg:string):string;  //err msg
  235.     procedure ClearAll;
  236.     function  TegsFilter(const Tegs:TTegsArray):TStrings;
  237.  
  238.     property ForumsSavePath: string read FForumPath write FForumPath;
  239.     property EngineSavePath: string read FEnginePath write FEnginePath;
  240.     property BooksSavePath: string read FBookPath write FBookPath;
  241.   end;
  242.  
  243.   // =================={ Request }==============================================
  244.  
  245.   TRqtStatusConteyner = record
  246.     Error:      integer;
  247.     Warring:    integer;
  248.     Done:       integer;
  249.     Terminated: integer;
  250.     fElse:      integer; //не використовується
  251.     Summ:       integer;
  252.   end;
  253.   TRqtWorkBeginEvent = procedure (Sender:TObject; Max:integer) of object;
  254.   TRqtWorkEvent = procedure (Sender:TObject;
  255.                           const Status:TRqtStatusConteyner) of object;
  256.   TRqtWorkEndEvent = TNotifyEvent;
  257.  
  258.   TRqtThreadLogItemType = (itError, itWarning, itTerminated, itDone,
  259.                                                               itEvent, itNone);
  260.   TRqtThreadLogConteyner = record
  261.     Item: string;
  262.     ItemType: TRqtThreadLogItemType;
  263.     Time: TDate;
  264.     ThreadId: integer;
  265.   end;
  266.   TRqtThreadLogManager = TList<TRqtThreadLogConteyner>;
  267.  
  268.  
  269.   TFPRequest = class
  270.   private type
  271.  
  272.     TFPRqtThread = class (TThread)
  273.     private type
  274.       TStatus = (stWait, stCompited, stError);
  275.     private
  276.       FParams: TRqtParam;
  277.       FStatus:  TStatus;
  278.       FManager: TFPRequest;
  279.         FThreadId: integer;
  280.         FHighLogType: TRqtThreadLogItemType;
  281.       procedure DocumentComplete(ASender: TObject;  const pDisp: IDispatch;
  282.         const URL: OleVariant);
  283.       procedure NavigateError(ASender: TObject; const pDisp: IDispatch;
  284.                                                          const URL: OleVariant;
  285.                                                          const Frame: OleVariant;
  286.                                                          const StatusCode: OleVariant;
  287.                                                          var Cancel: WordBool);
  288.       procedure AddToLog(const Item:string; ItemType:TRqtThreadLogItemType);
  289.         procedure SetHighLogType(const Value: TRqtThreadLogItemType);
  290.     protected
  291.       procedure Execute; override;
  292.     public
  293.       constructor Create(const Param: TRqtParam; Manager: TFPRequest);
  294.       destructor Destroy; override;
  295.       property ThreadId:integer read FThreadId write FThreadId;
  296.       property HighLogType:TRqtThreadLogItemType read FHighLogType write SetHighLogType;
  297.     end;
  298.  
  299.     TThreadNotifiEvent =  procedure(Sender: TObject; const Item: TRqtThreadLogConteyner;
  300.     Action: TCollectionNotification) of object;
  301.   private
  302.     fThreadsMax:  integer;
  303.     fThreads:     integer;
  304.     FCompitStatus:TRqtStatusConteyner;
  305.     fTerminated:   boolean;
  306.     FLookNewRequest: boolean; //вказує чи була завершенна попередня спороба постінгу
  307.     fRqtList:     TRqtParamList;
  308.     FOnWorkBegin: TRqtWorkBeginEvent;
  309.     FOnWork:      TRqtWorkEvent;
  310.     FOnWorkEnd:   TRqtWorkEndEvent;
  311.     FNextThreadId:  integer;
  312.     FLogList: TRqtThreadLogManager;
  313.  
  314.     procedure DoRequest(Params: TRqtParamList);
  315.     procedure ThreadDone(Sender: TObject);
  316.     procedure CheckWorkEnd;
  317.     function GetThreadLogAdd: TThreadNotifiEvent;
  318.     procedure SetThreadLogAdd(
  319.       const Value: TThreadNotifiEvent);
  320.   public
  321.     constructor Create;
  322.     destructor Destroy;  override;
  323.     procedure Posting;
  324.     procedure Terminate;
  325.  
  326.     procedure AddToList(const NewConf:TRqtParam);
  327.     function  ListCount:integer;
  328.     procedure ClearList;
  329.  
  330.     class procedure SetNullStatus(var Status:TRqtStatusConteyner);
  331.  
  332.     property Terminated:boolean read fTerminated write fTerminated;
  333.     property ThreadMax: integer read fThreadsMax write fThreadsMax default 20;
  334.     property OnWorkBegin: TRqtWorkBeginEvent read FOnWorkBegin write FOnWorkBegin;
  335.     property OnWork: TRqtWorkEvent read FOnWork write FOnWork;
  336.     property OnWorkEnd: TRqtWorkEndEvent read FOnWorkEnd write FOnWorkEnd;
  337.     property OnThreadEvent: TThreadNotifiEvent
  338.         read GetThreadLogAdd write SetThreadLogAdd;
  339.     property LogList:TRqtThreadLogManager read FLogList write FLogList;
  340.   end;
  341.  
  342.   TFPAllInOne = class
  343.   private
  344.     FRequest: TFPRequest;
  345.     FDBList: TFPConfDB;
  346.   public
  347.     constructor Create;
  348.     destructor Destroy; override;
  349.  
  350.     property Request: TFPRequest read FRequest write FRequest;
  351.     property DBList: TFPConfDB read FDBList write FDBList;
  352.   end;
  353.  
  354.   TForumsPoster = TFPAllInOne;
  355.  
  356. function enArray(const Ar: String): ShortString;
  357. function deArray(const s: ShortString): String;
  358.  
  359. implementation
  360.  
  361. resourcestring
  362.   RSBadIdent = '"%s" - не є правльним іднетифікатором!';
  363.  
  364. function enArray(const Ar: string): ShortString;
  365. begin
  366.   SetLength(result, 255);
  367.   result := AnsiString(Ar)+ShortString(StringOfChar(#0, 255-Length(Ar)));
  368. end;
  369.  
  370. function deArray(const s: ShortString): string;
  371. var
  372.   P, Stop: PAnsiChar;
  373. begin
  374.   P := (@s[1]);
  375.   Stop := P;
  376.   while Stop^ <> #0 do
  377.     inc(Stop);
  378.   result := String(Copy(s, 1, Stop - P));
  379. end;
  380.  
  381. { TFPConfList }
  382.  
  383. function TFPConfDB.BookToRqtPrm(const Book:TBookmarkConf; out Conf:TRqtParam;
  384.   const Title,Msg:string):string;
  385. var
  386.   I: Integer;
  387.   ForumConf:TForumConf;
  388.   EngineConf:TEngineConf;
  389. begin
  390.   i:= FForumList.IndexOfFromURI(Book.URI);
  391.   if i<0 then
  392.   begin
  393.     Result:=Format(SErrMsgPrefix+SErrForumFromURINotExists,[book.URI]);
  394.     exit;
  395.   end;
  396.   ForumConf:=FForumList.Items[i];
  397.  
  398.   i:= FEngineList.IndexOf(ForumConf.EngineName);
  399.   if i<-1 then
  400.   begin
  401.     Result:=Format(SErrMsgPrefix+SErrEngineFromForumNotExists,
  402.         [ForumConf.EngineName, ForumConf.Name]);
  403.     exit;
  404.   end;
  405.   EngineConf:=FEngineList.Items[i];
  406.  
  407.   with  conf[0] do
  408.   begin
  409.     URI:=     ForumConf.LogURI;
  410.     Prm[0,0]:=EngineConf.LogUser;
  411.     Prm[1,0]:=EngineConf.LogPass;
  412.     Prm[0,1]:=ForumConf.LogName;
  413.     Prm[1,1]:=ForumConf.LogPass;
  414.     ErrIf:='';
  415.     Captcha:='';
  416.   end;
  417.  
  418.   with Conf[1] do
  419.   begin
  420.     URI:=Book.URI;
  421.  
  422.     if Book.isMsg then
  423.     begin
  424.       Prm[0,0]:=EngineConf.MsgTitle;
  425.       Prm[1,0]:=EngineConf.MsgMess;
  426.       Btn :=    ForumConf.MsgBtn;
  427.     end
  428.     else
  429.     begin
  430.       Prm[0,0]:=EngineConf.TopicTitle;
  431.       Prm[1,0]:=EngineConf.TopicMsg;
  432.       Btn :=    ForumConf.TopicBtn;
  433.     end;
  434.  
  435.     Prm[0,1]:=Title;
  436.     Prm[1,1]:=Msg;
  437.     ErrIf:='';
  438.     Captcha:='';
  439.   end;
  440.  
  441. end;
  442.  
  443. procedure TFPConfDB.ClearAll;
  444. begin
  445.   FEngineList.Clear;
  446.   FForumList.Clear;
  447.   FBookmarkList.Clear;
  448. end;
  449.  
  450. constructor TFPConfDB.Create;
  451. begin
  452.   inherited;
  453.   FForumList:=TForumConfList.Create;
  454.   FEngineList:=TEngineConfList.Create;
  455.   FBookmarkList:=TBookmarkConfList.Create;
  456. end;
  457.  
  458. destructor TFPConfDB.Destroy;
  459. begin
  460.   ClearAll;
  461.   FEngineTegs.Free;
  462.   FForumTegs.Free;
  463.   FBookTegs.Free;
  464.   inherited;
  465. end;
  466.  
  467. class function TFPConfDB.CheckConfType(const FileName: string): TConfType;
  468. var
  469.   Ini: TIniFile;
  470.   buff: string;
  471. begin
  472.   Ini := TIniFile.Create(FileName);
  473.   try
  474.     buff := Ini.ReadString(MetadataSection,ItemTypeIdent,'');
  475.     if buff = EngineTypeIdent then
  476.       Result  :=  ctEngine
  477.     else if buff = ForumTypeIdent then
  478.       Result  :=  ctForum
  479.     else if buff = BookmarkTypeIdent then
  480.       Result  :=  ctBookmark
  481.     else
  482.       Result  :=  ctUnknown;
  483.   finally
  484.     Ini.Free;
  485.   end;
  486. end;
  487.  
  488. class function TFPConfDB.CheckConfVersion(const FileName: string): Double;
  489. var
  490.   Ini: TIniFile;
  491. begin
  492.   Ini := TIniFile.Create(FileName);
  493.   try
  494.     Result := Ini.ReadFloat(MetadataSection, VersionIdent, 0.00);
  495.   finally
  496.     Ini.Free;
  497.   end;
  498. end;
  499.  
  500. class function TFPConfDB.LoadBookmark(const FileName: string): TBookmarkConfArray;
  501. var
  502.   Ini:TMemIniFile;
  503.   I: Integer;
  504.   NumStr:string;
  505.   FileVersion:Double;
  506. begin
  507.   SetLength(Result,0);
  508.   if not FileExists(FileName) then
  509.     Exit;
  510.  
  511.   Ini := TMemIniFile.Create(FileName);
  512.   try
  513.     with ini do
  514.     begin
  515.       {Провірки...}
  516.       if ReadString(MetadataSection, ItemTypeIdent, '') <> BookmarkTypeIdent then
  517.         raise EFPException.CreateFmt(SErrFileTypeNotValited,
  518.           [ExtractFileName(FileName),SToBookmark]);
  519.  
  520.       FileVersion:= ReadFloat(MetadataSection, VersionIdent, 0.0);
  521.       if FileVersion <> BookmarkVersion then
  522.         if Abs(FileVersion-BookmarkVersion)<1 then  //різниця в мінорні версії
  523.           if MessageDlg(Format(SWrgDBVersionMinorDelta,
  524.                           [SToBookmark, FileVersion, BookmarkVersion]),
  525.                         mtWarning, mbAbortIgnore,-1)=mrAbort
  526.           then
  527.             Exit
  528.         else
  529.           MessageBox(0, PChar(Format(SErrDBVersionMajorDelta,
  530.                         [SToBookmark, FileVersion, BookmarkVersion])),
  531.                 PChar(SErrLoadFileTitle), MB_OK or MB_ICONSTOP or MB_TASKMODAL);
  532.       {/Провірки}
  533.  
  534.       SetLength(Result,ReadInteger(MetadataSection, ItemsCount, 0));
  535.       for I := 0 to High(Result) do
  536.         with  Result[i] do
  537.         begin
  538.           NumStr:=IntToStr(i);
  539.           Tegs  :=  TTegsList.Create();
  540.           Name  :=        ReadString(NumStr, 'Name',    '');
  541.           URI   :=        ReadString(NumStr, 'URI',     '');
  542.           Tegs.TegsStr := ReadString(NumStr, 'Tegs',    '');
  543.           isMsg :=        ReadBool(NumStr, 'LogUser', False);
  544.         end;
  545.  
  546.     end;
  547.   finally
  548.     Ini.Free;
  549.   end;
  550. end;
  551.  
  552. class function TFPConfDB.LoadEngine(const FileName: string): TEngineConfArray;
  553. var
  554.   Ini:TMemIniFile;
  555.   I: Integer;
  556.   NumStr:string;
  557. //  FileVersion:Double;
  558. begin
  559.   SetLength(Result,0);
  560.   if not FileExists(FileName) then
  561.     Exit;
  562.  
  563.   Ini := TMemIniFile.Create(FileName);
  564.   try
  565.     with ini do
  566.     begin
  567.       {Провірки...}
  568.       if ReadString(MetadataSection, ItemTypeIdent, '') <> EngineTypeIdent then
  569.         raise EFPException.CreateFmt(SErrFileTypeNotValited,
  570.           [ExtractFileName(FileName),SToEngine]);
  571.  
  572.       {FileVersion:= ReadFloat(MetadataSection, VersionIdent, 0.0);
  573.       if FileVersion <> EngineVersion then
  574.         if Abs(FileVersion-EngineVersion)<1 then  //різниця в мінорні версії
  575.           if MessageDlg(Format(SWrgDBVersionMinorDelta,
  576.                           [SToEngine, FileVersion, EngineVersion]),
  577.                         mtWarning, mbAbortIgnore,-1)=mrAbort
  578.           then
  579.             Exit
  580.         else
  581.           MessageBox(0, PChar(Format(SErrDBVersionMajorDelta,
  582.                         [SToEngine, FileVersion, EngineVersion])),
  583.                 PChar(SErrLoadFileTitle), MB_OK or MB_ICONSTOP or MB_TASKMODAL);}
  584.       {/Провірки}
  585.  
  586.       SetLength(Result,ReadInteger(MetadataSection, ItemsCount, 0));
  587.       for I := 0 to High(Result) do
  588.         with  Result[i] do
  589.         begin
  590.           NumStr    :=    IntToStr(i);
  591.           Tegs      :=    TTegsList.Create();
  592.           Name      :=    ReadString(NumStr, 'Name',    '');
  593.           Coment    :=    ReadString(NumStr, 'Coment',  '');
  594.           Tegs.TegsStr:=  ReadString(NumStr, 'Tegs',    '');
  595.           LogUser   :=    ReadString(NumStr, 'LogUser', '');
  596.           LogPass   :=    ReadString(NumStr, 'LogPass', '');
  597.           MsgTitle  :=    ReadString(NumStr, 'MsgTitle','');
  598.           MsgMess   :=    ReadString(NumStr, 'MsgMess', '');
  599.           TopicTitle:=    ReadString(NumStr, 'TopicTitle','');
  600.           TopicMsg  :=    ReadString(NumStr, 'TopicMsg','');
  601.         end;
  602.  
  603.     end;
  604.   finally
  605.     Ini.Free;
  606.   end;
  607. end;
  608.  
  609. class function TFPConfDB.LoadForum(const FileName: string): TForumConfArray;
  610. var
  611.   Ini:TMemIniFile;
  612.   I: Integer;
  613.   NumStr:string;
  614.   FileVersion:Double;
  615. begin
  616.   SetLength(Result,0);
  617.   if not FileExists(FileName) then
  618.     Exit;
  619.  
  620.   Ini := TMemIniFile.Create(FileName);
  621.   try
  622.     with ini do
  623.     begin
  624.       {Провірки...}
  625.       if ReadString(MetadataSection, ItemTypeIdent, '') <> ForumTypeIdent then
  626.         raise EFPException.CreateFmt(SErrFileTypeNotValited,
  627.           [ExtractFileName(FileName),SToForum]);
  628.  
  629.       FileVersion:= ReadFloat(MetadataSection, VersionIdent, 0.0);
  630.       if FileVersion <> ForumVersion then
  631.         if Abs(FileVersion-ForumVersion)<1 then  //різниця в мінорні версії
  632.           if MessageDlg(Format(SWrgDBVersionMinorDelta,
  633.                           [SToForum, FileVersion, ForumVersion]),
  634.                         mtWarning, mbAbortIgnore,-1)=mrAbort
  635.           then
  636.             Exit
  637.         else
  638.           MessageBox(0, PChar(Format(SErrDBVersionMajorDelta,
  639.                         [SToForum, FileVersion, ForumVersion])),
  640.                 PChar(SErrLoadFileTitle), MB_OK or MB_ICONSTOP or MB_TASKMODAL);
  641.       {/Провірки}
  642.  
  643.       SetLength(Result,ReadInteger(MetadataSection, ItemsCount, 0));
  644.       for I := 0 to High(Result) do
  645.         with  Result[i] do
  646.         begin
  647.           NumStr:=IntToStr(i);
  648.           Tegs  :=  TTegsList.Create();
  649.           Name  :=        ReadString(NumStr, 'Name',    '');
  650.           Coment  :=      ReadString(NumStr, 'Coment',  '');
  651.           Tegs.TegsStr := ReadString(NumStr, 'Tegs',    '');
  652.           LogName   :=    ReadString(NumStr, 'LogName', '');
  653.           LogPass   :=    ReadString(NumStr, 'LogPass', '');
  654.           LogURI    :=    ReadString(NumStr, 'LogURI',  '');
  655.           LogBtn    :=    ReadString(NumStr, 'LogBtn',  '');
  656.           MsgBtn    :=    ReadString(NumStr, 'MsgBtn',  '');
  657.           TopicBtn  :=    ReadString(NumStr, 'TopicBtn','');
  658.           EngineName:=    ReadString(NumStr, 'EngineName','')
  659.         end;
  660.     end;
  661.   finally
  662.     Ini.Free;
  663.   end;
  664. end;
  665.  
  666. procedure TFPConfDB.LoadFromFile;
  667. var
  668.   AEngine:TEngineConfArray;
  669.   AForum:TForumConfArray;
  670.   ABookmark:TBookmarkConfArray;
  671. begin
  672.   ClearAll;
  673.  
  674.   try
  675.     AEngine:= LoadEngine(FEnginePath);
  676.     FEngineList.AddRange(AEngine);
  677.     SetLength(AEngine,0);
  678.   except
  679.     on E: EFOpenError do
  680.       if not(E is EFOpenError) then
  681.         raise;
  682.   end;
  683.  
  684.   try
  685.     AForum  :=  LoadForum(FForumPath);
  686.     FForumList.AddRange(AForum);
  687.     SetLength(AForum,0);
  688.   except
  689.     on E: EFOpenError do
  690.       if not(E is EFOpenError) then
  691.         raise;
  692.   end;
  693.  
  694.   try
  695.     ABookmark :=  LoadBookmark(FBookPath);
  696.     FBookmarkList.AddRange(ABookmark);
  697.     SetLength(ABookmark,0);
  698.   except
  699.     on E: EFOpenError do
  700.       if not(E is EFOpenError) then
  701.         raise;
  702.   end;
  703. end;
  704.  
  705. class procedure TFPConfDB.SaveBook(const FileName: string;
  706.   const ABookmarkList: TBookmarkConfList);
  707. var
  708.   Ini:TMemIniFile;
  709.   I: Integer;
  710.   NumStr:string;
  711. begin
  712.   Ini := TMemIniFile.Create(FileName);
  713.   try
  714.     with ini do
  715.     begin
  716.       WriteString(MetadataSection, ItemTypeIdent, BookmarkTypeIdent);
  717.       WriteFloat(MetadataSection, VersionIdent, BookmarkVersion);
  718.       WriteInteger(MetadataSection, ItemsCount, ABookmarkList.Count);
  719.  
  720.       for I := 0 to ABookmarkList.Count-1 do
  721.         with  ABookmarkList.Items[i] do
  722.         begin
  723.           NumStr:=IntToStr(i);
  724.           WriteString(NumStr, 'Name',       Name);      
  725.           WriteString(NumStr, 'URI',        URI);
  726.           WriteString(NumStr, 'Tegs',       Tegs.TegsStr);
  727.           WriteBool(NumStr,   'isMsg',      isMsg);
  728.         end;                                        
  729.     end;
  730.     Ini.UpdateFile;
  731.   finally
  732.     Ini.Free;
  733.   end;
  734. end;
  735.  
  736.  
  737. class procedure TFPConfDB.SaveEngine(const FileName: string;
  738.   const AEngineList: TEngineConfList);
  739. var
  740.   Ini:TMemIniFile;
  741.   I: Integer;
  742.   NumStr:string;
  743. begin
  744.   Ini := TMemIniFile.Create(FileName);
  745.   try
  746.     with ini do
  747.     begin
  748.       WriteString(MetadataSection, ItemTypeIdent, EngineTypeIdent);
  749.       WriteFloat(MetadataSection, VersionIdent, EngineVersion);
  750.       WriteInteger(MetadataSection, ItemsCount, AEngineList.Count);
  751.  
  752.       for I := 0 to AEngineList.Count-1 do
  753.         with  AEngineList.Items[i] do
  754.         begin
  755.           NumStr:=IntToStr(i);
  756.           WriteString(NumStr, 'Name',       Name);
  757.           WriteString(NumStr, 'Coment',     Coment);
  758.           WriteString(NumStr, 'Tegs',       Tegs.TegsStr);
  759.           WriteString(NumStr, 'LogUser',    LogUser);
  760.           WriteString(NumStr, 'LogPass',    LogPass);
  761.           WriteString(NumStr, 'MsgTitle',   MsgTitle);
  762.           WriteString(NumStr, 'MsgMess',    MsgMess);
  763.           WriteString(NumStr, 'TopicTitle', TopicTitle);
  764.           WriteString(NumStr, 'TopicMsg',   TopicMsg);
  765.         end;
  766.  
  767.     end;
  768.     Ini.UpdateFile;
  769.   finally
  770.     Ini.Free;
  771.   end;
  772. end;
  773.  
  774. class procedure TFPConfDB.SaveForum(const FileName: string;
  775.   const AForumList: TForumConfList);
  776. var
  777.   Ini:TMemIniFile;
  778.   I: Integer;
  779.   NumStr:string;
  780. begin
  781.   Ini := TMemIniFile.Create(FileName);
  782.   try
  783.     with ini do
  784.     begin
  785.       WriteString(MetadataSection, ItemTypeIdent, ForumTypeIdent);
  786.       WriteFloat(MetadataSection, VersionIdent, ForumVersion);
  787.       WriteInteger(MetadataSection, ItemsCount, AForumList.Count);
  788.  
  789.       for I := 0 to AForumList.Count-1 do
  790.         with  AForumList.Items[i] do
  791.         begin
  792.           NumStr:=IntToStr(i);
  793.           WriteString(NumStr, 'Name',       Name);
  794.           WriteString(NumStr, 'Coment',     Coment);
  795.           WriteString(NumStr, 'Tegs',       Tegs.TegsStr);
  796.           WriteString(NumStr, 'LogName',    LogName);
  797.           WriteString(NumStr, 'LogPass',    LogPass);
  798.           WriteString(NumStr, 'LogURI',     LogURI);
  799.           WriteString(NumStr, 'LogBtn',     LogBtn);
  800.           WriteString(NumStr, 'MsgBtn',     MsgBtn);
  801.           WriteString(NumStr, 'TopicBtn',   TopicBtn);
  802.           WriteString(NumStr, 'EngineName', EngineName);
  803.         end;
  804.  
  805.     end;
  806.     Ini.UpdateFile;
  807.   finally
  808.     Ini.Free;
  809.   end;
  810. end;
  811.  
  812. procedure TFPConfDB.SaveToFile;
  813. begin
  814.   SaveEngine(FEnginePath, FEngineList);
  815.   SaveForum(FForumPath, FForumList);
  816.   SaveBook(FBookPath, FBookmarkList);
  817. end;
  818.  
  819. //==============================================================================
  820.  
  821. function TFPConfDB.TegsFilter(const Tegs:TTegsArray): TStrings;
  822. var
  823.   ar:array [0..1] of array of SmallInt;
  824.  
  825. //------------------------------------------------------------------------------
  826.  
  827.   function NormEngine(index:integer):smallInt;
  828.   begin
  829.     if Index<0 then
  830.     begin
  831.       Result:=-1;
  832.       exit;
  833.     end;
  834.     if ar[0,index]=-1 then
  835.       if  FEngineList[index].Tegs.TegsInList(tegs[2,0])
  836.       and FEngineList[index].Tegs.NotTegsinList(tegs[2,1])
  837.       then
  838.         ar[0,index]:=1
  839.       else
  840.         ar[0,index]:=0;
  841.     result:=ar[0,index];
  842.   end;
  843.  
  844. //------------------------------------------------------------------------------
  845.  
  846.   function NormForum(index:integer):SmallInt;
  847.   begin
  848.     if Index<0 then
  849.     begin
  850.       Result:=-1;
  851.       exit;
  852.     end;
  853.  
  854.     if ar[1,index]=-1 then
  855.       if  (NormEngine(FEngineList.IndexOf(FForumList[index].EngineName))=1)
  856.       and FForumList[index].Tegs.TegsInList(tegs[1,0])
  857.       and FForumList[index].Tegs.NotTegsinList(tegs[1,1])
  858.       then
  859.         ar[1,index]:=1
  860.       else
  861.         ar[1,index]:=0;
  862.     result:=ar[1,index];
  863.   end;
  864.  
  865. //------------------------------------------------------------------------------
  866.  
  867.   function NormBook(index:integer):boolean;
  868.   begin
  869.     result:= (NormForum(FForumList.IndexOfFromURI(FBookmarkList[index].URI))=1)
  870.       and FBookmarkList[index].Tegs.TegsInList(tegs[0,0])
  871.       and FBookmarkList[index].Tegs.NotTegsinList(Tegs[0,1]);
  872.   end;
  873.  
  874. //------------------------------------------------------------------------------
  875.  
  876. var
  877.   I: Integer;
  878. begin
  879.   SetLength(ar[0],FEngineList.Count);
  880.   SetLength(ar[1],FForumList.Count);
  881.   for I := 0 to FEngineList.Count -1 do
  882.     ar[0,i]:=-1;
  883.   for I := 0 to FForumList.Count -1 do
  884.     ar[1,i]:=-1;
  885.  
  886.   if Assigned(FStrings) then
  887.     FStrings.Clear
  888.   else
  889.     FStrings:=TStringList.Create;
  890.   Result:=FStrings;
  891.  
  892.   for I := 0 to FBookmarkList.Count -1 do
  893.     if NormBook(i) then
  894.       Result.Add(FBookmarkList[i].URI);
  895.  
  896. end;
  897.  
  898. { TFPRequest }
  899.  
  900. procedure TFPRequest.AddToList(const NewConf: TRqtParam);
  901. begin
  902.   fRqtList.Add(NewConf);
  903. end;
  904.  
  905. procedure TFPRequest.CheckWorkEnd;
  906. begin
  907.   if (FThreads=0) and (not FLookNewRequest) and Assigned(OnWorkEnd) then
  908.     OnWorkEnd(self);
  909. end;
  910.  
  911. procedure TFPRequest.ClearList;
  912. begin
  913.   fRqtList.Clear;
  914. end;
  915.  
  916. constructor TFPRequest.Create;
  917. begin
  918.   inherited;
  919.   fTerminated:= True;
  920.   fThreadsMax:=  20;
  921.   FLogList:=TRqtThreadLogManager.Create;
  922.   fRqtList:=TRqtParamList.Create;
  923. end;
  924.  
  925. destructor TFPRequest.Destroy;
  926. begin
  927.   FLogList.Free;
  928.   fRqtList.Free;
  929.   inherited;
  930. end;
  931.  
  932. procedure TFPRequest.DoRequest(Params: TRqtParamList);
  933. var
  934.   i: integer;
  935. begin
  936.   if Assigned(OnWorkBegin) then
  937.     OnWorkBegin(Self,Params.Count);
  938.  
  939.   if fThreads<>0 then
  940.     raise EFPThreadRuning.CreateFmt(SRqsErrThreadRuning,[fThreads]);
  941.  
  942.   fTerminated:=false;
  943.   SetNullStatus(FCompitStatus);
  944.   FNextThreadId:=0;
  945.   FLogList.Clear;
  946.  
  947.   FLookNewRequest:=true;
  948.   try
  949.     if Params.Count = 0 then
  950.       exit;
  951.  
  952.     for i := 0 to Params.Count-1 do
  953.     begin
  954.       with TFPRqtThread.Create(Params.Items[i],Self) do
  955.       begin
  956.         OnTerminate := ThreadDone;
  957.         ThreadId:=FNextThreadId;
  958.         Start;
  959.       end;
  960.       inc(fThreads);
  961.       inc(FNextThreadId);
  962.  
  963.       while fThreads >= fThreadsMax do
  964.       begin
  965.         Application.ProcessMessages;
  966.         if fTerminated then
  967.           Exit;
  968.       end;
  969.       Application.ProcessMessages;
  970.       if fTerminated then
  971.         Exit;
  972.     end;
  973.   finally
  974.     FLookNewRequest:=false;
  975.     CheckWorkEnd;
  976.   end;
  977. end;
  978.  
  979. function TFPRequest.GetThreadLogAdd: TThreadNotifiEvent;
  980. begin
  981.   Result:= FLogList.OnNotify;
  982. end;
  983.  
  984. function TFPRequest.ListCount: integer;
  985. begin
  986.   Result:=fRqtList.Count;
  987. end;
  988.  
  989. class procedure TFPRequest.SetNullStatus(var Status: TRqtStatusConteyner);
  990. begin
  991.   with Status do
  992.   begin
  993.     Error:=0;
  994.     Done:=0;
  995.     Terminated:=0;
  996.     fElse:=0;
  997.     Summ:=0;
  998.   end;
  999. end;
  1000.  
  1001. procedure TFPRequest.SetThreadLogAdd(
  1002.   const Value: TThreadNotifiEvent);
  1003. begin
  1004.   FLogList.OnNotify:=Value;
  1005. end;
  1006.  
  1007. procedure TFPRequest.ThreadDone(Sender: TObject);
  1008. begin
  1009.   case TFPRqtThread(Sender).HighLogType of
  1010.     itError:      Inc(FCompitStatus.Error);
  1011.     itWarning:    Inc(FCompitStatus.Warring);
  1012.     itTerminated: Inc(FCompitStatus.Terminated);
  1013.     itDone:       Inc(FCompitStatus.Done);
  1014.     else          Inc(FCompitStatus.fElse);
  1015.   end;
  1016.   inc(FCompitStatus.Summ);
  1017.   Dec(FThreads);
  1018.   if Assigned(OnWork) then
  1019.     OnWork(Self,FCompitStatus);
  1020.   CheckWorkEnd;
  1021. end;
  1022.  
  1023. procedure TFPRequest.Posting;
  1024. begin
  1025.   DoRequest(fRqtList);
  1026. end;
  1027.  
  1028. procedure TFPRequest.Terminate;
  1029. begin
  1030.   fTerminated := True;
  1031. end;
  1032.  
  1033. { TFPAllInOne }
  1034.  
  1035. constructor TFPAllInOne.Create;
  1036. begin
  1037.   inherited;
  1038.   FRequest := TFPRequest.Create;
  1039.   FDBList := TFPConfDB.Create;
  1040. end;
  1041.  
  1042. destructor TFPAllInOne.Destroy;
  1043. begin
  1044.   FRequest.Free;
  1045.   FDBList.Free;
  1046.   inherited;
  1047. end;
  1048.  
  1049. { TTegsList }
  1050.  
  1051. procedure TTegsList.Add(const Teg: string);
  1052. begin
  1053.   if (Teg<>'') and (not TegInList(Teg)) then
  1054.     FTegsList.Add(Trim(Teg));
  1055. end;
  1056.  
  1057. procedure TTegsList.Add(const Tegs: TTegsList);
  1058. var
  1059.   i: integer;
  1060. begin
  1061.   for i := 0 to Tegs.Count - 1 do
  1062.     Add(Tegs.TegsList.Strings[i]);
  1063. end;
  1064.  
  1065. procedure TTegsList.Clear;
  1066. begin
  1067.   FTegsList.Clear;
  1068. end;
  1069.  
  1070. constructor TTegsList.Create(Sorted:boolean=true);
  1071. begin
  1072.   inherited Create;
  1073.   FTegsList := TStringList.Create;
  1074.   FTegsList.Duplicates:=dupIgnore;
  1075.   FTegsList.CaseSensitive:=False;
  1076.   FTegsList.Sorted:=true;
  1077. end;
  1078.  
  1079. procedure TTegsList.DeleteTegs(const Tegs: TTegsList);
  1080. var
  1081.   i: Integer;
  1082. begin
  1083.   for i := 0 to Tegs.Count-1 do
  1084.     if FTegsList.IndexOf(Tegs.TegsList.Strings[i])<>-1 then
  1085.       FTegsList.Delete(FTegsList.IndexOf(Tegs.TegsList.Strings[i]));
  1086. end;
  1087.  
  1088. procedure TTegsList.DeleteTegs(const Tegs: String);
  1089. var
  1090.   fTegs:TTegsList;
  1091. begin
  1092.   fTegs:=TTegsList.Create;
  1093.   try
  1094.     fTegs.TegsStr:=Tegs;
  1095.     DeleteTegs(fTegs);
  1096.   finally
  1097.     fTegs.Free;
  1098.   end;
  1099. end;
  1100.  
  1101. destructor TTegsList.Destroy;
  1102. begin
  1103.   FTegsList.Free;
  1104.   inherited;
  1105. end;
  1106.  
  1107. function TTegsList.GetCount: integer;
  1108. begin
  1109.   Result:=FTegsList.Count;
  1110. end;
  1111.  
  1112. function TTegsList.GetTegs: string;
  1113. var
  1114.   i: integer;
  1115. begin
  1116.   result := '';
  1117.   for i := 0 to FTegsList.Count - 1 do
  1118.     result := result + FTegsList.Strings[i] + ', ';
  1119.   if Length(result)>2 then
  1120.     Delete(result, Length(result) - 1, 2);
  1121. end;
  1122.  
  1123. function TTegsList.NotTegsinList(Tegs: TTegsList): boolean;
  1124. var
  1125.   i: integer;
  1126. begin
  1127.   for i := 0 to FTegsList.Count - 1 do
  1128.     if (FTegsList.Strings[i]<>'')
  1129.       and Tegs.TegInList(FTegsList.Strings[i])
  1130.     then
  1131.     begin
  1132.       result := False;
  1133.       Exit;
  1134.     end;
  1135.   result := True;
  1136. end;
  1137.  
  1138. procedure TTegsList.SetTegs(const Value: string);
  1139. var
  1140.   Start, P: PChar;
  1141.   s: String;
  1142. begin
  1143.   FTegsList.Clear;
  1144.   P := Pointer(Value);
  1145.   if P <> nil then
  1146.     while P^ <> #0 do
  1147.     begin
  1148.       Start := P;
  1149.       while not CharInSet(P^, [#0, #44]) do
  1150.         inc(P);
  1151.       SetString(s, Start, P - Start);
  1152.       Add(s);
  1153.       if P^ = #44 then
  1154.         inc(P);
  1155.       if P^ = #32 then
  1156.         inc(P);
  1157.     end;
  1158. end;
  1159.  
  1160. function TTegsList.TegInList(const Tegs: string): boolean;
  1161. begin
  1162.   result := FTegsList.IndexOf(Trim(Tegs)) > -1;
  1163. end;
  1164.  
  1165. function TTegsList.TegsInList(Tegs: TTegsList): boolean;
  1166. var
  1167.   i: integer;
  1168. begin
  1169.   for i := 0 to Tegs.TegsList.Count - 1 do
  1170.     if (Tegs.TegsList.Strings[i]<>'')
  1171.       and (not TegInList(Tegs.TegsList.Strings[i]))
  1172.     then
  1173.     begin
  1174.       result := False;
  1175.       Exit;
  1176.     end;
  1177.   result := True;
  1178. end;
  1179.  
  1180. { TFPRequest.TFPRqtThread }
  1181.  
  1182. procedure TFPRequest.TFPRqtThread.AddToLog(const Item: string;
  1183.   ItemType: TRqtThreadLogItemType);
  1184. var
  1185.   buff:TRqtThreadLogConteyner;
  1186. begin
  1187.   buff.Item:=Item;
  1188.   buff.ItemType:=ItemType;
  1189.   buff.Time:=Time;
  1190.   buff.ThreadId:=FThreadId;
  1191.   Synchronize(procedure
  1192.   begin
  1193.     FManager.LogList.Add(buff)
  1194.   end);
  1195.  
  1196.   if ItemType<FHighLogType then
  1197.     FHighLogType:=ItemType;
  1198. end;
  1199.  
  1200. constructor TFPRequest.TFPRqtThread.Create(const Param: TRqtParam; Manager: TFPRequest);
  1201. begin
  1202.   inherited Create(true);
  1203.   FParams:=Param;
  1204.   FManager:=Manager;
  1205.   FHighLogType:=itNone;
  1206. end;
  1207.  
  1208. destructor TFPRequest.TFPRqtThread.Destroy;
  1209. begin
  1210.   inherited;
  1211. end;
  1212.  
  1213. procedure TFPRequest.TFPRqtThread.DocumentComplete(ASender: TObject;
  1214.   const pDisp: IDispatch; const URL: OleVariant);
  1215. begin
  1216.   FStatus:=stCompited;
  1217. end;
  1218.  
  1219. procedure TFPRequest.TFPRqtThread.Execute;
  1220.  
  1221.   function SetValForm(WebBrowser: TWebBrowser; FieldName: string;
  1222.     Value: string): boolean;
  1223.   var
  1224.     i, j: integer;
  1225.     FormItem: Variant;
  1226.   begin
  1227.     result := False;
  1228.     // Формы нет
  1229.     if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then
  1230.     begin
  1231.       Exit;
  1232.     end;
  1233.     // Форм в документе
  1234.     for i := 0 to WebBrowser.OleObject.Document.Forms.Length - 1 do
  1235.     begin
  1236.       FormItem := WebBrowser.OleObject.Document.Forms.Item(i);
  1237.       for j := 0 to FormItem.Length - 1 do
  1238.       begin
  1239.         try
  1240.           // если найденно изменить.
  1241.           if FormItem.Item(j).Name = FieldName then
  1242.           begin
  1243.             FormItem.Item(j).Value := Value;
  1244.             result := True;
  1245.           end;
  1246.         except
  1247.           Exit;
  1248.         end;
  1249.       end;
  1250.     end;
  1251.   end;
  1252.  
  1253.   // Узнаем значение
  1254.   function GetValForm(WebBrowser: TWebBrowser; FieldName: string): String;
  1255.   var
  1256.     i, j: integer;
  1257.     FormItem: Variant;
  1258.   begin
  1259.     if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then
  1260.     begin
  1261.       Exit;
  1262.     end;
  1263.     for i := 0 to WebBrowser.OleObject.Document.Forms.Length - 1 do
  1264.     begin
  1265.       FormItem := WebBrowser.OleObject.Document.Forms.Item(i);
  1266.       for j := 0 to FormItem.Length - 1 do
  1267.       begin
  1268.         try
  1269.           if FormItem.Item(j).Name = FieldName then
  1270.           begin
  1271.             FormItem.Item(j).Click;
  1272.             result := FormItem.Item(j).Value;
  1273.           end;
  1274.         except
  1275.           Exit;
  1276.         end;
  1277.       end;
  1278.     end;
  1279.   end;
  1280.  
  1281.   // Нажатие
  1282.   function ClickForm(WebBrowser: TWebBrowser; FieldName: string): boolean;
  1283.   var
  1284.     i, j: integer;
  1285.     FormItem: Variant;
  1286.   begin
  1287.     result := False;
  1288.     // Нет формы в документе
  1289.     if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then
  1290.     begin
  1291.       Exit;
  1292.     end;
  1293.     // Найдена форма в документе
  1294.     for i := 0 to WebBrowser.OleObject.Document.Forms.Length - 1 do
  1295.     begin
  1296.       FormItem := WebBrowser.OleObject.Document.Forms.Item(i);
  1297.       for j := 0 to FormItem.Length - 1 do
  1298.       begin
  1299.         try
  1300.           // when the fieldname is found, try to fill out
  1301.           if FormItem.Item(j).Value = FieldName then //
  1302.           begin
  1303.             FormItem.Item(j).Click;
  1304.             result := True;
  1305.           end;
  1306.         except
  1307.           Exit;
  1308.         end;
  1309.       end;
  1310.     end;
  1311.   end;
  1312.  
  1313.  
  1314.  
  1315. var
  1316.   Browser:TWebBrowser;
  1317.   I: Integer;
  1318.   J: Integer;
  1319. begin
  1320.   inherited;
  1321.   CoInitialize(nil);
  1322.   Browser:=TWebBrowser.Create(nil);
  1323.   try
  1324.     Browser.OnDocumentComplete:=DocumentComplete;
  1325.     Browser.OnNavigateError:=NavigateError;
  1326.  
  1327.     AddToLog(Format(SRqsMsgThreadStart,[FParams[1].URI]),itEvent);
  1328.  
  1329.     for I := Low(FParams) to High(FParams) do
  1330.       with FParams[i] do
  1331.       begin
  1332.         FStatus:=stWait;
  1333.         Browser.Navigate(URI);
  1334.         while FStatus=stWait do
  1335.         begin
  1336.           Application.ProcessMessages;
  1337.           sleep(100);
  1338.           if (Terminated or FManager.fTerminated) then
  1339.           begin
  1340.             AddToLog(Format(SRqsErrThreadTerminated, [URI]),itTerminated);
  1341.             exit;
  1342.           end;
  1343.         end;
  1344.  
  1345.         if FStatus=stError then
  1346.           Exit;
  1347.  
  1348.         for J := Low(Prm) to High(Prm) do
  1349.           if not SetValForm(Browser,Prm[j,0],Prm[j,1]) then
  1350.           begin
  1351.             AddToLog(Format(SRqsErrSetVal,[Prm[j,0],URI]), itError);
  1352.             Exit;
  1353.           end;
  1354.       end;
  1355.   finally
  1356.     Browser.Free;
  1357.     AddToLog(Format(SRqsMsgThreadComplited,[FParams[1].URI]),itDone);
  1358.   end;
  1359. end;
  1360.  
  1361. procedure TFPRequest.TFPRqtThread.NavigateError(ASender: TObject; const pDisp: IDispatch;
  1362.   const URL: OleVariant; const Frame: OleVariant; const StatusCode: OleVariant;
  1363.   var Cancel: WordBool);
  1364. begin
  1365.   AddToLog(Format(SRqsErrNavigateError,[URL,integer(StatusCode)]),itError);
  1366.   FStatus:=stError;
  1367. end;
  1368.  
  1369. procedure TFPRequest.TFPRqtThread.SetHighLogType(
  1370.   const Value: TRqtThreadLogItemType);
  1371. begin
  1372.   FHighLogType := Value;
  1373. end;
  1374.  
  1375. { TConfList<T> }
  1376.  
  1377. function TCustomConfList<T>.Add(const Value: T): Integer;
  1378. begin
  1379.   if not BinarySearch(Value,Result) then
  1380.     Insert(Result,Value)
  1381.   else
  1382.     Exit(arIdentExists);
  1383.   Modified:=true;
  1384. end;
  1385.  
  1386. procedure TCustomConfList<T>.AddRange(const Values: array of T);
  1387. var
  1388.   I: Integer;
  1389. begin
  1390.   for I := 0 to High(Values) do
  1391.     Add(Values[i]);
  1392. end;
  1393.  
  1394. procedure TCustomConfList<T>.AddRange(const Values: array of T;
  1395.   out Logs: TArray<Integer>);
  1396. var
  1397.   I, tmp: Integer;
  1398. begin
  1399.   SetLength(Logs, Length(Values));
  1400.   for I := 0 to High(Values) do
  1401.     Logs[i]:= Add(Values[i]);
  1402. end;
  1403.  
  1404. procedure TCustomConfList<T>.Clear;
  1405. begin
  1406.   inherited;
  1407.   Modified:=true;
  1408. end;
  1409.  
  1410. procedure TCustomConfList<T>.Delete(Index: Integer);
  1411. begin
  1412.   inherited;
  1413.   Modified:=true;
  1414. end;
  1415.  
  1416. function TCustomConfList<T>.IndexOf(const Value: T): Integer;
  1417. begin
  1418.   if not BinarySearch(Value,Result) then
  1419.     Result:=-1
  1420. end;
  1421.  
  1422. { TEngineConfList }
  1423.  
  1424. function TEngineConfList.Add(const Value: TEngineConf): Integer;
  1425. var
  1426.   AValue:TEngineConf;
  1427. begin
  1428.   if Value.Name='' then
  1429.     raise EFPException.CreateFmt(RSBadIdent,[Value.Name]);
  1430.   if not Assigned(Value.Tegs) then
  1431.   begin
  1432.     AValue:=Value;
  1433.     AValue.Tegs := TTegsList.Create;
  1434.     Result:= inherited Add(AValue);
  1435.   end
  1436.   else
  1437.     Result:= inherited;
  1438. end;
  1439.  
  1440. function TEngineConfList.Comparison(const Left, Right: TEngineConf): Integer;
  1441. begin
  1442.   if Left.Name > Right.Name then
  1443.     Result:=1
  1444.   else
  1445.     if Left.Name < Right.Name then
  1446.       Result:=-1
  1447.     else
  1448.       Result:=0;
  1449. end;
  1450.  
  1451. function TEngineConfList.Contains(const Name: string): Boolean;
  1452. begin
  1453.   Result:=IndexOf(Name) >= 0;
  1454. end;
  1455.  
  1456. constructor TEngineConfList.Create;
  1457. begin
  1458.   inherited Create(TComparer<TEngineConf>.Construct(Comparison));
  1459. end;
  1460.  
  1461. procedure TEngineConfList.Delete(const Name: string);
  1462. begin
  1463.   Delete(IndexOf(Name));
  1464. end;
  1465.  
  1466. function TEngineConfList.GetItems(Name: string): TEngineConf;
  1467. var
  1468.   i:integer;
  1469. begin
  1470.   i:=IndexOf(Name);
  1471.   if i=-1 then
  1472.     EFPExcpValue.Create(SErrAdd);
  1473.   Result:=Items[i];
  1474. end;
  1475.  
  1476. function TEngineConfList.IndexOf(const Name: string): integer;
  1477. var
  1478.   tmp:TEngineConf;
  1479. begin
  1480.   tmp.Name:=Name;
  1481.   if not BinarySearch(tmp,Result) then
  1482.     Result:=-1;
  1483. end;
  1484.  
  1485. function TEngineConfList.ListOfNames: string;
  1486. var
  1487.   I:integer;
  1488. begin
  1489.   Result:='';
  1490.   for i := 0 to Count-1 do
  1491.     Result:=Result + Items[i].Name + #10;
  1492. end;
  1493.  
  1494. procedure TEngineConfList.SetItems(Name: string; const Value: TEngineConf);
  1495. begin
  1496.   Delete(Name);
  1497.   Add(Value);
  1498. end;
  1499.  
  1500. function TEngineConfList.GetTegsList: TTegsList;
  1501. var
  1502.   I: Integer;
  1503. begin
  1504.   if Assigned(FTegsList) then
  1505.     FTegsList.Clear
  1506.   else
  1507.     FTegsList:=TTegsList.Create;
  1508.  
  1509.   for I := 0 to Count-1 do
  1510.     FTegsList.Add(Items[i].Tegs);
  1511.   Result:=FTegsList;
  1512. end;
  1513.  
  1514. { TForumConfList }
  1515.  
  1516. function TForumConfList.Add(const Value: TForumConf): Integer;
  1517. var
  1518.   AValue:TForumConf;
  1519. begin
  1520.   if Value.Name='' then
  1521.     raise EFPException.CreateFmt(RSBadIdent,[Value.Name]);
  1522.   if ContainsFromURI(Value.LogURI) then
  1523.     Exit(arSubIdentExists);
  1524.  
  1525.   if not Assigned(Value.Tegs) then
  1526.   begin
  1527.     AValue:=Value;
  1528.     AValue.Tegs := TTegsList.Create;
  1529.     Result:= Inherited Add(AValue);
  1530.   end
  1531.   else
  1532.     Result:= inherited;
  1533. end;
  1534.  
  1535. function TForumConfList.Comparison(const Left, Right: TForumConf): Integer;
  1536. begin
  1537.   if Left.Name > Right.Name then
  1538.     Result:=1
  1539.   else
  1540.     if Left.Name < Right.Name then
  1541.       Result:=-1
  1542.     else
  1543.       Result:=0;
  1544. end;
  1545.  
  1546. function TForumConfList.ComparisonDomain(const Left,
  1547.   Right: TDomainRec): integer;
  1548. begin
  1549.   if Left.Key > Right.Key then
  1550.     Result:=1
  1551.   else
  1552.     if Left.Key < Right.Key then
  1553.       Result:=-1
  1554.     else
  1555.       Result:=0;
  1556. end;
  1557.  
  1558. function TForumConfList.Contains(const Name: string): Boolean;
  1559. begin
  1560.   Result:=IndexOf(Name) >= 0;
  1561. end;
  1562.  
  1563. function TForumConfList.ContainsFromURI(const URI: string): boolean;
  1564. begin
  1565.   Result:=IndexOfFromURI(URI) >= 0;
  1566. end;
  1567.  
  1568. constructor TForumConfList.Create;
  1569. begin
  1570.   inherited Create(TComparer<TForumConf>.Construct(Comparison));
  1571.   FDomainComparer:=TComparer<TDomainRec>.Construct(ComparisonDomain);
  1572. end;
  1573.  
  1574. procedure TForumConfList.Delete(const Name: string);
  1575. begin
  1576.   Delete(IndexOf(Name));
  1577. end;
  1578.  
  1579. function TForumConfList.GetItems(Name: string): TForumConf;
  1580. var
  1581.   i:integer;
  1582. begin
  1583.   i:=IndexOf(Name);
  1584.   if i=-1 then
  1585.     EFPExcpValue.Create(SErrAdd);
  1586.   Result:=Items[i];
  1587. end;
  1588.  
  1589. function TForumConfList.GetTegsList: TTegsList;
  1590. var
  1591.   I: Integer;
  1592. begin
  1593.   if Assigned(FTegsList) then
  1594.     FTegsList.Clear
  1595.   else
  1596.     FTegsList:=TTegsList.Create;
  1597.  
  1598.   for I := 0 to Count-1 do
  1599.     FTegsList.Add(Items[i].Tegs);
  1600.   Result:=FTegsList;
  1601. end;
  1602.  
  1603. function TForumConfList.GetURIItems(URI: string): TForumConf;
  1604. begin
  1605.   Result:=Items[IndexOfFromURI(URI)];
  1606. end;
  1607.  
  1608. function TForumConfList.IndexOf(const Name: string): integer;
  1609. var
  1610.   tmp:TForumConf;
  1611. begin
  1612.   tmp.Name:=Name;
  1613.   if not BinarySearch(tmp,Result) then
  1614.     Result:=-1;
  1615. end;
  1616.  
  1617. function TForumConfList.IndexOfFromURI(const URI: string): integer;
  1618. begin
  1619.   MakeDomainArray;
  1620.   if not TArray.BinarySearch<TDomainRec>(FDomainArray,
  1621.         TDomainRec.Create(GetDomain(URI),-1),
  1622.         Result, FDomainComparer)
  1623.   then
  1624.     Result:=-1
  1625.   else
  1626.     Result:=FDomainArray[Result].Value;
  1627. end;
  1628.  
  1629. function TForumConfList.ListOfNames: string;
  1630. var
  1631.   I:integer;
  1632. begin
  1633.   Result:='';
  1634.   for i := 0 to Count-1 do
  1635.     Result:=Result + Items[i].Name + #10;
  1636. end;
  1637.  
  1638.  
  1639. function TForumConfList.ListOfURI: string;
  1640. var
  1641.   I: Integer;
  1642. begin
  1643.   Result:='';
  1644.   for I := 0 to Count-1 do
  1645.     Result:=Result+Items[i].LogURI+#10;
  1646. end;
  1647.  
  1648. procedure TForumConfList.MakeDomainArray;
  1649. var
  1650.   I: Integer;
  1651. begin
  1652.   if FModified then
  1653.   begin
  1654.     FModified:=false;
  1655.     SetLength(FDomainArray,Count);
  1656.     for I := 0 to Count-1 do
  1657.     begin
  1658.       FDomainArray[i].Key:=GetDomain(Items[i].LogURI);
  1659.       FDomainArray[i].Value:=i;
  1660.     end;
  1661.     TArray.Sort<TDomainRec>(FDomainArray,FDomainComparer);
  1662.   end;
  1663. end;
  1664.  
  1665. procedure TForumConfList.SetItems(Name: string; const Value: TForumConf);
  1666. begin
  1667.   Delete(Name);
  1668.   Add(Value);
  1669. end;
  1670.  
  1671. procedure TForumConfList.SetURIItems(URI: string; const Value: TForumConf);
  1672. begin
  1673.   Items[IndexOfFromURI(URI)]:=Value;
  1674. end;
  1675.  
  1676. { TBookConfList }
  1677.  
  1678. function TBookmarkConfList.Add(const Value: TBookmarkConf): Integer;
  1679. var
  1680.   AValue:TBookmarkConf;
  1681. begin
  1682. //  if Value.URI='' then
  1683. //    raise EFPException.CreateFmt(RSBadIdent,[Value.URI]);
  1684.   if not Assigned(Value.Tegs) then
  1685.   begin
  1686.     AValue:=Value;
  1687.     AValue.Tegs := TTegsList.Create;
  1688.     Result:= inherited Add(AValue);
  1689.   end
  1690.   else
  1691.     Result:= inherited;
  1692. end;
  1693.  
  1694. function TBookmarkConfList.Comparison(const Left, Right: TBookmarkConf): Integer;
  1695. begin
  1696.   if Left.URI > Right.URI then
  1697.     Result:=1
  1698.   else
  1699.     if Left.URI < Right.URI then
  1700.       Result:=-1
  1701.     else
  1702.       Result:=0;
  1703. end;
  1704.  
  1705. function TBookmarkConfList.Contains(const URI: string): Boolean;
  1706. begin
  1707.   Result:= IndexOf(URI) >= 0;
  1708. end;
  1709.  
  1710. constructor TBookmarkConfList.Create;
  1711. begin
  1712.   inherited Create(TComparer<TBookmarkConf>.Construct(Comparison));
  1713. end;
  1714.  
  1715. procedure TBookmarkConfList.Delete(const URI: string);
  1716. begin
  1717.   Delete(IndexOf(URI));
  1718. end;
  1719.  
  1720. function TBookmarkConfList.GetItems(URI: string): TBookmarkConf;
  1721. var
  1722.   i:integer;
  1723. begin
  1724.   i:=IndexOf(URI);
  1725.   if i=-1 then
  1726.     EFPExcpValue.Create(SErrAdd);
  1727.   Result:=Items[i];
  1728. end;
  1729.  
  1730. function TBookmarkConfList.IndexOf(const URI: string): integer;
  1731. var
  1732.   tmp:TBookmarkConf;
  1733. begin
  1734.   tmp.URI:=URI;
  1735.   if not BinarySearch(tmp,Result) then
  1736.     Result:=-1;
  1737. end;
  1738.  
  1739. function TBookmarkConfList.ListOfURI: string;
  1740. var
  1741.   I:integer;
  1742. begin
  1743.   Result:='';
  1744.   for i := 0 to Count-1 do
  1745.     Result:=Result + Items[i].URI + #10;
  1746. end;
  1747.  
  1748. procedure TBookmarkConfList.SetItems(URI: string; const Value: TBookmarkConf);
  1749. begin
  1750.   Delete(URI);
  1751.   Add(Value);
  1752. end;
  1753.  
  1754. function TBookmarkConfList.GetTegsList: TTegsList;
  1755. var
  1756.   I: Integer;
  1757. begin
  1758.   if Assigned(FTegsList) then
  1759.     FTegsList.Clear
  1760.   else
  1761.     FTegsList:=TTegsList.Create;
  1762.  
  1763.   for I := 0 to Count-1 do
  1764.     FTegsList.Add(Items[i].Tegs);
  1765.   Result:=FTegsList;
  1766. end;
  1767.  
  1768. end.
Advertisement
Add Comment
Please, Sign In to add comment