Skip to content

Commit

Permalink
search in specified folder only
Browse files Browse the repository at this point in the history
  • Loading branch information
vigi86 committed May 26, 2023
1 parent 97be84a commit 4cc125d
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 73 deletions.
18 changes: 18 additions & 0 deletions src/DLP_Win/DLP_Win/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="DLP_Win.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<DLP_Win.Properties.Settings>
<setting name="AHV_NR" serializeAs="String">
<value>.*756\.\d{4}\.\d{4}\.\d{2}.*</value>
</setting>
<setting name="CUSTOMER_NR" serializeAs="String">
<value>\d{2}\.\d{5}-\d</value>
</setting>
</DLP_Win.Properties.Settings>
</applicationSettings>
</configuration>
2 changes: 1 addition & 1 deletion src/DLP_Win/DLP_Win/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private static void Main()
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmMain());
Application.Run(new FrmMain());
}
}
}
2 changes: 1 addition & 1 deletion src/DLP_Win/DLP_Win/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 28 additions & 17 deletions src/DLP_Win/DLP_Win/ScanEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class ScanEngine
private static CancellationTokenSource _scannerCancellationTokenSource;
private static CancellationTokenSource _monitorCancellationTokenSource;
private static readonly Form _form;
private static string QUARANTINE_FOLDER = $"{Application.StartupPath}\\QUARANTINE";
private static string QUARANTINE_FOLDER;// = $"{Application.StartupPath}\\QUARANTINE";

public static async Task Monitor()
{
Expand All @@ -35,13 +35,13 @@ await Task.Run(() =>
// Nach Dateierweiterung suchen
//foreach (string extension in extensions)
//{
// SearchFiles(frmMain, drive.RootDirectory, extension, rulesets);
// SearchFiles(FrmMain, drive.RootDirectory, extension, rulesets);

// // Überprüfung, ob der Task abgebrochen werden soll
// CheckCancelledTask();
//}
string compareName = "BK-Soft\\Work1";
using (FileSystemWatcher watcher = new FileSystemWatcher(drive.RootDirectory.FullName, "*.txt"))
using (FileSystemWatcher watcher = new(drive.RootDirectory.FullName, "*.txt"))
{
watcher.NotifyFilter = NotifyFilters.LastAccess
| NotifyFilters.LastWrite
Expand Down Expand Up @@ -105,9 +105,10 @@ private static void OnRenamed(object source, RenamedEventArgs e, string compareN
/// </summary>
/// <param name="rulesets">Liste mit </param>
/// <returns></returns>
public static async Task Scan(frmMain frmMain, List<Ruleset> rulesets, List<string> extensions)
public static async Task Scan(FrmMain frmMain, List<Ruleset> rulesets, List<string> extensions, string searchfolder, string quarantinefolder)
{
_scannerCancellationTokenSource = new CancellationTokenSource();
QUARANTINE_FOLDER = quarantinefolder;

if (frmMain.ScanButton.Text == "System Scan")
{
Expand All @@ -122,19 +123,29 @@ await Task.Run(() =>
try
{
// Alle Laufwerke durchsuchen
foreach (DriveInfo drive in DriveInfo.GetDrives())
//foreach (DriveInfo drive in DriveInfo.GetDrives())
//{
// if (drive.IsReady)
// {
// // Nach Dateierweiterung suchen
// foreach (string extension in extensions)
// {
// // Überprüfung, ob der Task abgebrochen werden soll
// CheckCancelledScannerTask();

// SearchFiles(frmMain, drive.RootDirectory, extension, rulesets);
// }
// }
//}

// Nach Dateierweiterung suchen
foreach (string extension in extensions)
{
if (drive.IsReady)
{
// Nach Dateierweiterung suchen
foreach (string extension in extensions)
{
// Überprüfung, ob der Task abgebrochen werden soll
CheckCancelledScannerTask();
// Überprüfung, ob der Task abgebrochen werden soll
CheckCancelledScannerTask();
DirectoryInfo directory = new(searchfolder);

SearchFiles(frmMain, drive.RootDirectory, extension, rulesets);
}
}
SearchFiles(frmMain, directory, extension, rulesets);
}
}

Expand Down Expand Up @@ -196,7 +207,7 @@ private static void CheckCancelledMonitorTask()

}

private static void SearchFiles(frmMain frmMain, DirectoryInfo directory, string fileExtension, List<Ruleset> rulesets)// TextBox loggerBox, ToolStripStatusLabel toolStripStatusLabel)
private static void SearchFiles(FrmMain frmMain, DirectoryInfo directory, string fileExtension, List<Ruleset> rulesets)// TextBox loggerBox, ToolStripStatusLabel toolStripStatusLabel)
{

// Überspringe Quarantäne-Ordner
Expand Down Expand Up @@ -398,7 +409,7 @@ private static bool CompareAuthorToName(string filePath, string compareName)
if (File.Exists(filePath))
{
// Read the author metadata using FileInfo and GetAccessControl method
FileInfo fileInfo = new FileInfo(filePath);
FileInfo fileInfo = new(filePath);
FileSecurity fileSecurity = fileInfo.GetAccessControl();
IdentityReference author = fileSecurity.GetOwner(typeof(NTAccount));

Expand Down
34 changes: 17 additions & 17 deletions src/DLP_Win/DLP_Win/frmMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4cc125d

Please sign in to comment.