private async Task InitSession() { try { StatusText = "Inititializing session..."; await osdbClient.InitSessionAsync(); } catch (OSDbException e) { var result = MessageBox.Show( $"Failed to initialize session: {e.Message}", "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); if (result == DialogResult.Retry) { await InitSession(); } else { Application.Exit(); } } StatusText = "Session initialized."; }
private static async Task <int> MainAsync() { IEnumerable <string> files = Enumerable.Empty <string>(); if (Directory.Exists(options.Path)) { files = ScanDirectory(options.Path); } else if (File.Exists(options.Path)) { if (options.Replace || !HasSubtitle(options.Path)) { files = new[] { options.Path }; } } else { Console.WriteLine("Path must be an existing file or directory."); Console.WriteLine(options.GetUsage()); return(1); } await client.InitSessionAsync(); var searchTasks = files.Select(f => SearchSubtitleAsync(f)); var subs = (await Task.WhenAll(searchTasks)).AsEnumerable(); subs = subs.Where(s => s.Selection != null); if (!options.DryRun && subs.Any()) { Console.WriteLine(); Console.WriteLine("Downloading..."); await DownloadSubtitlesAsync(subs); Console.WriteLine("Done!"); } return(0); }