patterncsharpMinor
Small Launcher Application
Viewed 0 times
launchersmallapplication
Problem
I have just somewhat completed a program, and was wondering what I could do to improve readability, and design as some functions seems to be rather large and an eye-sore.
```
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;
using WoWLauncher.Properties;
using MessageBox = System.Windows.MessageBox;
namespace WoWLauncher
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
}
private void MainWindow_OnMouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
DragMove();
}
private void Minimize_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
WindowState = WindowState.Minimized;
}
private void Exit_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Close();
}
private async void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
{
IProgress progressPercent = new Progress(percent =>
{
if (progressBar.IsIndeterminate)
progressBar.IsIndeterminate = false;
progressBar.Value = percent;
});
IProgress progressText = new Progress(text => updateLabel.Content = text);
windowTitle.Content = Settings.Default.ServerTitle;
news.Text = await GetNews(progressText);
await GetWoWDirectory();
await CheckUpdates(progressPercent, progressText);
}
private static async Task GetNews(IProgress updateText)
{
try
{
updateText.Re
```
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;
using WoWLauncher.Properties;
using MessageBox = System.Windows.MessageBox;
namespace WoWLauncher
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
}
private void MainWindow_OnMouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
DragMove();
}
private void Minimize_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
WindowState = WindowState.Minimized;
}
private void Exit_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Close();
}
private async void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
{
IProgress progressPercent = new Progress(percent =>
{
if (progressBar.IsIndeterminate)
progressBar.IsIndeterminate = false;
progressBar.Value = percent;
});
IProgress progressText = new Progress(text => updateLabel.Content = text);
windowTitle.Content = Settings.Default.ServerTitle;
news.Text = await GetNews(progressText);
await GetWoWDirectory();
await CheckUpdates(progressPercent, progressText);
}
private static async Task GetNews(IProgress updateText)
{
try
{
updateText.Re
Solution
It seems a bit odd to me that you suddenly use
I'm not a big fan of some of your names. For instance:
Watch out for inconsistent naming:
You have a
Even though this isn't that long (250 lines), I still feel that there's a lot of code in this class that belongs in a dedicated class, e.g. the update check, retrieval of the WoW directory,...
Web Forms MVP is probably overkill for this kind of project (since I doubt there will be much functionality to be added in the future), but I'd still try to limit the code in this
MessageBox.Show("Cannot find WoW Directory. Please choose.");, whereas in other places you update updateLabel.Realmlist is a compound word, so it should be RealmList. Actually, scrap that, it should be Realms because you should avoid using the name of the type in the name of the property or field.I'm not a big fan of some of your names. For instance:
progressText doesn't really convey what it is. (Also please be consistent: in one place you name this updateText.)Watch out for inconsistent naming:
FindWoWDirectory vs WoWFolder, for instance.You have a
using System.Windows.Forms; at the top, yet you still specify the full namespace in the code: System.Windows.Forms.DialogResult.OK.Even though this isn't that long (250 lines), I still feel that there's a lot of code in this class that belongs in a dedicated class, e.g. the update check, retrieval of the WoW directory,...
Web Forms MVP is probably overkill for this kind of project (since I doubt there will be much functionality to be added in the future), but I'd still try to limit the code in this
MainWindow class to UI-related code, and move all other code to smaller dedicated classes.Context
StackExchange Code Review Q#101538, answer score: 5
Revisions (0)
No revisions yet.