jarsourcehandler.pas 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 jarsourcehandler;
  13. {$MODE OBJFPC} {$H+}
  14. interface
  15. uses
  16. Classes, SysUtils, sourcehandler, zipper;
  17. const
  18. resbasedir = 'org'+DirectorySeparator+'freepascal'+DirectorySeparator+'rawresources'+DirectorySeparator;
  19. type
  20. ESourceFilesException = class(Exception);
  21. ECantOpenFileException = class(ESourceFilesException);
  22. EUnknownInputFormatException = class(ESourceFilesException);
  23. type
  24. { TSourceFiles }
  25. TJarSourceFiles = class(TSourceFiles)
  26. private
  27. protected
  28. public
  29. procedure Load(aResources : TZipper);reintroduce;
  30. end;
  31. implementation
  32. uses msghandler, closablefilestream;
  33. { TJarSourceFiles }
  34. procedure TJarSourceFiles.Load(aResources: TZipper);
  35. var aStream : TClosableFileStream;
  36. i : integer;
  37. begin
  38. if fFileList.Count<>0 then
  39. begin
  40. aResources.Entries.AddFileEntry('org/');
  41. aResources.Entries.AddFileEntry('org/freepascal/');
  42. aResources.Entries.AddFileEntry(resbasedir);
  43. end;
  44. try
  45. for i:=0 to fFileList.Count-1 do
  46. begin
  47. Messages.DoVerbose(Format('Trying to open file %s...',[fFileList[i]]));
  48. try
  49. aStream:=TClosableFileStream.Create(fFileList[i],fmOpenRead or fmShareDenyWrite);
  50. except
  51. raise ECantOpenFileException.Create(fFileList[i]);
  52. end;
  53. astream.Free;
  54. aResources.Entries.AddFileEntry(fFileList[i],resbasedir+fFileList[i]);
  55. end;
  56. Messages.DoVerbose(Format('%d resources read.',[aResources.Entries.Count]));
  57. finally
  58. end;
  59. end;
  60. end.