diff --git a/MediaBrowser.Common.Implementations/Updates/PackageManager.cs b/MediaBrowser.Common.Implementations/Updates/PackageManager.cs index f53f503db2..cef631e607 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 progress, IZipClient zipClient, IApplicationPaths appPaths, PackageVersionInfo package, CancellationToken cancellationToken) + public async Task InstallPackage(IHttpClient client, ILogger logger, ResourcePool resourcePool, IProgress 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 f3ca1d8cf2..1db5ea7066 100644 --- a/MediaBrowser.Common/Updates/IPackageManager.cs +++ b/MediaBrowser.Common/Updates/IPackageManager.cs @@ -40,7 +40,6 @@ namespace MediaBrowser.Common.Updates /// /// /// - /// /// /// The package. /// The cancellation token. @@ -49,7 +48,6 @@ namespace MediaBrowser.Common.Updates ILogger logger, ResourcePool resourcePool, IProgress progress, - IZipClient zipClient, IApplicationPaths appPaths, PackageVersionInfo package, CancellationToken cancellationToken); diff --git a/MediaBrowser.Controller/Updates/InstallationManager.cs b/MediaBrowser.Controller/Updates/InstallationManager.cs index f248c6d44f..d616e88984 100644 --- a/MediaBrowser.Controller/Updates/InstallationManager.cs +++ b/MediaBrowser.Controller/Updates/InstallationManager.cs @@ -93,12 +93,6 @@ namespace MediaBrowser.Controller.Updates } #endregion - /// - /// Gets or sets the zip client. - /// - /// The zip client. - private IZipClient ZipClient { get; set; } - /// /// The _logger /// @@ -137,20 +131,15 @@ namespace MediaBrowser.Controller.Updates /// /// The kernel. /// The HTTP client. - /// The zip client. /// The network manager. /// The package manager. /// The json serializer. /// The logger. /// The app host. /// zipClient - 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; } /// @@ -430,7 +418,7 @@ namespace MediaBrowser.Controller.Updates private async Task InstallPackageInternal(PackageVersionInfo package, IProgress 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 3e040d3e03..06727dfaee 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"> - - + + - - - /// - 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; } /// @@ -277,7 +276,12 @@ namespace MediaBrowser.Installer /// 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 4149a8ab18..3a7d9102ee 100644 --- a/MediaBrowser.Installer/MediaBrowser.Installer.csproj +++ b/MediaBrowser.Installer/MediaBrowser.Installer.csproj @@ -29,7 +29,7 @@ Media Browser Team Media Browser false - 28 + 32 0.1.1.%2a false true diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 9034434838..654fce42ec 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 progress) { var pkgManager = Resolve(); - return pkgManager.InstallPackage(Resolve(), Resolve(), Kernel.ResourcePools, progress, Resolve(), Kernel.ApplicationPaths, package, cancellationToken); + return pkgManager.InstallPackage(Resolve(), Resolve(), Kernel.ResourcePools, progress, Kernel.ApplicationPaths, package, cancellationToken); } ///