Add project

This commit is contained in:
Allen Wolf
2024-01-10 00:43:27 -06:00
parent 33e94d1e5c
commit 652fba9b44
6 changed files with 399 additions and 0 deletions

132
src/Form1.Designer.cs generated Executable file
View File

@ -0,0 +1,132 @@

namespace SambaFileDetection
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

150
src/Form1.cs Executable file
View File

@ -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<FileSystemWatcher> DrivesFSW = new List<FileSystemWatcher>();
string[] drivePaths;
List<NotifyIcon> FileNotifications = new List<NotifyIcon>();
Dictionary<NotifyIcon, string> FileDict = new Dictionary<NotifyIcon, string>();
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}\"");
}
}
}

60
src/Form1.resx Executable file
View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

23
src/Program.cs Executable file
View File

@ -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
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

9
src/SambaFileDetection.csproj Executable file
View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
</Project>

25
src/SambaFileDetection.sln Executable file
View File

@ -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