diff --git a/MediaBrowser.Installer/App.config b/MediaBrowser.Installer/App.config index 8e15646352..eb69b68d0d 100644 --- a/MediaBrowser.Installer/App.config +++ b/MediaBrowser.Installer/App.config @@ -1,5 +1,9 @@  + + + + 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/Icon.ico b/MediaBrowser.Installer/Icon.ico new file mode 100644 index 0000000000..4acd8f9219 Binary files /dev/null and b/MediaBrowser.Installer/Icon.ico differ diff --git a/MediaBrowser.Installer/MainWindow.xaml.cs b/MediaBrowser.Installer/MainWindow.xaml.cs index 8924ddb5d3..01e15dfd8c 100644 --- a/MediaBrowser.Installer/MainWindow.xaml.cs +++ b/MediaBrowser.Installer/MainWindow.xaml.cs @@ -1,11 +1,11 @@ using System; using System.Collections.Generic; +using System.Configuration; using System.Diagnostics; 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; @@ -20,7 +20,7 @@ namespace MediaBrowser.Installer public partial class MainWindow : Window { protected PackageVersionClass PackageClass = PackageVersionClass.Release; - protected Version PackageVersion = new Version(10,0,0,0); + protected Version PackageVersion = new Version(4,0,0,0); protected string PackageName = "MBServer"; protected string RootSuffix = "-Server"; protected string TargetExe = "MediaBrowser.ServerApplication.exe"; @@ -65,20 +65,26 @@ namespace MediaBrowser.Installer protected void GetArgs() { - var args = AppDomain.CurrentDomain.SetupInformation.ActivationArguments; + var product = ConfigurationManager.AppSettings["product"] ?? "server"; + PackageClass = (PackageVersionClass) Enum.Parse(typeof (PackageVersionClass), ConfigurationManager.AppSettings["class"] ?? "Release"); - if (args == null || args.ActivationData == null || args.ActivationData.Length <= 0) return; - var url = new Uri(args.ActivationData[0], UriKind.Absolute); + switch (product.ToLower()) + { + case "mbt": + PackageName = "MBTheater"; + RootSuffix = "-UI"; + TargetExe = "MediaBrowser.UI.exe"; + FriendlyName = "Media Browser Theater"; + break; - var parameters = HttpUtility.ParseQueryString(url.Query); + default: + PackageName = "MBServer"; + RootSuffix = "-Server"; + TargetExe = "MediaBrowser.ServerApplication.exe"; + FriendlyName = "Media Browser Server"; + break; + } - // 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; RootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MediaBrowser" + RootSuffix); } @@ -89,13 +95,17 @@ namespace MediaBrowser.Installer /// protected async Task DoInstall() { - lblStatus.Content = "Downloading "+FriendlyName+"..."; + lblStatus.Content = string.Format("Downloading {0}...", FriendlyName); dlAnimation.StartAnimation(); prgProgress.Value = 0; prgProgress.Visibility = Visibility.Visible; + // Determine Package version + var version = await GetPackageVersion(); + lblStatus.Content = string.Format("Downloading {0} (version {1})...", FriendlyName, version.versionStr); + // Download - var archive = await DownloadPackage(); + var archive = await DownloadPackage(version); dlAnimation.StopAnimation(); prgProgress.Visibility = btnCancel.Visibility = Visibility.Hidden; @@ -135,18 +145,14 @@ namespace MediaBrowser.Installer } - /// - /// Download our specified package to an archive in a temp location - /// - /// The fully qualified name of the downloaded package - protected async Task DownloadPackage() + protected async Task GetPackageVersion() { using (var client = new WebClient()) { try { // get the package information for the server - var json = await client.DownloadStringTaskAsync("http://www.mb3admin.com/admin/service/package/retrieveAll?name="+PackageName); + var json = await client.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); @@ -155,6 +161,27 @@ namespace MediaBrowser.Installer SystemClose("Could not locate download package. Aborting."); return null; } + return version; + } + catch (Exception e) + { + SystemClose(e.GetType().FullName + "\n\n" + e.Message); + } + + } + return null; + } + + /// + /// Download our specified package to an archive in a temp location + /// + /// The fully qualified name of the downloaded package + protected async Task DownloadPackage(PackageVersionInfo version) + { + using (var client = new WebClient()) + { + try + { var archiveFile = Path.Combine(PrepareTempLocation(), version.targetFilename); // setup download progress and download the package @@ -210,7 +237,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 +266,6 @@ namespace MediaBrowser.Installer Directory.Delete(location, true); } } + } } diff --git a/MediaBrowser.Installer/MediaBrowser.Installer.csproj b/MediaBrowser.Installer/MediaBrowser.Installer.csproj index 036340be7e..30267e76ec 100644 --- a/MediaBrowser.Installer/MediaBrowser.Installer.csproj +++ b/MediaBrowser.Installer/MediaBrowser.Installer.csproj @@ -28,8 +28,8 @@ Media Browser Installer Media Browser Team Media Browser - true - 8 + false + 14 0.1.1.%2a false true @@ -66,6 +66,15 @@ true + + LocalIntranet + + + Properties\app.manifest + + + Icon.ico + ..\packages\DotNetZip.1.9.1.8\lib\net20\Ionic.Zip.dll @@ -74,6 +83,7 @@ ..\packages\ServiceStack.Text.3.9.37\lib\net35\ServiceStack.Text.dll + @@ -139,7 +149,9 @@ ResXFileCodeGenerator Resources.Designer.cs + + SettingsSingleFileGenerator Settings.Designer.cs @@ -189,6 +201,9 @@ True + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MediaBrowser.Installer/mbt.config b/MediaBrowser.Installer/mbt.config new file mode 100644 index 0000000000..b94d81797d --- /dev/null +++ b/MediaBrowser.Installer/mbt.config @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs b/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs index a5e5b39c44..ff29badff2 100644 --- a/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs +++ b/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs @@ -17,7 +17,7 @@ namespace MediaBrowser.Server.Implementations : base(true) { } -#elif (RELEASE) +#else public ServerApplicationPaths() : base(false) { diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj index 50cb0be6ca..3c82943bd8 100644 --- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj +++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj @@ -397,7 +397,10 @@ 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.config" "$(SolutionDir)..\Deploy\Server\System\" /y +xcopy "$(SolutionDir)Mediabrowser.Uninstaller.Execute\bin\Release\MediaBrowser.Uninstaller.Execute.exe.config" "$(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(), "MediaBrowser.Uninstaller.Execute.exe"); + var tempConfig = Path.Combine(Path.GetTempPath(), "MediaBrowser.Uninstaller.Execute.exe.config"); + 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 + var sourceDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) ?? ""; + File.WriteAllBytes(tempExe, File.ReadAllBytes(Path.Combine(sourceDir ,"MediaBrowser.Uninstaller.Execute.exe"))); + File.Copy(tempConfig, Path.Combine(sourceDir ,"MediaBrowser.Uninstaller.Execute.exe.config")); + //kick off the copy + MessageBox.Show("About to start " + tempExe); + 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 - -