-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHostsHelper.cs
More file actions
57 lines (55 loc) · 1.66 KB
/
Copy pathHostsHelper.cs
File metadata and controls
57 lines (55 loc) · 1.66 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
namespace VisualParadigmKeygen
{
class HostsHelper
{
private readonly string hostsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), @"drivers\etc\hosts");
readonly string[] txt =
{
"# Added by VisualParadigmKeygen",
"0.0.0.0 cs.visual-paradigm.com",
"0.0.0.0 license.visual-paradigm.com",
"0.0.0.0 visual-paradigm.com",
"# End"
};
public bool AddToHosts()
{
try
{
string hostsContent = File.ReadAllText(hostsPath);
bool already = hostsContent.Contains(txt[1]);
if (!already)
{
using StreamWriter streamWriter = File.AppendText(hostsPath);
foreach (string line in txt)
{
streamWriter.WriteLine(line);
}
}
return true;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
}
public bool RemoveFromHosts()
{
try
{
var lines = File.ReadAllLines(hostsPath).ToList();
foreach (string txts in txt)
{
lines.RemoveAll(line => line.Trim() == txts);
}
File.WriteAllLines(hostsPath, lines);
return true;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
}
}
}