Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
Initial Release
Browse files Browse the repository at this point in the history
Initial Release
  • Loading branch information
ElektroStudios committed Apr 13, 2019
1 parent bdb319a commit 0addad8
Show file tree
Hide file tree
Showing 4 changed files with 267 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
# LogDisabler plugin for DemonBuddy

![](images/Logo.png)

**LogDisabler** is a plugin for **DemonBuddy** (a bot for **Diablo III** videogame),
on which you can use this plugin to disable the creation of log files.

**DemonBuddy** performs thousands and thousands of I/O disk write operations in short periods of time for writing log files; this can reduce the life of your hard-drive and also can cause an overall negative performance impact on your system if other programs needs are requesting to perform other I/O disk operations simultaneously.

If you don't need to manage the log files created by **DemonBuddy**, then there is no good reason why you are allowing **DemonBuddy** to create these logs. The problem here is **DemonBuddy** does not provide a built-in feature to disable log file creation, and this is why you should use **LogDisabler** plugin.

------------------------

# Screenshots

![](images/01.png)

------------------------

# Donations

To support me, maybe you would like to consider buying 'DevCase for .NET Framework', a powerful set of libraries for .NET developers.

Here is a link to the purchase page:

https://codecanyon.net/item/elektrokit-class-library-for-net/19260282

Thank you.
Binary file added images/01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
240 changes: 240 additions & 0 deletions src/Plugins/LogDisabler/Plugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
// ***********************************************************************
// Author : ElektroStudios
// Modified : 13-April-2019
// ***********************************************************************

#region Usings

using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;

using log4net;

using Zeta.Bot;
using Zeta.Common;
using Zeta.Common.Plugins;

#endregion

#region Plugin

namespace LogDisabler {

/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// Plugin.
/// </remarks>
/// ----------------------------------------------------------------------------------------------------
public sealed class Plugin : IPlugin {

#region Private Fields

/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// The logger instance.
/// </summary>
/// ----------------------------------------------------------------------------------------------------
private readonly ILog log = Logger.GetLoggerInstanceForType();

#endregion

#region Properties

/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// Gets the plugin name.
/// </summary>
/// ----------------------------------------------------------------------------------------------------
public string Name {
get {
return "Log Disabler";
}
}

/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// Gets the plugin description.
/// </summary>
/// ----------------------------------------------------------------------------------------------------
public string Description {
get {
return "Disables the creation of log files.";
}
}

/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// Gets the plugin version.
/// </summary>
/// ----------------------------------------------------------------------------------------------------
public Version Version {
get {
return new Version(1, 0);
}
}

/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// Gets the plugin author.
/// </summary>
/// ----------------------------------------------------------------------------------------------------
public string Author {
get {
return "ElektroStudios";
}
}

/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// Gets the user-interface configuration window.
/// </summary>
/// ----------------------------------------------------------------------------------------------------
public Window DisplayWindow {
get {
return null;
}
}

#endregion

#region Event Invocators

/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// Called when this plugin is initialized.
/// </summary>
/// ----------------------------------------------------------------------------------------------------
void IPlugin.OnInitialize() {
}

/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// Called when the bot sends a "pulse".
/// </summary>
/// ----------------------------------------------------------------------------------------------------
void IPlugin.OnPulse() {
}

/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// Called when this plugin is enabled.
/// </summary>
/// ----------------------------------------------------------------------------------------------------
void IPlugin.OnEnabled() {
this.log.Info("[Log Disabler] Plugin enabled.");

string assemblyPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
string logDirPath = Path.Combine(assemblyPath, "Logs");

DirectoryInfo logDir = new DirectoryInfo(logDirPath);
if (!logDir.Exists) {
try {
logDir.Create();
} catch (Exception ex) {
this.log.Error("[Log Disabler] Can't create 'Logs' directory: " + ex);
}
}

WindowsIdentity id = WindowsIdentity.GetCurrent();
FileSystemAccessRule rule = new FileSystemAccessRule(id.User, FileSystemRights.WriteData, AccessControlType.Deny);

DirectorySecurity acl = new DirectorySecurity();
acl.AddAccessRule(rule);
try {
logDir.SetAccessControl(acl);
} catch (Exception ex) {
this.log.Error("[Log Disabler] Can't set ACL for 'Logs' directory: " + ex);
}

// Delete any log file.
foreach (FileInfo logFile in logDir.EnumerateFiles("*.txt")) {
try {
logFile.Delete();
} catch (Exception ex) {
}
}
}

/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// Called when this plugin is disabled.
/// </summary>
/// ----------------------------------------------------------------------------------------------------
void IPlugin.OnDisabled() {
this.log.Info("[Log Disabler] Plugin disabled.");

string assemblyPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
string logDirPath = Path.Combine(assemblyPath, "Logs");

DirectoryInfo logDir = new DirectoryInfo(logDirPath);
if (!logDir.Exists) {
try {
logDir.Create();
} catch (Exception ex) {
this.log.Error("[Log Disabler] Can't create 'Logs' directory: " + ex);
}
}

WindowsIdentity id = WindowsIdentity.GetCurrent();
FileSystemAccessRule rule = new FileSystemAccessRule(id.User, FileSystemRights.WriteData, AccessControlType.Allow);

DirectorySecurity acl = new DirectorySecurity();
acl.AddAccessRule(rule);
try {
logDir.SetAccessControl(acl);
} catch (Exception ex) {
this.log.Error("[Log Disabler] Can't set ACL for 'Logs' directory: " + ex);
}
}

/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// Called when the bot is shutting down.
/// </summary>
/// ----------------------------------------------------------------------------------------------------
void IPlugin.OnShutdown() {
}

#endregion

#region Public Methods

/// ----------------------------------------------------------------------------------------------------
/// <summary>
/// Indicates whether or not the current <see cref="IPlugin"/> is equal to another <see cref="IPlugin"/>.
/// </summary>
/// ----------------------------------------------------------------------------------------------------
/// <param name="other">
/// An <see cref="IPlugin"/> to compare with this <see cref="IPlugin"/>.
/// </param>
/// ----------------------------------------------------------------------------------------------------
/// <returns>
/// <see langword="true" /> if the current <see cref="IPlugin"/> is equal to the <paramref name="other" /> parameter;
/// otherwise, <see langword="false" />.
/// </returns>
/// ----------------------------------------------------------------------------------------------------
public bool Equals(IPlugin other) {
string thisName = (this.Name + this.Author);
string otherName = (other.Name + other.Author);
return otherName.Equals(thisName, StringComparison.InvariantCultureIgnoreCase);
}

#endregion

}

}

#endregion

0 comments on commit 0addad8

Please sign in to comment.