/// <summary> /// Applies user-selected modifications to a feed. /// </summary> /// <param name="feedEditing">The feed to modify.</param> /// <exception cref="OperationCanceledException">The user canceled the task.</exception> /// <exception cref="WebException">A file could not be downloaded from the internet.</exception> /// <exception cref="IOException">There is a problem access a temporary file.</exception> /// <exception cref="UnauthorizedAccessException">Read or write access to a temporary file is not permitted.</exception> /// <exception cref="DigestMismatchException">An existing digest does not match the newly calculated one.</exception> private void HandleModify(FeedEditing feedEditing) { if (_addMissing) { AddMissing(feedEditing.SignedFeed.Feed.Elements, feedEditing); } }
/// <summary> /// Creates a new feed editing form. /// </summary> /// <param name="feedEditing">The feed to open on start up.</param> /// <param name="openPgp">The OpenPGP-compatible system used to create signatures.</param> public MainForm([NotNull] FeedEditing feedEditing, [NotNull] IOpenPgp openPgp) { InitializeComponent(); _openPgp = openPgp; FeedEditing = feedEditing; }
/// <summary> /// Creates a new feed editing form. /// </summary> /// <param name="feedEditing">The feed to open on start up.</param> /// <param name="openPgp">The OpenPGP-compatible system used to create signatures.</param> public MainForm([NotNull] FeedEditing feedEditing, [NotNull] IOpenPgp openPgp) { InitializeComponent(); _openPgp = openPgp; FeedEditing = feedEditing; }
private void SwitchToMain(FeedEditing feedEditing) { using (var form = new MainForm(feedEditing, _openPgp)) { Hide(); form.ShowDialog(); Close(); } }
/// <summary> /// Saves a feed. /// </summary> /// <exception cref="IOException">A file could not be read or written or the GnuPG could not be launched or the feed file could not be read or written.</exception> /// <exception cref="UnauthorizedAccessException">Read or write access to a feed file is not permitted.</exception> /// <exception cref="KeyNotFoundException">An OpenPGP key could not be found.</exception> private void SaveFeed(FeedEditing feedEditing) { if (_unsign) { // Remove any existing signatures feedEditing.SignedFeed.SecretKey = null; } else { var openPgp = OpenPgpFactory.CreateDefault(); if (_xmlSign) { // Signing explicitly requested if (feedEditing.SignedFeed.SecretKey == null) { // No previous signature // Use user-specified key or default key feedEditing.SignedFeed.SecretKey = openPgp.GetSecretKey(_key); } else { // Existing siganture if (!string.IsNullOrEmpty(_key)) // Use new user-specified key { feedEditing.SignedFeed.SecretKey = openPgp.GetSecretKey(_key); } //else resign implied } } //else resign implied } // If no signing or unsigning was explicitly requested and the content did not change // there is no need to overwrite (and potentiall resign) the file if (!_xmlSign && !_unsign && !feedEditing.Changed) { return; } while (true) { try { Debug.Assert(feedEditing.Path != null); feedEditing.SignedFeed.Save(feedEditing.Path, _openPgpPassphrase); break; // Exit loop if passphrase is correct } catch (WrongPassphraseException ex) { // Continue loop if passhrase is incorrect if (!string.IsNullOrEmpty(_openPgpPassphrase)) { Log.Error(ex); } } // Ask for passphrase to unlock secret key if we were unable to save without it _openPgpPassphrase = CliUtils.ReadPassword(string.Format(Resources.AskForPassphrase, feedEditing.SignedFeed.SecretKey)); } }
private void SwitchToMain(FeedEditing feedEditing) { using (var form = new MainForm(feedEditing, _openPgp)) { Hide(); form.ShowDialog(); Close(); } }
/// <summary> /// Applies user-selected modifications to a feed. /// </summary> /// <param name="feedEditing">The feed to modify.</param> /// <exception cref="OperationCanceledException">The user canceled the task.</exception> /// <exception cref="WebException">A file could not be downloaded from the internet.</exception> /// <exception cref="IOException">There is a problem access a temporary file.</exception> /// <exception cref="UnauthorizedAccessException">Read or write access to a temporary file is not permitted.</exception> /// <exception cref="DigestMismatchException">An existing digest does not match the newly calculated one.</exception> private void HandleModify(FeedEditing feedEditing) { if (_addMissing) { var feed = feedEditing.SignedFeed.Feed; feed.ResolveInternalReferences(); AddMissing(feed.Elements, feedEditing); } }
private void menuOpen_Click(object sender, EventArgs e) { try { AskForChangeSave(); FeedEditing = OpenFeed(this); } catch (OperationCanceledException) {} }
private void menuNew_Click(object sender, EventArgs e) { try { AskForChangeSave(); FeedEditing = new FeedEditing(); comboBoxKeys.SelectedItem = null; } catch (OperationCanceledException) {} }
private void menuNewWizard_Click(object sender, EventArgs e) { try { AskForChangeSave(); var result = Wizards.NewFeedWizard.Run(_openPgp, this); if (result != null) { FeedEditing = new FeedEditing(result); } } catch (OperationCanceledException) {} }
[STAThread] // Required for WinForms private static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); ErrorReportForm.SetupMonitoring(new Uri("https://0install.de/error-report/")); NetUtils.ApplyProxy(); var openPgp = OpenPgpFactory.CreateDefault(); if (args == null || args.Length == 0) { Application.Run(new WelcomeForm(openPgp)); } else { try { var files = ArgumentUtils.GetFiles(args, "*.xml"); if (files.Count == 1) { string path = files.First().FullName; Application.Run(new MainForm(FeedEditing.Load(path), openPgp)); } else { MassSignForm.Show(files); } } #region Error handling catch (ArgumentException ex) { Msg.Inform(null, ex.Message, MsgSeverity.Warn); } catch (IOException ex) { Msg.Inform(null, ex.Message, MsgSeverity.Warn); } catch (UnauthorizedAccessException ex) { Msg.Inform(null, ex.Message, MsgSeverity.Warn); } catch (InvalidDataException ex) { Msg.Inform(null, ex.Message + (ex.InnerException == null ? "" : Environment.NewLine + ex.InnerException.Message), MsgSeverity.Warn); } #endregion } }
/// <summary> /// Saves a feed. /// </summary> /// <exception cref="IOException">A file could not be read or written or the GnuPG could not be launched or the feed file could not be read or written.</exception> /// <exception cref="UnauthorizedAccessException">Read or write access to a feed file is not permitted.</exception> /// <exception cref="KeyNotFoundException">An OpenPGP key could not be found.</exception> private void SaveFeed(FeedEditing feedEditing) { if (!feedEditing.Path !.EndsWith(".xml.template") && !feedEditing.IsValid(out string problem)) { Log.Warn(problem); } if (_unsign) { // Remove any existing signatures feedEditing.SignedFeed.SecretKey = null; } else { var openPgp = OpenPgp.Signing(); if (_xmlSign) { // Signing explicitly requested if (feedEditing.SignedFeed.SecretKey == null) { // No previous signature // Use user-specified key or default key feedEditing.SignedFeed.SecretKey = openPgp.GetSecretKey(_key); } else { // Existing signature if (!string.IsNullOrEmpty(_key)) // Use new user-specified key { feedEditing.SignedFeed.SecretKey = openPgp.GetSecretKey(_key); } //else resign implied } } //else resign implied } // If no signing or unsigning was explicitly requested and the content did not change // there is no need to overwrite (and potential resign) the file if (!_xmlSign && !_unsign && !feedEditing.UnsavedChanges) { return; } PromptPassphrase( () => feedEditing.SignedFeed.Save(feedEditing.Path !, _openPgpPassphrase), feedEditing.SignedFeed.SecretKey); }
/// <summary> /// Executes the commands specified by the command-line arguments. /// </summary> /// <returns>The error code to end the process with.</returns> /// <exception cref="OperationCanceledException">The user canceled the task.</exception> /// <exception cref="OptionException">The specified feed file paths were invalid.</exception> /// <exception cref="WebException">A file could not be downloaded from the internet.</exception> /// <exception cref="InvalidDataException">A feed file is damaged.</exception> /// <exception cref="FileNotFoundException">A feed file could not be found.</exception> /// <exception cref="IOException">A file could not be read or written or the GnuPG could not be launched or the feed file could not be read or written.</exception> /// <exception cref="UnauthorizedAccessException">Read or write access to a feed file or the catalog file is not permitted.</exception> /// <exception cref="DigestMismatchException">An existing digest does not match the newly calculated one.</exception> /// <exception cref="KeyNotFoundException">An OpenPGP key could not be found.</exception> /// <exception cref="NotSupportedException">A MIME type doesn't belong to a known and supported archive type.</exception> public ExitCode Execute() { switch (_mode) { case OperationMode.Normal: if (_feeds.Count == 0) { Log.Error(string.Format(Resources.MissingArguments, "0publish")); return(ExitCode.InvalidArguments); } foreach (var feedEditing in _feeds.Select(file => FeedEditing.Load(file.FullName))) { HandleModify(feedEditing); SaveFeed(feedEditing); } return(ExitCode.OK); case OperationMode.Catalog: // Default to using all XML files in the current directory if (_feeds.Count == 0) { _feeds = ArgumentUtils.GetFiles(new[] { Environment.CurrentDirectory }, "*.xml"); } var catalog = new Catalog(); foreach (var feed in _feeds.Select(feedFile => XmlStorage.LoadXml <Feed>(feedFile.FullName))) { feed.Strip(); catalog.Feeds.Add(feed); } if (catalog.Feeds.Count == 0) { throw new FileNotFoundException(Resources.NoFeedFilesFound); } SaveCatalog(catalog); return(ExitCode.OK); default: Log.Error(string.Format(Resources.UnknownMode, "0publish")); return(ExitCode.InvalidArguments); } }
[STAThread] // Required for WinForms private static void Main(string[] args) { ProcessUtils.SanitizeEnvironmentVariables(); NetUtils.ApplyProxy(); WindowsUtils.SetCurrentProcessAppID("ZeroInstall.Publishing"); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); ErrorReportForm.SetupMonitoring(new Uri("https://0install.de/error-report/")); var openPgp = OpenPgp.Signing(); if (args.Length == 0) { Application.Run(new WelcomeForm(openPgp)); } else { try { var files = Paths.ResolveFiles(args, "*.xml"); if (files.Count == 1) { string path = files.First().FullName; Application.Run(new MainForm(FeedEditing.Load(path), openPgp)); } else { MassSignForm.Show(files); } } #region Error handling catch (Exception ex) when(ex is ArgumentException or IOException or InvalidDataException) { Msg.Inform(null, ex.GetMessageWithInner(), MsgSeverity.Warn); } catch (Exception ex) when(ex is UnauthorizedAccessException) { Msg.Inform(null, ex.Message, MsgSeverity.Error); } #endregion } }
private void menuOpen_Click(object sender, EventArgs e) { try { AskForChangeSave(); FeedEditing = OpenFeed(this); } catch (OperationCanceledException) {} }
private void menuNew_Click(object sender, EventArgs e) { try { AskForChangeSave(); FeedEditing = new FeedEditing(); comboBoxKeys.SelectedItem = null; } catch (OperationCanceledException) {} }
private void menuNewWizard_Click(object sender, EventArgs e) { try { AskForChangeSave(); var result = NewFeedWizard.Run(_openPgp, this); if (result != null) FeedEditing = new FeedEditing(result); } catch (OperationCanceledException) {} }
/// <summary> /// Saves a feed. /// </summary> /// <exception cref="IOException">A file could not be read or written or the GnuPG could not be launched or the feed file could not be read or written.</exception> /// <exception cref="UnauthorizedAccessException">Read or write access to a feed file is not permitted.</exception> /// <exception cref="KeyNotFoundException">An OpenPGP key could not be found.</exception> private void SaveFeed(FeedEditing feedEditing) { if (_unsign) { // Remove any existing signatures feedEditing.SignedFeed.SecretKey = null; } else { var openPgp = OpenPgpFactory.CreateDefault(); if (_xmlSign) { // Signing explicitly requested if (feedEditing.SignedFeed.SecretKey == null) { // No previous signature // Use user-specified key or default key feedEditing.SignedFeed.SecretKey = openPgp.GetSecretKey(_key); } else { // Existing siganture if (!string.IsNullOrEmpty(_key)) // Use new user-specified key feedEditing.SignedFeed.SecretKey = openPgp.GetSecretKey(_key); //else resign implied } } //else resign implied } // If no signing or unsigning was explicitly requested and the content did not change // there is no need to overwrite (and potentiall resign) the file if (!_xmlSign && !_unsign && !feedEditing.Changed) return; while (true) { try { Debug.Assert(feedEditing.Path != null); feedEditing.SignedFeed.Save(feedEditing.Path, _openPgpPassphrase); break; // Exit loop if passphrase is correct } catch (WrongPassphraseException ex) { // Continue loop if passhrase is incorrect if (!string.IsNullOrEmpty(_openPgpPassphrase)) Log.Error(ex); } // Ask for passphrase to unlock secret key if we were unable to save without it _openPgpPassphrase = CliUtils.ReadPassword(string.Format(Resources.AskForPassphrase, feedEditing.SignedFeed.SecretKey)); } }
/// <summary> /// Applies user-selected modifications to a feed. /// </summary> /// <param name="feedEditing">The feed to modify.</param> /// <exception cref="OperationCanceledException">The user canceled the task.</exception> /// <exception cref="WebException">A file could not be downloaded from the internet.</exception> /// <exception cref="IOException">There is a problem access a temporary file.</exception> /// <exception cref="UnauthorizedAccessException">Read or write access to a temporary file is not permitted.</exception> /// <exception cref="DigestMismatchException">An existing digest does not match the newly calculated one.</exception> private void HandleModify(FeedEditing feedEditing) { if (_addMissing) AddMissing(feedEditing.SignedFeed.Feed.Elements, feedEditing); }