Skip to content

Commit

Permalink
Added the FluentCommandLineParser.dll library to the project to easie…
Browse files Browse the repository at this point in the history
…r get the passed parameters. https://github.com/fclp/fluent-command-line-parser

Added a new argument 'Filename' (-f, /f, --filename): Set the path and/or filename for the generated report file. If the passed path is a directory the default filename will be appended to it. Absolute or relative paths are allowed
Added a new argument 'Max Tasks' (-t, /t, --max-tasks <value>): Sets the maximum number of concurrent tasks enabled to generate the reports. If it is -1, there is no limit on the number of concurrently running operations (Default). If it is 1 it will run in a single thread, best used with single core CPUs or for debuging.
Added a new argument 'Help' (-?, /?, --help): Display a help message with all possible arguments and its usages
Added support for combined (grouped) options when passing three or more boolean arguments. ex: -sno (same as: -s -n -o)
Changed the way arguments can be passed. Now it support the following syntax: [-|--|/][switch_name][=|:| ][value]
Removed the empty columns for installed programs table under Mac OSX
Removed 'Single Thread' argument in favor of the new 'Max Tasks' argument, use -t 1 to produce the same effect
sn4k3 committed Apr 22, 2015
1 parent e9669ec commit ae8a1d4
Showing 13 changed files with 601 additions and 68 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

# v1.6.1.0
## 22/04/2015

* Added the FluentCommandLineParser.dll library to the project to easier get the passed parameters. https://github.com/fclp/fluent-command-line-parser
* Added a new argument 'Filename' (-f, /f, --filename): Set the path and/or filename for the generated report file. If the passed path is a directory the default filename will be appended to it. Absolute or relative paths are allowed
* Added a new argument 'Max Tasks' (-t, /t, --max-tasks <value>): Sets the maximum number of concurrent tasks enabled to generate the reports. If it is -1, there is no limit on the number of concurrently running operations (Default). If it is 1 it will run in a single thread, best used with single core CPUs or for debuging.
* Added a new argument 'Help' (-?, /?, --help): Display a help message with all possible arguments and its usages
* Added support for combined (grouped) options when passing three or more boolean arguments. ex: -sno (same as: -s -n -o)
* Changed the way arguments can be passed. Now it support the following syntax: [-|--|/][switch_name][=|:| ][value]
* Removed the empty columns for installed programs table under Mac OSX
* Removed 'Single Thread' argument in favor of the new 'Max Tasks' argument, use -t 1 to produce the same effect


# v1.6.0.0
## 21/04/2015

@@ -9,6 +22,7 @@
* Fixed a critical bug under linux and OSX that cause the processes report to broke all the html when any process name is null
* Changed the InstalledProgram class was been rewrited and moved into Core


# v1.5.0.0
## 18/04/2015

374 changes: 374 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

115 changes: 80 additions & 35 deletions SystemInfoSnapshot/ApplicationArguments.cs
Original file line number Diff line number Diff line change
@@ -5,9 +5,8 @@
* http://systeminfosnapshot.com/
* https://github.com/sn4k3/SystemInfoSnapshot
*/
using System;
using System.Collections.Generic;
using System.Linq;

using Fclp;

