unit repositorysystem;

interface

uses xmldom, XMLIntf, msxmldom, XMLDoc, sysutils, forms;

Type
  TRepository = record
   Title: String;
   Description: String;
   Creator: String;
   Rating: String;
   ReviewComment: String;
   ReviewedBy: String;
   Screen: String;
   UpdFile: String;
  end;
  TRepositoryList = class(Tobject)
  private
   fList: Array of TRepository;
    function GET_COUNT: integer;
    function GET_REP(Index: Integer): TRepository;
    procedure SET_REP(Index: Integer; const Value: TRepository);
  public
   property Count: integer read GET_COUNT;
   property Repository[Index: Integer]: TRepository read GET_REP write SET_REP; default;
   function add: TRepository;
   function LoadXML(Filename: String): boolean;
  end;

  TpluginType = (ptGeneral, ptVisual, ptCMLx);
  Function IsPlugInInstalled(Name: String; PluginType: TPlugInType): Boolean;

implementation

Uses Registry, Windows, Classes, CM2Update, LPL_Sysutils;

Function IsPlugInInstalled(Name: String; PluginType: TPlugInType): Boolean;
Var
 Reg: TRegistry;
 List: TStringList;
 I: Integer;
 PlugLocation: String;
 DefaultKeyValue: String;
Begin
 Result := false;
 Reg := TRegistry.Create;
 Reg.RootKey := HKEY_CURRENT_USER;
 Case PlugInType of
  ptGeneral: Begin
              PlugLocation := GenPlugLocation;
             end;
  ptVisual: Begin
              PlugLocation := VisPlugLocation;
            end;
  ptCMLx: begin
           PlugLocation := CMLxPlugLocation;
          end;
 end;
 If Not Reg.OpenKey(PlugLocation, false) then begin
  Reg.Free;
  exit;
 end;
 List := TStringList.Create;
 Reg.GetKeyNames(List);
 For I := 0 to List.Count - 1 do begin
  Reg.OpenKey(PathToOk(PlugLocation) + List[I], false);
  DefaultKeyValue := Reg.ReadString('');
  If uppercase(Name) = uppercase(DefaultKeyValue) then begin
   Result := true;
   break;
  end;
 end;
 Reg.Free;
 List.Free;
End;

{ TRepositoryList }

function TRepositoryList.add: TRepository;
begin
 Setlength(fList, length(fList) + 1);
 Result := fList[Length(fList)-1];
end;

function TRepositoryList.GET_COUNT: integer;
begin
 Result := length(flist);
end;

function TRepositoryList.GET_REP(Index: Integer): TRepository;
begin
 Result := fList[Index];
end;

function TRepositoryList.LoadXML(Filename: String): boolean;
Var
 XML: TXMLDocument;
 aNode, Node: IXMLNode;
 I: Integer;
 aForm: TForm;
begin
 Result := false;
 If not fileexists(Filename) then exit;
 aForm := TForm.Create(nil);
 XML := TXMLDocument.Create(aForm);
 XML.FileName := filename;
 XML.Active := true;
 Node := XML.ChildNodes.FindNode('Repository');
 if node <> nil then begin
  result := true;
  For I := 0 to Node.ChildNodes.Count - 1 do begin
   If uppercase(node.ChildNodes[I].NodeName) = 'PLUGIN' then begin
    aNode := Node.ChildNodes[I];
    SetLength(fList, length(fList) + 1);
    With fList[Length(fList)-1] do begin
     Title := aNode.ChildNodes.FindNode('Title').NodeValue;
     Description := aNode.ChildNodes.FindNode('Description').NodeValue;
     Creator := aNode.ChildNodes.FindNode('Creator').NodeValue;
     Rating := aNode.ChildNodes.FindNode('Rating').NodeValue;
     ReviewComment := aNode.ChildNodes.FindNode('ReviewComment').NodeValue;
     ReviewedBy := aNode.ChildNodes.FindNode('ReviewedBy').NodeValue;
     Try
      Screen := aNode.ChildNodes.FindNode('Screen').NodeValue;
     except
      Screen := 'NOFILE';
     end;
     Try
      UpdFile := aNode.ChildNodes.FindNode('UpdFile').NodeValue;
     except

     end;
    end;
   end;
  end;
 end;
 XML.Active := false;
 FreeAndNil(XML);
 FreeAndNil(aForm);
end;

procedure TRepositoryList.SET_REP(Index: Integer;
  const Value: TRepository);
begin
 fList[Index] := Value;
end;

end.
