DModule.pas 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. destructor Destroy; override;
  58. procedure CheckForMissingFiles;
  59. procedure GetFileList(const ACriteria: String; AFiles: TStrings);
  60. property DataPath : String read FDataPath write SetDataPath;
  61. property OutputPath : String read FOutputPath write FOutputPath;
  62. property Ini: TMemIniFile read FIni;
  63. end;
  64. var
  65. DM: TDM;
  66. var
  67. GIndyPath : String = 'W:\Source\Indy10\';
  68. procedure DumpData(const AFile: String);
  69. implementation
  70. {$R *.dfm}
  71. procedure DumpData(const AFile: String);
  72. var
  73. LNames: TStringList;
  74. I: Integer;
  75. begin
  76. LNames := TStringList.Create;
  77. try
  78. DM.Ini.ReadSection(AFile, LNames);
  79. for I := 0 to LNames.Count-1 do
  80. WriteLn(LNames[I] + ' = "' + DM.Ini.ReadString(AFile, LNames[I], '') + '"');
  81. finally
  82. LNames.Free;
  83. end;
  84. end;
  85. function UpTwoDirs(const APath : String):String;
  86. begin
  87. Result := SysUtils.ExcludeTrailingPathDelimiter(APath);
  88. Result := ExtractFilePath(Result);
  89. Result := SysUtils.ExcludeTrailingPathDelimiter(Result);
  90. Result := ExtractFilePath(Result);
  91. end;
  92. { TDM }
  93. constructor TDM.Create(AOwner: TComponent);
  94. begin
  95. inherited Create(AOwner);
  96. // Default Output Path is w:\source\Indy10\
  97. OutputPath := SysUtils.IncludeTrailingPathDelimiter(GIndyPath);
  98. // Default Data Path is W:\source\Indy10\Builder\Package Generator\Data
  99. DataPath := OutputPath + 'Builder\Package Generator\Data\';
  100. end;
  101. destructor TDM.Destroy;
  102. begin
  103. FreeAndNil(FIni);
  104. inherited Destroy;
  105. end;
  106. procedure TDM.CheckForMissingFiles;
  107. var
  108. SR: TSearchRec;
  109. UnitName: String;
  110. begin
  111. if FindFirst(GIndyPath + 'Lib\System\*.pas', faAnyFile, SR) = 0 then
  112. try
  113. repeat
  114. UnitName := ChangeFileExt(SR.Name, '');
  115. if not FIni.SectionExists(UnitName) then
  116. begin
  117. FIni.WriteString(UnitName, 'Pkg', 'System');
  118. FIni.WriteBool(UnitName, 'SettingsNeeded', True);
  119. WriteLn('Missing settings for: System\' + UnitName);
  120. end;
  121. until FindNext(SR) <> 0;
  122. finally
  123. FindClose(SR);
  124. end;
  125. if FindFirst(GIndyPath + 'Lib\Core\*.pas', faAnyFile, SR) = 0 then
  126. try
  127. repeat
  128. UnitName := ChangeFileExt(SR.Name, '');
  129. if not FIni.SectionExists(UnitName) then
  130. begin
  131. FIni.WriteString(UnitName, 'Pkg', 'Core');
  132. FIni.WriteBool(UnitName, 'SettingsNeeded', True);
  133. WriteLn('Missing settings for: Core\' + UnitName);
  134. end;
  135. until FindNext(SR) <> 0;
  136. finally
  137. FindClose(SR);
  138. end;
  139. if FindFirst(GIndyPath + 'Lib\Protocols\*.pas', faAnyFile, SR) = 0 then
  140. try
  141. repeat
  142. UnitName := ChangeFileExt(SR.Name, '');
  143. if not FIni.SectionExists(UnitName) then
  144. begin
  145. FIni.WriteString(UnitName, 'Pkg', 'Protocols');
  146. FIni.WriteBool(UnitName, 'SettingsNeeded', True);
  147. WriteLn('Missing settings for: Protocols\' + UnitName);
  148. end;
  149. until FindNext(SR) <> 0;
  150. finally
  151. FindClose(SR);
  152. end;
  153. end;
  154. procedure TDM.GetFileList(const ACriteria: String; AFiles: TStrings);
  155. var
  156. LFiles: TStringList;
  157. LCriteria: TStringList;
  158. I, J: Integer;
  159. LMatches: Boolean;
  160. LCriteriaName, LCriteriaValue, LFileValue: String;
  161. begin
  162. AFiles.Clear;
  163. LFiles := TStringList.Create;
  164. try
  165. FIni.ReadSections(LFiles);
  166. //LFiles.Sort;
  167. LCriteria := TStringList.Create;
  168. try
  169. LCriteria.CommaText := ACriteria;
  170. for I := 0 to LFiles.Count-1 do
  171. begin
  172. LMatches := True;
  173. for J := 0 to LCriteria.Count-1 do
  174. begin
  175. LCriteriaName := LCriteria.Names[J];
  176. LCriteriaValue := LCriteria.ValueFromIndex[J];
  177. LFileValue := FIni.ReadString(LFiles[I], LCriteriaName, '');
  178. if LFileValue <> LCriteriaValue then
  179. begin
  180. LMatches := False;
  181. Break;
  182. end;
  183. end;
  184. if LMatches then
  185. begin
  186. AFiles.Add(LFiles[I]);
  187. end;
  188. end;
  189. finally
  190. LCriteria.Free;
  191. end;
  192. finally
  193. LFiles.Free;
  194. end;
  195. end;
  196. procedure TDM.SetDataPath(const AValue: String);
  197. begin
  198. FDataPath := SysUtils.IncludeTrailingPathDelimiter(AValue);
  199. FreeAndNil(FIni);
  200. FIni := TMemIniFile.Create(FDataPath + 'File.ini');
  201. FIni.AutoSave := True;
  202. end;
  203. procedure SetIndyPath;
  204. var
  205. Param: String;
  206. I: Integer;
  207. begin
  208. if ParamCount > 0 then begin
  209. for I := 1 to ParamCount do begin
  210. Param := ParamStr(I);
  211. if not CharInSet(Param[1], ['/', '-']) then begin
  212. GIndyPath := IncludeTrailingPathDelimiter(Param);
  213. Exit;
  214. end;
  215. end;
  216. end;
  217. GIndyPath := UpTwoDirs(ExtractFilePath(ParamStr(0)));
  218. end;
  219. initialization
  220. SetIndyPath;
  221. end.