2013-08-01 16:20:39 -04:00
|
|
|
|
using System;
|
2013-09-15 14:08:14 -04:00
|
|
|
|
using System.Collections.Generic;
|
2013-08-01 16:20:39 -04:00
|
|
|
|
using System.IO;
|
2013-12-12 04:24:24 -05:00
|
|
|
|
using Android.Content;
|
|
|
|
|
using Android.OS;
|
2013-08-01 16:20:39 -04:00
|
|
|
|
using KeePassLib.Serialization;
|
2013-12-12 04:24:24 -05:00
|
|
|
|
using keepass2android;
|
2013-08-01 16:20:39 -04:00
|
|
|
|
using keepass2android.Io;
|
|
|
|
|
|
|
|
|
|
namespace Kp2aUnitTests
|
|
|
|
|
{
|
|
|
|
|
internal class TestFileStorage: IFileStorage
|
|
|
|
|
{
|
2013-12-12 04:24:24 -05:00
|
|
|
|
public TestFileStorage(IKp2aApp app)
|
|
|
|
|
{
|
|
|
|
|
_builtIn = new BuiltInFileStorage(app);
|
|
|
|
|
}
|
|
|
|
|
private BuiltInFileStorage _builtIn;
|
2013-08-01 16:20:39 -04:00
|
|
|
|
|
2013-12-12 04:24:24 -05:00
|
|
|
|
public static bool Offline { get; set; }
|
2013-08-01 16:20:39 -04:00
|
|
|
|
|
2013-09-15 14:08:14 -04:00
|
|
|
|
public IEnumerable<string> SupportedProtocols { get { yield return "test"; } }
|
2013-08-01 16:20:39 -04:00
|
|
|
|
|
|
|
|
|
public void DeleteFile(IOConnectionInfo ioc)
|
|
|
|
|
{
|
|
|
|
|
if (Offline)
|
|
|
|
|
throw new IOException("offline");
|
2013-09-28 01:46:44 -04:00
|
|
|
|
_builtIn.Delete(ioc);
|
2013-08-01 16:20:39 -04:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-28 01:46:44 -04:00
|
|
|
|
public void Delete(IOConnectionInfo ioc)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-01 16:20:39 -04:00
|
|
|
|
public bool CheckForFileChangeFast(IOConnectionInfo ioc, string previousFileVersion)
|
|
|
|
|
{
|
|
|
|
|
if (Offline)
|
|
|
|
|
return false;
|
|
|
|
|
return _builtIn.CheckForFileChangeFast(ioc, previousFileVersion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetCurrentFileVersionFast(IOConnectionInfo ioc)
|
|
|
|
|
{
|
|
|
|
|
if (Offline)
|
|
|
|
|
throw new IOException("offline");
|
|
|
|
|
return _builtIn.GetCurrentFileVersionFast(ioc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Stream OpenFileForRead(IOConnectionInfo ioc)
|
|
|
|
|
{
|
|
|
|
|
if (Offline)
|
|
|
|
|
throw new IOException("offline");
|
|
|
|
|
return _builtIn.OpenFileForRead(ioc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IWriteTransaction OpenWriteTransaction(IOConnectionInfo ioc, bool useFileTransaction)
|
|
|
|
|
{
|
|
|
|
|
if (Offline)
|
|
|
|
|
throw new IOException("offline");
|
|
|
|
|
return new TestFileTransaction(ioc, useFileTransaction, Offline);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class TestFileTransaction : IWriteTransaction
|
|
|
|
|
{
|
|
|
|
|
private readonly bool _offline;
|
|
|
|
|
private readonly FileTransactionEx _transaction;
|
|
|
|
|
|
|
|
|
|
public TestFileTransaction(IOConnectionInfo ioc, bool useFileTransaction, bool offline)
|
|
|
|
|
{
|
|
|
|
|
_offline = offline;
|
|
|
|
|
_transaction = new FileTransactionEx(ioc, useFileTransaction);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Stream OpenFile()
|
|
|
|
|
{
|
|
|
|
|
if (_offline)
|
|
|
|
|
throw new IOException("offline");
|
|
|
|
|
return _transaction.OpenWrite();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CommitWrite()
|
|
|
|
|
{
|
|
|
|
|
if (_offline)
|
|
|
|
|
throw new IOException("offline");
|
|
|
|
|
_transaction.CommitWrite();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string GetFilenameWithoutPathAndExt(IOConnectionInfo ioc)
|
|
|
|
|
{
|
|
|
|
|
return _builtIn.GetFilenameWithoutPathAndExt(ioc);
|
|
|
|
|
}
|
2013-09-15 14:08:14 -04:00
|
|
|
|
|
|
|
|
|
public bool RequiresCredentials(IOConnectionInfo ioc)
|
|
|
|
|
{
|
|
|
|
|
return _builtIn.RequiresCredentials(ioc);
|
|
|
|
|
}
|
2013-09-28 01:46:44 -04:00
|
|
|
|
|
2013-12-12 04:24:24 -05:00
|
|
|
|
public void CreateDirectory(IOConnectionInfo ioc, string newDirName)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-28 01:46:44 -04:00
|
|
|
|
public void CreateDirectory(IOConnectionInfo ioc)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<FileDescription> ListContents(IOConnectionInfo ioc)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
2013-09-28 15:14:21 -04:00
|
|
|
|
|
|
|
|
|
public FileDescription GetFileDescription(IOConnectionInfo ioc)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
2013-12-12 04:24:24 -05:00
|
|
|
|
|
|
|
|
|
public bool RequiresSetup(IOConnectionInfo ioConnection)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string IocToPath(IOConnectionInfo ioc)
|
|
|
|
|
{
|
|
|
|
|
return ioc.Path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StartSelectFile(IFileStorageSetupInitiatorActivity activity, bool isForSave, int requestCode, string protocolId)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void PrepareFileUsage(IFileStorageSetupInitiatorActivity activity, IOConnectionInfo ioc, int requestCode,
|
|
|
|
|
bool alwaysReturnSuccess)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnCreate(IFileStorageSetupActivity activity, Bundle savedInstanceState)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnResume(IFileStorageSetupActivity activity)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnStart(IFileStorageSetupActivity activity)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnActivityResult(IFileStorageSetupActivity activity, int requestCode, int resultCode, Intent data)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetDisplayName(IOConnectionInfo ioc)
|
|
|
|
|
{
|
|
|
|
|
return ioc.Path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string CreateFilePath(string parent, string newFilename)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IOConnectionInfo GetParentPath(IOConnectionInfo ioc)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IOConnectionInfo GetFilePath(IOConnectionInfo folderPath, string filename)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
2014-11-18 00:24:35 -05:00
|
|
|
|
|
|
|
|
|
public bool IsPermanentLocation(IOConnectionInfo ioc)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsReadOnly(IOConnectionInfo ioc)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-08-01 16:20:39 -04:00
|
|
|
|
}
|
|
|
|
|
}
|