ISPP.Sessions.pas 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. {
  2. Inno Setup Preprocessor
  3. Copyright (C) 2001-2002 Alex Yackimoff
  4. Inno Setup
  5. Copyright (C) 1997-2024 Jordan Russell
  6. Portions by Martijn Laan
  7. For conditions of distribution and use, see LICENSE.TXT.
  8. }
  9. unit ISPP.Sessions;
  10. interface
  11. uses
  12. ISPP.Preprocessor;
  13. procedure PushPreproc(APreproc: TPreprocessor);
  14. function PopPreproc: TPreprocessor;
  15. function PeekPreproc: TPreprocessor;
  16. procedure WarningMsg(const Msg: string; const Args: array of const);
  17. procedure VerboseMsg(Level: Byte; const Msg: string; const Args: array of const);
  18. procedure QueueFileForDeletion(const FileName: string);
  19. implementation
  20. uses
  21. SysUtils, Classes, ISPP.Stack, Windows;
  22. procedure WarningMsg(const Msg: string; const Args: array of const);
  23. var
  24. P: TPreprocessor;
  25. begin
  26. P := PeekPreproc;
  27. if Assigned(P) then
  28. P.WarningMsg(Msg, Args)
  29. end;
  30. procedure VerboseMsg(Level: Byte; const Msg: string; const Args: array of const);
  31. var
  32. P: TPreprocessor;
  33. begin
  34. P := PeekPreproc;
  35. if Assigned(P) then
  36. P.VerboseMsg(Level, Msg, Args);
  37. end;
  38. { TPreprocessorFlowStack }
  39. type
  40. TPreprocessorFlowStack = class(TStack)
  41. private
  42. FReference: Pointer;
  43. FTempFiles: TStringList;
  44. public
  45. constructor Create(var Reference);
  46. destructor Destroy; override;
  47. procedure Push(APreproc: TPreprocessor);
  48. function Pop: TPreprocessor;
  49. function Peek: TPreprocessor;
  50. procedure QueueFile(const FileName: string);
  51. end;
  52. constructor TPreprocessorFlowStack.Create(var Reference);
  53. begin
  54. inherited Create;
  55. TPreprocessorFlowStack(Reference) := Self;
  56. FReference := @Reference
  57. end;
  58. destructor TPreprocessorFlowStack.Destroy;
  59. var
  60. I: Integer;
  61. begin
  62. TPreprocessorFlowStack(FReference^) := nil;
  63. if FTempFiles <> nil then
  64. begin
  65. for I := 0 to FTempFiles.Count - 1 do
  66. DeleteFile(PChar(FTempFiles[I]));
  67. FTempFiles.Free;
  68. end;
  69. inherited Destroy;
  70. end;
  71. function TPreprocessorFlowStack.Peek: TPreprocessor;
  72. begin
  73. Result := TPreprocessor(inherited Peek);
  74. end;
  75. function TPreprocessorFlowStack.Pop: TPreprocessor;
  76. begin
  77. Result := TPreprocessor(inherited Pop);
  78. if not AtLeast(1) then Free;
  79. end;
  80. procedure TPreprocessorFlowStack.Push(APreproc: TPreprocessor);
  81. begin
  82. inherited Push(APreproc);
  83. end;
  84. procedure TPreprocessorFlowStack.QueueFile(const FileName: string);
  85. begin
  86. if FTempFiles = nil then
  87. begin
  88. FTempFiles := TStringList.Create;
  89. FTempFiles.Duplicates := dupIgnore;
  90. end;
  91. FTempFiles.Add(FileName);
  92. end;
  93. var
  94. FlowStack: TPreprocessorFlowStack;
  95. procedure PushPreproc(APreproc: TPreprocessor);
  96. begin
  97. if FlowStack = nil then
  98. TPreprocessorFlowStack.Create(FlowStack);
  99. FlowStack.Push(APreproc)
  100. end;
  101. function PopPreproc: TPreprocessor;
  102. begin
  103. if FlowStack <> nil then
  104. Result := FlowStack.Pop
  105. else
  106. Result := nil;
  107. end;
  108. function PeekPreproc: TPreprocessor;
  109. begin
  110. if FlowStack <> nil then
  111. Result := FlowStack.Peek
  112. else
  113. Result := nil;
  114. end;
  115. procedure QueueFileForDeletion(const FileName: string);
  116. begin
  117. if FlowStack <> nil then
  118. FlowStack.QueueFile(FileName)
  119. else
  120. DeleteFile(PChar(FileName));
  121. end;
  122. end.