CompTypes.pas 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. unit CompTypes;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2014 Jordan Russell
  5. Portions by Martijn Laan
  6. For conditions of distribution and use, see LICENSE.TXT.
  7. Types and functions used by both IDE and ISCC units
  8. }
  9. interface
  10. uses
  11. Windows, SysUtils, Registry, Classes;
  12. type
  13. TConfigIniFile = class(TRegIniFile)
  14. private
  15. FMutex: THandle;
  16. FAcquiredMutex: Boolean;
  17. public
  18. constructor Create;
  19. destructor Destroy; override;
  20. end;
  21. procedure ReadSignTools(SignTools: TStringList);
  22. function AddSignToolParam(Sign: string): string;
  23. implementation
  24. procedure ReadSignTools(SignTools: TStringList);
  25. var
  26. Ini: TConfigIniFile;
  27. I: Integer;
  28. S: String;
  29. begin
  30. Ini := TConfigIniFile.Create;
  31. try
  32. { Sign tools }
  33. SignTools.Clear();
  34. I := 0;
  35. repeat
  36. S := Ini.ReadString('SignTools', 'SignTool' + IntToStr(I), '');
  37. if S <> '' then
  38. SignTools.Add(S);
  39. Inc(I);
  40. until S = '';
  41. finally
  42. Ini.Free;
  43. end;
  44. end;
  45. function AddSignToolParam(Sign: string): string;
  46. begin
  47. Result := 'SignTool-' + Sign + #0;
  48. end;
  49. { TConfigIniFile }
  50. constructor TConfigIniFile.Create;
  51. begin
  52. inherited Create('Software\Jordan Russell\Inno Setup');
  53. { Paranoia: Use a mutex to prevent multiple instances from reading/writing
  54. to the registry simultaneously }
  55. FMutex := CreateMutex(nil, False, 'Inno-Setup-IDE-Config-Mutex');
  56. if FMutex <> 0 then
  57. if WaitForSingleObject(FMutex, INFINITE) <> WAIT_FAILED then
  58. FAcquiredMutex := True;
  59. end;
  60. destructor TConfigIniFile.Destroy;
  61. begin
  62. if FMutex <> 0 then begin
  63. if FAcquiredMutex then
  64. ReleaseMutex(FMutex);
  65. CloseHandle(FMutex);
  66. end;
  67. inherited;
  68. end;
  69. end.