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() { // 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; } }