private void SetupProgressDialog(IKp2aApp app) { string currentMessage = "Initializing..."; string currentSubmessage = ""; if (_progressDialogStatusLogger != null) { currentMessage = _progressDialogStatusLogger.Message; currentSubmessage = _progressDialogStatusLogger.SubMessage; } if (_progressDialog != null) { var pd = _progressDialog; app.UiThreadHandler.Post(() => { pd.Dismiss(); }); } // Show process dialog _progressDialog = app.CreateProgressDialog(_activeActivity); _progressDialog.SetTitle(_app.GetResourceString(UiStringKey.progress_title)); _progressDialogStatusLogger = new ProgressDialogStatusLogger(_app, _handler, _progressDialog); _progressDialogStatusLogger.UpdateMessage(currentMessage); _progressDialogStatusLogger.UpdateSubMessage(currentSubmessage); }
public void SetStatusLogger(ProgressDialogStatusLogger status) { if (OnFinishToRun != null) { OnFinishToRun.StatusLogger = status; } StatusLogger = status; }
public Database LoadDatabase(IOConnectionInfo ioConnectionInfo, MemoryStream memoryStream, CompositeKey compositeKey, ProgressDialogStatusLogger statusLogger, IDatabaseFormat databaseFormat, bool makeCurrent) { var prefs = PreferenceManager.GetDefaultSharedPreferences(Application.Context); var createBackup = prefs.GetBoolean(Application.Context.GetString(Resource.String.CreateBackups_key), true) && !(new LocalFileStorage(this).IsLocalBackup(ioConnectionInfo)); MemoryStream backupCopy = new MemoryStream(); if (createBackup) { memoryStream.CopyTo(backupCopy); backupCopy.Seek(0, SeekOrigin.Begin); //reset stream if we need to reuse it later: memoryStream.Seek(0, SeekOrigin.Begin); } foreach (Database openDb in _openDatabases) { if (openDb.Ioc.IsSameFileAs(ioConnectionInfo)) { //TODO check this earlier and simply open the database's root group throw new Exception("Database already loaded!"); } } _openAttempts.Add(ioConnectionInfo); var newDb = new Database(new DrawableFactory(), this); newDb.LoadData(this, ioConnectionInfo, memoryStream, compositeKey, statusLogger, databaseFormat); if ((_currentDatabase == null) || makeCurrent) { _currentDatabase = newDb; } _openDatabases.Add(newDb); if (createBackup) { statusLogger.UpdateMessage(Application.Context.GetString(Resource.String.UpdatingBackup)); Java.IO.File internalDirectory = IoUtil.GetInternalDirectory(Application.Context); string baseDisplayName = App.Kp2a.GetFileStorage(ioConnectionInfo).GetDisplayName(ioConnectionInfo); string targetPath = baseDisplayName; var charsToRemove = "|\\?*<\":>+[]/'"; foreach (char c in charsToRemove) { targetPath = targetPath.Replace(c.ToString(), string.Empty); } if (targetPath == "") { targetPath = "local_backup"; } var targetIoc = IOConnectionInfo.FromPath(new Java.IO.File(internalDirectory, targetPath).CanonicalPath); using (var transaction = new LocalFileStorage(App.Kp2a).OpenWriteTransaction(targetIoc, false)) { using (var file = transaction.OpenFile()) { backupCopy.CopyTo(file); transaction.CommitWrite(); } } Java.Lang.Object baseIocDisplayName = baseDisplayName; string keyfile = App.Kp2a.FileDbHelper.GetKeyFileForFile(ioConnectionInfo.Path); App.Kp2a.StoreOpenedFileAsRecent(targetIoc, keyfile, false, Application.Context. GetString(Resource.String.LocalBackupOf, new Java.Lang.Object[] { baseIocDisplayName })); prefs.Edit() .PutBoolean(IoUtil.GetIocPrefKey(ioConnectionInfo, "has_local_backup"), true) .PutBoolean(IoUtil.GetIocPrefKey(targetIoc, "is_local_backup"), true) .Commit(); } else { prefs.Edit() .PutBoolean(IoUtil.GetIocPrefKey(ioConnectionInfo, "has_local_backup"), false) //there might be an older local backup, but we won't "advertise" this anymore .Commit(); } UpdateOngoingNotification(); return(newDb); }
public void LoadDatabase(IOConnectionInfo ioConnectionInfo, MemoryStream memoryStream, CompositeKey compKey, ProgressDialogStatusLogger statusLogger, IDatabaseFormat databaseFormat) { _db.LoadData(this, ioConnectionInfo, memoryStream, compKey, statusLogger, databaseFormat); }
protected virtual void PopulateDatabaseFromStream(PwDatabase pwDatabase, Stream s, IOConnectionInfo iocInfo, CompositeKey compositeKey, ProgressDialogStatusLogger status, IDatabaseFormat databaseFormat) { IFileStorage fileStorage = _app.GetFileStorage(iocInfo); var filename = fileStorage.GetFilenameWithoutPathAndExt(iocInfo); pwDatabase.Open(s, filename, iocInfo, compositeKey, status, databaseFormat); }
/// <summary> /// Do not call this method directly. Call App.Kp2a.LoadDatabase instead. /// </summary> public void LoadData(IKp2aApp app, IOConnectionInfo iocInfo, MemoryStream databaseData, CompositeKey compositeKey, ProgressDialogStatusLogger status, IDatabaseFormat databaseFormat) { PwDatabase pwDatabase = new PwDatabase(); IFileStorage fileStorage = _app.GetFileStorage(iocInfo); Stream s = databaseData ?? fileStorage.OpenFileForRead(iocInfo); var fileVersion = _app.GetFileStorage(iocInfo).GetCurrentFileVersionFast(iocInfo); PopulateDatabaseFromStream(pwDatabase, s, iocInfo, compositeKey, status, databaseFormat); try { LastFileVersion = fileVersion; status.UpdateSubMessage(""); Root = pwDatabase.RootGroup; PopulateGlobals(Root); KpDatabase = pwDatabase; SearchHelper = new SearchDbHelper(app); _databaseFormat = databaseFormat; CanWrite = databaseFormat.CanWrite && !fileStorage.IsReadOnly(iocInfo); Loaded = true; } catch (Exception) { Clear(); throw; } }
public void LoadDatabase(IOConnectionInfo ioConnectionInfo, MemoryStream memoryStream, CompositeKey compositeKey, ProgressDialogStatusLogger statusLogger, IDatabaseFormat databaseFormat) { _db.LoadData(this, ioConnectionInfo, memoryStream, compositeKey, statusLogger, databaseFormat); UpdateOngoingNotification(); }
public void LoadDatabase(IOConnectionInfo ioConnectionInfo, MemoryStream memoryStream, CompositeKey compositeKey, ProgressDialogStatusLogger statusLogger, IDatabaseFormat databaseFormat) { var prefs = PreferenceManager.GetDefaultSharedPreferences(Application.Context); var createBackup = prefs.GetBoolean(Application.Context.GetString(Resource.String.CreateBackups_key), true); MemoryStream backupCopy = new MemoryStream(); if (createBackup) { memoryStream.CopyTo(backupCopy); backupCopy.Seek(0, SeekOrigin.Begin); //reset stream if we need to reuse it later: memoryStream.Seek(0, SeekOrigin.Begin); } _db.LoadData(this, ioConnectionInfo, memoryStream, compositeKey, statusLogger, databaseFormat); if (createBackup) { statusLogger.UpdateMessage(Application.Context.GetString(Resource.String.UpdatingBackup)); Java.IO.File internalDirectory = IoUtil.GetInternalDirectory(Application.Context); string baseDisplayName = App.Kp2a.GetFileStorage(ioConnectionInfo).GetDisplayName(ioConnectionInfo); string targetPath = baseDisplayName; var charsToRemove = "|\\?*<\":>+[]/'"; foreach (char c in charsToRemove) { targetPath = targetPath.Replace(c.ToString(), string.Empty); } if (targetPath == "") { targetPath = "local_backup"; } var targetIoc = IOConnectionInfo.FromPath(new Java.IO.File(internalDirectory, targetPath).CanonicalPath); using (var transaction = new LocalFileStorage(App.Kp2a).OpenWriteTransaction(targetIoc, false)) { var file = transaction.OpenFile(); backupCopy.CopyTo(file); transaction.CommitWrite(); } Java.Lang.Object baseIocDisplayName = baseDisplayName; string keyfile = App.Kp2a.FileDbHelper.GetKeyFileForFile(ioConnectionInfo.Path); App.Kp2a.StoreOpenedFileAsRecent(targetIoc, keyfile, Application.Context. GetString(Resource.String.LocalBackupOf, new Java.Lang.Object[] { baseIocDisplayName })); prefs.Edit() .PutBoolean(IoUtil.GetIocPrefKey(ioConnectionInfo, "has_local_backup"), true) .PutBoolean(IoUtil.GetIocPrefKey(targetIoc, "is_local_backup"), true) .Commit(); } else { prefs.Edit() .PutBoolean(IoUtil.GetIocPrefKey(ioConnectionInfo, "has_local_backup"), false) //there might be an older local backup, but we won't "advertise" this anymore .Commit(); } UpdateOngoingNotification(); }
/// <summary> /// Do not call this method directly. Call App.Kp2a.LoadDatabase instead. /// </summary> public void LoadData(IKp2aApp app, IOConnectionInfo iocInfo, MemoryStream databaseData, CompositeKey compositeKey, ProgressDialogStatusLogger status, IDatabaseFormat databaseFormat) { PwDatabase pwDatabase = new PwDatabase(); IFileStorage fileStorage = _app.GetFileStorage(iocInfo); Stream s = databaseData ?? fileStorage.OpenFileForRead(iocInfo); var fileVersion = _app.GetFileStorage(iocInfo).GetCurrentFileVersionFast(iocInfo); PopulateDatabaseFromStream(pwDatabase, s, iocInfo, compositeKey, status, databaseFormat); try { LastFileVersion = fileVersion; status.UpdateSubMessage(""); Root = pwDatabase.RootGroup; PopulateGlobals(Root); Loaded = true; KpDatabase = pwDatabase; SearchHelper = new SearchDbHelper(app); _databaseFormat = databaseFormat; CanWrite = databaseFormat.CanWrite && !fileStorage.IsReadOnly(iocInfo); } catch (Exception) { Clear(); throw; } }