aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Updater
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-12-16 02:10:02 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-12-16 02:10:02 +0200
commit33bbdd4f67822cdf6a655ae92ab8307d72ee0365 (patch)
tree4715479328500e55bb13f12653af41f6556bb28b /Software/Visual_Studio/PPC/Tango.PPC.Updater
parent66be0fdd579050375421ad54dc25cf35bac0845c (diff)
downloadTango-33bbdd4f67822cdf6a655ae92ab8307d72ee0365.tar.gz
Tango-33bbdd4f67822cdf6a655ae92ab8307d72ee0365.zip
More improvements to PPC updater.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Updater')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Updater/Images/warning.pngbin0 -> 8947 bytes
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Updater/MainWindow.xaml35
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Updater/MainWindow.xaml.cs115
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Updater/Tango.PPC.Updater.csproj3
4 files changed, 122 insertions, 31 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Updater/Images/warning.png b/Software/Visual_Studio/PPC/Tango.PPC.Updater/Images/warning.png
new file mode 100644
index 000000000..26ccc3ecb
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Updater/Images/warning.png
Binary files differ
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Updater/MainWindow.xaml b/Software/Visual_Studio/PPC/Tango.PPC.Updater/MainWindow.xaml
index a5e63477f..351ca0838 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Updater/MainWindow.xaml
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Updater/MainWindow.xaml
@@ -6,12 +6,43 @@
xmlns:local="clr-namespace:Tango.PPC.Updater"
mc:Ignorable="d"
WindowStyle="None" ResizeMode="NoResize" Width="800" Height="1280">
+
+ <Window.Resources>
+ <SolidColorBrush x:Key="Foreground" Color="#1c63ea" />
+
+ <Style TargetType="Button" x:Key="Button">
+ <Setter Property="Foreground" Value="{StaticResource Foreground}"></Setter>
+ <Setter Property="FontSize" Value="18"></Setter>
+ <Setter Property="FontWeight" Value="SemiBold"></Setter>
+ <Setter Property="Margin" Value="20 0"></Setter>
+ <Setter Property="Template">
+ <Setter.Value>
+ <ControlTemplate TargetType="Button">
+ <Border BorderBrush="{StaticResource Foreground}" BorderThickness="1" CornerRadius="25" Background="Transparent">
+ <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Content="{TemplateBinding Content}" />
+ </Border>
+ </ControlTemplate>
+ </Setter.Value>
+ </Setter>
+ </Style>
+ </Window.Resources>
<Grid>
- <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
+ <StackPanel x:Name="stackProgress" HorizontalAlignment="Center" VerticalAlignment="Center">
<Image Source="/Images/package.png" Width="200" />
<TextBlock x:Name="txtStatus" Margin="0 100 0 0" FontSize="16" Text="Updating Tango..." HorizontalAlignment="Center"></TextBlock>
- <ProgressBar x:Name="prog" Margin="0 30 0 0" Width="500" Height="10" Maximum="100" Value="0" BorderThickness="0" Foreground="#1c63ea"></ProgressBar>
+ <ProgressBar x:Name="prog" Margin="0 30 0 0" Width="500" Height="10" Maximum="100" Value="0" BorderThickness="0" Foreground="{StaticResource Foreground}"></ProgressBar>
+ </StackPanel>
+
+ <StackPanel x:Name="stackFailed" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0 460 0 0" Visibility="Collapsed">
+ <Image Source="/Images/warning.png" Width="200" RenderOptions.BitmapScalingMode="Fant" />
+ <TextBlock Margin="0 100 0 0" FontSize="16" Text="Update Failed" Foreground="#FF0072" FontWeight="SemiBold" HorizontalAlignment="Center"></TextBlock>
+ <TextBlock x:Name="txtError" Margin="0 20 0 0" FontSize="16" Foreground="Gray" Text="Unexpected error" HorizontalAlignment="Center" TextAlignment="Center" TextWrapping="Wrap" Height="100"></TextBlock>
+
+ <UniformGrid Width="600" Height="55" Columns="2" Margin="0 200 0 0">
+ <Button x:Name="btnAbort" Content="ABORT" Style="{StaticResource Button}"></Button>
+ <Button x:Name="btnRetry" Content="RETRY" Style="{StaticResource Button}"></Button>
+ </UniformGrid>
</StackPanel>
</Grid>
</Window>
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Updater/MainWindow.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.Updater/MainWindow.xaml.cs
index b821b332b..8f521c85a 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Updater/MainWindow.xaml.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Updater/MainWindow.xaml.cs
@@ -27,6 +27,7 @@ namespace Tango.PPC.Updater
private String _sourceFolder = AppDomain.CurrentDomain.BaseDirectory;
private String _msProcessName = "Tango.PPC.UI";
private String _appPath;
+ private bool EMULATE_EXCEPTION = false;
public MainWindow()
{
@@ -57,8 +58,16 @@ namespace Tango.PPC.Updater
Width = touch_screen.Bounds.Width;
Height = touch_screen.Bounds.Height;
}
+ else
+ {
+ Top = 0;
+ Left = 0;
+ }
ContentRendered += MainWindow_ContentRendered;
+
+ btnRetry.Click += BtnRetry_Click;
+ btnAbort.Click += BtnAbort_Click;
}
private void MainWindow_ContentRendered(object sender, EventArgs e)
@@ -70,6 +79,8 @@ namespace Tango.PPC.Updater
{
try
{
+ ShowProgress();
+
if (!IdentityUtils.IsElevated())
{
ShowError("The updater utility is not running under elevated permissions and cannot perform.\nThe process will restart.");
@@ -87,6 +98,13 @@ namespace Tango.PPC.Updater
try
{
Init();
+
+ if (EMULATE_EXCEPTION)
+ {
+ EMULATE_EXCEPTION = false;
+ throw new InvalidOperationException("This is an emulated error.");
+ }
+
EnsureTangoIsDown();
RemoveOldDLLFiles();
ReplaceFiles();
@@ -99,18 +117,7 @@ namespace Tango.PPC.Updater
}
catch (Exception ex)
{
- if (ShowErrorRetry($"Update failed.\n{ex.Message}"))
- {
- Update();
- }
- else
- {
- txtStatus.Text = "Update failed. Restoring previous application state...";
- DoEvents();
- Thread.Sleep(1000);
- StartTango(false);
- Exit();
- }
+ ShowFailed(ex);
}
}
@@ -236,37 +243,49 @@ namespace Tango.PPC.Updater
{
Process appProcess = null;
- int tries = 0;
-
- do
+ for (int i = 0; i < 20; i++)
{
- appProcess = Process.GetProcessesByName(_msProcessName).FirstOrDefault();
- Process p = new Process();
- p.StartInfo.CreateNoWindow = true;
- p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
- p.StartInfo.FileName = "wmic";
- p.StartInfo.Arguments = String.Format("process where name='{0}' delete", _msProcessName);
+ try
+ {
+ appProcess = Process.GetProcessesByName(_msProcessName).FirstOrDefault();
+ }
+ catch
+ {
+ Thread.Sleep(1000);
+ continue;
+ }
if (appProcess != null)
{
- tries++;
- appProcess.Kill();
+ try
+ {
+ appProcess.Kill();
+ }
+ catch { }
try
{
+ Process p = new Process();
+ p.StartInfo.CreateNoWindow = true;
+ p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
+ p.StartInfo.FileName = "wmic";
+ p.StartInfo.Arguments = String.Format("process where name='{0}' delete", _msProcessName);
p.Start();
}
catch { }
-
- Thread.Sleep(1000);
}
-
- if (tries > 10)
+ else
{
- throw new IOException("The main Tango process seems to in a frozen state. Please restart your computer and try again.");
+ break;
}
- } while (appProcess != null);
+ Thread.Sleep(1000);
+ }
+
+ if (appProcess != null)
+ {
+ throw new IOException("The main Tango process seems to in a frozen state. Please restart your computer and try again.");
+ }
}
/// <summary>
@@ -287,5 +306,43 @@ namespace Tango.PPC.Updater
var result = MessageBox.Show(error + "\n" + "Press yes to retry.", "Tango Update", MessageBoxButton.YesNo, MessageBoxImage.Error);
return result == MessageBoxResult.Yes;
}
+
+ private void ShowProgress()
+ {
+ stackProgress.Visibility = Visibility.Visible;
+ stackFailed.Visibility = Visibility.Collapsed;
+ }
+
+ private void ShowFailed(Exception ex)
+ {
+ try
+ {
+ using (EventLog eventLog = new EventLog("Application"))
+ {
+ eventLog.Source = "PPC Updater";
+ eventLog.WriteEntry($"PPC Updater Failed\n{ex.ToString()}", EventLogEntryType.Error, 101, 1);
+ }
+ }
+ catch { }
+
+ stackProgress.Visibility = Visibility.Collapsed;
+ stackFailed.Visibility = Visibility.Visible;
+ txtError.Text = ex.Message;
+ }
+
+ private void BtnAbort_Click(object sender, RoutedEventArgs e)
+ {
+ ShowProgress();
+ txtStatus.Text = "Update failed. Restoring previous application state...";
+ DoEvents();
+ Thread.Sleep(1000);
+ StartTango(false);
+ Exit();
+ }
+
+ private void BtnRetry_Click(object sender, RoutedEventArgs e)
+ {
+ Update();
+ }
}
}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Updater/Tango.PPC.Updater.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Updater/Tango.PPC.Updater.csproj
index ec40d5887..8f8430102 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Updater/Tango.PPC.Updater.csproj
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Updater/Tango.PPC.Updater.csproj
@@ -103,6 +103,9 @@
<ItemGroup>
<Resource Include="Images\package.png" />
</ItemGroup>
+ <ItemGroup>
+ <Resource Include="Images\warning.png" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>