Cleanup.cpp 5.8 KB

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