Changeset 7 for trunk/UProject.pas


Ignore:
Timestamp:
Mar 30, 2016, 11:32:54 PM (8 years ago)
Author:
chronos
Message:
  • Added: Main menu with available actions.
  • Added: Basic functionality to save project to file and open project from file.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UProject.pas

    r2 r7  
    66
    77uses
    8   Classes, SysUtils;
     8  Classes, SysUtils, Contnrs, DOM, XMLRead, XMLWrite, UXMLUtils, UDriveScan;
    99
    1010type
     
    2020    SectorCount: Integer;
    2121    Modified: Boolean;
     22    Scans: TDriveScanList;
    2223    constructor Create;
     24    destructor Destroy; override;
     25    procedure LoadFromFile(FileName: string);
     26    procedure SaveToFile(FileName: string);
    2327  end;
    2428
     29
    2530implementation
     31
     32resourcestring
     33  SWrongFileFormat = 'Wrong file format';
     34
    2635
    2736{ TProject }
     
    3039begin
    3140  SectorSize := 4096;
     41  Scans := TDriveScanList.Create;
    3242end;
     43
     44destructor TProject.Destroy;
     45begin
     46  FreeAndNil(Scans);
     47  inherited Destroy;
     48end;
     49
     50procedure TProject.SaveToFile(FileName: string);
     51var
     52  NewNode: TDOMNode;
     53  Doc: TXMLDocument;
     54  RootNode: TDOMNode;
     55begin
     56  Self.FileName := FileName;
     57  Doc := TXMLDocument.Create;
     58  with Doc do try
     59    RootNode := CreateElement('CoolDiskProject');
     60    AppendChild(RootNode);
     61    with RootNode do begin
     62      WriteInteger(RootNode, 'SectorSize', SectorSize);
     63
     64      NewNode := OwnerDocument.CreateElement('Scans');
     65      AppendChild(NewNode);
     66      Scans.SaveToNode(NewNode);
     67    end;
     68    ForceDirectories(ExtractFileDir(FileName));
     69    WriteXMLFile(Doc, FileName);
     70  finally
     71    Doc.Free;
     72  end;
     73end;
     74
     75procedure TProject.LoadFromFile(FileName: string);
     76var
     77  Doc: TXMLDocument;
     78  RootNode: TDOMNode;
     79  NewNode: TDOMNode;
     80begin
     81  Self.FileName := FileName;
     82  ReadXMLFile(Doc, FileName);
     83  with Doc do try
     84    if Doc.DocumentElement.NodeName <> 'CoolDiskProject' then
     85      raise Exception.Create(SWrongFileFormat);
     86    RootNode := Doc.DocumentElement;
     87    with RootNode do begin
     88      SectorSize := ReadInteger(RootNode, 'SectorSize', 4096);
     89
     90      NewNode := FindNode('Scans');
     91      if Assigned(NewNode) then
     92        Scans.LoadFromNode(NewNode);
     93    end;
     94  finally
     95    Doc.Free;
     96  end;
     97end;
     98
    3399
    34100end.
Note: See TracChangeset for help on using the changeset viewer.