This commit is contained in:
LukePulverenti 2013-03-11 12:55:00 -04:00
commit 61b5f66f20
5 changed files with 107 additions and 10 deletions

View File

@ -24,7 +24,7 @@ namespace MediaBrowser.Common.Implementations.Updates
var target = Path.Combine(Path.GetTempPath(), UpdaterExe);
var product = app == MBApplication.MBTheater ? "mbt" : "server";
File.Copy(source, target, true);
Process.Start(UpdaterExe, string.Format("product={0} archive=\"{1}\" caller={2}", product, archive, Process.GetCurrentProcess().Id));
Process.Start(target, string.Format("product={0} archive=\"{1}\" caller={2}", product, archive, Process.GetCurrentProcess().Id));
// That's it. The installer will do the work once we exit
}

View File

@ -9,6 +9,7 @@ using System.Windows;
using System.Linq;
using Ionic.Zip;
using MediaBrowser.Installer.Code;
using Microsoft.Win32;
using ServiceStack.Text;
namespace MediaBrowser.Installer
@ -19,7 +20,8 @@ namespace MediaBrowser.Installer
public partial class MainWindow : Window
{
protected PackageVersionClass PackageClass = PackageVersionClass.Release;
protected Version PackageVersion = new Version(4,0,0,0);
protected Version RequestedVersion = new Version(4,0,0,0);
protected Version ActualVersion;
protected string PackageName = "MBServer";
protected string RootSuffix = "-Server";
protected string TargetExe = "MediaBrowser.ServerApplication.exe";
@ -92,7 +94,7 @@ namespace MediaBrowser.Installer
var product = args.GetValueOrDefault("product", null) ?? ConfigurationManager.AppSettings["product"] ?? "server";
PackageClass = (PackageVersionClass) Enum.Parse(typeof (PackageVersionClass), args.GetValueOrDefault("class", null) ?? ConfigurationManager.AppSettings["class"] ?? "Release");
PackageVersion = new Version(args.GetValueOrDefault("version", "4.0"));
RequestedVersion = new Version(args.GetValueOrDefault("version", "4.0"));
var callerId = args.GetValueOrDefault("caller", null);
if (callerId != null)
@ -140,6 +142,7 @@ namespace MediaBrowser.Installer
// Determine Package version
var version = await GetPackageVersion();
ActualVersion = version.version;
// Now try and shut down the server if that is what we are installing and it is running
var procs = Process.GetProcessesByName("mediabrowser.serverapplication");
@ -202,6 +205,7 @@ namespace MediaBrowser.Installer
catch (Exception e)
{
SystemClose("Error Downloading Package - " + e.GetType().FullName + "\n\n" + e.Message);
return;
}
}
@ -224,11 +228,13 @@ namespace MediaBrowser.Installer
{
SystemClose("Error Removing Archive - " + e.GetType().FullName + "\n\n" + e.Message);
return;
}
}
catch (Exception e)
{
SystemClose("Error Extracting - " + e.GetType().FullName + "\n\n" + e.Message);
return;
}
// Create shortcut
@ -240,6 +246,7 @@ namespace MediaBrowser.Installer
catch (Exception e)
{
SystemClose("Error Creating Shortcut - "+e.GetType().FullName+"\n\n"+e.Message);
return;
}
// And run
@ -250,6 +257,7 @@ namespace MediaBrowser.Installer
catch (Exception e)
{
SystemClose("Error Executing - "+fullPath+ " "+e.GetType().FullName+"\n\n"+e.Message);
return;
}
SystemClose();
@ -264,7 +272,7 @@ namespace MediaBrowser.Installer
var json = await MainClient.DownloadStringTaskAsync("http://www.mb3admin.com/admin/service/package/retrieveAll?name=" + PackageName);
var packages = JsonSerializer.DeserializeFromString<List<PackageInfo>>(json);
var version = packages[0].versions.Where(v => v.classification <= PackageClass).OrderByDescending(v => v.version).FirstOrDefault(v => v.version <= PackageVersion);
var version = packages[0].versions.Where(v => v.classification <= PackageClass).OrderByDescending(v => v.version).FirstOrDefault(v => v.version <= RequestedVersion);
if (version == null)
{
SystemClose("Could not locate download package. Aborting.");
@ -373,12 +381,66 @@ namespace MediaBrowser.Installer
dashboard.Save();
}
var uninstall = new ShellShortcut(Path.Combine(startMenu, "Uninstall " + FriendlyName + ".lnk"))
{Path = Path.Combine(Path.GetDirectoryName(targetExe), "MediaBrowser.Uninstaller.exe"), Arguments = (PackageName == "MBServer" ? "server" : "mbt"), Description = "Uninstall " + FriendlyName};
uninstall.Save();
CreateUninstaller(Path.Combine(Path.GetDirectoryName(targetExe) ?? "", "MediaBrowser.Uninstaller.exe")+ " "+ (PackageName == "MBServer" ? "server" : "mbt"), targetExe);
}
/// <summary>
/// Create uninstall entry in add/remove
/// </summary>
/// <param name="uninstallPath"></param>
/// <param name="targetExe"></param>
private void CreateUninstaller(string uninstallPath, string targetExe)
{
using (var parent = Registry.LocalMachine.OpenSubKey(
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", true))
{
if (parent == null)
{
MessageBox.Show("Uninstall registry key not found.");
return;
}
try
{
RegistryKey key = null;
try
{
const string guidText = "{4E76DB4E-1BB9-4A7B-860C-7940779CF7A0}";
key = parent.OpenSubKey(guidText, true) ??
parent.CreateSubKey(guidText);
if (key == null)
{
MessageBox.Show(String.Format("Unable to create uninstaller entry'{0}\\{1}'", @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", guidText));
return;
}
key.SetValue("DisplayName", FriendlyName);
key.SetValue("ApplicationVersion", ActualVersion);
key.SetValue("Publisher", "Media Browser Team");
key.SetValue("DisplayIcon", targetExe);
key.SetValue("DisplayVersion", ActualVersion.ToString(2));
key.SetValue("URLInfoAbout", "http://www.mediabrowser3.com");
key.SetValue("Contact", "http://community.mediabrowser.tv");
key.SetValue("InstallDate", DateTime.Now.ToString("yyyyMMdd"));
key.SetValue("UninstallString", uninstallPath);
}
finally
{
if (key != null)
{
key.Close();
}
}
}
catch (Exception ex)
{
MessageBox.Show("An error occurred writing uninstall information to the registry.");
}
}
}
/// <summary>
/// Prepare a temporary location to download to
/// </summary>

View File

@ -31,7 +31,7 @@
<PublisherName>Media Browser Team</PublisherName>
<SuiteName>Media Browser</SuiteName>
<OpenBrowserOnPublish>false</OpenBrowserOnPublish>
<ApplicationRevision>36</ApplicationRevision>
<ApplicationRevision>38</ApplicationRevision>
<ApplicationVersion>0.1.1.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>

View File

@ -1,7 +1,7 @@
using System;
using System.Diagnostics;
using System.Net;
using System.Reflection;
using Microsoft.Win32;
using System.IO;
using System.Threading;
using System.Windows;
@ -195,13 +195,43 @@ namespace MediaBrowser.Uninstaller.Execute
}
}
// Remove reference to us
RemoveUninstall();
// and done
lblHeading.Content = string.Format("Media Browser {0} Uninstalled.", Product);
btnUninstall.Visibility = Visibility.Hidden;
btnFinished.Visibility = Visibility.Visible;
}
private static void RemoveShortcut(string path)
private void RemoveUninstall()
{
using (var parent = Registry.LocalMachine.OpenSubKey(
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", true))
{
if (parent == null)
{
MessageBox.Show("Uninstall registry key not found.");
return;
}
try
{
const string guidText = "{4E76DB4E-1BB9-4A7B-860C-7940779CF7A0}";
parent.DeleteSubKey(guidText,false);
}
catch (Exception ex)
{
throw new Exception(
"An error occurred removing uninstall information from the registry.",
ex);
}
}
}
private static
void RemoveShortcut(string path)
{
try
{

View File

@ -34,6 +34,11 @@
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>
</ApplicationIcon>
</PropertyGroup>
<PropertyGroup />
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />