CoreMain.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "CoreMain.h"
  5. #include "Common.h"
  6. #include "Interface.h"
  7. #include "Configuration.h"
  8. #include "PuttyIntf.h"
  9. #include "Cryptography.h"
  10. #include <DateUtils.hpp>
  11. #ifndef NO_FILEZILLA
  12. #include "FileZillaIntf.h"
  13. #endif
  14. //---------------------------------------------------------------------------
  15. #pragma package(smart_init)
  16. //---------------------------------------------------------------------------
  17. TConfiguration * Configuration = NULL;
  18. TStoredSessionList * StoredSessions = NULL;
  19. //---------------------------------------------------------------------------
  20. TQueryButtonAlias::TQueryButtonAlias()
  21. {
  22. OnClick = NULL;
  23. GroupWith = -1;
  24. }
  25. //---------------------------------------------------------------------------
  26. TQueryParams::TQueryParams(unsigned int AParams, UnicodeString AHelpKeyword)
  27. {
  28. Params = AParams;
  29. Aliases = NULL;
  30. AliasesCount = 0;
  31. Timer = 0;
  32. TimerEvent = NULL;
  33. TimerMessage = L"";
  34. TimerAnswers = 0;
  35. TimerQueryType = static_cast<TQueryType>(-1);
  36. Timeout = 0;
  37. TimeoutAnswer = 0;
  38. NoBatchAnswers = 0;
  39. HelpKeyword = AHelpKeyword;
  40. }
  41. //---------------------------------------------------------------------------
  42. TQueryParams::TQueryParams(const TQueryParams & Source)
  43. {
  44. Assign(Source);
  45. }
  46. //---------------------------------------------------------------------------
  47. void TQueryParams::Assign(const TQueryParams & Source)
  48. {
  49. *this = Source;
  50. }
  51. //---------------------------------------------------------------------------
  52. bool __fastcall IsAuthenticationPrompt(TPromptKind Kind)
  53. {
  54. return
  55. (Kind == pkUserName) || (Kind == pkPassphrase) || (Kind == pkTIS) ||
  56. (Kind == pkCryptoCard) || (Kind == pkKeybInteractive) ||
  57. (Kind == pkPassword) || (Kind == pkNewPassword);
  58. }
  59. //---------------------------------------------------------------------------
  60. void CoreInitialize()
  61. {
  62. Randomize();
  63. CryptographyInitialize();
  64. // configuration needs to be created and loaded before putty is initialized,
  65. // so that random seed path is known
  66. Configuration = CreateConfiguration();
  67. try
  68. {
  69. Configuration->Load();
  70. }
  71. catch (Exception & E)
  72. {
  73. ShowExtendedException(&E);
  74. }
  75. PuttyInitialize();
  76. #ifndef NO_FILEZILLA
  77. TFileZillaIntf::Initialize();
  78. #endif
  79. StoredSessions = new TStoredSessionList();
  80. try
  81. {
  82. StoredSessions->Load();
  83. }
  84. catch (Exception & E)
  85. {
  86. ShowExtendedException(&E);
  87. }
  88. }
  89. //---------------------------------------------------------------------------
  90. void CoreFinalize()
  91. {
  92. try
  93. {
  94. Configuration->Save();
  95. }
  96. catch(Exception & E)
  97. {
  98. ShowExtendedException(&E);
  99. }
  100. #ifndef NO_FILEZILLA
  101. TFileZillaIntf::Finalize();
  102. #endif
  103. PuttyFinalize();
  104. delete StoredSessions;
  105. StoredSessions = NULL;
  106. delete Configuration;
  107. Configuration = NULL;
  108. CryptographyFinalize();
  109. }
  110. //---------------------------------------------------------------------------
  111. void CoreSetResourceModule(void * ResourceHandle)
  112. {
  113. #ifndef NO_FILEZILLA
  114. TFileZillaIntf::SetResourceModule(ResourceHandle);
  115. #else
  116. USEDPARAM(ResourceHandle);
  117. #endif
  118. }
  119. //---------------------------------------------------------------------------
  120. void CoreMaintenanceTask()
  121. {
  122. DontSaveRandomSeed();
  123. }
  124. //---------------------------------------------------------------------------
  125. //---------------------------------------------------------------------------
  126. __fastcall TOperationVisualizer::TOperationVisualizer(bool UseBusyCursor) :
  127. FUseBusyCursor(UseBusyCursor)
  128. {
  129. if (FUseBusyCursor)
  130. {
  131. FToken = BusyStart();
  132. }
  133. }
  134. //---------------------------------------------------------------------------
  135. __fastcall TOperationVisualizer::~TOperationVisualizer()
  136. {
  137. if (FUseBusyCursor)
  138. {
  139. BusyEnd(FToken);
  140. }
  141. }
  142. //---------------------------------------------------------------------------
  143. //---------------------------------------------------------------------------
  144. __fastcall TInstantOperationVisualizer::TInstantOperationVisualizer() :
  145. FStart(Now())
  146. {
  147. }
  148. //---------------------------------------------------------------------------
  149. __fastcall TInstantOperationVisualizer::~TInstantOperationVisualizer()
  150. {
  151. TDateTime Time = Now();
  152. __int64 Duration = MilliSecondsBetween(Time, FStart);
  153. const __int64 MinDuration = 250;
  154. if (Duration < MinDuration)
  155. {
  156. Sleep(static_cast<unsigned int>(MinDuration - Duration));
  157. }
  158. }
  159. //---------------------------------------------------------------------------
  160. // WORKAROUND, suppress warning about unused constants in DateUtils.hpp
  161. #pragma warn -8080