Cleanup.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <VCLCommon.h>
  5. #include "Cleanup.h"
  6. #include "TextsWin.h"
  7. //---------------------------------------------------------------------
  8. #pragma resource "*.dfm"
  9. //---------------------------------------------------------------------
  10. Boolean __fastcall DoCleanupDialog(TStoredSessionList *SessionList,
  11. TConfiguration *Configuration)
  12. {
  13. Boolean Result;
  14. TCleanupDialog *CleanupDialog;
  15. try {
  16. CleanupDialog = new TCleanupDialog(Application);
  17. CleanupDialog->SessionList = SessionList;
  18. CleanupDialog->Configuration = Configuration;
  19. Result = (CleanupDialog->ShowModal() == mrOk);
  20. if (Result)
  21. {
  22. if (CleanupDialog->CleanupData[wdConfiguration])
  23. Configuration->CleanupConfiguration();
  24. if (CleanupDialog->CleanupData[wdStoredSessions])
  25. SessionList->Cleanup();
  26. if (CleanupDialog->CleanupData[wdHostKeys])
  27. Configuration->CleanupHostKeys();
  28. if (CleanupDialog->CleanupData[wdConfigurationIniFile])
  29. Configuration->CleanupIniFile();
  30. if (CleanupDialog->CleanupData[wdRandomSeedFile])
  31. Configuration->CleanupRandomSeedFile();
  32. }
  33. } __finally {
  34. delete CleanupDialog;
  35. }
  36. return Result;
  37. }
  38. //---------------------------------------------------------------------
  39. __fastcall TCleanupDialog::TCleanupDialog(TComponent* AOwner)
  40. : TForm(AOwner)
  41. {
  42. UseSystemSettings(this);
  43. }
  44. //---------------------------------------------------------------------
  45. void __fastcall TCleanupDialog::InitControls()
  46. {
  47. int I = 0;
  48. while (I < DataListView->Items->Count)
  49. {
  50. TListItem *Item = DataListView->Items->Item[I];
  51. AnsiString Location;
  52. Item->Caption = LoadStr(CLEANUP_CONFIG + Item->ImageIndex - 1);
  53. switch (Item->ImageIndex) {
  54. case wdConfiguration: Location = Configuration->ConfigurationSubKey; break;
  55. case wdStoredSessions: Location = Configuration->StoredSessionsSubKey; break;
  56. case wdHostKeys: Location = Configuration->SshHostKeysSubKey; break;
  57. case wdConfigurationIniFile: Location = Configuration->IniFileStorageName; break;
  58. case wdRandomSeedFile: Location = Configuration->RandomSeedFile; break;
  59. default: Location = ""; break;
  60. }
  61. if (Item->ImageIndex < wdConfigurationIniFile)
  62. {
  63. Location = Configuration->RootKeyStr + '\\' +
  64. Configuration->RegistryStorageKey + '\\' + Location;
  65. }
  66. Item->SubItems->Add(Location);
  67. I++;
  68. }
  69. }
  70. //---------------------------------------------------------------------
  71. void __fastcall TCleanupDialog::UpdateControls()
  72. {
  73. int I = 0;
  74. bool Checked = false;
  75. bool UnChecked = false;
  76. while (I < DataListView->Items->Count)
  77. {
  78. TListItem *Item = DataListView->Items->Item[I];
  79. if (Item->Checked) Checked = true;
  80. if (!Item->Checked) UnChecked = true;
  81. I++;
  82. }
  83. EnableControl(OKButton, Checked);
  84. EnableControl(CheckAllButton, UnChecked);
  85. }
  86. //---------------------------------------------------------------------------
  87. void __fastcall TCleanupDialog::DataListViewMouseDown(
  88. TObject * /*Sender*/, TMouseButton /*Button*/, TShiftState /*Shift*/,
  89. int /*X*/, int /*Y*/)
  90. {
  91. UpdateControls();
  92. }
  93. //---------------------------------------------------------------------------
  94. void __fastcall TCleanupDialog::DataListViewKeyUp(
  95. TObject * /*Sender*/, WORD & /*Key*/, TShiftState /*Shift*/)
  96. {
  97. UpdateControls();
  98. }
  99. //---------------------------------------------------------------------------
  100. void __fastcall TCleanupDialog::FormShow(TObject * /*Sender*/)
  101. {
  102. InitControls();
  103. UpdateControls();
  104. }
  105. //---------------------------------------------------------------------------
  106. void __fastcall TCleanupDialog::CheckAllButtonClick(TObject * /*Sender*/)
  107. {
  108. for (Integer Index = 0; Index < DataListView->Items->Count; Index ++)
  109. DataListView->Items->Item[Index]->Checked = True;
  110. UpdateControls();
  111. }
  112. //---------------------------------------------------------------------------
  113. void __fastcall TCleanupDialog::DataListViewInfoTip(TObject * /*Sender*/,
  114. TListItem * Item, AnsiString & InfoTip)
  115. {
  116. InfoTip = Format("%s\nLocation: %s",
  117. ARRAYOFCONST((Item->Caption, Item->SubItems->Strings[0])));
  118. }
  119. //---------------------------------------------------------------------------
  120. void __fastcall TCleanupDialog::SetCleanupData(TWinSCPData Data, Boolean value)
  121. {
  122. for (Integer Index = 0; Index < DataListView->Items->Count; Index ++)
  123. {
  124. TListItem *Item = DataListView->Items->Item[Index];
  125. if ((Item->ImageIndex == Data) && (Item->Checked != value))
  126. {
  127. Item->Checked = value;
  128. UpdateControls();
  129. }
  130. }
  131. }
  132. //---------------------------------------------------------------------------
  133. Boolean __fastcall TCleanupDialog::GetCleanupData(TWinSCPData Data)
  134. {
  135. for (Integer Index = 0; Index < DataListView->Items->Count; Index ++)
  136. {
  137. TListItem *Item = DataListView->Items->Item[Index];
  138. if (Item->ImageIndex == Data) return Item->Checked;
  139. }
  140. return False;
  141. }