From d26ef5824f853c29530e855dc386a2707749838d Mon Sep 17 00:00:00 2001 From: adelgado Date: Mon, 25 Apr 2022 14:48:15 -0700 Subject: [PATCH 1/2] Changed to .net6. Fixed bug where whitespace breaks subfolder creation. --- Split-FANUC-Program-Backup/Program.cs | 5 +++-- Split-FANUC-Program-Backup/Split-FANUC-Program-Backup.csproj | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Split-FANUC-Program-Backup/Program.cs b/Split-FANUC-Program-Backup/Program.cs index 60c5d05..645a3b3 100644 --- a/Split-FANUC-Program-Backup/Program.cs +++ b/Split-FANUC-Program-Backup/Program.cs @@ -26,7 +26,7 @@ private static string BuildDate { buildDateTime = new DateTime(2000, 1, 1).AddDays(version.Build).AddSeconds(version.Revision * 2); } - + return buildDateTime.ToString("o"); } } @@ -34,6 +34,7 @@ private static string BuildDate private const string cncProgramFileExtension = ".CNC"; private const string defaultCNCprogramName = "Unknown"; private const char programDelimiter = '%'; + private static readonly char[] subFolderTrim = { ' ', '/' }; private const int minimumProgramSize = 7; /// @@ -150,7 +151,7 @@ private static string GetProgramNameFromHeader(string cncProgramText) } // Strip out the directory flag and slashes to get just the folder name. - subFolder = Regex.Replace(line, directoryFlag, string.Empty).Trim('/'); + subFolder = Regex.Replace(line, directoryFlag, string.Empty).Trim(subFolderTrim); Directory.CreateDirectory(Path.Combine(outputFolder, subFolder)); // Don't append notation to next program diff --git a/Split-FANUC-Program-Backup/Split-FANUC-Program-Backup.csproj b/Split-FANUC-Program-Backup/Split-FANUC-Program-Backup.csproj index 59158e5..0eba4ae 100644 --- a/Split-FANUC-Program-Backup/Split-FANUC-Program-Backup.csproj +++ b/Split-FANUC-Program-Backup/Split-FANUC-Program-Backup.csproj @@ -1,8 +1,8 @@ - + Exe - net5.0-windows + net6.0-windows SplitFANUCProgramBackup False From f68cd3361ef24cf237e0d59f14a48b521fea9b3a Mon Sep 17 00:00:00 2001 From: A9G-Data-Droid <26984068+A9G-Data-Droid@users.noreply.github.com> Date: Tue, 26 Apr 2022 15:02:11 -0700 Subject: [PATCH 2/2] Add explicit access modifiers - Comment on Main --- Split-FANUC-Program-Backup/Program.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Split-FANUC-Program-Backup/Program.cs b/Split-FANUC-Program-Backup/Program.cs index 645a3b3..ab94c06 100644 --- a/Split-FANUC-Program-Backup/Program.cs +++ b/Split-FANUC-Program-Backup/Program.cs @@ -8,7 +8,7 @@ namespace SplitFANUCProgramBackup { - static class Program + public static class Program { private static string ThisExecutableName => AppDomain.CurrentDomain.FriendlyName; private static Version? AssemblyVersion => Assembly.GetExecutingAssembly().GetName().Version; @@ -48,7 +48,12 @@ private static string BuildDate /// private const string directoryFlag = @"(&F=)"; - static async Task Main(string[] args) + /// + /// Command line entry point + /// + /// Requires only one argument: full path to the backup file. + /// Zero for success + public static async Task Main(string[] args) { DisplayHeader(); @@ -132,7 +137,7 @@ private static string GetProgramNameFromHeader(string cncProgramText) /// /// Full path to "ALL-PROG.TXT" /// Each CNC program as a string, and any associated subdirectory - static IEnumerable<(string SubFolder, string ProgramText)> GetCNCProgams(string fileName, string outputFolder) + private static IEnumerable<(string SubFolder, string ProgramText)> GetCNCProgams(string fileName, string outputFolder) { StringBuilder content = new(); string subFolder = ""; @@ -176,7 +181,7 @@ private static string GetProgramNameFromHeader(string cncProgramText) yield return (subFolder, CncProgramText(content)); } - static string CncProgramText(StringBuilder content) + private static string CncProgramText(StringBuilder content) { // Prevent IndexOutOfBounds exceptions if final program is empty if (content.Length > minimumProgramSize) @@ -203,7 +208,7 @@ private static void NotFoundError(string fileName) Console.WriteLine("File not found: " + fileName); } - static void DisplayHelp() + private static void DisplayHelp() { Console.WriteLine(@" At least one argument required. Enter only the path of the file you would like to split.