internal static string ShowKeyFileDialog(bool bSaveMode, string strTitle, string strSuggestedFileName, bool bAllFilesByDefault, bool bSecureDesktop) { Debug.Assert(!bSaveMode || !bAllFilesByDefault); // Not all files when saving string strFilter = AppDefs.GetKeyFileFilter(); int iFilterIndex = (bAllFilesByDefault ? 2 : 1); string strExt = (bSaveMode ? AppDefs.FileExtension.KeyFile : null); string strContext = AppDefs.FileDialogContext.KeyFile; return(ShowFileDialog(bSaveMode, strTitle, strSuggestedFileName, strFilter, iFilterIndex, strExt, strContext, bSecureDesktop)); }
private string GetKeyFilePath() { string strExt = AppDefs.FileExtension.KeyFile; string strFilter = AppDefs.GetKeyFileFilter(); string strName = UrlUtil.StripExtension(UrlUtil.GetFileName(m_ioInfo.Path)); if (string.IsNullOrEmpty(strName)) { strName = KPRes.KeyFileSafe; } SaveFileDialogEx sfd = UIUtil.CreateSaveFileDialog(KPRes.KeyFileCreateTitle, strName + "." + strExt, strFilter, 1, strExt, AppDefs.FileDialogContext.KeyFile); if (sfd.ShowDialog() == DialogResult.OK) { return(sfd.FileName); } return(null); }
private void OnClickKeyFileBrowse(object sender, EventArgs e) { string strFile = null; if (m_bSecureDesktop) { FileBrowserForm dlg = new FileBrowserForm(); dlg.InitEx(false, KPRes.KeyFileSelect, KPRes.SecDeskFileDialogHint, AppDefs.FileDialogContext.KeyFile); if (dlg.ShowDialog() == DialogResult.OK) { strFile = dlg.SelectedFile; } UIUtil.DestroyForm(dlg); } else { string strFilter = AppDefs.GetKeyFileFilter(); OpenFileDialogEx ofd = UIUtil.CreateOpenFileDialog(KPRes.KeyFileSelect, strFilter, 2, null, false, AppDefs.FileDialogContext.KeyFile); if (ofd.ShowDialog() == DialogResult.OK) { strFile = ofd.FileName; } } if (!string.IsNullOrEmpty(strFile)) { if ((Program.Config.UI.KeyPromptFlags & (ulong)AceKeyUIFlags.UncheckKeyFile) == 0) { UIUtil.SetChecked(m_cbKeyFile, true); } AddKeyFileSuggPriv(strFile, true); } EnableUserControls(); }
private void OnClickKeyFileBrowse(object sender, EventArgs e) { string strFilter = AppDefs.GetKeyFileFilter(); OpenFileDialogEx ofd = UIUtil.CreateOpenFileDialog(KPRes.KeyFileUseExisting, strFilter, 1, null, false, AppDefs.FileDialogContext.KeyFile); if (ofd.ShowDialog() != DialogResult.OK) { return; } string strFile = ofd.FileName; try { // Test whether we can read the file IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFile); IOConnection.OpenRead(ioc).Close(); // Check the file size? } catch (Exception ex) { MessageService.ShowWarning(ex); return; } if (!KfxFile.CanLoad(strFile)) { if (!MessageService.AskYesNo(strFile + MessageService.NewParagraph + KPRes.KeyFileNoXml + MessageService.NewParagraph + KPRes.KeyFileUseAnywayQ, null, false)) { return; } } m_cmbKeyFile.Items.Add(strFile); m_cmbKeyFile.SelectedIndex = m_cmbKeyFile.Items.Count - 1; EnableUserControls(); }