From 889bd32e9e798fe816f4ae1d0051e755c30eac5e Mon Sep 17 00:00:00 2001 From: Eric Reed Date: Mon, 11 Mar 2013 11:03:10 -0400 Subject: [PATCH 1/3] Fix target reference in updater --- .../Updates/ApplicationUpdater.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MediaBrowser.Common.Implementations/Updates/ApplicationUpdater.cs b/MediaBrowser.Common.Implementations/Updates/ApplicationUpdater.cs index 3b06f2006..00e232e44 100644 --- a/MediaBrowser.Common.Implementations/Updates/ApplicationUpdater.cs +++ b/MediaBrowser.Common.Implementations/Updates/ApplicationUpdater.cs @@ -24,7 +24,7 @@ namespace MediaBrowser.Common.Implementations.Updates var target = Path.Combine(Path.GetTempPath(), UpdaterExe); var product = app == MBApplication.MBTheater ? "mbt" : "server"; File.Copy(source, target, true); - Process.Start(UpdaterExe, string.Format("product={0} archive=\"{1}\" caller={2}", product, archive, Process.GetCurrentProcess().Id)); + Process.Start(target, string.Format("product={0} archive=\"{1}\" caller={2}", product, archive, Process.GetCurrentProcess().Id)); // That's it. The installer will do the work once we exit } From 9e5c8f97210437a81f80afd4be9cb68284627389 Mon Sep 17 00:00:00 2001 From: Eric Reed Date: Mon, 11 Mar 2013 12:10:12 -0400 Subject: [PATCH 2/3] Move uninstall to add/remove programs. Also fix continuation errors when problem downloading package. --- MediaBrowser.Installer/MainWindow.xaml.cs | 74 +++++++++++++++++-- .../MainWindow.xaml.cs | 34 ++++++++- .../MediaBrowser.Uninstaller.csproj | 5 ++ 3 files changed, 105 insertions(+), 8 deletions(-) diff --git a/MediaBrowser.Installer/MainWindow.xaml.cs b/MediaBrowser.Installer/MainWindow.xaml.cs index 431a7fb58..c8e1dc97c 100644 --- a/MediaBrowser.Installer/MainWindow.xaml.cs +++ b/MediaBrowser.Installer/MainWindow.xaml.cs @@ -9,6 +9,7 @@ using System.Windows; using System.Linq; using Ionic.Zip; using MediaBrowser.Installer.Code; +using Microsoft.Win32; using ServiceStack.Text; namespace MediaBrowser.Installer @@ -19,7 +20,8 @@ namespace MediaBrowser.Installer public partial class MainWindow : Window { protected PackageVersionClass PackageClass = PackageVersionClass.Release; - protected Version PackageVersion = new Version(4,0,0,0); + protected Version RequestedVersion = new Version(4,0,0,0); + protected Version ActualVersion; protected string PackageName = "MBServer"; protected string RootSuffix = "-Server"; protected string TargetExe = "MediaBrowser.ServerApplication.exe"; @@ -92,7 +94,7 @@ namespace MediaBrowser.Installer var product = args.GetValueOrDefault("product", null) ?? ConfigurationManager.AppSettings["product"] ?? "server"; PackageClass = (PackageVersionClass) Enum.Parse(typeof (PackageVersionClass), args.GetValueOrDefault("class", null) ?? ConfigurationManager.AppSettings["class"] ?? "Release"); - PackageVersion = new Version(args.GetValueOrDefault("version", "4.0")); + RequestedVersion = new Version(args.GetValueOrDefault("version", "4.0")); var callerId = args.GetValueOrDefault("caller", null); if (callerId != null) @@ -140,6 +142,7 @@ namespace MediaBrowser.Installer // Determine Package version var version = await GetPackageVersion(); + ActualVersion = version.version; // Now try and shut down the server if that is what we are installing and it is running var procs = Process.GetProcessesByName("mediabrowser.serverapplication"); @@ -202,6 +205,7 @@ namespace MediaBrowser.Installer catch (Exception e) { SystemClose("Error Downloading Package - " + e.GetType().FullName + "\n\n" + e.Message); + return; } } @@ -224,11 +228,13 @@ namespace MediaBrowser.Installer { SystemClose("Error Removing Archive - " + e.GetType().FullName + "\n\n" + e.Message); + return; } } catch (Exception e) { SystemClose("Error Extracting - " + e.GetType().FullName + "\n\n" + e.Message); + return; } // Create shortcut @@ -240,6 +246,7 @@ namespace MediaBrowser.Installer catch (Exception e) { SystemClose("Error Creating Shortcut - "+e.GetType().FullName+"\n\n"+e.Message); + return; } // And run @@ -250,6 +257,7 @@ namespace MediaBrowser.Installer catch (Exception e) { SystemClose("Error Executing - "+fullPath+ " "+e.GetType().FullName+"\n\n"+e.Message); + return; } SystemClose(); @@ -264,7 +272,7 @@ namespace MediaBrowser.Installer var json = await MainClient.DownloadStringTaskAsync("http://www.mb3admin.com/admin/service/package/retrieveAll?name=" + PackageName); var packages = JsonSerializer.DeserializeFromString>(json); - var version = packages[0].versions.Where(v => v.classification <= PackageClass).OrderByDescending(v => v.version).FirstOrDefault(v => v.version <= PackageVersion); + var version = packages[0].versions.Where(v => v.classification <= PackageClass).OrderByDescending(v => v.version).FirstOrDefault(v => v.version <= RequestedVersion); if (version == null) { SystemClose("Could not locate download package. Aborting."); @@ -373,12 +381,66 @@ namespace MediaBrowser.Installer dashboard.Save(); } - var uninstall = new ShellShortcut(Path.Combine(startMenu, "Uninstall " + FriendlyName + ".lnk")) - {Path = Path.Combine(Path.GetDirectoryName(targetExe), "MediaBrowser.Uninstaller.exe"), Arguments = (PackageName == "MBServer" ? "server" : "mbt"), Description = "Uninstall " + FriendlyName}; - uninstall.Save(); + CreateUninstaller(Path.Combine(Path.GetDirectoryName(targetExe) ?? "", "MediaBrowser.Uninstaller.exe")+ " "+ (PackageName == "MBServer" ? "server" : "mbt"), targetExe); } + /// + /// Create uninstall entry in add/remove + /// + /// + /// + private void CreateUninstaller(string uninstallPath, string targetExe) + { + using (var parent = Registry.LocalMachine.OpenSubKey( + @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", true)) + { + if (parent == null) + { + MessageBox.Show("Uninstall registry key not found."); + return; + } + try + { + RegistryKey key = null; + + try + { + const string guidText = "{4E76DB4E-1BB9-4A7B-860C-7940779CF7A0}"; + key = parent.OpenSubKey(guidText, true) ?? + parent.CreateSubKey(guidText); + + if (key == null) + { + MessageBox.Show(String.Format("Unable to create uninstaller entry'{0}\\{1}'", @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", guidText)); + return; + } + + key.SetValue("DisplayName", FriendlyName); + key.SetValue("ApplicationVersion", ActualVersion); + key.SetValue("Publisher", "Media Browser Team"); + key.SetValue("DisplayIcon", targetExe); + key.SetValue("DisplayVersion", ActualVersion.ToString(2)); + key.SetValue("URLInfoAbout", "http://www.mediabrowser3.com"); + key.SetValue("Contact", "http://community.mediabrowser.tv"); + key.SetValue("InstallDate", DateTime.Now.ToString("yyyyMMdd")); + key.SetValue("UninstallString", uninstallPath); + } + finally + { + if (key != null) + { + key.Close(); + } + } + } + catch (Exception ex) + { + MessageBox.Show("An error occurred writing uninstall information to the registry."); + } + } + } + /// /// Prepare a temporary location to download to /// diff --git a/MediaBrowser.Uninstaller.Execute/MainWindow.xaml.cs b/MediaBrowser.Uninstaller.Execute/MainWindow.xaml.cs index 4e2e80787..7b1983d53 100644 --- a/MediaBrowser.Uninstaller.Execute/MainWindow.xaml.cs +++ b/MediaBrowser.Uninstaller.Execute/MainWindow.xaml.cs @@ -1,7 +1,7 @@ using System; using System.Diagnostics; using System.Net; -using System.Reflection; +using Microsoft.Win32; using System.IO; using System.Threading; using System.Windows; @@ -195,13 +195,43 @@ namespace MediaBrowser.Uninstaller.Execute } } + // Remove reference to us + RemoveUninstall(); + // and done lblHeading.Content = string.Format("Media Browser {0} Uninstalled.", Product); btnUninstall.Visibility = Visibility.Hidden; btnFinished.Visibility = Visibility.Visible; } - private static void RemoveShortcut(string path) + private void RemoveUninstall() + { + + using (var parent = Registry.LocalMachine.OpenSubKey( + @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", true)) + { + if (parent == null) + { + MessageBox.Show("Uninstall registry key not found."); + return; + } + try + { + const string guidText = "{4E76DB4E-1BB9-4A7B-860C-7940779CF7A0}"; + parent.DeleteSubKey(guidText,false); + + } + catch (Exception ex) + { + throw new Exception( + "An error occurred removing uninstall information from the registry.", + ex); + } + } + } + + private static + void RemoveShortcut(string path) { try { diff --git a/MediaBrowser.Uninstaller/MediaBrowser.Uninstaller.csproj b/MediaBrowser.Uninstaller/MediaBrowser.Uninstaller.csproj index 3291ebdb1..cdfec10d1 100644 --- a/MediaBrowser.Uninstaller/MediaBrowser.Uninstaller.csproj +++ b/MediaBrowser.Uninstaller/MediaBrowser.Uninstaller.csproj @@ -34,6 +34,11 @@ + + + + + From f8261ebdb5be9ff6c69ee88a0303f4d09846b307 Mon Sep 17 00:00:00 2001 From: Eric Reed Date: Mon, 11 Mar 2013 12:45:40 -0400 Subject: [PATCH 3/3] Publish new installers --- MediaBrowser.Installer/MediaBrowser.Installer.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MediaBrowser.Installer/MediaBrowser.Installer.csproj b/MediaBrowser.Installer/MediaBrowser.Installer.csproj index 470a18463..819b17c50 100644 --- a/MediaBrowser.Installer/MediaBrowser.Installer.csproj +++ b/MediaBrowser.Installer/MediaBrowser.Installer.csproj @@ -31,7 +31,7 @@ Media Browser Team Media Browser false - 36 + 38 0.1.1.%2a false true