Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
  • Loading branch information
A9G-Data-Droid committed Apr 26, 2022
2 parents 8eddd36 + f68cd33 commit 53defd0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
20 changes: 13 additions & 7 deletions Split-FANUC-Program-Backup/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,14 +26,15 @@ private static string BuildDate
{
buildDateTime = new DateTime(2000, 1, 1).AddDays(version.Build).AddSeconds(version.Revision * 2);
}

return buildDateTime.ToString("o");
}
}

private const string cncProgramFileExtension = ".CNC";
private const string defaultCNCprogramName = "Unknown";
private const char programDelimiter = '%';
private static readonly char[] subFolderTrim = { ' ', '/' };
private const int minimumProgramSize = 7;

/// <summary>
Expand All @@ -47,7 +48,12 @@ private static string BuildDate
/// </summary>
private const string directoryFlag = @"(&F=)";

static async Task<int> Main(string[] args)
/// <summary>
/// Command line entry point
/// </summary>
/// <param name="args">Requires only one argument: full path to the backup file.</param>
/// <returns>Zero for success</returns>
public static async Task<int> Main(string[] args)
{
DisplayHeader();

Expand Down Expand Up @@ -131,7 +137,7 @@ private static string GetProgramNameFromHeader(string cncProgramText)
/// </summary>
/// <param name="fileName">Full path to "ALL-PROG.TXT"</param>
/// <returns>Each CNC program as a string, and any associated subdirectory</returns>
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 = "";
Expand All @@ -150,7 +156,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
Expand All @@ -175,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)
Expand All @@ -202,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.
Expand Down
4 changes: 2 additions & 2 deletions Split-FANUC-Program-Backup/Split-FANUC-Program-Backup.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<TargetFramework>net6.0-windows</TargetFramework>
<RootNamespace>SplitFANUCProgramBackup</RootNamespace>
<StartupObject></StartupObject>
<Deterministic>False</Deterministic>
Expand Down

0 comments on commit 53defd0

Please sign in to comment.