Cleanup.cpp 5.9 KB

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