/// <summary> /// Registers the specified storage file. /// </summary> /// <param name="file">The database file.</param> /// <returns>The database registration information.</returns> public async Task <DatabaseRegistration> RegisterAsync(IStorageFile file) { using (var input = await file.OpenReadAsync()) { var headers = await FileFormat.Headers(input); switch (headers.Format) { case FileFormats.KeePass1x: case FileFormats.NewVersion: case FileFormats.NotSupported: case FileFormats.OldVersion: await _events.PublishOnUIThreadAsync( new DatabaseSupportMessage { FileName = file.Name, Format = headers.Format, }); return(null); case FileFormats.PartialSupported: await _events.PublishOnUIThreadAsync( new DatabaseSupportMessage { FileName = file.Name, Format = headers.Format, }); break; } } var meta = new DatabaseMetaData { Name = GetName(file.Name), }; // Check already registered database file var exists = _accessList.CheckAccess(file); if (exists) { await _events.PublishOnUIThreadAsync( new DuplicateDatabaseMessage()); return(null); } // Register for future access var token = _accessList.Add(file, JsonConvert.SerializeObject(meta)); await file.CopyAsync(await _cacheFolder, token + ".kdbx"); var info = new DatabaseRegistration { Id = token, Name = meta.Name, }; // Send notification message await _events.PublishOnUIThreadAsync( new DatabaseRegistrationMessage { Id = info.Id, Registration = info, Action = DatabaseRegistrationActions.Added, }); return(info); }