Computil.dpr 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. { $HDR$}
  2. {**********************************************************************}
  3. { Unit archived using Team Coherence }
  4. { Team Coherence is Copyright 2002 by Quality Software Components }
  5. { }
  6. { For further information / comments, visit our WEB site at }
  7. { http://www.TeamCoherence.com }
  8. {**********************************************************************}
  9. {}
  10. { $Log: 10019: Computil.dpr
  11. {
  12. { Rev 1.4 24/08/2004 12:41:44 ANeillans
  13. { Modified to ensure the registry object is opened in Read Only mode.
  14. }
  15. {
  16. { Rev 1.3 7/14/04 1:40:26 PM RLebeau
  17. { removed some repeating code
  18. }
  19. {
  20. { Rev 1.2 14/07/2004 21:15:38 ANeillans
  21. { Modification to allow both HKLM and HKCU to be used for fetching binary path.
  22. }
  23. {
  24. { Rev 1.1 03/05/2004 15:36:22 ANeillans
  25. { Bug fix: Rootdir blank causes AV. Changes HKEY_LOCAL_MACHINE to
  26. { HKEY_CURRENT_USER.
  27. }
  28. {
  29. { Rev 1.0 2002.11.12 10:25:38 PM czhower
  30. }
  31. program CompUtil;
  32. {$APPTYPE CONSOLE}
  33. uses
  34. Windows, SysUtils, Registry, Classes;
  35. type
  36. TWhichOption = (
  37. woHppModify,
  38. woSetupD2,woSetupD3,woSetupD4,woSetupD5,woSetupD6,woSetupD7,woSetupD8,
  39. woSetupD9,woSetupD10,woSetupD11,woSetupD12,woSetupD14,woSetupD15,woSetupD16,
  40. woSetupD17,woSetupD18,woSetupD19,woSetupD20,woSetupD21,woSetupD22,woSetupD23,
  41. woSetupD24,woSetupD25,woSetupD26,woSetupD27,woSetupD28,
  42. woSetupC1,woSetupC3,woSetupC4,woSetupC5,woSetupC6,woSetupC7,woSetupC8,
  43. woSetupC9,woSetupC10,woSetupC11,woSetupC12,woSetupC14,woSetupC15,woSetupC16,
  44. woSetupC17,woSetupC18,woSetupC19,woSetupC20,woSetupC21,woSetupC22,woSetupC23,
  45. woSetupC24,woSetupC25,woSetupC26,woSetupC27,woSetupC28,
  46. woInvalid);
  47. var
  48. Options: array[TWhichOption] of String = (
  49. 'HppModify',
  50. 'SetupD2','SetupD3','SetupD4','SetupD5','SetupD6','SetupD7','SetupD8',
  51. 'SetupD9','SetupD10','SetupD11','SetupD12','SetupD14','SetupD15','SetupD16',
  52. 'SetupD17','SetupD18','SetupD19','SetupD20','SetupD21','SetupD22','SetupD23',
  53. 'SetupD24','SetupD25','SetupD26','SetupD27','SetupD28',
  54. 'SetupC1','SetupC3','SetupC4','SetupC5','SetupC6','SetupC7','SetupC8',
  55. 'SetupC9','SetupC10','SetupC11','SetupC12','SetupC14','SetupC15','SetupC16',
  56. 'SetupC17','SetupC18','SetupC19','SetupC20','SetupC21','SetupC22','SetupC23',
  57. 'SetupC24','SetupC25','SetupC26','SetupC27','SetupC28',
  58. 'Invalid'
  59. );
  60. WhichOption: TWhichOption;
  61. CmdParam: string;
  62. procedure HPPModify;
  63. var
  64. InFile: file;
  65. OutFile: text;
  66. Line: AnsiString;
  67. Buffer: pointer;
  68. BufPtr: PAnsiChar;
  69. BufSize: longint;
  70. EOL: boolean;
  71. begin
  72. // Fix C++Builder HPP conversion bug:
  73. // - Input line in RVDefine.pas is
  74. // TRaveUnits = {$IFDEF WIN32}type{$ENDIF} TRaveFloat;
  75. //
  76. // - Invalid output line in RVDefine.hpp is
  77. // typedef TRaveUnits TRaveUnits;
  78. //
  79. // - Valid output line in RVDefine.hpp should be
  80. // typedef double TRaveUnits;
  81. { Read in RVDefine.hpp as binary }
  82. AssignFile(InFile,ParamStr(2) + 'RVDefine.hpp');
  83. Reset(InFile,1);
  84. BufSize := FileSize(InFile);
  85. GetMem(Buffer,BufSize);
  86. BlockRead(InFile,Buffer^,BufSize);
  87. CloseFile(InFile);
  88. BufPtr := Buffer;
  89. { Write out modified RVDefine.hpp as text }
  90. AssignFile(OutFile,ParamStr(2) + 'RVDefine.hpp');
  91. Rewrite(OutFile);
  92. While BufSize > 0 do begin
  93. Line := '';
  94. EOL := false;
  95. Repeat { Get a line of text }
  96. If BufPtr^ = #13 then begin
  97. Inc(BufPtr);
  98. Dec(BufSize);
  99. Inc(BufPtr);
  100. Dec(BufSize);
  101. EOL := true;
  102. end else begin
  103. Line := Line + BufPtr^;
  104. Inc(BufPtr);
  105. Dec(BufSize);
  106. end; { else }
  107. until EOL or (BufSize = 0);
  108. If Line = 'typedef TRaveUnits TRaveUnits;' then begin
  109. Line := 'typedef double TRaveUnits;';
  110. end; { if }
  111. Writeln(OutFile,Line);
  112. end; { while }
  113. CloseFile(OutFile);
  114. end; { HPPModify }
  115. procedure SetPath(EnvName: string; RegRoot: string);
  116. var
  117. CompilerFound: boolean;
  118. SysDirFound: boolean;
  119. KeyOpened: boolean;
  120. EnvUpdated: boolean;
  121. EnvList: TStringList;
  122. SysDir: string;
  123. ShortPath: string;
  124. LongPath: string;
  125. begin
  126. CompilerFound := GetEnvironmentVariable(PChar(EnvName), nil, 0) <> 0;
  127. SysDirFound := GetEnvironmentVariable('NDWINSYS', nil, 0) <> 0;
  128. If (not CompilerFound) or (not SysDirFound) then begin
  129. EnvUpdated := False;
  130. EnvList := TStringList.Create;
  131. try
  132. If FileExists('SetEnv.bat') then begin { Read in existing file }
  133. EnvList.LoadFromFile('SetEnv.bat');
  134. end; { if }
  135. If not CompilerFound then begin { Get compiler path and add to string list }
  136. With TRegistry.Create do try
  137. RootKey := HKEY_LOCAL_MACHINE;
  138. KeyOpened := OpenKeyReadOnly(RegRoot);
  139. if not KeyOpened then begin
  140. Writeln('Resetting registry rootkey to HKCU, and retrying');
  141. RootKey := HKEY_CURRENT_USER;
  142. KeyOpened := OpenKeyReadOnly(RegRoot);
  143. End;
  144. if KeyOpened and ValueExists('RootDir') then begin
  145. LongPath := ReadString('RootDir');
  146. SetLength(ShortPath, MAX_PATH); // when casting to a PChar, be sure the string is not empty
  147. SetLength(ShortPath, GetShortPathName(PChar(LongPath), PChar(ShortPath), MAX_PATH) );
  148. If (ShortPath[1] = #0) or (Length(ShortPath) = Length(LongPath)) then begin
  149. ShortPath := LongPath;
  150. end;
  151. EnvList.Add('SET ' + EnvName + '=' + ShortPath);
  152. EnvUpdated := True;
  153. end else begin
  154. Writeln('Compiler not installed!');
  155. Halt(1);
  156. End; { else }
  157. finally
  158. Free;
  159. end; { with }
  160. end; { if }
  161. If not SysDirFound then begin { Get System Directory and add to string list }
  162. SetLength(SysDir, MAX_PATH);
  163. SetLength(SysDir, GetSystemDirectory(PChar(SysDir), MAX_PATH));
  164. EnvList.Add('SET NDWINSYS=' + SysDir);
  165. EnvUpdated := True;
  166. end; { if }
  167. If EnvUpdated then begin
  168. EnvList.SaveToFile('SetEnv.bat');
  169. End; { if }
  170. finally
  171. EnvList.Free;
  172. end; { tryf }
  173. end; { if }
  174. end; { SetPath }
  175. begin
  176. { Figure out which feature to run }
  177. CmdParam := ParamStr(1);
  178. WhichOption := Low(WhichOption);
  179. While WhichOption < High(WhichOption) do begin
  180. If UpperCase(CmdParam) = UpperCase(Options[WhichOption]) then begin
  181. Break;
  182. end; { if }
  183. Inc(WhichOption);
  184. end; { while }
  185. Case WhichOption of
  186. woHppModify: HPPModify;
  187. woSetupD2: SetPath('NDD2','Software\Borland\Delphi\2.0');
  188. woSetupD3: SetPath('NDD3','Software\Borland\Delphi\3.0');
  189. woSetupD4: SetPath('NDD4','Software\Borland\Delphi\4.0');
  190. woSetupD5: SetPath('NDD5','Software\Borland\Delphi\5.0');
  191. woSetupD6: SetPath('NDD6','Software\Borland\Delphi\6.0');
  192. woSetupD7: SetPath('NDD7','Software\Borland\Delphi\7.0');
  193. woSetupD8: SetPath('NDD8','Software\Borland\Delphi\8.0');
  194. woSetupD9: SetPath('NDD9','Software\Borland\BDS\3.0');
  195. woSetupD10: SetPath('NDD10','Software\Borland\BDS\4.0');
  196. woSetupD11: SetPath('NDD11','Software\Borland\BDS\5.0');
  197. woSetupD12: SetPath('NDD12','Software\CodeGear\BDS\6.0');
  198. woSetupD14: SetPath('NDD14','Software\CodeGear\BDS\7.0');
  199. woSetupD15: SetPath('NDD15','Software\Embarcadero\BDS\8.0');
  200. woSetupD16: SetPath('NDD16','Software\Embarcadero\BDS\9.0');
  201. woSetupD17: SetPath('NDD17','Software\Embarcadero\BDS\10.0');
  202. woSetupD18: SetPath('NDD18','Software\Embarcadero\BDS\11.0');
  203. woSetupD19: SetPath('NDD19','Software\Embarcadero\BDS\12.0');
  204. woSetupD20: SetPath('NDD20','Software\Embarcadero\BDS\14.0');
  205. woSetupD21: SetPath('NDD21','Software\Embarcadero\BDS\15.0');
  206. woSetupD22: SetPath('NDD22','Software\Embarcadero\BDS\16.0');
  207. woSetupD23: SetPath('NDD23','Software\Embarcadero\BDS\17.0');
  208. woSetupD24: SetPath('NDD24','Software\Embarcadero\BDS\18.0');
  209. woSetupD25: SetPath('NDD25','Software\Embarcadero\BDS\19.0');
  210. woSetupD26: SetPath('NDD26','Software\Embarcadero\BDS\20.0');
  211. woSetupD27: SetPath('NDD27','Software\Embarcadero\BDS\21.0');
  212. woSetupD28: SetPath('NDD28','Software\Embarcadero\BDS\22.0');
  213. woSetupC1: SetPath('NDC1','Software\Borland\C++Builder\1.0');
  214. woSetupC3: SetPath('NDC3','Software\Borland\C++Builder\3.0');
  215. woSetupC4: SetPath('NDC4','Software\Borland\C++Builder\4.0');
  216. woSetupC5: SetPath('NDC5','Software\Borland\C++Builder\5.0');
  217. woSetupC6: SetPath('NDC6','Software\Borland\C++Builder\6.0');
  218. woSetupC10: SetPath('NDC10','Software\Borland\BDS\4.0');
  219. woSetupC11: SetPath('NDC11','Software\Borland\BDS\5.0');
  220. woSetupC12: SetPath('NDC12','Software\CodeGear\BDS\6.0');
  221. woSetupC14: SetPath('NDC14','Software\CodeGear\BDS\7.0');
  222. woSetupC15: SetPath('NDC15','Software\Embarcadero\BDS\8.0');
  223. woSetupC16: SetPath('NDC16','Software\Embarcadero\BDS\9.0');
  224. woSetupC17: SetPath('NDC17','Software\Embarcadero\BDS\10.0');
  225. woSetupC18: SetPath('NDC18','Software\Embarcadero\BDS\11.0');
  226. woSetupC19: SetPath('NDC19','Software\Embarcadero\BDS\12.0');
  227. woSetupC20: SetPath('NDC20','Software\Embarcadero\BDS\14.0');
  228. woSetupC21: SetPath('NDC21','Software\Embarcadero\BDS\15.0');
  229. woSetupC22: SetPath('NDC22','Software\Embarcadero\BDS\16.0');
  230. woSetupC23: SetPath('NDC23','Software\Embarcadero\BDS\17.0');
  231. woSetupC24: SetPath('NDC24','Software\Embarcadero\BDS\18.0');
  232. woSetupC25: SetPath('NDC25','Software\Embarcadero\BDS\19.0');
  233. woSetupC26: SetPath('NDC26','Software\Embarcadero\BDS\20.0');
  234. woSetupC27: SetPath('NDC27','Software\Embarcadero\BDS\21.0');
  235. woSetupC28: SetPath('NDC28','Software\Embarcadero\BDS\22.0');
  236. woInvalid: Writeln('Invalid Parameter');
  237. end; { case }
  238. end.