namespace SystemInfoSnapshot
{
@@ -17,75 +16,121 @@ namespace SystemInfoSnapshot
public sealed class ApplicationArguments
{
#region Singleton
/// <summary>
/// A instance of this class
/// </summary>
private static ApplicationArguments _instance;

/// <summary>
/// Gets the singleton instance of this class
/// </summary>
public static ApplicationArguments Instance
{
get { return _instance ?? (_instance = new ApplicationArguments()); }
get { return CmdParser.Object; }
}
#endregion

#region Properties

/// <summary>
/// Gets the parameter parser
/// </summary>
public static FluentCommandLineParser<ApplicationArguments> CmdParser = new FluentCommandLineParser<ApplicationArguments> { IsCaseSensitive = false };

/// <summary>
/// Gets if program will lunch without the GUI. (Terminal only)
/// </summary>
public bool NoGUI
{
get
{
return Silent && Null;
}
}

/// <summary>
/// Gets if Null mode as passed as argument.
/// </summary>
public bool Null { get; private set; }
public bool Null { get; set; }

/// <summary>
/// Gets if Silent mode as passed as argument.
/// </summary>
public bool Silent { get; private set; }
public bool Silent { get; set; }

/// <summary>
/// Gets if OpenReport mode as passed as argument.
/// </summary>
public bool OpenReport { get; private set; }
public bool OpenReport { get; set; }

/// <summary>
/// Gets if the reports will be generated under a single thread.
/// </summary>
public bool UseSingleThread { get; private set; }
#endregion
public int MaxDegreeOfParallelism { get; set; }

#region Arguments Variable
/// <summary>
/// Variable - Arguments list
/// Gets the full or partial filename to save the report
/// </summary>
public readonly Dictionary<string, string[]> Arguments = new Dictionary<string, string[]>
{
{"Null", new []{"-n", "/n", "--null"}},
{"Silent", new []{"-s", "/s", "--silent"}},
{"OpenReport", new []{"-o", "/o", "--open-report"}},
{"UseSingleThread", new []{"-st", "/st", "--single-thread"}}
};
public string Filename { get; set; }
#endregion

#region Constructor
/// <summary>
/// Constructor. Auto initalize arguments.
/// </summary>
private ApplicationArguments()
public ApplicationArguments()
{
var args = Environment.GetCommandLineArgs().ToList();
}
#endregion

foreach (var argument in Arguments)
#region Methods
/// <summary>
/// Fix some paramters and define limits.
/// </summary>
public void Fix()
{
// Set to -1 if 0 or lower
if (MaxDegreeOfParallelism <= 0)
{
foreach (var s in argument.Value)
{
if(!args.Contains(s))
continue;

var type = GetType();
var prop = type.GetProperty(argument.Key);
prop.SetValue(this, true);
}
MaxDegreeOfParallelism = -1;
}

if (string.IsNullOrWhiteSpace(Filename))
{
Filename = null;
}
}
#endregion

#region Static methods
public static ICommandLineParserResult Init(string[] args)
{
CmdParser.SetupHelp("?", "help").Callback(SystemHelper.DisplayMessage);
CmdParser.Setup(arg => arg.Null).
As('n', "null").
SetDefault(false).
WithDescription("Only generate the report without showing or doing anything. Good for scripts or tasks.");

CmdParser.Setup(arg => arg.Silent).
As('s', "silent").
SetDefault(false).
WithDescription("Run program without showing the GUI. After the report is generated that will be shown on explorer after completion.");

CmdParser.Setup(arg => arg.OpenReport).
As('o', "open-report").
SetDefault(false).
WithDescription("After the report is generated that will be opened automatically in the default browser.");

CmdParser.Setup(arg => arg.MaxDegreeOfParallelism).
As('t', "max-tasks").
SetDefault(-1).
WithDescription("Sets the maximum number of concurrent tasks enabled to generate the reports. If it is -1, there is no limit on the number of concurrently running operations (Default). " +
"If it is 1 it will run in a single thread, best used with single core CPUs or for debuging.");

CmdParser.Setup(arg => arg.Filename).
As('f', "target").
SetDefault(null).
WithDescription("Set the path and/or filename for the generated report file. If the passed path is a directory the default filename will be appended to it. Absolute or relative paths are allowed.");

var result = CmdParser.Parse(args);

return result;

}
#endregion
}
2 changes: 1 addition & 1 deletion SystemInfoSnapshot/EmbeddedAssembly.cs
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Windows.Forms;

namespace SystemInfoSnapshot
{
@@ -143,7 +144,6 @@ public static Assembly OnResolveAssembly(object sender, ResolveEventArgs e)
// Get the Name of the AssemblyFile
var assemblyName = new AssemblyName(e.Name);
var dllName = assemblyName.Name + ".dll";

// Load from Embedded Resources
var resources = thisAssembly.GetManifestResourceNames().Where(s => s.EndsWith(dllName));
if (resources.Any())
6 changes: 3 additions & 3 deletions SystemInfoSnapshot/FrmMain.cs
Original file line number Diff line number Diff line change
@@ -109,12 +109,12 @@ private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventA
{
ButtonsSetEnabled(true);
var location = Path.GetDirectoryName(Program.HtmlTemplate.LastSaveFilePath);
if (string.IsNullOrEmpty(location))
/*if (string.IsNullOrEmpty(location))
{
location = Application.StartupPath;
}
}*/
lbFilename.Text = Path.GetFileName(Program.HtmlTemplate.LastSaveFilePath);
//lbLocation.Text = location;
lbLocation.Text = location;
EndDateTime = DateTime.Now;
tmClock.Stop();
lbStatus.Text = string.Format("Report completed in {0:0.##}s", (EndDateTime - StartDateTime).TotalSeconds);
37 changes: 32 additions & 5 deletions SystemInfoSnapshot/HTMLTemplate.cs
Original file line number Diff line number Diff line change
@@ -59,12 +59,39 @@ public void WriteFromVar(string templateVar, string html)
/// </summary>
public void WriteToFile()
{
var filename = Filename ?? "SystemInfoSnapshot";
filename += string.Format("_{0}.html", DateTime.Now).Replace(':', '-').Replace('/', '-').Replace(' ', '_');
var defaultFilename = string.Format("SystemInfoSnapshot_{0}.html", DateTime.Now).
Replace(':', '-').
Replace('/', '-').
Replace(' ', '_');;
var filename = Filename ?? defaultFilename;

//filename += string.Format("_{0}.html", DateTime.Now).Replace(':', '-').Replace('/', '-').Replace(' ', '_');
#if !DEBUG
var path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

filename = Directory.Exists(path) ? Path.Combine(path, filename) : filename;
string path = null;
if (!string.IsNullOrEmpty(Filename))
{
// If is a directory then keep filename the default name and set the folder only.
if (Directory.Exists(filename))
{
path = filename;
filename = defaultFilename;
}
else // If is not a directory then get the path from the filename if any and append .html to the filename
{
path = Path.GetDirectoryName(Filename);
if (!filename.EndsWith(".html"))
filename += ".html";
}
}

// Last check for invalid path, if invalid set path as dekstop
if (string.IsNullOrEmpty(path) || !Directory.Exists(path))
{
path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
}


filename = !string.IsNullOrEmpty(path) && Directory.Exists(path) ? Path.Combine(path, filename) : filename;
#endif
using (var htmlWriter = new StreamWriter(filename))
{
51 changes: 46 additions & 5 deletions SystemInfoSnapshot/Program.cs
Original file line number Diff line number Diff line change
@@ -7,27 +7,65 @@
*/

using System;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
using SystemInfoSnapshot.Reports;

namespace SystemInfoSnapshot
{
static class Program
{
#region Properties
/// <summary>
/// Gets the project website
/// </summary>
public const string Website = "http://systeminfosnapshot.com";
public static HtmlTemplate HtmlTemplate;
public static Report[] Reports;
public static HtmlTemplate HtmlTemplate { get; private set; }
public static Report[] Reports { get; private set; }
#endregion

#region Constructor
/// <summary>
/// Constructor
/// </summary>
static Program()
{
AppDomain.CurrentDomain.AssemblyResolve += EmbeddedAssembly.OnResolveAssembly;
}
#endregion

#region Bootsrap
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
AppDomain.CurrentDomain.AssemblyResolve += EmbeddedAssembly.OnResolveAssembly;
// Skip this method and do all work on a secondary method for .NET able to register embbeded assemblies correctly
MainCore();
}

/// <summary>
///
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
static void MainCore()
{
Reports = Report.GetReports();
var resultArgs = ApplicationArguments.Init(Environment.GetCommandLineArgs());
if (resultArgs.HasErrors)
{
SystemHelper.DisplayMessage(resultArgs.ErrorText);
}
if (resultArgs.HelpCalled)
{
// Quit
return;
}
ApplicationArguments.Instance.Fix();

// Null or Silent mode, skip GUI.
if (ApplicationArguments.Instance.Null || ApplicationArguments.Instance.Silent)
if (ApplicationArguments.Instance.NoGUI)
{
WriteTemplate();
return;
@@ -37,13 +75,15 @@ static void Main()
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmMain());
}
#endregion

#region Static Methods
/// <summary>
/// Write all info into template and output the html file.
/// </summary>
public static void WriteTemplate()
{
HtmlTemplate = Report.GenerateReports(Reports, true, ApplicationArguments.Instance.UseSingleThread);
HtmlTemplate = Report.GenerateReports(Reports, true, ApplicationArguments.Instance.Filename, ApplicationArguments.Instance.MaxDegreeOfParallelism);

if (ApplicationArguments.Instance.Silent)
{
@@ -55,5 +95,6 @@ public static void WriteTemplate()
HtmlTemplate.OpenInDefaultBrowser();
}
}
#endregion
}
}
5 changes: 2 additions & 3 deletions SystemInfoSnapshot/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
@@ -32,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.6.0.0")]
[assembly: AssemblyFileVersion("1.6.0.0")]
[assembly: AssemblyVersion("1.6.1.0")]
[assembly: AssemblyFileVersion("1.6.1.0")]
Loading

0 comments on commit ae8a1d4

Please sign in to comment.