From 868a7ce9c8b50bd64c8b5ae33fec77abfd25ef7c Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Thu, 21 Feb 2013 23:23:06 -0500 Subject: isolated clickonce dependancies --- .../Updates/ApplicationUpdateCheck.cs | 92 --------- MediaBrowser.Common/Updates/ApplicationUpdater.cs | 93 --------- MediaBrowser.Common/Updates/ClickOnceHelper.cs | 217 --------------------- 3 files changed, 402 deletions(-) delete mode 100644 MediaBrowser.Common/Updates/ApplicationUpdateCheck.cs delete mode 100644 MediaBrowser.Common/Updates/ApplicationUpdater.cs delete mode 100644 MediaBrowser.Common/Updates/ClickOnceHelper.cs (limited to 'MediaBrowser.Common/Updates') diff --git a/MediaBrowser.Common/Updates/ApplicationUpdateCheck.cs b/MediaBrowser.Common/Updates/ApplicationUpdateCheck.cs deleted file mode 100644 index 7501d7321b..0000000000 --- a/MediaBrowser.Common/Updates/ApplicationUpdateCheck.cs +++ /dev/null @@ -1,92 +0,0 @@ -using MediaBrowser.Model.Tasks; -using System; -using System.Deployment.Application; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Common.Updates -{ - /// - /// Class ApplicationUpdateCheck - /// - public class ApplicationUpdateCheck - { - /// - /// The _task completion source - /// - private TaskCompletionSource _taskCompletionSource; - - /// - /// The _progress - /// - private IProgress _progress; - - /// - /// Checks for application update. - /// - /// The cancellation token. - /// The progress. - /// Task{CheckForUpdateCompletedEventArgs}. - /// Current deployment is not a ClickOnce deployment - public Task CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress progress) - { - if (!ApplicationDeployment.IsNetworkDeployed) - { - throw new InvalidOperationException("Current deployment is not network deployed."); - } - - _progress = progress; - - _taskCompletionSource = new TaskCompletionSource(); - - var deployment = ApplicationDeployment.CurrentDeployment; - - cancellationToken.Register(deployment.CheckForUpdateAsyncCancel); - - cancellationToken.ThrowIfCancellationRequested(); - - deployment.CheckForUpdateCompleted += deployment_CheckForUpdateCompleted; - deployment.CheckForUpdateProgressChanged += deployment_CheckForUpdateProgressChanged; - - deployment.CheckForUpdateAsync(); - - return _taskCompletionSource.Task; - } - - /// - /// Handles the CheckForUpdateCompleted event of the deployment control. - /// - /// The source of the event. - /// The instance containing the event data. - void deployment_CheckForUpdateCompleted(object sender, CheckForUpdateCompletedEventArgs e) - { - var deployment = ApplicationDeployment.CurrentDeployment; - - deployment.CheckForUpdateCompleted -= deployment_CheckForUpdateCompleted; - deployment.CheckForUpdateProgressChanged -= deployment_CheckForUpdateProgressChanged; - - if (e.Error != null) - { - _taskCompletionSource.SetException(e.Error); - } - else if (e.Cancelled) - { - _taskCompletionSource.SetCanceled(); - } - else - { - _taskCompletionSource.SetResult(e); - } - } - - /// - /// Handles the CheckForUpdateProgressChanged event of the deployment control. - /// - /// The source of the event. - /// The instance containing the event data. - void deployment_CheckForUpdateProgressChanged(object sender, DeploymentProgressChangedEventArgs e) - { - _progress.Report(new TaskProgress { PercentComplete = e.ProgressPercentage }); - } - } -} diff --git a/MediaBrowser.Common/Updates/ApplicationUpdater.cs b/MediaBrowser.Common/Updates/ApplicationUpdater.cs deleted file mode 100644 index d8ae87b375..0000000000 --- a/MediaBrowser.Common/Updates/ApplicationUpdater.cs +++ /dev/null @@ -1,93 +0,0 @@ -using MediaBrowser.Model.Tasks; -using System; -using System.ComponentModel; -using System.Deployment.Application; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Common.Updates -{ - /// - /// Class ApplicationUpdater - /// - public class ApplicationUpdater - { - /// - /// The _task completion source - /// - private TaskCompletionSource _taskCompletionSource; - - /// - /// The _progress - /// - private IProgress _progress; - - /// - /// Updates the application - /// - /// The cancellation token. - /// The progress. - /// Task{AsyncCompletedEventArgs}. - /// Current deployment is not network deployed. - public Task UpdateApplication(CancellationToken cancellationToken, IProgress progress) - { - if (!ApplicationDeployment.IsNetworkDeployed) - { - throw new InvalidOperationException("Current deployment is not network deployed."); - } - - _progress = progress; - - _taskCompletionSource = new TaskCompletionSource(); - - var deployment = ApplicationDeployment.CurrentDeployment; - - cancellationToken.Register(deployment.UpdateAsyncCancel); - - cancellationToken.ThrowIfCancellationRequested(); - - deployment.UpdateCompleted += deployment_UpdateCompleted; - deployment.UpdateProgressChanged += deployment_UpdateProgressChanged; - - deployment.UpdateAsync(); - - return _taskCompletionSource.Task; - } - - /// - /// Handles the UpdateCompleted event of the deployment control. - /// - /// The source of the event. - /// The instance containing the event data. - void deployment_UpdateCompleted(object sender, AsyncCompletedEventArgs e) - { - var deployment = ApplicationDeployment.CurrentDeployment; - - deployment.UpdateCompleted -= deployment_UpdateCompleted; - deployment.UpdateProgressChanged -= deployment_UpdateProgressChanged; - - if (e.Error != null) - { - _taskCompletionSource.SetException(e.Error); - } - else if (e.Cancelled) - { - _taskCompletionSource.SetCanceled(); - } - else - { - _taskCompletionSource.SetResult(e); - } - } - - /// - /// Handles the UpdateProgressChanged event of the deployment control. - /// - /// The source of the event. - /// The instance containing the event data. - void deployment_UpdateProgressChanged(object sender, DeploymentProgressChangedEventArgs e) - { - _progress.Report(new TaskProgress { PercentComplete = e.ProgressPercentage }); - } - } -} diff --git a/MediaBrowser.Common/Updates/ClickOnceHelper.cs b/MediaBrowser.Common/Updates/ClickOnceHelper.cs deleted file mode 100644 index 7dd0cf9c57..0000000000 --- a/MediaBrowser.Common/Updates/ClickOnceHelper.cs +++ /dev/null @@ -1,217 +0,0 @@ -using Microsoft.Win32; -using System; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Security.AccessControl; - -namespace MediaBrowser.Common.Updates -{ - /// - /// Class ClickOnceHelper - /// - public class ClickOnceHelper - { - /// - /// The uninstall string - /// - private const string UninstallString = "UninstallString"; - /// - /// The display name key - /// - private const string DisplayNameKey = "DisplayName"; - /// - /// The uninstall string file - /// - private const string UninstallStringFile = "UninstallString.bat"; - /// - /// The appref extension - /// - private const string ApprefExtension = ".appref-ms"; - /// - /// The uninstall registry key - /// - private readonly RegistryKey UninstallRegistryKey; - - /// - /// Gets the location. - /// - /// The location. - private static string Location - { - get { return Assembly.GetExecutingAssembly().Location; } - } - - /// - /// Gets the name of the publisher. - /// - /// The name of the publisher. - public string PublisherName { get; private set; } - /// - /// Gets the name of the product. - /// - /// The name of the product. - public string ProductName { get; private set; } - /// - /// Gets the uninstall file. - /// - /// The uninstall file. - public string UninstallFile { get; private set; } - /// - /// Gets the name of the suite. - /// - /// The name of the suite. - public string SuiteName { get; private set; } - - /// - /// Initializes a new instance of the class. - /// - /// Name of the publisher. - /// Name of the product. - /// Name of the suite. - public ClickOnceHelper(string publisherName, string productName, string suiteName) - { - PublisherName = publisherName; - ProductName = productName; - SuiteName = suiteName; - - var publisherFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), PublisherName); - - if (!Directory.Exists(publisherFolder)) - { - Directory.CreateDirectory(publisherFolder); - } - - UninstallFile = Path.Combine(publisherFolder, UninstallStringFile); - - UninstallRegistryKey = GetUninstallRegistryKeyByProductName(ProductName); - } - - /// - /// Gets the shortcut path. - /// - /// System.String. - private string GetShortcutPath() - { - var allProgramsPath = Environment.GetFolderPath(Environment.SpecialFolder.Programs); - - var shortcutPath = Path.Combine(allProgramsPath, PublisherName); - - if (!string.IsNullOrEmpty(SuiteName)) - { - shortcutPath = Path.Combine(shortcutPath, SuiteName); - } - - return Path.Combine(shortcutPath, ProductName) + ApprefExtension; - } - - /// - /// Gets the startup shortcut path. - /// - /// System.String. - private string GetStartupShortcutPath() - { - var startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); - - return Path.Combine(startupPath, ProductName) + ApprefExtension; - } - - /// - /// Adds the shortcut to startup. - /// - public void AddShortcutToStartup() - { - var startupPath = GetStartupShortcutPath(); - - if (!File.Exists(startupPath)) - { - File.Copy(GetShortcutPath(), startupPath); - } - } - - /// - /// Removes the shortcut from startup. - /// - public void RemoveShortcutFromStartup() - { - var startupPath = GetStartupShortcutPath(); - - if (File.Exists(startupPath)) - { - File.Delete(startupPath); - } - } - - /// - /// Updates the uninstall parameters. - /// - /// Name of the uninstaller file. - public void UpdateUninstallParameters(string uninstallerFileName) - { - if (UninstallRegistryKey != null) - { - UpdateUninstallString(uninstallerFileName); - } - } - - /// - /// Gets the name of the uninstall registry key by product. - /// - /// Name of the product. - /// RegistryKey. - private RegistryKey GetUninstallRegistryKeyByProductName(string productName) - { - var subKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall"); - - if (subKey == null) - { - return null; - } - - return subKey.GetSubKeyNames() - .Select(name => subKey.OpenSubKey(name, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.QueryValues | RegistryRights.ReadKey | RegistryRights.SetValue)) - .Where(application => application != null) - .FirstOrDefault(application => application.GetValueNames().Where(appKey => appKey.Equals(DisplayNameKey)).Any(appKey => application.GetValue(appKey).Equals(productName))); - } - - /// - /// Updates the uninstall string. - /// - /// Name of the uninstaller file. - private void UpdateUninstallString(string uninstallerFileName) - { - var uninstallString = (string)UninstallRegistryKey.GetValue(UninstallString); - - if (!string.IsNullOrEmpty(UninstallFile) && uninstallString.StartsWith("rundll32.exe", StringComparison.OrdinalIgnoreCase)) - { - File.WriteAllText(UninstallFile, uninstallString); - } - - var str = String.Format("\"{0}\" uninstall", Path.Combine(Path.GetDirectoryName(Location), uninstallerFileName)); - - UninstallRegistryKey.SetValue(UninstallString, str); - } - - /// - /// Uninstalls this instance. - /// - public void Uninstall() - { - RemoveShortcutFromStartup(); - - var uninstallString = File.ReadAllText(UninstallFile); - - new Process - { - StartInfo = - { - Arguments = uninstallString.Substring(uninstallString.IndexOf(" ", StringComparison.OrdinalIgnoreCase) + 1), - FileName = uninstallString.Substring(0, uninstallString.IndexOf(" ", StringComparison.OrdinalIgnoreCase)), - UseShellExecute = false - } - - }.Start(); - } - } -} -- cgit v1.2.3