diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI')
3 files changed, 233 insertions, 3 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Properties/AssemblyInfo.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Properties/AssemblyInfo.cs index 2c31c002f..224cd3199 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Properties/AssemblyInfo.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Properties/AssemblyInfo.cs @@ -4,5 +4,5 @@ using System.Runtime.InteropServices; [assembly: System.Windows.ThemeInfo(System.Windows.ResourceDictionaryLocation.None, System.Windows.ResourceDictionaryLocation.SourceAssembly)] [assembly: AssemblyTitle("Tango - Machine Studio")] -[assembly: AssemblyVersion("3.3.38.18238")] +[assembly: AssemblyVersion("3.3.39.18238")] [assembly: ComVisible(false)]
\ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs index c5831f701..55f585626 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs @@ -35,6 +35,9 @@ namespace Tango.MachineStudio.UI.ViewModels Updating, UpdateCompleted, Error, + RollingBack, + RollbackCompleted, + RollbackError, } public class UpdateViewVM : ViewModel @@ -48,6 +51,7 @@ namespace Tango.MachineStudio.UI.ViewModels private IAuthenticationProvider _authentication; private CheckForUpdatesResponse _updateInfo; private TemporaryFolder _newPackageTempFolder; + private TemporaryFolder _previousPackageTempFolder; private bool _forcedUpdate; public bool ForcedUpdate @@ -88,6 +92,14 @@ namespace Tango.MachineStudio.UI.ViewModels set { _downloadProgress = value; RaisePropertyChangedAuto(); } } + private double _rollbackProgress; + + public double RollbackProgress + { + get { return _rollbackProgress; } + set { _rollbackProgress = value; RaisePropertyChangedAuto(); } + } + private double _updateProgress; public double UpdateProgress @@ -104,6 +116,14 @@ namespace Tango.MachineStudio.UI.ViewModels set { _currentUpdateFile = value; RaisePropertyChanged(nameof(CurrentUpdateFile)); } } + private bool _isRollbackAvailable; + + public bool IsRollbackAvailable + { + get { return _isRollbackAvailable; } + set { _isRollbackAvailable = value; RaisePropertyChangedAuto(); } + } + public RelayCommand UpdateCommand { get; set; } public RelayCommand BackCommand { get; set; } @@ -112,6 +132,10 @@ namespace Tango.MachineStudio.UI.ViewModels public RelayCommand TryAgainCommand { get; set; } + public RelayCommand RollbackCommand { get; set; } + + public RelayCommand TryRollbackAgainCommand { get; set; } + public UpdateViewVM(INotificationProvider notification, IAuthenticationProvider authentication, INavigationManager navigation, IStudioApplicationManager application) { _notification = notification; @@ -123,8 +147,12 @@ namespace Tango.MachineStudio.UI.ViewModels Status = UpdateStatus.CheckingForUpdate; UpdateCommand = new RelayCommand(StartUpdate, () => Status == UpdateStatus.UpdateAvailable); BackCommand = new RelayCommand(BackToApplication, () => Status != UpdateStatus.Updating && !ForcedUpdate); - RestartCommand = new RelayCommand(RestartApplication, () => Status == UpdateStatus.UpdateCompleted); + RestartCommand = new RelayCommand(RestartApplication, () => Status == UpdateStatus.UpdateCompleted || Status == UpdateStatus.RollbackCompleted); TryAgainCommand = new RelayCommand(TryAgain, () => Status == UpdateStatus.Error); + RollbackCommand = new RelayCommand(Rollback, () => Status != UpdateStatus.RollingBack && !ForcedUpdate); + TryRollbackAgainCommand = new RelayCommand(TryRollbackAgain, () => Status == UpdateStatus.RollbackError); + + IsRollbackAvailable = File.Exists(GetRollbackFile()); TangoMessenger.Default.Register<Messages.ForcedUpdateMessage>(HandleForcedUpdateMessage); } @@ -294,6 +322,41 @@ namespace Tango.MachineStudio.UI.ViewModels } } + try + { + LogManager.Log("Backing up current version..."); + CurrentUpdateFile = "Backing up current version..."; + + String rollbackFolder = GetRollbackFolder(); + Directory.CreateDirectory(rollbackFolder); + + String backFile = GetRollbackFile(); + + if (File.Exists(backFile)) + { + File.Delete(backFile); + } + + using (ZipFile backZip = new ZipFile(backFile)) + { + int currentEntry = 0; + + backZip.SaveProgress += (_, e) => + { + UpdateProgress = ((double)(currentEntry++) / (double)backZip.Entries.Count) * 100d; + }; + + backZip.Password = "Aa123456"; + backZip.AddDirectory(_appPath); + backZip.Save(); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Could not construct rollback."); + _notification.ShowWarning("Update center has failed to construct a rollback point for the current version. Version rollback will not be available."); + } + TangoIOC.Default.GetInstance<MainViewVM>().DisableCheckForUpdates = true; Status = UpdateStatus.UpdateCompleted; } @@ -319,7 +382,16 @@ namespace Tango.MachineStudio.UI.ViewModels try { Process p = new Process(); - p.StartInfo.FileName = _newPackageTempFolder + "\\Tango.MachineStudio.Updater.exe"; + + if (Status == UpdateStatus.UpdateCompleted) + { + p.StartInfo.FileName = _newPackageTempFolder + "\\Tango.MachineStudio.Updater.exe"; + } + else if (Status == UpdateStatus.RollbackCompleted) + { + p.StartInfo.FileName = _previousPackageTempFolder + "\\Tango.MachineStudio.Updater.exe"; + } + p.StartInfo.UseShellExecute = true; p.StartInfo.Arguments = _appPath; p.Start(); @@ -335,6 +407,90 @@ namespace Tango.MachineStudio.UI.ViewModels Environment.Exit(0); } + private void Rollback() + { + if (_notification.ShowQuestion("Are you sure you want to restore the previous version?")) + { + Status = UpdateStatus.RollingBack; + + try + { + Task.Factory.StartNew(() => + { + _previousPackageTempFolder = TemporaryManager.CreateFolder(); + _previousPackageTempFolder.Persist = true; + + using (ZipFile zip = new ZipFile(GetRollbackFile())) + { + zip.Password = "Aa123456"; + + int currentEntry = 0; + + zip.ExtractProgress += (x, args) => + { + if (args.EventType == ZipProgressEventType.Extracting_AfterExtractEntry) + { + logManager.Log("Extracting " + Path.GetFileName(args.CurrentEntry.FileName)); + RollbackProgress = ((double)(currentEntry++) / (double)zip.Entries.Count) * 100d; + } + }; + + foreach (ZipEntry entry in zip) + { + Thread.Sleep(10); + + string newPath = Path.Combine(_previousPackageTempFolder.Path, entry.FileName); + + try + { + if (entry.IsDirectory) + { + Directory.CreateDirectory(newPath); + } + else + { + entry.Extract(_previousPackageTempFolder.Path, ExtractExistingFileAction.OverwriteSilently); + } + } + catch + { + logManager.Log("Could not extract file " + entry.FileName); + } + } + + } + + File.Delete(GetRollbackFile()); + + Status = UpdateStatus.RollbackCompleted; + }); + } + catch (Exception ex) + { + Status = UpdateStatus.Error; + LogManager.Log(ex, "Error while trying to restore version."); + _notification.ShowError("An error occurred while trying to restore the previous version."); + } + } + } + + private void TryRollbackAgain() + { + CheckForUpdates(); + } + + private String GetRollbackFolder() + { + String rollbackFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "Rollback"); + return rollbackFolder; + } + + private String GetRollbackFile() + { + String backFile = Path.Combine(GetRollbackFolder(), Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName) + ".rollback"); + return backFile; + } + protected override void RaisePropertyChangedAuto([CallerMemberName] string caller = null) { base.RaisePropertyChangedAuto(caller); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/UpdateView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/UpdateView.xaml index 52ba9ee18..6818d13cc 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/UpdateView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/UpdateView.xaml @@ -108,6 +108,13 @@ <TextBlock Margin="5 0 0 0" VerticalAlignment="Center">UPDATE</TextBlock> </StackPanel> </Button> + + <Button Visibility="{Binding IsRollbackAvailable,Converter={StaticResource BoolToVisConverter}}" MinWidth="140" Height="40" Style="{StaticResource MaterialDesignFlatButton}" ToolTip="Restore Machine Studio to the previous version." Margin="0 40 0 0" Command="{Binding RollbackCommand}" Foreground="#FF5F5F"> + <StackPanel Orientation="Horizontal"> + <materialDesign:PackIcon Kind="BackupRestore" Width="24" Height="24" /> + <TextBlock Margin="5 0 0 0" VerticalAlignment="Center">Restore previous version</TextBlock> + </StackPanel> + </Button> </StackPanel> </Grid> </Setter.Value> @@ -177,6 +184,13 @@ <StackPanel Orientation="Horizontal"> <TextBlock VerticalAlignment="Center" Margin="0 20 0 0">Your version of Machine Studio is up to date!</TextBlock> </StackPanel> + + <Button Visibility="{Binding IsRollbackAvailable,Converter={StaticResource BoolToVisConverter}}" MinWidth="140" Height="40" Style="{StaticResource MaterialDesignFlatButton}" ToolTip="Restore Machine Studio to the previous version." Margin="0 40 0 0" Command="{Binding RollbackCommand}" Foreground="#FF5F5F"> + <StackPanel Orientation="Horizontal"> + <materialDesign:PackIcon Kind="BackupRestore" Width="24" Height="24" /> + <TextBlock Margin="5 0 0 0" VerticalAlignment="Center">Restore previous version</TextBlock> + </StackPanel> + </Button> </StackPanel> </Grid> </Setter.Value> @@ -205,6 +219,66 @@ </Setter.Value> </Setter> </DataTrigger> + <DataTrigger Binding="{Binding Status}" Value="{x:Static vm:UpdateStatus.RollingBack}"> + <Setter Property="Content"> + <Setter.Value> + <Grid> + <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> + <TextBlock HorizontalAlignment="Center"> + <Run>Restoring previous version, please wait...</Run> + </TextBlock> + <ProgressBar Height="10" Foreground="DimGray" Margin="0 20 0 0" Maximum="100" Value="{Binding RollbackProgress}"></ProgressBar> + </StackPanel> + </Grid> + </Setter.Value> + </Setter> + </DataTrigger> + <DataTrigger Binding="{Binding Status}" Value="{x:Static vm:UpdateStatus.RollbackError}"> + <Setter Property="Content"> + <Setter.Value> + <Grid> + <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> + <materialDesign:PackIcon Kind="Alert" Width="100" Height="100" Foreground="#FF5F5F" HorizontalAlignment="Center" /> + <TextBlock VerticalAlignment="Center" Margin="0 20 0 0" HorizontalAlignment="Center">Error restoring previous version</TextBlock> + <TextBlock HorizontalAlignment="Center" Margin="0 10 0 0" FontSize="12" TextAlignment="Center"> + <Run>An error occurred while restore the last version.</Run> + <LineBreak/> + <Run>press 'Try Again' to give it another try.</Run> + </TextBlock> + <Button MinWidth="140" Height="40" Margin="0 50 0 0" Width="200" Command="{Binding TryRollbackAgainCommand}"> + <StackPanel Orientation="Horizontal"> + <materialDesign:PackIcon Kind="BackupRestore" Width="24" Height="24" /> + <TextBlock Margin="5 0 0 0" VerticalAlignment="Center">TRY AGAIN</TextBlock> + </StackPanel> + </Button> + </StackPanel> + </Grid> + </Setter.Value> + </Setter> + </DataTrigger> + <DataTrigger Binding="{Binding Status}" Value="{x:Static vm:UpdateStatus.RollbackCompleted}"> + <Setter Property="Content"> + <Setter.Value> + <Grid> + <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> + <materialDesign:PackIcon Kind="Check" Width="100" Height="100" Foreground="#1CBB1C" HorizontalAlignment="Center" /> + <StackPanel Orientation="Horizontal"> + <TextBlock VerticalAlignment="Center" Margin="0 20 0 0">Machine studio has been restored to the previous version!</TextBlock> + </StackPanel> + + <TextBlock HorizontalAlignment="Center" Margin="0 10 0 0" FontSize="12">Please restart Machine Studio in order to apply the changes.</TextBlock> + + <Button MinWidth="140" Height="40" Margin="0 50 0 0" Width="200" Command="{Binding RestartCommand}"> + <StackPanel Orientation="Horizontal"> + <materialDesign:PackIcon Kind="BackupRestore" Width="24" Height="24" /> + <TextBlock Margin="5 0 0 0" VerticalAlignment="Center">RESTART</TextBlock> + </StackPanel> + </Button> + </StackPanel> + </Grid> + </Setter.Value> + </Setter> + </DataTrigger> </Style.Triggers> </Style> </ContentControl.Style> |
