| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- {
- $Project$
- $Workfile$
- $Revision$
- $DateUTC$
- $Id$
- This file is part of the Indy (Internet Direct) project, and is offered
- under the dual-licensing agreement described on the Indy website.
- (http://www.indyproject.org/)
- Copyright:
- (c) 1993-2005, Chad Z. Hower and the Indy Pit Crew. All rights reserved.
- }
- {
- $Log$
- }
- {
- { Rev 1.5 9/4/2004 10:46:20 AM JPMugaas
- { Now some path settings were hard coded into the data module DFM causing
- { strange resutls.
- }
- {
- { Rev 1.4 04/09/2004 12:45:16 ANeillans
- { Moved the databasename and output paths into a globally accessible variable
- { -- makes it a lot easier to override if you need to (as I did for my local
- { file structure).
- }
- {
- { Rev 1.3 6/9/2004 7:47:16 AM JPMugaas
- { New feild for FTP Parser class.
- }
- {
- { Rev 1.2 02/06/2004 17:00:44 HHariri
- { design-time added
- }
- {
- { Rev 1.1 2004.01.22 8:17:58 PM czhower
- { Updates
- }
- {
- { Rev 1.0 2004.01.22 1:52:42 AM czhower
- { Initial checkin
- }
- unit DModule;
- interface
- uses
- SysUtils, Classes, IniFiles;
- type
- TDM = class(TDataModule)
- private
- protected
- FDataPath : String;
- FOutputPath : String;
- FIni: TMemIniFile;
- procedure SetDataPath(const AValue : String);
- public
- constructor Create(AOwner: TComponent); override;
- procedure CheckForMissingFiles;
- procedure GetFileList(const ACriteria: String; AFiles: TStrings);
- property DataPath : String read FDataPath write SetDataPath;
- property OutputPath : String read FOutputPath write FOutputPath;
- property Ini: TMemIniFile read FIni;
- end;
- var
- DM: TDM;
-
- var
- GIndyPath : String = 'W:\Source\Indy10\';
- procedure DumpData(const AFile: String);
- implementation
- {$R *.dfm}
- procedure DumpData(const AFile: String);
- var
- LNames: TStringList;
- I: Integer;
- begin
- LNames := TStringList.Create;
- try
- DM.Ini.ReadSection(AFile, LNames);
- for I := 0 to LNames.Count-1 do
- WriteLn(LNames[I] + ' = "' + DM.Ini.ReadString(AFile, LNames[I], '') + '"');
- finally
- LNames.Free;
- end;
- end;
- function UpTwoDirs(const APath : String):String;
- begin
- Result := SysUtils.ExcludeTrailingPathDelimiter(APath);
- Result := ExtractFilePath(Result);
- Result := SysUtils.ExcludeTrailingPathDelimiter(Result);
- Result := ExtractFilePath(Result);
- end;
- { TDM }
- constructor TDM.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- // Default Output Path is w:\source\Indy10
- OutputPath := SysUtils.ExcludeTrailingPathDelimiter(GIndyPath);
- // Default Data Path is W:\source\Indy10\builder\Package Generator\Data
- DataPath := GIndyPath + 'Builder\Package Generator\Data';
- end;
- procedure TDM.CheckForMissingFiles;
- var
- SR: TSearchRec;
- UnitName: String;
- begin
- if FindFirst(GIndyPath + 'Lib\System\*.pas', faAnyFile, SR) = 0 then
- try
- repeat
- UnitName := ChangeFileExt(SR.Name, '');
- if not FIni.SectionExists(UnitName) then
- begin
- FIni.WriteString(UnitName, 'Pkg', 'System');
- FIni.WriteBool(UnitName, 'SettingsNeeded', True);
- WriteLn('Missing settings for: System\' + UnitName);
- end;
- until FindNext(SR) <> 0;
- finally
- FindClose(SR);
- end;
- if FindFirst(GIndyPath + 'Lib\Core\*.pas', faAnyFile, SR) = 0 then
- try
- repeat
- UnitName := ChangeFileExt(SR.Name, '');
- if not FIni.SectionExists(UnitName) then
- begin
- FIni.WriteString(UnitName, 'Pkg', 'Core');
- FIni.WriteBool(UnitName, 'SettingsNeeded', True);
- WriteLn('Missing settings for: Core\' + UnitName);
- end;
- until FindNext(SR) <> 0;
- finally
- FindClose(SR);
- end;
- if FindFirst(GIndyPath + 'Lib\Protocols\*.pas', faAnyFile, SR) = 0 then
- try
- repeat
- UnitName := ChangeFileExt(SR.Name, '');
- if not FIni.SectionExists(UnitName) then
- begin
- FIni.WriteString(UnitName, 'Pkg', 'Protocols');
- FIni.WriteBool(UnitName, 'SettingsNeeded', True);
- WriteLn('Missing settings for: Protocols\' + UnitName);
- end;
- until FindNext(SR) <> 0;
- finally
- FindClose(SR);
- end;
- if FindFirst(GIndyPath + 'Lib\Protocols\IdFTPListParse*.pas', faAnyFile, SR) = 0 then
- try
- repeat
- UnitName := ChangeFileExt(SR.Name, '');
- if not FIni.SectionExists(UnitName) then
- begin
- FIni.WriteString(UnitName, 'Pkg', 'Protocols');
- FIni.WriteBool(UnitName, 'SettingsNeeded', True);
- WriteLn('Missing settings for: Protocols\' + UnitName);
- end;
- until FindNext(SR) <> 0;
- finally
- FindClose(SR);
- end;
- end;
- procedure TDM.GetFileList(const ACriteria: String; AFiles: TStrings);
- var
- LFiles: TStringList;
- LCriteria: TStringList;
- I, J: Integer;
- LMatches: Boolean;
- LCriteriaName, LCriteriaValue, LFileValue: String;
- begin
- AFiles.Clear;
- LFiles := TStringList.Create;
- try
- FIni.ReadSections(LFiles);
- LCriteria := TStringList.Create;
- try
- LCriteria.CommaText := ACriteria;
- for I := 0 to LFiles.Count-1 do
- begin
- LMatches := True;
- for J := 0 to LCriteria.Count-1 do
- begin
- LCriteriaName := LCriteria.Names[J];
- LCriteriaValue := LCriteria.ValueFromIndex[J];
- LFileValue := FIni.ReadString(LFiles[I], LCriteriaName, '');
- if LFileValue <> LCriteriaValue then
- begin
- LMatches := False;
- Break;
- end;
- end;
- if LMatches then
- begin
- AFiles.Add(LFiles[I]);
- end;
- end;
- finally
- LCriteria.Free;
- end;
- finally
- LFiles.Free;
- end;
- end;
- procedure TDM.SetDataPath(const AValue: String);
- begin
- FDataPath := AValue;
- FreeAndNil(FIni);
- FIni := TMemIniFile.Create(SysUtils.IncludeTrailingPathDelimiter(AValue) + 'File.ini');
- end;
- procedure SetIndyPath;
- var
- Param: String;
- I: Integer;
- begin
- if ParamCount > 0 then begin
- for I := 1 to ParamCount do begin
- Param := ParamStr(I);
- if not CharInSet(Param[1], ['/', '-']) then begin
- GIndyPath := IncludeTrailingPathDelimiter(Param);
- Exit;
- end;
- end;
- end;
- GIndyPath := UpTwoDirs(ExtractFilePath(ParamStr(0)));
- end;
- initialization
- SetIndyPath;
- end.
|