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 ! --- .../Tango.MachineStudio.Updater/App.config | 6 + .../Tango.MachineStudio.Updater/App.xaml | 9 ++ .../Tango.MachineStudio.Updater/App.xaml.cs | 24 ++++ .../Images/machine-trans.png | Bin 0 -> 45618 bytes .../Tango.MachineStudio.Updater/Images/update.png | Bin 0 -> 5289 bytes .../Tango.MachineStudio.Updater/MainWindow.xaml | 37 ++++++ .../Tango.MachineStudio.Updater/MainWindow.xaml.cs | 146 +++++++++++++++++++++ .../Properties/AssemblyInfo.cs | 17 +++ .../Properties/Resources.Designer.cs | 71 ++++++++++ .../Properties/Resources.resx | 117 +++++++++++++++++ .../Properties/Settings.Designer.cs | 30 +++++ .../Properties/Settings.settings | 7 + .../Tango.MachineStudio.Updater.csproj | 110 ++++++++++++++++ .../Tango.MachineStudio.Updater/app.manifest | 76 +++++++++++ 14 files changed, 650 insertions(+) create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/App.config create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/App.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/App.xaml.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Images/machine-trans.png create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Images/update.png create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/MainWindow.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/MainWindow.xaml.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Properties/AssemblyInfo.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Properties/Resources.Designer.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Properties/Resources.resx create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Properties/Settings.Designer.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Properties/Settings.settings create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Tango.MachineStudio.Updater.csproj create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/app.manifest (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/App.config b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/App.config new file mode 100644 index 000000000..8324aa6ff --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/App.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/App.xaml new file mode 100644 index 000000000..c3e63550a --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/App.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/App.xaml.cs new file mode 100644 index 000000000..6c3dce868 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/App.xaml.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace Tango.MachineStudio.Updater +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + public static String[] StartupArgs { get; private set; } + + protected override void OnStartup(StartupEventArgs e) + { + StartupArgs = e.Args; + base.OnStartup(e); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Images/machine-trans.png b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Images/machine-trans.png new file mode 100644 index 000000000..a7cf65852 Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Images/machine-trans.png differ diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Images/update.png b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Images/update.png new file mode 100644 index 000000000..a82777414 Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Images/update.png differ diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/MainWindow.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/MainWindow.xaml new file mode 100644 index 000000000..a8d428650 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/MainWindow.xaml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + MACHINE STUDIO + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/MainWindow.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/MainWindow.xaml.cs new file mode 100644 index 000000000..e0e9e7f0d --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/MainWindow.xaml.cs @@ -0,0 +1,146 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Threading; + +namespace Tango.MachineStudio.Updater +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + private String _appPath = AppDomain.CurrentDomain.BaseDirectory; + private String _msProcessName = "Tango.MachineStudio.UI"; + private String _sourceFolder = App.StartupArgs.FirstOrDefault(); + + public MainWindow() + { + if (!Directory.Exists(_sourceFolder)) + { + ShowError("This update utility can only be executed by Machine Studio."); + Environment.Exit(0); + } + + InitializeComponent(); + ContentRendered += MainWindow_ContentRendered; + } + + private void MainWindow_ContentRendered(object sender, EventArgs e) + { + Update(); + } + + private void Update() + { + EnsureMachineStudioIsDown(); + ReplaceFiles(); + StartMachineStudio(); + Environment.Exit(0); + } + + private void StartMachineStudio() + { + txtStatus.Text = "Update completed. Starting Machine Studio..."; + DoEvents(); + Thread.Sleep(1000); + + Process p = new Process(); + p.StartInfo.FileName = _appPath + "\\" + _msProcessName + ".exe"; + p.StartInfo.LoadUserProfile = true; + p.StartInfo.UseShellExecute = true; + p.Start(); + } + + private void ReplaceFiles() + { + int maxProgress = Directory.GetFiles(_sourceFolder, "*.*", SearchOption.AllDirectories).Length; + int progress = 0; + + foreach (string dirPath in Directory.GetDirectories(_sourceFolder, "*", SearchOption.AllDirectories)) + { + try + { + Directory.CreateDirectory(dirPath.Replace(_sourceFolder, _appPath)); + } + catch (Exception ex) + { + ShowError("Could not create directory " + Path.GetFileName(dirPath) + Environment.NewLine + ex.Message); + } + } + + foreach (string newPath in Directory.GetFiles(_sourceFolder, "*.*", SearchOption.AllDirectories)) + { + try + { + txtStatus.Text = "Copying file " + Path.GetFileName(newPath); + DoEvents(); + + File.Copy(newPath, newPath.Replace(_sourceFolder, _appPath), true); + + prog.Maximum = maxProgress; + prog.Value = progress++; + DoEvents(); + + Thread.Sleep(30); + } + catch (Exception ex) + { + ShowError("Could not create file " + Path.GetFileName(newPath) + Environment.NewLine + ex.Message); + } + } + } + + private void EnsureMachineStudioIsDown() + { + Process appProcess = null; + + int tries = 0; + + do + { + appProcess = Process.GetProcessesByName(_msProcessName).FirstOrDefault(); + + if (appProcess != null) + { + tries++; + appProcess.Kill(); + Thread.Sleep(1000); + } + + if (tries > 10) + { + ShowError("The main Machine Studio process seems to in a frozen state. Please restart your computer and try again."); + Environment.Exit(0); + } + + } while (appProcess != null); + } + + /// + /// Forces UI rendering. + /// + private void DoEvents() + { + Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { })); + } + + private void ShowError(String error) + { + MessageBox.Show(error, "Machine Studio Update", MessageBoxButton.OK, MessageBoxImage.Error); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Properties/AssemblyInfo.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..7a79d1042 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Properties/AssemblyInfo.cs @@ -0,0 +1,17 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +[assembly: AssemblyTitle("Tango - Machine Studio Updater Utility")] +[assembly: ComVisible(false)] + +[assembly:ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Properties/Resources.Designer.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Properties/Resources.Designer.cs new file mode 100644 index 000000000..5061e6179 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Tango.MachineStudio.Updater.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Tango.MachineStudio.Updater.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Properties/Resources.resx b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Properties/Settings.Designer.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Properties/Settings.Designer.cs new file mode 100644 index 000000000..a18e7398e --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Tango.MachineStudio.Updater.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Properties/Settings.settings b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Properties/Settings.settings new file mode 100644 index 000000000..033d7a5e9 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Tango.MachineStudio.Updater.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Tango.MachineStudio.Updater.csproj new file mode 100644 index 000000000..c77222c03 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Tango.MachineStudio.Updater.csproj @@ -0,0 +1,110 @@ + + + + + Debug + AnyCPU + {844787CE-F409-4F18-BCCC-F3809ECB86F3} + WinExe + Tango.MachineStudio.Updater + Tango.MachineStudio.Updater + v4.6 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + + + AnyCPU + true + full + false + ..\..\Build\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + app.manifest + + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + GlobalVersionInfo.cs + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/app.manifest b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/app.manifest new file mode 100644 index 000000000..467015914 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/app.manifest @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.3.1