CoreMain.cpp 2.8 KB

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