| @@ -30,8 +30,45 @@ type | |||
| procedure SaveStream(const aFilename: String; const aStream: TStream); | |||
| end; | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| TutlFileReaderProxy = class(TInterfacedObject, IutlFileReader) | |||
| private | |||
| fReader: IutlFileReader; | |||
| fPrefix: String; | |||
| public | |||
| function LoadStream(const aFilename: String; const aStream: TStream): Boolean; | |||
| constructor Create(const aReader: IutlFileReader; const aPrefix: String); | |||
| end; | |||
| TutlFileWriterProxy = class(TInterfacedObject, IutlFileWriter) | |||
| private | |||
| fWriter: IutlFileWriter; | |||
| fPrefix: String; | |||
| public | |||
| procedure SaveStream(const aFilename: String; const aStream: TStream); | |||
| constructor Create(const aWriter: IutlFileWriter; const aPrefix: String); | |||
| end; | |||
| implementation | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| //TutlSimpleFileReader////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| function TutlSimpleFileReader.LoadStream(const aFilename: String; const aStream: TStream): Boolean; | |||
| var | |||
| fs: TFileStream; | |||
| begin | |||
| result := FileExists(aFilename); | |||
| if result then begin | |||
| fs := TFileStream.Create(aFilename, fmOpenRead); | |||
| try | |||
| aStream.CopyFrom(fs, fs.Size - fs.Position); | |||
| finally | |||
| FreeAndNil(fs); | |||
| end; | |||
| end; | |||
| end; | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| //TutlSimpleFileWriter////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| @@ -48,21 +85,41 @@ begin | |||
| end; | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| //TutlSimpleFileReader////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| //TutlFileReaderProxy/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| function TutlSimpleFileReader.LoadStream(const aFilename: String; const aStream: TStream): Boolean; | |||
| function TutlFileReaderProxy.LoadStream(const aFilename: String; const aStream: TStream): Boolean; | |||
| var | |||
| fs: TFileStream; | |||
| dir, name: String; | |||
| begin | |||
| result := FileExists(aFilename); | |||
| if result then begin | |||
| fs := TFileStream.Create(aFilename, fmOpenRead); | |||
| try | |||
| aStream.CopyFrom(fs, fs.Size - fs.Position); | |||
| finally | |||
| FreeAndNil(fs); | |||
| end; | |||
| end; | |||
| dir := ExtractFilePath(aFilename); | |||
| name := ExtractFileName(aFilename); | |||
| result := fReader.LoadStream(dir + fPrefix + name, aStream); | |||
| end; | |||
| constructor TutlFileReaderProxy.Create(const aReader: IutlFileReader; const aPrefix: String); | |||
| begin | |||
| inherited Create; | |||
| fReader := aReader; | |||
| fPrefix := aPrefix; | |||
| end; | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| //TutlFileWriterProxy/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| procedure TutlFileWriterProxy.SaveStream(const aFilename: String; const aStream: TStream); | |||
| var | |||
| dir, name: String; | |||
| begin | |||
| dir := ExtractFilePath(aFilename); | |||
| name := ExtractFileName(aFilename); | |||
| fWriter.SaveStream(dir + fPrefix + name, aStream); | |||
| end; | |||
| constructor TutlFileWriterProxy.Create(const aWriter: IutlFileWriter; const aPrefix: String); | |||
| begin | |||
| inherited Create; | |||
| fWriter := aWriter; | |||
| fPrefix := aPrefix; | |||
| end; | |||
| end. | |||