From 844121acc96f0280d9f527175e56e77b4dac8d71 Mon Sep 17 00:00:00 2001 From: Eric Reed Date: Mon, 25 Feb 2013 20:11:51 -0500 Subject: [PATCH] More uninstaller/installer incrementals Gonna need separate installers for server and mbt due to CO limitations --- .../Code/ModelExtensions.cs | 23 ++++ MediaBrowser.Installer/MainWindow.xaml.cs | 34 +++-- .../MediaBrowser.Installer.csproj | 11 +- .../Properties/app.manifest | 52 ++++++++ .../MediaBrowser.ServerApplication.csproj | 1 + MediaBrowser.Uninstaller.Execute/App.config | 6 + MediaBrowser.Uninstaller.Execute/App.xaml | 8 ++ MediaBrowser.Uninstaller.Execute/App.xaml.cs | 17 +++ .../MainWindow.xaml | 16 +++ .../MainWindow.xaml.cs | 82 ++++++++++++ .../MediaBrowser.Uninstaller.Execute.csproj | 110 ++++++++++++++++ .../Properties/AssemblyInfo.cs | 55 ++++++++ .../Properties/Resources.Designer.cs | 63 ++++++++++ .../Properties/Resources.resx | 117 ++++++++++++++++++ .../Properties/Settings.Designer.cs | 26 ++++ .../Properties/Settings.settings | 7 ++ MediaBrowser.Uninstaller/MainWindow.xaml | 12 +- MediaBrowser.Uninstaller/MainWindow.xaml.cs | 77 +++--------- .../MediaBrowser.Uninstaller.csproj | 8 +- .../Properties/AssemblyInfo.cs | 4 +- MediaBrowser.sln | 48 ++++--- 21 files changed, 671 insertions(+), 106 deletions(-) create mode 100644 MediaBrowser.Installer/Properties/app.manifest create mode 100644 MediaBrowser.Uninstaller.Execute/App.config create mode 100644 MediaBrowser.Uninstaller.Execute/App.xaml create mode 100644 MediaBrowser.Uninstaller.Execute/App.xaml.cs create mode 100644 MediaBrowser.Uninstaller.Execute/MainWindow.xaml create mode 100644 MediaBrowser.Uninstaller.Execute/MainWindow.xaml.cs create mode 100644 MediaBrowser.Uninstaller.Execute/MediaBrowser.Uninstaller.Execute.csproj create mode 100644 MediaBrowser.Uninstaller.Execute/Properties/AssemblyInfo.cs create mode 100644 MediaBrowser.Uninstaller.Execute/Properties/Resources.Designer.cs create mode 100644 MediaBrowser.Uninstaller.Execute/Properties/Resources.resx create mode 100644 MediaBrowser.Uninstaller.Execute/Properties/Settings.Designer.cs create mode 100644 MediaBrowser.Uninstaller.Execute/Properties/Settings.settings diff --git a/MediaBrowser.Installer/Code/ModelExtensions.cs b/MediaBrowser.Installer/Code/ModelExtensions.cs index 5a3051164c..66e51ec117 100644 --- a/MediaBrowser.Installer/Code/ModelExtensions.cs +++ b/MediaBrowser.Installer/Code/ModelExtensions.cs @@ -1,4 +1,6 @@  +using System.Collections.Generic; + namespace MediaBrowser.Installer.Code { /// @@ -16,5 +18,26 @@ namespace MediaBrowser.Installer.Code { return string.IsNullOrEmpty(str) ? def : str; } + + /// + /// Helper method for Dictionaries since they throw on not-found keys + /// + /// + /// + /// The dictionary. + /// The key. + /// The default value. + /// ``1. + public static U GetValueOrDefault(this Dictionary dictionary, T key, U defaultValue) + { + U val; + if (!dictionary.TryGetValue(key, out val)) + { + val = defaultValue; + } + return val; + + } + } } diff --git a/MediaBrowser.Installer/MainWindow.xaml.cs b/MediaBrowser.Installer/MainWindow.xaml.cs index 8924ddb5d3..efa2c71774 100644 --- a/MediaBrowser.Installer/MainWindow.xaml.cs +++ b/MediaBrowser.Installer/MainWindow.xaml.cs @@ -5,7 +5,6 @@ using System.IO; using System.Net; using System.Threading.Tasks; using System.Windows; -using System.Web; using System.Linq; using Ionic.Zip; using MediaBrowser.Installer.Code; @@ -65,20 +64,29 @@ namespace MediaBrowser.Installer protected void GetArgs() { - var args = AppDomain.CurrentDomain.SetupInformation.ActivationArguments; + var args = Environment.GetCommandLineArgs(); - if (args == null || args.ActivationData == null || args.ActivationData.Length <= 0) return; - var url = new Uri(args.ActivationData[0], UriKind.Absolute); - var parameters = HttpUtility.ParseQueryString(url.Query); + var parameters = new Dictionary(StringComparer.OrdinalIgnoreCase); + foreach (var arg in args) + { + var nameValue = arg.Split('='); + try + { + parameters[nameValue[0]] = nameValue[1]; + } + catch // let it default below + { + } + } // fill in our arguments if there - PackageName = parameters["package"] ?? "MBServer"; - PackageClass = (PackageVersionClass)Enum.Parse(typeof(PackageVersionClass), parameters["class"] ?? "Release"); - PackageVersion = new Version(parameters["version"].ValueOrDefault("10.0.0.0")); - RootSuffix = parameters["suffix"] ?? "-Server"; - TargetExe = parameters["target"] ?? "MediaBrowser.ServerApplication.exe"; - FriendlyName = parameters["name"] ?? PackageName; + PackageName = parameters.GetValueOrDefault("package","MBServer"); + PackageClass = (PackageVersionClass)Enum.Parse(typeof(PackageVersionClass), parameters.GetValueOrDefault("class","Release")); + PackageVersion = new Version(parameters.GetValueOrDefault("version","10.0.0.0")); + RootSuffix = parameters.GetValueOrDefault("suffix", "-Server"); + TargetExe = parameters.GetValueOrDefault("target", "MediaBrowser.ServerApplication.exe"); + FriendlyName = parameters.GetValueOrDefault("name", PackageName); RootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MediaBrowser" + RootSuffix); } @@ -210,7 +218,8 @@ namespace MediaBrowser.Installer product.Save(); var uninstall = (IWshShortcut)shell.CreateShortcut(Path.Combine(startMenu, "Uninstall " + FriendlyName + ".lnk")); - uninstall.TargetPath = Path.Combine(Path.GetDirectoryName(targetExe),"MediaBrowser.Uninstall.exe "+(PackageName == "MBServer" ? "server" : "mbt")); + uninstall.TargetPath = Path.Combine(Path.GetDirectoryName(targetExe),"MediaBrowser.Uninstaller.exe"); + uninstall.Arguments = (PackageName == "MBServer" ? "server" : "mbt"); uninstall.Description = "Uninstall " + FriendlyName; uninstall.Save(); @@ -238,5 +247,6 @@ namespace MediaBrowser.Installer Directory.Delete(location, true); } } + } } diff --git a/MediaBrowser.Installer/MediaBrowser.Installer.csproj b/MediaBrowser.Installer/MediaBrowser.Installer.csproj index 036340be7e..ff6537b21f 100644 --- a/MediaBrowser.Installer/MediaBrowser.Installer.csproj +++ b/MediaBrowser.Installer/MediaBrowser.Installer.csproj @@ -29,7 +29,7 @@ Media Browser Team Media Browser true - 8 + 10 0.1.1.%2a false true @@ -61,11 +61,17 @@ MediaBrowser.Installer_1_TemporaryKey.pfx - true + false true + + LocalIntranet + + + Properties\app.manifest + ..\packages\DotNetZip.1.9.1.8\lib\net20\Ionic.Zip.dll @@ -140,6 +146,7 @@ Resources.Designer.cs + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/MediaBrowser.Installer/Properties/app.manifest b/MediaBrowser.Installer/Properties/app.manifest new file mode 100644 index 0000000000..f499e6ab6d --- /dev/null +++ b/MediaBrowser.Installer/Properties/app.manifest @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj index c843242c32..3ed16f825d 100644 --- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj +++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj @@ -386,6 +386,7 @@ if $(ConfigurationName) == Release ( mkdir "$(SolutionDir)..\Deploy\Server\System" xcopy "$(TargetDir)$(TargetFileName)" "$(SolutionDir)..\Deploy\Server\System\" /y xcopy "$(SolutionDir)Mediabrowser.Uninstaller\bin\Release\MediaBrowser.Uninstaller.exe" "$(SolutionDir)..\Deploy\Server\System\" /y +xcopy "$(SolutionDir)Mediabrowser.Uninstaller.Execute\bin\Release\MediaBrowser.Uninstaller.Execute.exe" "$(SolutionDir)..\Deploy\Server\System\" /y xcopy "$(TargetDir)$(TargetFileName).config" "$(SolutionDir)..\Deploy\Server\System\" /y diff --git a/MediaBrowser.Uninstaller.Execute/App.config b/MediaBrowser.Uninstaller.Execute/App.config new file mode 100644 index 0000000000..8e15646352 --- /dev/null +++ b/MediaBrowser.Uninstaller.Execute/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MediaBrowser.Uninstaller.Execute/App.xaml b/MediaBrowser.Uninstaller.Execute/App.xaml new file mode 100644 index 0000000000..8d0735d423 --- /dev/null +++ b/MediaBrowser.Uninstaller.Execute/App.xaml @@ -0,0 +1,8 @@ + + + + + diff --git a/MediaBrowser.Uninstaller.Execute/App.xaml.cs b/MediaBrowser.Uninstaller.Execute/App.xaml.cs new file mode 100644 index 0000000000..b38e27e1a9 --- /dev/null +++ b/MediaBrowser.Uninstaller.Execute/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace MediaBrowser.Uninstaller +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/MediaBrowser.Uninstaller.Execute/MainWindow.xaml b/MediaBrowser.Uninstaller.Execute/MainWindow.xaml new file mode 100644 index 0000000000..d2a093ec42 --- /dev/null +++ b/MediaBrowser.Uninstaller.Execute/MainWindow.xaml @@ -0,0 +1,16 @@ + + + + public partial class MainWindow : Window { - protected string Product = "Server"; - public MainWindow() { - InitializeComponent(); + //All our work is behind the scenes var args = Environment.GetCommandLineArgs(); var product = args.Length > 1 ? args[1] : "server"; - - switch (product) + //copy the real program to a temp location so we can delete everything here (including us) + var tempExe = Path.Combine(Path.GetTempPath(), "MBUninstall.exe"); + using (var file = File.Create(tempExe, 4096, FileOptions.DeleteOnClose)) { - case "server": - Product = "Server"; - break; - - case "mbt": - Product = "Theater"; - break; - - default: - Console.WriteLine("Please specify which application to un-install (server or mbt)"); - Close(); - break; - + //copy the real uninstaller to temp location + File.WriteAllBytes(tempExe, File.ReadAllBytes(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) ?? "","MediaBrowser.Uninstaller.Execute.exe"))); + //kick off the copy + Process.Start(tempExe, product); + //wait for it to start up + Thread.Sleep(500); + //and shut down + Close(); } - - lblHeading.Content = this.Title = "Uninstall Media Browser " + Product; - - } - - private void btnCancel_Click(object sender, RoutedEventArgs e) - { - Close(); - } - - private void cbxRemoveAll_Checked(object sender, RoutedEventArgs e) - { - if (cbxRemoveAll.IsChecked == true) - { - cbxRemoveCache.IsChecked = cbxRemoveConfig.IsChecked = cbxRemovePlugins.IsChecked = true; - } - - cbxRemoveCache.IsEnabled = cbxRemoveConfig.IsEnabled = cbxRemovePlugins.IsEnabled = !cbxRemoveAll.IsChecked.Value; - } - - private void btnUninstall_Click(object sender, RoutedEventArgs e) - { - // First remove our shortcuts - var startMenu = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Media Browser"); - var linkName = "Media Browser " + Product + ".lnk"; - try - { - File.Delete(Path.Combine(startMenu,linkName)); - } - catch {} // oh well - - linkName = "Uninstall " + linkName; - try - { - File.Delete(Path.Combine(startMenu,linkName)); - } - catch {} // oh well - + + //InitializeComponent(); } } } diff --git a/MediaBrowser.Uninstaller/MediaBrowser.Uninstaller.csproj b/MediaBrowser.Uninstaller/MediaBrowser.Uninstaller.csproj index a9db3ee9b0..c9c3e537cd 100644 --- a/MediaBrowser.Uninstaller/MediaBrowser.Uninstaller.csproj +++ b/MediaBrowser.Uninstaller/MediaBrowser.Uninstaller.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - {FACAF749-3E28-46DD-B613-654FCD434959} + {21EC6FB8-F444-4B60-8BA5-9CA443901A0D} WinExe Properties MediaBrowser.Uninstaller @@ -93,12 +93,6 @@ - - - - Code\Images\mb3logo800.png - -