Cleanup.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. 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. for (int i = wdConfiguration; i <= wdTemporaryFolders; i++)
  77. {
  78. UnicodeString Caption;
  79. UnicodeString Location;
  80. switch (i)
  81. {
  82. case wdConfiguration:
  83. Caption = LoadStr(CLEANUP_CONFIG);
  84. Location = Configuration->ConfigurationSubKey;
  85. break;
  86. case wdStoredSessions:
  87. Caption = LoadStr(CLEANUP_SESSIONS);
  88. Location = Configuration->StoredSessionsSubKey;
  89. break;
  90. case wdHostKeys:
  91. Caption = LoadStr(CLEANUP_HOSTKEYS);
  92. Location = Configuration->SshHostKeysSubKey;
  93. break;
  94. case wdConfigurationIniFile:
  95. Caption = LoadStr(CLEANUP_INIFILE);
  96. Location = ExpandEnvironmentVariables(Configuration->IniFileStorageNameForReading);
  97. break;
  98. case wdRandomSeedFile:
  99. Caption = LoadStr(CLEANUP_SEEDFILE);
  100. Location = ExpandEnvironmentVariables(Configuration->RandomSeedFile);
  101. break;
  102. case wdTemporaryFolders:
  103. Caption = LoadStr(CLEANUP_TEMP_FOLDERS);
  104. Location = WinConfiguration->TemporaryDir(true);
  105. break;
  106. default:
  107. FAIL;
  108. break;
  109. }
  110. TListItem * Item = DataListView->Items->Add();
  111. Item->Caption = Caption;
  112. if (i < wdConfigurationIniFile)
  113. {
  114. Location = Configuration->RootKeyStr + L'\\' +
  115. Configuration->RegistryStorageKey + L'\\' + Location;
  116. }
  117. Item->SubItems->Add(Location);
  118. assert(Item->Index == i - 1);
  119. }
  120. AutoSizeListColumnsWidth(DataListView);
  121. }
  122. //---------------------------------------------------------------------
  123. void __fastcall TCleanupDialog::UpdateControls()
  124. {
  125. EnableControl(OKButton, ListViewAnyChecked(DataListView));
  126. }
  127. //---------------------------------------------------------------------------
  128. void __fastcall TCleanupDialog::DataListViewMouseDown(
  129. TObject * /*Sender*/, TMouseButton /*Button*/, TShiftState /*Shift*/,
  130. int /*X*/, int /*Y*/)
  131. {
  132. UpdateControls();
  133. }
  134. //---------------------------------------------------------------------------
  135. void __fastcall TCleanupDialog::DataListViewKeyUp(
  136. TObject * /*Sender*/, WORD & /*Key*/, TShiftState /*Shift*/)
  137. {
  138. UpdateControls();
  139. }
  140. //---------------------------------------------------------------------------
  141. void __fastcall TCleanupDialog::FormShow(TObject * /*Sender*/)
  142. {
  143. InitControls();
  144. UpdateControls();
  145. }
  146. //---------------------------------------------------------------------------
  147. void __fastcall TCleanupDialog::CheckAllButtonClick(TObject * /*Sender*/)
  148. {
  149. ListViewCheckAll(DataListView, caToggle);
  150. UpdateControls();
  151. }
  152. //---------------------------------------------------------------------------
  153. void __fastcall TCleanupDialog::DataListViewInfoTip(TObject * /*Sender*/,
  154. TListItem * Item, UnicodeString & InfoTip)
  155. {
  156. InfoTip = Format(L"%s\nLocation: %s",
  157. ARRAYOFCONST((Item->Caption, Item->SubItems->Strings[0])));
  158. }
  159. //---------------------------------------------------------------------------
  160. bool __fastcall TCleanupDialog::GetCleanupData(TWinSCPData Data)
  161. {
  162. return DataListView->Items->Item[Data - 1]->Checked;
  163. }
  164. //---------------------------------------------------------------------------
  165. void __fastcall TCleanupDialog::HelpButtonClick(TObject * /*Sender*/)
  166. {
  167. FormHelp(this);
  168. }
  169. //---------------------------------------------------------------------------