|
|
@@ -4,139 +4,104 @@
|
|
|
|
|
|
#include <Common.h>
|
|
|
#include <VCLCommon.h>
|
|
|
+#include <CoreMain.h>
|
|
|
#include <WinConfiguration.h>
|
|
|
#include <TextsWin.h>
|
|
|
+#include <HelpWin.h>
|
|
|
+#include <PuttyTools.h>
|
|
|
#include "Cleanup.h"
|
|
|
//---------------------------------------------------------------------
|
|
|
#ifndef NO_RESOURCES
|
|
|
#pragma resource "*.dfm"
|
|
|
#endif
|
|
|
//---------------------------------------------------------------------
|
|
|
-Boolean __fastcall DoCleanupDialog(TStoredSessionList *SessionList,
|
|
|
- TConfiguration *Configuration)
|
|
|
+bool __fastcall DoCleanupDialog()
|
|
|
{
|
|
|
- Boolean Result;
|
|
|
- TCleanupDialog *CleanupDialog;
|
|
|
- try {
|
|
|
- CleanupDialog = SafeFormCreate<TCleanupDialog>();
|
|
|
-
|
|
|
- CleanupDialog->SessionList = SessionList;
|
|
|
- CleanupDialog->Configuration = Configuration;
|
|
|
-
|
|
|
- Result = (CleanupDialog->ShowModal() == DefaultResult(CleanupDialog));
|
|
|
- if (Result)
|
|
|
- {
|
|
|
- Configuration->Usage->Inc(L"Cleanups");
|
|
|
-
|
|
|
- for (int i = wdConfiguration; i <= wdTemporaryFolders; i++)
|
|
|
- {
|
|
|
- if (CleanupDialog->CleanupData[(TWinSCPData)i])
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- switch (i)
|
|
|
- {
|
|
|
- case wdConfiguration:
|
|
|
- Configuration->CleanupConfiguration();
|
|
|
- break;
|
|
|
-
|
|
|
- case wdStoredSessions:
|
|
|
- SessionList->Cleanup();
|
|
|
- break;
|
|
|
-
|
|
|
- case wdCaches:
|
|
|
- Configuration->CleanupCaches();
|
|
|
- break;
|
|
|
-
|
|
|
- case wdConfigurationIniFile:
|
|
|
- Configuration->CleanupIniFile();
|
|
|
- break;
|
|
|
-
|
|
|
- case wdRandomSeedFile:
|
|
|
- Configuration->CleanupRandomSeedFile();
|
|
|
- break;
|
|
|
-
|
|
|
- case wdTemporaryFolders:
|
|
|
- WinConfiguration->CleanupTemporaryFolders();
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- catch(Exception & E)
|
|
|
- {
|
|
|
- ShowExtendedException(&E);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } __finally {
|
|
|
- delete CleanupDialog;
|
|
|
+ std::unique_ptr<TCleanupDialog> CleanupDialog(SafeFormCreate<TCleanupDialog>());
|
|
|
+ return CleanupDialog->Execute();
|
|
|
+}
|
|
|
+//---------------------------------------------------------------------
|
|
|
+void __fastcall DoCleanupDialogIfAnyDataAndWanted()
|
|
|
+{
|
|
|
+ std::unique_ptr<TCleanupDialog> CleanupDialog(SafeFormCreate<TCleanupDialog>());
|
|
|
+ if (CleanupDialog->AnyData() &&
|
|
|
+ (MessageDialog(LoadStr(UNINSTALL_CLEANUP), qtConfirmation, qaYes | qaNo, HELP_UNINSTALL_CLEANUP) == qaYes))
|
|
|
+ {
|
|
|
+ CleanupDialog->Execute();
|
|
|
}
|
|
|
- return Result;
|
|
|
}
|
|
|
//---------------------------------------------------------------------
|
|
|
__fastcall TCleanupDialog::TCleanupDialog(TComponent* AOwner)
|
|
|
: TForm(AOwner)
|
|
|
{
|
|
|
+ FAnyData = false;
|
|
|
+ FindData();
|
|
|
UseSystemSettings(this);
|
|
|
}
|
|
|
//---------------------------------------------------------------------
|
|
|
-void __fastcall TCleanupDialog::InitControls()
|
|
|
+void __fastcall TCleanupDialog::AddLocation(int CaptionId, const UnicodeString & Location, TCleanupEvent Event)
|
|
|
{
|
|
|
- // Particularly in response to WM_DPICHANGED, the form may re-show
|
|
|
- DataListView->Items->Clear();
|
|
|
+ FCaptions.push_back(LoadStr(CaptionId));
|
|
|
+ FLocations.push_back(Location);
|
|
|
+ FCleanupEvents.push_back(Event);
|
|
|
+ FAnyData = true;
|
|
|
+}
|
|
|
+//---------------------------------------------------------------------
|
|
|
+void __fastcall TCleanupDialog::AddRegistryLocation(int CaptionId, const UnicodeString & Location, TCleanupEvent Event)
|
|
|
+{
|
|
|
+ AddLocation(CaptionId, Configuration->RootKeyStr + L'\\' + Configuration->RegistryStorageKey + L'\\' + Location, Event);
|
|
|
+}
|
|
|
+//---------------------------------------------------------------------
|
|
|
+bool __fastcall TCleanupDialog::AnyData()
|
|
|
+{
|
|
|
+ return FAnyData;
|
|
|
+}
|
|
|
+//---------------------------------------------------------------------
|
|
|
+void __fastcall TCleanupDialog::FindData()
|
|
|
+{
|
|
|
+ // Add unconditionally (as it has a side effect of not saving the configuration)
|
|
|
+ AddRegistryLocation(CLEANUP_CONFIG, Configuration->ConfigurationSubKey, Configuration->CleanupConfiguration);
|
|
|
+ // But count as real data, only if it really exists
|
|
|
+ FAnyData = Configuration->RegistryPathExists(Configuration->ConfigurationSubKey);
|
|
|
|
|
|
- for (int i = wdConfiguration; i <= wdTemporaryFolders; i++)
|
|
|
+ if (Configuration->RegistryPathExists(Configuration->StoredSessionsSubKey))
|
|
|
{
|
|
|
- UnicodeString Caption;
|
|
|
- UnicodeString Location;
|
|
|
-
|
|
|
- switch (i)
|
|
|
- {
|
|
|
- case wdConfiguration:
|
|
|
- Caption = LoadStr(CLEANUP_CONFIG);
|
|
|
- Location = Configuration->ConfigurationSubKey;
|
|
|
- break;
|
|
|
-
|
|
|
- case wdStoredSessions:
|
|
|
- Caption = LoadStr(CLEANUP_SESSIONS);
|
|
|
- Location = Configuration->StoredSessionsSubKey;
|
|
|
- break;
|
|
|
-
|
|
|
- case wdCaches:
|
|
|
- Caption = LoadStr(CLEANUP_HOSTKEYS);
|
|
|
- Location = L"...";
|
|
|
- break;
|
|
|
-
|
|
|
- case wdConfigurationIniFile:
|
|
|
- Caption = LoadStr(CLEANUP_INIFILE);
|
|
|
- Location = ExpandEnvironmentVariables(Configuration->IniFileStorageNameForReading);
|
|
|
- break;
|
|
|
+ AddRegistryLocation(CLEANUP_SESSIONS, Configuration->StoredSessionsSubKey, StoredSessions->Cleanup);
|
|
|
+ }
|
|
|
|
|
|
- case wdRandomSeedFile:
|
|
|
- Caption = LoadStr(CLEANUP_SEEDFILE);
|
|
|
- Location = ExpandEnvironmentVariables(Configuration->RandomSeedFile);
|
|
|
- break;
|
|
|
+ if (Configuration->HasAnyCache())
|
|
|
+ {
|
|
|
+ AddRegistryLocation(CLEANUP_HOSTKEYS, L"...", Configuration->CleanupCaches);
|
|
|
+ }
|
|
|
|
|
|
- case wdTemporaryFolders:
|
|
|
- Caption = LoadStr(CLEANUP_TEMP_FOLDERS);
|
|
|
- Location = WinConfiguration->TemporaryDir(true);
|
|
|
- break;
|
|
|
+ UnicodeString IniFilePath = ExpandEnvironmentVariables(Configuration->IniFileStorageNameForReading);
|
|
|
+ if (FileExists(IniFilePath))
|
|
|
+ {
|
|
|
+ AddLocation(CLEANUP_INIFILE, IniFilePath, Configuration->CleanupIniFile);
|
|
|
+ }
|
|
|
|
|
|
- default:
|
|
|
- DebugFail();
|
|
|
- break;
|
|
|
- }
|
|
|
+ if (RandomSeedExists())
|
|
|
+ {
|
|
|
+ AddLocation(CLEANUP_SEEDFILE, Configuration->RandomSeedFileName, Configuration->CleanupRandomSeedFile);
|
|
|
+ }
|
|
|
|
|
|
+ if (WinConfiguration->AnyTemporaryFolders())
|
|
|
+ {
|
|
|
+ AddLocation(CLEANUP_TEMP_FOLDERS, WinConfiguration->TemporaryDir(true), WinConfiguration->CleanupTemporaryFolders);
|
|
|
+ }
|
|
|
+}
|
|
|
+//---------------------------------------------------------------------
|
|
|
+void __fastcall TCleanupDialog::InitControls()
|
|
|
+{
|
|
|
+ DebugAssert(FCaptions.size() == FLocations.size());
|
|
|
+ DebugAssert(FCaptions.size() == FCleanupEvents.size());
|
|
|
+ // Particularly in response to WM_DPICHANGED, the form may re-show
|
|
|
+ DataListView->Items->Clear();
|
|
|
+ for (size_t Index = 0; Index < FCaptions.size(); Index++)
|
|
|
+ {
|
|
|
TListItem * Item = DataListView->Items->Add();
|
|
|
- Item->Caption = Caption;
|
|
|
- if (i < wdConfigurationIniFile)
|
|
|
- {
|
|
|
- Location = Configuration->RootKeyStr + L'\\' +
|
|
|
- Configuration->RegistryStorageKey + L'\\' + Location;
|
|
|
- }
|
|
|
-
|
|
|
- Item->SubItems->Add(Location);
|
|
|
- DebugAssert(Item->Index == i - 1);
|
|
|
+ Item->Caption = FCaptions[Index];
|
|
|
+ Item->SubItems->Add(FLocations[Index]);
|
|
|
}
|
|
|
|
|
|
AutoSizeListColumnsWidth(DataListView);
|
|
|
@@ -179,13 +144,33 @@ void __fastcall TCleanupDialog::DataListViewInfoTip(TObject * /*Sender*/,
|
|
|
ARRAYOFCONST((Item->Caption, Item->SubItems->Strings[0])));
|
|
|
}
|
|
|
//---------------------------------------------------------------------------
|
|
|
-bool __fastcall TCleanupDialog::GetCleanupData(TWinSCPData Data)
|
|
|
+void __fastcall TCleanupDialog::HelpButtonClick(TObject * /*Sender*/)
|
|
|
{
|
|
|
- return DataListView->Items->Item[Data - 1]->Checked;
|
|
|
+ FormHelp(this);
|
|
|
}
|
|
|
//---------------------------------------------------------------------------
|
|
|
-void __fastcall TCleanupDialog::HelpButtonClick(TObject * /*Sender*/)
|
|
|
+bool __fastcall TCleanupDialog::Execute()
|
|
|
{
|
|
|
- FormHelp(this);
|
|
|
+ bool Result = (ShowModal() == DefaultResult(this));
|
|
|
+ if (Result)
|
|
|
+ {
|
|
|
+ Configuration->Usage->Inc(L"Cleanups");
|
|
|
+
|
|
|
+ for (int Index = 0; Index < DataListView->Items->Count; Index++)
|
|
|
+ {
|
|
|
+ if (DataListView->Items->Item[Index]->Checked)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ FCleanupEvents[Index]();
|
|
|
+ }
|
|
|
+ catch (Exception & E)
|
|
|
+ {
|
|
|
+ ShowExtendedException(&E);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result;
|
|
|
}
|
|
|
//---------------------------------------------------------------------------
|