Cleanup.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include <VCLCommon.h>
  6. #include <WinConfiguration.h>
  7. #include <TextsWin.h>
  8. #include "Cleanup.h"
  9. //---------------------------------------------------------------------
  10. #ifndef NO_RESOURCES
  11. #pragma resource "*.dfm"
  12. #endif
  13. //---------------------------------------------------------------------
  14. Boolean __fastcall DoCleanupDialog(TStoredSessionList *SessionList,
  15. TConfiguration *Configuration)
  16. {
  17. Boolean Result;
  18. TCleanupDialog *CleanupDialog;
  19. try {
  20. CleanupDialog = new TCleanupDialog(Application);
  21. CleanupDialog->SessionList = SessionList;
  22. CleanupDialog->Configuration = Configuration;
  23. Result = (CleanupDialog->ShowModal() == DefaultResult(CleanupDialog));
  24. if (Result)
  25. {
  26. for (int i = wdConfiguration; i <= wdTemporaryFolders; i++)
  27. {
  28. if (CleanupDialog->CleanupData[(TWinSCPData)i])
  29. {
  30. try
  31. {
  32. switch (i)
  33. {
  34. case wdConfiguration:
  35. Configuration->CleanupConfiguration();
  36. break;
  37. case wdStoredSessions:
  38. SessionList->Cleanup();
  39. break;
  40. case wdHostKeys:
  41. Configuration->CleanupHostKeys();
  42. break;
  43. case wdConfigurationIniFile:
  44. Configuration->CleanupIniFile();
  45. break;
  46. case wdRandomSeedFile:
  47. Configuration->CleanupRandomSeedFile();
  48. break;
  49. case wdTemporaryFolders:
  50. WinConfiguration->CleanupTemporaryFolders();
  51. break;
  52. }
  53. }
  54. catch(Exception & E)
  55. {
  56. ShowExtendedException(&E);
  57. }
  58. }
  59. }
  60. }
  61. } __finally {
  62. delete CleanupDialog;
  63. }
  64. return Result;
  65. }
  66. //---------------------------------------------------------------------
  67. __fastcall TCleanupDialog::TCleanupDialog(TComponent* AOwner)
  68. : TForm(AOwner)
  69. {
  70. UseSystemSettings(this);
  71. }
  72. //---------------------------------------------------------------------
  73. void __fastcall TCleanupDialog::InitControls()
  74. {
  75. for (int i = wdConfiguration; i <= wdTemporaryFolders; i++)
  76. {
  77. UnicodeString Caption;
  78. UnicodeString Location;
  79. switch (i)
  80. {
  81. case wdConfiguration:
  82. Caption = LoadStr(CLEANUP_CONFIG);
  83. Location = Configuration->ConfigurationSubKey;
  84. break;
  85. case wdStoredSessions:
  86. Caption = LoadStr(CLEANUP_SESSIONS);
  87. Location = Configuration->StoredSessionsSubKey;
  88. break;
  89. case wdHostKeys:
  90. Caption = LoadStr(CLEANUP_HOSTKEYS);
  91. Location = Configuration->SshHostKeysSubKey;
  92. break;
  93. case wdConfigurationIniFile:
  94. Caption = LoadStr(CLEANUP_INIFILE);
  95. Location = ExpandEnvironmentVariables(Configuration->IniFileStorageNameForReading);
  96. break;
  97. case wdRandomSeedFile:
  98. Caption = LoadStr(CLEANUP_SEEDFILE);
  99. Location = ExpandEnvironmentVariables(Configuration->RandomSeedFile);
  100. break;
  101. case wdTemporaryFolders:
  102. Caption = LoadStr(CLEANUP_TEMP_FOLDERS);
  103. Location = WinConfiguration->TemporaryDir(true);
  104. break;
  105. default:
  106. FAIL;
  107. break;
  108. }
  109. TListItem * Item = DataListView->Items->Add();
  110. Item->Caption = Caption;
  111. if (i < wdConfigurationIniFile)
  112. {
  113. Location = Configuration->RootKeyStr + L'\\' +
  114. Configuration->RegistryStorageKey + L'\\' + Location;
  115. }
  116. Item->SubItems->Add(Location);
  117. assert(Item->Index == i - 1);
  118. }
  119. }
  120. //---------------------------------------------------------------------
  121. void __fastcall TCleanupDialog::UpdateControls()
  122. {
  123. EnableControl(OKButton, ListViewAnyChecked(DataListView));
  124. }
  125. //---------------------------------------------------------------------------
  126. void __fastcall TCleanupDialog::DataListViewMouseDown(
  127. TObject * /*Sender*/, TMouseButton /*Button*/, TShiftState /*Shift*/,
  128. int /*X*/, int /*Y*/)
  129. {
  130. UpdateControls();
  131. }
  132. //---------------------------------------------------------------------------
  133. void __fastcall TCleanupDialog::DataListViewKeyUp(
  134. TObject * /*Sender*/, WORD & /*Key*/, TShiftState /*Shift*/)
  135. {
  136. UpdateControls();
  137. }
  138. //---------------------------------------------------------------------------
  139. void __fastcall TCleanupDialog::FormShow(TObject * /*Sender*/)
  140. {
  141. InitControls();
  142. UpdateControls();
  143. }
  144. //---------------------------------------------------------------------------
  145. void __fastcall TCleanupDialog::CheckAllButtonClick(TObject * /*Sender*/)
  146. {
  147. ListViewCheckAll(DataListView, caToggle);
  148. UpdateControls();
  149. }
  150. //---------------------------------------------------------------------------
  151. void __fastcall TCleanupDialog::DataListViewInfoTip(TObject * /*Sender*/,
  152. TListItem * Item, UnicodeString & InfoTip)
  153. {
  154. InfoTip = Format(L"%s\nLocation: %s",
  155. ARRAYOFCONST((Item->Caption, Item->SubItems->Strings[0])));
  156. }
  157. //---------------------------------------------------------------------------
  158. bool __fastcall TCleanupDialog::GetCleanupData(TWinSCPData Data)
  159. {
  160. return DataListView->Items->Item[Data - 1]->Checked;
  161. }
  162. //---------------------------------------------------------------------------
  163. void __fastcall TCleanupDialog::HelpButtonClick(TObject * /*Sender*/)
  164. {
  165. FormHelp(this);
  166. }
  167. //---------------------------------------------------------------------------