Changeset 3 for trunk/USource.pas


Ignore:
Timestamp:
Feb 2, 2011, 2:14:37 PM (13 years ago)
Author:
chronos
Message:
  • Added: Not finished updating of sources from web.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        11lib
        22FreePascalManager.exe
         3SourceList.xml
         4Config.xml
  • trunk/USource.pas

    r2 r3  
    66
    77uses
    8   Classes, SysUtils, Contnrs;
     8  Classes, SysUtils, Contnrs, FileUtil,
     9  DOM, XMLWrite, XMLRead, HTTPSend;
    910
    1011type
    1112  TSourceType = (stFPC, stIDE);
     13
     14  { TSource }
    1215
    1316  TSource = class
     
    1518    Name: string;
    1619    SubversionURL: string;
    17     Version: string;
    18     Variation: string;
     20    VersionNumber: string;
     21    VersionType: string;
    1922    SourceType: TSourceType;
     23    procedure Assign(Source: TSource);
    2024  end;
    2125
     
    2428  TSourceList = class(TObjectList)
    2529    function FindById(Id: Integer): TSource;
     30    procedure UpdateFormFile(FileName: string);
    2631  end;
    2732
    2833implementation
     34
     35{ TSource }
     36
     37procedure TSource.Assign(Source: TSource);
     38begin
     39  Id := Source.Id;
     40  Name := Source.Name;
     41  VersionNumber := Source.VersionNumber;
     42  VersionType := Source.VersionType;
     43  SubversionURL := Source.SubversionURL;
     44  SourceType := Source.SourceType;
     45end;
    2946
    3047{ TSourceList }
     
    4057end;
    4158
     59procedure TSourceList.UpdateFormFile(FileName: string);
     60var
     61  Doc: TXMLDocument;
     62  NewNode: TDOMNode;
     63  NewSubNode: TDOMNode;
     64  I: Integer;
     65  NewSource: TSource;
     66  Child: TDOMNode;
     67  ExistedSource: TSource;
     68begin
     69  if FileExistsUTF8(FileName) then
     70  try
     71    ReadXMLFile(Doc, UTF8Decode(FileName));
     72
     73    NewNode := Doc.DocumentElement.FindNode('Items');
     74    Child := NewNode.FirstChild;
     75    while Assigned(Child) do
     76    with Child do begin
     77      try
     78        NewSource := TSource.Create;
     79        with NewSource do begin
     80          NewSubNode := Child.FindNode('Name');
     81          if Assigned(NewSubNode) then
     82            Name := UTF8Encode(string(NewSubNode.TextContent));
     83          NewSubNode := Child.FindNode('Id');
     84          if Assigned(NewSubNode) then
     85            Id := StrToInt(NewSubNode.TextContent);
     86          NewSubNode := Child.FindNode('SubversionURL');
     87          if Assigned(NewSubNode) then
     88            SubversionURL := UTF8Encode(string(NewSubNode.TextContent));
     89          NewSubNode := Child.FindNode('VersionNumber');
     90          if Assigned(NewSubNode) then
     91            VersionNumber := UTF8Encode(string(NewSubNode.TextContent));
     92          NewSubNode := Child.FindNode('VersionType');
     93          if Assigned(NewSubNode) then
     94            VersionType := UTF8Encode(string(NewSubNode.TextContent));
     95          NewSubNode := Child.FindNode('SourceType');
     96          if Assigned(NewSubNode) then
     97            SourceType := TSourceType(StrToInt(NewSubNode.TextContent));
     98        end;
     99        ExistedSource := FindById(NewSource.Id);
     100        if Assigned(ExistedSource) then begin
     101          ExistedSource.Assign(NewSource);
     102        end else begin
     103          Add(NewSource);
     104          FreeAndNil(NewSource);
     105        end;
     106      finally
     107        NewSource.Free;
     108      end;
     109      Child := Child.NextSibling;
     110    end;
     111  finally
     112    Doc.Free;
     113  end;
     114end;
     115
    42116end.
    43117
Note: See TracChangeset for help on using the changeset viewer.