Remove archive extraction from PackageManager

It is no longer needed as the installer does this
This commit is contained in:
Eric Reed 2013-03-01 15:42:44 -05:00
parent 833639ff87
commit e3b42ad59e
5 changed files with 31 additions and 54 deletions

View File

@ -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 // Target based on if it is an archive or single assembly
// zip archives are assumed to contain directory structures relative to our ProgramDataPath // zip archives are assumed to contain directory structures relative to our ProgramDataPath
var isArchive = string.Equals(Path.GetExtension(package.targetFilename), ".zip", StringComparison.OrdinalIgnoreCase); 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 // 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); var tempFile = await client.GetTempFile(package.sourceUrl, resourcePool.Mb, cancellationToken, progress).ConfigureAwait(false);
@ -71,22 +71,7 @@ namespace MediaBrowser.Common.Implementations.Updates
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
// Success - move it to the real target based on type // Success - move it to the real target
if (isArchive)
{
try
{
zipClient.ExtractAll(tempFile, target, true);
}
catch (IOException e)
{
logger.ErrorException("Error attempting to extract archive from {0} to {1}", e, tempFile, target);
throw;
}
}
else
{
try try
{ {
File.Copy(tempFile, target, true); File.Copy(tempFile, target, true);
@ -97,7 +82,6 @@ namespace MediaBrowser.Common.Implementations.Updates
logger.ErrorException("Error attempting to move file from {0} to {1}", e, tempFile, target); logger.ErrorException("Error attempting to move file from {0} to {1}", e, tempFile, target);
throw; throw;
} }
}
} }

View File

@ -40,7 +40,6 @@ namespace MediaBrowser.Common.Updates
/// <param name="logger"></param> /// <param name="logger"></param>
/// <param name="resourcePool"></param> /// <param name="resourcePool"></param>
/// <param name="progress"></param> /// <param name="progress"></param>
/// <param name="zipClient"></param>
/// <param name="appPaths"></param> /// <param name="appPaths"></param>
/// <param name="package">The package.</param> /// <param name="package">The package.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
@ -49,7 +48,6 @@ namespace MediaBrowser.Common.Updates
ILogger logger, ILogger logger,
ResourcePool resourcePool, ResourcePool resourcePool,
IProgress<double> progress, IProgress<double> progress,
IZipClient zipClient,
IApplicationPaths appPaths, IApplicationPaths appPaths,
PackageVersionInfo package, PackageVersionInfo package,
CancellationToken cancellationToken); CancellationToken cancellationToken);

View File

