Cleanup.cpp 5.8 KB

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