forked from tejashwikalptaru/csharp-clamAV-antivirus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exclusion.cs
132 lines (125 loc) · 3.95 KB
/
Exclusion.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TejashPlayer;
using System.IO;
using System.Text.RegularExpressions;
namespace AntiVirus_Project
{
class Exclusion
{
private IniFile ini = null;
private string loc = string.Empty;
public List<string> exclusions = new List<string>();
public Exclusion()
{
loc = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
loc = loc + "\\NetSky\\";
if (Directory.Exists(loc))
{
loc = loc + "NetSky_Exclusion.db";
if (File.Exists(loc))
{
ini = new IniFile(loc);
string t = ini.IniReadValue("Total_Exclusion", "Value");
if (t.Trim().Length > 0)
{
int total = Convert.ToInt32(t);
for (int i = 1; i <= total; i++)
{
string h = ini.IniReadValue("Exclusion", i.ToString());
if (h.Trim().Length > 0)
{
if(Directory.Exists(h))
exclusions.Add(h);
if (File.Exists(h))
exclusions.Add(h);
}
}
}
}
else
{
File.Create(loc);
}
}
else
{
Directory.CreateDirectory(loc);
File.Create(loc + "Netsky_Exclusion.db");
loc = loc + "Netsky_Exclusion.db";
}
}
public bool isExclusion(string path)
{
if (exclusions != null)
{
foreach (string ex in exclusions)
{
if (path.Contains(ex))
return true;
}
return false;
}
else return false;
}
public void AddExclusion(string path)
{
IniFile ins = new IniFile(loc);
int index = 0;
string t = string.Empty;
try
{
t = ins.IniReadValue("Total_Exclusion", "Value");
}
catch { }
if (t.Trim().Length > 0)
{
index = Convert.ToInt32(t);
index++;
}
else
index++;
exclusions.Add(path);
ins.IniWriteValue("Exclusion", index.ToString(), path);
ins.IniWriteValue("Total_Exclusion", "Value", index.ToString());
}
public void DelExclusion(string path)
{
IniFile ins = new IniFile(loc);
string t = string.Empty;
int total = 0;
try
{
t = ins.IniReadValue("Total_Exclusion", "Value");
}
catch { }
if (t.Trim().Length > 0)
{
total = Convert.ToInt32(t);
for(int i=1;i<=total;i++)
{
t = ins.IniReadValue("Exclusion", i.ToString());
if(t==path)
{
ins.IniWriteValue("Exclusion", i.ToString(), path + "netsky.removed.exclusion");
exclusions.Remove(path);
}
}
}
}
public void ClearExclusion()
{
if (File.Exists(loc))
{
try
{
File.Delete(loc);
exclusions = null;
}
catch { }
}
}
}
}