Shared.ConfigIniFile.pas 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. unit Shared.ConfigIniFile;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2024 Jordan Russell
  5. Portions by Martijn Laan
  6. For conditions of distribution and use, see LICENSE.TXT.
  7. ConfigIniFile class used by both IDE and ISCC units
  8. }
  9. interface
  10. uses
  11. Windows, Registry;
  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. implementation
  22. { TConfigIniFile }
  23. constructor TConfigIniFile.Create;
  24. begin
  25. inherited Create('Software\Jordan Russell\Inno Setup');
  26. { Paranoia: Use a mutex to prevent multiple instances from reading/writing
  27. to the registry simultaneously }
  28. FMutex := CreateMutex(nil, False, 'Inno-Setup-IDE-Config-Mutex');
  29. if FMutex <> 0 then
  30. if WaitForSingleObject(FMutex, INFINITE) <> WAIT_FAILED then
  31. FAcquiredMutex := True;
  32. end;
  33. destructor TConfigIniFile.Destroy;
  34. begin
  35. if FMutex <> 0 then begin
  36. if FAcquiredMutex then
  37. ReleaseMutex(FMutex);
  38. CloseHandle(FMutex);
  39. end;
  40. inherited;
  41. end;
  42. end.