public MainWindow() { // Clean or create log file File.WriteAllText(Globals.logFile, ""); InitializeComponent(); Title = title; titleLabel.Content = title; // Set global reference to this window Globals.mainWindow = this; // Make sure all folders are there or recreate them var folders = new string[] { "Captchas", "ChromeExtensions", "Configs", "DB", "Screenshots", "Settings", "Sounds", "Wordlists" }; foreach (var folder in folders.Select(f => System.IO.Path.Combine(Directory.GetCurrentDirectory(), f))) { if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } } // Initialize Environment Settings try { Globals.environment = IOManager.ParseEnvironmentSettings(Globals.envFile); } catch { MessageBox.Show("Could not find / parse the Environment Settings file. Please fix the issue and try again."); Environment.Exit(0); } if (Globals.environment.WordlistTypes.Count == 0 || Globals.environment.CustomKeychains.Count == 0) { MessageBox.Show("At least one WordlistType and one CustomKeychain must be defined in the Environment Settings file."); Environment.Exit(0); } // Initialize Settings Globals.rlSettings = new RLSettingsViewModel(); Globals.obSettings = new OBSettingsViewModel(); // Create / Load Settings 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"); IOManager.SaveSettings(Globals.rlSettingsFile, Globals.rlSettings); Globals.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"); } 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"); OBIOManager.SaveSettings(Globals.obSettingsFile, Globals.obSettings); Globals.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"); } Topmost = Globals.obSettings.General.AlwaysOnTop; RunnerManagerPage = new RunnerManager(Globals.obSettings.General.AutoCreateRunner); if (Globals.obSettings.General.AutoCreateRunner) { CurrentRunnerPage = RunnerManagerPage.vm.Runners.FirstOrDefault().Page; } Globals.LogInfo(Components.Main, "Initialized RunnerManager"); ProxyManagerPage = new ProxyManager(); Globals.LogInfo(Components.Main, "Initialized ProxyManager"); WordlistManagerPage = new WordlistManager(); Globals.LogInfo(Components.Main, "Initialized WordlistManager"); ConfigsPage = new Configs(); Globals.LogInfo(Components.Main, "Initialized ConfigManager"); HitsDBPage = new HitsDB(); Globals.LogInfo(Components.Main, "Initialized HitsDB"); OBSettingsPage = new Settings(); Globals.LogInfo(Components.Main, "Initialized Settings"); ToolsPage = new Tools(); Globals.LogInfo(Components.Main, "Initialized Tools"); AboutPage = new About(); menuOptionRunner_MouseDown(this, null); var width = Globals.obSettings.General.StartingWidth; var height = Globals.obSettings.General.StartingHeight; if (width > 800) { Width = width; } if (height > 600) { Height = height; } WindowStartupLocation = WindowStartupLocation.CenterScreen; if (Globals.obSettings.Themes.EnableSnow) { Loaded += MainWindow_Loaded; } }
public MainWindow() { // Clean or create log file File.WriteAllText(Globals.logFile, ""); InitializeComponent(); Title = title; titleLabel.Content = title; // Set global reference to this window Globals.mainWindow = this; // Make sure all folders are there or recreate them var folders = new string[] { "Captchas", "ChromeExtensions", "Configs", "DB", "Screenshots", "Settings", "Sounds", "Wordlists" }; foreach (var folder in folders.Select(f => System.IO.Path.Combine(Directory.GetCurrentDirectory(), f))) { if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } } // Initialize Environment Settings try { Globals.environment = IOManager.ParseEnvironmentSettings(Globals.envFile); } catch { MessageBox.Show("Could not find / parse the Environment Settings file. Please fix the issue and try again."); Environment.Exit(0); } if (Globals.environment.WordlistTypes.Count == 0 || Globals.environment.CustomKeychains.Count == 0) { MessageBox.Show("At least one WordlistType and one CustomKeychain must be defined in the Environment Settings file."); Environment.Exit(0); } // Initialize Settings Globals.rlSettings = new RLSettingsViewModel(); Globals.obSettings = new OBSettingsViewModel(); // Create / Load Settings 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"); IOManager.SaveSettings(Globals.rlSettingsFile, Globals.rlSettings); Globals.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"); } 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"); OBIOManager.SaveSettings(Globals.obSettingsFile, Globals.obSettings); Globals.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"); } // If there is no DB backup or if it's more than 1 day old, back up the DB try { if (Globals.obSettings.General.BackupDB && (!File.Exists(Globals.dataBaseBackupFile) || (File.Exists(Globals.dataBaseBackupFile) && ((DateTime.Now - File.GetCreationTime(Globals.dataBaseBackupFile)).TotalDays > 1)))) { // Check that the DB is not corrupted by accessing a random collection. If this fails, an exception will be thrown. using (var db = new LiteDB.LiteDatabase(Globals.dataBaseFile)) { var coll = db.GetCollection <RuriLib.Models.CProxy>("proxies"); } // 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"); } } catch (Exception ex) { Globals.LogError(Components.Main, $"Could not backup the DB: {ex.Message}"); } Topmost = Globals.obSettings.General.AlwaysOnTop; RunnerManagerPage = new RunnerManager(Globals.obSettings.General.AutoCreateRunner); if (Globals.obSettings.General.AutoCreateRunner) { CurrentRunnerPage = RunnerManagerPage.vm.Runners.FirstOrDefault().Page; } Globals.LogInfo(Components.Main, "Initialized RunnerManager"); ProxyManagerPage = new ProxyManager(); Globals.LogInfo(Components.Main, "Initialized ProxyManager"); WordlistManagerPage = new WordlistManager(); Globals.LogInfo(Components.Main, "Initialized WordlistManager"); ConfigsPage = new Configs(); Globals.LogInfo(Components.Main, "Initialized ConfigManager"); HitsDBPage = new HitsDB(); Globals.LogInfo(Components.Main, "Initialized HitsDB"); OBSettingsPage = new Settings(); Globals.LogInfo(Components.Main, "Initialized Settings"); ToolsPage = new Tools(); Globals.LogInfo(Components.Main, "Initialized Tools"); AboutPage = new About(); menuOptionRunner_MouseDown(this, null); var width = Globals.obSettings.General.StartingWidth; var height = Globals.obSettings.General.StartingHeight; if (width > 800) { Width = width; } if (height > 600) { Height = height; } WindowStartupLocation = WindowStartupLocation.CenterScreen; if (Globals.obSettings.Themes.EnableSnow) { Loaded += MainWindow_Loaded; } }
public MainWindow() { OB.MainWindow = this; // Clean or create log file File.WriteAllText(OB.logFile, ""); InitializeComponent(); var title = $"OpenBullet {OB.Version}"; Title = title; titleLabel.Content = title; // Make sure all folders are there or recreate them var folders = new string[] { "Captchas", "ChromeExtensions", "Configs", "DB", "Hits", "Plugins", "Screenshots", "Settings", "Sounds", "Wordlists" }; foreach (var folder in folders.Select(f => Path.Combine(Directory.GetCurrentDirectory(), f))) { if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } } // Initialize Environment Settings try { OB.Settings.Environment = IOManager.ParseEnvironmentSettings(OB.envFile); } catch { OB.Logger.LogError(Components.Main, "Could not find / parse the Environment Settings file. Please fix the issue and try again.", true); Environment.Exit(0); } if (OB.Settings.Environment.WordlistTypes.Count == 0 || OB.Settings.Environment.CustomKeychains.Count == 0) { OB.Logger.LogError(Components.Main, "At least one WordlistType and one CustomKeychain must be defined in the Environment Settings file.", true); Environment.Exit(0); } // Initialize Settings OB.Settings.RLSettings = new RLSettingsViewModel(); OB.Settings.ProxyManagerSettings = new ProxyManagerSettings(); OB.OBSettings = new OBSettingsViewModel(); // Create / Load Settings if (!File.Exists(OB.rlSettingsFile)) { MessageBox.Show("RuriLib Settings file not found, generating a default one"); OB.Logger.LogWarning(Components.Main, "RuriLib Settings file not found, generating a default one"); IOManager.SaveSettings(OB.rlSettingsFile, OB.Settings.RLSettings); OB.Logger.LogInfo(Components.Main, $"Created the default RuriLib Settings file {OB.rlSettingsFile}"); } else { OB.Settings.RLSettings = IOManager.LoadSettings <RLSettingsViewModel>(OB.rlSettingsFile); OB.Logger.LogInfo(Components.Main, "Loaded the existing RuriLib Settings file"); } if (!File.Exists(OB.proxyManagerSettingsFile)) { OB.Logger.LogWarning(Components.Main, "Proxy manager Settings file not found, generating a default one"); OB.Settings.ProxyManagerSettings.ProxySiteUrls.Add(OB.defaultProxySiteUrl); OB.Settings.ProxyManagerSettings.ActiveProxySiteUrl = OB.defaultProxySiteUrl; OB.Settings.ProxyManagerSettings.ProxyKeys.Add(OB.defaultProxyKey); OB.Settings.ProxyManagerSettings.ActiveProxyKey = OB.defaultProxyKey; IOManager.SaveSettings(OB.proxyManagerSettingsFile, OB.Settings.ProxyManagerSettings); OB.Logger.LogInfo(Components.Main, $"Created the default proxy manager Settings file {OB.proxyManagerSettingsFile}"); } else { OB.Settings.ProxyManagerSettings = IOManager.LoadSettings <ProxyManagerSettings>(OB.proxyManagerSettingsFile); OB.Logger.LogInfo(Components.Main, "Loaded the existing proxy manager Settings file"); } if (!File.Exists(OB.obSettingsFile)) { MessageBox.Show("OpenBullet Settings file not found, generating a default one"); OB.Logger.LogWarning(Components.Main, "OpenBullet Settings file not found, generating a default one"); OBIOManager.SaveSettings(OB.obSettingsFile, OB.OBSettings); OB.Logger.LogInfo(Components.Main, $"Created the default OpenBullet Settings file {OB.obSettingsFile}"); } else { OB.OBSettings = OBIOManager.LoadSettings(OB.obSettingsFile); OB.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 try { if (OB.OBSettings.General.BackupDB && (!File.Exists(OB.dataBaseBackupFile) || (File.Exists(OB.dataBaseBackupFile) && ((DateTime.Now - File.GetCreationTime(OB.dataBaseBackupFile)).TotalDays > 1)))) { // Check that the DB is not corrupted by accessing a random collection. If this fails, an exception will be thrown. using (var db = new LiteDB.LiteDatabase(OB.dataBaseFile)) { var coll = db.GetCollection <RuriLib.Models.CProxy>("proxies"); } // Delete the old file and copy over the new one File.Delete(OB.dataBaseBackupFile); File.Copy(OB.dataBaseFile, OB.dataBaseBackupFile); OB.Logger.LogInfo(Components.Main, "Backed up the DB"); } } catch (Exception ex) { OB.Logger.LogError(Components.Main, $"Could not backup the DB: {ex.Message}"); } Topmost = OB.OBSettings.General.AlwaysOnTop; // Load Plugins var(plugins, blockPlugins) = Loader.LoadPlugins(OB.pluginsFolder); OB.BlockPlugins = blockPlugins.ToList(); // Set mappings OB.BlockMappings = new List <(Type, Type, System.Windows.Media.Color)>() { (typeof(BlockBypassCF), typeof(PageBlockBypassCF), Colors.DarkSalmon), (typeof(BlockImageCaptcha), typeof(PageBlockCaptcha), Colors.DarkOrange), (typeof(BlockReportCaptcha), typeof(PageBlockReportCaptcha), Colors.DarkOrange), (typeof(BlockFunction), typeof(PageBlockFunction), Colors.YellowGreen), (typeof(BlockKeycheck), typeof(PageBlockKeycheck), Colors.DodgerBlue), (typeof(BlockLSCode), typeof(PageBlockLSCode), Colors.White), (typeof(BlockParse), typeof(PageBlockParse), Colors.Gold), (typeof(BlockRecaptcha), typeof(PageBlockRecaptcha), Colors.Turquoise), (typeof(BlockSolveCaptcha), typeof(PageBlockSolveCaptcha), Colors.Turquoise), (typeof(BlockRequest), typeof(PageBlockRequest), Colors.LimeGreen), (typeof(BlockTCP), typeof(PageBlockTCP), Colors.MediumPurple), (typeof(BlockUtility), typeof(PageBlockUtility), Colors.Wheat), (typeof(SBlockBrowserAction), typeof(PageSBlockBrowserAction), Colors.Green), (typeof(SBlockElementAction), typeof(PageSBlockElementAction), Colors.Firebrick), (typeof(SBlockExecuteJS), typeof(PageSBlockExecuteJS), Colors.Indigo), (typeof(SBlockNavigate), typeof(PageSBlockNavigate), Colors.RoyalBlue) }; // Add block plugins to mappings foreach (var plugin in blockPlugins) { try { var color = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(plugin.Color); OB.BlockMappings.Add((plugin.GetType(), typeof(BlockPluginPage), color)); BlockParser.BlockMappings.Add(plugin.Name, plugin.GetType()); OB.Logger.LogInfo(Components.Main, $"Initialized {plugin.Name} block plugin"); } catch { OB.Logger.LogError(Components.Main, $"The color {plugin.Color} in block plugin {plugin.Name} is invalid", true); Environment.Exit(0); } } // ViewModels OB.RunnerManager = new RunnerManagerViewModel(); OB.ProxyManager = new ProxyManagerViewModel(); OB.WordlistManager = new WordlistManagerViewModel(); OB.ConfigManager = new ConfigManagerViewModel(); OB.HitsDB = new HitsDBViewModel(); // Views RunnerManagerPage = new RunnerManager(); // If we create first runner and there was no session to restore if (OB.OBSettings.General.AutoCreateRunner & !OB.RunnerManager.RestoreSession()) { var firstRunner = OB.RunnerManager.Create(); CurrentRunnerPage = OB.RunnerManager.RunnersCollection.FirstOrDefault().View; } OB.Logger.LogInfo(Components.Main, "Initialized RunnerManager"); ProxyManagerPage = new ProxyManager(); OB.Logger.LogInfo(Components.Main, "Initialized ProxyManager"); WordlistManagerPage = new WordlistManager(); OB.Logger.LogInfo(Components.Main, "Initialized WordlistManager"); ConfigsPage = new ConfigsSection(); OB.Logger.LogInfo(Components.Main, "Initialized ConfigManager"); HitsDBPage = new HitsDB(); OB.Logger.LogInfo(Components.Main, "Initialized HitsDB"); OBSettingsPage = new Settings(); OB.Logger.LogInfo(Components.Main, "Initialized Settings"); ToolsPage = new ToolsSection(); OB.Logger.LogInfo(Components.Main, "Initialized Tools"); PluginsPage = new PluginsSection(plugins); OB.Logger.LogInfo(Components.Main, "Initialized Plugins"); AboutPage = new About(); menuOptionRunner_MouseDown(this, null); var width = OB.OBSettings.General.StartingWidth; var height = OB.OBSettings.General.StartingHeight; if (width > 800) { Width = width; } if (height > 600) { Height = height; } WindowStartupLocation = WindowStartupLocation.CenterScreen; if (OB.OBSettings.Themes.EnableSnow) { Loaded += MainWindow_Loaded; } }