Advertisement
Guest User

ResPACKAGEINFO.dpr

a guest
Nov 7th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 5.09 KB | None | 0 0
  1. program ResPACKAGEINFO;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   Windows,
  7.   System.Classes,
  8.   SysUtils,
  9.   System.IOUtils,
  10.   System.Types;
  11.  
  12.  
  13. var
  14.   RequiresList: TStrings;
  15.   ImplicitUnits: TStrings;
  16.   ContainsList: TStrings;
  17.  
  18. function GetUnitFlagInfo(Flags: Byte):string;
  19. begin
  20.  
  21.   { PackageUnitFlags:
  22.     bit      meaning
  23.     -----------------------------------------------------------------------------------------
  24.     0      | main unit
  25.     1      | package unit (dpk source)
  26.     2      | $WEAKPACKAGEUNIT unit
  27.     3      | original containment of $WEAKPACKAGEUNIT (package into which it was compiled)
  28.     4      | implicitly imported
  29.     5..7   | reserved
  30.   }
  31.  
  32.   Result:='';
  33.   if (Flags and ufMainUnit<>0) then
  34.   Result:='[Main Unit] ';
  35.  
  36.   if (Flags and ufPackageUnit<>0) then
  37.   Result:=Result+'[Package Unit] ';
  38.  
  39.   if (Flags and ufWeakUnit<>0) then
  40.   Result:=Result+'[Weak Unit] ';
  41.  
  42.   if (Flags and ufImplicitUnit<>0) then
  43.   Result:=Result+'[implicitly imported] ';
  44.  
  45.   if (Flags and ufWeakPackageUnit<>0) then
  46.   Result:=Result+'[$WEAKPACKAGEUNIT unit] ';
  47.  
  48.   if (Flags and ufOrgWeakUnit<>0) then
  49.   Result:=Result+'[original containment of $WEAKPACKAGEUNIT]';
  50. end;
  51.  
  52.  
  53. procedure GetInfoPackageFlags(Flags:Cardinal);
  54. begin
  55.  
  56.         { Package flags:
  57.           bit     meaning
  58.           -----------------------------------------------------------------------------------------
  59.           0     | 1: never-build                  0: always build
  60.           1     | 1: design-time only             0: not design-time only      on => bit 2 = off
  61.           2     | 1: run-time only                0: not run-time only         on => bit 1 = off
  62.           3     | 1: do not check for dup units   0: perform normal dup unit check
  63.           4..25 | reserved
  64.           26..27| (producer) 0: pre-V4, 1: undefined, 2: c++, 3: Pascal
  65.           28..29| reserved
  66.           30..31| 0: EXE, 1: Package DLL, 2: Library DLL, 3: undefined
  67.         }
  68.  
  69.  
  70.         if  (Flags and pfModuleTypeMask = pfExeModule) then
  71.          Writeln('Type Exe')
  72.         else
  73.         if  (Flags and pfModuleTypeMask = pfPackageModule) then
  74.          Writeln('Type Package')
  75.         else
  76.         if  (Flags and pfModuleTypeMask = pfLibraryModule) then
  77.          Writeln('Type Library');
  78.  
  79.         if  (Flags and pfNeverBuild = 0) then
  80.          Writeln('Build with runtime packages')
  81.         else
  82.          Writeln('Build without runtime packages');
  83.  
  84.         if  (Flags and pfIgnoreDupUnits = 0) then
  85.          Writeln('perform normal dup unit check')
  86.         else
  87.          Writeln('Ignore Dup Units');
  88.  
  89.         if  (Flags and pfProducerMask = pfDelphi4Produced) then
  90.          Writeln('Producer Pascal');
  91.  
  92.         if  (Flags and pfProducerMask = pfV3Produced) then
  93.          Writeln('Producer pre-V4');
  94.  
  95.         if  (Flags and pfProducerMask = pfProducerUndefined) then
  96.          Writeln('Producer undefined');
  97.  
  98.         if  (Flags and pfProducerMask = pfBCB4Produced) then
  99.          Writeln('Producer c++');
  100.  
  101.         if  (Flags and pfConsumerMask = pfConsumerCompat) then
  102.          Writeln('Consumer Compatible')
  103.         else
  104.         if  (Flags and pfConsumerMask = pfConsumerDelphi) then
  105.          Writeln('Consumer Delphi')
  106.         else
  107.         if  (Flags and pfConsumerMask = pfConsumerBCB) then
  108.          Writeln('Consumer BCB');
  109. end;
  110.  
  111. procedure PackageInfoCallback(const Name: string; NameType: TNameType; Flags: Byte; Param: Pointer);
  112. begin
  113.     case NameType of
  114.       ntContainsUnit   :  ContainsList.Add(Name);
  115.       ntRequiresPackage:  RequiresList.Add(Name);
  116.     end;
  117. end;
  118.  
  119.  
  120. procedure GetPackageResInfo(const FileName:string);
  121. const
  122.  ResPACKAGEINFO='PACKAGEINFO';
  123. var
  124.   FModule    : Cardinal;
  125.   Flags      : Integer;
  126.   S : String;
  127. begin
  128.   FModule := LoadLibraryEx(PChar(FileName), 0, LOAD_LIBRARY_AS_DATAFILE);
  129.   RequiresList.Clear; ImplicitUnits.Clear; ContainsList.Clear;
  130.   try
  131.     SysUtils.GetPackageInfo(FModule, nil, Flags, PackageInfoCallback);
  132. //    GetInfoPackageFlags(Flags);
  133. //    Writeln(GetPackageDescription(PChar(FileName)));
  134.     Writeln(ExtractFileName(FileName)+' requires '+RequiresList.CommaText);
  135.     Writeln(ExtractFileName(FileName)+' contains '+ContainsList.CommaText);
  136.   finally
  137.     FreeLibrary(FModule);
  138.   end;
  139. end;
  140.  
  141. procedure GetPackagesDirectory(const PathName: String);
  142. var Files: TStringDynArray; FileName: String;
  143. begin
  144.   Files:= TDirectory.GetFiles(PathName, '*.bpl');
  145.   for FileName in Files do
  146.     GetPackageResInfo(FileName);
  147. end;
  148.  
  149. begin
  150.   RequiresList := TStringList.Create;
  151.   ImplicitUnits := TStringList.Create;
  152.   ContainsList := TStringList.Create;
  153.   try
  154.     try
  155.        if ParamCount > 0 then
  156.          if TFile.Exists(ParamStr(1)) then GetPackageResInfo(ParamStr(1))
  157.          else if TDirectory.Exists(ParamStr(1)) then GetPackagesDirectory(ParamStr(1))
  158.          else Writeln('No valid file or path given!')
  159.        else Writeln(Format('Usage: %s file|path',[ExtractFileName(ParamStr(0))]));
  160.     except
  161.       on E:Exception do
  162.         Writeln(E.Classname, ': ', E.Message);
  163.     end;
  164.   finally
  165.     RequiresList.Free;
  166.     ImplicitUnits.Free;
  167.     ContainsList.Free;
  168.   end;
  169. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement