Skip to content

Commit

Permalink
Use file scoped namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
cooolbros committed Jul 30, 2023
1 parent e93b4a3 commit 769e3d2
Show file tree
Hide file tree
Showing 43 changed files with 2,159 additions and 2,203 deletions.
34 changes: 16 additions & 18 deletions src/HUDMerger/AboutWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Input;

namespace HUDMerger
namespace HUDMerger;

/// <summary>
/// Interaction logic for AboutWindow.xaml
/// </summary>
public partial class AboutWindow : Window
{
/// <summary>
/// Interaction logic for AboutWindow.xaml
/// </summary>
public partial class AboutWindow : Window
public AboutWindow()
{
public AboutWindow()
{
InitializeComponent();
}
InitializeComponent();
}

private void Open_Github(object sender, MouseButtonEventArgs e)
{
Process.Start("explorer", "https://github.com/cooolbros/hud-merger");
}
private void Open_Github(object sender, MouseButtonEventArgs e)
{
Process.Start("explorer", "https://github.com/cooolbros/hud-merger");
}

private void Open_TeamFortressTV(object sender, MouseButtonEventArgs e)
{
Process.Start("explorer", "https://www.teamfortress.tv/60220/hud-merger");
}
private void Open_TeamFortressTV(object sender, MouseButtonEventArgs e)
{
Process.Start("explorer", "https://www.teamfortress.tv/60220/hud-merger");
}
}
27 changes: 13 additions & 14 deletions src/HUDMerger/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@
using System.Threading.Tasks;
using System.Windows;

namespace HUDMerger
namespace HUDMerger;

/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
protected override void OnStartup(StartupEventArgs e)
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
base.OnStartup(e);

MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel()
};
MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel()
};

MainWindow.Show();
}
MainWindow.Show();
}
}
31 changes: 15 additions & 16 deletions src/HUDMerger/Commands/CommandBase.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
using System;
using System.Windows.Input;

namespace HUDMerger.Commands
namespace HUDMerger.Commands;

public abstract class CommandBase : ICommand, IDisposable
{
public abstract class CommandBase : ICommand, IDisposable
{
public event EventHandler CanExecuteChanged;
public event EventHandler CanExecuteChanged;

public virtual bool CanExecute(object parameter)
{
return true;
}
public virtual bool CanExecute(object parameter)
{
return true;
}

public void OnCanExecuteChanged()
{
CanExecuteChanged?.Invoke(this, new EventArgs());
}
public void OnCanExecuteChanged()
{
CanExecuteChanged?.Invoke(this, new EventArgs());
}

public abstract void Execute(object parameter);
public abstract void Execute(object parameter);

public virtual void Dispose()
{
}
public virtual void Dispose()
{
}
}
71 changes: 35 additions & 36 deletions src/HUDMerger/Commands/MergeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,58 @@
using HUDMerger.Models;
using HUDMerger.ViewModels;

namespace HUDMerger.Commands
namespace HUDMerger.Commands;

public class MergeCommand : CommandBase
{
public class MergeCommand : CommandBase
private readonly MainWindowViewModel _mainWindowViewModel;

public MergeCommand(MainWindowViewModel mainWindowViewModel)
{
private readonly MainWindowViewModel _mainWindowViewModel;
_mainWindowViewModel = mainWindowViewModel;
_mainWindowViewModel.PropertyChanged += _mainWindowViewModel_PropertyChanged;
}

public MergeCommand(MainWindowViewModel mainWindowViewModel)
private void _mainWindowViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(MainWindowViewModel.SourceHUD) || e.PropertyName == nameof(MainWindowViewModel.TargetHUD))
{
_mainWindowViewModel = mainWindowViewModel;
_mainWindowViewModel.PropertyChanged += _mainWindowViewModel_PropertyChanged;
OnCanExecuteChanged();
}
}

private void _mainWindowViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
public override bool CanExecute(object parameter)
{
return _mainWindowViewModel.SourceHUD != null && _mainWindowViewModel.TargetHUD != null && base.CanExecute(parameter);
}

