From efa696ffcaac7033188efe8963bb82a2e5d16e48 Mon Sep 17 00:00:00 2001 From: betato Date: Thu, 17 Sep 2020 12:25:38 -0400 Subject: [PATCH 1/3] Update file+folder regexes and move to constants file --- RocketcadManager/Assembly.cs | 3 +-- RocketcadManager/CadComponent.cs | 5 +---- RocketcadManager/Folder.cs | 5 +++-- RocketcadManager/Part.cs | 3 +-- RocketcadManagerLib/ConstantPaths.cs | 8 ++++++++ 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/RocketcadManager/Assembly.cs b/RocketcadManager/Assembly.cs index 65ac18f..d51653f 100644 --- a/RocketcadManager/Assembly.cs +++ b/RocketcadManager/Assembly.cs @@ -103,8 +103,7 @@ public TreeNode SubComponentTree() public override bool NameOk() { - // Assembly names must end with 00 - return Regex.IsMatch(ComponentFileInfo.Name, @"^([0-9]{2}-)+00(\s.*)*\.(?i)SLDASM(?-i)$"); + return Regex.IsMatch(ComponentFileInfo.Name, ConstantPaths.ValidAssemblyRegex); } } } diff --git a/RocketcadManager/CadComponent.cs b/RocketcadManager/CadComponent.cs index 2e52cf6..30f2956 100644 --- a/RocketcadManager/CadComponent.cs +++ b/RocketcadManager/CadComponent.cs @@ -75,10 +75,7 @@ private void SetImageKey(TreeNode node, string imageKey) node.SelectedImageKey = imageKey; } - public virtual bool NameOk() - { - return Regex.IsMatch(ComponentFileInfo.Name, @"^([0-9]{2}-)+[0-9]{2}(\s.*)*\.(?i)(SLDASM|SLDPRT)(?-i)$"); - } + public abstract bool NameOk(); public int UsageCount() { diff --git a/RocketcadManager/Folder.cs b/RocketcadManager/Folder.cs index 76f96f4..a99bfb5 100644 --- a/RocketcadManager/Folder.cs +++ b/RocketcadManager/Folder.cs @@ -1,4 +1,5 @@ -using System; +using RocketcadManagerLib; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; @@ -61,7 +62,7 @@ public bool IsEmpty() public bool NameOk() { - return Regex.IsMatch(Path.Name, @"^([0-9]{2}-)+[0-9]{2}($|\s)"); + return Regex.IsMatch(Path.Name, ConstantPaths.ValidFolderRegex); } } } diff --git a/RocketcadManager/Part.cs b/RocketcadManager/Part.cs index 1e9a5c1..1d73542 100644 --- a/RocketcadManager/Part.cs +++ b/RocketcadManager/Part.cs @@ -27,8 +27,7 @@ public override void Save() public override bool NameOk() { - // Part names cannot end with 00 - return base.NameOk() && !Regex.IsMatch(ComponentFileInfo.Name, @"^([0-9]{2}-)+00(\s.*)*\.(?i)SLDASM(?-i)$"); + return Regex.IsMatch(ComponentFileInfo.Name, ConstantPaths.ValidPartRegex); } } } diff --git a/RocketcadManagerLib/ConstantPaths.cs b/RocketcadManagerLib/ConstantPaths.cs index 8f3c8b1..c02486d 100644 --- a/RocketcadManagerLib/ConstantPaths.cs +++ b/RocketcadManagerLib/ConstantPaths.cs @@ -14,5 +14,13 @@ public static class ConstantPaths public static DirectoryInfo LogDir { get { return new DirectoryInfo(dataFolder + @"\logs"); } } public static FileInfo ConfigFile { get { return new FileInfo(dataFolder + @"\config.json"); } } + + public static readonly string ValidPartRegex = @"^([0-9]{2}-)+(0[1-9]|[1-9][0-9])(\s.*)?\.(?i)SLDPRT(?-i)$"; + public static readonly string ValidAssemblyRegex = @"^([0-9]{2}-)+00(\s.*)?\.(?i)SLDASM(?-i)$"; + public static readonly string ValidFolderRegex = @"^([0-9]{2}-)+[0-9]{2}($|\s)"; + + public static readonly string ParentFolderRegex = @"^([0-9]{2}-)+[0-9]{2}($|\s)"; + public static readonly string ChildFolderRegex = @""; + public static readonly string ChildFileRegex = @""; } } From 9c4c34922e74561cbb42af96d447579cdf55391f Mon Sep 17 00:00:00 2001 From: betato Date: Thu, 17 Sep 2020 12:44:09 -0400 Subject: [PATCH 2/3] Combine CadComponent and warnings list image keys --- RocketcadManager/CadComponent.cs | 43 +++++++++++++++++----------- RocketcadManager/Folder.cs | 8 +++++- RocketcadManager/WarningsListForm.cs | 15 +--------- 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/RocketcadManager/CadComponent.cs b/RocketcadManager/CadComponent.cs index 30f2956..7423acb 100644 --- a/RocketcadManager/CadComponent.cs +++ b/RocketcadManager/CadComponent.cs @@ -46,36 +46,37 @@ public CadComponent(FileInfo fileInfo, Folder parentFolder) return cadInfo; } - public TreeNode GetNode() + public string GetImageKey() { - TreeNode thisNode = new TreeNode(); - thisNode.Tag = this; - thisNode.Text = ComponentFileInfo.Name; - if (!NameOk()) + if (!NameOk() || !LocationOk()) { if (MissingComponentError || LoadingError) - SetImageKey(thisNode, "WarningErrorFile"); + return "WarningErrorFile"; else if (!HasInfo) - SetImageKey(thisNode, "WarningQuestionFile"); + return "WarningQuestionFile"; else - SetImageKey(thisNode, "WarningFile"); + return "WarningFile"; } else if (MissingComponentError || LoadingError) - SetImageKey(thisNode, "ErrorFile"); + return "ErrorFile"; else if (!HasInfo) - SetImageKey(thisNode, "QuestionFile"); + return "QuestionFile"; else - SetImageKey(thisNode, "File"); - return thisNode; + return "File"; } - private void SetImageKey(TreeNode node, string imageKey) + public TreeNode GetNode() { - node.ImageKey = imageKey; - node.SelectedImageKey = imageKey; - } + TreeNode thisNode = new TreeNode(); + string imageKey = GetImageKey(); - public abstract bool NameOk(); + thisNode.Tag = this; + thisNode.Text = ComponentFileInfo.Name; + thisNode.ImageKey = imageKey; + thisNode.SelectedImageKey = imageKey; + + return thisNode; + } public int UsageCount() { @@ -101,5 +102,13 @@ public TreeNode DependancyTree() } public abstract void Save(); + + public abstract bool NameOk(); + + public bool LocationOk() + { + return Regex.Match(ComponentFileInfo.Name, ConstantPaths.ParentFolderRegex).Value + == Regex.Match(ComponentFileInfo.Name, ConstantPaths.ChildFileRegex).Value; + } } } diff --git a/RocketcadManager/Folder.cs b/RocketcadManager/Folder.cs index a99bfb5..4d7a900 100644 --- a/RocketcadManager/Folder.cs +++ b/RocketcadManager/Folder.cs @@ -31,7 +31,7 @@ public TreeNode DirectoryTree() thisNode.Tag = this; thisNode.Text = Path.Name; - if (NameOk()) + if (NameOk() && LocationOk()) SetImageKey(thisNode, "Folder"); else SetImageKey(thisNode, "WarningFolder"); @@ -64,5 +64,11 @@ public bool NameOk() { return Regex.IsMatch(Path.Name, ConstantPaths.ValidFolderRegex); } + + public bool LocationOk() + { + return Regex.Match(Path.Name, ConstantPaths.ParentFolderRegex).Value + == Regex.Match(Path.Name, ConstantPaths.ChildFolderRegex).Value; + } } } diff --git a/RocketcadManager/WarningsListForm.cs b/RocketcadManager/WarningsListForm.cs index 37cac4a..0a956e5 100644 --- a/RocketcadManager/WarningsListForm.cs +++ b/RocketcadManager/WarningsListForm.cs @@ -41,20 +41,7 @@ private void WarningsListForm_Load(object sender, EventArgs e) string errorStr = errorStrBuilder.ToString(); // Set error icons - // TODO: Combine this with the similar CadComponent method - if (!cadComponent.NameOk()) - { - if (cadComponent.MissingComponentError || cadComponent.LoadingError) - AddWarning(cadComponent, errorStr, "WarningErrorFile"); - else if (!cadComponent.HasInfo) - AddWarning(cadComponent, errorStr, "WarningQuestionFile"); - else - AddWarning(cadComponent, errorStr, "WarningFile"); - } - else if (cadComponent.MissingComponentError || cadComponent.LoadingError) - AddWarning(cadComponent, errorStr, "ErrorFile"); - else if (!cadComponent.HasInfo) - AddWarning(cadComponent, errorStr, "QuestionFile"); + AddWarning(cadComponent, errorStr, cadComponent.GetImageKey()); } foreach (ColumnHeader column in listViewWarnings.Columns) { From a4703074ed32dbb7e971e3a06ea639a13dbe1416 Mon Sep 17 00:00:00 2001 From: betato Date: Thu, 17 Sep 2020 13:44:01 -0400 Subject: [PATCH 3/3] Add parent folder checking --- RocketcadManager/CadComponent.cs | 8 ++++++-- RocketcadManager/Folder.cs | 12 ++++++++++-- RocketcadManager/WarningsListForm.cs | 2 ++ RocketcadManagerLib/ConstantPaths.cs | 7 ++++--- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/RocketcadManager/CadComponent.cs b/RocketcadManager/CadComponent.cs index 7423acb..49e5f8e 100644 --- a/RocketcadManager/CadComponent.cs +++ b/RocketcadManager/CadComponent.cs @@ -107,8 +107,12 @@ public TreeNode DependancyTree() public bool LocationOk() { - return Regex.Match(ComponentFileInfo.Name, ConstantPaths.ParentFolderRegex).Value - == Regex.Match(ComponentFileInfo.Name, ConstantPaths.ChildFileRegex).Value; + if (ParentFolder == null) + return true; + if (ConstantPaths.IgnoreTopLevelFolders && ParentFolder.ParentFolder == null) + return true; + return Regex.Match(ParentFolder.Path.Name, ConstantPaths.ParentFolderRegex).Groups[1].Value + == Regex.Match(ComponentFileInfo.Name, ConstantPaths.ChildFileRegex).Groups[1].Value; } } } diff --git a/RocketcadManager/Folder.cs b/RocketcadManager/Folder.cs index 4d7a900..33641fb 100644 --- a/RocketcadManager/Folder.cs +++ b/RocketcadManager/Folder.cs @@ -62,13 +62,21 @@ public bool IsEmpty() public bool NameOk() { + // Ignore top level folders + if (ConstantPaths.IgnoreTopLevelFolders && ParentFolder == null) + return true; return Regex.IsMatch(Path.Name, ConstantPaths.ValidFolderRegex); } public bool LocationOk() { - return Regex.Match(Path.Name, ConstantPaths.ParentFolderRegex).Value - == Regex.Match(Path.Name, ConstantPaths.ChildFolderRegex).Value; + if (ParentFolder == null) + return true; + // Ignore top level folders + if (ConstantPaths.IgnoreTopLevelFolders && ParentFolder.ParentFolder == null) + return true; + return Regex.Match(ParentFolder.Path.Name, ConstantPaths.ParentFolderRegex).Groups[1].Value + == Regex.Match(Path.Name, ConstantPaths.ChildFolderRegex).Groups[1].Value; } } } diff --git a/RocketcadManager/WarningsListForm.cs b/RocketcadManager/WarningsListForm.cs index 0a956e5..51ae810 100644 --- a/RocketcadManager/WarningsListForm.cs +++ b/RocketcadManager/WarningsListForm.cs @@ -29,6 +29,8 @@ private void WarningsListForm_Load(object sender, EventArgs e) StringBuilder errorStrBuilder = new StringBuilder(); if (!cadComponent.NameOk()) errorStrBuilder.Append("Naming violation, "); + if (!cadComponent.LocationOk()) + errorStrBuilder.Append("Name does not match parent folder, "); if (!cadComponent.HasInfo) errorStrBuilder.Append("Missing info file, "); if (cadComponent.MissingComponentError) diff --git a/RocketcadManagerLib/ConstantPaths.cs b/RocketcadManagerLib/ConstantPaths.cs index c02486d..aaf8b66 100644 --- a/RocketcadManagerLib/ConstantPaths.cs +++ b/RocketcadManagerLib/ConstantPaths.cs @@ -19,8 +19,9 @@ public static class ConstantPaths public static readonly string ValidAssemblyRegex = @"^([0-9]{2}-)+00(\s.*)?\.(?i)SLDASM(?-i)$"; public static readonly string ValidFolderRegex = @"^([0-9]{2}-)+[0-9]{2}($|\s)"; - public static readonly string ParentFolderRegex = @"^([0-9]{2}-)+[0-9]{2}($|\s)"; - public static readonly string ChildFolderRegex = @""; - public static readonly string ChildFileRegex = @""; + public static readonly string ParentFolderRegex = @"^(([0-9]{2}-)+[0-9]{2})"; + public static readonly string ChildFolderRegex = @"^([0-9]{2}(-[0-9]{2})*)-[0-9]{2}($|\s)"; + public static readonly string ChildFileRegex = @"^([0-9]{2}(-[0-9]{2})*)-[0-9]{2}(\s.*)?\.(?i)(SLDASM|SLDPRT)(?-i)$"; + public static readonly bool IgnoreTopLevelFolders = true; } }