From 042b4d3e7b0af729792ca20e086756c36d2f5768 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 22 Feb 2018 13:23:49 +0200 Subject: Working on machine studio update center ! --- .../ViewModels/UpdateViewVM.cs | 67 +++++----------------- 1 file changed, 14 insertions(+), 53 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels') 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 e5f3d7a46..c24204fb6 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs @@ -2,6 +2,7 @@ using Ionic.Zip; using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; @@ -42,6 +43,7 @@ namespace Tango.MachineStudio.UI.ViewModels private IStudioApplicationManager _application; private IAuthenticationProvider _authentication; private CheckForUpdatesResponse _updateInfo; + private String _newPackageTempFolder; private UpdateStatus _status; public UpdateStatus Status @@ -94,11 +96,6 @@ namespace Tango.MachineStudio.UI.ViewModels BackCommand = new RelayCommand(BackToApplication, () => Status != UpdateStatus.Updating); RestartCommand = new RelayCommand(RestartApplication, () => Status == UpdateStatus.UpdateCompleted); TryAgainCommand = new RelayCommand(TryAgain, () => Status == UpdateStatus.CheckingForUpdate); - - foreach (var file in Directory.GetFiles(_appPath, "*.tmp")) - { - PathHelper.TryDeleteFile(file); - } } public void OnNavigatedInto() @@ -117,7 +114,7 @@ namespace Tango.MachineStudio.UI.ViewModels try { Thread.Sleep(2000); - + service = UpdateServiceHelper.GetUpdateServiceChannel(); var client = service.CreateChannel(); @@ -167,7 +164,7 @@ namespace Tango.MachineStudio.UI.ViewModels _navigation.NavigateTo(NavigationView.MainView); Status = UpdateStatus.None; } - + private void StartUpdate() { DownloadProgress = 0; @@ -209,7 +206,7 @@ namespace Tango.MachineStudio.UI.ViewModels Status = UpdateStatus.Updating; - int lockedCounter = 0; + _newPackageTempFolder = PathHelper.GetTempFolderPath(); using (ZipFile zip = ZipFile.Read(tempFile)) { @@ -228,7 +225,7 @@ namespace Tango.MachineStudio.UI.ViewModels { Thread.Sleep(10); - string newPath = Path.Combine(_appPath, entry.FileName); + string newPath = Path.Combine(_newPackageTempFolder, entry.FileName); try { @@ -238,23 +235,12 @@ namespace Tango.MachineStudio.UI.ViewModels } else { - if (!IsFileLocked(newPath)) - { - entry.Extract(_appPath, ExtractExistingFileAction.OverwriteSilently); - } - else - { - LogManager.Log("File locked: " + entry.FileName); - File.Move(newPath, newPath + ".tmp"); - entry.Extract(_appPath, ExtractExistingFileAction.OverwriteSilently); - LogManager.Log("Performed overwrite bypass... (changes will be applied on restart)."); - lockedCounter++; - } + entry.Extract(_newPackageTempFolder, ExtractExistingFileAction.OverwriteSilently); } } catch { - LogManager.Log("Could not overwrite " + entry.FileName); + LogManager.Log("Could not extract file " + entry.FileName); } } } @@ -269,36 +255,6 @@ namespace Tango.MachineStudio.UI.ViewModels }); } - /// - /// Determines whether [is file locked] [the specified file]. - /// - /// The file.