@ -93,12 +93,6 @@ namespace MediaBrowser.Controller.Updates
} }
#endregion #endregion
/// <summary>
/// Gets or sets the zip client.
/// </summary>
/// <value>The zip client.</value>
private IZipClient ZipClient { get; set; }
/// <summary> /// <summary>
/// The _logger /// The _logger
/// </summary> /// </summary>
@ -137,20 +131,15 @@ namespace MediaBrowser.Controller.Updates
/// </summary> /// </summary>
/// <param name="kernel">The kernel.</param> /// <param name="kernel">The kernel.</param>
/// <param name="httpClient">The HTTP client.</param> /// <param name="httpClient">The HTTP client.</param>
/// <param name="zipClient">The zip client.</param>
/// <param name="networkManager">The network manager.</param> /// <param name="networkManager">The network manager.</param>
/// <param name="packageManager">The package manager.</param> /// <param name="packageManager">The package manager.</param>
/// <param name="jsonSerializer">The json serializer.</param> /// <param name="jsonSerializer">The json serializer.</param>
/// <param name="logger">The logger.</param> /// <param name="logger">The logger.</param>
/// <param name="appHost">The app host.</param> /// <param name="appHost">The app host.</param>
/// <exception cref="System.ArgumentNullException">zipClient</exception> /// <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) : base(kernel)
{ {
if (zipClient == null)
{
throw new ArgumentNullException("zipClient");
}
if (networkManager == null) if (networkManager == null)
{ {
throw new ArgumentNullException("networkManager"); throw new ArgumentNullException("networkManager");
@ -180,7 +169,6 @@ namespace MediaBrowser.Controller.Updates
_networkManager = networkManager; _networkManager = networkManager;
_packageManager = packageManager; _packageManager = packageManager;
_logger = logger; _logger = logger;
ZipClient = zipClient;
} }
/// <summary> /// <summary>
@ -430,7 +418,7 @@ namespace MediaBrowser.Controller.Updates
private async Task InstallPackageInternal(PackageVersionInfo package, IProgress<double> progress, CancellationToken cancellationToken) private async Task InstallPackageInternal(PackageVersionInfo package, IProgress<double> progress, CancellationToken cancellationToken)
{ {
// Do the install // 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 // Do plugin-specific processing
if (!(Path.GetExtension(package.targetFilename) ?? "").Equals(".zip", StringComparison.OrdinalIgnoreCase)) if (!(Path.GetExtension(package.targetFilename) ?? "").Equals(".zip", StringComparison.OrdinalIgnoreCase))

View File

@ -24,6 +24,7 @@ namespace MediaBrowser.Installer
protected string RootSuffix = "-Server"; protected string RootSuffix = "-Server";
protected string TargetExe = "MediaBrowser.ServerApplication.exe"; protected string TargetExe = "MediaBrowser.ServerApplication.exe";
protected string FriendlyName = "Media Browser Server"; protected string FriendlyName = "Media Browser Server";
protected string Archive = null;
protected string RootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MediaBrowser-Server"); protected string RootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MediaBrowser-Server");
protected bool SystemClosing = false; protected bool SystemClosing = false;
@ -36,7 +37,7 @@ namespace MediaBrowser.Installer
{ {
GetArgs(); GetArgs();
InitializeComponent(); InitializeComponent();
DoInstall(); DoInstall(Archive);
} }
private void btnCancel_Click(object sender, RoutedEventArgs e) private void btnCancel_Click(object sender, RoutedEventArgs e)
@ -77,6 +78,8 @@ namespace MediaBrowser.Installer
{ {
var product = ConfigurationManager.AppSettings["product"] ?? "server"; var product = ConfigurationManager.AppSettings["product"] ?? "server";
PackageClass = (PackageVersionClass) Enum.Parse(typeof (PackageVersionClass), ConfigurationManager.AppSettings["class"] ?? "Release"); PackageClass = (PackageVersionClass) Enum.Parse(typeof (PackageVersionClass), ConfigurationManager.AppSettings["class"] ?? "Release");
var cmdArgs = Environment.GetCommandLineArgs();
Archive = cmdArgs.Length > 1 ? cmdArgs[1] : null;
switch (product.ToLower()) switch (product.ToLower())
{ {
@ -103,7 +106,7 @@ namespace MediaBrowser.Installer
/// Execute the install process /// Execute the install process
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
protected async Task DoInstall() protected async Task DoInstall(string archive)
{ {
lblStatus.Text = string.Format("Downloading {0}...", FriendlyName); lblStatus.Text = string.Format("Downloading {0}...", FriendlyName);
@ -150,8 +153,9 @@ namespace MediaBrowser.Installer
} }
} }
// Download // Download if we don't already have it
string archive = null; if (archive == null)
{
lblStatus.Text = string.Format("Downloading {0} (version {1})...", FriendlyName, version.versionStr); lblStatus.Text = string.Format("Downloading {0} (version {1})...", FriendlyName, version.versionStr);
try try
{ {
@ -161,6 +165,7 @@ namespace MediaBrowser.Installer
{ {
SystemClose("Error Downloading Package - " + e.GetType().FullName + "\n\n" + e.Message); 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 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 // Delete old content of system
var systemDir = Path.Combine(RootPath, "system"); var systemDir = Path.Combine(RootPath, "system");
if (Directory.Exists(systemDir)) Directory.Delete(systemDir, true); 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)) using (var zipFile = ZipFile.Read(fileStream))
{ {

View File

@ -178,7 +178,7 @@ namespace MediaBrowser.ServerApplication
public Task UpdateApplication(PackageVersionInfo package, CancellationToken cancellationToken, IProgress<double> progress) public Task UpdateApplication(PackageVersionInfo package, CancellationToken cancellationToken, IProgress<double> progress)
{ {
var pkgManager = Resolve<IPackageManager>(); 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> /// <summary>