private void openFile() { try { Encrypter encrypter = Settings.SelectedEncrypter; if (System.IO.Directory.Exists(path)) { DialogResult result = openFileDialog.ShowDialog(); if (result == DialogResult.OK) { parent.OpenFile(openFileDialog.FileName, passwordTextbox.Text, encrypter); } } else //path is file assumed { parent.OpenFile(path, passwordTextbox.Text, encrypter); } this.Close(); } catch (FileException exception) { ShowError(Settings.GetString(exception.Error)); } catch (EncrypterException exception) { ShowError(Settings.GetString(exception.Error)); } }
static void Main(string[] args) { CommandLine cl = new CommandLine(args); if (cl.DisplayUI() || cl.ReceivedNoArguments()) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); FileForm form = new FileForm(); if (cl.HasErrors()) { form.ShowError(cl.ErrorMessages); } else { try { //opening a file if (cl.HasFile() && cl.HasDecryptInfo()) { form.OpenFile(cl.File, cl.Password, cl.Encrypter); } else if (cl.HasFile()) { form.CreateOpenForm(cl.File); } else if (cl.CreateNewFile()) { form.OpenNewFile(); } //fetching a field if (cl.HasField()) { form.CopyValueToClipboard(cl.Field); } } catch (FileException e) { form.ShowError(Settings.GetString(e.Error)); } catch (EncrypterException e) { form.ShowError(Settings.GetString(e.Error)); } } Application.Run(form); } else if (cl.HasFile() && cl.HasDecryptInfo()) { if (cl.HasErrors()) { Clipboard.SetText(cl.ErrorMessages); } else { try { File file = File.Open(cl.File, cl.Password, cl.Encrypter); if (cl.HasField()) { file.CopyToClipboard(cl.Field, Settings.ClipboardTimeout); } } catch (FileException e) { Clipboard.SetText(Settings.GetString(e.Error)); } catch (EncrypterException e) { Clipboard.SetText(Settings.GetString(e.Error)); } } } }