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
This commit is contained in:
Rick Brown
2023-11-06 16:55:36 -05:00
parent 4dbd33ba97
commit 141d2f3ddb
2 changed files with 28 additions and 2 deletions

View File

@@ -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<bool> actionOnResult)
{
Handler handler = new Handler(Looper.MainLooper);

View File

@@ -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)