Skip to content

Commit

Permalink
Improved a couple of things
Browse files Browse the repository at this point in the history
  • Loading branch information
Lamonin committed Nov 13, 2023
1 parent 5cd5f85 commit e7903a8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
10 changes: 5 additions & 5 deletions ConfirmDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:XboxExplorerKiller"
mc:Ignorable="d"
Title="ConfirmDialog" Height="220" Width="280" ResizeMode="NoResize" WindowStartupLocation="CenterOwner">
<Grid Margin="16,16,16,16">
Title="ConfirmDialog" Height="Auto" Width="240" SizeToContent="Height" ResizeMode="NoResize" WindowStartupLocation="CenterOwner">
<Grid Margin="8,8,8,8">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="24px"/>
Expand All @@ -15,8 +15,8 @@
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="ConfirmDialogMessage" TextWrapping="Wrap" Text="Default Confirm Message" Grid.ColumnSpan="2" Margin="0,0,0,8"/>
<Button Content="Yes" Grid.Row="1" Margin="0,0,4,0" IsDefault="true" Click="Yes_Button_Click"/>
<Button Grid.Column="1" Content="Cancel" Grid.Row="1" Margin="4,0,0,0" IsCancel="True"/>
<TextBlock x:Name="ConfirmDialogMessage" TextWrapping="Wrap" Text="Default Confirm Message" Grid.ColumnSpan="2" Margin="0,0,0,24"/>
<Button x:Name="ConfirmButton" Content="Yes" Grid.Row="1" Margin="0,0,4,0" IsDefault="true" Click="Yes_Button_Click"/>
<Button x:Name="CancelButton" Grid.Column="1" Content="Cancel" Grid.Row="1" Margin="4,0,0,0" IsCancel="True"/>
</Grid>
</Window>
6 changes: 5 additions & 1 deletion ConfirmDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ public ConfirmDialog()
InitializeComponent();
}

public static bool? Open(Window owner, string title, string message)
public static bool? Open(Window owner, string title, string message, string okBtnText = "Yes", string cancelBtnText = "Cancel")
{
ConfirmDialog dialog = new ConfirmDialog
{
Title = title,
Owner = owner
};

dialog.ConfirmDialogMessage.Text = message;
dialog.ConfirmButton.Content = okBtnText;
dialog.CancelButton.Content = cancelBtnText;

return dialog.ShowDialog();
}

Expand Down
4 changes: 2 additions & 2 deletions InputDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:XboxExplorerKiller"
mc:Ignorable="d"
Title="InputDialog" Height="220" Width="280" WindowStartupLocation="CenterOwner">
<Grid Margin="16,16,16,16">
Title="InputDialog" Height="Auto" Width="240" WindowStartupLocation="CenterOwner" SizeToContent="Height" ResizeMode="NoResize">
<Grid Margin="8,8,8,8">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="28px"/>
Expand Down
32 changes: 27 additions & 5 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public MainWindow()

killerTimer = new Timer(1000);
killerTimer.Elapsed += KillerTimer_Elapsed;

Closing += MainWindow_Closing;
}

private void Window_Loaded(object sender, RoutedEventArgs e)
Expand All @@ -51,6 +53,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e)

LoadData();

killedProcessName = "";
DateTimeLabel.Content = DateTime.Now;

var tb = new TextBlock();
Expand All @@ -67,6 +70,24 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
}


private void MainWindow_Closing(object? sender, System.ComponentModel.CancelEventArgs e)
{
killerTimer.Stop();

if (isExplorerKilled)
{
const string message_title = "Restart explorer.exe process?";
const string message_body = "If you do not restart the Explorer process now, " +
"then you will have to do it through the Task Manager, or in some other way. " +
"Do you want to restart the Explorer process?";

if (ConfirmDialog.Open(this, message_title, message_body, "Yes", "No") == true)
{
RestartExplorer();
}
}
}

private void TimeTimer_Elapsed(object? sender, ElapsedEventArgs e)
{
Dispatcher.Invoke(() =>
Expand All @@ -77,12 +98,12 @@ private void TimeTimer_Elapsed(object? sender, ElapsedEventArgs e)

private void KillerTimer_Elapsed(object sender, ElapsedEventArgs e)
{
if (isExplorerKilled)
if (killedProcessName != "")
{
if (Process.GetProcessesByName(killedProcessName).Length == 0)
{
RestartExplorer();
isExplorerKilled = false;
killedProcessName = "";
}
}
else
Expand All @@ -94,7 +115,6 @@ private void KillerTimer_Elapsed(object sender, ElapsedEventArgs e)
if (processNamesForKill.Contains(process.ProcessName))
{
KillExplorer();
isExplorerKilled = true;
killedProcessName = process.ProcessName;
break;
}
Expand Down Expand Up @@ -152,6 +172,7 @@ private void KillExplorer()
explorerStatusRun.Foreground = Brushes.Red;
});
CallCmdCommand("taskkill /f /im explorer.exe");
isExplorerKilled = true;
}

private void RestartExplorer()
Expand All @@ -162,6 +183,7 @@ private void RestartExplorer()
explorerStatusRun.Foreground = Brushes.Green;
});
CallCmdCommand("start %windir%\\explorer.exe");
isExplorerKilled = false;
}

private string GetListBoxSelectedValue(ListBox listBox)
Expand Down Expand Up @@ -240,13 +262,13 @@ private void Start_Button_Click(object sender, RoutedEventArgs e)
private void Kill_Button_Click(object sender, RoutedEventArgs e)
{
KillExplorer();
this.Focus();
Focus();
}

private void Restart_Button_Click(object sender, RoutedEventArgs e)
{
RestartExplorer();
this.Focus();
Focus();
}
}
}

0 comments on commit e7903a8

Please sign in to comment.