From e3af1798566b7aa0b568d2db2f06a1af7a0b0ec3 Mon Sep 17 00:00:00 2001 From: Eric Reed Date: Wed, 13 Mar 2013 10:00:49 -0400 Subject: [PATCH] Consolidate uninstaller into one assembly and don't allow run directly --- MediaBrowser.Uninstaller.Execute/App.config | 6 - .../MediaBrowser.Uninstaller.Execute.csproj | 110 ------------------ .../Properties/AssemblyInfo.cs | 55 --------- .../App.xaml | 2 +- .../App.xaml.cs | 8 +- .../MainWindow.xaml | 0 .../MainWindow.xaml.cs | 82 ++++++++----- .../MediaBrowser.Uninstaller.csproj | 72 +++++++++--- MediaBrowser.Uninstaller/Program.cs | 36 ------ .../Properties/AssemblyInfo.cs | 27 ++++- .../Properties/Resources.Designer.cs | 4 +- .../Properties/Resources.resx | 0 .../Properties/Settings.Designer.cs | 2 +- .../Properties/Settings.settings | 0 MediaBrowser.sln | 18 +-- 15 files changed, 138 insertions(+), 284 deletions(-) delete mode 100644 MediaBrowser.Uninstaller.Execute/App.config delete mode 100644 MediaBrowser.Uninstaller.Execute/MediaBrowser.Uninstaller.Execute.csproj delete mode 100644 MediaBrowser.Uninstaller.Execute/Properties/AssemblyInfo.cs rename {MediaBrowser.Uninstaller.Execute => MediaBrowser.Uninstaller}/App.xaml (81%) rename {MediaBrowser.Uninstaller.Execute => MediaBrowser.Uninstaller}/App.xaml.cs (50%) rename {MediaBrowser.Uninstaller.Execute => MediaBrowser.Uninstaller}/MainWindow.xaml (100%) rename {MediaBrowser.Uninstaller.Execute => MediaBrowser.Uninstaller}/MainWindow.xaml.cs (80%) delete mode 100644 MediaBrowser.Uninstaller/Program.cs rename {MediaBrowser.Uninstaller.Execute => MediaBrowser.Uninstaller}/Properties/Resources.Designer.cs (95%) rename {MediaBrowser.Uninstaller.Execute => MediaBrowser.Uninstaller}/Properties/Resources.resx (100%) rename {MediaBrowser.Uninstaller.Execute => MediaBrowser.Uninstaller}/Properties/Settings.Designer.cs (94%) rename {MediaBrowser.Uninstaller.Execute => MediaBrowser.Uninstaller}/Properties/Settings.settings (100%) diff --git a/MediaBrowser.Uninstaller.Execute/App.config b/MediaBrowser.Uninstaller.Execute/App.config deleted file mode 100644 index 8e15646352..0000000000 --- a/MediaBrowser.Uninstaller.Execute/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/MediaBrowser.Uninstaller.Execute/MediaBrowser.Uninstaller.Execute.csproj b/MediaBrowser.Uninstaller.Execute/MediaBrowser.Uninstaller.Execute.csproj deleted file mode 100644 index 1e64363a0f..0000000000 --- a/MediaBrowser.Uninstaller.Execute/MediaBrowser.Uninstaller.Execute.csproj +++ /dev/null @@ -1,110 +0,0 @@ - - - - - Debug - AnyCPU - {FACAF749-3E28-46DD-B613-654FCD434959} - WinExe - Properties - MediaBrowser.Uninstaller.Execute - MediaBrowser.Uninstaller.Execute - v4.5 - 512 - {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 4 - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - 4.0 - - - - - - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - - - App.xaml - Code - - - MainWindow.xaml - Code - - - - - Code - - - True - True - Resources.resx - - - True - Settings.settings - True - - - ResXFileCodeGenerator - Resources.Designer.cs - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - - - - - - - - Code\Images\mb3logo800.png - - - - - \ No newline at end of file diff --git a/MediaBrowser.Uninstaller.Execute/Properties/AssemblyInfo.cs b/MediaBrowser.Uninstaller.Execute/Properties/AssemblyInfo.cs deleted file mode 100644 index 613589a7dc..0000000000 --- a/MediaBrowser.Uninstaller.Execute/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System.Reflection; -using System.Resources; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Windows; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("MediaBrowser.Uninstaller")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Media Browser Team")] -[assembly: AssemblyProduct("MediaBrowser.Uninstaller")] -[assembly: AssemblyCopyright("Copyright © Media Browser Team 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -//In order to begin building localizable applications, set -//CultureYouAreCodingWith in your .csproj file -//inside a . For example, if you are using US english -//in your source files, set the to en-US. Then uncomment -//the NeutralResourceLanguage attribute below. Update the "en-US" in -//the line below to match the UICulture setting in the project file. - -//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] - - -[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) -)] - - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MediaBrowser.Uninstaller.Execute/App.xaml b/MediaBrowser.Uninstaller/App.xaml similarity index 81% rename from MediaBrowser.Uninstaller.Execute/App.xaml rename to MediaBrowser.Uninstaller/App.xaml index 8d0735d423..59eab9383a 100644 --- a/MediaBrowser.Uninstaller.Execute/App.xaml +++ b/MediaBrowser.Uninstaller/App.xaml @@ -1,4 +1,4 @@ - diff --git a/MediaBrowser.Uninstaller.Execute/App.xaml.cs b/MediaBrowser.Uninstaller/App.xaml.cs similarity index 50% rename from MediaBrowser.Uninstaller.Execute/App.xaml.cs rename to MediaBrowser.Uninstaller/App.xaml.cs index b38e27e1a9..165eb4ff8a 100644 --- a/MediaBrowser.Uninstaller.Execute/App.xaml.cs +++ b/MediaBrowser.Uninstaller/App.xaml.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Linq; -using System.Threading.Tasks; -using System.Windows; +using System.Windows; namespace MediaBrowser.Uninstaller { diff --git a/MediaBrowser.Uninstaller.Execute/MainWindow.xaml b/MediaBrowser.Uninstaller/MainWindow.xaml similarity index 100% rename from MediaBrowser.Uninstaller.Execute/MainWindow.xaml rename to MediaBrowser.Uninstaller/MainWindow.xaml diff --git a/MediaBrowser.Uninstaller.Execute/MainWindow.xaml.cs b/MediaBrowser.Uninstaller/MainWindow.xaml.cs similarity index 80% rename from MediaBrowser.Uninstaller.Execute/MainWindow.xaml.cs rename to MediaBrowser.Uninstaller/MainWindow.xaml.cs index 5870a8ed58..c3a0133ee9 100644 --- a/MediaBrowser.Uninstaller.Execute/MainWindow.xaml.cs +++ b/MediaBrowser.Uninstaller/MainWindow.xaml.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Net; +using System.Reflection; using Microsoft.Win32; using System.IO; using System.Threading; @@ -20,49 +21,68 @@ namespace MediaBrowser.Uninstaller.Execute { var args = Environment.GetCommandLineArgs(); - var product = args.Length > 1 ? args[1] : "server"; - var callerId = args.Length > 2 ? args[2] : null; - if (callerId != null) + var product = args.Length > 1 ? args[1] : null; + if (product == null) { - // Wait for our caller to exit - try + MessageBox.Show("Please use 'Programs and Features' to uninstall."); + Close(); + } + else + { + var callerId = args.Length > 2 ? args[2] : null; + if (callerId != null) { - var process = Process.GetProcessById(Convert.ToInt32(callerId)); - process.WaitForExit(); + // Wait for our caller to exit + try + { + var process = Process.GetProcessById(Convert.ToInt32(callerId)); + process.WaitForExit(); + } + catch (ArgumentException) + { + // wasn't running + } } - catch (ArgumentException) + else { - // wasn't running + // No caller - means we were called directly and need to move to temp file and execute there + //copy the real program to a temp location so we can delete everything here (including us) + var us = Assembly.GetExecutingAssembly().Location; + var tempExe = Path.Combine(Path.GetTempPath(), Path.GetFileName(us) ?? "Mediabrowser.Uninstaller.exe"); + File.Copy(us,tempExe,true); + //get our pid to pass to the uninstaller so it can wait for us to exit + var pid = Process.GetCurrentProcess().Id; + //kick off the copy + Process.Start(tempExe, product + " " + pid); + //and shut down + Close(); } - } - else - { - Thread.Sleep(1000); // crude method - } - InitializeComponent(); + InitializeComponent(); - switch (product) - { - case "server": - Product = "Server"; - RootSuffix = "-Server"; - break; + switch (product) + { + case "server": + Product = "Server"; + RootSuffix = "-Server"; + break; - case "mbt": - Product = "Theater"; - RootSuffix = "-Theater"; - break; + case "mbt": + Product = "Theater"; + RootSuffix = "-Theater"; + break; - default: - MessageBox.Show("Please specify which application to un-install (server or mbt)"); - Close(); - break; + default: + MessageBox.Show("Please Use 'Programs and Features' to uninstall."); + Close(); + break; - } + } - lblHeading.Content = this.Title = "Uninstall Media Browser " + Product; + lblHeading.Content = this.Title = "Uninstall Media Browser " + Product; + + } } diff --git a/MediaBrowser.Uninstaller/MediaBrowser.Uninstaller.csproj b/MediaBrowser.Uninstaller/MediaBrowser.Uninstaller.csproj index cdfec10d1b..a9db3ee9b0 100644 --- a/MediaBrowser.Uninstaller/MediaBrowser.Uninstaller.csproj +++ b/MediaBrowser.Uninstaller/MediaBrowser.Uninstaller.csproj @@ -4,13 +4,15 @@ Debug AnyCPU - {8B930005-D5B2-4A78-9377-46AC6EDAB688} + {FACAF749-3E28-46DD-B613-654FCD434959} WinExe Properties MediaBrowser.Uninstaller MediaBrowser.Uninstaller v4.5 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 AnyCPU @@ -31,30 +33,72 @@ prompt 4 - - - - - - - - + + + - - - + + 4.0 + + + + - - + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + Code\Images\mb3logo800.png + +