CoreMain.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #ifndef NO_FILEZILLA
  11. #include "FileZillaIntf.h"
  12. #endif
  13. //---------------------------------------------------------------------------
  14. #pragma package(smart_init)
  15. //---------------------------------------------------------------------------
  16. TConfiguration * Configuration = NULL;
  17. TStoredSessionList * StoredSessions = NULL;
  18. //---------------------------------------------------------------------------
  19. TQueryButtonAlias::TQueryButtonAlias()
  20. {
  21. OnClick = NULL;
  22. GroupWith = -1;
  23. }
  24. //---------------------------------------------------------------------------
  25. TQueryParams::TQueryParams(unsigned int AParams, UnicodeString AHelpKeyword)
  26. {
  27. Params = AParams;
  28. Aliases = NULL;
  29. AliasesCount = 0;
  30. Timer = 0;
  31. TimerEvent = NULL;
  32. TimerMessage = L"";
  33. TimerAnswers = 0;
  34. Timeout = 0;
  35. TimeoutAnswer = 0;
  36. NoBatchAnswers = 0;
  37. HelpKeyword = AHelpKeyword;
  38. }
  39. //---------------------------------------------------------------------------
  40. TQueryParams::TQueryParams(const TQueryParams & Source)
  41. {
  42. Assign(Source);
  43. }
  44. //---------------------------------------------------------------------------
  45. void TQueryParams::Assign(const TQueryParams & Source)
  46. {
  47. *this = Source;
  48. }
  49. //---------------------------------------------------------------------------
  50. bool __fastcall IsAuthenticationPrompt(TPromptKind Kind)
  51. {
  52. return
  53. (Kind == pkUserName) || (Kind == pkPassphrase) || (Kind == pkTIS) ||
  54. (Kind == pkCryptoCard) || (Kind == pkKeybInteractive) ||
  55. (Kind == pkPassword) || (Kind == pkNewPassword);
  56. }
  57. //---------------------------------------------------------------------------
  58. void CoreInitialize()
  59. {
  60. Randomize();
  61. CryptographyInitialize();
  62. // configuration needs to be created and loaded before putty is initialized,
  63. // so that random seed path is known
  64. Configuration = CreateConfiguration();
  65. try
  66. {
  67. Configuration->Load();
  68. }
  69. catch (Exception & E)
  70. {
  71. ShowExtendedException(&E);
  72. }
  73. PuttyInitialize();
  74. #ifndef NO_FILEZILLA
  75. TFileZillaIntf::Initialize();
  76. #endif
  77. StoredSessions = new TStoredSessionList();
  78. try
  79. {
  80. StoredSessions->Load();
  81. }
  82. catch (Exception & E)
  83. {
  84. ShowExtendedException(&E);
  85. }
  86. }
  87. //---------------------------------------------------------------------------
  88. void CoreFinalize()
  89. {
  90. try
  91. {
  92. Configuration->Save();
  93. }
  94. catch(Exception & E)
  95. {
  96. ShowExtendedException(&E);
  97. }
  98. #ifndef NO_FILEZILLA
  99. TFileZillaIntf::Finalize();
  100. #endif
  101. PuttyFinalize();
  102. delete StoredSessions;
  103. StoredSessions = NULL;
  104. delete Configuration;
  105. Configuration = NULL;
  106. CryptographyFinalize();
  107. }
  108. //---------------------------------------------------------------------------
  109. void CoreSetResourceModule(void * ResourceHandle)
  110. {
  111. #ifndef NO_FILEZILLA
  112. TFileZillaIntf::SetResourceModule(ResourceHandle);
  113. #else
  114. USEDPARAM(ResourceHandle);
  115. #endif
  116. }
  117. //---------------------------------------------------------------------------
  118. void CoreMaintenanceTask()
  119. {
  120. DontSaveRandomSeed();
  121. }
  122. //---------------------------------------------------------------------------