Refactored Logging System

This commit is contained in:
ruri
2019-12-21 01:44:55 +01:00
parent b9dadd6ee8
commit 49b96d926f
18 changed files with 341 additions and 289 deletions
+2 -98
View File
@@ -12,25 +12,6 @@ using System.Windows.Media;
namespace OpenBullet
{
public enum Components
{
Main,
RunnerManager,
Runner,
ProxyManager,
WordlistManager,
HitsDB,
ConfigManager,
Stacker,
OtherOptions,
Settings,
ListGenerator,
SeleniumTools,
Database,
ComboSuite,
About
}
public static class Globals
{
// Version
@@ -41,7 +22,7 @@ namespace OpenBullet
// Log Window
public static LogWindow logWindow;
public static OBLog log = new OBLog();
public static LoggerViewModel logger = new LoggerViewModel();
// Constant file paths
public static string dataBaseFile = @"DB/OpenBullet.db";
@@ -62,84 +43,7 @@ namespace OpenBullet
// Runners
public static ObservableCollection<RunnerViewModel> Runners = new ObservableCollection<RunnerViewModel>();
// Logging Methods
public static void Log(Components component, LogLevel level, string message, bool prompt = false, int timeout = 0)
{
if (prompt)
{
if (timeout == 0)
{
MessageBox.Show(message, level.ToString());
}
else
{
var w = new System.Windows.Forms.Form() { Size = new System.Drawing.Size(0, 0) };
Task.Delay(TimeSpan.FromSeconds(timeout))
.ContinueWith((t) => w.Close(), TaskScheduler.FromCurrentSynchronizationContext());
System.Windows.Forms.MessageBox.Show(w, message, level.ToString());
}
}
if (!CanLog()) return;
App.Current.Dispatcher.Invoke(new Action(() =>
{
var entry = new LogEntry(component.ToString(), message, level);
InsertEntry(entry);
LogToFile(entry);
}));
}
public static void LogInfo(Components component, string message, bool prompt = false, int timeout = 0)
{
Log(component, LogLevel.Info, message, prompt, timeout);
}
public static void LogWarning(Components component, string message, bool prompt = false, int timeout = 0)
{
Log(component, LogLevel.Warning, message, prompt, timeout);
}
public static void LogError(Components component, string message, bool prompt = false, int timeout = 0)
{
Log(component, LogLevel.Error, message, prompt, timeout);
}
private static bool CanLog()
{
try
{
return obSettings.General.EnableLogging;
}
catch { return false; }
}
private static void InsertEntry(LogEntry entry)
{
try
{
log.List.Insert(0, entry);
var count = log.List.Count;
if (count > obSettings.General.LogBufferSize)
{
log.List.RemoveAt(count - 1);
}
}
catch { }
}
private static void LogToFile(LogEntry entry)
{
try
{
if(obSettings.General.LogToFile)
File.AppendAllText(logFile, $"[{entry.LogTime}] ({entry.LogLevel}) {entry.LogComponent} - " + entry.LogString + Environment.NewLine);
}
catch { }
}
public static System.Windows.Media.Color GetColor(string propertyName)
public static Color GetColor(string propertyName)
{
try { return ((SolidColorBrush)App.Current.Resources[propertyName]).Color; }
catch { return ((SolidColorBrush)App.Current.Resources["ForegroundMain"]).Color; }
+1 -1
View File
@@ -19,7 +19,7 @@
<RowDefinition Height="40" />
</Grid.RowDefinitions>
<ListView x:Name="logListView" Grid.Row="0" Foreground="Gainsboro" Background="Transparent" ItemsSource="{Binding Path=List, Mode=OneWay}" SelectionMode="Extended" BorderThickness="1">
<ListView x:Name="logListView" Grid.Row="0" Foreground="Gainsboro" Background="Transparent" ItemsSource="{Binding Path=EntriesCollection, Mode=OneWay}" SelectionMode="Extended" BorderThickness="1">
<!-- Align Headers to the Left -->
<ListView.Resources>
<Style x:Key="GridViewColumnHeaderGripper" TargetType="Thumb">
+3 -3
View File
@@ -13,7 +13,7 @@ namespace OpenBullet
public LogWindow()
{
InitializeComponent();
DataContext = Globals.log;
DataContext = Globals.logger;
Closing += LogWindowClosing;
}
@@ -51,14 +51,14 @@ namespace OpenBullet
{
try
{
Globals.log.List.Clear();
Globals.logger.EntriesCollection.Clear();
}
catch { }
}
private void searchButton_Click(object sender, RoutedEventArgs e)
{
Globals.log.Refresh();
Globals.logger.Refresh();
}
}
}
+190
View File
@@ -0,0 +1,190 @@
using RuriLib;
using RuriLib.Interfaces;
using RuriLib.ViewModels;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
namespace OpenBullet
{
public enum Components
{
Main,
RunnerManager,
Runner,
ProxyManager,
WordlistManager,
HitsDB,
ConfigManager,
Stacker,
OtherOptions,
Settings,
ListGenerator,
SeleniumTools,
Database,
About,
Unknown
}
public class LoggerViewModel : ViewModelBase, ILogger
{
public ObservableCollection<LogEntry> EntriesCollection { get; set; }
public IEnumerable<LogEntry> Entries => EntriesCollection;
public bool Enabled
{
get
{
try
{
// The settings might be null
return Globals.obSettings.General.EnableLogging;
}
catch
{
return false;
}
}
}
public int BufferSize
{
get
{
try
{
// The settings might be null
return Globals.obSettings.General.LogBufferSize;
}
catch
{
return 0;
}
}
}
public LoggerViewModel()
{
EntriesCollection = new ObservableCollection<LogEntry>();
CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(EntriesCollection);
view.Filter = ErrorFilter;
}
public void Refresh()
{
try
{
CollectionViewSource.GetDefaultView(EntriesCollection).Refresh();
}
catch { }
}
#region Filters
private bool onlyErrors = false;
public bool OnlyErrors { get { return onlyErrors; } set { onlyErrors = value; OnPropertyChanged(); Refresh(); } }
private string searchString = "";
public string SearchString { get { return searchString; } set { searchString = value; OnPropertyChanged(); } }
private bool ErrorFilter(object item)
{
// If search box not empty, filter out all the stuff that's not needed
if (SearchString != "")
{
if (!(item as LogEntry).LogString.ToLower().Contains(SearchString.ToLower()))
return false;
}
if (!Globals.logger.OnlyErrors)
return true;
else
return ((item as LogEntry).LogLevel == LogLevel.Error);
}
#endregion
public void Log(string message, LogLevel level, bool prompt = false, int timeout = 0)
{
Log(Components.Unknown, level, message, prompt, timeout);
}
public void Log(Components component, LogLevel level, string message, bool prompt = false, int timeout = 0)
{
if (prompt)
{
if (timeout == 0)
{
MessageBox.Show(message, level.ToString());
}
else
{
var w = new System.Windows.Forms.Form() { Size = new System.Drawing.Size(0, 0) };
Task.Delay(TimeSpan.FromSeconds(timeout))
.ContinueWith((t) => w.Close(), TaskScheduler.FromCurrentSynchronizationContext());
System.Windows.Forms.MessageBox.Show(w, message, level.ToString());
}
}
if (!Enabled)
{
return;
}
App.Current.Dispatcher.Invoke(new Action(() =>
{
var entry = new LogEntry(component.ToString(), message, level);
InsertEntry(entry);
LogToFile(entry);
}));
}
public void LogInfo(Components component, string message, bool prompt = false, int timeout = 0)
{
Log(component, LogLevel.Info, message, prompt, timeout);
}
public void LogWarning(Components component, string message, bool prompt = false, int timeout = 0)
{
Log(component, LogLevel.Warning, message, prompt, timeout);
}
public void LogError(Components component, string message, bool prompt = false, int timeout = 0)
{
Log(component, LogLevel.Error, message, prompt, timeout);
}
private void InsertEntry(LogEntry entry)
{
try
{
EntriesCollection.Insert(0, entry);
var count = EntriesCollection.Count;
if (count > BufferSize)
{
EntriesCollection.RemoveAt(count - 1);
}
}
catch { }
}
private static void LogToFile(LogEntry entry)
{
try
{
if (Globals.obSettings.General.LogToFile)
{
File.AppendAllText(Globals.logFile, $"[{entry.LogTime}] ({entry.LogLevel}) {entry.LogComponent} - " + entry.LogString + Environment.NewLine);
}
}
catch { }
}
}
}
+19 -19
View File
@@ -96,27 +96,27 @@ namespace OpenBullet
if (!File.Exists(Globals.rlSettingsFile))
{
MessageBox.Show("RuriLib Settings file not found, generating a default one");
Globals.LogWarning(Components.Main, "RuriLib Settings file not found, generating a default one");
Globals.logger.LogWarning(Components.Main, "RuriLib Settings file not found, generating a default one");
IOManager.SaveSettings(Globals.rlSettingsFile, Globals.rlSettings);
Globals.LogInfo(Components.Main, $"Created the default RuriLib Settings file {Globals.rlSettingsFile}");
Globals.logger.LogInfo(Components.Main, $"Created the default RuriLib Settings file {Globals.rlSettingsFile}");
}
else
{
Globals.rlSettings = IOManager.LoadSettings(Globals.rlSettingsFile);
Globals.LogInfo(Components.Main, "Loaded the existing RuriLib Settings file");
Globals.logger.LogInfo(Components.Main, "Loaded the existing RuriLib Settings file");
}
if (!File.Exists(Globals.obSettingsFile))
{
MessageBox.Show("OpenBullet Settings file not found, generating a default one");
Globals.LogWarning(Components.Main, "OpenBullet Settings file not found, generating a default one");
Globals.logger.LogWarning(Components.Main, "OpenBullet Settings file not found, generating a default one");
OBIOManager.SaveSettings(Globals.obSettingsFile, Globals.obSettings);
Globals.LogInfo(Components.Main, $"Created the default OpenBullet Settings file {Globals.obSettingsFile}");
Globals.logger.LogInfo(Components.Main, $"Created the default OpenBullet Settings file {Globals.obSettingsFile}");
}
else
{
Globals.obSettings = OBIOManager.LoadSettings(Globals.obSettingsFile);
Globals.LogInfo(Components.Main, "Loaded the existing OpenBullet Settings file");
Globals.logger.LogInfo(Components.Main, "Loaded the existing OpenBullet Settings file");
}
// If there is no DB backup or if it's more than 1 day old, back up the DB
@@ -135,12 +135,12 @@ namespace OpenBullet
// Delete the old file and copy over the new one
File.Delete(Globals.dataBaseBackupFile);
File.Copy(Globals.dataBaseFile, Globals.dataBaseBackupFile);
Globals.LogInfo(Components.Main, "Backed up the DB");
Globals.logger.LogInfo(Components.Main, "Backed up the DB");
}
}
catch (Exception ex)
{
Globals.LogError(Components.Main, $"Could not backup the DB: {ex.Message}");
Globals.logger.LogError(Components.Main, $"Could not backup the DB: {ex.Message}");
}
Topmost = Globals.obSettings.General.AlwaysOnTop;
@@ -148,19 +148,19 @@ namespace OpenBullet
RunnerManagerPage = new RunnerManager(Globals.obSettings.General.AutoCreateRunner);
if (Globals.obSettings.General.AutoCreateRunner)
CurrentRunnerPage = RunnerManagerPage.vm.Runners.FirstOrDefault().Page;
Globals.LogInfo(Components.Main, "Initialized RunnerManager");
Globals.logger.LogInfo(Components.Main, "Initialized RunnerManager");
ProxyManagerPage = new ProxyManager();
Globals.LogInfo(Components.Main, "Initialized ProxyManager");
Globals.logger.LogInfo(Components.Main, "Initialized ProxyManager");
WordlistManagerPage = new WordlistManager();
Globals.LogInfo(Components.Main, "Initialized WordlistManager");
Globals.logger.LogInfo(Components.Main, "Initialized WordlistManager");
ConfigsPage = new ConfigsSection();
Globals.LogInfo(Components.Main, "Initialized ConfigManager");
Globals.logger.LogInfo(Components.Main, "Initialized ConfigManager");
HitsDBPage = new HitsDB();
Globals.LogInfo(Components.Main, "Initialized HitsDB");
Globals.logger.LogInfo(Components.Main, "Initialized HitsDB");
OBSettingsPage = new Settings();
Globals.LogInfo(Components.Main, "Initialized Settings");
Globals.logger.LogInfo(Components.Main, "Initialized Settings");
ToolsPage = new ToolsSection();
Globals.LogInfo(Components.Main, "Initialized Tools");
Globals.logger.LogInfo(Components.Main, "Initialized Tools");
AboutPage = new About();
menuOptionRunner_MouseDown(this, null);
@@ -328,7 +328,7 @@ namespace OpenBullet
var active = RunnerManagerPage.vm.Runners.Count(r => r.Runner.Busy);
if (!Globals.obSettings.General.DisableQuitWarning || active > 0)
{
Globals.LogWarning(Components.Main, "Prompting quit confirmation");
Globals.logger.LogWarning(Components.Main, "Prompting quit confirmation");
if (active == 0)
{
@@ -346,12 +346,12 @@ namespace OpenBullet
if (!Globals.obSettings.General.DisableNotSavedWarning && !Globals.mainWindow.ConfigsPage.ConfigManagerPage.CheckSaved())
{
Globals.LogWarning(Components.Main, "Config not saved, prompting quit confirmation");
Globals.logger.LogWarning(Components.Main, "Config not saved, prompting quit confirmation");
if (MessageBox.Show("The Config in Stacker wasn't saved.\nAre you sure you want to quit?",
"Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
return false;
}
Globals.LogInfo(Components.Main, "Quit sequence initiated");
Globals.logger.LogInfo(Components.Main, "Quit sequence initiated");
return true;
}
@@ -472,7 +472,7 @@ namespace OpenBullet
var bitmap = CopyScreen((int)Width, (int)Height, (int)Top, (int)Left);
Clipboard.SetImage(bitmap);
GetBitmap(bitmap).Save("screenshot.jpg", ImageFormat.Jpeg);
Globals.LogInfo(Components.Main, "Acquired screenshot");
Globals.logger.LogInfo(Components.Main, "Acquired screenshot");
}
private static BitmapSource CopyScreen(int width, int height, int top, int left)
-48
View File
@@ -1,48 +0,0 @@
using RuriLib;
using RuriLib.ViewModels;
using System.Collections.ObjectModel;
using System.Windows.Data;
namespace OpenBullet
{
public class OBLog : ViewModelBase
{
public ObservableCollection<LogEntry> List { get; set; }
private bool onlyErrors = false;
public bool OnlyErrors { get { return onlyErrors; } set { onlyErrors = value; OnPropertyChanged("OnlyErrors"); Refresh(); } }
private string searchString = "";
public string SearchString { get { return searchString; } set { searchString = value; OnPropertyChanged("SearchString"); } }
public OBLog()
{
List = new ObservableCollection<LogEntry>();
CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(List);
view.Filter = ErrorFilter;
}
public void Refresh()
{
try
{
CollectionViewSource.GetDefaultView(List).Refresh();
}
catch { }
}
private bool ErrorFilter(object item)
{
if (SearchString != "") // If search box not empty, filter out all the stuff that's not needed
{
if (!(item as LogEntry).LogString.ToLower().Contains(SearchString.ToLower()))
return false;
}
if (!Globals.log.OnlyErrors)
return true;
else
return ((item as LogEntry).LogLevel == LogLevel.Error);
}
}
}
+1 -1
View File
@@ -189,7 +189,7 @@
<Compile Include="Extensions.cs" />
<Compile Include="Models\Source.cs" />
<Compile Include="OBIOManager.cs" />
<Compile Include="OBLog.cs" />
<Compile Include="LoggerViewModel.cs" />
<Compile Include="LogWindow.xaml.cs">
<DependentUpon>LogWindow.xaml</DependentUpon>
</Compile>
@@ -99,7 +99,7 @@ namespace OpenBullet.ViewModels
foreach(var file in Directory.EnumerateFiles(Globals.configFolder).Where(file => file.EndsWith(".loli")))
{
try { models.Add(new ConfigViewModel(file, "Default", IOManager.LoadConfig(file))); }
catch { Globals.LogError(Components.ConfigManager, "Could not load file: " + file); }
catch { Globals.logger.LogError(Components.ConfigManager, "Could not load file: " + file); }
}
// Load the configs in the subfolders
@@ -108,7 +108,7 @@ namespace OpenBullet.ViewModels
foreach(var file in Directory.EnumerateFiles(categoryFolder).Where(file => file.EndsWith(".loli")))
{
try { models.Add(new ConfigViewModel(file, Path.GetFileName(categoryFolder), IOManager.LoadConfig(file))); }
catch { Globals.LogError(Components.ConfigManager, "Could not load file: " + file); }
catch { Globals.logger.LogError(Components.ConfigManager, "Could not load file: " + file); }
}
}
@@ -52,12 +52,12 @@ namespace OpenBullet
case 0:
if (fileName != "")
{
Globals.LogInfo(Components.ProxyManager, $"Trying to load from file {fileName}");
Globals.logger.LogInfo(Components.ProxyManager, $"Trying to load from file {fileName}");
lines.AddRange(File.ReadAllLines(fileName).ToList());
}
else
{
Globals.LogError(Components.ProxyManager, "No file specified!", true);
Globals.logger.LogError(Components.ProxyManager, "No file specified!", true);
return;
}
break;
@@ -69,7 +69,7 @@ namespace OpenBullet
}
else
{
Globals.LogError(Components.ProxyManager, "The box is empty!", true);
Globals.logger.LogError(Components.ProxyManager, "The box is empty!", true);
return;
}
break;
@@ -83,7 +83,7 @@ namespace OpenBullet
}
else
{
Globals.LogError(Components.ProxyManager, "No URL specified!", true);
Globals.logger.LogError(Components.ProxyManager, "No URL specified!", true);
return;
}
break;
@@ -91,7 +91,7 @@ namespace OpenBullet
}
catch (Exception ex)
{
Globals.LogError(Components.ProxyManager, $"There was an error: {ex.Message}");
Globals.logger.LogError(Components.ProxyManager, $"There was an error: {ex.Message}");
return;
}
@@ -33,7 +33,7 @@ namespace OpenBullet
private void searchButton_Click(object sender, RoutedEventArgs e)
{
Globals.LogInfo(Components.Stacker, $"Seaching for {vm.SearchString}");
Globals.logger.LogInfo(Components.Stacker, $"Seaching for {vm.SearchString}");
// Reset all highlights
logRTB.SelectAll();
@@ -65,7 +65,7 @@ namespace OpenBullet
logRTB.SelectionLength = 0;
logRTB.SelectionColor = System.Drawing.Color.Black;
Globals.LogInfo(Components.Stacker, $"Found {vm.Indexes.Count} matches", true);
Globals.logger.LogInfo(Components.Stacker, $"Found {vm.Indexes.Count} matches", true);
if (vm.Indexes.Count > 0)
vm.CurrentSearchMatch = 1;
@@ -53,7 +53,7 @@ namespace OpenBullet.Views.Main.Configs
{
if (!CheckSaved())
{
Globals.LogWarning(Components.Stacker, "Config not saved, prompting quit confirmation");
Globals.logger.LogWarning(Components.Stacker, "Config not saved, prompting quit confirmation");
if (MessageBox.Show("The Config in Stacker wasn't saved.\nAre you sure you want to load another config?",
"Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
return;
@@ -66,12 +66,12 @@ namespace OpenBullet.Views.Main.Configs
{
if (Current.Remote)
{
Globals.LogError(Components.ConfigManager, "The config was pulled from a remote source and cannot be edited!", true);
Globals.logger.LogError(Components.ConfigManager, "The config was pulled from a remote source and cannot be edited!", true);
Current = null;
return;
}
Globals.LogInfo(Components.ConfigManager, "Loading config: " + Current.Name);
Globals.logger.LogInfo(Components.ConfigManager, "Loading config: " + Current.Name);
Globals.mainWindow.ConfigsPage.menuOptionStacker.IsEnabled = true;
Globals.mainWindow.ConfigsPage.menuOptionOtherOptions.IsEnabled = true;
@@ -83,9 +83,9 @@ namespace OpenBullet.Views.Main.Configs
newStacker.vm.ProxyType = Globals.mainWindow.ConfigsPage.StackerPage.vm.ProxyType;
}
Globals.mainWindow.ConfigsPage.StackerPage = newStacker; // Create a Stacker instance
Globals.LogInfo(Components.ConfigManager, "Created and assigned a new Stacker instance");
Globals.logger.LogInfo(Components.ConfigManager, "Created and assigned a new Stacker instance");
Globals.mainWindow.ConfigsPage.OtherOptionsPage = new ConfigOtherOptions(); // Create an Other Options instance
Globals.LogInfo(Components.ConfigManager, "Created and assigned a new Other Options instance");
Globals.logger.LogInfo(Components.ConfigManager, "Created and assigned a new Other Options instance");
Globals.mainWindow.ConfigsPage.menuOptionStacker_MouseDown(this, null); // Switch to Stacker
// Save the last state of the config
@@ -94,7 +94,7 @@ namespace OpenBullet.Views.Main.Configs
}
else
{
Globals.LogError(Components.ConfigManager, "No config selected for loading", true);
Globals.logger.LogError(Components.ConfigManager, "No config selected for loading", true);
}
}
@@ -103,7 +103,7 @@ namespace OpenBullet.Views.Main.Configs
{
if (Current == null)
{
Globals.LogError(Components.ConfigManager, "No config selected for saving!");
Globals.logger.LogError(Components.ConfigManager, "No config selected for saving!");
return;
}
@@ -117,18 +117,18 @@ namespace OpenBullet.Views.Main.Configs
Globals.mainWindow.ConfigsPage.StackerPage == null ||
Globals.mainWindow.ConfigsPage.OtherOptionsPage == null)
{
Globals.LogError(Components.ConfigManager, "No config eligible for saving!", true);
Globals.logger.LogError(Components.ConfigManager, "No config eligible for saving!", true);
return;
}
if (Current.Remote)
{
Globals.LogError(Components.ConfigManager, "The config was pulled from a remote source and cannot be saved!", true);
Globals.logger.LogError(Components.ConfigManager, "The config was pulled from a remote source and cannot be saved!", true);
return;
}
if (vm.CurrentConfigName == "") {
Globals.LogError(Components.ConfigManager, "Empty config name, cannot save", true);
Globals.logger.LogError(Components.ConfigManager, "Empty config name, cannot save", true);
return;
}
@@ -140,28 +140,28 @@ namespace OpenBullet.Views.Main.Configs
Current.Config.Script = stacker.LS.Script;
Globals.LogInfo(Components.ConfigManager, $"Saving config {vm.CurrentConfigName}");
Globals.logger.LogInfo(Components.ConfigManager, $"Saving config {vm.CurrentConfigName}");
Current.Config.Settings.LastModified = DateTime.Now;
Current.Config.Settings.Version = Globals.obVersion;
Globals.LogInfo(Components.ConfigManager, "Converted the unbinded observables and set the Last Modified date");
Globals.logger.LogInfo(Components.ConfigManager, "Converted the unbinded observables and set the Last Modified date");
// Save to file
if (!IOManager.SaveConfig(Current.Config, Current.Path)) {
Globals.LogError(Components.ConfigManager, "Failed to save the config to file.", true);
Globals.logger.LogError(Components.ConfigManager, "Failed to save the config to file.", true);
return;
};
// Save the last state of the config
SaveState();
Globals.LogInfo(Components.ConfigManager, "Refreshing the list");
Globals.logger.LogInfo(Components.ConfigManager, "Refreshing the list");
vm.RefreshList(false);
}
private void deleteConfigsButton_Click(object sender, RoutedEventArgs e)
{
Globals.LogWarning(Components.ConfigManager, "Deletion initiated, prompting warning");
Globals.logger.LogWarning(Components.ConfigManager, "Deletion initiated, prompting warning");
if (MessageBox.Show("This will delete the physical files from your disk! Are you sure you want to continue?", "WARNING", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
{
foreach(ConfigViewModel config in configsListView.SelectedItems)
@@ -170,15 +170,15 @@ namespace OpenBullet.Views.Main.Configs
{
File.Delete(config.Path);
}
catch { Globals.LogError(Components.ConfigManager, "Could not delete file: " + config.Path); }
catch { Globals.logger.LogError(Components.ConfigManager, "Could not delete file: " + config.Path); }
}
Globals.LogInfo(Components.ConfigManager, $"Deleted {configsListView.SelectedItems.Count} configs");
Globals.logger.LogInfo(Components.ConfigManager, $"Deleted {configsListView.SelectedItems.Count} configs");
vm.RefreshList(false);
}
else
{
Globals.LogInfo(Components.ConfigManager, "Deletion cancelled");
Globals.logger.LogInfo(Components.ConfigManager, "Deletion cancelled");
}
}
@@ -191,7 +191,7 @@ namespace OpenBullet.Views.Main.Configs
{
if (!CheckSaved())
{
Globals.LogWarning(Components.Stacker, "Config not saved, prompting quit confirmation");
Globals.logger.LogWarning(Components.Stacker, "Config not saved, prompting quit confirmation");
if (MessageBox.Show("The Config in Stacker wasn't saved.\nAre you sure you want to create a new config?",
"Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
return;
@@ -217,7 +217,7 @@ namespace OpenBullet.Views.Main.Configs
var settings = new ConfigSettings();
settings.Name = name;
settings.Author = author;
Globals.LogInfo(Components.ConfigManager, "Setting up the new Config object, with path '" + path + "'");
Globals.logger.LogInfo(Components.ConfigManager, "Setting up the new Config object, with path '" + path + "'");
Current = new ConfigViewModel(path, category, new Config(settings, ""));
var newStacker = new Stacker(Current);
@@ -228,9 +228,9 @@ namespace OpenBullet.Views.Main.Configs
newStacker.vm.ProxyType = Globals.mainWindow.ConfigsPage.StackerPage.vm.ProxyType;
}
Globals.mainWindow.ConfigsPage.StackerPage = newStacker; // Create a Stacker instance
Globals.LogInfo(Components.ConfigManager, "Created and assigned a new Stacker instance");
Globals.logger.LogInfo(Components.ConfigManager, "Created and assigned a new Stacker instance");
Globals.mainWindow.ConfigsPage.OtherOptionsPage = new ConfigOtherOptions(); // Create an Other Options instance
Globals.LogInfo(Components.ConfigManager, "Created and assigned a new Other Options instance");
Globals.logger.LogInfo(Components.ConfigManager, "Created and assigned a new Other Options instance");
Globals.mainWindow.ConfigsPage.menuOptionStacker_MouseDown(this, null); // Switch to Stacker
// Save to disk
@@ -287,7 +287,7 @@ namespace OpenBullet.Views.Main.Configs
{
System.Diagnostics.Process.Start(System.IO.Path.Combine(Directory.GetCurrentDirectory(), Globals.configFolder));
}
catch { Globals.LogError(Components.ConfigManager, "No config folder found!", true); }
catch { Globals.logger.LogError(Components.ConfigManager, "No config folder found!", true); }
}
private void ListViewItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)
+27 -27
View File
@@ -170,7 +170,7 @@ namespace OpenBullet.Views.Main.Configs
public void AddBlock(BlockBase block)
{
Globals.LogInfo(Components.Stacker, $"Added a block of type {block.GetType()} in position {vm.Stack.Count}");
Globals.logger.LogInfo(Components.Stacker, $"Added a block of type {block.GetType()} in position {vm.Stack.Count}");
vm.AddBlock(block, -1);
}
@@ -225,16 +225,16 @@ namespace OpenBullet.Views.Main.Configs
if (vm.LastDeletedBlock != null)
{
vm.AddBlock(vm.LastDeletedBlock, vm.LastDeletedIndex);
Globals.LogInfo(Components.Stacker, $"Readded block of type {vm.LastDeletedBlock.GetType()} in position {vm.LastDeletedIndex}");
Globals.logger.LogInfo(Components.Stacker, $"Readded block of type {vm.LastDeletedBlock.GetType()} in position {vm.LastDeletedIndex}");
vm.LastDeletedBlock = null;
}
else Globals.LogError(Components.Stacker, "Nothing to undo");
else Globals.logger.LogError(Components.Stacker, "Nothing to undo");
break;
case System.Windows.Input.Key.C:
if (Globals.obSettings.General.DisableCopyPasteBlocks) return;
try { Clipboard.SetText(IOManager.SerializeBlocks(vm.SelectedBlocks.Select(b => b.Block).ToList())); }
catch { Globals.LogError(Components.Stacker, "Exception while copying blocks"); }
catch { Globals.logger.LogError(Components.Stacker, "Exception while copying blocks"); }
break;
case System.Windows.Input.Key.V:
@@ -244,7 +244,7 @@ namespace OpenBullet.Views.Main.Configs
foreach (var block in IOManager.DeserializeBlocks(Clipboard.GetText()))
vm.AddBlock(block);
}
catch { Globals.LogError(Components.Stacker, "Exception while pasting blocks"); }
catch { Globals.logger.LogError(Components.Stacker, "Exception while pasting blocks"); }
break;
case System.Windows.Input.Key.S:
@@ -281,9 +281,9 @@ namespace OpenBullet.Views.Main.Configs
if (!debugger.IsBusy)
{
debugger.RunWorkerAsync();
Globals.LogInfo(Components.Stacker, "Started the debugger");
Globals.logger.LogInfo(Components.Stacker, "Started the debugger");
}
else { Globals.LogError(Components.Stacker, "Cannot start the debugger (busy)"); }
else { Globals.logger.LogError(Components.Stacker, "Cannot start the debugger (busy)"); }
startDebuggerButton.Content = "Abort";
debugger.Status = WorkerStatus.Running;
@@ -293,7 +293,7 @@ namespace OpenBullet.Views.Main.Configs
if (debugger.IsBusy)
{
debugger.CancelAsync();
Globals.LogInfo(Components.Stacker, "Sent Cancellation Request to the debugger");
Globals.logger.LogInfo(Components.Stacker, "Sent Cancellation Request to the debugger");
}
startDebuggerButton.Content = "Force";
@@ -302,7 +302,7 @@ namespace OpenBullet.Views.Main.Configs
case WorkerStatus.Stopping:
debugger.Abort();
Globals.LogInfo(Components.Stacker, "Hard aborted the debugger");
Globals.logger.LogInfo(Components.Stacker, "Hard aborted the debugger");
startDebuggerButton.Content = "Start";
debugger.Status = WorkerStatus.Idle;
vm.ControlsEnabled = true;
@@ -317,23 +317,23 @@ namespace OpenBullet.Views.Main.Configs
{
if (vm.BotData.BrowserOpen)
{
Globals.LogInfo(Components.Stacker, "Quitting the previously opened browser");
Globals.logger.LogInfo(Components.Stacker, "Quitting the previously opened browser");
vm.BotData.Driver.Quit();
Globals.LogInfo(Components.Stacker, "Quitted correctly");
Globals.logger.LogInfo(Components.Stacker, "Quitted correctly");
}
}
// Convert Observables
Globals.LogInfo(Components.Stacker, "Converting Observables");
Globals.logger.LogInfo(Components.Stacker, "Converting Observables");
vm.ConvertKeychains();
// Initialize Request Data
Globals.LogInfo(Components.Stacker, "Initializing the request data");
Globals.logger.LogInfo(Components.Stacker, "Initializing the request data");
CProxy proxy = null;
if (vm.TestProxy.StartsWith("(")) // Parse in advanced mode
{
try { proxy = (new CProxy()).Parse(vm.TestProxy); }
catch { Globals.LogError(Components.Stacker, "Invalid Proxy Syntax", true); }
catch { Globals.logger.LogError(Components.Stacker, "Invalid Proxy Syntax", true); }
}
else // Parse in standard mode
{
@@ -349,7 +349,7 @@ namespace OpenBullet.Views.Main.Configs
// Ask for user input
foreach (var input in vm.BotData.ConfigSettings.CustomInputs)
{
Globals.LogInfo(Components.Stacker, $"Asking for user input: {input.Description}");
Globals.logger.LogInfo(Components.Stacker, $"Asking for user input: {input.Description}");
App.Current.Dispatcher.Invoke(new Action(() =>
{
(new MainDialog(new DialogCustomInput(this, input.VariableName, input.Description), "Custom Input")).ShowDialog();
@@ -357,7 +357,7 @@ namespace OpenBullet.Views.Main.Configs
}
// Set start block
Globals.LogInfo(Components.Stacker, "Setting the first block as the current block");
Globals.logger.LogInfo(Components.Stacker, "Setting the first block as the current block");
// Print start line
var proxyEnabledText = vm.UseProxy ? "ENABLED" : "DISABLED";
@@ -369,7 +369,7 @@ namespace OpenBullet.Views.Main.Configs
// Open browser if Always Open
if (vm.Config.Config.Settings.AlwaysOpen)
{
Globals.LogInfo(Components.Stacker, "Opening the Browser");
Globals.logger.LogInfo(Components.Stacker, "Opening the Browser");
SBlockBrowserAction.OpenBrowser(vm.BotData);
}
@@ -382,7 +382,7 @@ namespace OpenBullet.Views.Main.Configs
Thread.Sleep(100);
if (debugger.CancellationPending) {
Globals.LogInfo(Components.Stacker, "Found cancellation pending, aborting debugger");
Globals.logger.LogInfo(Components.Stacker, "Found cancellation pending, aborting debugger");
return;
}
@@ -390,7 +390,7 @@ namespace OpenBullet.Views.Main.Configs
{
vm.SBSEnabled = false;
Process();
Globals.LogInfo(Components.Stacker, $"Block processed in SBS mode, can proceed: {vm.LS.CanProceed}");
Globals.logger.LogInfo(Components.Stacker, $"Block processed in SBS mode, can proceed: {vm.LS.CanProceed}");
vm.SBSEnabled = true;
vm.SBSClear = false;
}
@@ -405,7 +405,7 @@ namespace OpenBullet.Views.Main.Configs
{
if (debugger.CancellationPending)
{
Globals.LogInfo(Components.Stacker, "Found cancellation pending, aborting debugger");
Globals.logger.LogInfo(Components.Stacker, "Found cancellation pending, aborting debugger");
return;
}
@@ -420,9 +420,9 @@ namespace OpenBullet.Views.Main.Configs
try {
vm.BotData.Driver.Quit();
vm.BotData.BrowserOpen = false;
Globals.LogInfo(Components.Stacker, "Successfully quit the browser");
Globals.logger.LogInfo(Components.Stacker, "Successfully quit the browser");
}
catch (Exception ex) { Globals.LogError(Components.Stacker, $"Cannot quit the browser - {ex.Message}"); }
catch (Exception ex) { Globals.logger.LogError(Components.Stacker, $"Cannot quit the browser - {ex.Message}"); }
}
}
@@ -430,10 +430,10 @@ namespace OpenBullet.Views.Main.Configs
{
try {
vm.LS.TakeStep(vm.BotData);
Globals.LogInfo(Components.Stacker, $"Processed {BlockBase.TruncatePretty(vm.LS.CurrentLine, 20)}");
Globals.logger.LogInfo(Components.Stacker, $"Processed {BlockBase.TruncatePretty(vm.LS.CurrentLine, 20)}");
}
catch (Exception ex) {
Globals.LogError(Components.Stacker, $"Processing of line {BlockBase.TruncatePretty(vm.LS.CurrentLine, 20)} failed, exception: {ex.Message}");
Globals.logger.LogError(Components.Stacker, $"Processing of line {BlockBase.TruncatePretty(vm.LS.CurrentLine, 20)} failed, exception: {ex.Message}");
}
PrintBotData();
@@ -527,7 +527,7 @@ namespace OpenBullet.Views.Main.Configs
vm.BotData.LogBuffer.Add(new LogEntry($"===== DEBUGGER ENDED AFTER {timer.ElapsedMilliseconds / 1000.0} SECOND(S) WITH STATUS: {vm.BotData.StatusString} =====", Colors.White));
PrintLogBuffer();
Globals.LogInfo(Components.Stacker, "Debugger completed");
Globals.logger.LogInfo(Components.Stacker, "Debugger completed");
}
private void nextStepButton_Click(object sender, RoutedEventArgs e)
@@ -542,7 +542,7 @@ namespace OpenBullet.Views.Main.Configs
private void searchButton_Click(object sender, RoutedEventArgs e)
{
Globals.LogInfo(Components.Stacker, $"Seaching for {vm.SearchString}");
Globals.logger.LogInfo(Components.Stacker, $"Seaching for {vm.SearchString}");
// Reset all highlights
logRTB.SelectAll();
@@ -574,7 +574,7 @@ namespace OpenBullet.Views.Main.Configs
logRTB.SelectionLength = 0;
logRTB.SelectionColor = System.Drawing.Color.Black;
Globals.LogInfo(Components.Stacker, $"Found {vm.Indexes.Count} matches", true);
Globals.logger.LogInfo(Components.Stacker, $"Found {vm.Indexes.Count} matches", true);
if (vm.Indexes.Count > 0)
vm.CurrentSearchMatch = 1;
+3 -3
View File
@@ -20,7 +20,7 @@ namespace OpenBullet.Views.Main
InitializeComponent();
ConfigManagerPage = new ConfigManager();
Globals.LogInfo(Components.ConfigManager, "Initialized Manager Page");
Globals.logger.LogInfo(Components.ConfigManager, "Initialized Manager Page");
menuOptionManager_MouseDown(this, null);
}
@@ -41,7 +41,7 @@ namespace OpenBullet.Views.Main
}
else
{
Globals.LogError(Components.ConfigManager, "Cannot switch to stacker since no config is loaded or the loaded config isn't public");
Globals.logger.LogError(Components.ConfigManager, "Cannot switch to stacker since no config is loaded or the loaded config isn't public");
}
}
@@ -57,7 +57,7 @@ namespace OpenBullet.Views.Main
}
else
{
Globals.LogError(Components.ConfigManager, "Cannot switch to other options since no config is loaded");
Globals.logger.LogError(Components.ConfigManager, "Cannot switch to other options since no config is loaded");
}
}
+22 -22
View File
@@ -89,28 +89,28 @@ namespace OpenBullet.Views.Main
private void configFilterCombobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
vm.ConfigFilter = configFilterCombobox.SelectedValue.ToString();
Globals.LogInfo(Components.HitsDB, $"Changed config filter to {vm.ConfigFilter}, found {vm.Total} hits");
Globals.logger.LogInfo(Components.HitsDB, $"Changed config filter to {vm.ConfigFilter}, found {vm.Total} hits");
}
private void typeFilterCombobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
vm.TypeFilter = (string)typeFilterCombobox.SelectedValue;
Globals.LogInfo(Components.HitsDB, $"Changed type filter to {vm.TypeFilter}, found {vm.Total} hits");
Globals.logger.LogInfo(Components.HitsDB, $"Changed type filter to {vm.TypeFilter}, found {vm.Total} hits");
}
private void purgeButton_Click(object sender, RoutedEventArgs e)
{
Globals.LogWarning(Components.HitsDB, "Purge selected, prompting warning");
Globals.logger.LogWarning(Components.HitsDB, "Purge selected, prompting warning");
if (MessageBox.Show("This will purge the WHOLE Hits DB, are you sure you want to continue?", "WARNING", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
{
Globals.LogInfo(Components.HitsDB, "Purge initiated");
Globals.logger.LogInfo(Components.HitsDB, "Purge initiated");
vm.RemoveAll();
Globals.LogInfo(Components.HitsDB, "Purge finished");
Globals.logger.LogInfo(Components.HitsDB, "Purge finished");
}
else { Globals.LogInfo(Components.HitsDB, "Purge dismissed"); }
else { Globals.logger.LogInfo(Components.HitsDB, "Purge dismissed"); }
}
private void listViewColumnHeader_Click(object sender, RoutedEventArgs e)
@@ -156,7 +156,7 @@ namespace OpenBullet.Views.Main
}
catch (Exception ex)
{
Globals.LogError(Components.HitsDB, $"Exception while copying hits - {ex.Message}");
Globals.logger.LogError(Components.HitsDB, $"Exception while copying hits - {ex.Message}");
}
}
@@ -168,7 +168,7 @@ namespace OpenBullet.Views.Main
}
catch (Exception ex)
{
Globals.LogError(Components.HitsDB, $"Exception while copying hits - {ex.Message}");
Globals.logger.LogError(Components.HitsDB, $"Exception while copying hits - {ex.Message}");
}
}
@@ -180,7 +180,7 @@ namespace OpenBullet.Views.Main
}
catch (Exception ex)
{
Globals.LogError(Components.HitsDB, $"Exception while copying hits - {ex.Message}");
Globals.logger.LogError(Components.HitsDB, $"Exception while copying hits - {ex.Message}");
}
}
@@ -192,7 +192,7 @@ namespace OpenBullet.Views.Main
}
catch (Exception ex)
{
Globals.LogError(Components.HitsDB, $"Exception while copying hits - {ex.Message}");
Globals.logger.LogError(Components.HitsDB, $"Exception while copying hits - {ex.Message}");
}
}
#endregion
@@ -206,7 +206,7 @@ namespace OpenBullet.Views.Main
}
catch (Exception ex)
{
Globals.LogError(Components.HitsDB, $"Exception while saving hits - {ex.Message}");
Globals.logger.LogError(Components.HitsDB, $"Exception while saving hits - {ex.Message}");
}
}
@@ -218,7 +218,7 @@ namespace OpenBullet.Views.Main
}
catch (Exception ex)
{
Globals.LogError(Components.HitsDB, $"Exception while saving hits - {ex.Message}");
Globals.logger.LogError(Components.HitsDB, $"Exception while saving hits - {ex.Message}");
}
}
@@ -230,7 +230,7 @@ namespace OpenBullet.Views.Main
}
catch (Exception ex)
{
Globals.LogError(Components.HitsDB, $"Exception while saving hits - {ex.Message}");
Globals.logger.LogError(Components.HitsDB, $"Exception while saving hits - {ex.Message}");
}
}
@@ -242,7 +242,7 @@ namespace OpenBullet.Views.Main
}
catch (Exception ex)
{
Globals.LogError(Components.HitsDB, $"Exception while copying hits - {ex.Message}");
Globals.logger.LogError(Components.HitsDB, $"Exception while copying hits - {ex.Message}");
}
}
#endregion
@@ -261,19 +261,19 @@ namespace OpenBullet.Views.Main
}
catch (Exception ex)
{
Globals.LogError(Components.HitsDB, $"Failed to copy selected proxy - {ex.Message}");
Globals.logger.LogError(Components.HitsDB, $"Failed to copy selected proxy - {ex.Message}");
}
}
private void searchButton_Click(object sender, RoutedEventArgs e)
{
vm.SearchString = searchBar.Text;
Globals.LogInfo(Components.HitsDB, "Changed capture filter to '"+ vm.SearchString + $"', found {vm.Total} hits");
Globals.logger.LogInfo(Components.HitsDB, "Changed capture filter to '"+ vm.SearchString + $"', found {vm.Total} hits");
}
private void sendToRecheck_Click(object sender, RoutedEventArgs e)
{
if (hitsListView.SelectedItems.Count == 0) { Globals.LogError(Components.HitsDB, "No hits selected!", true); return; }
if (hitsListView.SelectedItems.Count == 0) { Globals.logger.LogError(Components.HitsDB, "No hits selected!", true); return; }
var first = (Hit)hitsListView.SelectedItem;
var partialName = "Recheck-" + first.ConfigName;
var wordlist = new Wordlist(partialName, "NULL", Globals.environment.RecognizeWordlistType(first.Data), "", true, true);
@@ -301,32 +301,32 @@ namespace OpenBullet.Views.Main
private void deleteSelected_Click(object sender, RoutedEventArgs e)
{
Globals.LogInfo(Components.HitsDB, $"Deleting {hitsListView.SelectedItems.Count} hits");
Globals.logger.LogInfo(Components.HitsDB, $"Deleting {hitsListView.SelectedItems.Count} hits");
foreach (var hit in Selected.ToList())
{
vm.Remove(hit);
}
Globals.LogInfo(Components.HitsDB, "Succesfully sent the delete query and refreshed the list");
Globals.logger.LogInfo(Components.HitsDB, "Succesfully sent the delete query and refreshed the list");
}
private void removeDuplicatesButton_Click(object sender, RoutedEventArgs e)
{
vm.DeleteDuplicates();
Globals.LogInfo(Components.HitsDB, "Deleted duplicate hits");
Globals.logger.LogInfo(Components.HitsDB, "Deleted duplicate hits");
}
private void deleteFilteredButton_Click(object sender, RoutedEventArgs e)
{
Globals.LogWarning(Components.HitsDB, "Delete filtered selected, prompting warning");
Globals.logger.LogWarning(Components.HitsDB, "Delete filtered selected, prompting warning");
if (MessageBox.Show("This will delete all the hits that are currently being displayed, are you sure you want to continue?", "WARNING", MessageBoxButton.YesNo, MessageBoxImage.Warning) != MessageBoxResult.Yes)
return;
vm.DeleteFiltered();
Globals.LogInfo(Components.HitsDB, "Deleted filtered hits");
Globals.logger.LogInfo(Components.HitsDB, "Deleted filtered hits");
}
}
}
+22 -22
View File
@@ -56,7 +56,7 @@ namespace OpenBullet.Views.Main.Runner
if (Globals.obSettings.General.ChangeRunnerInterface)
{
Globals.LogInfo(Components.About, "Changed the Runner interface");
Globals.logger.LogInfo(Components.About, "Changed the Runner interface");
Grid.SetColumn(rightGrid, 0);
Grid.SetRow(rightGrid, 1);
Grid.SetColumn(bottomLeftGrid, 2);
@@ -70,7 +70,7 @@ namespace OpenBullet.Views.Main.Runner
#region Events
private void LogRunnerData(IRunnerMessaging sender, LogLevel level, string message, bool prompt, int timeout)
{
Globals.Log(Components.Runner, level, message, prompt, timeout);
Globals.logger.Log(Components.Runner, level, message, prompt, timeout);
}
private void LogWorkerStatus(IRunnerMessaging sender)
@@ -102,7 +102,7 @@ namespace OpenBullet.Views.Main.Runner
private void RegisterHit(IRunnerMessaging sender, Hit hit)
{
Globals.LogInfo(Components.Runner, $"Adding {hit.Type} hit " + hit.Data + " to the DB");
Globals.logger.LogInfo(Components.Runner, $"Adding {hit.Type} hit " + hit.Data + " to the DB");
try
{
using (var db = new LiteDatabase(Globals.dataBaseFile))
@@ -115,7 +115,7 @@ namespace OpenBullet.Views.Main.Runner
db.GetCollection<Hit>("hits").Insert(hit);
}
}
catch (Exception ex) { Globals.LogError(Components.Runner, $"Failed to add {hit.Type} hit " + hit.Data + $" to the DB - {ex.Message}"); }
catch (Exception ex) { Globals.logger.LogError(Components.Runner, $"Failed to add {hit.Type} hit " + hit.Data + $" to the DB - {ex.Message}"); }
}
private void PlayHitSound(IRunnerMessaging sender, Hit hit)
@@ -185,7 +185,7 @@ namespace OpenBullet.Views.Main.Runner
vm.CustomInputs = new List<KeyValuePair<string, string>>();
foreach (var input in vm.Config.Settings.CustomInputs)
{
Globals.LogInfo(Components.Runner, $"Asking for input {input.Description}");
Globals.logger.LogInfo(Components.Runner, $"Asking for input {input.Description}");
(new MainDialog(new DialogCustomInput(this, input.VariableName, input.Description), "Custom Input")).ShowDialog();
}
vm.CustomInputsInitialized = true;
@@ -232,7 +232,7 @@ namespace OpenBullet.Views.Main.Runner
var reloadSound = $"Sounds/{Globals.obSettings.Sounds.OnReloadSound}";
if (File.Exists(hitSound)) hitPlayer = new SoundPlayer(hitSound);
if (File.Exists(reloadSound)) reloadPlayer = new SoundPlayer(reloadSound);
Globals.LogInfo(Components.Runner, "Set up sound players");
Globals.logger.LogInfo(Components.Runner, "Set up sound players");
}
#endregion
@@ -274,21 +274,21 @@ namespace OpenBullet.Views.Main.Runner
private void hitsFilterButton_Click(object sender, RoutedEventArgs e)
{
vm.ResultsFilter = BotStatus.SUCCESS;
Globals.LogInfo(Components.Runner, $"Changed valid filter to {vm.ResultsFilter}");
Globals.logger.LogInfo(Components.Runner, $"Changed valid filter to {vm.ResultsFilter}");
RefreshListView();
}
private void customFilterButton_Click(object sender, RoutedEventArgs e)
{
vm.ResultsFilter = BotStatus.CUSTOM;
Globals.LogInfo(Components.Runner, $"Changed valid filter to {vm.ResultsFilter}");
Globals.logger.LogInfo(Components.Runner, $"Changed valid filter to {vm.ResultsFilter}");
RefreshListView();
}
private void toCheckFilterButton_Click(object sender, RoutedEventArgs e)
{
vm.ResultsFilter = BotStatus.NONE;
Globals.LogInfo(Components.Runner, $"Changed valid filter to {vm.ResultsFilter}");
Globals.logger.LogInfo(Components.Runner, $"Changed valid filter to {vm.ResultsFilter}");
RefreshListView();
}
@@ -334,12 +334,12 @@ namespace OpenBullet.Views.Main.Runner
if (record != null)
{
vm.StartingPoint = record.Checkpoint;
Globals.LogInfo(Components.Runner, "Retrieved record from the DB for wordlist '" + vm.Wordlist.Name + "' and config '" + vm.ConfigName + $"' (set {vm.StartingPoint} as starting point)");
Globals.logger.LogInfo(Components.Runner, "Retrieved record from the DB for wordlist '" + vm.Wordlist.Name + "' and config '" + vm.ConfigName + $"' (set {vm.StartingPoint} as starting point)");
}
else
{
vm.StartingPoint = 1;
Globals.LogInfo(Components.Runner, "No record found in the DB for wordlist '" + vm.Wordlist.Name + "' and config '" + vm.ConfigName + "'");
Globals.logger.LogInfo(Components.Runner, "No record found in the DB for wordlist '" + vm.Wordlist.Name + "' and config '" + vm.ConfigName + "'");
}
}
}
@@ -370,9 +370,9 @@ namespace OpenBullet.Views.Main.Runner
{
File.WriteAllText("source.html", ((ValidData)GetCurrentListView().SelectedItem).Source);
System.Diagnostics.Process.Start("source.html");
Globals.LogInfo(Components.Runner, "Saved the html to source.html and opened it with the default viewer");
Globals.logger.LogInfo(Components.Runner, "Saved the html to source.html and opened it with the default viewer");
}
catch (Exception ex) { Globals.LogError(Components.Runner, $"Couldn't show the HTML - {ex.Message}", true); }
catch (Exception ex) { Globals.logger.LogError(Components.Runner, $"Couldn't show the HTML - {ex.Message}", true); }
}
private void showLog_Click(object sender, RoutedEventArgs e)
@@ -380,7 +380,7 @@ namespace OpenBullet.Views.Main.Runner
try
{
(new MainDialog(new DialogShowLog(((ValidData)GetCurrentListView().SelectedItem).Log), "Complete Log")).Show();
Globals.LogInfo(Components.Runner, "Opened the log for the hit "+ ((ValidData)GetCurrentListView().SelectedItem).Data);
Globals.logger.LogInfo(Components.Runner, "Opened the log for the hit "+ ((ValidData)GetCurrentListView().SelectedItem).Data);
}
catch { MessageBox.Show("FAILED"); }
}
@@ -393,10 +393,10 @@ namespace OpenBullet.Views.Main.Runner
foreach (ValidData selected in GetCurrentListView().SelectedItems)
clipboardText += selected.Data + Environment.NewLine;
Globals.LogInfo(Components.Runner, $"Copied {GetCurrentListView().SelectedItems.Count} data");
Globals.logger.LogInfo(Components.Runner, $"Copied {GetCurrentListView().SelectedItems.Count} data");
Clipboard.SetText(clipboardText);
}
catch (Exception ex) { Globals.LogError(Components.Runner, $"Exception while copying data - {ex.Message}"); }
catch (Exception ex) { Globals.logger.LogError(Components.Runner, $"Exception while copying data - {ex.Message}"); }
}
private void copySelectedCapture_Click(object sender, RoutedEventArgs e)
@@ -407,10 +407,10 @@ namespace OpenBullet.Views.Main.Runner
foreach (ValidData selected in GetCurrentListView().SelectedItems)
clipboardText += selected.Data + " | " + selected.CapturedData + Environment.NewLine;
Globals.LogInfo(Components.Runner, $"Copied {GetCurrentListView().SelectedItems.Count} data");
Globals.logger.LogInfo(Components.Runner, $"Copied {GetCurrentListView().SelectedItems.Count} data");
Clipboard.SetText(clipboardText);
}
catch (Exception ex) { Globals.LogError(Components.Runner, $"Exception while copying data - {ex.Message}"); }
catch (Exception ex) { Globals.logger.LogError(Components.Runner, $"Exception while copying data - {ex.Message}"); }
}
private void selectAll_Click(object sender, RoutedEventArgs e)
@@ -423,9 +423,9 @@ namespace OpenBullet.Views.Main.Runner
try
{
Clipboard.SetText(((ValidData)GetCurrentListView().SelectedItem).Proxy);
Globals.LogInfo(Components.Runner, "Copied the proxy " + ((ValidData)GetCurrentListView().SelectedItem).Proxy);
Globals.logger.LogInfo(Components.Runner, "Copied the proxy " + ((ValidData)GetCurrentListView().SelectedItem).Proxy);
}
catch (Exception ex) { Globals.LogError(Components.Runner, $"Couldn't copy the proxy for the selected hit - {ex.Message}"); }
catch (Exception ex) { Globals.logger.LogError(Components.Runner, $"Couldn't copy the proxy for the selected hit - {ex.Message}"); }
}
private void sendToDebugger_Click(object sender, RoutedEventArgs e)
@@ -440,9 +440,9 @@ namespace OpenBullet.Views.Main.Runner
stacker.TestProxy = current.Proxy;
stacker.ProxyType = current.ProxyType;
Globals.LogInfo(Components.Runner, $"Sent to the debugger");
Globals.logger.LogInfo(Components.Runner, $"Sent to the debugger");
}
catch (Exception ex) { Globals.LogError(Components.Runner, $"Could not send data and proxy to the debugger - {ex.Message}"); }
catch (Exception ex) { Globals.logger.LogError(Components.Runner, $"Could not send data and proxy to the debugger - {ex.Message}"); }
}
#endregion
}
+3 -3
View File
@@ -31,7 +31,7 @@ namespace OpenBullet.Views.Main.Tools
{
if (Globals.mainWindow.RunnerManagerPage.vm.Runners.Any(r => r.Runner.Master.IsBusy))
{
Globals.LogWarning(Components.Database, "Please stop all active runners before shrinking the database!", true);
Globals.logger.LogWarning(Components.Database, "Please stop all active runners before shrinking the database!", true);
return;
}
@@ -42,12 +42,12 @@ namespace OpenBullet.Views.Main.Tools
var previousSize = (int)(new FileInfo(Globals.dataBaseFile).Length / 1000);
db.Shrink();
var newSize = (int)(new FileInfo(Globals.dataBaseFile).Length / 1000);
Globals.LogInfo(Components.Database, $"Database successfully shrinked from {previousSize} KB to {newSize} KB", true);
Globals.logger.LogInfo(Components.Database, $"Database successfully shrinked from {previousSize} KB to {newSize} KB", true);
}
}
catch (Exception ex)
{
Globals.LogError(Components.Database, $"Shrink failed! Error: {ex.Message}");
Globals.logger.LogError(Components.Database, $"Shrink failed! Error: {ex.Message}");
}
}
}
@@ -39,7 +39,7 @@ namespace OpenBullet.Views.Main
}
catch (Exception e)
{
Globals.LogError(Components.WordlistManager, e.Message);
Globals.logger.LogError(Components.WordlistManager, e.Message);
}
}
@@ -51,30 +51,30 @@ namespace OpenBullet.Views.Main
private void deleteButton_Click(object sender, RoutedEventArgs e)
{
Globals.LogInfo(Components.WordlistManager, $"Deleting {wordlistListView.SelectedItems.Count} references from the DB");
Globals.logger.LogInfo(Components.WordlistManager, $"Deleting {wordlistListView.SelectedItems.Count} references from the DB");
foreach (var wordlist in wordlistListView.SelectedItems.Cast<Wordlist>().ToList())
{
vm.Remove(wordlist);
}
Globals.LogInfo(Components.WordlistManager, "Successfully deleted the wordlist references from the DB");
Globals.logger.LogInfo(Components.WordlistManager, "Successfully deleted the wordlist references from the DB");
}
private void deleteAllButton_Click(object sender, RoutedEventArgs e)
{
Globals.LogWarning(Components.WordlistManager, "Purge selected, prompting warning");
Globals.logger.LogWarning(Components.WordlistManager, "Purge selected, prompting warning");
if (MessageBox.Show("This will purge the WHOLE Wordlists DB, are you sure you want to continue?", "WARNING", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
{
Globals.LogInfo(Components.WordlistManager, "Purge initiated");
Globals.logger.LogInfo(Components.WordlistManager, "Purge initiated");
vm.RemoveAll();
Globals.LogInfo(Components.WordlistManager, "Purge finished");
Globals.logger.LogInfo(Components.WordlistManager, "Purge finished");
}
else { Globals.LogInfo(Components.WordlistManager, "Purge dismissed"); }
else { Globals.logger.LogInfo(Components.WordlistManager, "Purge dismissed"); }
}
private void deleteNotFoundWordlistsButton_Click(object sender, RoutedEventArgs e)
{
Globals.LogWarning(Components.WordlistManager, "Deleting wordlists with missing files.");
Globals.logger.LogWarning(Components.WordlistManager, "Deleting wordlists with missing files.");
vm.DeleteNotFound();
}
#endregion
+8 -2
View File
@@ -17,16 +17,22 @@ namespace RuriLib.Interfaces
/// <param name="message">The message body</param>
/// <param name="level">The message level of criticality</param>
/// <param name="prompt">Whether to prompt the entry to the user in an immediately visible way</param>
void Log(string message, LogLevel level = LogLevel.Info, bool prompt = false);
/// <param name="timeout">The amount of seconds after which the prompt will close (0 = never close)</param>
void Log(string message, LogLevel level = LogLevel.Info, bool prompt = false, int timeout = 0);
/// <summary>
/// All entries in the logging system.
/// </summary>
IEnumerable<LogEntry> Entries { get; }
/// <summary>
/// Whether logging is enabled.
/// </summary>
bool Enabled { get; }
/// <summary>
/// The maximum amount of entries that can be stored (0 = unlimited).
/// </summary>
int BufferSize { get; set; }
int BufferSize { get; }
}
}