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 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 f3ca1d8cf..1db5ea706 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 7765b8aef..718c3c64f 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.cs b/MediaBrowser.Installer/MainWindow.xaml.cs index dfa1991df..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,7 +106,7 @@ namespace MediaBrowser.Installer /// Execute the install process /// /// - protected async Task DoInstall() + protected async Task DoInstall(string archive) { lblStatus.Text = string.Format("Downloading {0}...", FriendlyName); @@ -150,16 +153,18 @@ namespace MediaBrowser.Installer } } - // Download - string archive = null; - lblStatus.Text = string.Format("Downloading {0} (version {1})...", FriendlyName, version.versionStr); - try + // Download if we don't already have it + if (archive == null) { - archive = await DownloadPackage(version); - } - catch (Exception e) - { - 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); + } } if (archive == null) return; //we canceled or had an error that was already reported @@ -274,7 +279,9 @@ namespace MediaBrowser.Installer // Delete old content of system var systemDir = Path.Combine(RootPath, "system"); if (Directory.Exists(systemDir)) Directory.Delete(systemDir, true); - using (var fileStream = System.IO.File.OpenRead(archive)) + + // And extract + using (var fileStream = File.OpenRead(archive)) { using (var zipFile = ZipFile.Read(fileStream)) { diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 894f7cc75..e4405d123 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -178,7 +178,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); } ///