CheckRideResourceZipper.lpr 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. program CheckRideResourceZipper;
  2. {$mode objfpc}{$H+}
  3. {$APPTYPE CONSOLE}
  4. //Handy for error messages in resourcezipper
  5. {$DEFINE CONSOLE}
  6. uses {$IFDEF UNIX} {$IFDEF UseCThreads}
  7. cthreads, {$ENDIF} {$ENDIF}
  8. Classes,
  9. Interfaces, // this includes the LCL widgetset
  10. SysUtils,
  11. Forms {for application support},
  12. checkrideutil {for future work with unzipping from resources},
  13. resourcezipper;
  14. var
  15. OurResourceZipper: TResourceZipper;
  16. FMustWriteCheckRideResource: boolean;
  17. FMustWriteCheckRideHelpResource: boolean;
  18. FMustWriteAllResources: boolean;
  19. FExeDirectory: string;
  20. procedure ShowCommandLineHelp;
  21. begin
  22. writeln(ExtractFileName(Application.ExeName) + ' [options]');
  23. writeln('-h or --help : help');
  24. writeln('-o <dir> or --outputdirectory=<dir> : output directory');
  25. writeln('--writeresourcecheck : add zip as "poor man''s resource"');
  26. writeln(' to the ' +
  27. CheckRideExe + ' executable.');
  28. writeln('--writeresourcehelp : add zip as "poor man''s resource"');
  29. writeln(' to the ' +
  30. CheckRideHelperExe + ' executable.');
  31. writeln(' to the both executable.');
  32. end;
  33. procedure OptionsAndInit;
  34. var
  35. ErrorMessage: string;
  36. begin
  37. Application.CaseSensitiveOptions := False; //accept upper and lowercase
  38. ErrorMessage := Application.CheckOptions('ho:',
  39. 'help outputdirectory: writeallresources writeresourcecheck writeresourcehelp');
  40. if Length(ErrorMessage) > 0 then
  41. begin
  42. writeln(ErrorMessage);
  43. ShowCommandLineHelp;
  44. halt(1); //invalid options
  45. end;
  46. if (Application.HasOption('h', 'help')) or (Application.HasOption('?')) then
  47. begin
  48. ShowCommandLineHelp;
  49. halt(0);
  50. end;
  51. FExeDirectory := '';
  52. if Application.HasOption('o', 'outputdirectory') then
  53. begin
  54. //Get absolute path
  55. //Trailed separator apparently not attached by ExpandFileName
  56. // We write zips to output, this helps in troubleshooting.
  57. FExeDirectory := ExpandFileName(
  58. Trim(Application.GetOptionValue('o', 'outputdirectory')));
  59. OurResourceZipper.ZipDirectory := FExeDirectory;
  60. end;
  61. if Application.HasOption('writeresourcecheck') then
  62. begin
  63. FMustWriteCheckRideResource := True;
  64. end
  65. else
  66. begin
  67. FMustWriteCheckRideResource := False;
  68. end;
  69. if Application.HasOption('writeallresources') then
  70. begin
  71. FMustWriteAllResources := True;
  72. end
  73. else
  74. begin
  75. FMustWriteAllResources := False;
  76. end;
  77. if Application.HasOption('writeresourcehelp') then
  78. begin
  79. FMustWriteCheckRideHelpResource := True;
  80. end
  81. else
  82. begin
  83. FMustWriteCheckRideHelpResource := False;
  84. end;
  85. end;
  86. begin
  87. OurResourceZipper := TResourceZipper.Create;
  88. try
  89. writeln(ExtractFileName(Application.ExeName) +
  90. ': zip CheckRide files for use into resource; optionally write resource.');
  91. writeln('***NOTE: please update and recompile CheckRideResourceZipper.lpr');
  92. writeln(' whenever you need files added to the resource.');
  93. //Setup
  94. OptionsAndInit; //Check what users asked us to do.
  95. //Create zip(s), append to executable(s):
  96. if (FMustWriteCheckRideResource or FMustWriteAllResources) then
  97. begin
  98. OurResourceZipper.Executable := FExeDirectory + CheckRideExe;
  99. OurResourceZipper.WriteCheckRideResource;
  100. end;
  101. if (FMustWriteCheckRideHelpResource or FMustWriteAllResources) then
  102. begin
  103. OurResourceZipper.Executable := FExeDirectory + CheckRideHelperExe;
  104. OurResourceZipper.WriteCheckRideHelperResource;
  105. end;
  106. finally
  107. OurResourceZipper.Free;
  108. end;
  109. end.