-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
114 lines (107 loc) · 4.72 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using NLog;
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
namespace DonationDowloader
{
class Program
{
private static Logger logger = LogManager.GetCurrentClassLogger();
static void Main(string[] args)
{
try
{
while (true)
{
bool failedToRead = false;
bool failedToWrite = false;
bool failedToReadCurrent = false;
string[] config = File.ReadAllLines(@"config.txt");
string inPath = config?[0];
if (File.Exists(inPath))
{
string[] lines = new string[0];
try
{
lines = File.ReadAllLines(inPath);
failedToRead = false;
logger.Info(DateTime.Now + " New File Received");
Console.WriteLine(DateTime.Now + " New File Received");
}
catch
{
failedToRead = true;
logger.Error(DateTime.Now + " Failed to Read");
Console.WriteLine(DateTime.Now + " Failed to Read");
}
foreach (var line in lines)
{
if (line.Contains("https://cravatar.eu/helmavatar/"))
{
string rx = @"helmavatar/(?<name>.*)/([0-9])";
var newNames = Regex.Matches(line, rx)
.OfType<Match>()
.Select(m => m.Groups["name"].Value)
.ToArray();
string outPath = @"c:\out\capes.txt";
if (!File.Exists(outPath))
{
File.CreateText(outPath);
}
string[] currentNames = new string[0];
try
{
currentNames = File.ReadAllLines(outPath);
failedToReadCurrent = false;
}
catch
{
failedToReadCurrent = true;
logger.Error(DateTime.Now + " Failed to Read Current");
Console.WriteLine(DateTime.Now + " Failed to Read Current");
}
foreach (var currentName in currentNames)
{
newNames = newNames.Where(o => o != currentName.Split(':')[0]).ToArray();
}
try
{
using (StreamWriter sw = File.AppendText(outPath))
{
foreach (var newName in newNames)
{
sw.WriteLine(newName + ":capedonor");
logger.Info(DateTime.Now + " Added " + newName);
Console.WriteLine(DateTime.Now + " Added " + newName);
}
}
failedToWrite = false;
}
catch
{
failedToWrite = true;
logger.Error(DateTime.Now + " Failed to Write");
Console.WriteLine(DateTime.Now + " Failed to Write");
}
}
}
try
{
if (!failedToRead && !failedToWrite && !failedToReadCurrent)
File.Delete(inPath);
}
catch { }
}
Thread.Sleep(30000);
}
}
finally
{
Console.Write("Press Enter to close window ...");
Console.Read();
}
}
}
}