Skip to content

Commit

Permalink
Added a new argument 'single thread': Generate all the reports one by…
Browse files Browse the repository at this point in the history
… one without use parallel tasks. Best used with single core CPUs or for debuging.

Fixed application always crash on autoruns collection when tab icons are null
Removed unused namespaces
  • Loading branch information
sn4k3 committed Apr 10, 2015
1 parent e5b64d1 commit 4ddd1b2
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 37 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

# 1.2.20.2
## 10/04/2015

* Added a new argument 'single thread': Generate all the reports one by one without use parallel tasks. Best used with single core CPUs or for debuging.
* Fixed application always crash on autoruns collection when tab icons are null
* Removed unused namespaces


# 1.2.20.0
## 10/04/2015

Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@ Report will be generated and the html file will show on explorer after completio
* **Description:** Run program without showing the GUI. After the report is generated that will be shown on explorer after completion.
* **Example:** "SystemInfoSnapshot.exe -s"

##Open report on completion
## Open report on completion
* **Arguments:** '-o', '/o' or '--open-report'
* **Description:** After the report is generated that will be opened automatically in the default browser.
* **Example:** "SystemInfoSnapshot.exe -o"

## Use single thread instead (No parallelism)
* **Arguments:** '-st', '/st' or '--single-thread'
* **Description:** Generate all the reports one by one without use parallel tasks. Best used with single core CPUs or for debuging.
* **Example:** "SystemInfoSnapshot.exe -st"

## Examples
1. "SystemInfoSnapshot.exe --null -o" - Generate and open the report in the default browser without showing the GUI.
2. "SystemInfoSnapshot.exe -s -o" - Generate, show and open the report in the explorer and the default browser without showing the GUI.
Expand Down
12 changes: 9 additions & 3 deletions SystemInfoSnapshot/ApplicationArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,20 @@ public sealed class ApplicationArguments
/// </summary>
public bool OpenReport { get; private set; }

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

/// <summary>
/// Variable - Arguments list
/// </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"}}
{"Null", new []{"-n", "/n", "--null"}},
{"Silent", new []{"-s", "/s", "--silent"}},
{"OpenReport", new []{"-o", "/o", "--open-report"}},
{"UseSingleThread", new []{"-st", "/st", "--single-thread"}}
};

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions SystemInfoSnapshot/Autoruns.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using SystemInfoSnapshot.Properties;

