diff --git a/src/Kp2aBusinessLogic/Io/OneDriveFileStorage.cs b/src/Kp2aBusinessLogic/Io/OneDriveFileStorage.cs new file mode 100644 index 00000000..c5d522a8 --- /dev/null +++ b/src/Kp2aBusinessLogic/Io/OneDriveFileStorage.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +using Android.App; +using Android.Content; +using Android.OS; +using Android.Runtime; +using Android.Views; +using Android.Widget; +using KeePassLib.Serialization; +#if !EXCLUDE_JAVAFILESTORAGE +using Keepass2android.Javafilestorage; + +namespace keepass2android.Io +{ + public class OneDriveFileStorage: JavaFileStorage + { + private const string ClientId = "000000004010C234"; + + public OneDriveFileStorage(Context ctx, IKp2aApp app) : + base(new Keepass2android.Javafilestorage.OneDriveStorage(ctx, ClientId), app) + { + } + + public override IEnumerable SupportedProtocols + { + get + { + yield return "skydrive"; + yield return "onedrive"; + } + } + } +} +#endif \ No newline at end of file diff --git a/src/Kp2aBusinessLogic/Io/WebDavFileStorage.cs b/src/Kp2aBusinessLogic/Io/WebDavFileStorage.cs new file mode 100644 index 00000000..4459d4f8 --- /dev/null +++ b/src/Kp2aBusinessLogic/Io/WebDavFileStorage.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using Android.App; +using Android.Content; +using Android.OS; +using Android.Runtime; +using Android.Views; +using Android.Widget; +#if !NoNet +using Keepass2android.Javafilestorage; +#endif +using KeePassLib.Serialization; + +namespace keepass2android.Io +{ +#if !NoNet + public class WebDavFileStorage: JavaFileStorage + { + public WebDavFileStorage(IKp2aApp app) : base(new Keepass2android.Javafilestorage.WebDavStorage(app.CertificateErrorHandler), app) + { + } + + public override IEnumerable SupportedProtocols + { + get + { + yield return "http"; + yield return "https"; + yield return "owncloud"; + } + } + + public static string Owncloud2Webdav(string owncloudUrl) + { + string owncloudPrefix = "owncloud://"; + if (owncloudUrl.StartsWith(owncloudPrefix)) + { + owncloudUrl = owncloudUrl.Substring(owncloudPrefix.Length); + } + if (!owncloudUrl.Contains("://")) + owncloudUrl = "https://" + owncloudUrl; + if (!owncloudUrl.EndsWith("/")) + owncloudUrl += "/"; + owncloudUrl += "remote.php/webdav/"; + return owncloudUrl; + } + + public override void StartSelectFile(IFileStorageSetupInitiatorActivity activity, bool isForSave, int requestCode, + string protocolId) + { + //need to override so we can loop the protocolId through + activity.PerformManualFileSelect(isForSave, requestCode, protocolId); + } + + public override string IocToPath(IOConnectionInfo ioc) + { + if (ioc.Path.StartsWith("owncloud")) + throw new Exception("owncloud-URIs must be converted to https:// after credential input!"); + if (!String.IsNullOrEmpty(ioc.UserName)) + { + //legacy support. Some users may have stored IOCs with UserName inside. + return ((WebDavStorage)Jfs).BuildFullPath(ioc.Path, ioc.UserName, ioc.Password); + } + return base.IocToPath(ioc); + } + } +#endif +} \ No newline at end of file