This repository has been archived by the owner on Dec 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
91 lines (79 loc) · 2.21 KB
/
Program.cs
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Net;
using System.Web;
namespace FsUaDownloader
{
internal class Program
{
private static void Main(string[] args)
{
if (args.Length == 0)
{
ShowError("Filename with links not specified.");
return;
}
var filename = args[0];
if (!File.Exists(filename))
{
ShowError("File '" + filename + "' not exists.");
return;
}
string domain = ConfigurationManager.AppSettings["app:domain"];
Console.WriteLine("Load and parse links for download...");
var availableLinks = new Dictionary<string, string>();
var lines = File.ReadAllLines(filename);
foreach (var line in lines)
{
var tempLine = line.Trim();
if (String.IsNullOrWhiteSpace(tempLine))
continue;
if (!tempLine.StartsWith("/get/"))
continue;
var name = Path.GetFileName(tempLine);
if (String.IsNullOrWhiteSpace(name))
continue;
availableLinks.Add(domain + tempLine, HttpUtility.UrlDecode(name));
}
if (availableLinks.Count == 0)
{
ShowError("Not found any links to download.");
return;
}
try
{
Console.WriteLine("Found " + availableLinks.Count + " files for downloading:");
Console.WriteLine();
var wc = new WebClient();
foreach (var link in availableLinks)
{
Console.Write(" Starting downloading: '" + link.Value + "'... ");
// not use async for special reasons
wc.DownloadFile(link.Key, link.Value);
Console.WriteLine(" Completed!");
}
}
catch (Exception ex)
{
Console.WriteLine("Exception occured during download. Review StackTrace below:");
ShowError(ex.ToString());
return;
}
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("All downloads completed... Press Enter for exit.");
Console.ResetColor();
Console.ReadLine();
}
private static void ShowError(string message)
{
if (String.IsNullOrWhiteSpace(message))
return;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(message);
Console.ResetColor();
}
}
}