From 141d2f3ddb0ae2270f9ccc33369a9ad669ce6add Mon Sep 17 00:00:00 2001 From: Rick Brown Date: Mon, 6 Nov 2023 16:55:36 -0500 Subject: [PATCH] Persist FTP/SFTP debug log preference -Commit/apply FtpDebug_key state to persistent preferences -Configure SFTP/JSch logging based on FtpDebug_key/LogFilename state on app startup --- src/keepass2android/app/App.cs | 24 ++++++++++++++++++- .../settings/DatabaseSettingsActivity.cs | 6 ++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/keepass2android/app/App.cs b/src/keepass2android/app/App.cs index ec3959de..3ea9e560 100644 --- a/src/keepass2android/app/App.cs +++ b/src/keepass2android/app/App.cs @@ -832,7 +832,7 @@ namespace keepass2android new OneDrive2FullFileStorage(), new OneDrive2MyFilesFileStorage(), new OneDrive2AppFolderFileStorage(), - new SftpFileStorage(LocaleManager.LocalizedAppContext, this), + CreateSftpFileStorage(), new NetFtpFileStorage(LocaleManager.LocalizedAppContext, this, IsFtpDebugEnabled), new WebDavFileStorage(this), new PCloudFileStorage(LocaleManager.LocalizedAppContext, this), @@ -855,6 +855,28 @@ namespace keepass2android .GetBoolean(LocaleManager.LocalizedAppContext.GetString(Resource.String.FtpDebug_key), false); } + private IFileStorage CreateSftpFileStorage() + { + Context ctx = LocaleManager.LocalizedAppContext; + SftpFileStorage fileStorage = new SftpFileStorage(ctx, this); + + var storage = new SftpStorage(ctx); + if (IsFtpDebugEnabled()) + { + string? logFilename = null; + if (Kp2aLog.LogToFile) + { + logFilename = Kp2aLog.LogFilename; + } + storage.SetJschLogging(true, logFilename); + } else + { + storage.SetJschLogging(false, null); + } + + return fileStorage; + } + public void TriggerReload(Context ctx, Action actionOnResult) { Handler handler = new Handler(Looper.MainLooper); diff --git a/src/keepass2android/settings/DatabaseSettingsActivity.cs b/src/keepass2android/settings/DatabaseSettingsActivity.cs index 8ca43717..9d7aa071 100644 --- a/src/keepass2android/settings/DatabaseSettingsActivity.cs +++ b/src/keepass2android/settings/DatabaseSettingsActivity.cs @@ -401,7 +401,11 @@ namespace keepass2android #if !EXCLUDE_JAVAFILESTORAGE && !NoNet private void OnJSchDebugChanged(object sender, Preference.PreferenceChangeEventArgs e) { - SetJSchLogging((bool)e.NewValue); + bool debugEnabled = (bool)e.NewValue; + SetJSchLogging(debugEnabled); + + string prefKey = Application.Context.GetString(Resource.String.FtpDebug_key); + PreferenceManager.SharedPreferences.Edit().PutBoolean(prefKey, debugEnabled).Apply(); } private void SetJSchLogging(bool enabled)