Source file: /~heha/hsn/WdxInfoPacker64.zip/Thread_IniPop.pas

{$D-,O+,Q-,R-,S-}
unit Thread_IniPop;

interface

uses
  //dialogs,
  someStuff,
  Windows, ExtCtrls, Forms, StdCtrls,Menus, Classes, WdxStruc,IniFile_Class, SysUtils,Inifiles;

type
  IniPop = class(TThread)
  private
  IniFile,ContP:array[0..260] of char;
  PopupMenu1:TPopupMenu;
  edit99:TEDIT;
  locbutton:TButton;
  lng:array[0..4]of char;
  CptPlugin:integer;
  testUnload:boolean;
  procedure setInifile(Value:pchar);
  procedure PopItemClickForUnit(Sender: TObject);
  procedure PopItemClickForField(Sender: TObject);
  public
    displayMe:boolean;
    constructor Create(PopMenu:TPopupMenu;WdxInfoPacker:TMyIni;Edit7:TEDIT;Button11:TButton;ContPlug:pchar);
  protected
  procedure Execute(); override;
  end;

implementation

var AllMyKnownWdx:array of TWdxInfo;
WdxInfoLoc:TMyIni;
var dps1:tContentDefaultParamStruct;
constructor IniPop.Create(PopMenu:TPopupMenu;WdxInfoPacker:TMyIni;Edit7:TEDIT;Button11:TButton;ContPlug:pchar);
begin
  WdxInfoLoc:=TMyIni.Create;
  FreeOnTerminate := True;
  inherited Create(False);
  locbutton:=Tbutton.Create(application);
  locbutton:=Button11;
  locbutton.Enabled:=false;
  FillChar(ContP,sizeof(ContP),#0);
  StrLCopy(ContP,ContPlug,sizeof(ContP)-1);
  setInifile(WdxInfoPacker.MyIni.PathToIni);
  PopupMenu1:=TPopupMenu.Create(application);
  PopupMenu1:=PopMenu;
  PopupMenu1.items.clear;
  Edit99:=TEdit.Create(application);
  Edit99:=Edit7;
  fillchar(lng,sizeof(lng),#0);
  strlcat(lng,WdxInfoPacker.MyIni.Wdx_lng,sizeof(lng)-1);
  CptPlugin:=WdxInfoPacker.CountknownPlugin;

  SetLength(AllMyknownWdx,CptPlugin);
  WdxInfoLoc:=WdxInfoPacker;

end;

  procedure IniPop.setInifile(Value:pchar);
  begin
  fillchar(IniFile,sizeof(IniFile),#0);
  strlcat(IniFile,Value,sizeof(IniFile)-1);
  end;

procedure IniPop.PopItemClickForUnit(Sender: TObject);
var Parent,GDParent : TMENUITEM;
current:integer;
begin
  Parent:=(Sender as TMENUITEM).Parent;
  current:=Parent.IndexOf((Sender as TMENUITEM));
  GDParent:=Parent.Parent;
  if edit99.text<>'' then begin
    edit99.Text:=edit99.Text+';@Mod='+Parent.Hint+'.'+Parent.Find(Parent.items[current].Caption).Hint+'@'+GDParent.caption;
  end else begin
    edit99.Text:='@Mod='+Parent.Hint+'.'+Parent.Find(Parent.items[current].Caption).Hint+'@'+GDParent.caption;
  end;
end;
procedure IniPop.PopItemClickForField(Sender: TObject);
var Parent : TMENUITEM;
current:integer;
begin
  Parent:=(Sender as TMENUITEM).Parent;
  current:=Parent.IndexOf((Sender as TMENUITEM));
  if edit99.text<>'' then begin
    edit99.Text:=edit99.Text+';@Mod='+Parent.items[current].Hint+'@'+Parent.Caption;
  end else begin
    edit99.Text:='@Mod='+Parent.items[current].Hint+'@'+Parent.Caption;
  end;
end;

procedure IniPop.Execute;
var path,s,s1:string;
i,j,k:integer;
Lev1,Lev2,Lev3: TMenuItem;
List2,List3:Tstringlist;
Liste1,Liste2:Tstringlist;
UnloadListe:Tstringlist;
tmpini:TIniFile;
translation:boolean;
res:bool;
begin
     UnloadListe:=Tstringlist.create;
     Liste1:=Tstringlist.create;
     Liste2:=Tstringlist.create;
     WdxInfoLoc.ListPlugin(liste1,liste2);
     dps1.PluginInterfaceVersionLow:=40;
     dps1.PluginInterfaceVersionHi:=1;
     dps1.size:=sizeof(dps1);
     s:=ContP;
     FillChar(dps1.DefaultIniName,sizeof(dps1.DefaultIniName),#0);
     strlcat(dps1.DefaultIniName,pchar(s),sizeof(dps1.DefaultIniName)-1);
     dps1.size:=sizeof(dps1);
     for  i:=0 to liste1.count-1 do begin
        AllMyKnownWdx[i]:=TwdxInfo.create;
        res:=AllMyKnownWdx[i].Load(pchar(Liste1[i]),pchar(Liste2[i]),dps1);
        AllMyKnownWdx[i].CanBeUsed:=res;
        AllMyKnownWdx[i].init;
     end;
  for i:=0 to Liste1.Count-1 do begin
	s:='';
	tmpini:=TIniFile.Create(s);
	translation:=false;
	path:=liste2[i];
  if lng <> '' then begin
    translation:=true;
    s:=StringReplace(path,ExtractFileExt(path), '.lng',[rfReplaceAll, rfIgnoreCase]);
    tmpini:=TIniFile.Create(s);
  end;
  Lev1 := TMenuItem.Create(PopupMenu1);
  Lev1.Caption :=Liste1[i]; //Nom du plugin
  PopupMenu1.Items.Add(Lev1);
  List2:=AllMyKnownWdx[i].GetPluginField('empty');
  for k:=0 to List2.Count-1 do begin
	  Lev2:=TMenuItem.Create(Lev1);
	  if (translation) then begin
	  s1:=tmpini.ReadString(lng,List2[k],List2[k]);
	  Lev2.caption:=s1;
	  Lev2.Hint:=List2[k];
	  end
    else begin
      Lev2.caption:=List2[k];
      Lev2.Hint:=List2[k];
    end;
          PopupMenu1.Items[i].Add(Lev2);
          List3:=AllMyKnownWdx[i].GetCurrentUnit(k);
          if List3.count>1 then begin
             for j:=0 to List3.Count-1 do begin
                 Lev3:=TMenuItem.Create(Lev2);
                 if translation then begin
                    s1:=tmpini.ReadString(lng,List3[j],List3[j]);
                    Lev3.caption:=s1;
                    Lev3.Hint:=List3[j];
                 end
		 else begin
                    Lev3.caption:=List3[j];
                    Lev3.Hint:=List3[j];
                 end;
                 Lev3.OnClick := PopItemClickForUnit;
                 PopupMenu1.Items[i].items[k].add(Lev3);
             end;
          end else Lev2.OnClick := PopItemClickForField;
        end;
	tmpini.Free;
  end;

  s:=getExtendedPath(WdxInfoLoc.MyIni.UnloadingFile);
  if (pos(':\',s)=0) then s:=ExtractFilePath(WdxInfoLoc.MyIni.PathToIni)+s;
  if (strlen(pchar(s))>0) then begin
    if (FileExists(s)) then begin
      UnloadListe.LoadFromFile(s);
      testUnload:=true;
    end
    else testUnload:=false;
  end;
  k:=0;
  for i:=0 to  CptPlugin-1 do begin
    if (testUnload=true) then begin
      if (UnloadListe.Find(AllMyKnownWdx[i].Name,k)=true) then AllMyKnownWdx[i].FreeMe(true)
      else AllMyKnownWdx[i].FreeMe(false);
    end else AllMyKnownWdx[i].FreeMe(false);
  end;
  UnloadListe.Free;
  Setlength(AllMyKnownWdx,0);
locbutton.Enabled:=true;
end;

end.
Detected encoding: ASCII (7 bit)2