コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: App.cs プロジェクト: Arushacked/keepass2
        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);
        }
コード例 #3
0
        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();
        }