2
0

sourcehandler.pas 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. {
  2. FPCRes - Free Pascal Resource Converter
  3. Part of the Free Pascal distribution
  4. Copyright (C) 2008 by Giulio Bernardi
  5. Source files handling
  6. See the file COPYING, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. }
  12. unit sourcehandler;
  13. {$MODE OBJFPC} {$H+}
  14. interface
  15. uses
  16. Classes, SysUtils, resource;
  17. type
  18. ESourceFilesException = class(Exception);
  19. ECantOpenFileException = class(ESourceFilesException);
  20. EUnknownInputFormatException = class(ESourceFilesException);
  21. type
  22. { TSourceFiles }
  23. TSourceFiles = class
  24. private
  25. fFileList : TStringList;
  26. fStreamList : TFPList;
  27. protected
  28. public
  29. constructor Create;
  30. destructor Destroy; override;
  31. procedure Load(aResources : TResources);
  32. property FileList : TStringList read fFileList;
  33. end;
  34. implementation
  35. uses msghandler;
  36. { TSourceFiles }
  37. constructor TSourceFiles.Create;
  38. begin
  39. fFileList:=TStringList.Create;
  40. fStreamList:=TFPList.Create;
  41. end;
  42. destructor TSourceFiles.Destroy;
  43. var i : integer;
  44. begin
  45. fFileList.Free;
  46. for i:=0 to fStreamList.Count-1 do
  47. TStream(fStreamList[i]).Free;
  48. fStreamList.Free;
  49. end;
  50. procedure TSourceFiles.Load(aResources: TResources);
  51. var aReader : TAbstractResourceReader;
  52. aStream : TFileStream;
  53. i : integer;
  54. tmpres : TResources;
  55. begin
  56. tmpres:=TResources.Create;
  57. try
  58. for i:=0 to fFileList.Count-1 do
  59. begin
  60. Messages.DoVerbose(Format('Trying to open file %s...',[fFileList[i]]));
  61. try
  62. aStream:=TFileStream.Create(fFileList[i],fmOpenRead or fmShareDenyWrite);
  63. except
  64. raise ECantOpenFileException.Create(fFileList[i]);
  65. end;
  66. fStreamList.Add(aStream);
  67. try
  68. aReader:=TResources.FindReader(aStream);
  69. except
  70. raise EUnknownInputFormatException.Create(fFileList[i]);
  71. end;
  72. Messages.DoVerbose(Format('Chosen reader: %s',[aReader.Description]));
  73. try
  74. Messages.DoVerbose('Reading resource information...');
  75. tmpres.LoadFromStream(aStream,aReader);
  76. aResources.MoveFrom(tmpres);
  77. Messages.DoVerbose('Resource information read');
  78. finally
  79. aReader.Free;
  80. end;
  81. end;
  82. Messages.DoVerbose(Format('%d resources read.',[aResources.Count]));
  83. finally
  84. tmpres.Free;
  85. end;
  86. end;
  87. end.