diff --git a/DeFRaG_Helper/App.xaml.cs b/DeFRaG_Helper/App.xaml.cs index 10336d5..546350f 100644 --- a/DeFRaG_Helper/App.xaml.cs +++ b/DeFRaG_Helper/App.xaml.cs @@ -15,14 +15,14 @@ protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); // Initialize logging - SimpleLogger.Log("Application starting"); + MessageHelper.Log("Application starting"); LoadConfigurationAndStartAsync().ContinueWith(_ => { // This ensures the continuation runs on the UI thread Dispatcher.Invoke(() => { // Now that configuration and resources are loaded, show the main window - SimpleLogger.Log("Main window created"); + MessageHelper.Log("Main window created"); MainWindow mainWindow = new MainWindow(); mainWindow.Show(); }); @@ -46,32 +46,32 @@ private async void StartDelayedTasks() private async Task LoadConfigurationAndStartAsync() { // Ensure the configuration is loaded before proceeding - await SimpleLogger.LogAsync("Loading configuration"); + await MessageHelper.LogAsync("Loading configuration"); await AppConfig.LoadConfigurationAsync(); - await SimpleLogger.LogAsync($"Configuration loaded: {AppConfig.GameDirectoryPath}"); + await MessageHelper.LogAsync($"Configuration loaded: {AppConfig.GameDirectoryPath}"); ApplyThemeColor(); // Create an instance of MapHistoryManager - SimpleLogger.Log("Creating MapHistoryManager"); + MessageHelper.Log("Creating MapHistoryManager"); var mapHistoryManager = MapHistoryManager.GetInstance("DeFRaG_Helper"); - SimpleLogger.Log("MapHistoryManager created"); + MessageHelper.Log("MapHistoryManager created"); await AppConfig.EnsureDatabaseExistsAsync(); - SimpleLogger.Log("Database exists"); + MessageHelper.Log("Database exists"); // The main window creation and showing is moved to the continuation of this method in OnStartup } private void ApplyThemeColor() { if (!string.IsNullOrEmpty(AppConfig.SelectedColor)) { - SimpleLogger.Log($"Applying theme color: {AppConfig.SelectedColor}"); + MessageHelper.Log($"Applying theme color: {AppConfig.SelectedColor}"); // Assuming AppConfig.SelectedColor is a string like "Red", "Yellow", etc. var color = (Color)ColorConverter.ConvertFromString(AppConfig.SelectedColor); var brush = new SolidColorBrush(color); Current.Resources["ThemeColor"] = brush; } - else { SimpleLogger.Log("No theme color selected"); + else { MessageHelper.Log("No theme color selected"); } } } diff --git a/DeFRaG_Helper/Config/AppConfig.cs b/DeFRaG_Helper/Config/AppConfig.cs index c0a0f37..8f0434f 100644 --- a/DeFRaG_Helper/Config/AppConfig.cs +++ b/DeFRaG_Helper/Config/AppConfig.cs @@ -28,7 +28,7 @@ static AppConfig() if (!Directory.Exists(appFolder)) { Directory.CreateDirectory(appFolder); - SimpleLogger.Log($"Created directory: {appFolder}"); + MessageHelper.Log($"Created directory: {appFolder}"); } // Default values for new properties DatabasePath = Path.Combine(appFolder, "MapData.db"); @@ -42,7 +42,7 @@ public static async Task LoadConfigurationAsync() { if (File.Exists(configFilePath)) { - await SimpleLogger.LogAsync($"Found config {configFilePath}"); + await MessageHelper.LogAsync($"Found config {configFilePath}"); string json = await File.ReadAllTextAsync(configFilePath); var config = JsonSerializer.Deserialize(json); @@ -54,25 +54,25 @@ public static async Task LoadConfigurationAsync() DatabaseUrl = config?.DatabaseUrl ?? DatabaseUrl; MenuState = config?.MenuState ?? MenuState; // Use default if not set ConnectionString = config?.ConnectionString ?? ConnectionString; // Use default if not set - await SimpleLogger.LogAsync($"GameDirectoryPath: {GameDirectoryPath}"); - await SimpleLogger.LogAsync($"SelectedColor: {SelectedColor}"); - await SimpleLogger.LogAsync($"ButtonState: {ButtonState}"); - await SimpleLogger.LogAsync($"PhysicsSetting: {PhysicsSetting}"); - await SimpleLogger.LogAsync($"DatabasePath: {DatabasePath}"); - await SimpleLogger.LogAsync($"DatabaseUrl: {DatabaseUrl}"); + await MessageHelper.LogAsync($"GameDirectoryPath: {GameDirectoryPath}"); + await MessageHelper.LogAsync($"SelectedColor: {SelectedColor}"); + await MessageHelper.LogAsync($"ButtonState: {ButtonState}"); + await MessageHelper.LogAsync($"PhysicsSetting: {PhysicsSetting}"); + await MessageHelper.LogAsync($"DatabasePath: {DatabasePath}"); + await MessageHelper.LogAsync($"DatabaseUrl: {DatabaseUrl}"); } else { //create the file if it doesn't exist - await SimpleLogger.LogAsync($"{configFilePath} not found"); + await MessageHelper.LogAsync($"{configFilePath} not found"); //await SaveConfigurationAsync(); } } catch (Exception ex) { - SimpleLogger.Log(ex.Message); + MessageHelper.Log(ex.Message); throw; } @@ -100,23 +100,23 @@ public static async Task SaveConfigurationAsync() ConnectionString = ConnectionString }; - SimpleLogger.Log($"GameDirectoryPath: {GameDirectoryPath}"); - SimpleLogger.Log($"SelectedColor: {SelectedColor}"); - SimpleLogger.Log($"ButtonState: {ButtonState}"); - SimpleLogger.Log($"PhysicsSetting: {PhysicsSetting}"); - SimpleLogger.Log($"DatabasePath: {DatabasePath}"); - SimpleLogger.Log($"DatabaseUrl: {DatabaseUrl}"); + MessageHelper.Log($"GameDirectoryPath: {GameDirectoryPath}"); + MessageHelper.Log($"SelectedColor: {SelectedColor}"); + MessageHelper.Log($"ButtonState: {ButtonState}"); + MessageHelper.Log($"PhysicsSetting: {PhysicsSetting}"); + MessageHelper.Log($"DatabasePath: {DatabasePath}"); + MessageHelper.Log($"DatabaseUrl: {DatabaseUrl}"); var options = new JsonSerializerOptions { WriteIndented = true }; string json = JsonSerializer.Serialize(config, options); try { await File.WriteAllTextAsync(configFilePath, json); - SimpleLogger.Log("Configuration saved"); + MessageHelper.Log("Configuration saved"); } catch (Exception ex) { - SimpleLogger.Log(ex.Message); + MessageHelper.Log(ex.Message); throw; } } @@ -124,15 +124,15 @@ public static async Task EnsureDatabaseExistsAsync() { if (!File.Exists(DatabasePath)) { - await SimpleLogger.LogAsync("Database not found, downloading..."); + await MessageHelper.LogAsync("Database not found, downloading..."); // Use Downloader to download the database // Assuming Downloader has a static method DownloadFileAsync for this purpose await Downloader.DownloadFileAsync(DatabaseUrl, DatabasePath, null); - await SimpleLogger.LogAsync("Database downloaded"); + await MessageHelper.LogAsync("Database downloaded"); } else { - await SimpleLogger.LogAsync($"Database found at {DatabasePath}"); + await MessageHelper.LogAsync($"Database found at {DatabasePath}"); } } diff --git a/DeFRaG_Helper/Config/CheckGameInstall.cs b/DeFRaG_Helper/Config/CheckGameInstall.cs index 029e31f..0165cbc 100644 --- a/DeFRaG_Helper/Config/CheckGameInstall.cs +++ b/DeFRaG_Helper/Config/CheckGameInstall.cs @@ -17,7 +17,7 @@ class CheckGameInstall public async static void StartChecks() { // Check if the game directory path is set in the AppConfig class - SimpleLogger.Log("Checking game install"); + MessageHelper.Log("Checking game install"); SetGameDirectoryPath(); // Await the fully initialized instance of MapViewModel @@ -33,16 +33,16 @@ public async static void StartChecks() public static bool CheckInstall(string path) { string[] dirs = System.IO.Directory.GetDirectories(path); - SimpleLogger.Log($"Checking for defrag folder in {path}"); + MessageHelper.Log($"Checking for defrag folder in {path}"); foreach (string dir in dirs) { if (dir.Contains("defrag")) { - SimpleLogger.Log("Defrag folder found"); + MessageHelper.Log("Defrag folder found"); return true; } } - SimpleLogger.Log("Defrag folder not found"); + MessageHelper.Log("Defrag folder not found"); return false; } //if the folder is found, we check if there is a file called "oDFe.x64.exe" or "oDFe.exe" in the "defrag" folder @@ -50,16 +50,16 @@ public static bool CheckExe(string path) { //string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string[] files = System.IO.Directory.GetFiles(path); - SimpleLogger.Log($"Checking for oDFe.x64.exe or oDFe.exe in {path}"); + MessageHelper.Log($"Checking for oDFe.x64.exe or oDFe.exe in {path}"); foreach (string file in files) { if (file.Contains("oDFe.x64.exe") || file.Contains("oDFe.exe")) { - SimpleLogger.Log("oDFe.x64.exe or oDFe.exe found"); + MessageHelper.Log("oDFe.x64.exe or oDFe.exe found"); return true; } } - SimpleLogger.Log("oDFe.x64.exe or oDFe.exe not found"); + MessageHelper.Log("oDFe.x64.exe or oDFe.exe not found"); return false; } @@ -71,10 +71,10 @@ public async static void SetGameDirectoryPath() string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); if (string.IsNullOrEmpty(AppConfig.GameDirectoryPath)) { - SimpleLogger.Log("Game directory path not set"); + MessageHelper.Log("Game directory path not set"); if (CheckInstall(path) && CheckExe(path)) { - SimpleLogger.Log($"Game found in {path}"); + MessageHelper.Log($"Game found in {path}"); AppConfig.GameDirectoryPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); //save the game directory path in the app.config file await AppConfig.SaveConfigurationAsync(); @@ -84,7 +84,7 @@ public async static void SetGameDirectoryPath() } else { - SimpleLogger.Log($"Game not found in {path}"); + MessageHelper.Log($"Game not found in {path}"); //prompt user to set game directory path in a folder browser dialog //App.Current.Dispatcher.Invoke(() => MainWindow.Instance.ShowMessage("Game not found")); //open file browser dialog from wpf (as forms not working) to set game directory path @@ -92,24 +92,24 @@ public async static void SetGameDirectoryPath() if (tempDir != null) { AppConfig.GameDirectoryPath = tempDir; - SimpleLogger.Log($"Game directory path set to {tempDir}"); + MessageHelper.Log($"Game directory path set to {tempDir}"); //save the game directory path in the app.config file await AppConfig.SaveConfigurationAsync(); - SimpleLogger.Log("Game directory path saved"); + MessageHelper.Log("Game directory path saved"); //we need check again, if the folder and the file are found now, if yes we set the game directory path in the AppConfig class to the actual application path, if no, we install the game in method InstallGame() path = tempDir; - SimpleLogger.Log($"Checking game install in {path}"); + MessageHelper.Log($"Checking game install in {path}"); if (CheckInstall(path) && CheckExe(path)) { - SimpleLogger.Log($"Game found in {path}"); + MessageHelper.Log($"Game found in {path}"); AppConfig.GameDirectoryPath = path; App.Current.Dispatcher.Invoke(() => MainWindow.Instance.ShowMessage("Game found")); await AppConfig.SaveConfigurationAsync(); } else { - SimpleLogger.Log($"Game not found in {path}"); + MessageHelper.Log($"Game not found in {path}"); InstallGame(); } @@ -127,7 +127,7 @@ public async static void SetGameDirectoryPath() } else { - SimpleLogger.Log($"Game directory path set to {AppConfig.GameDirectoryPath}"); + MessageHelper.Log($"Game directory path set to {AppConfig.GameDirectoryPath}"); } } @@ -135,10 +135,10 @@ public async static void SetGameDirectoryPath() private async static Task InstallGame() { App.Current.Dispatcher.Invoke(() => MainWindow.Instance.ShowMessage("Game data will be downloaded")); - SimpleLogger.Log("Game data will be downloaded"); + MessageHelper.Log("Game data will be downloaded"); // Create a folder called "defrag" in the GameDirectoryPath string path = AppConfig.GameDirectoryPath; - SimpleLogger.Log($"Game directory path set to {path}"); + MessageHelper.Log($"Game directory path set to {path}"); System.IO.Directory.CreateDirectory(path + "\\defrag"); // Prepare the progress handler to update the UI @@ -149,26 +149,26 @@ private async static Task InstallGame() IProgress progress = progressHandler; // Download the game from the server - SimpleLogger.Log("Downloading game data"); + MessageHelper.Log("Downloading game data"); await Downloader.DownloadFileAsync("https://github.com/JBustos22/oDFe/releases/download/latest/oDFe-windows-x86_64.zip", path + "\\oDFe-windows-x86_64.zip", progress); // Extract the engine from the zip file - SimpleLogger.Log($"Extracting game data in {path}"); + MessageHelper.Log($"Extracting game data in {path}"); await Downloader.UnpackFile(path + "\\oDFe-windows-x86_64.zip", path, progress); //check if the defrag folder already contains autoexec.cfg. if not we need install the gamedata if (!System.IO.File.Exists(path + "\\defrag\\autoexec.cfg")) { - SimpleLogger.Log("Game data will be installed"); + MessageHelper.Log("Game data will be installed"); //Download the game data from await Downloader.DownloadFileAsync("https://dl.defrag.racing/downloads/game-bundles/DeFRaG%20Bundle%20all-in-one%20Windows%2064bit.7z", path + "\\DeFRaG Bundle all-in-one Windows 64bit.7z", progress); //Extract the game data from the 7z file - SimpleLogger.Log("Extracting game data"); + MessageHelper.Log("Extracting game data"); await Downloader.UnpackFile(path + "\\DeFRaG Bundle all-in-one Windows 64bit.7z", path, progress); //move the contents of the extracted folder (DeFRaG Bundle all-in-one Windows 64bit) to the root folder - SimpleLogger.Log($"Moving game data in {path}"); + MessageHelper.Log($"Moving game data in {path}"); await Downloader.MoveFolderContents(path + "\\DeFRaG Bundle all-in-one Windows 64bit", path, progress); //create "archive" folder in the root folder - SimpleLogger.Log("Creating archive folder"); + MessageHelper.Log("Creating archive folder"); System.IO.Directory.CreateDirectory(path + "\\archive"); } @@ -191,7 +191,7 @@ public static string BrowseFolder() // Set the filter to only show directories openFileDialog.Filter = "Folder|*.none"; openFileDialog.FileName = "Select Folder"; - SimpleLogger.Log("Opening folder browser dialog"); + MessageHelper.Log("Opening folder browser dialog"); if (openFileDialog.ShowDialog() == true) { // Return the directory path diff --git a/DeFRaG_Helper/Helpers/CreateAndUpdateDB.cs b/DeFRaG_Helper/Helpers/CreateAndUpdateDB.cs index d3553aa..e4f8b4e 100644 --- a/DeFRaG_Helper/Helpers/CreateAndUpdateDB.cs +++ b/DeFRaG_Helper/Helpers/CreateAndUpdateDB.cs @@ -66,7 +66,7 @@ public static async Task UpdateDB() catch (Exception ex) { // Handle any errors that might occur during the update process - SimpleLogger.Log($"An error occurred during the database update: {ex.Message}"); + MessageHelper.Log($"An error occurred during the database update: {ex.Message}"); } } @@ -208,7 +208,7 @@ private static async Task ParsePagesAsync(int pageCount) else { consecutiveExistingMaps = 0; // Reset the counter if a new map is found - SimpleLogger.Log($"Parsing map: {fullDetailsPageUrl}"); + MessageHelper.Log($"Parsing map: {fullDetailsPageUrl}"); } // Assuming the third cell contains the filename in an tag's href attribute @@ -227,12 +227,12 @@ private static async Task ParsePagesAsync(int pageCount) } } } - SimpleLogger.Log($"Page {i + 1} of {pageCount} processed."); + MessageHelper.Log($"Page {i + 1} of {pageCount} processed."); } } catch (Exception ex) { - SimpleLogger.Log($"An error occurred during the database update: {ex.Message}"); + MessageHelper.Log($"An error occurred during the database update: {ex.Message}"); throw; } } @@ -675,7 +675,7 @@ public static List ExtractImageUrls(string html) var slideMatch = slideRegex.Match(dataAttributes); if (slideMatch.Success) { - //SimpleLogger.Log($"Found slide {i}: {slideMatch.Groups[1].Value}"); + //MessageHelper.Log($"Found slide {i}: {slideMatch.Groups[1].Value}"); imageUrls.Add(slideMatch.Groups[1].Value); } } diff --git a/DeFRaG_Helper/Helpers/DbActions.cs b/DeFRaG_Helper/Helpers/DbActions.cs index bb64ff2..ddb874b 100644 --- a/DeFRaG_Helper/Helpers/DbActions.cs +++ b/DeFRaG_Helper/Helpers/DbActions.cs @@ -276,15 +276,15 @@ public async Task UpdateMap(Map map) }); await Task.CompletedTask; - SimpleLogger.Log($"Updated Base data for {map.Mapname}"); + MessageHelper.Log($"Updated Base data for {map.Mapname}"); if (map.Weapons != null) { - //SimpleLogger.Log($"Updating {map.Weapons.Count} Weapons for {map.Mapname}"); + //MessageHelper.Log($"Updating {map.Weapons.Count} Weapons for {map.Mapname}"); foreach (var weaponName in map.Weapons) { - //SimpleLogger.Log($"Updating {weaponName} for {map.Mapname}"); + //MessageHelper.Log($"Updating {weaponName} for {map.Mapname}"); DbQueue.Instance.Enqueue(async connection => { // First, get the WeaponID from the 'Weapons' table @@ -325,11 +325,11 @@ public async Task UpdateMap(Map map) } if (map.Items != null) { - //SimpleLogger.Log($"Updating {map.Items.Count} Items for {map.Mapname}"); + //MessageHelper.Log($"Updating {map.Items.Count} Items for {map.Mapname}"); foreach (var itemName in map.Items) { - //SimpleLogger.Log($"Updating {itemName} for {map.Mapname}"); + //MessageHelper.Log($"Updating {itemName} for {map.Mapname}"); DbQueue.Instance.Enqueue(async connection => { // First, get the ItemID from the 'Item' table @@ -371,11 +371,11 @@ public async Task UpdateMap(Map map) if (map.Function != null) { - //SimpleLogger.Log($"Updating {map.Function.Count} Function for {map.Mapname}"); + //MessageHelper.Log($"Updating {map.Function.Count} Function for {map.Mapname}"); foreach (var functionName in map.Function) { - //SimpleLogger.Log($"Updating {functionName} for {map.Mapname}"); + //MessageHelper.Log($"Updating {functionName} for {map.Mapname}"); DbQueue.Instance.Enqueue(async connection => { // First, get the FunctionID from the 'Function' table diff --git a/DeFRaG_Helper/Helpers/DbQueue.cs b/DeFRaG_Helper/Helpers/DbQueue.cs index 2565fca..ed78cbf 100644 --- a/DeFRaG_Helper/Helpers/DbQueue.cs +++ b/DeFRaG_Helper/Helpers/DbQueue.cs @@ -53,12 +53,12 @@ private async Task ProcessQueue(string callerMemberName) await connection.OpenAsync(); await operation(connection); } - //SimpleLogger.Log($"DbQueue operation completed by {callerMemberName}"); + //MessageHelper.Log($"DbQueue operation completed by {callerMemberName}"); } catch (Exception ex) { Console.WriteLine($"DbQueue operation failed: {ex.Message} - Called by {callerMemberName}"); - SimpleLogger.Log($"DbQueue operation failed: {ex.Message}, {ex.StackTrace}- Called by {callerMemberName}"); + MessageHelper.Log($"DbQueue operation failed: {ex.Message}, {ex.StackTrace}- Called by {callerMemberName}"); _tcs.SetException(ex); // Consider setting the exception to signal failure return; // Exit on failure } @@ -69,7 +69,7 @@ private async Task ProcessQueue(string callerMemberName) if (!_operations.IsEmpty) { // If new operations were enqueued during processing, continue processing without setting _isProcessing to false. - SimpleLogger.Log("DbQueue operations enqueued during processing"); + MessageHelper.Log("DbQueue operations enqueued during processing"); return; } _isProcessing = false; diff --git a/DeFRaG_Helper/Helpers/MapHistoryManager.cs b/DeFRaG_Helper/Helpers/MapHistoryManager.cs index daaa1ce..e7d32b3 100644 --- a/DeFRaG_Helper/Helpers/MapHistoryManager.cs +++ b/DeFRaG_Helper/Helpers/MapHistoryManager.cs @@ -17,19 +17,19 @@ public class MapHistoryManager private MapHistoryManager(string appName) { string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); - SimpleLogger.Log($"AppDataPath from MapHistoryManager: {appDataPath}"); + MessageHelper.Log($"AppDataPath from MapHistoryManager: {appDataPath}"); string appFolder = Path.Combine(appDataPath, appName); - SimpleLogger.Log($"AppFolder from MapHistoryManager: {appFolder}"); + MessageHelper.Log($"AppFolder from MapHistoryManager: {appFolder}"); filePath = Path.Combine(appFolder, "lastPlayedMaps.json"); if (!Directory.Exists(appFolder)) { Directory.CreateDirectory(appFolder); - SimpleLogger.Log($"Created directory: {appFolder}"); + MessageHelper.Log($"Created directory: {appFolder}"); } // Load the last played maps into memory at initialization - SimpleLogger.Log($"Loading last played maps from file: {filePath}"); + MessageHelper.Log($"Loading last played maps from file: {filePath}"); LoadLastPlayedMapsFromFile(); } @@ -48,22 +48,22 @@ private async void LoadLastPlayedMapsFromFile() { if (File.Exists(filePath)) { - SimpleLogger.Log($"Found file: {filePath}"); + MessageHelper.Log($"Found file: {filePath}"); string json = await File.ReadAllTextAsync(filePath); lastPlayedMapsInMemory = JsonSerializer.Deserialize>(json) ?? new List(); - SimpleLogger.Log($"Loaded {lastPlayedMapsInMemory.Count} last played maps"); + MessageHelper.Log($"Loaded {lastPlayedMapsInMemory.Count} last played maps"); } else { //create the file if it doesn't exist await SaveLastPlayedMapsAsync(); - SimpleLogger.Log($"File not found: {filePath}"); + MessageHelper.Log($"File not found: {filePath}"); } } catch (Exception ex) { - SimpleLogger.Log($"Failed to load last played maps from file: {filePath}"); - SimpleLogger.Log(ex.Message); + MessageHelper.Log($"Failed to load last played maps from file: {filePath}"); + MessageHelper.Log(ex.Message); throw; } @@ -74,20 +74,20 @@ public async Task SaveLastPlayedMapsAsync() var options = new JsonSerializerOptions { WriteIndented = true }; string json = JsonSerializer.Serialize(lastPlayedMapsInMemory, options); await File.WriteAllTextAsync(filePath, json); - SimpleLogger.Log($"Saved {lastPlayedMapsInMemory.Count} last played maps to file: {filePath}"); + MessageHelper.Log($"Saved {lastPlayedMapsInMemory.Count} last played maps to file: {filePath}"); } public List LoadLastPlayedMapsAsync() { // Return a copy of the in-memory list to prevent external modifications return new List(lastPlayedMapsInMemory); - SimpleLogger.Log($"Loaded async {lastPlayedMapsInMemory.Count} last played maps"); + MessageHelper.Log($"Loaded async {lastPlayedMapsInMemory.Count} last played maps"); } public List GetLastPlayedMaps() { // Return a copy of the in-memory list to prevent external modifications return new List(lastPlayedMapsInMemory); - SimpleLogger.Log($"Loaded {lastPlayedMapsInMemory.Count} last played maps"); + MessageHelper.Log($"Loaded {lastPlayedMapsInMemory.Count} last played maps"); } public async Task UpdateLastPlayedMapsAsync(int mapId) { @@ -95,12 +95,12 @@ public async Task UpdateLastPlayedMapsAsync(int mapId) if (lastPlayedMapsInMemory.Count > 10) { lastPlayedMapsInMemory.RemoveAt(0); - await SimpleLogger.LogAsync("Removed oldest map from last played list"); + await MessageHelper.LogAsync("Removed oldest map from last played list"); } MapHistoryUpdated?.Invoke(); // Optionally, save to file immediately or wait to save at session end - await SimpleLogger.LogAsync($"Added map {mapId} to last played list"); + await MessageHelper.LogAsync($"Added map {mapId} to last played list"); await SaveLastPlayedMapsAsync(); } } diff --git a/DeFRaG_Helper/MessageHelper.cs b/DeFRaG_Helper/Helpers/MessageHelper.cs similarity index 92% rename from DeFRaG_Helper/MessageHelper.cs rename to DeFRaG_Helper/Helpers/MessageHelper.cs index 29a9e4c..5db76a9 100644 --- a/DeFRaG_Helper/MessageHelper.cs +++ b/DeFRaG_Helper/Helpers/MessageHelper.cs @@ -20,12 +20,12 @@ public static void ShowMessageAsync(string message) SimpleLogger.Log(message); } - public static void LogMessage(string message) + public static void Log(string message) { SimpleLogger.Log(message); } - public static async Task LogMessageAsync(string message) + public static async Task LogAsync(string message) { await SimpleLogger.LogAsync(message); } diff --git a/DeFRaG_Helper/MainWindow.xaml.cs b/DeFRaG_Helper/MainWindow.xaml.cs index 859b8ba..755cd52 100644 --- a/DeFRaG_Helper/MainWindow.xaml.cs +++ b/DeFRaG_Helper/MainWindow.xaml.cs @@ -11,6 +11,8 @@ using WPFFolderBrowser; +/// +/// MainWindow.xaml.cs for general UI logic namespace DeFRaG_Helper { @@ -45,18 +47,19 @@ public static MainWindow Instance { if (_instance == null) _instance = Application.Current.MainWindow as MainWindow; + MessageHelper.Log("MainWindow Instance"); + return _instance; - SimpleLogger.Log("MainWindow Instance"); } } public MainWindow() { InitializeComponent(); - SimpleLogger.Log("MainWindow Constructor"); + MessageHelper.Log("MainWindow Constructor"); MainFrame.Navigated += MainFrame_Navigated; this.SourceInitialized += MainWindow_SourceInitialized; - SimpleLogger.Log("MainWindow SourceInitialized"); + MessageHelper.Log("MainWindow SourceInitialized"); Loaded += MainWindow_Loaded; Closed += MainWindow_Closed; NavigationListView.SelectionChanged += NavigationListView_SelectionChanged; @@ -67,16 +70,22 @@ public MainWindow() hideProgressBarTimer.Elapsed += HideProgressBarTimer_Elapsed; hideProgressBarTimer.AutoReset = false; // Ensure the timer runs only once per start } + + //Method to apply filters based on the page navigated to in the MainFrame private void MainFrame_Navigated(object sender, NavigationEventArgs e) { ApplyFilterBasedOnPageAsync(e.Content); } + + //Method to request game directory private async Task RequestGameDirectoryAsync() { // Assuming you have a method to show a dialog and return the selected path string selectedPath = await ShowDirectorySelectionDialogAsync(); return selectedPath; } + + //Method to show a folder selection dialog public static async Task ShowDirectorySelectionDialogAsync() { string folderPath = string.Empty; @@ -94,6 +103,9 @@ await Application.Current.Dispatcher.InvokeAsync(() => }); return folderPath; } + + + //Method to apply filters based on the page navigated to in the MainFrame private async void ApplyFilterBasedOnPageAsync(object navigatedContent) { try @@ -140,7 +152,6 @@ private async void ApplyFilterBasedOnPageAsync(object navigatedContent) - private async void MainWindow_Loaded(object sender, RoutedEventArgs e) { MessagingService.Subscribe(ShowMessage); @@ -154,6 +165,7 @@ private async void MainWindow_Loaded(object sender, RoutedEventArgs e) } + //Method to check and install preview pictures private async Task CheckAndInstallPreviewPictures() { //get appdata path @@ -162,7 +174,7 @@ private async Task CheckAndInstallPreviewPictures() string previewPicturesPath = System.IO.Path.Combine(appDataFolder, "PreviewImages"); if (!System.IO.Directory.Exists(previewPicturesPath)) { - SimpleLogger.Log("Images not found, downloading"); + MessageHelper.Log("Images not found, downloading"); //download images from https://dl.netquick.ch/PreviewImages.zip using Downloader class string url = "https://dl.netquick.ch/PreviewImages.zip"; string zipPath = System.IO.Path.Combine(appDataFolder, "PreviewImages.zip"); @@ -175,7 +187,7 @@ private async Task CheckAndInstallPreviewPictures() await Downloader.DownloadFileAsync(url, zipPath, progress); ShowMessage("Images downloaded, unpacking"); await Downloader.UnpackFile(zipPath, appDataFolder, progress); - SimpleLogger.Log("Images downloaded and extracted"); + MessageHelper.Log("Images downloaded and extracted"); } @@ -190,6 +202,8 @@ private void MainWindow_Closed(object sender, EventArgs e) { MessagingService.Unsubscribe(ShowMessage); } + + //Method to auto close the progress bar after 2 seconds private void HideProgressBarTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { Dispatcher.Invoke(() => @@ -197,6 +211,8 @@ private void HideProgressBarTimer_Elapsed(object sender, System.Timers.ElapsedEv progressBar.Visibility = Visibility.Hidden; }); } + + //method to Load Navigation Bar public void LoadNavigationBar() { NavigationListView.ItemsSource = new List @@ -225,14 +241,7 @@ public void LoadNavigationBar() } - public void ShowProgressBar() - { - progressBar.Visibility = Visibility.Visible; - } - public void HideProgressBar() - { - progressBar.Visibility = Visibility.Hidden; - } + //Method to update progress bar public void UpdateProgressBar(double value) { Debug.WriteLine("Updating progress bar: " + value); @@ -251,6 +260,7 @@ public void UpdateProgressBar(double value) } + //Method to get physics setting public int GetPhysicsSetting () { // get state of chkPhysics checkbox and return the corresponding value for physics setting. 2 for CPM, 1 for VQ3 @@ -258,6 +268,8 @@ public int GetPhysicsSetting () } + + //Method to set physics setting in checkbox toggle private void PhysicsMode_Changed(object sender, RoutedEventArgs e) { // Implementation logic here @@ -270,6 +282,8 @@ private void PhysicsMode_Changed(object sender, RoutedEventArgs e) lblPhysics.Content = AppConfig.PhysicsSetting; } } + + //TODO: check if this method is directly called public void ShowMessage(string message) { Dispatcher.Invoke(() => @@ -303,16 +317,18 @@ public void ShowMessage(string message) }; timer.Start(); }); - SimpleLogger.Log(message); + MessageHelper.Log(message); } + + // Define the pages to navigate to private Start startPage = new Start(); private Maps mapsPage = new Maps(); private Settings settingsPage = new Settings(); private Demos demosPage = new Demos(); private Server serverPage = new Server(); - // Define other pages similarly + //Method to handle navigation list view selection changed private void NavigationListView_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (NavigationListView.SelectedItem is NavigationItem selectedItem) @@ -357,7 +373,7 @@ private void NavigationListView_SelectionChanged(object sender, SelectionChanged } - + //Method to handle source initialized private void MainWindow_SourceInitialized(object sender, EventArgs e) { int isEnabled = 0; @@ -372,6 +388,10 @@ private void MainWindow_SourceInitialized(object sender, EventArgs e) DwmExtendFrameIntoClientArea(hWnd, ref margins); } } + + + //Method to implement drag and drop functionality + private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { // Allows the window to be dragged around by the custom title bar @@ -380,6 +400,8 @@ private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) this.DragMove(); } } + + //Method to implement window resizing functionality on doubleclick private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (e.ClickCount == 2) // Check if it's a double-click @@ -405,7 +427,7 @@ private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) } - + //Button click events for minimize, maximize and close buttons private void Minimize_Click(object sender, RoutedEventArgs e) { this.WindowState = WindowState.Minimized; @@ -421,6 +443,7 @@ private void Close_Click(object sender, RoutedEventArgs e) this.Close(); } + //Method to handle window resizing private void SearchBox_GotFocus(object sender, RoutedEventArgs e) { Dispatcher.BeginInvoke(new Action(() => @@ -430,6 +453,7 @@ private void SearchBox_GotFocus(object sender, RoutedEventArgs e) Debug.WriteLine("Got focus"); } + //Methods to handle window resizing private void OnRightDragDelta(object sender, DragDeltaEventArgs e) { double newWidth = this.Width + e.HorizontalChange; @@ -473,6 +497,8 @@ private void OnBottomRightDragDelta(object sender, DragDeltaEventArgs e) } private bool isSidebarCollapsed = false; // Tracks the sidebar state + + //Method to toggle sidebar private void ToggleSidebar(object sender, RoutedEventArgs e) { if (isSidebarCollapsed) @@ -494,21 +520,5 @@ private void ToggleSidebar(object sender, RoutedEventArgs e) // Save the new state asynchronously AppConfig.SaveConfigurationAsync().ConfigureAwait(false); } - - - private async void Srv_Click(object sender, RoutedEventArgs e) - { - Quake3ServerQuery query = new Quake3ServerQuery("83.243.73.220", 27961); - var (Success, Response) = await query.QueryServerAsync(); - if (Success) - { - MessageBox.Show($"Query Successful: {Response}"); - } - else - { - MessageBox.Show($"Query Failed: {Response}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); - } - } - } } diff --git a/DeFRaG_Helper/ViewModels/MapViewModel.cs b/DeFRaG_Helper/ViewModels/MapViewModel.cs index 92617b2..38d9228 100644 --- a/DeFRaG_Helper/ViewModels/MapViewModel.cs +++ b/DeFRaG_Helper/ViewModels/MapViewModel.cs @@ -351,7 +351,7 @@ public async Task UpdateOrAddMap(Map map) } catch (Exception ex) { - SimpleLogger.Log($"Error updating or adding map: {ex.Message}"); + MessageHelper.Log($"Error updating or adding map: {ex.Message}"); } } diff --git a/DeFRaG_Helper/Views/Demos.xaml.cs b/DeFRaG_Helper/Views/Demos.xaml.cs index 23130b9..bc58a1a 100644 --- a/DeFRaG_Helper/Views/Demos.xaml.cs +++ b/DeFRaG_Helper/Views/Demos.xaml.cs @@ -104,11 +104,11 @@ private async void TxtMapSearch_KeyDown(object sender, KeyEventArgs e) { // Clear the ListView's ItemsSource lvDemos.ItemsSource = null; - SimpleLogger.Log("Clear list"); + MessageHelper.Log("Clear list"); } else { - SimpleLogger.Log($"Searching for demos with map name: {txtMapSearch.Text}"); + MessageHelper.Log($"Searching for demos with map name: {txtMapSearch.Text}"); LoadDemoDataAsync(); } } @@ -139,14 +139,14 @@ private async void LvDemos_MouseDoubleClick(object sender, MouseButtonEventArgs var mapName = item.Mapname; //now we have to check if the map is installed. We check "IsInstalled" property of the map var viewModel = MapViewModel.GetInstanceAsync().Result; - SimpleLogger.Log($"Checking for Mapname: {mapName}"); + MessageHelper.Log($"Checking for Mapname: {mapName}"); var map = viewModel.Maps.FirstOrDefault(m => m.Mapname == (mapName + ".bsp")); if (map != null) { if (map.IsInstalled == 0) { await MapInstaller.InstallMap(map); - SimpleLogger.Log($"Map {map.Mapname} installed."); + MessageHelper.Log($"Map {map.Mapname} installed."); } //Prepare the progress handler to update the UI var progressHandler = new Progress(value => diff --git a/DeFRaG_Helper/Views/Start.xaml.cs b/DeFRaG_Helper/Views/Start.xaml.cs index ba9b329..7ad7993 100644 --- a/DeFRaG_Helper/Views/Start.xaml.cs +++ b/DeFRaG_Helper/Views/Start.xaml.cs @@ -128,7 +128,7 @@ private async Task InitializeAsync() } catch (Exception ex) { - SimpleLogger.Log(ex.Message); + MessageHelper.Log(ex.Message); throw; }