diff options
| -rw-r--r-- | MediaBrowser.Common.Implementations/Updates/PackageManager.cs | 34 | ||||
| -rw-r--r-- | MediaBrowser.Common/Updates/IPackageManager.cs | 2 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Updates/InstallationManager.cs | 16 | ||||
| -rw-r--r-- | MediaBrowser.Installer/MainWindow.xaml | 54 | ||||
| -rw-r--r-- | MediaBrowser.Installer/MainWindow.xaml.cs | 50 | ||||
| -rw-r--r-- | MediaBrowser.Installer/MediaBrowser.Installer.csproj | 2 | ||||
| -rw-r--r-- | MediaBrowser.ServerApplication/ApplicationHost.cs | 2 |
7 files changed, 88 insertions, 72 deletions
diff --git a/MediaBrowser.Common.Implementations/Updates/PackageManager.cs b/MediaBrowser.Common.Implementations/Updates/PackageManager.cs index f53f503db..cef631e60 100644 --- a/MediaBrowser.Common.Implementations/Updates/PackageManager.cs +++ b/MediaBrowser.Common.Implementations/Updates/PackageManager.cs @@ -43,12 +43,12 @@ namespace MediaBrowser.Common.Implementations.Updates } - public async Task InstallPackage(IHttpClient client, ILogger logger, ResourcePool resourcePool, IProgress<double> progress, IZipClient zipClient, IApplicationPaths appPaths, PackageVersionInfo package, CancellationToken cancellationToken) + public async Task InstallPackage(IHttpClient client, ILogger logger, ResourcePool resourcePool, IProgress<double> progress, IApplicationPaths appPaths, PackageVersionInfo package, CancellationToken cancellationToken) { // Target based on if it is an archive or single assembly // zip archives are assumed to contain directory structures relative to our ProgramDataPath var isArchive = string.Equals(Path.GetExtension(package.targetFilename), ".zip", StringComparison.OrdinalIgnoreCase); - var target = isArchive ? appPaths.TempUpdatePath : Path.Combine(appPaths.PluginsPath, package.targetFilename); + var target = Path.Combine(isArchive ? appPaths.TempUpdatePath : appPaths.PluginsPath, package.targetFilename); // Download to temporary file so that, if interrupted, it won't destroy the existing installation var tempFile = await client.GetTempFile(package.sourceUrl, resourcePool.Mb, cancellationToken, progress).ConfigureAwait(false); @@ -71,32 +71,16 @@ namespace MediaBrowser.Common.Implementations.Updates cancellationToken.ThrowIfCancellationRequested(); - // Success - move it to the real target based on type - if (isArchive) + // Success - move it to the real target + try { - try - { - zipClient.ExtractAll(tempFile, target, true); - } - catch (IOException e) - { - logger.ErrorException("Error attempting to extract archive from {0} to {1}", e, tempFile, target); - throw; - } - + File.Copy(tempFile, target, true); + File.Delete(tempFile); } - else + catch (IOException e) { - try - { - File.Copy(tempFile, target, true); - File.Delete(tempFile); - } - catch (IOException e) - { - logger.ErrorException("Error attempting to move file from {0} to {1}", e, tempFile, target); - throw; - } + logger.ErrorException("Error attempting to move file from {0} to {1}", e, tempFile, target); + throw; } } diff --git a/MediaBrowser.Common/Updates/IPackageManager.cs b/MediaBrowser.Common/Updates/IPackageManager.cs index f3ca1d8cf..1db5ea706 100644 --- a/MediaBrowser.Common/Updates/IPackageManager.cs +++ b/MediaBrowser.Common/Updates/IPackageManager.cs @@ -40,7 +40,6 @@ namespace MediaBrowser.Common.Updates /// <param name="logger"></param> /// <param name="resourcePool"></param> /// <param name="progress"></param> - /// <param name="zipClient"></param> /// <param name="appPaths"></param> /// <param name="package">The package.</param> /// <param name="cancellationToken">The cancellation token.</param> @@ -49,7 +48,6 @@ namespace MediaBrowser.Common.Updates ILogger logger, ResourcePool resourcePool, IProgress<double> progress, - IZipClient zipClient, IApplicationPaths appPaths, PackageVersionInfo package, CancellationToken cancellationToken); diff --git a/MediaBrowser.Controller/Updates/InstallationManager.cs b/MediaBrowser.Controller/Updates/InstallationManager.cs index f248c6d44..d616e8898 100644 --- a/MediaBrowser.Controller/Updates/InstallationManager.cs +++ b/MediaBrowser.Controller/Updates/InstallationManager.cs @@ -94,12 +94,6 @@ namespace MediaBrowser.Controller.Updates #endregion /// <summary> - /// Gets or sets the zip client. - /// </summary> - /// <value>The zip client.</value> - private IZipClient ZipClient { get; set; } - - /// <summary> /// The _logger /// </summary> private readonly ILogger _logger; @@ -137,20 +131,15 @@ namespace MediaBrowser.Controller.Updates /// </summary> /// <param name="kernel">The kernel.</param> /// <param name="httpClient">The HTTP client.</param> - /// <param name="zipClient">The zip client.</param> /// <param name="networkManager">The network manager.</param> /// <param name="packageManager">The package manager.</param> /// <param name="jsonSerializer">The json serializer.</param> /// <param name="logger">The logger.</param> /// <param name="appHost">The app host.</param> /// <exception cref="System.ArgumentNullException">zipClient</exception> - public InstallationManager(Kernel kernel, IHttpClient httpClient, IZipClient zipClient, INetworkManager networkManager, IPackageManager packageManager, IJsonSerializer jsonSerializer, ILogger logger, IApplicationHost appHost) + public InstallationManager(Kernel kernel, IHttpClient httpClient, INetworkManager networkManager, IPackageManager packageManager, IJsonSerializer jsonSerializer, ILogger logger, IApplicationHost appHost) : base(kernel) { - if (zipClient == null) - { - throw new ArgumentNullException("zipClient"); - } if (networkManager == null) { throw new ArgumentNullException("networkManager"); @@ -180,7 +169,6 @@ namespace MediaBrowser.Controller.Updates _networkManager = networkManager; _packageManager = packageManager; _logger = logger; - ZipClient = zipClient; } /// <summary> @@ -430,7 +418,7 @@ namespace MediaBrowser.Controller.Updates private async Task InstallPackageInternal(PackageVersionInfo package, IProgress<double> progress, CancellationToken cancellationToken) { // Do the install - await _packageManager.InstallPackage(HttpClient, _logger, Kernel.ResourcePools, progress, ZipClient, Kernel.ApplicationPaths, package, cancellationToken).ConfigureAwait(false); + await _packageManager.InstallPackage(HttpClient, _logger, Kernel.ResourcePools, progress, Kernel.ApplicationPaths, package, cancellationToken).ConfigureAwait(false); // Do plugin-specific processing if (!(Path.GetExtension(package.targetFilename) ?? "").Equals(".zip", StringComparison.OrdinalIgnoreCase)) diff --git a/MediaBrowser.Installer/MainWindow.xaml b/MediaBrowser.Installer/MainWindow.xaml index 3e040d3e0..06727dfae 100644 --- a/MediaBrowser.Installer/MainWindow.xaml +++ b/MediaBrowser.Installer/MainWindow.xaml @@ -3,14 +3,56 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Code="clr-namespace:MediaBrowser.Installer.Code" x:Class="MediaBrowser.Installer.MainWindow" Title="Install Media Browser Server" Height="383.481" Width="663.057" ResizeMode="NoResize" WindowStyle="None"> - <Border BorderBrush="DarkGray" BorderThickness="2"> - <Grid Margin="0,0,0,2"> + <Border BorderBrush="DarkGray" BorderThickness="2" Margin="0,0,0,0"> + <Grid Margin="-2,0,0,0"> <Image x:Name="imgLogo" HorizontalAlignment="Center" Height="172" Margin="10,10,57,0" VerticalAlignment="Top" Width="590" Source="Code/Images/mb3logo800.png" Opacity="0.5"/> - <ProgressBar x:Name="prgProgress" HorizontalAlignment="Left" Height="11" Margin="52,320,0,0" VerticalAlignment="Top" Width="460"/> - <Code:DownloadAnimation x:Name="dlAnimation" HorizontalAlignment="Left" Margin="26,97,0,0" VerticalAlignment="Top" Height="196" Width="574" RenderTransformOrigin="0.5,0.5"/> - <Button x:Name="btnCancel" Content="Cancel" HorizontalAlignment="Left" Margin="547,309,0,0" VerticalAlignment="Top" Width="79" FontSize="14" Click="btnCancel_Click"/> - <Label x:Name="lblStatus" Content="Status" HorizontalAlignment="Left" Margin="52,264,0,0" VerticalAlignment="Top" Width="574" FontSize="14" FontWeight="Bold"/> + <Grid HorizontalAlignment="Left" Height="153" Margin="0,173,0,0" VerticalAlignment="Top" Width="662" Background="Gray"> + <TextBlock x:Name="lblStatus" HorizontalAlignment="Left" Margin="12,14,0,18" Width="637" FontSize="36" Foreground="#FFE6D7D7" Text="Status" TextWrapping="WrapWithOverflow"/> + <Rectangle Fill="#FF49494B" HorizontalAlignment="Left" Height="13" Stroke="Black" VerticalAlignment="Bottom" Width="662"/> + <Rectangle x:Name="rectProgress" Fill="#FF0A0ABF" HorizontalAlignment="Left" Height="13" Stroke="Black" VerticalAlignment="Bottom" Width="0"/> + </Grid> + <Button x:Name="btnCancel" Content="Cancel" HorizontalAlignment="Left" Margin="552,336,0,0" Width="97" FontSize="14" Click="btnCancel_Click" Height="31" VerticalAlignment="Top"/> </Grid> </Border> + <Window.Resources> + <!--Metro Button--> + <Style TargetType="{x:Type Button}" BasedOn="{x:Null}"> + <Setter Property="Background" Value="Transparent"/> + <Setter Property="Foreground" Value="#222222"/> + <Setter Property="FontSize" Value="16"/> + <Setter Property="Padding" Value="10,5,10,5"/> + <Setter Property="BorderBrush" Value="#222222"/> + <Setter Property="BorderThickness" Value="2"/> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type Button}"> + <!-- We use Grid as a root because it is easy to add more elements to customize the button --> + <Grid x:Name="Grid"> + <Border x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"/> + + <!-- Content Presenter is where the text content etc is placed by the control --> + <!-- The bindings are useful so that the control can be parameterized without editing the template --> + <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RecognizesAccessKey="True"/> + </Grid> + + <!--Each state sets a brush on the Border in the template --> + <ControlTemplate.Triggers> + <Trigger Property="IsPressed" Value="true"> + <Setter Property="Background" Value="#222222" TargetName="Border"/> + <Setter Property="BorderBrush" Value="#222222" TargetName="Border"/> + <Setter Property="Foreground" Value="White"/> + <Setter Property="FontSize" Value="16"/> + </Trigger> + <Trigger Property="IsEnabled" Value="true"/> + <Trigger Property="IsEnabled" Value="false"> + <Setter Property="BorderBrush" Value="#7f222222" TargetName="Border"/> + <Setter Property="Foreground" Value="#7f222222"/> + </Trigger> + </ControlTemplate.Triggers> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + </Window.Resources> </Window> diff --git a/MediaBrowser.Installer/MainWindow.xaml.cs b/MediaBrowser.Installer/MainWindow.xaml.cs index 63e1f5dbd..1ead1fced 100644 --- a/MediaBrowser.Installer/MainWindow.xaml.cs +++ b/MediaBrowser.Installer/MainWindow.xaml.cs @@ -24,6 +24,7 @@ namespace MediaBrowser.Installer protected string RootSuffix = "-Server"; protected string TargetExe = "MediaBrowser.ServerApplication.exe"; protected string FriendlyName = "Media Browser Server"; + protected string Archive = null; protected string RootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MediaBrowser-Server"); protected bool SystemClosing = false; @@ -36,7 +37,7 @@ namespace MediaBrowser.Installer { GetArgs(); InitializeComponent(); - DoInstall(); + DoInstall(Archive); } private void btnCancel_Click(object sender, RoutedEventArgs e) @@ -77,6 +78,8 @@ namespace MediaBrowser.Installer { var product = ConfigurationManager.AppSettings["product"] ?? "server"; PackageClass = (PackageVersionClass) Enum.Parse(typeof (PackageVersionClass), ConfigurationManager.AppSettings["class"] ?? "Release"); + var cmdArgs = Environment.GetCommandLineArgs(); + Archive = cmdArgs.Length > 1 ? cmdArgs[1] : null; switch (product.ToLower()) { @@ -103,12 +106,9 @@ namespace MediaBrowser.Installer /// Execute the install process /// </summary> /// <returns></returns> - protected async Task DoInstall() + protected async Task DoInstall(string archive) { - lblStatus.Content = string.Format("Downloading {0}...", FriendlyName); - dlAnimation.StartAnimation(); - prgProgress.Value = 0; - prgProgress.Visibility = Visibility.Visible; + lblStatus.Text = string.Format("Downloading {0}...", FriendlyName); // Determine Package version var version = await GetPackageVersion(); @@ -116,7 +116,7 @@ namespace MediaBrowser.Installer // Now try and shut down the server if that is what we are installing and it is running if (PackageName == "MBServer" && Process.GetProcessesByName("mediabrowser.serverapplication").Length != 0) { - lblStatus.Content = "Shutting Down Media Browser Server..."; + lblStatus.Text = "Shutting Down Media Browser Server..."; using (var client = new WebClient()) { try @@ -139,7 +139,7 @@ namespace MediaBrowser.Installer var processes = Process.GetProcessesByName("mediabrowser.ui"); if (processes.Length > 0) { - lblStatus.Content = "Shutting Down Media Browser Theater..."; + lblStatus.Text = "Shutting Down Media Browser Theater..."; try { processes[0].Kill(); @@ -153,25 +153,24 @@ namespace MediaBrowser.Installer } } - // Download - string archive = null; - lblStatus.Content = string.Format("Downloading {0} (version {1})...", FriendlyName, version.versionStr); - try - { - archive = await DownloadPackage(version); - } - catch (Exception e) + // Download if we don't already have it + if (archive == null) { - SystemClose("Error Downloading Package - " + e.GetType().FullName + "\n\n" + e.Message); + lblStatus.Text = string.Format("Downloading {0} (version {1})...", FriendlyName, version.versionStr); + try + { + archive = await DownloadPackage(version); + } + catch (Exception e) + { + SystemClose("Error Downloading Package - " + e.GetType().FullName + "\n\n" + e.Message); + } } - dlAnimation.StopAnimation(); - prgProgress.Visibility = btnCancel.Visibility = Visibility.Hidden; - if (archive == null) return; //we canceled or had an error that was already reported // Extract - lblStatus.Content = "Extracting Package..."; + lblStatus.Text = "Extracting Package..."; try { ExtractPackage(archive); @@ -267,7 +266,7 @@ namespace MediaBrowser.Installer void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { - prgProgress.Value = e.ProgressPercentage; + rectProgress.Width = (this.Width * e.ProgressPercentage)/100f; } /// <summary> @@ -277,7 +276,12 @@ namespace MediaBrowser.Installer /// <param name="archive"></param> protected void ExtractPackage(string archive) { - using (var fileStream = System.IO.File.OpenRead(archive)) + // Delete old content of system + var systemDir = Path.Combine(RootPath, "system"); + if (Directory.Exists(systemDir)) Directory.Delete(systemDir, true); + + // And extract + using (var fileStream = File.OpenRead(archive)) { using (var zipFile = ZipFile.Read(fileStream)) { diff --git a/MediaBrowser.Installer/MediaBrowser.Installer.csproj b/MediaBrowser.Installer/MediaBrowser.Installer.csproj index 4149a8ab1..3a7d9102e 100644 --- a/MediaBrowser.Installer/MediaBrowser.Installer.csproj +++ b/MediaBrowser.Installer/MediaBrowser.Installer.csproj @@ -29,7 +29,7 @@ <PublisherName>Media Browser Team</PublisherName> <SuiteName>Media Browser</SuiteName> <OpenBrowserOnPublish>false</OpenBrowserOnPublish> - <ApplicationRevision>28</ApplicationRevision> + <ApplicationRevision>32</ApplicationRevision> <ApplicationVersion>0.1.1.%2a</ApplicationVersion> <UseApplicationTrust>false</UseApplicationTrust> <PublishWizardCompleted>true</PublishWizardCompleted> diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 903443483..654fce42e 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -196,7 +196,7 @@ namespace MediaBrowser.ServerApplication public Task UpdateApplication(PackageVersionInfo package, CancellationToken cancellationToken, IProgress<double> progress) { var pkgManager = Resolve<IPackageManager>(); - return pkgManager.InstallPackage(Resolve<IHttpClient>(), Resolve<ILogger>(), Kernel.ResourcePools, progress, Resolve<IZipClient>(), Kernel.ApplicationPaths, package, cancellationToken); + return pkgManager.InstallPackage(Resolve<IHttpClient>(), Resolve<ILogger>(), Kernel.ResourcePools, progress, Kernel.ApplicationPaths, package, cancellationToken); } /// <summary> |
