From fe529af769273df462045e486a4434c71a45ce6e Mon Sep 17 00:00:00 2001 From: Syntriax Date: Mon, 1 Aug 2022 15:26:09 +0300 Subject: [PATCH] Init --- CodeSigner.csproj | 10 ++++++++++ Program.cs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 CodeSigner.csproj create mode 100644 Program.cs diff --git a/CodeSigner.csproj b/CodeSigner.csproj new file mode 100644 index 0000000..74abf5c --- /dev/null +++ b/CodeSigner.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..b9092e6 --- /dev/null +++ b/Program.cs @@ -0,0 +1,44 @@ +const string AuthorName = "Syntriax"; +const string AuthorEmail = "Syntriax@gmail.com"; + +const string FileSearchPattern = "*.cs"; +const string ProgramSignature = $"Signed by an automated program written by Syntriax"; +const string CreationDateTag = ""; +const string Signature = +$@"/* + Author: {AuthorName} + Email: {AuthorEmail} + Creation Date: {CreationDateTag} UTC + {ProgramSignature} +*/ +"; + +void ExploreDirectory(string path) +{ + string[] files = Directory.GetFiles(path, FileSearchPattern); + string[] directories = Directory.GetDirectories(path); + + foreach (string filePath in files) + Sign(filePath); + + foreach (string directoryPath in directories) + ExploreDirectory(directoryPath); +} + +void Sign(string filePath) +{ + string[] lines = File.ReadAllLines(filePath); + + foreach (string line in lines) + if (line.Contains(ProgramSignature)) + return; + + Console.WriteLine($"Signing -> {filePath}"); + DateTime dateTime = File.GetCreationTimeUtc(filePath); + string newContents = Signature.Replace(CreationDateTag, $"{dateTime.ToLongDateString()} - {dateTime.ToLongTimeString()}"); + newContents += File.ReadAllText(filePath); + File.WriteAllText(filePath, newContents); +} + +ExploreDirectory(Environment.GetCommandLineArgs()[1]); +Console.ReadKey();