public override void Execute(object parameter)
{
try
{
if (e.PropertyName == nameof(MainWindowViewModel.SourceHUD) || e.PropertyName == nameof(MainWindowViewModel.TargetHUD))
if (Utilities.PathContainsPath(Path.Join(Properties.Settings.Default.Team_Fortress_2_Folder, "tf\\custom"), _mainWindowViewModel.TargetHUD.FolderPath) && Process.GetProcessesByName("hl2").Any())
{
OnCanExecuteChanged();
MessageBox.Show("HL2 process open, cannot merge!", "HL2 Open Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
}

public override bool CanExecute(object parameter)
{
return _mainWindowViewModel.SourceHUD != null && _mainWindowViewModel.TargetHUD != null && base.CanExecute(parameter);
_mainWindowViewModel.TargetHUD.Merge(_mainWindowViewModel.SourceHUD, MainWindowViewModel.HUDPanels.Where(hudPanelViewModel => hudPanelViewModel.Armed).Select(hudPanelViewModel => hudPanelViewModel.HUDPanel).ToArray());
MessageBox.Show("Done!");
}

public override void Execute(object parameter)
catch (Exception e)
{
try
{
if (Utilities.PathContainsPath(Path.Join(Properties.Settings.Default.Team_Fortress_2_Folder, "tf\\custom"), _mainWindowViewModel.TargetHUD.FolderPath) && Process.GetProcessesByName("hl2").Any())
{
MessageBox.Show("HL2 process open, cannot merge!", "HL2 Open Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

_mainWindowViewModel.TargetHUD.Merge(_mainWindowViewModel.SourceHUD, MainWindowViewModel.HUDPanels.Where(hudPanelViewModel => hudPanelViewModel.Armed).Select(hudPanelViewModel => hudPanelViewModel.HUDPanel).ToArray());
MessageBox.Show("Done!");
}
catch (Exception e)
{
List<string> paragraphs = new List<string>
List<string> paragraphs = new List<string>
{
e.Message,
};

MessageBox.Show(String.Join("\r\n\r\n", paragraphs), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
MessageBox.Show(String.Join("\r\n\r\n", paragraphs), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}

public override void Dispose()
{
base.Dispose();
_mainWindowViewModel.PropertyChanged -= _mainWindowViewModel_PropertyChanged;
}
public override void Dispose()
{
base.Dispose();
_mainWindowViewModel.PropertyChanged -= _mainWindowViewModel_PropertyChanged;
}
}
25 changes: 12 additions & 13 deletions src/HUDMerger/Converters/BooleanEvaluateConverter.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
using System;
using System.Globalization;

namespace HUDMerger.Converters
namespace HUDMerger.Converters;

/// <summary>
/// Evaluate a boolean and return the ConverterParameter or TargetNullValue
/// </summary>
public class BooleanEvaluateConverter : ConverterBase
{
/// <summary>
/// Evaluate a boolean and return the ConverterParameter or TargetNullValue
/// </summary>
public class BooleanEvaluateConverter : ConverterBase
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (bool)value ? parameter : null;
}
return (bool)value ? parameter : null;
}

public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
11 changes: 5 additions & 6 deletions src/HUDMerger/Converters/ConverterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
using System.Globalization;
using System.Windows.Data;

namespace HUDMerger.Converters
namespace HUDMerger.Converters;

public abstract class ConverterBase : IValueConverter
{
public abstract class ConverterBase : IValueConverter
{
public abstract object Convert(object value, Type targetType, object parameter, CultureInfo culture);
public abstract object Convert(object value, Type targetType, object parameter, CultureInfo culture);

public abstract object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture);
}
public abstract object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture);
}
29 changes: 14 additions & 15 deletions src/HUDMerger/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
using System;
using System.Windows;

namespace HUDMerger
namespace HUDMerger;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
public MainWindow()
{
public MainWindow()
{
InitializeComponent();
InitializeComponent();

Properties.Settings.Default.Upgrade();
Properties.Settings.Default.Save();
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.Save();

// Updater
bool download = Properties.Settings.Default.Download_latest_HUD_file_definitions_file_on_start_up;
bool extract = Properties.Settings.Default.Extract_required_TF2_HUD_files_on_startup;
Updater.Update(download, extract);
}
// Updater
bool download = Properties.Settings.Default.Download_latest_HUD_file_definitions_file_on_start_up;
bool extract = Properties.Settings.Default.Extract_required_TF2_HUD_files_on_startup;
Updater.Update(download, extract);
}
}
Loading

0 comments on commit 769e3d2

Please sign in to comment.