diff --git a/src/DLP_Win/DLP_Win/App.config b/src/DLP_Win/DLP_Win/App.config
new file mode 100644
index 0000000..87591cb
--- /dev/null
+++ b/src/DLP_Win/DLP_Win/App.config
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+ .*756\.\d{4}\.\d{4}\.\d{2}.*
+
+
+ \d{2}\.\d{5}-\d
+
+
+
+
\ No newline at end of file
diff --git a/src/DLP_Win/DLP_Win/Program.cs b/src/DLP_Win/DLP_Win/Program.cs
index 7156e06..f0c591e 100644
--- a/src/DLP_Win/DLP_Win/Program.cs
+++ b/src/DLP_Win/DLP_Win/Program.cs
@@ -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());
}
}
}
diff --git a/src/DLP_Win/DLP_Win/Properties/Settings.Designer.cs b/src/DLP_Win/DLP_Win/Properties/Settings.Designer.cs
index 959dc03..791f8ac 100644
--- a/src/DLP_Win/DLP_Win/Properties/Settings.Designer.cs
+++ b/src/DLP_Win/DLP_Win/Properties/Settings.Designer.cs
@@ -12,7 +12,7 @@ namespace DLP_Win.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.6.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
diff --git a/src/DLP_Win/DLP_Win/ScanEngine.cs b/src/DLP_Win/DLP_Win/ScanEngine.cs
index 90ecad7..e2b5667 100644
--- a/src/DLP_Win/DLP_Win/ScanEngine.cs
+++ b/src/DLP_Win/DLP_Win/ScanEngine.cs
@@ -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()
{
@@ -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
@@ -105,9 +105,10 @@ private static void OnRenamed(object source, RenamedEventArgs e, string compareN
///
/// Liste mit
///
- public static async Task Scan(frmMain frmMain, List rulesets, List extensions)
+ public static async Task Scan(FrmMain frmMain, List rulesets, List extensions, string searchfolder, string quarantinefolder)
{
_scannerCancellationTokenSource = new CancellationTokenSource();
+ QUARANTINE_FOLDER = quarantinefolder;
if (frmMain.ScanButton.Text == "System Scan")
{
@@ -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);
}
}
@@ -196,7 +207,7 @@ private static void CheckCancelledMonitorTask()
}
- private static void SearchFiles(frmMain frmMain, DirectoryInfo directory, string fileExtension, List rulesets)// TextBox loggerBox, ToolStripStatusLabel toolStripStatusLabel)
+ private static void SearchFiles(FrmMain frmMain, DirectoryInfo directory, string fileExtension, List rulesets)// TextBox loggerBox, ToolStripStatusLabel toolStripStatusLabel)
{
// Überspringe Quarantäne-Ordner
@@ -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));
diff --git a/src/DLP_Win/DLP_Win/frmMain.Designer.cs b/src/DLP_Win/DLP_Win/frmMain.Designer.cs
index 6207ae9..ef5db47 100644
--- a/src/DLP_Win/DLP_Win/frmMain.Designer.cs
+++ b/src/DLP_Win/DLP_Win/frmMain.Designer.cs
@@ -1,7 +1,7 @@
namespace DLP_Win
{
- partial class frmMain
+ partial class FrmMain
{
///
/// Required designer variable.
@@ -95,7 +95,7 @@ private void InitializeComponent()
cmdScan.TabIndex = 0;
cmdScan.Text = "System Scan";
cmdScan.UseVisualStyleBackColor = false;
- cmdScan.Click += cmdScan_Click;
+ cmdScan.Click += CmdScan_Click;
//
// dataGridView1
//
@@ -110,10 +110,10 @@ private void InitializeComponent()
dataGridView1.RowTemplate.Height = 25;
dataGridView1.Size = new System.Drawing.Size(786, 335);
dataGridView1.TabIndex = 1;
- dataGridView1.CellBeginEdit += dataGridView1_CellBeginEdit;
- dataGridView1.CellValidating += dataGridView1_CellValidating;
- dataGridView1.DataError += dataGridView1_DataError;
- dataGridView1.SortCompare += dataGridView1_SortCompare;
+ dataGridView1.CellBeginEdit += DataGridView1_CellBeginEdit;
+ dataGridView1.CellValidating += DataGridView1_CellValidating;
+ dataGridView1.DataError += DataGridView1_DataError;
+ dataGridView1.SortCompare += DataGridView1_SortCompare;
//
// colIndex
//
@@ -179,7 +179,7 @@ private void InitializeComponent()
rulesetOpenToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O;
rulesetOpenToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
rulesetOpenToolStripMenuItem.Text = "Ruleset Ö&ffnen";
- rulesetOpenToolStripMenuItem.Click += rulesetOpenToolStripMenuItem_Click;
+ rulesetOpenToolStripMenuItem.Click += RulesetOpenToolStripMenuItem_Click;
//
// rulesetSaveToolStripMenuItem
//
@@ -187,7 +187,7 @@ private void InitializeComponent()
rulesetSaveToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S;
rulesetSaveToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
rulesetSaveToolStripMenuItem.Text = "Ruleset &Speichern";
- rulesetSaveToolStripMenuItem.Click += rulesetSaveToolStripMenuItem_Click;
+ rulesetSaveToolStripMenuItem.Click += RulesetSaveToolStripMenuItem_Click;
//
// toolStripSeparator1
//
@@ -200,7 +200,7 @@ private void InitializeComponent()
toolStripMenuItemExit.ShortcutKeys = System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.F4;
toolStripMenuItemExit.Size = new System.Drawing.Size(209, 22);
toolStripMenuItemExit.Text = "B&eenden";
- toolStripMenuItemExit.Click += toolStripMenuItemExit_Click;
+ toolStripMenuItemExit.Click += ToolStripMenuItemExit_Click;
//
// extrasToolStripMenuItem
//
@@ -214,7 +214,7 @@ private void InitializeComponent()
settingsToolStripMenuItem.Name = "settingsToolStripMenuItem";
settingsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
settingsToolStripMenuItem.Text = "&Optionen";
- settingsToolStripMenuItem.Click += settingsToolStripMenuItem_Click;
+ settingsToolStripMenuItem.Click += SettingsToolStripMenuItem_Click;
//
// stsMain
//
@@ -286,7 +286,7 @@ private void InitializeComponent()
openRulesetDialog.FileName = "ruleset.json";
openRulesetDialog.Filter = "JSON-Datei (*.json)|*.json";
openRulesetDialog.Title = "Ruleset öffnen";
- openRulesetDialog.FileOk += openRulesetDialog_FileOk;
+ openRulesetDialog.FileOk += OpenRulesetDialog_FileOk;
//
// saveRulesetDialog
//
@@ -294,9 +294,9 @@ private void InitializeComponent()
saveRulesetDialog.FileName = "ruleset.json";
saveRulesetDialog.Filter = "JSON-Date (*.json)|*.json";
saveRulesetDialog.Title = "Ruleset speichern";
- saveRulesetDialog.FileOk += saveRulesetDialog_FileOk;
+ saveRulesetDialog.FileOk += SaveRulesetDialog_FileOk;
//
- // frmMain
+ // FrmMain
//
AllowDrop = true;
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@@ -305,11 +305,11 @@ private void InitializeComponent()
Controls.Add(tabControl1);
Controls.Add(stsMain);
Controls.Add(mnuMain);
- Name = "frmMain";
+ Name = "FrmMain";
Text = "DLP Rule Mgmt";
- FormClosing += frmMain_FormClosing;
- Load += frmMain_Load;
- DragDrop += frmMain_DragDrop;
+ FormClosing += FrmMain_FormClosing;
+ Load += FrmMain_Load;
+ DragDrop += FrmMain_DragDrop;
pnlMain.ResumeLayout(false);
panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
diff --git a/src/DLP_Win/DLP_Win/frmMain.cs b/src/DLP_Win/DLP_Win/frmMain.cs
index 30ef81b..c8a3a22 100644
--- a/src/DLP_Win/DLP_Win/frmMain.cs
+++ b/src/DLP_Win/DLP_Win/frmMain.cs
@@ -7,7 +7,7 @@
namespace DLP_Win
{
- public partial class frmMain : Form
+ public partial class FrmMain : Form
{
private List rulesets;
private string originalCellValue;
@@ -16,7 +16,9 @@ public partial class frmMain : Form
//private readonly string CUSTOMER_NR = Properties.Settings.Default.CUSTOMER_NR; // @"\d{2}\.\d{5}-\d";
private readonly List EXTENSIONS;
- private frmSettings frmSettings;
+ private readonly string SEARCHFOLDER;
+ private readonly string QUARANTINEFOLDER;
+ private readonly FrmSettings frmSettings;
public Form Self => this;
@@ -40,13 +42,15 @@ public Button ScanButton
///
/// Konstruktor.
///
- public frmMain()
+ public FrmMain()
{
InitializeComponent();
- frmSettings = new frmSettings();
+ frmSettings = new FrmSettings();
EXTENSIONS = frmSettings.Extensions;
+ SEARCHFOLDER = frmSettings.Searchfolder;
+ QUARANTINEFOLDER = frmSettings.Quarantinefolder;
dataGridView1.DataSource = rulesets;
string rulesetPath = Path.Combine(Application.StartupPath, "lof");
@@ -69,7 +73,7 @@ public frmMain()
if (File.Exists(path))
{
openRulesetDialog.FileName = path;
- openRulesetDialog_FileOk(this, new CancelEventArgs());
+ OpenRulesetDialog_FileOk(this, new CancelEventArgs());
}
}
else
@@ -78,7 +82,7 @@ public frmMain()
openRulesetDialog.InitialDirectory = Application.StartupPath;
saveRulesetDialog.InitialDirectory = Application.StartupPath;
}
- dataGridView1.CellValueChanged += dataGridView1_CellValueChanged;
+ dataGridView1.CellValueChanged += DataGridView1_CellValueChanged;
//Toast t = new Toast();
}
@@ -87,7 +91,7 @@ public frmMain()
///
///
///
- private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
+ private void DataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
try
{
@@ -100,7 +104,7 @@ private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEvent
}
catch (Exception ex)
{
- txtLogger.Text += $"{Environment.NewLine}{ex}";
+ txtLogger.Text += $"{Environment.NewLine}{ex}{Environment.NewLine}";
}
}
@@ -109,7 +113,7 @@ private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEvent
///
///
///
- private void dataGridView1_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
+ private void DataGridView1_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
if (e.Column.Name == "colIndex") // nur für die Spalte "Index"
{
@@ -130,7 +134,7 @@ private void dataGridView1_SortCompare(object sender, DataGridViewSortCompareEve
///
///
///
- private void toolStripMenuItemExit_Click(object sender, EventArgs e)
+ private void ToolStripMenuItemExit_Click(object sender, EventArgs e)
{
Close();
}
@@ -140,7 +144,7 @@ private void toolStripMenuItemExit_Click(object sender, EventArgs e)
///
///
///
- private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
+ private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (datagridChanged)
{
@@ -148,7 +152,7 @@ private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
if (result == DialogResult.Yes)
{
- saveRulesetDialog_FileOk(sender, new System.ComponentModel.CancelEventArgs());
+ SaveRulesetDialog_FileOk(sender, new System.ComponentModel.CancelEventArgs());
}
else if (result == DialogResult.Cancel)
{
@@ -162,7 +166,7 @@ private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
///
///
///
- private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
+ private void DataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
//Überprüft spezifisch die Spalte "Index" auf eine Zahl grösser 0.
if (dataGridView1.Columns[e.ColumnIndex].Name == "colIndex")
@@ -211,7 +215,7 @@ private void dataGridView1_CellValidating(object sender, DataGridViewCellValidat
///
///
///
- private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
+ private void DataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
originalCellValue = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value?.ToString();
}
@@ -221,7 +225,7 @@ private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEv
///
///
///
- private void openRulesetDialog_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
+ private void OpenRulesetDialog_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
{
string fileName = openRulesetDialog.FileName;
@@ -274,7 +278,7 @@ private void openRulesetDialog_FileOk(object sender, System.ComponentModel.Cance
///
///
///
- private void saveRulesetDialog_FileOk(object sender, CancelEventArgs e)
+ private void SaveRulesetDialog_FileOk(object sender, CancelEventArgs e)
{
string fileName = saveRulesetDialog.FileName;
string filePath = Path.Combine(Application.StartupPath, "lof");
@@ -322,7 +326,7 @@ private void saveRulesetDialog_FileOk(object sender, CancelEventArgs e)
///
///
///
- private void rulesetOpenToolStripMenuItem_Click(object sender, EventArgs e)
+ private void RulesetOpenToolStripMenuItem_Click(object sender, EventArgs e)
{
openRulesetDialog.ShowDialog();
}
@@ -332,39 +336,39 @@ private void rulesetOpenToolStripMenuItem_Click(object sender, EventArgs e)
///
///
///
- private void rulesetSaveToolStripMenuItem_Click(object sender, EventArgs e)
+ private void RulesetSaveToolStripMenuItem_Click(object sender, EventArgs e)
{
saveRulesetDialog.ShowDialog();
}
- private void cmdScan_Click(object sender, EventArgs e)
+ private void CmdScan_Click(object sender, EventArgs e)
{
//TODO: Button Zurücksetzten wenn Scan automatisch endet
- ScanEngine.Scan(this, rulesets, EXTENSIONS); //, txtLogger, toolStripStatusLabel1);
+ ScanEngine.Scan(this, rulesets, EXTENSIONS, SEARCHFOLDER, QUARANTINEFOLDER); //, txtLogger, toolStripStatusLabel1);
}
- private void frmMain_DragDrop(object sender, DragEventArgs e)
+ private void FrmMain_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
openRulesetDialog.FileName = ((string[])e.Data.GetData(DataFormats.FileDrop))[0];
- openRulesetDialog_FileOk(sender, new CancelEventArgs());
+ OpenRulesetDialog_FileOk(sender, new CancelEventArgs());
}
}
- private void frmMain_Load(object sender, EventArgs e)
+ private void FrmMain_Load(object sender, EventArgs e)
{
//ScanEngine.Monitor();
}
- private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
+ private void DataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
Console.WriteLine("Ruleset kann nicht dargestellt werden.");
}
- private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
+ private void SettingsToolStripMenuItem_Click(object sender, EventArgs e)
{
frmSettings.ShowDialog();
}
diff --git a/src/DLP_Win/DLP_Win/frmSettings.Designer.cs b/src/DLP_Win/DLP_Win/frmSettings.Designer.cs
index 49b9eb6..c06eea9 100644
--- a/src/DLP_Win/DLP_Win/frmSettings.Designer.cs
+++ b/src/DLP_Win/DLP_Win/frmSettings.Designer.cs
@@ -1,6 +1,6 @@
namespace DLP_Win
{
- partial class frmSettings
+ partial class FrmSettings
{
///
/// Required designer variable.
@@ -32,27 +32,32 @@ private void InitializeComponent()
lblExtensions = new System.Windows.Forms.Label();
openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
groupBox1 = new System.Windows.Forms.GroupBox();
+ label1 = new System.Windows.Forms.Label();
+ txtQuarantineFolder = new System.Windows.Forms.TextBox();
txtExtensions = new System.Windows.Forms.TextBox();
+ lblSearchOrdner = new System.Windows.Forms.Label();
+ txtSearchFolder = new System.Windows.Forms.TextBox();
groupBox1.SuspendLayout();
SuspendLayout();
//
// cmdSave
//
- cmdSave.Location = new System.Drawing.Point(301, 16);
+ cmdSave.Location = new System.Drawing.Point(140, 182);
cmdSave.Name = "cmdSave";
cmdSave.Size = new System.Drawing.Size(75, 23);
cmdSave.TabIndex = 0;
cmdSave.Text = "OK";
cmdSave.UseVisualStyleBackColor = true;
+ cmdSave.Click += CmdSave_Click;
//
// lblExtensions
//
lblExtensions.AutoSize = true;
lblExtensions.Location = new System.Drawing.Point(6, 19);
lblExtensions.Name = "lblExtensions";
- lblExtensions.Size = new System.Drawing.Size(68, 15);
+ lblExtensions.Size = new System.Drawing.Size(145, 15);
lblExtensions.TabIndex = 1;
- lblExtensions.Text = "Datentypen";
+ lblExtensions.Text = "Datentypen (txt doc docx)";
//
// openFileDialog1
//
@@ -60,34 +65,69 @@ private void InitializeComponent()
//
// groupBox1
//
+ groupBox1.Controls.Add(lblSearchOrdner);
+ groupBox1.Controls.Add(txtSearchFolder);
+ groupBox1.Controls.Add(label1);
+ groupBox1.Controls.Add(txtQuarantineFolder);
groupBox1.Controls.Add(txtExtensions);
groupBox1.Controls.Add(lblExtensions);
groupBox1.Controls.Add(cmdSave);
groupBox1.Dock = System.Windows.Forms.DockStyle.Fill;
groupBox1.Location = new System.Drawing.Point(0, 0);
groupBox1.Name = "groupBox1";
- groupBox1.Size = new System.Drawing.Size(388, 51);
+ groupBox1.Size = new System.Drawing.Size(225, 211);
groupBox1.TabIndex = 2;
groupBox1.TabStop = false;
groupBox1.Text = "Einstellungen";
//
+ // label1
+ //
+ label1.AutoSize = true;
+ label1.Location = new System.Drawing.Point(6, 75);
+ label1.Name = "label1";
+ label1.Size = new System.Drawing.Size(191, 15);
+ label1.TabIndex = 4;
+ label1.Text = "Quarantäne-Ordner (C:\\myfolder\\)";
+ //
+ // txtQuarantineFolder
+ //
+ txtQuarantineFolder.Location = new System.Drawing.Point(6, 93);
+ txtQuarantineFolder.Name = "txtQuarantineFolder";
+ txtQuarantineFolder.Size = new System.Drawing.Size(209, 23);
+ txtQuarantineFolder.TabIndex = 3;
+ //
// txtExtensions
//
- txtExtensions.Location = new System.Drawing.Point(80, 16);
+ txtExtensions.Location = new System.Drawing.Point(6, 37);
txtExtensions.Name = "txtExtensions";
txtExtensions.Size = new System.Drawing.Size(209, 23);
txtExtensions.TabIndex = 2;
- txtExtensions.Text = "txt";
//
- // frmSettings
+ // lblSearchOrdner
+ //
+ lblSearchOrdner.AutoSize = true;
+ lblSearchOrdner.Location = new System.Drawing.Point(6, 129);
+ lblSearchOrdner.Name = "lblSearchOrdner";
+ lblSearchOrdner.Size = new System.Drawing.Size(155, 15);
+ lblSearchOrdner.TabIndex = 6;
+ lblSearchOrdner.Text = "Such-Ordner (C:\\myfolder\\)";
+ //
+ // txtSearchFolder
+ //
+ txtSearchFolder.Location = new System.Drawing.Point(6, 147);
+ txtSearchFolder.Name = "txtSearchFolder";
+ txtSearchFolder.Size = new System.Drawing.Size(209, 23);
+ txtSearchFolder.TabIndex = 5;
+ //
+ // FrmSettings
//
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- ClientSize = new System.Drawing.Size(388, 51);
+ ClientSize = new System.Drawing.Size(225, 211);
Controls.Add(groupBox1);
FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
MaximizeBox = false;
- Name = "frmSettings";
+ Name = "FrmSettings";
Text = "Einstellungen";
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
@@ -101,5 +141,9 @@ private void InitializeComponent()
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox txtExtensions;
+ private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.TextBox txtQuarantineFolder;
+ private System.Windows.Forms.Label lblSearchOrdner;
+ private System.Windows.Forms.TextBox txtSearchFolder;
}
}
\ No newline at end of file
diff --git a/src/DLP_Win/DLP_Win/frmSettings.cs b/src/DLP_Win/DLP_Win/frmSettings.cs
index 6ac2129..a81e67a 100644
--- a/src/DLP_Win/DLP_Win/frmSettings.cs
+++ b/src/DLP_Win/DLP_Win/frmSettings.cs
@@ -7,11 +7,19 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
+using System.IO;
+using System.Text.Json;
+using System.Configuration;
+using GemBox.Document;
namespace DLP_Win
{
- public partial class frmSettings : Form
+
+ public partial class FrmSettings : Form
{
+ private Configuration configuration = new();
+ private string ConfigFile { get; } = "config.json";
+
public List Extensions
{
get
@@ -19,9 +27,67 @@ public List Extensions
return txtExtensions.Text.Split(' ').ToList();
}
}
- public frmSettings()
+ public string Searchfolder
+ {
+ get
+ {
+ return configuration.SearchFolder;
+ }
+ }
+ public string Quarantinefolder
+ {
+ get
+ {
+ return configuration.QuarantineFolder;
+ }
+ }
+
+ public FrmSettings()
{
InitializeComponent();
+ ReadConfigurationFromFile();
+ }
+
+ private void CmdSave_Click(object sender, EventArgs e)
+ {
+ WriteConfiguration();
+ this.Close();
}
+
+ private void WriteConfiguration()
+ {
+ configuration.Extensions = txtExtensions.Text;
+ configuration.QuarantineFolder = txtQuarantineFolder.Text;
+ configuration.SearchFolder = txtSearchFolder.Text;
+
+ string json = JsonSerializer.Serialize(configuration, new JsonSerializerOptions { WriteIndented = true });
+ File.WriteAllText(ConfigFile, json);
+ }
+
+ public void ReadConfigurationFromFile()
+ {
+ if (File.Exists(ConfigFile))
+ {
+ string json = File.ReadAllText(ConfigFile);
+ configuration = JsonSerializer.Deserialize(json);
+
+ txtExtensions.Text = configuration.Extensions;
+ txtQuarantineFolder.Text = configuration.QuarantineFolder;
+ txtSearchFolder.Text = configuration.SearchFolder;
+ }
+ else
+ {
+ txtExtensions.Text = configuration.Extensions = "txt doc docx";
+ txtQuarantineFolder.Text = configuration.QuarantineFolder = $"{Application.StartupPath}QUARANTINE";
+ txtSearchFolder.Text = configuration.SearchFolder = $"{Application.StartupPath}MaliciousFolder";
+ }
+ }
+ }
+
+ public class Configuration
+ {
+ public string Extensions { get; set; }
+ public string QuarantineFolder { get; set; }
+ public string SearchFolder { get; set; }
}
}