refactor SftpFileStorage creation

This commit is contained in:
Philipp Crocoll
2023-11-13 09:18:39 +01:00
parent c19b8d2238
commit 30d45e086c
3 changed files with 28 additions and 31 deletions

View File

@@ -25,7 +25,7 @@ namespace keepass2android.Io
public abstract bool UserShouldBackup { get; }
private readonly IJavaFileStorage _jfs;
protected readonly IJavaFileStorage _jfs;
private readonly IKp2aApp _app;
public JavaFileStorage(IJavaFileStorage jfs, IKp2aApp app)

View File

@@ -1,17 +1,39 @@
using Android.Content;
using Java.Nio.FileNio;
#if !EXCLUDE_JAVAFILESTORAGE
namespace keepass2android.Io
{
public class SftpFileStorage: JavaFileStorage
{
public SftpFileStorage(Context ctx, IKp2aApp app) :
public SftpFileStorage(Context ctx, IKp2aApp app, bool debugEnabled) :
base(new Keepass2android.Javafilestorage.SftpStorage(ctx.ApplicationContext), app)
{
}
var storage = BaseStorage;
if (debugEnabled)
{
string? logFilename = null;
if (Kp2aLog.LogToFile)
{
logFilename = Kp2aLog.LogFilename;
}
storage.SetJschLogging(true, logFilename);
}
else
{
storage.SetJschLogging(false, null);
}
}
private Keepass2android.Javafilestorage.SftpStorage BaseStorage
{
get
{
return _jfs as Keepass2android.Javafilestorage.SftpStorage;
}
}
public override bool UserShouldBackup
public override bool UserShouldBackup
{
get { return true; }
}

View File

@@ -832,7 +832,7 @@ namespace keepass2android
new OneDrive2FullFileStorage(),
new OneDrive2MyFilesFileStorage(),
new OneDrive2AppFolderFileStorage(),
CreateSftpFileStorage(),
new SftpFileStorage(LocaleManager.LocalizedAppContext, this, IsFtpDebugEnabled()),
new NetFtpFileStorage(LocaleManager.LocalizedAppContext, this, IsFtpDebugEnabled),
new WebDavFileStorage(this),
new PCloudFileStorage(LocaleManager.LocalizedAppContext, this),
@@ -854,33 +854,8 @@ namespace keepass2android
return PreferenceManager.GetDefaultSharedPreferences(LocaleManager.LocalizedAppContext)
.GetBoolean(LocaleManager.LocalizedAppContext.GetString(Resource.String.FtpDebug_key), false);
}
#if !EXCLUDE_JAVAFILESTORAGE
#if !NoNet
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;
}
#endif
#endif
public void TriggerReload(Context ctx, Action<bool> actionOnResult)
public void TriggerReload(Context ctx, Action<bool> actionOnResult)
{
Handler handler = new Handler(Looper.MainLooper);
handler.Post(() =>