diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-22 13:23:49 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-22 13:23:49 +0200 |
| commit | 042b4d3e7b0af729792ca20e086756c36d2f5768 (patch) | |
| tree | 90fe664895ae143c25f1afb15b8ccbbcad94837e /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs | |
| parent | f991f37a95a854e9b2aada52982d83ddaa0ca1b0 (diff) | |
| download | Tango-042b4d3e7b0af729792ca20e086756c36d2f5768.tar.gz Tango-042b4d3e7b0af729792ca20e086756c36d2f5768.zip | |
Working on machine studio update center !
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs | 67 |
1 files changed, 14 insertions, 53 deletions
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 }); } - /// <summary> - /// Determines whether [is file locked] [the specified file]. - /// </summary> - /// <param name="file">The file.</param - private bool IsFileLocked(String file) - { - FileStream stream = null; - - try - { - stream = new FileInfo(file).Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None); - } - catch (IOException) - { - //the file is unavailable because it is: - //still being written to - //or being processed by another thread - //or does not exist (has already been processed) - return true; - } - finally - { - if (stream != null) - stream.Close(); - } - - //file is not locked - return false; - } - private void TryAgain() { CheckForUpdates(); @@ -306,7 +262,12 @@ namespace Tango.MachineStudio.UI.ViewModels private void RestartApplication() { - _application.ShutDown(); + Process p = new Process(); + p.StartInfo.FileName = _appPath + "\\Tango.MachineStudio.Updater.exe"; + p.StartInfo.UseShellExecute = true; + p.StartInfo.Arguments = _newPackageTempFolder; + p.Start(); + Environment.Exit(0); } protected override void RaisePropertyChangedAuto([CallerMemberName] string caller = null) |
