-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
66 lines (63 loc) · 2.3 KB
/
Program.cs
File metadata and controls
66 lines (63 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace AmazonEbookGetter
{
static class Program
{
static readonly AmazonEbookGetter ebookGetter = new AmazonEbookGetter();
static readonly CancellationTokenSource token = new CancellationTokenSource();
static async Task Main(string[] args)
{
try
{
string fireDir = string.Empty;
while (!File.Exists(fireDir))
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(@"Enter firefox exe directory (e.g. C:\Program Files\Mozilla Firefox\firefox.exe):");
Console.ForegroundColor = ConsoleColor.White;
fireDir = Console.ReadLine().Trim();
}
ebookGetter.StartBrowser(fireDir);
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ex.Message);
Console.ForegroundColor = ConsoleColor.White;
}
try
{
var t = Task.Run(() => ebookGetter.Run(token.Token), token.Token);
Console.ReadKey(true);
if (!t.IsCompleted)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Cancelling...\nPlease wait for \"Press enter to close...\" to appear before closing this window");
token.Cancel();
await t;
}
else
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Please wait for \"Press enter to close...\" to appear before closing this window");
}
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(e.Message);
}
finally
{
ebookGetter.CloseBrowser();
token.Dispose();
}
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Press enter to close...");
Console.ReadLine();
}
}
}