Ejemplo n.º 1
0
        private void OnComponentShow(object sender, EventArgs e)
        {
            ListViewItem lvi = GetSelectedComponent();

            if (lvi == null)
            {
                Debug.Assert(false); return;
            }

            string strPath = (lvi.Tag as string);

            if (string.IsNullOrEmpty(strPath))
            {
                return;
            }

            if (File.Exists(strPath))
            {
                WinUtil.ShowFileInFileManager(strPath, true);
            }
            else
            {
                WinUtil.OpenUrlDirectly(strPath);
            }
        }
Ejemplo n.º 2
0
        internal static void ShowConfigError(string strPath, string strError,
                                             bool bSaving, bool bCreateBackup)
        {
            if (string.IsNullOrEmpty(strError))
            {
                Debug.Assert(false); return;
            }

            StringBuilder sb = new StringBuilder();

            if (!string.IsNullOrEmpty(strPath))
            {
                sb.AppendLine(VistaTaskDialog.CreateLink("c", strPath));
                sb.AppendLine();
            }

            sb.AppendLine(bSaving ? KLRes.FileSaveFailed : KLRes.FileLoadFailed);
            sb.AppendLine();
            sb.Append(strError);

            string strText = sb.ToString();

            VistaTaskDialog dlg = new VistaTaskDialog();

            dlg.AddButton((int)DialogResult.Cancel, KPRes.Ok, null);
            dlg.CommandLinks     = false;
            dlg.Content          = strText;
            dlg.DefaultButtonID  = (int)DialogResult.Cancel;
            dlg.EnableHyperlinks = true;
            dlg.MainInstruction  = KPRes.ConfigError;
            dlg.SetIcon(VtdIcon.Warning);
            dlg.WindowTitle = PwDefs.ShortProductName;

            string strBackupText = null;
            string strBackupPath = (bCreateBackup ? AppConfigSerializer.TryCreateBackup(
                                        strPath) : null);

            if (!string.IsNullOrEmpty(strBackupPath))
            {
                strBackupText = KPRes.ConfigOverwriteBackup + MessageService.NewLine +
                                VistaTaskDialog.CreateLink("b", strBackupPath);
                dlg.FooterText = strBackupText;
                dlg.SetFooterIcon(VtdIcon.Information);
            }

            dlg.LinkClicked += delegate(object sender, LinkClickedEventArgs e)
            {
                string str = (e.LinkText ?? string.Empty);
                if (str.Equals("c", StrUtil.CaseIgnoreCmp))
                {
                    WinUtil.ShowFileInFileManager(strPath, false);
                }
                else if (str.Equals("b", StrUtil.CaseIgnoreCmp))
                {
                    WinUtil.ShowFileInFileManager(strBackupPath, false);
                }
                else
                {
                    Debug.Assert(false);
                }
            };

            if (!dlg.ShowDialog())
            {
                if (!string.IsNullOrEmpty(strBackupText))
                {
                    strText += MessageService.NewParagraph + strBackupText;
                }
                strText = VistaTaskDialog.Unlink(strText);

                MessageService.ShowWarning(KPRes.ConfigError + "!", strText);
            }
        }
Ejemplo n.º 3
0
        public static bool Export(PwExportInfo pwExportInfo, FileFormatProvider fileFormat,
                                  IOConnectionInfo iocOutput, IStatusLogger slLogger)
        {
            if (pwExportInfo == null)
            {
                throw new ArgumentNullException("pwExportInfo");
            }
            if (pwExportInfo.DataGroup == null)
            {
                throw new ArgumentException();
            }
            if (fileFormat == null)
            {
                throw new ArgumentNullException("fileFormat");
            }

            bool bFileReq = fileFormat.RequiresFile;

            if (bFileReq && (iocOutput == null))
            {
                throw new ArgumentNullException("iocOutput");
            }
            if (bFileReq && (iocOutput.Path.Length == 0))
            {
                throw new ArgumentException();
            }

            PwDatabase pd = pwExportInfo.ContextDatabase;

            Debug.Assert(pd != null);

            if (!AppPolicy.Try(AppPolicyId.Export))
            {
                return(false);
            }
            if (!AppPolicy.Current.ExportNoKey && (pd != null))
            {
                if (!KeyUtil.ReAskKey(pd, true))
                {
                    return(false);
                }
            }

            if (!fileFormat.SupportsExport)
            {
                return(false);
            }
            if (!fileFormat.TryBeginExport())
            {
                return(false);
            }

            CompositeKey ckOrgMasterKey = null;
            DateTime     dtOrgMasterKey = PwDefs.DtDefaultNow;

            PwGroup pgOrgData     = pwExportInfo.DataGroup;
            PwGroup pgOrgRoot     = ((pd != null) ? pd.RootGroup : null);
            bool    bParentGroups = (pwExportInfo.ExportParentGroups && (pd != null) &&
                                     (pgOrgData != pgOrgRoot));

            bool bExistedAlready = true;             // No deletion by default
            bool bResult         = false;

            try
            {
                if (pwExportInfo.ExportMasterKeySpec && fileFormat.RequiresKey &&
                    (pd != null))
                {
                    KeyCreationForm kcf = new KeyCreationForm();
                    kcf.InitEx((iocOutput ?? new IOConnectionInfo()), true);

                    if (UIUtil.ShowDialogNotValue(kcf, DialogResult.OK))
                    {
                        return(false);
                    }

                    ckOrgMasterKey = pd.MasterKey;
                    dtOrgMasterKey = pd.MasterKeyChanged;

                    pd.MasterKey        = kcf.CompositeKey;
                    pd.MasterKeyChanged = DateTime.UtcNow;

                    UIUtil.DestroyForm(kcf);
                }

                if (bParentGroups)
                {
                    PwGroup pgNew = WithParentGroups(pgOrgData, pd);
                    pwExportInfo.DataGroup = pgNew;
                    pd.RootGroup           = pgNew;
                }

                if (bFileReq)
                {
                    bExistedAlready = IOConnection.FileExists(iocOutput);
                }

                Stream s = (bFileReq ? IOConnection.OpenWrite(iocOutput) : null);
                try { bResult = fileFormat.Export(pwExportInfo, s, slLogger); }
                finally { if (s != null)
                          {
                              s.Close();
                          }
                }

                if (bFileReq && bResult)
                {
                    if (pwExportInfo.ExportPostOpen)
                    {
                        NativeLib.StartProcess(iocOutput.Path);
                    }
                    if (pwExportInfo.ExportPostShow)
                    {
                        WinUtil.ShowFileInFileManager(iocOutput.Path, true);
                    }
                }
            }
            catch (Exception ex) { MessageService.ShowWarning(ex); }
            finally
            {
                if (ckOrgMasterKey != null)
                {
                    pd.MasterKey        = ckOrgMasterKey;
                    pd.MasterKeyChanged = dtOrgMasterKey;
                }

                if (bParentGroups)
                {
                    pwExportInfo.DataGroup = pgOrgData;
                    pd.RootGroup           = pgOrgRoot;
                }
            }

            if (bFileReq && !bResult && !bExistedAlready)
            {
                try { IOConnection.DeleteFile(iocOutput); }
                catch (Exception) { }
            }

            return(bResult);
        }