source: trunk/USource.pas

Last change on this file was 13, checked in by chronos, 6 years ago
  • Fixed: Build under Lazarus 1.8.0.
File size: 5.2 KB
Line 
1unit USource;
2
3{$mode objfpc}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, Contnrs, FileUtil, Dialogs, Forms,
9 DOM, XMLWrite, XMLRead;
10
11type
12 TSourceType = (stFPC, stIDE);
13
14 { TSource }
15
16 TSource = class
17 private
18 function GetDownloaded: Boolean;
19 public
20 Id: Integer;
21 ProjectName: string;
22 ProjectShortName: string;
23 ProjectType: string;
24 SubversionURL: string;
25 VersionNumber: string;
26 VersionType: string;
27 SourceType: TSourceType;
28 ExecutableFile: string;
29 property Downloaded: Boolean read GetDownloaded;
30 procedure Assign(Source: TSource);
31 procedure Download;
32 procedure Update;
33 procedure ExportTo(Path: string);
34 function GetExecutableFile: string;
35 function GetPath: string;
36 function GetName: string;
37 end;
38
39 { TSourceList }
40
41 TSourceList = class(TObjectList)
42 function FindById(Id: Integer): TSource;
43 procedure UpdateFormFile(FileName: string);
44 end;
45
46implementation
47
48uses
49 UMainForm, UOperationProgress;
50
51{ TSource }
52
53function TSource.GetDownloaded: Boolean;
54begin
55 Result := DirectoryExists(GetPath);
56end;
57
58procedure TSource.Assign(Source: TSource);
59begin
60 Id := Source.Id;
61 ProjectName := Source.ProjectName;
62 ProjectShortName := Source.ProjectShortName;
63 ProjectType := Source.ProjectType;
64 VersionNumber := Source.VersionNumber;
65 VersionType := Source.VersionType;
66 SubversionURL := Source.SubversionURL;
67 SourceType := Source.SourceType;
68 ExecutableFile := Source.ExecutableFile;
69end;
70
71procedure TSource.Download;
72begin
73 OperationProgressForm.CommandLine := 'svn checkout "' + SubversionURL +
74 '" "' + GetPath + '"';
75 OperationProgressForm.ShowModal;
76end;
77
78procedure TSource.Update;
79begin
80 OperationProgressForm.CommandLine := 'svn update "' + GetPath + '"';
81 OperationProgressForm.ShowModal;
82end;
83
84procedure TSource.ExportTo(Path: string);
85begin
86 OperationProgressForm.CommandLine := 'svn export --force "' + GetPath + '" "' +
87 Path + '"';
88 OperationProgressForm.ShowModal;
89end;
90
91function TSource.GetExecutableFile: string;
92var
93 Postfix: string;
94begin
95 PostFix := '';
96 {$IFDEF WINDOWS}
97 PostFix := '.exe';
98 {$ENDIF}
99 Result := ExecutableFile + Postfix;
100end;
101
102function TSource.GetPath: string;
103begin
104 Result := ExtractFileDir(Application.ExeName) + DirectorySeparator +
105 MainForm.SourceDir + DirectorySeparator + IntToStr(Id);
106end;
107
108function TSource.GetName: string;
109begin
110 Result := ProjectShortName + ' ' + VersionNumber +
111 ' (' + VersionType + ')';
112end;
113
114{ TSourceList }
115
116function TSourceList.FindById(Id: Integer): TSource;
117var
118 I: Integer;
119begin
120 I := 0;
121 while (I < Count) and (TSource(Items[I]).Id <> Id) do Inc(I);
122 if I < Count then Result := TSource(Items[I])
123 else Result := nil;
124end;
125
126procedure TSourceList.UpdateFormFile(FileName: string);
127var
128 Doc: TXMLDocument;
129 NewNode: TDOMNode;
130 NewSubNode: TDOMNode;
131 I: Integer;
132 NewSource: TSource;
133 Child: TDOMNode;
134 ExistedSource: TSource;
135begin
136 if FileExists(FileName) then
137 try
138 ReadXMLFile(Doc, UTF8Decode(FileName));
139
140 NewNode := Doc.DocumentElement.FindNode('Items');
141 Child := NewNode.FirstChild;
142 while Assigned(Child) do
143 with Child do begin
144 try
145 NewSource := TSource.Create;
146 with NewSource do begin
147 NewSubNode := Child.FindNode('ProjectName');
148 if Assigned(NewSubNode) then
149 ProjectName := UTF8Encode(string(NewSubNode.TextContent));
150 NewSubNode := Child.FindNode('ProjectShortName');
151 if Assigned(NewSubNode) then
152 ProjectShortName := UTF8Encode(string(NewSubNode.TextContent));
153 NewSubNode := Child.FindNode('ProjectType');
154 if Assigned(NewSubNode) then
155 ProjectType := UTF8Encode(string(NewSubNode.TextContent));
156 NewSubNode := Child.FindNode('Id');
157 if Assigned(NewSubNode) then
158 Id := StrToInt(NewSubNode.TextContent);
159 NewSubNode := Child.FindNode('SubversionURL');
160 if Assigned(NewSubNode) then
161 SubversionURL := UTF8Encode(string(NewSubNode.TextContent));
162 NewSubNode := Child.FindNode('VersionNumber');
163 if Assigned(NewSubNode) then
164 VersionNumber := UTF8Encode(string(NewSubNode.TextContent));
165 NewSubNode := Child.FindNode('VersionType');
166 if Assigned(NewSubNode) then
167 VersionType := UTF8Encode(string(NewSubNode.TextContent));
168 NewSubNode := Child.FindNode('ExecutableFile');
169 if Assigned(NewSubNode) then
170 ExecutableFile := UTF8Encode(string(NewSubNode.TextContent));
171 NewSubNode := Child.FindNode('SourceType');
172 if Assigned(NewSubNode) then
173 SourceType := TSourceType(StrToInt(NewSubNode.TextContent));
174 end;
175 ExistedSource := FindById(NewSource.Id);
176 if Assigned(ExistedSource) then begin
177 ExistedSource.Assign(NewSource);
178 end else begin
179 Add(NewSource);
180 NewSource := nil;
181 end;
182 finally
183 NewSource.Free;
184 end;
185 Child := Child.NextSibling;
186 end;
187 finally
188 Doc.Free;
189 end;
190end;
191
192end.
193
Note: See TracBrowser for help on using the repository browser.