Exemple #1
0
        private KuaipanClient CreateClient()
        {
            if (_MPwd == null)
            {
                _MPwd = _DataModel.ReadMPwd();
            }
            OAuthConsumer consumer = new OAuthConsumer();
            consumer.consumer_key = "xcLegJ8HLq7ZoQ0U";
            consumer.consumer_secret = "psaBwFH0Z0r2PEPI";

            OAuthTokenV1 token = new OAuthTokenV1();
            token.oauth_token = _MPwd.CsAuth;
            KuaipanClient client = new KuaipanClient(consumer, token, false);
            return client;
        }
Exemple #2
0
 public void SaveMPwd(MPwd pwd)
 {
     _DbEngine.Save(pwd);
 }
Exemple #3
0
        /// <summary>
        /// 远程恢复
        /// </summary>
        public void RemoteResume()
        {
            // 是否保存
            if (_SafeModel.Modified && DialogResult.Yes != Main.ShowConfirm("您的数据已修改,确认要丢弃吗?"))
            {
                return;
            }

            if (_MPwd == null)
            {
                _MPwd = _DataModel.ReadMPwd();
            }
            // 远程配置
            if (string.IsNullOrWhiteSpace(_MPwd.CsAuth) && !RemoteConfig())
            {
                return;
            }

            var client = CreateClient();
            var metas = client.ListMeta("/");
            if (metas == null || metas.Count < 1)
            {
                return;
            }

            PcsViewer viewer = new PcsViewer(metas);
            if (DialogResult.OK != viewer.ShowDialog(this))
            {
                return;
            }
            var meta = viewer.SelectedMeta;
            var file = Path.Combine(Path.GetTempPath(), meta.GetMetaName());
            var task = client.NewDownloadTask();
            task.Meta = meta.GetMeta();
            task.MetaName = meta.GetMetaName();
            task.MetaSize = meta.GetSize();
            task.File = file;
            task.FileName = task.MetaName;
            task.FileStream = new FileStream(file, FileMode.Create);
            task.Start();
        }
Exemple #4
0
        public bool RemoteConfig()
        {
            var client = CreateClient();
            if (!client.Verify())
            {
                return false;
            }

            var account = client.Account();
            if (_MPwd == null)
            {
                _MPwd = _DataModel.ReadMPwd();
            }
            _MPwd.CsType = "kuaipan";
            _MPwd.CsAuth = client.Token.oauth_token;
            _MPwd.CsUser = account.Name;
            _DataModel.SaveMPwd(_MPwd);
            return true;
        }
Exemple #5
0
        /// <summary>
        /// 远程备份
        /// </summary>
        public void RemoteBackup()
        {
            // 是否保存
            if (_SafeModel.Modified && DialogResult.Yes != Main.ShowConfirm("您的数据已修改,确认要丢弃吗?"))
            {
                return;
            }

            if (_MPwd == null)
            {
                _MPwd = _DataModel.ReadMPwd();
            }
            // 远程配置
            if (string.IsNullOrWhiteSpace(_MPwd.CsAuth) && !RemoteConfig())
            {
                return;
            }

            StartWork(new VoidHandler(DoRemoteBackup));
            Main.ShowWaiting("数据备份中,请稍候……");
        }
Exemple #6
0
        /// <summary>
        /// 本地恢复
        /// </summary>
        public void NativeResume()
        {
            if (_MPwd == null)
            {
                _MPwd = _DataModel.ReadMPwd();
            }

            if (string.IsNullOrWhiteSpace(_MPwd.NsPath))
            {
                Main.ShowAlert("您尚未配置本地备份路径!");
                return;
            }

            if (!Directory.Exists(_MPwd.NsPath))
            {
                Main.ShowAlert("本地备份路径不存在,请确认配置是否正确!");
                return;
            }

            if (_SafeModel.Modified && DialogResult.Yes != Main.ShowConfirm("您的数据已修改,确认要丢弃吗?"))
            {
                return;
            }

            if (DialogResult.OK != Main.ShowOpenFileDialog(this, "密码箱备份文件|*.apbak", "", _MPwd.NsPath, false))
            {
                return;
            }

            StartWork(new VoidHandler(DoNativeBackup));
            Main.ShowWaiting("数据恢复中,请稍候……");
        }
Exemple #7
0
        public bool NativeConfig()
        {
            if (_MPwd == null)
            {
                _MPwd = _DataModel.ReadMPwd();
            }
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            dialog.Description = "请选择本地备份路径:";
            dialog.SelectedPath = _MPwd.NsPath;
            if (DialogResult.OK != dialog.ShowDialog(this))
            {
                return false;
            }

            _MPwd.NsPath = dialog.SelectedPath;
            _DataModel.SaveMPwd(_MPwd);
            return true;
        }