From e5c4e1484ee9290f7dec1eb773dac65fa5ca4f40 Mon Sep 17 00:00:00 2001 From: Brett Parker Date: Wed, 19 Apr 2023 18:54:25 +0100 Subject: [PATCH 1/5] Export class added Allows for export to word --- BinaryDetail.cs | 7 -- BinaryDetailFactory.cs | 2 - BinaryDetailer.csproj | 5 + Export.cs | 205 +++++++++++++++++++++++++++++++++++++++++ Program.cs | 39 ++------ README.md | 2 +- 6 files changed, 221 insertions(+), 39 deletions(-) create mode 100644 Export.cs diff --git a/BinaryDetail.cs b/BinaryDetail.cs index 66b3d0d..0c0db4f 100644 --- a/BinaryDetail.cs +++ b/BinaryDetail.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; @@ -9,7 +8,6 @@ namespace BinaryDetailer [Serializable] public class BinaryDetail { - public BinaryDetail(FileInfo fileInfo) { FileInfo = fileInfo; @@ -23,15 +21,11 @@ public BinaryDetail(FileInfo fileInfo) public ProcessorArchitecture ProcessorArchitecture { get; internal set; } public string TargetFrameworkAttribute { get; internal set; } public string AssemblyVersion { get; internal set; } - public string FileVersion => FileVersionInfo.GetVersionInfo(FileInfo.FullName).FileVersion; - public string ProductVersion => FileVersionInfo.GetVersionInfo(FileInfo.FullName).ProductVersion; - public string AssemblyCompanyAttribute => FileVersionInfo.GetVersionInfo(FileInfo.FullName).CompanyName; public string AssemblyCopyrightAttribute => FileVersionInfo.GetVersionInfo(FileInfo.FullName).LegalCopyright; - public static string[] CSVHeader { get @@ -43,7 +37,6 @@ public static string[] CSVHeader } } - public string ToCsv() { return diff --git a/BinaryDetailFactory.cs b/BinaryDetailFactory.cs index a47321a..58feb1a 100644 --- a/BinaryDetailFactory.cs +++ b/BinaryDetailFactory.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; @@ -77,7 +76,6 @@ private AppDomain BuildChildDomain(AppDomain parentDomain) evidence, setup); } - private class BinaryDetailPopulator : MarshalByRefObject { [SuppressMessage("Microsoft.Performance", diff --git a/BinaryDetailer.csproj b/BinaryDetailer.csproj index dcb669e..765bdd0 100644 --- a/BinaryDetailer.csproj +++ b/BinaryDetailer.csproj @@ -33,12 +33,14 @@ 4 + + @@ -50,6 +52,9 @@ 1.5.1 + + 15.0.4797.1004 + diff --git a/Export.cs b/Export.cs new file mode 100644 index 0000000..a40922d --- /dev/null +++ b/Export.cs @@ -0,0 +1,205 @@ +using Microsoft.Office.Interop.Word; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; + +namespace BinaryDetailer +{ + public class Export + { + readonly List ExcludeNames = new List(); + + public Export(List excludeNames) + { + ExcludeNames = excludeNames; + } + + public void CreateReport(List binaryDetails) + { + string csvFileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), + Guid.NewGuid() + ".csv"); + File.Create(csvFileName).Close(); + File.AppendAllLines(csvFileName, BinaryDetail.CSVHeader); + foreach (var binaryDetail in binaryDetails) + { + bool include = true; + foreach (string excludeName in ExcludeNames) + { + if ((binaryDetail.AssemblyCompanyAttribute != null && binaryDetail.AssemblyCompanyAttribute.ToLower().Contains(excludeName)) || + (binaryDetail.AssemblyCopyrightAttribute != null && binaryDetail.AssemblyCopyrightAttribute.ToLower().Contains(excludeName))) + { + include = false; + } + } + + if (include == false) continue; + + File.AppendAllLines(csvFileName, new[] { binaryDetail.ToCsv() }); + } + + Console.WriteLine("File created at " + csvFileName); + } + + public void CreateWordDoc(List binaryDetails) + { + try + { + string wordFileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), + Guid.NewGuid() + ".docx"); + + //Create an instance for word app + Application winword = new Application + { + ShowAnimation = false, + Visible = false + }; + + //Create a missing variable for missing value + object missing = Missing.Value; + + //Create a new document + Document document = winword.Documents.Add(ref missing, ref missing, ref missing, ref missing); + document.PageSetup.Orientation = WdOrientation.wdOrientLandscape; + + //Add header into the document + foreach (Section section in document.Sections) + { + //Get the header range and add the header details. + Range headerRange = section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range; + headerRange.Fields.Add(headerRange, WdFieldType.wdFieldPage); + headerRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; + headerRange.Font.ColorIndex = WdColorIndex.wdBlue; + headerRange.Font.Size = 10; + headerRange.Text = "Binary Detailer"; + } + + //Add the footers into the document + foreach (Section wordSection in document.Sections) + { + //Get the footer range and add the footer details. + Range footerRange = wordSection.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range; + footerRange.Font.ColorIndex = WdColorIndex.wdDarkRed; + footerRange.Font.Size = 10; + footerRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; + footerRange.Text = "Github repository: https://github.com/stuartjsmith/binarydetailer"; + } + + //adding text to document + document.Content.SetRange(0, 0); + string firstLine = "Binary Detailer is a method of outputting binary details such as net framework, " + + "64-bit compatibility, version etc. Given a directory name, it will iterate dll and exe files " + + "and output the results to a csv file."; + + document.Content.Text = firstLine + Environment.NewLine; + + //Add paragraph with Heading 1 style + Paragraph para1 = document.Content.Paragraphs.Add(ref missing); + object styleHeading1 = "Heading 1"; + para1.Range.set_Style(ref styleHeading1); + para1.Range.Text = "Binary Details"; + para1.Range.InsertParagraphAfter(); + + //Create a 5X5 table and insert some dummy record (+1 in count to allow for a column heading) + Table firstTable = document.Tables.Add(para1.Range, binaryDetails.Count + 1, 4, ref missing, ref missing); + + // Define column headings + WordColumnHeadings(firstTable); + + firstTable.Borders.Enable = 1; + foreach (var binaryDetail in binaryDetails.Select((value, i) => new { i, value })) + { + + bool include = true; + foreach (string excludeName in ExcludeNames) + { + if ((binaryDetail.value.AssemblyCompanyAttribute != null && binaryDetail.value.AssemblyCompanyAttribute.ToLower().Contains(excludeName)) || + (binaryDetail.value.AssemblyCopyrightAttribute != null && binaryDetail.value.AssemblyCopyrightAttribute.ToLower().Contains(excludeName))) + { + include = false; + } + } + + if (include == false) continue; + + // Passing the index + 2 as there is a heading column to overcome. + WordRowData(binaryDetail.i + 2, firstTable, binaryDetail.value); + } + + //Save the document + object filename = wordFileName; + document.SaveAs2(ref filename); + document.Close(ref missing, ref missing, ref missing); + document = null; + winword.Quit(ref missing, ref missing, ref missing); + winword = null; + Console.WriteLine("Word Document created at " + filename); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } + + public void WordColumnHeadings(Table firstTable) + { + // Loop through each cell in the row + foreach (Cell cell in firstTable.Rows[1].Cells) + { + // Switch between the columns + switch (cell.ColumnIndex) + { + case 1: + cell.Range.Text = "File Name"; + break; + case 2: + cell.Range.Text = "Assembly Company Attribute"; + break; + case 3: + cell.Range.Text = "Assembly Version"; + break; + case 4: + cell.Range.Text = "File Version"; + break; + } + + // Format properties goes here + cell.Range.Font.Bold = 1; + cell.Range.Font.Name = "verdana"; + cell.Range.Font.Size = 10; + + // cell.Range.Font.ColorIndex = WdColorIndex.wdGray25; + cell.Shading.BackgroundPatternColor = WdColor.wdColorGray25; + + // Center alignment for the Header cells + cell.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter; + cell.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; + } + } + + public void WordRowData(int index, Table firstTable, BinaryDetail binaryDetail) + { + // Loop through each cell in the row + foreach (Cell cell in firstTable.Rows[index].Cells) + { + // Switch between the columns + switch (cell.ColumnIndex) + { + case 1: + cell.Range.Text = binaryDetail.FileInfo.Name; + break; + case 2: + cell.Range.Text = binaryDetail.AssemblyCompanyAttribute; + break; + case 3: + cell.Range.Text = binaryDetail.AssemblyVersion; + break; + case 4: + cell.Range.Text = binaryDetail.FileVersion; + break; + } + } + } + } +} diff --git a/Program.cs b/Program.cs index cae61da..fbfa3fa 100644 --- a/Program.cs +++ b/Program.cs @@ -1,16 +1,14 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; -using System.Reflection; -using System.Text.RegularExpressions; + +// CMD command: BinaryDetailer.exe "C:\Program Files\dotnet\sdk\6.0.400\cs" doc namespace BinaryDetailer { internal class Program { - private static string currentBinary = string.Empty; private static List ExcludeNames = new List(); private static void Main(string[] args) @@ -24,6 +22,8 @@ private static void Main(string[] args) } } + Export ex = new Export(ExcludeNames); + List binaryDetails = new List(); IEnumerable allFiles = GetFiles(path, new[] { "*.dll", "*.exe" }, SearchOption.AllDirectories); @@ -33,34 +33,15 @@ private static void Main(string[] args) binaryDetails.Add(bd); } - CreateReport(binaryDetails); - Console.In.ReadLine(); - } + ex.CreateReport(binaryDetails); - private static void CreateReport(List binaryDetails) - { - string fileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), - Guid.NewGuid() + ".csv"); - File.Create(fileName).Close(); - File.AppendAllLines(fileName, BinaryDetail.CSVHeader); - foreach (var binaryDetail in binaryDetails) + if (args.Length > 1 && args[1].ToLower().Equals("doc")) { - bool include = true; - foreach (string excludeName in ExcludeNames) - { - if ((binaryDetail.AssemblyCompanyAttribute != null && binaryDetail.AssemblyCompanyAttribute.ToLower().Contains(excludeName)) || - (binaryDetail.AssemblyCopyrightAttribute != null && binaryDetail.AssemblyCopyrightAttribute.ToLower().Contains(excludeName))) - { - include = false; - } - } - - if (include == false) continue; - - File.AppendAllLines(fileName, new[] { binaryDetail.ToCsv() }); + ex.CreateWordDoc(binaryDetails); } - Console.WriteLine("File created at " + fileName); + Console.WriteLine("Export complete"); + Console.In.ReadLine(); } private static IEnumerable GetFiles(string path, @@ -72,4 +53,4 @@ private static IEnumerable GetFiles(string path, Directory.EnumerateFiles(path, searchPattern, searchOption)); } } -} +} \ No newline at end of file diff --git a/README.md b/README.md index d7ca456..46e15aa 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Binary Detailer -Binary Detailer is a method of outputing binary details such as net framework, 64 bit compatibility, version etc. Given a directory name, it will iterate dll and exe files and output the results to a csv file. +Binary Detailer is a method of outputting binary details such as net framework, 64-bit compatibility, version etc. Given a directory name, it will iterate dll and exe files and output the results to a csv file. ___ ### Usage From 5195984933c695c1200106b2a3faad8d248ba986 Mon Sep 17 00:00:00 2001 From: Brett Parker Date: Wed, 26 Apr 2023 11:30:36 +0100 Subject: [PATCH 2/5] Working XML groupings --- BinaryDetail.cs | 4 ++- BinaryDetailer.csproj | 5 ++++ Export.cs | 60 ++++++++++++++++++++++++++++++++++++++----- GroupingConfig.xml | 17 ++++++++++++ Program.cs | 8 +++++- 5 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 GroupingConfig.xml diff --git a/BinaryDetail.cs b/BinaryDetail.cs index 0c0db4f..f8a0b0e 100644 --- a/BinaryDetail.cs +++ b/BinaryDetail.cs @@ -13,6 +13,7 @@ public BinaryDetail(FileInfo fileInfo) FileInfo = fileInfo; } + public string GroupId { get; internal set; } public string Error { get; internal set; } public FileInfo FileInfo { get; internal set; } public ImageFileMachine ImageFileMachine { get; internal set; } @@ -32,7 +33,7 @@ public static string[] CSVHeader { return new[] { - "Full Path,FileName,AssemblyCompanyAttribute,AssemblyCopyrightAttribute,AssemblyVersion,FileVersion,ProductVersion,ImageRuntimeVersion,TargetFrameworkAttribute,PortableExecutableKinds,ImageFileMachine,ProcessorArchitecture,Error" + "Group Id, Full Path,FileName,AssemblyCompanyAttribute,AssemblyCopyrightAttribute,AssemblyVersion,FileVersion,ProductVersion,ImageRuntimeVersion,TargetFrameworkAttribute,PortableExecutableKinds,ImageFileMachine,ProcessorArchitecture,Error" }; } } @@ -40,6 +41,7 @@ public static string[] CSVHeader public string ToCsv() { return + "\"" + GroupId + "\"," + "\"" + FileInfo.FullName + "\"," + "\"" + FileInfo.Name + "\"," + "\"" + AssemblyCompanyAttribute + "\"," + diff --git a/BinaryDetailer.csproj b/BinaryDetailer.csproj index 765bdd0..62c3dc4 100644 --- a/BinaryDetailer.csproj +++ b/BinaryDetailer.csproj @@ -36,6 +36,8 @@ + + @@ -56,6 +58,9 @@ 15.0.4797.1004 + + + diff --git a/Export.cs b/Export.cs index a40922d..77f95e5 100644 --- a/Export.cs +++ b/Export.cs @@ -1,9 +1,12 @@ -using Microsoft.Office.Interop.Word; -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; +using System.Xml; +using System.Xml.Linq; +// Use of this library requires an install of Microsoft office +using Microsoft.Office.Interop.Word; namespace BinaryDetailer { @@ -15,6 +18,49 @@ public Export(List excludeNames) { ExcludeNames = excludeNames; } + public void GroupBinary(List binaryDetails, string xmlFilePath) + { + List groupedStrings = new List(); + XDocument xmlDoc = XDocument.Load(xmlFilePath); + + foreach (var binaryDetail in binaryDetails) + { + // Set an escape from the loop once match is found + bool groupIdSet = false; + + // Loop through each "group" element + foreach (XElement group in xmlDoc.Root.Elements("group")) + { + if (groupIdSet == true) + { + break; + } + + string groupName = group.Attribute("name").Value; + + if (binaryDetail.AssemblyCompanyAttribute == groupName) + { + // Loop through each "dll" element in the matching group + foreach (XElement dll in group.Elements("dll")) + { + // Check if the "dllname" attribute matches a "FileInfo.Name" + string dllName = dll.Attribute("dllname")?.Value ?? dll.Value; + + if (binaryDetail.FileInfo.Name == dllName) + { + binaryDetail.GroupId = groupName; + groupIdSet = true; + break; + } + } + } + else + { + binaryDetail.GroupId = "Unknown"; + } + } + } + } public void CreateReport(List binaryDetails) { @@ -22,6 +68,7 @@ public void CreateReport(List binaryDetails) Guid.NewGuid() + ".csv"); File.Create(csvFileName).Close(); File.AppendAllLines(csvFileName, BinaryDetail.CSVHeader); + foreach (var binaryDetail in binaryDetails) { bool include = true; @@ -134,6 +181,7 @@ public void CreateWordDoc(List binaryDetails) document = null; winword.Quit(ref missing, ref missing, ref missing); winword = null; + Console.WriteLine("Word Document created at " + filename); } catch (Exception ex) @@ -151,10 +199,10 @@ public void WordColumnHeadings(Table firstTable) switch (cell.ColumnIndex) { case 1: - cell.Range.Text = "File Name"; + cell.Range.Text = "Group ID"; break; case 2: - cell.Range.Text = "Assembly Company Attribute"; + cell.Range.Text = "File Name"; break; case 3: cell.Range.Text = "Assembly Version"; @@ -187,10 +235,10 @@ public void WordRowData(int index, Table firstTable, BinaryDetail binaryDetail) switch (cell.ColumnIndex) { case 1: - cell.Range.Text = binaryDetail.FileInfo.Name; + cell.Range.Text = binaryDetail.GroupId; break; case 2: - cell.Range.Text = binaryDetail.AssemblyCompanyAttribute; + cell.Range.Text = binaryDetail.FileInfo.Name; break; case 3: cell.Range.Text = binaryDetail.AssemblyVersion; diff --git a/GroupingConfig.xml b/GroupingConfig.xml new file mode 100644 index 0000000..0b7bb32 --- /dev/null +++ b/GroupingConfig.xml @@ -0,0 +1,17 @@ + + + + Infragistics.Documents.Core.dll + + + Microsoft.Build.Tasks.Core.resources.dll + + + + + + + + + + diff --git a/Program.cs b/Program.cs index fbfa3fa..7c6c67a 100644 --- a/Program.cs +++ b/Program.cs @@ -10,9 +10,11 @@ namespace BinaryDetailer internal class Program { private static List ExcludeNames = new List(); - + private static void Main(string[] args) { + List groupedStrings = new List(); + string path = args[0]; if (args.Length > 0) { @@ -40,6 +42,10 @@ private static void Main(string[] args) ex.CreateWordDoc(binaryDetails); } + ex.GroupBinary(binaryDetails, @"C:\AVEVA\GIT\binarydetailer\GroupingConfig.xml"); + + ex.CreateReport(binaryDetails); + Console.WriteLine("Export complete"); Console.In.ReadLine(); } From d0665e73b78596c4aebbfcfce3e1455832fc83f1 Mon Sep 17 00:00:00 2001 From: Brett Parker Date: Wed, 26 Apr 2023 11:32:19 +0100 Subject: [PATCH 3/5] Update grouping config --- GroupingConfig.xml => GroupingConfigExample.xml | 0 Program.cs | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename GroupingConfig.xml => GroupingConfigExample.xml (100%) diff --git a/GroupingConfig.xml b/GroupingConfigExample.xml similarity index 100% rename from GroupingConfig.xml rename to GroupingConfigExample.xml diff --git a/Program.cs b/Program.cs index 7c6c67a..11a205f 100644 --- a/Program.cs +++ b/Program.cs @@ -42,7 +42,7 @@ private static void Main(string[] args) ex.CreateWordDoc(binaryDetails); } - ex.GroupBinary(binaryDetails, @"C:\AVEVA\GIT\binarydetailer\GroupingConfig.xml"); + ex.GroupBinary(binaryDetails, @"C:\AVEVA\GIT\binarydetailer\GroupingConfigExample.xml"); ex.CreateReport(binaryDetails); From a826fb74489e0aefefe88781abd435ce0a26066e Mon Sep 17 00:00:00 2001 From: Brett Parker Date: Thu, 27 Apr 2023 11:08:35 +0100 Subject: [PATCH 4/5] Export class complete --- Export.cs | 112 ++++++++++++++++++++++++++++++++--------------------- Program.cs | 33 +++++++++++----- 2 files changed, 91 insertions(+), 54 deletions(-) diff --git a/Export.cs b/Export.cs index 77f95e5..c9f40ed 100644 --- a/Export.cs +++ b/Export.cs @@ -5,6 +5,7 @@ using System.Reflection; using System.Xml; using System.Xml.Linq; + // Use of this library requires an install of Microsoft office using Microsoft.Office.Interop.Word; @@ -18,54 +19,66 @@ public Export(List excludeNames) { ExcludeNames = excludeNames; } + public void GroupBinary(List binaryDetails, string xmlFilePath) { - List groupedStrings = new List(); - XDocument xmlDoc = XDocument.Load(xmlFilePath); - - foreach (var binaryDetail in binaryDetails) + try { - // Set an escape from the loop once match is found - bool groupIdSet = false; + // Load xml config file + XDocument xmlDoc = XDocument.Load(xmlFilePath); - // Loop through each "group" element - foreach (XElement group in xmlDoc.Root.Elements("group")) + // Loop through the binaries + foreach (var binaryDetail in binaryDetails) { - if (groupIdSet == true) + // Set an escape from the loop once match is found + bool groupIdSet = false; + + // Loop through each "group" element. I.E Company name + foreach (XElement group in xmlDoc.Root.Elements("group")) { - break; - } + if (groupIdSet == true) break; - string groupName = group.Attribute("name").Value; + string groupName = group.Attribute("name").Value; - if (binaryDetail.AssemblyCompanyAttribute == groupName) - { - // Loop through each "dll" element in the matching group - foreach (XElement dll in group.Elements("dll")) + // Check if the binary has a match in the config xml + if (binaryDetail.AssemblyCompanyAttribute == groupName) { - // Check if the "dllname" attribute matches a "FileInfo.Name" - string dllName = dll.Attribute("dllname")?.Value ?? dll.Value; - - if (binaryDetail.FileInfo.Name == dllName) + // Loop through each "dll" element in the matching group + // It is neccessarry to find the group first. It is possible a dll could be used in + // another library in which case a license check needs to be done. + foreach (XElement dll in group.Elements("dll")) { - binaryDetail.GroupId = groupName; - groupIdSet = true; - break; + // Check if the "dllname" attribute matches a "FileInfo.Name" + string dllName = dll.Attribute("dllname")?.Value ?? dll.Value; + + // If the dll in the config matches, set groupid + if (binaryDetail.FileInfo.Name == dllName) + { + binaryDetail.GroupId = groupName; + groupIdSet = true; + break; + } } } - } - else - { - binaryDetail.GroupId = "Unknown"; + else + { + // If nothing matches + binaryDetail.GroupId = "Unknown"; + } } } } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } } public void CreateReport(List binaryDetails) { string csvFileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), Guid.NewGuid() + ".csv"); + File.Create(csvFileName).Close(); File.AppendAllLines(csvFileName, BinaryDetail.CSVHeader); @@ -96,21 +109,21 @@ public void CreateWordDoc(List binaryDetails) string wordFileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), Guid.NewGuid() + ".docx"); - //Create an instance for word app + // Create an instance for word app Application winword = new Application { ShowAnimation = false, Visible = false }; - //Create a missing variable for missing value + // Create a missing variable for missing value object missing = Missing.Value; - //Create a new document + // Create a new document Document document = winword.Documents.Add(ref missing, ref missing, ref missing, ref missing); document.PageSetup.Orientation = WdOrientation.wdOrientLandscape; - //Add header into the document + // Add header into the document foreach (Section section in document.Sections) { //Get the header range and add the header details. @@ -122,7 +135,7 @@ public void CreateWordDoc(List binaryDetails) headerRange.Text = "Binary Detailer"; } - //Add the footers into the document + // Add the footers into the document foreach (Section wordSection in document.Sections) { //Get the footer range and add the footer details. @@ -133,7 +146,7 @@ public void CreateWordDoc(List binaryDetails) footerRange.Text = "Github repository: https://github.com/stuartjsmith/binarydetailer"; } - //adding text to document + // Adding text to document document.Content.SetRange(0, 0); string firstLine = "Binary Detailer is a method of outputting binary details such as net framework, " + "64-bit compatibility, version etc. Given a directory name, it will iterate dll and exe files " + @@ -141,24 +154,27 @@ public void CreateWordDoc(List binaryDetails) document.Content.Text = firstLine + Environment.NewLine; - //Add paragraph with Heading 1 style + // Add paragraph with Heading 1 style Paragraph para1 = document.Content.Paragraphs.Add(ref missing); object styleHeading1 = "Heading 1"; para1.Range.set_Style(ref styleHeading1); para1.Range.Text = "Binary Details"; para1.Range.InsertParagraphAfter(); - //Create a 5X5 table and insert some dummy record (+1 in count to allow for a column heading) - Table firstTable = document.Tables.Add(para1.Range, binaryDetails.Count + 1, 4, ref missing, ref missing); + // Create a table + Table table = document.Tables.Add(para1.Range, binaryDetails.Count + 1, 5, ref missing, ref missing); // Define column headings - WordColumnHeadings(firstTable); + WordColumnHeadings(table); - firstTable.Borders.Enable = 1; + // Add table borders + table.Borders.Enable = 1; + + // Loop through each binary and add to the table. foreach (var binaryDetail in binaryDetails.Select((value, i) => new { i, value })) { - bool include = true; + foreach (string excludeName in ExcludeNames) { if ((binaryDetail.value.AssemblyCompanyAttribute != null && binaryDetail.value.AssemblyCompanyAttribute.ToLower().Contains(excludeName)) || @@ -171,7 +187,7 @@ public void CreateWordDoc(List binaryDetails) if (include == false) continue; // Passing the index + 2 as there is a heading column to overcome. - WordRowData(binaryDetail.i + 2, firstTable, binaryDetail.value); + WordRowData(binaryDetail.i + 2, table, binaryDetail.value); } //Save the document @@ -202,12 +218,15 @@ public void WordColumnHeadings(Table firstTable) cell.Range.Text = "Group ID"; break; case 2: - cell.Range.Text = "File Name"; + cell.Range.Text = "Company Name"; break; case 3: - cell.Range.Text = "Assembly Version"; + cell.Range.Text = "File Name"; break; case 4: + cell.Range.Text = "Assembly Version"; + break; + case 5: cell.Range.Text = "File Version"; break; } @@ -217,7 +236,7 @@ public void WordColumnHeadings(Table firstTable) cell.Range.Font.Name = "verdana"; cell.Range.Font.Size = 10; - // cell.Range.Font.ColorIndex = WdColorIndex.wdGray25; + // Cell shading cell.Shading.BackgroundPatternColor = WdColor.wdColorGray25; // Center alignment for the Header cells @@ -238,12 +257,15 @@ public void WordRowData(int index, Table firstTable, BinaryDetail binaryDetail) cell.Range.Text = binaryDetail.GroupId; break; case 2: - cell.Range.Text = binaryDetail.FileInfo.Name; + cell.Range.Text = binaryDetail.AssemblyCompanyAttribute; break; case 3: - cell.Range.Text = binaryDetail.AssemblyVersion; + cell.Range.Text = binaryDetail.FileInfo.Name; break; case 4: + cell.Range.Text = binaryDetail.AssemblyVersion; + break; + case 5: cell.Range.Text = binaryDetail.FileVersion; break; } diff --git a/Program.cs b/Program.cs index 11a205f..eac8dde 100644 --- a/Program.cs +++ b/Program.cs @@ -3,8 +3,6 @@ using System.IO; using System.Linq; -// CMD command: BinaryDetailer.exe "C:\Program Files\dotnet\sdk\6.0.400\cs" doc - namespace BinaryDetailer { internal class Program @@ -35,16 +33,33 @@ private static void Main(string[] args) binaryDetails.Add(bd); } - ex.CreateReport(binaryDetails); - - if (args.Length > 1 && args[1].ToLower().Equals("doc")) + if (args.Length > 1) { - ex.CreateWordDoc(binaryDetails); - } + foreach (var arg in args.Select((value, i) => new { i, value })) + { + var index = arg.i; - ex.GroupBinary(binaryDetails, @"C:\AVEVA\GIT\binarydetailer\GroupingConfigExample.xml"); + // Skip the first arg as this is the path to report on + if (index.Equals(0)) continue; - ex.CreateReport(binaryDetails); + if (arg.value.ToLower().Equals("doc")) + { + // Create word document + ex.CreateWordDoc(binaryDetails); + } + else if (arg.value.ToLower().Equals("config")) + { + // Create a binary grouping based on a config. + ex.GroupBinary(binaryDetails, args[index+1]); + ex.CreateReport(binaryDetails); + } + } + } + else + { + // Raw report + ex.CreateReport(binaryDetails); + } Console.WriteLine("Export complete"); Console.In.ReadLine(); From 01bf03845d0fc4555be3893706c1f49c10eb4e60 Mon Sep 17 00:00:00 2001 From: Brett Parker Date: Thu, 27 Apr 2023 11:14:13 +0100 Subject: [PATCH 5/5] Readme update --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 46e15aa..7b5ba2d 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,13 @@ ___ ![Screenshot 3](data/screenshots/Completed-csv.jpg "Completed CSV File") ___ +### Arguments + +'config' - This requires an XML passed after the config argument. This will compare the binaries against the XML and group common binaries together. See "GroupingConfigExample.xml" +'doc' - This will create a word document table of the data. This requires a Microsoft Office install on the machine executing. + +Example argument: BinaryDetailer.exe "C:\Program Files\dotnet\sdk\6.0.400" config "C:\BinaryDetailer\GroupingConfigExample.xml" doc + ## Contribute Congratulations! You’re up and running. Now you can begin using and contributing your fixes and new features to the project.