From 652fba9b4400096d8bc42bf63b262f6d90e97d8f Mon Sep 17 00:00:00 2001
From: Allen Wolf <63997543+aaw3@users.noreply.github.com>
Date: Wed, 10 Jan 2024 00:43:27 -0600
Subject: [PATCH] Add project
---
src/Form1.Designer.cs | 132 ++++++++++++++++++++++++++++++
src/Form1.cs | 150 ++++++++++++++++++++++++++++++++++
src/Form1.resx | 60 ++++++++++++++
src/Program.cs | 23 ++++++
src/SambaFileDetection.csproj | 9 ++
src/SambaFileDetection.sln | 25 ++++++
6 files changed, 399 insertions(+)
create mode 100755 src/Form1.Designer.cs
create mode 100755 src/Form1.cs
create mode 100755 src/Form1.resx
create mode 100755 src/Program.cs
create mode 100755 src/SambaFileDetection.csproj
create mode 100755 src/SambaFileDetection.sln
diff --git a/src/Form1.Designer.cs b/src/Form1.Designer.cs
new file mode 100755
index 0000000..cf2344e
--- /dev/null
+++ b/src/Form1.Designer.cs
@@ -0,0 +1,132 @@
+
+namespace SambaFileDetection
+{
+ partial class Form1
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.components = new System.ComponentModel.Container();
+ this.drivesTxt = new System.Windows.Forms.TextBox();
+ this.label1 = new System.Windows.Forms.Label();
+ this.drivesChangeApplyBtn = new System.Windows.Forms.Button();
+ this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
+ this.contextMenuStrip2 = new System.Windows.Forms.ContextMenuStrip(this.components);
+ this.MuteCB = new System.Windows.Forms.CheckBox();
+ this.LoggerTxt = new System.Windows.Forms.RichTextBox();
+ this.SuspendLayout();
+ //
+ // drivesTxt
+ //
+ this.drivesTxt.Location = new System.Drawing.Point(12, 41);
+ this.drivesTxt.Name = "drivesTxt";
+ this.drivesTxt.Size = new System.Drawing.Size(100, 23);
+ this.drivesTxt.TabIndex = 0;
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(12, 23);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(98, 15);
+ this.label1.TabIndex = 100;
+ this.label1.Text = "CSV List of Drives";
+ //
+ // drivesChangeApplyBtn
+ //
+ this.drivesChangeApplyBtn.Location = new System.Drawing.Point(118, 40);
+ this.drivesChangeApplyBtn.Name = "drivesChangeApplyBtn";
+ this.drivesChangeApplyBtn.Size = new System.Drawing.Size(75, 23);
+ this.drivesChangeApplyBtn.TabIndex = 1;
+ this.drivesChangeApplyBtn.Text = "Apply";
+ this.drivesChangeApplyBtn.UseVisualStyleBackColor = true;
+ this.drivesChangeApplyBtn.Click += new System.EventHandler(this.drivesChangeApplyBtn_Click);
+ //
+ // contextMenuStrip1
+ //
+ this.contextMenuStrip1.Name = "contextMenuStrip1";
+ this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4);
+ //
+ // contextMenuStrip2
+ //
+ this.contextMenuStrip2.Name = "contextMenuStrip2";
+ this.contextMenuStrip2.Size = new System.Drawing.Size(61, 4);
+ //
+ // MuteCB
+ //
+ this.MuteCB.AutoSize = true;
+ this.MuteCB.Location = new System.Drawing.Point(212, 43);
+ this.MuteCB.Name = "MuteCB";
+ this.MuteCB.Size = new System.Drawing.Size(54, 19);
+ this.MuteCB.TabIndex = 2;
+ this.MuteCB.Text = "Mute";
+ this.MuteCB.UseVisualStyleBackColor = true;
+ //
+ // LoggerTxt
+ //
+ this.LoggerTxt.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.LoggerTxt.BackColor = System.Drawing.Color.White;
+ this.LoggerTxt.Location = new System.Drawing.Point(12, 70);
+ this.LoggerTxt.Name = "LoggerTxt";
+ this.LoggerTxt.ReadOnly = true;
+ this.LoggerTxt.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.ForcedVertical;
+ this.LoggerTxt.Size = new System.Drawing.Size(776, 368);
+ this.LoggerTxt.TabIndex = 3;
+ this.LoggerTxt.Text = "Debugger:";
+ this.LoggerTxt.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.LoggerTxt_LinkClicked);
+ //
+ // Form1
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.LoggerTxt);
+ this.Controls.Add(this.MuteCB);
+ this.Controls.Add(this.drivesChangeApplyBtn);
+ this.Controls.Add(this.label1);
+ this.Controls.Add(this.drivesTxt);
+ this.Name = "Form1";
+ this.Text = "SambaFileDetection";
+ this.Load += new System.EventHandler(this.Form1_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.TextBox drivesTxt;
+ private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.Button drivesChangeApplyBtn;
+ private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
+ private System.Windows.Forms.ContextMenuStrip contextMenuStrip2;
+ private System.Windows.Forms.CheckBox MuteCB;
+ private System.Windows.Forms.RichTextBox LoggerTxt;
+ }
+}
+
diff --git a/src/Form1.cs b/src/Form1.cs
new file mode 100755
index 0000000..321c8bd
--- /dev/null
+++ b/src/Form1.cs
@@ -0,0 +1,150 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Diagnostics;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace SambaFileDetection
+{
+ public partial class Form1 : Form
+ {
+ [DllImport("user32.dll")]
+ static extern bool FlashWindow(IntPtr hwnd, bool FlashStatus);
+
+ public Form1()
+ {
+ InitializeComponent();
+ }
+
+ private void Form1_Load(object sender, EventArgs e)
+ {
+ this.FormClosing += (s, eargs) => DrivesFSW.ForEach(d => d.Dispose());
+ }
+
+ void watcher_Error(object sender, ErrorEventArgs e)
+ {
+ Debug.WriteLine("error : " + e.GetException().Message);
+
+ Log($"Error: {e.GetException().Message}");
+ }
+
+ void watcher_Renamed(object sender, RenamedEventArgs e)
+ {
+ Debug.WriteLine($"rename success: {e.OldFullPath} {e.OldName} : {e.FullPath} : {e.Name}");
+ Log($"Rename: {e.OldFullPath} -> \"file:\\\\{e.FullPath}\"");
+ }
+
+ void watcher_Changed(object sender, FileSystemEventArgs e)
+ {
+ Debug.WriteLine($"change success: {e.FullPath} : {e.ChangeType} : {e.Name}");
+
+ Log($"Change: \"file:\\\\{e.FullPath}\" | {e.ChangeType}");
+ }
+
+ System.Media.SoundPlayer receiveFile = new System.Media.SoundPlayer(@"C:\Windows\Media\Windows Unlock.wav");
+ public void Log(string log)
+ {
+ this.Invoke((MethodInvoker) delegate
+ {
+ LoggerTxt.Text += "\r\n" + DateTime.Now.ToString("dd/MM/yy - HH:mm:ss") + " --- " + log;
+ LoggerTxt.SelectionStart = LoggerTxt.Text.Length;
+ LoggerTxt.ScrollToCaret();
+ });
+
+ if (!MuteCB.Checked)
+ {
+ receiveFile.Play();
+ }
+
+ this.Invoke((MethodInvoker) delegate { FlashWindow(this.Handle, true); });
+ }
+
+
+
+
+ public void BalloonClosed(object sender, EventArgs e)
+ {
+ Debug.WriteLine("Balloon Closed");
+ DisposeNotification((NotifyIcon)sender);
+ }
+
+ public void DisposeNotification(NotifyIcon ni)
+ {
+ FileNotifications.Remove(ni);
+ FileDict.Remove(ni);
+ ni.Dispose();
+
+ }
+
+ public void BalloonTipClicked(object sender, EventArgs e)
+ {
+ MessageBox.Show("explorer.exe", $"/select,\"\"{FileDict[(NotifyIcon)sender]}\"\"");
+ Process.Start("explorer.exe", $"/select,\"{FileDict[(NotifyIcon)sender]}\"");
+ }
+
+ List DrivesFSW = new List();
+ string[] drivePaths;
+
+ List FileNotifications = new List();
+
+ Dictionary FileDict = new Dictionary();
+
+ private void drivesChangeApplyBtn_Click(object sender, EventArgs e)
+ {
+ UnregisterWatchers();
+
+ drivePaths = drivesTxt.Text.Split(",");
+
+ RegisterNewWatchers(drivePaths);
+ }
+
+ public void RegisterNewWatchers(string[] drivePaths)
+ {
+ foreach (var drive in drivePaths)
+ {
+ FileSystemWatcher watcher = new FileSystemWatcher();
+ watcher.IncludeSubdirectories = true;
+ watcher.Path = drive;
+
+ watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;
+
+ watcher.Changed += watcher_Changed;
+ watcher.Created += watcher_Changed;
+ watcher.Deleted += watcher_Changed;
+ watcher.Renamed += watcher_Renamed;
+ watcher.Error += watcher_Error;
+
+ watcher.EnableRaisingEvents = true;
+ DrivesFSW.Add(watcher);
+ }
+ }
+
+ public void UnregisterWatchers()
+ {
+ Debug.WriteLine("Drives: " + DrivesFSW.Count);
+ foreach (var drive in DrivesFSW.ToList())
+ {
+ drive.Dispose();
+ DrivesFSW.Remove(drive);
+ }
+ Debug.WriteLine("Drives: " + DrivesFSW.Count);
+ }
+
+ private void LoggerTxt_LinkClicked(object sender, LinkClickedEventArgs e)
+ {
+ OpenInExplorer(e.LinkText);
+ }
+
+ public void OpenInExplorer(string link)
+ {
+ Process.Start("explorer.exe", $"/select,\"{link}\"");
+ }
+ }
+}
diff --git a/src/Form1.resx b/src/Form1.resx
new file mode 100755
index 0000000..b5ae26c
--- /dev/null
+++ b/src/Form1.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/src/Program.cs b/src/Program.cs
new file mode 100755
index 0000000..c2b9201
--- /dev/null
+++ b/src/Program.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace SambaFileDetection
+{
+ static class Program
+ {
+ ///
+ /// The main entry point for the application.
+ ///
+ [STAThread]
+ static void Main()
+ {
+ Application.SetHighDpiMode(HighDpiMode.SystemAware);
+ Application.EnableVisualStyles();
+ Application.SetCompatibleTextRenderingDefault(false);
+ Application.Run(new Form1());
+ }
+ }
+}
diff --git a/src/SambaFileDetection.csproj b/src/SambaFileDetection.csproj
new file mode 100755
index 0000000..7b05c62
--- /dev/null
+++ b/src/SambaFileDetection.csproj
@@ -0,0 +1,9 @@
+
+
+
+ WinExe
+ netcoreapp3.1
+ true
+
+
+
\ No newline at end of file
diff --git a/src/SambaFileDetection.sln b/src/SambaFileDetection.sln
new file mode 100755
index 0000000..dc44ba3
--- /dev/null
+++ b/src/SambaFileDetection.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.31112.23
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SambaFileDetection", "SambaFileDetection.csproj", "{F2FF6564-9F61-4FB6-985B-DE9F002113AB}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {F2FF6564-9F61-4FB6-985B-DE9F002113AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F2FF6564-9F61-4FB6-985B-DE9F002113AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F2FF6564-9F61-4FB6-985B-DE9F002113AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F2FF6564-9F61-4FB6-985B-DE9F002113AB}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {E504D1C4-3947-4A0D-8DAD-F0C3570BEF8D}
+ EndGlobalSection
+EndGlobal