[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> /// 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 } }