CoreMain.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. }
  23. //---------------------------------------------------------------------------
  24. TQueryParams::TQueryParams(unsigned int AParams, AnsiString AHelpKeyword)
  25. {
  26. Params = AParams;
  27. Aliases = NULL;
  28. AliasesCount = 0;
  29. Timer = 0;
  30. TimerEvent = NULL;
  31. TimerMessage = "";
  32. TimerAnswers = 0;
  33. Timeout = 0;
  34. TimeoutAnswer = 0;
  35. NoBatchAnswers = 0;
  36. HelpKeyword = AHelpKeyword;
  37. }
  38. //---------------------------------------------------------------------------
  39. bool __fastcall IsAuthenticationPrompt(TPromptKind Kind)
  40. {
  41. return
  42. (Kind == pkUserName) || (Kind == pkPassphrase) || (Kind == pkTIS) ||
  43. (Kind == pkCryptoCard) || (Kind == pkKeybInteractive) ||
  44. (Kind == pkPassword) || (Kind == pkNewPassword);
  45. }
  46. //---------------------------------------------------------------------------
  47. void CoreInitialize()
  48. {
  49. Randomize();
  50. CryptographyInitialize();
  51. // configuration needs to be created and loaded before putty is initialized,
  52. // so that random seed path is known
  53. Configuration = CreateConfiguration();
  54. try
  55. {
  56. Configuration->Load();
  57. }
  58. catch (Exception & E)
  59. {
  60. ShowExtendedException(&E);
  61. }
  62. PuttyInitialize();
  63. #ifndef NO_FILEZILLA
  64. TFileZillaIntf::Initialize();
  65. #endif
  66. StoredSessions = new TStoredSessionList();
  67. try
  68. {
  69. StoredSessions->Load();
  70. }
  71. catch (Exception & E)
  72. {
  73. ShowExtendedException(&E);
  74. }
  75. }
  76. //---------------------------------------------------------------------------
  77. void CoreFinalize()
  78. {
  79. try
  80. {
  81. // only modified, implicit
  82. Configuration->Save(false, false);
  83. }
  84. catch(Exception & E)
  85. {
  86. ShowExtendedException(&E);
  87. }
  88. #ifndef NO_FILEZILLA
  89. TFileZillaIntf::Finalize();
  90. #endif
  91. PuttyFinalize();
  92. delete StoredSessions;
  93. StoredSessions = NULL;
  94. delete Configuration;
  95. Configuration = NULL;
  96. CryptographyFinalize();
  97. }
  98. //---------------------------------------------------------------------------
  99. void CoreSetResourceModule(void * ResourceHandle)
  100. {
  101. #ifndef NO_FILEZILLA
  102. TFileZillaIntf::SetResourceModule(ResourceHandle);
  103. #else
  104. USEDPARAM(ResourceHandle);
  105. #endif
  106. }
  107. //---------------------------------------------------------------------------