From 30cb68c49b2450e6f8405fd22766ea51804e04ad Mon Sep 17 00:00:00 2001 From: betato Date: Wed, 16 Sep 2020 13:46:39 -0400 Subject: [PATCH 01/17] Add error log types --- RocketcadManager/MainForm.cs | 2 +- RocketcadManagerLib/LogWriter.cs | 21 ++++++++++++++++++--- RocketcadManagerPlugin/Addin.cs | 8 ++++---- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/RocketcadManager/MainForm.cs b/RocketcadManager/MainForm.cs index c79863d..c6debff 100644 --- a/RocketcadManager/MainForm.cs +++ b/RocketcadManager/MainForm.cs @@ -25,7 +25,7 @@ public MainForm() private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { Exception ex = (Exception)e.ExceptionObject; - string logFile = LogWriter.Write("crash", new string[] { ex.StackTrace }); + string logFile = LogWriter.Write(LogType.ManagerCrash, new string[] { ex.StackTrace }); MessageBox.Show(ex.Message + (e.IsTerminating ? " The program will now close." : "") + "\n\nStack trace written to: " + logFile, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } diff --git a/RocketcadManagerLib/LogWriter.cs b/RocketcadManagerLib/LogWriter.cs index 018097b..4f29c5d 100644 --- a/RocketcadManagerLib/LogWriter.cs +++ b/RocketcadManagerLib/LogWriter.cs @@ -8,17 +8,32 @@ namespace RocketcadManagerLib { + public class LogType + { + private LogType(string tag) { Tag = tag; } + public string Tag { get; private set; } + + public override string ToString() { return Tag; } + public static implicit operator string(LogType logType) { return logType.Tag; } + + public static LogType ManagerCrash { get { return new LogType("crash-manager"); } } + public static LogType AddinCrash { get { return new LogType("crash-addin"); } } + public static LogType AddinSaveCadError { get { return new LogType("error-addin-save_cad"); } } + public static LogType AddinSaveImageError { get { return new LogType("error-addin-save_image"); } } + } + public static class LogWriter { private static readonly DirectoryInfo logFolder = new DirectoryInfo( Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\RocketcadManager\logs"); - public static string Write(string tag, string[] message) + public static string Write(LogType logType, string[] message) { string timestamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"); - string namePrefix = Regex.Replace(tag, "[<>:\\\"/\\\\\\|\\?\\*\\t\\r\\n\\s]", "-"); + if (Regex.IsMatch(logType, "[<>:\\\"/\\\\\\|\\?\\*\\t\\r\\n\\s]")) + throw new FormatException("Invalid characters in file name"); logFolder.Create(); - string logFile = logFolder.FullName + @"\" + namePrefix + "-" + timestamp + ".txt"; + string logFile = logFolder.FullName + @"\" + logType + "-" + timestamp + ".txt"; File.WriteAllLines(logFile, message); return logFile; } diff --git a/RocketcadManagerPlugin/Addin.cs b/RocketcadManagerPlugin/Addin.cs index 2f3923a..73c11f7 100644 --- a/RocketcadManagerPlugin/Addin.cs +++ b/RocketcadManagerPlugin/Addin.cs @@ -43,7 +43,7 @@ private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionE // TODO: Fix global error handling - Solidworks may catch errors before they are logged Exception ex = (Exception)e.ExceptionObject; - LogWriter.Write("plugin-crash", new string[] { ex.StackTrace }); + LogWriter.Write(LogType.AddinCrash, new string[] { ex.StackTrace }); } public bool DisconnectFromSW() @@ -198,7 +198,7 @@ private void SaveCadInfo(string filename) catch (Exception e) { swApp.SendMsgToUser(e.Message); - LogWriter.Write("plugin-cad-save-error", new string[] { e.StackTrace }); + LogWriter.Write(LogType.AddinSaveCadError, new string[] { e.StackTrace }); } // Create anew PartInfo or AssemblyInfo if one was not loaded, then update the info @@ -229,7 +229,7 @@ private void SaveCadInfo(string filename) catch (Exception e) { swApp.SendMsgToUser(e.Message); - LogWriter.Write("plugin-cad-save-error", new string[] { e.StackTrace }); + LogWriter.Write(LogType.AddinSaveCadError, new string[] { e.StackTrace }); } #if DEBUG swApp.SendMsgToUser("Saved!"); @@ -350,7 +350,7 @@ private Image GetThumbnailImage(string filename) catch (Exception e) { swApp.SendMsgToUser(e.Message); - LogWriter.Write("plugin-image-save-error", new string[] { e.StackTrace }); + LogWriter.Write(LogType.AddinSaveImageError, new string[] { e.StackTrace }); } return thumb; } From c3cde3976506da4bdd4669e0d21898dad7306c2e Mon Sep 17 00:00:00 2001 From: betato Date: Wed, 16 Sep 2020 14:00:05 -0400 Subject: [PATCH 02/17] Change error names and add LogWriter error --- RocketcadManagerLib/ConfigLoader.cs | 2 +- RocketcadManagerLib/LogWriter.cs | 8 ++++---- RocketcadManagerPlugin/Addin.cs | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/RocketcadManagerLib/ConfigLoader.cs b/RocketcadManagerLib/ConfigLoader.cs index dc3f9a8..87f5efb 100644 --- a/RocketcadManagerLib/ConfigLoader.cs +++ b/RocketcadManagerLib/ConfigLoader.cs @@ -24,7 +24,7 @@ public static void Open(out Config config) catch (JsonException e) { // Json parsing error, overwrite the old file with the default config and log an error - LogWriter.Write("config-loader-error", new string[] { e.StackTrace }); + LogWriter.Write(LogType.ConfigLoaderError, new string[] { e.StackTrace }); Save(config); } } diff --git a/RocketcadManagerLib/LogWriter.cs b/RocketcadManagerLib/LogWriter.cs index 4f29c5d..e0410fb 100644 --- a/RocketcadManagerLib/LogWriter.cs +++ b/RocketcadManagerLib/LogWriter.cs @@ -16,10 +16,10 @@ public class LogType public override string ToString() { return Tag; } public static implicit operator string(LogType logType) { return logType.Tag; } - public static LogType ManagerCrash { get { return new LogType("crash-manager"); } } - public static LogType AddinCrash { get { return new LogType("crash-addin"); } } - public static LogType AddinSaveCadError { get { return new LogType("error-addin-save_cad"); } } - public static LogType AddinSaveImageError { get { return new LogType("error-addin-save_image"); } } + public static LogType ManagerCrash { get { return new LogType("manager-crash"); } } + public static LogType AddinCrash { get { return new LogType("addin-crash"); } } + public static LogType AddinSaveError { get { return new LogType("addin-save-error"); } } + public static LogType ConfigLoaderError { get { return new LogType("config-loader-error"); } } } public static class LogWriter diff --git a/RocketcadManagerPlugin/Addin.cs b/RocketcadManagerPlugin/Addin.cs index 73c11f7..ad4c1cd 100644 --- a/RocketcadManagerPlugin/Addin.cs +++ b/RocketcadManagerPlugin/Addin.cs @@ -198,7 +198,7 @@ private void SaveCadInfo(string filename) catch (Exception e) { swApp.SendMsgToUser(e.Message); - LogWriter.Write(LogType.AddinSaveCadError, new string[] { e.StackTrace }); + LogWriter.Write(LogType.AddinSaveError, new string[] { e.StackTrace }); } // Create anew PartInfo or AssemblyInfo if one was not loaded, then update the info @@ -229,7 +229,7 @@ private void SaveCadInfo(string filename) catch (Exception e) { swApp.SendMsgToUser(e.Message); - LogWriter.Write(LogType.AddinSaveCadError, new string[] { e.StackTrace }); + LogWriter.Write(LogType.AddinSaveError, new string[] { e.StackTrace }); } #if DEBUG swApp.SendMsgToUser("Saved!"); @@ -350,7 +350,7 @@ private Image GetThumbnailImage(string filename) catch (Exception e) { swApp.SendMsgToUser(e.Message); - LogWriter.Write(LogType.AddinSaveImageError, new string[] { e.StackTrace }); + LogWriter.Write(LogType.AddinSaveError, new string[] { e.StackTrace }); } return thumb; } From 2cbf238fb51ba5c6f7bce1cd5dad30e504ac143f Mon Sep 17 00:00:00 2001 From: betato Date: Wed, 16 Sep 2020 14:10:01 -0400 Subject: [PATCH 03/17] Add overloaded LogWriter Write method for strings --- RocketcadManager/MainForm.cs | 2 +- RocketcadManagerLib/ConfigLoader.cs | 2 +- RocketcadManagerLib/LogWriter.cs | 6 ++++++ RocketcadManagerPlugin/Addin.cs | 12 ++++-------- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/RocketcadManager/MainForm.cs b/RocketcadManager/MainForm.cs index c6debff..b6ab747 100644 --- a/RocketcadManager/MainForm.cs +++ b/RocketcadManager/MainForm.cs @@ -25,7 +25,7 @@ public MainForm() private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { Exception ex = (Exception)e.ExceptionObject; - string logFile = LogWriter.Write(LogType.ManagerCrash, new string[] { ex.StackTrace }); + string logFile = LogWriter.Write(LogType.ManagerCrash, ex.StackTrace); MessageBox.Show(ex.Message + (e.IsTerminating ? " The program will now close." : "") + "\n\nStack trace written to: " + logFile, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } diff --git a/RocketcadManagerLib/ConfigLoader.cs b/RocketcadManagerLib/ConfigLoader.cs index 87f5efb..0d3b775 100644 --- a/RocketcadManagerLib/ConfigLoader.cs +++ b/RocketcadManagerLib/ConfigLoader.cs @@ -24,7 +24,7 @@ public static void Open(out Config config) catch (JsonException e) { // Json parsing error, overwrite the old file with the default config and log an error - LogWriter.Write(LogType.ConfigLoaderError, new string[] { e.StackTrace }); + LogWriter.Write(LogType.ConfigLoaderError, e.StackTrace); Save(config); } } diff --git a/RocketcadManagerLib/LogWriter.cs b/RocketcadManagerLib/LogWriter.cs index e0410fb..5932521 100644 --- a/RocketcadManagerLib/LogWriter.cs +++ b/RocketcadManagerLib/LogWriter.cs @@ -18,6 +18,7 @@ public class LogType public static LogType ManagerCrash { get { return new LogType("manager-crash"); } } public static LogType AddinCrash { get { return new LogType("addin-crash"); } } + public static LogType AddinError { get { return new LogType("addin-error"); } } public static LogType AddinSaveError { get { return new LogType("addin-save-error"); } } public static LogType ConfigLoaderError { get { return new LogType("config-loader-error"); } } } @@ -27,6 +28,11 @@ public static class LogWriter private static readonly DirectoryInfo logFolder = new DirectoryInfo( Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\RocketcadManager\logs"); + public static string Write(LogType logType, string message) + { + return Write(logType, new string[] { message }); + } + public static string Write(LogType logType, string[] message) { string timestamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"); diff --git a/RocketcadManagerPlugin/Addin.cs b/RocketcadManagerPlugin/Addin.cs index ad4c1cd..ef00e03 100644 --- a/RocketcadManagerPlugin/Addin.cs +++ b/RocketcadManagerPlugin/Addin.cs @@ -43,7 +43,7 @@ private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionE // TODO: Fix global error handling - Solidworks may catch errors before they are logged Exception ex = (Exception)e.ExceptionObject; - LogWriter.Write(LogType.AddinCrash, new string[] { ex.StackTrace }); + LogWriter.Write(LogType.AddinCrash, ex.StackTrace); } public bool DisconnectFromSW() @@ -178,10 +178,6 @@ private void SaveCadInfo(string filename) if (modelType != 1 && modelType != 2) return; // Probably a drawing -#if DEBUG - swApp.SendMsgToUser("Checks complete"); -#endif - Image thumbnail = null; PartInfo partInfo = null; AssemblyInfo assemblyInfo = null; @@ -198,7 +194,7 @@ private void SaveCadInfo(string filename) catch (Exception e) { swApp.SendMsgToUser(e.Message); - LogWriter.Write(LogType.AddinSaveError, new string[] { e.StackTrace }); + LogWriter.Write(LogType.AddinSaveError, e.StackTrace); } // Create anew PartInfo or AssemblyInfo if one was not loaded, then update the info @@ -229,7 +225,7 @@ private void SaveCadInfo(string filename) catch (Exception e) { swApp.SendMsgToUser(e.Message); - LogWriter.Write(LogType.AddinSaveError, new string[] { e.StackTrace }); + LogWriter.Write(LogType.AddinSaveError, e.StackTrace); } #if DEBUG swApp.SendMsgToUser("Saved!"); @@ -350,7 +346,7 @@ private Image GetThumbnailImage(string filename) catch (Exception e) { swApp.SendMsgToUser(e.Message); - LogWriter.Write(LogType.AddinSaveError, new string[] { e.StackTrace }); + LogWriter.Write(LogType.AddinSaveError, e.StackTrace); } return thumb; } From 6fe6d581c17155937978e939e673291d7c2417d1 Mon Sep 17 00:00:00 2001 From: betato Date: Wed, 16 Sep 2020 14:46:50 -0400 Subject: [PATCH 04/17] Add more error handling to plugin --- RocketcadManagerPlugin/Addin.cs | 152 +++++++++++++++++++++----------- 1 file changed, 100 insertions(+), 52 deletions(-) diff --git a/RocketcadManagerPlugin/Addin.cs b/RocketcadManagerPlugin/Addin.cs index ef00e03..6f5080a 100644 --- a/RocketcadManagerPlugin/Addin.cs +++ b/RocketcadManagerPlugin/Addin.cs @@ -23,29 +23,49 @@ public class Addin : SwAddin public bool ConnectToSW(object ThisSW, int Cookie) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; - ConfigLoader.Open(out config); + + // Connect to SW + try + { + swApp = (SldWorks)ThisSW; + swApp.SetAddinCallbackInfo(0, this, Cookie); + sessionCookie = Cookie; + } + catch (Exception e) + { + // Can't show an error message here because sw is not connected + LogWriter.Write(LogType.AddinError, e.StackTrace); + } - swApp = (SldWorks)ThisSW; - swApp.SetAddinCallbackInfo(0, this, Cookie); - sessionCookie = Cookie; - - swApp.FileOpenNotify2 += SwApp_FileOpenNotify2; - swApp.FileNewNotify2 += SwApp_FileNewNotify2; - - swApp.FileCloseNotify += SwApp_FileCloseNotify; - + // Register file open event handlers + try + { + swApp.FileOpenNotify2 += SwApp_FileOpenNotify2; + swApp.FileNewNotify2 += SwApp_FileNewNotify2; + swApp.FileCloseNotify += SwApp_FileCloseNotify; + } + catch (Exception e) + { + LogErrorWithMessage(LogType.AddinError, e); + } return true; } private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { - // TODO: Fix global error handling - Solidworks may catch errors before they are logged - + // Solidworks might be catching errors before they are logged + // All possible errors should be caught locally Exception ex = (Exception)e.ExceptionObject; LogWriter.Write(LogType.AddinCrash, ex.StackTrace); } + private void LogErrorWithMessage(LogType logType, Exception e) + { + string logLocation = LogWriter.Write(logType, e.StackTrace); + swApp.SendMsgToUser(string.Format("Error: {0}\nLog Saved to:\n{1}", e.Message, logLocation)); + } + public bool DisconnectFromSW() { swApp = null; @@ -74,29 +94,43 @@ private int SwApp_FileCloseNotify(string FileName, int reason) private void RemovePartSaveEvent() { + // TODO: Remove part save events when files are closed (make this actually work) +#if DEBUG swApp.SendMsgToUser("Removing"); - +#endif ModelDoc2 swModel = swApp.ActiveDoc; if (swModel == null) + { + swApp.SendMsgToUser("Error! swModel is null"); return; + } swApp.SendMsgToUser("Removing save event for : " + swModel.GetTitle()); - - int modelType = swModel.GetType(); - // 1:part 2:assembly 3:drawing - if (modelType == 1) + try { - PartDoc part = (PartDoc)swModel; - part.FileSaveNotify -= Part_FileSaveNotify; - part.FileSaveAsNotify2 -= Part_FileSaveAsNotify2; - swApp.SendMsgToUser("Removed part: " + swModel.GetTitle()); + int modelType = swModel.GetType(); // 1:part 2:assembly 3:drawing + if (modelType == 1) + { + PartDoc part = (PartDoc)swModel; + part.FileSaveNotify -= Part_FileSaveNotify; + part.FileSaveAsNotify2 -= Part_FileSaveAsNotify2; +#if DEBUG + swApp.SendMsgToUser("Removed part: " + swModel.GetTitle()); +#endif + } + else if (modelType == 2) + { + AssemblyDoc assembly = (AssemblyDoc)swModel; + assembly.FileSaveNotify -= Assembly_FileSaveNotify; + assembly.FileSaveAsNotify2 -= Assembly_FileSaveAsNotify2; +#if DEBUG + swApp.SendMsgToUser("Removed assembly: " + swModel.GetTitle()); +#endif + } } - else if (modelType == 2) + catch (Exception e) { - AssemblyDoc assembly = (AssemblyDoc)swModel; - assembly.FileSaveNotify -= Assembly_FileSaveNotify; - assembly.FileSaveAsNotify2 -= Assembly_FileSaveAsNotify2; - swApp.SendMsgToUser("Removed assembly: " + swModel.GetTitle()); + LogErrorWithMessage(LogType.AddinError, e); } } @@ -104,22 +138,32 @@ private void AddPartSaveEvent() { ModelDoc2 swModel = swApp.ActiveDoc; if (swModel == null) + { + swApp.SendMsgToUser("Error! swModel is null"); return; - - int modelType = swModel.GetType(); - // 1:part 2:assembly 3:drawing - if (modelType == 1) + } + + try { - PartDoc part = (PartDoc)swModel; - part.FileSaveNotify += Part_FileSaveNotify; - part.FileSaveAsNotify2 += Part_FileSaveAsNotify2; + int modelType = swModel.GetType(); // 1:part 2:assembly 3:drawing + if (modelType == 1) + { + PartDoc part = (PartDoc)swModel; + part.FileSaveNotify += Part_FileSaveNotify; + part.FileSaveAsNotify2 += Part_FileSaveAsNotify2; + } + else if (modelType == 2) + { + AssemblyDoc assembly = (AssemblyDoc)swModel; + assembly.FileSaveNotify += Assembly_FileSaveNotify; + assembly.FileSaveAsNotify2 += Assembly_FileSaveAsNotify2; + } } - else if (modelType == 2) + catch (Exception e) { - AssemblyDoc assembly = (AssemblyDoc)swModel; - assembly.FileSaveNotify += Assembly_FileSaveNotify; - assembly.FileSaveAsNotify2 += Assembly_FileSaveAsNotify2; + LogErrorWithMessage(LogType.AddinError, e); } + #if DEBUG swApp.SendMsgToUser("Added part save event"); #endif @@ -193,22 +237,28 @@ private void SaveCadInfo(string filename) } catch (Exception e) { - swApp.SendMsgToUser(e.Message); - LogWriter.Write(LogType.AddinSaveError, e.StackTrace); + LogErrorWithMessage(LogType.AddinSaveError, e); } - // Create anew PartInfo or AssemblyInfo if one was not loaded, then update the info - if (modelType == 1) + // Create a new PartInfo or AssemblyInfo if one was not loaded, then update the info + try { - if (partInfo == null) - partInfo = new PartInfo(); - GetPartInfo(swModel, ref partInfo); + if (modelType == 1) + { + if (partInfo == null) + partInfo = new PartInfo(); + GetPartInfo(swModel, ref partInfo); + } + else if (modelType == 2) + { + if (assemblyInfo == null) + assemblyInfo = new AssemblyInfo(); + GetAssemblyInfo(swModel, ref assemblyInfo); + } } - else if (modelType == 2) + catch (Exception e) { - if (assemblyInfo == null) - assemblyInfo = new AssemblyInfo(); - GetAssemblyInfo(swModel, ref assemblyInfo); + LogErrorWithMessage(LogType.AddinSaveError, e); } // Get a new thumbnail image @@ -224,8 +274,7 @@ private void SaveCadInfo(string filename) } catch (Exception e) { - swApp.SendMsgToUser(e.Message); - LogWriter.Write(LogType.AddinSaveError, e.StackTrace); + LogErrorWithMessage(LogType.AddinSaveError, e); } #if DEBUG swApp.SendMsgToUser("Saved!"); @@ -345,8 +394,7 @@ private Image GetThumbnailImage(string filename) } catch (Exception e) { - swApp.SendMsgToUser(e.Message); - LogWriter.Write(LogType.AddinSaveError, e.StackTrace); + LogErrorWithMessage(LogType.AddinSaveError, e); } return thumb; } From e519b13ec13a8c6b7f2bfbbad807a3053d3618b6 Mon Sep 17 00:00:00 2001 From: betato Date: Wed, 16 Sep 2020 16:26:33 -0400 Subject: [PATCH 05/17] Add FolderNode tree to store file view expansion --- RocketcadManagerLib/Config.cs | 57 +++++++++++++++++-- .../RocketcadManagerLib.csproj | 1 + 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/RocketcadManagerLib/Config.cs b/RocketcadManagerLib/Config.cs index 4f306db..eec4922 100644 --- a/RocketcadManagerLib/Config.cs +++ b/RocketcadManagerLib/Config.cs @@ -3,25 +3,70 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Forms; namespace RocketcadManagerLib { public class Config { + private class FolderNode + { + public FolderNode sibling; + public FolderNode child; + + public string Name { get; private set; } + public bool Expanded { get; private set; } + + public FolderNode(string name, bool expanded) + { + Name = name; + Expanded = expanded; + } + + public void Clear() + { + sibling = null; + child = null; + } + } + + public List CadDirectories { get; set; } + private FolderNode folderViewExpansion; + public Config() { CadDirectories = new List(); } - public Config(Config config) : this() + public void SaveTreeViewExpansion(TreeNodeCollection treeNodes) { - // Copy constructor - foreach (string cadDirectory in config.CadDirectories) + + folderViewExpansion = SaveTreeViewNodes(treeNodes); + } + + private FolderNode SaveTreeViewNodes(TreeNodeCollection treeNodes) + { + FolderNode firstSibling = null; + FolderNode currentSibling = null; + foreach (TreeNode treeNode in treeNodes) { - CadDirectories.Add(cadDirectory); + TreeNodeCollection subNodes = treeNode.Nodes; + if (subNodes.Count > 0) // Node has children and is expandable + { + if (firstSibling == null) + { + firstSibling = new FolderNode(treeNode.Name, treeNode.IsExpanded); + currentSibling = firstSibling; + } + else + { + currentSibling.sibling = new FolderNode(treeNode.Name, treeNode.IsExpanded); + currentSibling = currentSibling.sibling; + currentSibling.child = SaveTreeViewNodes(subNodes); + } + } } + return firstSibling; } - - public List CadDirectories { get; set; } } } diff --git a/RocketcadManagerLib/RocketcadManagerLib.csproj b/RocketcadManagerLib/RocketcadManagerLib.csproj index 01c3f3a..3c79c2f 100644 --- a/RocketcadManagerLib/RocketcadManagerLib.csproj +++ b/RocketcadManagerLib/RocketcadManagerLib.csproj @@ -42,6 +42,7 @@ ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll + From b3e2ec3485a6e2c740358e1390629d36e290b3cd Mon Sep 17 00:00:00 2001 From: betato Date: Wed, 16 Sep 2020 16:51:45 -0400 Subject: [PATCH 06/17] Move constant folders to dedicated class --- RocketcadManagerLib/ConfigLoader.cs | 11 ++++------- RocketcadManagerLib/ConstantPaths.cs | 18 ++++++++++++++++++ RocketcadManagerLib/LogWriter.cs | 7 ++----- RocketcadManagerLib/RocketcadManagerLib.csproj | 1 + 4 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 RocketcadManagerLib/ConstantPaths.cs diff --git a/RocketcadManagerLib/ConfigLoader.cs b/RocketcadManagerLib/ConfigLoader.cs index 0d3b775..349d874 100644 --- a/RocketcadManagerLib/ConfigLoader.cs +++ b/RocketcadManagerLib/ConfigLoader.cs @@ -10,16 +10,13 @@ namespace RocketcadManagerLib { public static class ConfigLoader { - private static readonly FileInfo configFile = new FileInfo( - Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\RocketcadManager\config.json"); - public static void Open(out Config config) { config = new Config(); try { - if (configFile.Exists) - config = JsonConvert.DeserializeObject(File.ReadAllText(configFile.FullName)); + if (ConstantPaths.ConfigFile.Exists) + config = JsonConvert.DeserializeObject(File.ReadAllText(ConstantPaths.ConfigFile.FullName)); } catch (JsonException e) { @@ -31,8 +28,8 @@ public static void Open(out Config config) public static void Save(Config config) { - configFile.Directory.Create(); - File.WriteAllText(configFile.FullName, JsonConvert.SerializeObject(config)); + ConstantPaths.ConfigFile.Directory.Create(); + File.WriteAllText(ConstantPaths.ConfigFile.FullName, JsonConvert.SerializeObject(config)); } } } diff --git a/RocketcadManagerLib/ConstantPaths.cs b/RocketcadManagerLib/ConstantPaths.cs new file mode 100644 index 0000000..8f3c8b1 --- /dev/null +++ b/RocketcadManagerLib/ConstantPaths.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RocketcadManagerLib +{ + public static class ConstantPaths + { + private static readonly string dataFolder = + Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\RocketcadManager"; + + public static DirectoryInfo LogDir { get { return new DirectoryInfo(dataFolder + @"\logs"); } } + public static FileInfo ConfigFile { get { return new FileInfo(dataFolder + @"\config.json"); } } + } +} diff --git a/RocketcadManagerLib/LogWriter.cs b/RocketcadManagerLib/LogWriter.cs index 5932521..a56b9ef 100644 --- a/RocketcadManagerLib/LogWriter.cs +++ b/RocketcadManagerLib/LogWriter.cs @@ -25,9 +25,6 @@ public class LogType public static class LogWriter { - private static readonly DirectoryInfo logFolder = new DirectoryInfo( - Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\RocketcadManager\logs"); - public static string Write(LogType logType, string message) { return Write(logType, new string[] { message }); @@ -38,8 +35,8 @@ public static string Write(LogType logType, string[] message) string timestamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"); if (Regex.IsMatch(logType, "[<>:\\\"/\\\\\\|\\?\\*\\t\\r\\n\\s]")) throw new FormatException("Invalid characters in file name"); - logFolder.Create(); - string logFile = logFolder.FullName + @"\" + logType + "-" + timestamp + ".txt"; + ConstantPaths.LogDir.Create(); + string logFile = ConstantPaths.LogDir.FullName + @"\" + logType + "-" + timestamp + ".txt"; File.WriteAllLines(logFile, message); return logFile; } diff --git a/RocketcadManagerLib/RocketcadManagerLib.csproj b/RocketcadManagerLib/RocketcadManagerLib.csproj index 3c79c2f..302bfab 100644 --- a/RocketcadManagerLib/RocketcadManagerLib.csproj +++ b/RocketcadManagerLib/RocketcadManagerLib.csproj @@ -55,6 +55,7 @@ + From 0e82f14678d3a881c2aa649b805edc92fc24bf59 Mon Sep 17 00:00:00 2001 From: betato Date: Wed, 16 Sep 2020 17:03:00 -0400 Subject: [PATCH 07/17] Move Config save and open methods to Config class --- RocketcadManager/MainForm.cs | 4 +-- RocketcadManagerLib/Config.cs | 26 +++++++++++++- RocketcadManagerLib/ConfigLoader.cs | 35 ------------------- .../RocketcadManagerLib.csproj | 1 - RocketcadManagerPlugin/Addin.cs | 2 +- 5 files changed, 28 insertions(+), 40 deletions(-) delete mode 100644 RocketcadManagerLib/ConfigLoader.cs diff --git a/RocketcadManager/MainForm.cs b/RocketcadManager/MainForm.cs index b6ab747..5d60ffb 100644 --- a/RocketcadManager/MainForm.cs +++ b/RocketcadManager/MainForm.cs @@ -41,7 +41,7 @@ private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionE private void Form1_Load(object sender, EventArgs e) { - ConfigLoader.Open(out config); + Config.Open(out config); ImageList imageList = new ImageList(); imageList.ColorDepth = ColorDepth.Depth32Bit; @@ -343,7 +343,7 @@ private void toolStripSettings_Click(object sender, EventArgs e) SettingsForm settingsWindow = new SettingsForm(config); if (settingsWindow.ShowDialog(this) == DialogResult.OK) { - ConfigLoader.Save(config); + Config.Save(config); LoadFiles(); } } diff --git a/RocketcadManagerLib/Config.cs b/RocketcadManagerLib/Config.cs index eec4922..39017d3 100644 --- a/RocketcadManagerLib/Config.cs +++ b/RocketcadManagerLib/Config.cs @@ -1,5 +1,7 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,6 +11,28 @@ namespace RocketcadManagerLib { public class Config { + public static void Open(out Config config) + { + config = new Config(); + try + { + if (ConstantPaths.ConfigFile.Exists) + config = JsonConvert.DeserializeObject(File.ReadAllText(ConstantPaths.ConfigFile.FullName)); + } + catch (JsonException e) + { + // Json parsing error, overwrite the old file with the default config and log an error + LogWriter.Write(LogType.ConfigLoaderError, e.StackTrace); + Save(config); + } + } + + public static void Save(Config config) + { + ConstantPaths.ConfigFile.Directory.Create(); + File.WriteAllText(ConstantPaths.ConfigFile.FullName, JsonConvert.SerializeObject(config)); + } + private class FolderNode { public FolderNode sibling; diff --git a/RocketcadManagerLib/ConfigLoader.cs b/RocketcadManagerLib/ConfigLoader.cs deleted file mode 100644 index 349d874..0000000 --- a/RocketcadManagerLib/ConfigLoader.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RocketcadManagerLib -{ - public static class ConfigLoader - { - public static void Open(out Config config) - { - config = new Config(); - try - { - if (ConstantPaths.ConfigFile.Exists) - config = JsonConvert.DeserializeObject(File.ReadAllText(ConstantPaths.ConfigFile.FullName)); - } - catch (JsonException e) - { - // Json parsing error, overwrite the old file with the default config and log an error - LogWriter.Write(LogType.ConfigLoaderError, e.StackTrace); - Save(config); - } - } - - public static void Save(Config config) - { - ConstantPaths.ConfigFile.Directory.Create(); - File.WriteAllText(ConstantPaths.ConfigFile.FullName, JsonConvert.SerializeObject(config)); - } - } -} diff --git a/RocketcadManagerLib/RocketcadManagerLib.csproj b/RocketcadManagerLib/RocketcadManagerLib.csproj index 302bfab..52417f1 100644 --- a/RocketcadManagerLib/RocketcadManagerLib.csproj +++ b/RocketcadManagerLib/RocketcadManagerLib.csproj @@ -54,7 +54,6 @@ - diff --git a/RocketcadManagerPlugin/Addin.cs b/RocketcadManagerPlugin/Addin.cs index 6f5080a..7fba34f 100644 --- a/RocketcadManagerPlugin/Addin.cs +++ b/RocketcadManagerPlugin/Addin.cs @@ -23,7 +23,7 @@ public class Addin : SwAddin public bool ConnectToSW(object ThisSW, int Cookie) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; - ConfigLoader.Open(out config); + Config.Open(out config); // Connect to SW try From a5f2886f6772b2459b012f3adf7ed07741c734ca Mon Sep 17 00:00:00 2001 From: betato Date: Wed, 16 Sep 2020 17:18:07 -0400 Subject: [PATCH 08/17] Add file view expansion saving --- RocketcadManager/MainForm.cs | 3 +++ RocketcadManagerLib/Config.cs | 13 ++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/RocketcadManager/MainForm.cs b/RocketcadManager/MainForm.cs index 5d60ffb..11195a4 100644 --- a/RocketcadManager/MainForm.cs +++ b/RocketcadManager/MainForm.cs @@ -336,6 +336,9 @@ private void SaveSelected() private void Form1_FormClosing(object sender, FormClosingEventArgs e) { SaveSelected(); + config.SaveTreeViewExpansion(fileView.Nodes); + + Config.Save(config); } private void toolStripSettings_Click(object sender, EventArgs e) diff --git a/RocketcadManagerLib/Config.cs b/RocketcadManagerLib/Config.cs index 39017d3..9ee0767 100644 --- a/RocketcadManagerLib/Config.cs +++ b/RocketcadManagerLib/Config.cs @@ -54,17 +54,12 @@ public void Clear() } } - public List CadDirectories { get; set; } + public List CadDirectories { get; set; } = new List(); + [JsonProperty] private FolderNode folderViewExpansion; - public Config() - { - CadDirectories = new List(); - } - public void SaveTreeViewExpansion(TreeNodeCollection treeNodes) { - folderViewExpansion = SaveTreeViewNodes(treeNodes); } @@ -79,15 +74,15 @@ private FolderNode SaveTreeViewNodes(TreeNodeCollection treeNodes) { if (firstSibling == null) { - firstSibling = new FolderNode(treeNode.Name, treeNode.IsExpanded); + firstSibling = new FolderNode(treeNode.Text, treeNode.IsExpanded); currentSibling = firstSibling; } else { currentSibling.sibling = new FolderNode(treeNode.Name, treeNode.IsExpanded); currentSibling = currentSibling.sibling; - currentSibling.child = SaveTreeViewNodes(subNodes); } + currentSibling.child = SaveTreeViewNodes(subNodes); } } return firstSibling; From f2a68351c8e3aeb60613f69aac3a4bf48b07e973 Mon Sep 17 00:00:00 2001 From: betato Date: Wed, 16 Sep 2020 19:03:35 -0400 Subject: [PATCH 09/17] Save file view expansions only for folders in expanded path --- RocketcadManagerLib/Config.cs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/RocketcadManagerLib/Config.cs b/RocketcadManagerLib/Config.cs index 9ee0767..cd9b1c9 100644 --- a/RocketcadManagerLib/Config.cs +++ b/RocketcadManagerLib/Config.cs @@ -31,6 +31,7 @@ public static void Save(Config config) { ConstantPaths.ConfigFile.Directory.Create(); File.WriteAllText(ConstantPaths.ConfigFile.FullName, JsonConvert.SerializeObject(config)); + File.WriteAllText(ConstantPaths.ConfigFile.FullName, JsonConvert.SerializeObject(config, Formatting.Indented)); } private class FolderNode @@ -41,10 +42,11 @@ private class FolderNode public string Name { get; private set; } public bool Expanded { get; private set; } - public FolderNode(string name, bool expanded) + public FolderNode(string name, bool expanded, FolderNode child) { Name = name; Expanded = expanded; + this.child = child; } public void Clear() @@ -65,24 +67,33 @@ public void SaveTreeViewExpansion(TreeNodeCollection treeNodes) private FolderNode SaveTreeViewNodes(TreeNodeCollection treeNodes) { - FolderNode firstSibling = null; FolderNode currentSibling = null; + FolderNode firstSibling = null; + // Add all nodes that are expanded or have expanded children foreach (TreeNode treeNode in treeNodes) { + // For all sibling nodes in the collection TreeNodeCollection subNodes = treeNode.Nodes; - if (subNodes.Count > 0) // Node has children and is expandable + if (subNodes.Count <= 0) + continue; // Node does not have children and is not expandable + + FolderNode childNode = SaveTreeViewNodes(subNodes); + // Add node if it is expanded + // Add node if it has a child (their last child will be expanded) + if (treeNode.IsExpanded || childNode != null) { if (firstSibling == null) { - firstSibling = new FolderNode(treeNode.Text, treeNode.IsExpanded); - currentSibling = firstSibling; + // Set first sibling + currentSibling = new FolderNode(treeNode.Text, treeNode.IsExpanded, childNode); + firstSibling = currentSibling; } else { - currentSibling.sibling = new FolderNode(treeNode.Name, treeNode.IsExpanded); + // Set next sibling + currentSibling.sibling = new FolderNode(treeNode.Text, treeNode.IsExpanded, childNode); currentSibling = currentSibling.sibling; } - currentSibling.child = SaveTreeViewNodes(subNodes); } } return firstSibling; From dba33efd726492689f7e92e6de49590fa1cc5dac Mon Sep 17 00:00:00 2001 From: betato Date: Wed, 16 Sep 2020 19:16:37 -0400 Subject: [PATCH 10/17] Add file view expansion loading --- RocketcadManager/MainForm.cs | 17 ++++------------- RocketcadManagerLib/Config.cs | 34 +++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/RocketcadManager/MainForm.cs b/RocketcadManager/MainForm.cs index 11195a4..ef7b591 100644 --- a/RocketcadManager/MainForm.cs +++ b/RocketcadManager/MainForm.cs @@ -85,11 +85,8 @@ private void LoadFiles() { fileView.Nodes.Add(cadFolder.DirectoryTree()); } - // Expand top-level nodes - foreach (TreeNode node in fileView.Nodes) - { - node.Expand(); - } + // Expand nodes + config.LoadTreeViewExpansion(fileView.Nodes); toolStripStatusLabel1.Text = "Ready"; } @@ -309,14 +306,6 @@ private void fileView_AfterSelect(object sender, TreeViewEventArgs e) SelectComponent((CadComponent)component); } - private void textBoxStock_KeyPress(object sender, KeyPressEventArgs e) - { - if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)) - { - e.Handled = true; - } - } - private void SaveSelected() { // TODO: Add text checking @@ -346,6 +335,7 @@ private void toolStripSettings_Click(object sender, EventArgs e) SettingsForm settingsWindow = new SettingsForm(config); if (settingsWindow.ShowDialog(this) == DialogResult.OK) { + config.SaveTreeViewExpansion(fileView.Nodes); Config.Save(config); LoadFiles(); } @@ -353,6 +343,7 @@ private void toolStripSettings_Click(object sender, EventArgs e) private void toolStripRefresh_Click(object sender, EventArgs e) { + config.SaveTreeViewExpansion(fileView.Nodes); LoadFiles(); } diff --git a/RocketcadManagerLib/Config.cs b/RocketcadManagerLib/Config.cs index cd9b1c9..0bc4b4d 100644 --- a/RocketcadManagerLib/Config.cs +++ b/RocketcadManagerLib/Config.cs @@ -30,7 +30,6 @@ public static void Open(out Config config) public static void Save(Config config) { ConstantPaths.ConfigFile.Directory.Create(); - File.WriteAllText(ConstantPaths.ConfigFile.FullName, JsonConvert.SerializeObject(config)); File.WriteAllText(ConstantPaths.ConfigFile.FullName, JsonConvert.SerializeObject(config, Formatting.Indented)); } @@ -67,19 +66,18 @@ public void SaveTreeViewExpansion(TreeNodeCollection treeNodes) private FolderNode SaveTreeViewNodes(TreeNodeCollection treeNodes) { + // Add all nodes that are expanded or have expanded children FolderNode currentSibling = null; FolderNode firstSibling = null; - // Add all nodes that are expanded or have expanded children foreach (TreeNode treeNode in treeNodes) { // For all sibling nodes in the collection TreeNodeCollection subNodes = treeNode.Nodes; if (subNodes.Count <= 0) - continue; // Node does not have children and is not expandable + continue; // Node does not have children and is therefore not expandable FolderNode childNode = SaveTreeViewNodes(subNodes); - // Add node if it is expanded - // Add node if it has a child (their last child will be expanded) + // Add a node if it is expanded or if it has a child (the last child will be expanded) if (treeNode.IsExpanded || childNode != null) { if (firstSibling == null) @@ -98,5 +96,31 @@ private FolderNode SaveTreeViewNodes(TreeNodeCollection treeNodes) } return firstSibling; } + + public void LoadTreeViewExpansion(TreeNodeCollection treeNodes) + { + LoadTreeViewNodes(treeNodes, folderViewExpansion); + } + + private void LoadTreeViewNodes(TreeNodeCollection treeNodes, FolderNode folderNode) + { + // Loop through all sibling nodes + while (folderNode != null) + { + // TODO: Don't reiterate over already expanded nodes + foreach (TreeNode treeNode in treeNodes) + { + if (treeNode.Text == folderNode.Name) + { + if (folderNode.Expanded) + treeNode.Expand(); + if (folderNode.child != null) + LoadTreeViewNodes(treeNode.Nodes, folderNode.child); + break; + } + } + folderNode = folderNode.sibling; + } + } } } From 5efcfd9395469798873c4e7be4172511209a8418 Mon Sep 17 00:00:00 2001 From: betato Date: Wed, 16 Sep 2020 20:08:21 -0400 Subject: [PATCH 11/17] Save config as non-indented json --- RocketcadManagerLib/Config.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RocketcadManagerLib/Config.cs b/RocketcadManagerLib/Config.cs index 0bc4b4d..59e8b0d 100644 --- a/RocketcadManagerLib/Config.cs +++ b/RocketcadManagerLib/Config.cs @@ -30,7 +30,7 @@ public static void Open(out Config config) public static void Save(Config config) { ConstantPaths.ConfigFile.Directory.Create(); - File.WriteAllText(ConstantPaths.ConfigFile.FullName, JsonConvert.SerializeObject(config, Formatting.Indented)); + File.WriteAllText(ConstantPaths.ConfigFile.FullName, JsonConvert.SerializeObject(config)); } private class FolderNode From 184161fd231d41abc0b34f48bdf2eb6471c8209b Mon Sep 17 00:00:00 2001 From: betato Date: Wed, 16 Sep 2020 20:15:04 -0400 Subject: [PATCH 12/17] Add question mark icons --- RocketcadManager/Icons.Designer.cs | 40 ++++++++++++++++++ RocketcadManager/Icons.resx | 12 ++++++ RocketcadManager/Resources/QuestionFile16.png | Bin 0 -> 510 bytes .../Resources/QuestionFolder16.png | Bin 0 -> 430 bytes .../Resources/WarningErrorFile16.png | Bin 0 -> 474 bytes .../Resources/WarningErrorFolder16.png | Bin 0 -> 417 bytes .../Resources/WarningQuestionFile16.png | Bin 0 -> 485 bytes .../Resources/WarningQuestionFolder16.png | Bin 0 -> 444 bytes RocketcadManager/RocketcadManager.csproj | 6 +++ 9 files changed, 58 insertions(+) create mode 100644 RocketcadManager/Resources/QuestionFile16.png create mode 100644 RocketcadManager/Resources/QuestionFolder16.png create mode 100644 RocketcadManager/Resources/WarningErrorFile16.png create mode 100644 RocketcadManager/Resources/WarningErrorFolder16.png create mode 100644 RocketcadManager/Resources/WarningQuestionFile16.png create mode 100644 RocketcadManager/Resources/WarningQuestionFolder16.png diff --git a/RocketcadManager/Icons.Designer.cs b/RocketcadManager/Icons.Designer.cs index 33a5f31..5b4d7a8 100644 --- a/RocketcadManager/Icons.Designer.cs +++ b/RocketcadManager/Icons.Designer.cs @@ -120,6 +120,26 @@ internal static System.Drawing.Bitmap OpenFolder { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap QuestionFile { + get { + object obj = ResourceManager.GetObject("QuestionFile", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap QuestionFolder { + get { + object obj = ResourceManager.GetObject("QuestionFolder", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -180,6 +200,26 @@ internal static System.Drawing.Bitmap WarningFolder { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap WarningQuestionFile { + get { + object obj = ResourceManager.GetObject("WarningQuestionFile", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap WarningQuestionFolder { + get { + object obj = ResourceManager.GetObject("WarningQuestionFolder", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/RocketcadManager/Icons.resx b/RocketcadManager/Icons.resx index d80164e..5e2013e 100644 --- a/RocketcadManager/Icons.resx +++ b/RocketcadManager/Icons.resx @@ -136,6 +136,12 @@ Resources\OpenFolder.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + Resources\QuestionFile16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + Resources\QuestionFolder16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + Resources\Refresh21.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -154,6 +160,12 @@ Resources\WarningFolder.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + Resources\WarningQuestionFile16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + Resources\WarningQuestionFolder16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + Resources\Warning20.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a diff --git a/RocketcadManager/Resources/QuestionFile16.png b/RocketcadManager/Resources/QuestionFile16.png new file mode 100644 index 0000000000000000000000000000000000000000..5e02e557b562a485bacc5352bce80253cdaf0e78 GIT binary patch literal 510 zcmVPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!~g&e!~vBn4jTXf0h38YK~y+TZBx5a z!ax+gD=Dzk8GgbKu)$g?TWcw?(MlUDD+>z2Mx)V?1u0nWSEKMynWu8rA@9QT zaLDbGw&v|0-aWc18xt5=S$=eFCtN54sV=HrgdKDJ@Pg^=Q?|>%8ulRODWK057@2m& zbGUa*+~2p$9e0$KUyqQ#Ki>9P$nY!2j6>eyx(x40000007*qoM6N<$f=OrF A-T(jq literal 0 HcmV?d00001 diff --git a/RocketcadManager/Resources/QuestionFolder16.png b/RocketcadManager/Resources/QuestionFolder16.png new file mode 100644 index 0000000000000000000000000000000000000000..31862b8c4629d7fd9c7163daa2db95cb9e0a7222 GIT binary patch literal 430 zcmV;f0a5;mP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!T|pZ7Eo+e?Sn0v#}DfS2z?_tBZNb z%ueP!xP9DAGReHRN#=-|1MvO4FRu9ZGaGZ>S0mf}<}Kme2z>STcy{?%Je-H|rdVZ{ z_VfKFEJT4RYzozxOt!q3h(^F-ZOB8)o!ZHQPQVJtEyTz_l-0NvqJk_` z!TMAl<60?apu3S_>#Ie5ss!HxfLwjoqvn6`aleyX6-oZ;`MM4Z6G>@&`Sq+HmbNPT Y17iRA>`-fo`2YX_07*qoM6N<$f>g)1?f?J) literal 0 HcmV?d00001 diff --git a/RocketcadManager/Resources/WarningErrorFile16.png b/RocketcadManager/Resources/WarningErrorFile16.png new file mode 100644 index 0000000000000000000000000000000000000000..e9d828588c2e52c5c28d6d9941e23e021d9a4dfd GIT binary patch literal 474 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1G~mUKs7M+SzC z{oH>NS%Lhn0G|+7AiZ?y(#1=bELyZ^;lhRU=P#HyZ{D1_b7#+f4zG3>gv_2(`U^5@$+X- zPtSx&lYad8`TfVw-@pI#Png)--~au`kDlJX|2r9$stJFv5}z?+=AZiv|MxKb|NsBb zL!c`dwp_N|1*G&!g8YJkg2V%crvBnkpia&LkH}&M2EHR8%s5q>PZ}sV-_yl0L?hVu zT(nq|0T0WCQ_{Le*&{@kELhet;cxzV6*=2;_wOw86@8?|vDm_MbIo2ymnMhoSc&9Q zZ}ap8UO9)#uhsQ`-tDkt^{fS&x4&r#WWU??GRB@mg|+;)<@Nh4L5KGizPo47V#Hi? zu$ZNY;l&(z%XtquFL(d)sg<*3^vPn9nsJjwY^%YEGxjy=2@f0QoR((kda%8NS%Li00G|+7ApPm0@5c*1AJ6-I0HSj~@6UR_KjZ!GwAb5HUT;r&{(rsr|LaBn zUoZIoYX1LMbN|1Z^Z(_n|1W3$e=+_4i)n9w3SLZkbHelg^GUBk|8t+=|NsAg9x^;T2(pn`sMG^Ush0%#1p~#201VAx({BQ`a29w( z7BevL9ROj*tZSW|K*1(Y7sn8dVBd4$LWdQ2Tmv69dG=r4Z6NTrzH_3SuX}-h6lL@52hFE!UoNFW9{A9>dMmq)ldmuxPXw}?S?x`)^%sRcV0HO#I5ksEMPan55tM)idCCuWy^=;yCzyfs7G Vyl?8%R-kJbJYD@<);T3K0RRX#({BI( literal 0 HcmV?d00001 diff --git a/RocketcadManager/Resources/WarningQuestionFile16.png b/RocketcadManager/Resources/WarningQuestionFile16.png new file mode 100644 index 0000000000000000000000000000000000000000..15485e4076c2d763f928a88d358499a41d344907 GIT binary patch literal 485 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1G~mUKs7M+SzC z{oH>NS%LiC0G|+7AiZ?y(#1=bELyZ^;lhRU=P#HyZ{D1_b7#+f4zG3>gv_2(`U^5@$+X- zPtSx&lYad8`TfVw-@pI#Png)--_Pk<%Hdkd>00uCCj&#?ssI1~&zLdu&wU0?my$mZ z88}?afG*k6ajG3i>6Zlg1p^h302rc{T6_m;b|fr86CT^vI+ zf_2Zm7HU!uU`_axr&xAzg~`?NS%Lhz0G|+7ApPm0@5c*1AJ6-I0HSj~@6UR_KjZ!GwAb5HUT;r&{(rsr|LaBn zUoZIoYX1LMbN|1Z^Z(_n|1W3$e=+_4i)n9w3SLZkbHelg^GUBkkb#WGWL>4nJ@a+d-Mhn(p6`acw9GfAH92PS9Yeria-DP zt0tH2Ft(XvY|g2*G&C@5>$P6P*S=l?N6WU`%lNMa`1~ux|-;g?k$Z!5-HZ!k(Q=>=rY5@AFLdoPDLM&loAP@!xA`4>>zJiUVw|+ syax&FEnP7W+0H#$rV>%3`{$B;%PpD3$}E?FE@fcwboFyt=akR{0DQ;V6951J literal 0 HcmV?d00001 diff --git a/RocketcadManager/RocketcadManager.csproj b/RocketcadManager/RocketcadManager.csproj index 8e6d872..81eeacd 100644 --- a/RocketcadManager/RocketcadManager.csproj +++ b/RocketcadManager/RocketcadManager.csproj @@ -161,6 +161,12 @@ + + + + + + \ No newline at end of file From db34aeb6d61884d879cdf8b8f26340dbadcd6058 Mon Sep 17 00:00:00 2001 From: betato Date: Wed, 16 Sep 2020 20:21:02 -0400 Subject: [PATCH 13/17] Use question icons for missing info files --- RocketcadManager/CadComponent.cs | 14 ++++++++++++-- RocketcadManager/MainForm.cs | 4 ++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/RocketcadManager/CadComponent.cs b/RocketcadManager/CadComponent.cs index ef2c084..818aec5 100644 --- a/RocketcadManager/CadComponent.cs +++ b/RocketcadManager/CadComponent.cs @@ -53,22 +53,32 @@ public TreeNode GetNode() thisNode.Text = ComponentFileInfo.Name; if (!NameOk()) { - if (!HasInfo || MissingComponentError) + if (MissingComponentError) { thisNode.ImageKey = "WarningErrorFile"; thisNode.SelectedImageKey = "WarningErrorFile"; } + else if (!HasInfo) + { + thisNode.ImageKey = "WarningQuestionFile"; + thisNode.SelectedImageKey = "WarningQuestionFile"; + } else { thisNode.ImageKey = "WarningFile"; thisNode.SelectedImageKey = "WarningFile"; } } - else if (!HasInfo || MissingComponentError) + else if (MissingComponentError) { thisNode.ImageKey = "ErrorFile"; thisNode.SelectedImageKey = "ErrorFile"; } + else if (!HasInfo) + { + thisNode.ImageKey = "QuestionFile"; + thisNode.SelectedImageKey = "QuestionFile"; + } else { thisNode.ImageKey = "File"; diff --git a/RocketcadManager/MainForm.cs b/RocketcadManager/MainForm.cs index ef7b591..c3523cc 100644 --- a/RocketcadManager/MainForm.cs +++ b/RocketcadManager/MainForm.cs @@ -53,6 +53,10 @@ private void Form1_Load(object sender, EventArgs e) imageList.Images.Add("ErrorFolder", Icons.ErrorFolder); imageList.Images.Add("WarningErrorFile", Icons.WarningErrorFile); imageList.Images.Add("WarningErrorFolder", Icons.WarningErrorFolder); + imageList.Images.Add("QuestionFile", Icons.QuestionFile); + imageList.Images.Add("QuestionFolder", Icons.QuestionFolder); + imageList.Images.Add("WarningQuestionFile", Icons.WarningQuestionFile); + imageList.Images.Add("WarningQuestionFolder", Icons.WarningQuestionFolder); fileView.ImageList = imageList; LoadFiles(); From 5e806f2f097a5709de24f02c9bb061bdbc3a19a9 Mon Sep 17 00:00:00 2001 From: betato Date: Wed, 16 Sep 2020 20:40:31 -0400 Subject: [PATCH 14/17] Clean up image key assignment --- RocketcadManager/CadComponent.cs | 36 +++++++++++--------------------- RocketcadManager/Folder.cs | 25 ++++++++++------------ 2 files changed, 23 insertions(+), 38 deletions(-) diff --git a/RocketcadManager/CadComponent.cs b/RocketcadManager/CadComponent.cs index 818aec5..5557c0a 100644 --- a/RocketcadManager/CadComponent.cs +++ b/RocketcadManager/CadComponent.cs @@ -54,39 +54,27 @@ public TreeNode GetNode() if (!NameOk()) { if (MissingComponentError) - { - thisNode.ImageKey = "WarningErrorFile"; - thisNode.SelectedImageKey = "WarningErrorFile"; - } + SetImageKey(thisNode, "WarningErrorFile"); else if (!HasInfo) - { - thisNode.ImageKey = "WarningQuestionFile"; - thisNode.SelectedImageKey = "WarningQuestionFile"; - } + SetImageKey(thisNode, "WarningQuestionFile"); else - { - thisNode.ImageKey = "WarningFile"; - thisNode.SelectedImageKey = "WarningFile"; - } + SetImageKey(thisNode, "WarningFile"); } else if (MissingComponentError) - { - thisNode.ImageKey = "ErrorFile"; - thisNode.SelectedImageKey = "ErrorFile"; - } + SetImageKey(thisNode, "File"); else if (!HasInfo) - { - thisNode.ImageKey = "QuestionFile"; - thisNode.SelectedImageKey = "QuestionFile"; - } + SetImageKey(thisNode, "File"); else - { - thisNode.ImageKey = "File"; - thisNode.SelectedImageKey = "File"; - } + SetImageKey(thisNode, "File"); return thisNode; } + private void SetImageKey(TreeNode node, string imageKey) + { + node.ImageKey = imageKey; + node.SelectedImageKey = imageKey; + } + public virtual bool NameOk() { return Regex.IsMatch(ComponentFileInfo.Name, @"^([0-9]{2}-)+[0-9]{2}(\s.*)*\.(?i)(SLDASM|SLDPRT)(?-i)$"); diff --git a/RocketcadManager/Folder.cs b/RocketcadManager/Folder.cs index ec42c5d..76f96f4 100644 --- a/RocketcadManager/Folder.cs +++ b/RocketcadManager/Folder.cs @@ -31,31 +31,28 @@ public TreeNode DirectoryTree() thisNode.Text = Path.Name; if (NameOk()) - { - thisNode.ImageKey = "Folder"; - thisNode.SelectedImageKey = "Folder"; - } + SetImageKey(thisNode, "Folder"); else - { - thisNode.ImageKey = "WarningFolder"; - thisNode.SelectedImageKey = "WarningFolder"; - } + SetImageKey(thisNode, "WarningFolder"); foreach (Folder folder in subFolders) - { thisNode.Nodes.Add(folder.DirectoryTree()); - } + foreach (Assembly assembly in assemblies) - { thisNode.Nodes.Add(assembly.GetNode()); - } + foreach (Part part in parts) - { thisNode.Nodes.Add(part.GetNode()); - } + return thisNode; } + private void SetImageKey(TreeNode node, string imageKey) + { + node.ImageKey = imageKey; + node.SelectedImageKey = imageKey; + } + public bool IsEmpty() { // Contains no parts or assemblies From 15ba8c0770ea651b865d2cb33c9c5be59b8438b5 Mon Sep 17 00:00:00 2001 From: betato Date: Wed, 16 Sep 2020 20:52:14 -0400 Subject: [PATCH 15/17] Correct file thumbnails --- RocketcadManager/CadComponent.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RocketcadManager/CadComponent.cs b/RocketcadManager/CadComponent.cs index 5557c0a..20d76ab 100644 --- a/RocketcadManager/CadComponent.cs +++ b/RocketcadManager/CadComponent.cs @@ -61,9 +61,9 @@ public TreeNode GetNode() SetImageKey(thisNode, "WarningFile"); } else if (MissingComponentError) - SetImageKey(thisNode, "File"); + SetImageKey(thisNode, "ErrorFile"); else if (!HasInfo) - SetImageKey(thisNode, "File"); + SetImageKey(thisNode, "QuestionFile"); else SetImageKey(thisNode, "File"); return thisNode; From 6da23e2fd5d640527d6798132c1d39135be1844f Mon Sep 17 00:00:00 2001 From: betato Date: Wed, 16 Sep 2020 20:52:43 -0400 Subject: [PATCH 16/17] Add thumbnails to warnings list --- RocketcadManager/MainForm.cs | 32 ++++++++++++------------ RocketcadManager/WarningsListForm.cs | 37 +++++++++++++--------------- 2 files changed, 33 insertions(+), 36 deletions(-) diff --git a/RocketcadManager/MainForm.cs b/RocketcadManager/MainForm.cs index c3523cc..40c9d1a 100644 --- a/RocketcadManager/MainForm.cs +++ b/RocketcadManager/MainForm.cs @@ -31,6 +31,7 @@ private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionE } private Config config; + private ImageList iconList = new ImageList(); private Dictionary parts = new Dictionary(); private Dictionary assemblies = new Dictionary(); @@ -43,21 +44,20 @@ private void Form1_Load(object sender, EventArgs e) { Config.Open(out config); - ImageList imageList = new ImageList(); - imageList.ColorDepth = ColorDepth.Depth32Bit; - imageList.Images.Add("File", Icons.File); - imageList.Images.Add("Folder", Icons.Folder); - imageList.Images.Add("WarningFile", Icons.WarningFile); - imageList.Images.Add("WarningFolder", Icons.WarningFolder); - imageList.Images.Add("ErrorFile", Icons.ErrorFile); - imageList.Images.Add("ErrorFolder", Icons.ErrorFolder); - imageList.Images.Add("WarningErrorFile", Icons.WarningErrorFile); - imageList.Images.Add("WarningErrorFolder", Icons.WarningErrorFolder); - imageList.Images.Add("QuestionFile", Icons.QuestionFile); - imageList.Images.Add("QuestionFolder", Icons.QuestionFolder); - imageList.Images.Add("WarningQuestionFile", Icons.WarningQuestionFile); - imageList.Images.Add("WarningQuestionFolder", Icons.WarningQuestionFolder); - fileView.ImageList = imageList; + iconList.ColorDepth = ColorDepth.Depth32Bit; + iconList.Images.Add("File", Icons.File); + iconList.Images.Add("Folder", Icons.Folder); + iconList.Images.Add("WarningFile", Icons.WarningFile); + iconList.Images.Add("WarningFolder", Icons.WarningFolder); + iconList.Images.Add("ErrorFile", Icons.ErrorFile); + iconList.Images.Add("ErrorFolder", Icons.ErrorFolder); + iconList.Images.Add("WarningErrorFile", Icons.WarningErrorFile); + iconList.Images.Add("WarningErrorFolder", Icons.WarningErrorFolder); + iconList.Images.Add("QuestionFile", Icons.QuestionFile); + iconList.Images.Add("QuestionFolder", Icons.QuestionFolder); + iconList.Images.Add("WarningQuestionFile", Icons.WarningQuestionFile); + iconList.Images.Add("WarningQuestionFolder", Icons.WarningQuestionFolder); + fileView.ImageList = iconList; LoadFiles(); } @@ -438,7 +438,7 @@ private void toolStripWarnings_Click(object sender, EventArgs e) List cadComponents = new List(); cadComponents.AddRange(parts.Values.ToList()); cadComponents.AddRange(assemblies.Values.ToList()); - WarningsListForm warningsList = new WarningsListForm(cadComponents); + WarningsListForm warningsList = new WarningsListForm(cadComponents, iconList); warningsList.ShowDialog(this); } } diff --git a/RocketcadManager/WarningsListForm.cs b/RocketcadManager/WarningsListForm.cs index e2be324..3a3ba89 100644 --- a/RocketcadManager/WarningsListForm.cs +++ b/RocketcadManager/WarningsListForm.cs @@ -14,44 +14,41 @@ partial class WarningsListForm : Form { private List cadComponents; - public WarningsListForm(List cadComponents) + public WarningsListForm(List cadComponents, ImageList imageList) { this.cadComponents = cadComponents; InitializeComponent(); + listViewWarnings.SmallImageList = imageList; } private void WarningsListForm_Load(object sender, EventArgs e) { foreach (CadComponent cadComponent in cadComponents) { - string name = cadComponent.ComponentFileInfo.Name; - string file = cadComponent.ComponentFileInfo.FullName; - string[] entry = { name, null, file }; if (!cadComponent.HasInfo) - { - entry[1] = "Missing info file"; - listViewWarnings.Items.Add(new ListViewItem(entry)); - } + AddWarning(cadComponent, "Missing info file", "QuestionFile"); if (cadComponent.LoadingError) - { - entry[1] = "Error loading info file"; - listViewWarnings.Items.Add(new ListViewItem(entry)); - } + AddWarning(cadComponent, "Error loading info file", "ErrorFile"); if (!cadComponent.NameOk()) - { - entry[1] = "Naming violation"; - listViewWarnings.Items.Add(new ListViewItem(entry)); - } + AddWarning(cadComponent, "Naming violation", "WarningFile"); if (cadComponent.MissingComponentError) - { - entry[1] = "Referenced components not found"; - listViewWarnings.Items.Add(new ListViewItem(entry)); - } + AddWarning(cadComponent, "Referenced components not found", "ErrorFile"); } foreach (ColumnHeader column in listViewWarnings.Columns) { column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); } } + + private void AddWarning(CadComponent cadComponent, string message, string imageKey) + { + string name = cadComponent.ComponentFileInfo.Name; + string file = cadComponent.ComponentFileInfo.FullName; + string[] entry = { name, message, file }; + + ListViewItem listItem = new ListViewItem(entry); + listItem.ImageKey = imageKey; + listViewWarnings.Items.Add(listItem); + } } } From c781a6396bab8aca3a5bcabaed71ec43784da389 Mon Sep 17 00:00:00 2001 From: betato Date: Wed, 16 Sep 2020 21:17:16 -0400 Subject: [PATCH 17/17] Add multiple warnings to warnings list --- RocketcadManager/CadComponent.cs | 4 +-- RocketcadManager/WarningsListForm.Designer.cs | 2 +- RocketcadManager/WarningsListForm.cs | 32 ++++++++++++++++--- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/RocketcadManager/CadComponent.cs b/RocketcadManager/CadComponent.cs index 20d76ab..2e52cf6 100644 --- a/RocketcadManager/CadComponent.cs +++ b/RocketcadManager/CadComponent.cs @@ -53,14 +53,14 @@ public TreeNode GetNode() thisNode.Text = ComponentFileInfo.Name; if (!NameOk()) { - if (MissingComponentError) + if (MissingComponentError || LoadingError) SetImageKey(thisNode, "WarningErrorFile"); else if (!HasInfo) SetImageKey(thisNode, "WarningQuestionFile"); else SetImageKey(thisNode, "WarningFile"); } - else if (MissingComponentError) + else if (MissingComponentError || LoadingError) SetImageKey(thisNode, "ErrorFile"); else if (!HasInfo) SetImageKey(thisNode, "QuestionFile"); diff --git a/RocketcadManager/WarningsListForm.Designer.cs b/RocketcadManager/WarningsListForm.Designer.cs index f01ffb4..0212043 100644 --- a/RocketcadManager/WarningsListForm.Designer.cs +++ b/RocketcadManager/WarningsListForm.Designer.cs @@ -56,7 +56,7 @@ private void InitializeComponent() // // columnHeaderError // - this.columnHeaderError.Text = "Error"; + this.columnHeaderError.Text = "Errors"; this.columnHeaderError.Width = 40; // // columnHeaderFile diff --git a/RocketcadManager/WarningsListForm.cs b/RocketcadManager/WarningsListForm.cs index 3a3ba89..37cac4a 100644 --- a/RocketcadManager/WarningsListForm.cs +++ b/RocketcadManager/WarningsListForm.cs @@ -25,14 +25,36 @@ private void WarningsListForm_Load(object sender, EventArgs e) { foreach (CadComponent cadComponent in cadComponents) { + // Create error string + StringBuilder errorStrBuilder = new StringBuilder(); + if (!cadComponent.NameOk()) + errorStrBuilder.Append("Naming violation, "); if (!cadComponent.HasInfo) - AddWarning(cadComponent, "Missing info file", "QuestionFile"); + errorStrBuilder.Append("Missing info file, "); + if (cadComponent.MissingComponentError) + errorStrBuilder.Append("Referenced components not found, "); if (cadComponent.LoadingError) - AddWarning(cadComponent, "Error loading info file", "ErrorFile"); + errorStrBuilder.Append("Error loading info file, "); + if (errorStrBuilder.Length <= 0) + continue; // No errors + errorStrBuilder.Length -= 2; // Trim trailing comma and space + string errorStr = errorStrBuilder.ToString(); + + // Set error icons + // TODO: Combine this with the similar CadComponent method if (!cadComponent.NameOk()) - AddWarning(cadComponent, "Naming violation", "WarningFile"); - if (cadComponent.MissingComponentError) - AddWarning(cadComponent, "Referenced components not found", "ErrorFile"); + { + 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"); } foreach (ColumnHeader column in listViewWarnings.Columns) {