Skip to content

Commit

Permalink
apply the new source code
Browse files Browse the repository at this point in the history
  • Loading branch information
mammo0 committed Dec 6, 2021
1 parent b1c76be commit 44666d8
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 21 deletions.
35 changes: 35 additions & 0 deletions NetworkMiner/FileUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.IO;
using System.Threading.Tasks;

namespace NetworkMiner
{
public static class FileUtils
{
public static async Task<bool> DeleteDirectory(string directoryPath, int maxRetries = 10, int millisecondsDelay = 30)
{
if (directoryPath == null)
throw new ArgumentNullException(directoryPath);
if (maxRetries < 1)
throw new ArgumentOutOfRangeException(nameof(maxRetries));
if (millisecondsDelay < 1)
throw new ArgumentOutOfRangeException(nameof(millisecondsDelay));

for (int i = 0; i < maxRetries; ++i) {
try {
// try to delete the directory if it exists
if (Directory.Exists(directoryPath))
Directory.Delete(directoryPath, true);

return true;
} catch (IOException) { // System.IO.IOException: The directory is not empty
await Task.Delay(millisecondsDelay);
} catch (UnauthorizedAccessException) {
await Task.Delay(millisecondsDelay);
}
}

return false;
}
}
}
1 change: 1 addition & 0 deletions NetworkMiner/NetworkMiner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="FileUtils.cs" />
</ItemGroup>
<ItemGroup>
<None Include="networkminericon.ico">
Expand Down
39 changes: 20 additions & 19 deletions NetworkMiner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace NetworkMiner {
public static class Program {

private static string EXE_PATH = Path.GetFullPath(Assembly.GetEntryAssembly().Location);
private static readonly string EXE_PATH = Path.GetFullPath(Assembly.GetEntryAssembly().Location);

/// <summary>
/// The main entry point for the application.
Expand Down Expand Up @@ -59,39 +59,40 @@ static async Task Main(string[] args) {

public static void SetupLogger(string applicationName) {

Logger.ApplicationName = applicationName;
SharedUtils.Logger.ApplicationName = applicationName;

foreach (string arg in Environment.GetCommandLineArgs()) {
if (arg.Equals("--debug", StringComparison.InvariantCultureIgnoreCase)) {
Logger.CurrentLogLevel = Logger.LogLevel.Debug;
Logger.LogToConsole = true;
SharedUtils.Logger.CurrentLogLevel = SharedUtils.Logger.LogLevel.Debug;
SharedUtils.Logger.LogToConsole = true;
}
else if (arg.Equals("--eventlog", StringComparison.InvariantCultureIgnoreCase)) {
EventLog applicationEventLog = new EventLog("Application");
System.Diagnostics.EventLog applicationEventLog = new System.Diagnostics.EventLog("Application");
applicationEventLog.Source = applicationName;

Logger.CurrentLogLevel = Logger.LogLevel.Debug;
Logger.EnableEventLog((message, eventLogEntryType) => applicationEventLog.WriteEntry(message, (EventLogEntryType)eventLogEntryType));
SharedUtils.Logger.CurrentLogLevel = SharedUtils.Logger.LogLevel.Debug;
SharedUtils.Logger.EnableEventLog((message, eventLogEntryType) => applicationEventLog.WriteEntry(message, (System.Diagnostics.EventLogEntryType)eventLogEntryType));
}
else if (arg.Equals("--filelog", StringComparison.InvariantCultureIgnoreCase)) {
Logger.CurrentLogLevel = Logger.LogLevel.Debug;
Logger.LogToFile = true;
SharedUtils.Logger.CurrentLogLevel = SharedUtils.Logger.LogLevel.Debug;
SharedUtils.Logger.LogToFile = true;
}
}
#if DEBUG
Logger.CurrentLogLevel = Logger.LogLevel.Debug;
Logger.LogToConsole = true;
Logger.LogToFile = true;
SharedUtils.Logger.CurrentLogLevel = SharedUtils.Logger.LogLevel.Debug;
SharedUtils.Logger.LogToConsole = true;
//SharedUtils.Logger.EnableEventLog();
SharedUtils.Logger.LogToFile = true;
#endif

FileVersionInfo productInfo = FileVersionInfo.GetVersionInfo(EXE_PATH);
Logger.Log("Environment.Is64BitOperatingSystem = " + Environment.Is64BitOperatingSystem.ToString(), Logger.EventLogEntryType.Information);
Logger.Log("Environment.Is64BitProcess = " + Environment.Is64BitProcess.ToString(), Logger.EventLogEntryType.Information);
Logger.Log(productInfo.ProductName + " " + productInfo.ProductVersion, Logger.EventLogEntryType.Information);
Logger.Log("Application.ExecutablePath = " + EXE_PATH, Logger.EventLogEntryType.Information);
Logger.Log("Application.CurrentCulture = " + CultureInfo.CurrentCulture, Logger.EventLogEntryType.Information);
Logger.Log("Environment.Version = " + Environment.Version, Logger.EventLogEntryType.Information);//4.0.30319.42000 = .NET Framework 4.6, its point releases, and the .NET Framework 4.7
Logger.Log("Starting application", Logger.EventLogEntryType.Information);
SharedUtils.Logger.Log("Environment.Is64BitOperatingSystem = " + Environment.Is64BitOperatingSystem.ToString(), SharedUtils.Logger.EventLogEntryType.Information);
SharedUtils.Logger.Log("Environment.Is64BitProcess = " + Environment.Is64BitProcess.ToString(), SharedUtils.Logger.EventLogEntryType.Information);
SharedUtils.Logger.Log(productInfo.ProductName + " " + productInfo.ProductVersion, SharedUtils.Logger.EventLogEntryType.Information);
SharedUtils.Logger.Log("Application.ExecutablePath = " + EXE_PATH, SharedUtils.Logger.EventLogEntryType.Information);
SharedUtils.Logger.Log("Application.CurrentCulture = " + CultureInfo.CurrentCulture, SharedUtils.Logger.EventLogEntryType.Information);
SharedUtils.Logger.Log("Environment.Version = " + Environment.Version, SharedUtils.Logger.EventLogEntryType.Information);//4.0.30319.42000 = .NET Framework 4.6, its point releases, and the .NET Framework 4.7
SharedUtils.Logger.Log("Starting application", SharedUtils.Logger.EventLogEntryType.Information);

}

Expand Down
4 changes: 2 additions & 2 deletions NetworkMiner/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("2.6.0")]
[assembly: AssemblyFileVersion("2.6.0")]
[assembly: AssemblyVersion("2.7.1")]
[assembly: AssemblyFileVersion("2.7.1")]

0 comments on commit 44666d8

Please sign in to comment.