DModule.pas 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. {
  2. $Project$
  3. $Workfile$
  4. $Revision$
  5. $DateUTC$
  6. $Id$
  7. This file is part of the Indy (Internet Direct) project, and is offered
  8. under the dual-licensing agreement described on the Indy website.
  9. (http://www.indyproject.org/)
  10. Copyright:
  11. (c) 1993-2005, Chad Z. Hower and the Indy Pit Crew. All rights reserved.
  12. }
  13. {
  14. $Log$
  15. }
  16. {
  17. { Rev 1.5 9/4/2004 10:46:20 AM JPMugaas
  18. { Now some path settings were hard coded into the data module DFM causing
  19. { strange resutls.
  20. }
  21. {
  22. { Rev 1.4 04/09/2004 12:45:16 ANeillans
  23. { Moved the databasename and output paths into a globally accessible variable
  24. { -- makes it a lot easier to override if you need to (as I did for my local
  25. { file structure).
  26. }
  27. {
  28. { Rev 1.3 6/9/2004 7:47:16 AM JPMugaas
  29. { New feild for FTP Parser class.
  30. }
  31. {
  32. { Rev 1.2 02/06/2004 17:00:44 HHariri
  33. { design-time added
  34. }
  35. {
  36. { Rev 1.1 2004.01.22 8:17:58 PM czhower
  37. { Updates
  38. }
  39. {
  40. { Rev 1.0 2004.01.22 1:52:42 AM czhower
  41. { Initial checkin
  42. }
  43. unit DModule;
  44. interface
  45. uses
  46. SysUtils, Classes, IniFiles;
  47. type
  48. TDM = class(TDataModule)
  49. private
  50. protected
  51. FDataPath : String;
  52. FOutputPath : String;
  53. FIni: TMemIniFile;
  54. procedure SetDataPath(const AValue : String);
  55. public
  56. constructor Create(AOwner: TComponent); override;
  57. procedure CheckForMissingFiles;
  58. procedure GetFileList(const ACriteria: String; AFiles: TStrings);
  59. property DataPath : String read FDataPath write SetDataPath;
  60. property OutputPath : String read FOutputPath write FOutputPath;
  61. property Ini: TMemIniFile read FIni;
  62. end;
  63. var
  64. DM: TDM;
  65. var
  66. GIndyPath : String = 'W:\Source\Indy10\';
  67. procedure DumpData(const AFile: String);
  68. implementation
  69. {$R *.dfm}
  70. procedure DumpData(const AFile: String);
  71. var
  72. LNames: TStringList;
  73. I: Integer;
  74. begin
  75. LNames := TStringList.Create;
  76. try
  77. DM.Ini.ReadSection(AFile, LNames);
  78. for I := 0 to LNames.Count-1 do
  79. WriteLn(LNames[I] + ' = "' + DM.Ini.ReadString(AFile, LNames[I], '') + '"');
  80. finally
  81. LNames.Free;
  82. end;
  83. end;
  84. function UpTwoDirs(const APath : String):String;
  85. begin
  86. Result := SysUtils.ExcludeTrailingPathDelimiter(APath);
  87. Result := ExtractFilePath(Result);
  88. Result := SysUtils.ExcludeTrailingPathDelimiter(Result);
  89. Result := ExtractFilePath(Result);
  90. end;
  91. { TDM }
  92. constructor TDM.Create(AOwner: TComponent);
  93. begin
  94. inherited Create(AOwner);
  95. // Default Output Path is w:\source\Indy10
  96. OutputPath := SysUtils.ExcludeTrailingPathDelimiter(GIndyPath);
  97. // Default Data Path is W:\source\Indy10\builder\Package Generator\Data
  98. DataPath := GIndyPath + 'Builder\Package Generator\Data';
  99. end;
  100. procedure TDM.CheckForMissingFiles;
  101. var
  102. SR: TSearchRec;
  103. UnitName: String;
  104. begin
  105. if FindFirst(GIndyPath + 'Lib\System\*.pas', faAnyFile, SR) = 0 then
  106. try
  107. repeat
  108. UnitName := ChangeFileExt(SR.Name, '');
  109. if not FIni.SectionExists(UnitName) then
  110. begin
  111. FIni.WriteString(UnitName, 'Pkg', 'System');
  112. FIni.WriteBool(UnitName, 'SettingsNeeded', True);
  113. WriteLn('Missing settings for: System\' + UnitName);
  114. end;
  115. until FindNext(SR) <> 0;
  116. finally
  117. FindClose(SR);
  118. end;
  119. if FindFirst(GIndyPath + 'Lib\Core\*.pas', faAnyFile, SR) = 0 then
  120. try
  121. repeat
  122. UnitName := ChangeFileExt(SR.Name, '');
  123. if not FIni.SectionExists(UnitName) then
  124. begin
  125. FIni.WriteString(UnitName, 'Pkg', 'Core');
  126. FIni.WriteBool(UnitName, 'SettingsNeeded', True);
  127. WriteLn('Missing settings for: Core\' + UnitName);
  128. end;
  129. until FindNext(SR) <> 0;
  130. finally
  131. FindClose(SR);
  132. end;
  133. if FindFirst(GIndyPath + 'Lib\Protocols\*.pas', faAnyFile, SR) = 0 then
  134. try
  135. repeat
  136. UnitName := ChangeFileExt(SR.Name, '');
  137. if not FIni.SectionExists(UnitName) then
  138. begin
  139. FIni.WriteString(UnitName, 'Pkg', 'Protocols');
  140. FIni.WriteBool(UnitName, 'SettingsNeeded', True);
  141. WriteLn('Missing settings for: Protocols\' + UnitName);
  142. end;
  143. until FindNext(SR) <> 0;
  144. finally
  145. FindClose(SR);
  146. end;
  147. if FindFirst(GIndyPath + 'Lib\Protocols\IdFTPListParse*.pas', faAnyFile, SR) = 0 then
  148. try
  149. repeat
  150. UnitName := ChangeFileExt(SR.Name, '');
  151. if not FIni.SectionExists(UnitName) then
  152. begin
  153. FIni.WriteString(UnitName, 'Pkg', 'Protocols');
  154. FIni.WriteBool(UnitName, 'SettingsNeeded', True);
  155. WriteLn('Missing settings for: Protocols\' + UnitName);
  156. end;
  157. until FindNext(SR) <> 0;
  158. finally
  159. FindClose(SR);
  160. end;
  161. end;
  162. procedure TDM.GetFileList(const ACriteria: String; AFiles: TStrings);
  163. var
  164. LFiles: TStringList;
  165. LCriteria: TStringList;
  166. I, J: Integer;
  167. LMatches: Boolean;
  168. LCriteriaName, LCriteriaValue, LFileValue: String;
  169. begin
  170. AFiles.Clear;
  171. LFiles := TStringList.Create;
  172. try
  173. FIni.ReadSections(LFiles);
  174. LCriteria := TStringList.Create;
  175. try
  176. LCriteria.CommaText := ACriteria;
  177. for I := 0 to LFiles.Count-1 do
  178. begin
  179. LMatches := True;
  180. for J := 0 to LCriteria.Count-1 do
  181. begin
  182. LCriteriaName := LCriteria.Names[J];
  183. LCriteriaValue := LCriteria.ValueFromIndex[J];
  184. LFileValue := FIni.ReadString(LFiles[I], LCriteriaName, '');
  185. if LFileValue <> LCriteriaValue then
  186. begin
  187. LMatches := False;
  188. Break;
  189. end;
  190. end;
  191. if LMatches then
  192. begin
  193. AFiles.Add(LFiles[I]);
  194. end;
  195. end;
  196. finally
  197. LCriteria.Free;
  198. end;
  199. finally
  200. LFiles.Free;
  201. end;
  202. end;
  203. procedure TDM.SetDataPath(const AValue: String);
  204. begin
  205. FDataPath := AValue;
  206. FreeAndNil(FIni);
  207. FIni := TMemIniFile.Create(SysUtils.IncludeTrailingPathDelimiter(AValue) + 'File.ini');
  208. end;
  209. procedure SetIndyPath;
  210. var
  211. Param: String;
  212. I: Integer;
  213. begin
  214. if ParamCount > 0 then begin
  215. for I := 1 to ParamCount do begin
  216. Param := ParamStr(I);
  217. if not CharInSet(Param[1], ['/', '-']) then begin
  218. GIndyPath := IncludeTrailingPathDelimiter(Param);
  219. Exit;
  220. end;
  221. end;
  222. end;
  223. GIndyPath := UpTwoDirs(ExtractFilePath(ParamStr(0)));
  224. end;
  225. initialization
  226. SetIndyPath;
  227. end.