namespace SystemInfoSnapshot
{
Expand Down Expand Up @@ -88,12 +88,12 @@ public void BuildEntries()
if (string.IsNullOrEmpty(ExecutableFile))
{
ExecutableFile = Path.Combine(Path.GetTempPath(), "autorunsc.exe");
File.WriteAllBytes(ExecutableFile, Properties.Resources.autorunsc);
File.WriteAllBytes(ExecutableFile, Resources.autorunsc);
}
using (var proc = new Process())
{
proc.StartInfo.FileName = ExecutableFile;
proc.StartInfo.Arguments = "-a * -m -c";
proc.StartInfo.Arguments = "-a * -m -c -accepteula";
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
Expand Down
2 changes: 1 addition & 1 deletion SystemInfoSnapshot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static void Main()
/// </summary>
public static void WriteTemplate()
{
HtmlTemplate = Report.GenerateReports(Reports);
HtmlTemplate = Report.GenerateReports(Reports, true, ApplicationArguments.UseSingleThread);

if (ApplicationArguments.Silent)
{
Expand Down
4 changes: 2 additions & 2 deletions SystemInfoSnapshot/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,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.2.20.0")]
[assembly: AssemblyFileVersion("1.2.20.0")]
[assembly: AssemblyVersion("1.2.20.2")]
[assembly: AssemblyFileVersion("1.2.20.2")]
51 changes: 31 additions & 20 deletions SystemInfoSnapshot/Reports/Report.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,33 +137,44 @@ public static Report[] GetReports()
/// <param name="reports">List of reports to generate.</param>
/// <param name="saveReport">True for save reports in the html file.</param>
/// <returns><see cref="HtmlTemplate"/> with the reports already written in the template.</returns>
public static HtmlTemplate GenerateReports(Report[] reports, bool saveReport = true)
public static HtmlTemplate GenerateReports(Report[] reports, bool saveReport = true, bool useSingleThread = false)
{
var htmlTemplate = new HtmlTemplate();
/*List<Report> asyncReports = new List<Report>();
foreach (var report in reports)
{
if (report.CanAsync)
{
Debug.WriteLine(report.CanAsync);
asyncReports.Add(report);
continue;
}
report.Generate();
//if (ReferenceEquals(htmlTemplate, null)) continue;
htmlTemplate.WriteFromVar(report.GetTemplateVar(), report.Html);
}*/
//List<Report> asyncReports = new List<Report>();

Parallel.ForEach(reports, report =>
if (useSingleThread)
{
//Debug.WriteLine(report.GetTemplateVar());
report.Generate();

lock (htmlTemplate.TemplateHTML)
foreach (var report in reports)
{
//if (report.CanAsync)
//{
// asyncReports.Add(report);
// continue;
//}
report.Generate();
htmlTemplate.WriteFromVar(report.GetTemplateVar(), report.Html);
}
});
}
else
{
#if DEBUG
var options = new ParallelOptions { MaxDegreeOfParallelism = 1 };
#else
var options = new ParallelOptions { MaxDegreeOfParallelism = -1 };
#endif
Parallel.ForEach(reports, options, report =>
{
//Debug.WriteLine(report.GetTemplateVar());
report.Generate();

lock (htmlTemplate.TemplateHTML)
{
htmlTemplate.WriteFromVar(report.GetTemplateVar(), report.Html);
}
});
}




if (/*!ReferenceEquals(htmlTemplate, null) && */saveReport)
Expand Down
12 changes: 7 additions & 5 deletions SystemInfoSnapshot/Reports/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;

namespace SystemInfoSnapshot.Reports
{
Expand Down Expand Up @@ -64,6 +63,7 @@ protected override void Build()
{"LSA Providers", "fa fa-shield"},
{"Network Providers", "fa fa-wifi"},
{"WDM", ""},
{"WMI", ""},
{"Sidebar Gadgets", ""},
};
var autoruns = new Autoruns();
Expand All @@ -73,13 +73,15 @@ protected override void Build()
var result = "<ul class=\"nav nav-tabs\" role=\"tablist\">";
foreach (var autorunDict in autorunsDict)
{
result += string.Format("<li role=\"presentation\" class=\"{0}\"><a href=\"#autorun_{2}\" aria-controls=\"{2}\" role=\"tab\" data-toggle=\"tab\"><i class=\"{4}\"></i> {1} ({3})</a></li>", (autorunDict.Key.Equals("Logon") ? "active" : string.Empty), autorunDict.Key, autorunDict.Key.Replace(" ", ""), autorunDict.Value.Count, icons[autorunDict.Key]);
result += string.Format("<li role=\"presentation\" class=\"{0}\"><a href=\"#autorun_{2}\" aria-controls=\"{2}\" role=\"tab\" data-toggle=\"tab\"><i class=\"{4}\"></i> {1} ({3})</a></li>",
autorunDict.Key.Equals("Logon") ? "active" : string.Empty,
autorunDict.Key, autorunDict.Key.Replace(" ", ""),
autorunDict.Value.Count,
icons.ContainsKey(autorunDict.Key) ? icons[autorunDict.Key] : string.Empty);
}
result += "</ul>";



var i = 0;
result += "<div class=\"tab-content\">";
foreach (var autorunDict in autorunsDict)
{
Expand All @@ -101,7 +103,7 @@ protected override void Build()
"</tr>" +
"</thead>" +
"<tbody>";
i = 0;
var i = 0;
foreach (var autorunEntry in autorunDict.Value)
{
i++;
Expand Down
2 changes: 0 additions & 2 deletions SystemInfoSnapshot/Reports/SystemInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using OpenHardwareMonitor.Hardware;

namespace SystemInfoSnapshot.Reports
{
Expand Down

0 comments on commit 4ddd1b2

Please sign in to comment.