CoreMain.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. bool __fastcall IsAuthenticationPrompt(TPromptKind Kind)
  41. {
  42. return
  43. (Kind == pkUserName) || (Kind == pkPassphrase) || (Kind == pkTIS) ||
  44. (Kind == pkCryptoCard) || (Kind == pkKeybInteractive) ||
  45. (Kind == pkPassword) || (Kind == pkNewPassword);
  46. }
  47. //---------------------------------------------------------------------------
  48. void CoreInitialize()
  49. {
  50. Randomize();
  51. CryptographyInitialize();
  52. // configuration needs to be created and loaded before putty is initialized,
  53. // so that random seed path is known
  54. Configuration = CreateConfiguration();
  55. try
  56. {
  57. Configuration->Load();
  58. }
  59. catch (Exception & E)
  60. {
  61. ShowExtendedException(&E);
  62. }
  63. PuttyInitialize();
  64. #ifndef NO_FILEZILLA
  65. TFileZillaIntf::Initialize();
  66. #endif
  67. StoredSessions = new TStoredSessionList();
  68. try
  69. {
  70. StoredSessions->Load();
  71. }
  72. catch (Exception & E)
  73. {
  74. ShowExtendedException(&E);
  75. }
  76. }
  77. //---------------------------------------------------------------------------
  78. void CoreFinalize()
  79. {
  80. try
  81. {
  82. // only modified, implicit
  83. Configuration->Save(false, false);
  84. }
  85. catch(Exception & E)
  86. {
  87. ShowExtendedException(&E);
  88. }
  89. #ifndef NO_FILEZILLA
  90. TFileZillaIntf::Finalize();
  91. #endif
  92. PuttyFinalize();
  93. delete StoredSessions;
  94. StoredSessions = NULL;
  95. delete Configuration;
  96. Configuration = NULL;
  97. CryptographyFinalize();
  98. }
  99. //---------------------------------------------------------------------------
  100. void CoreSetResourceModule(void * ResourceHandle)
  101. {
  102. #ifndef NO_FILEZILLA
  103. TFileZillaIntf::SetResourceModule(ResourceHandle);
  104. #else
  105. USEDPARAM(ResourceHandle);
  106. #endif
  107. }
  108. //---------------------------------------------------------------------------
  109. void CoreMaintenanceTask()
  110. {
  111. DontSaveRandomSeed();
  112. }
  113. //---------------------------------------------------------------------------