2013-02-26 01:11:51 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
2013-02-28 16:33:54 +00:00
|
|
|
|
using System.Net;
|
2013-03-13 14:00:49 +00:00
|
|
|
|
using System.Reflection;
|
2013-03-11 16:10:12 +00:00
|
|
|
|
using Microsoft.Win32;
|
2013-02-26 01:11:51 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
2013-03-13 14:12:54 +00:00
|
|
|
|
namespace MediaBrowser.Uninstaller
|
2013-02-26 01:11:51 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for MainWindow.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
|
{
|
|
|
|
|
protected string Product = "Server";
|
2013-02-26 15:07:58 +00:00
|
|
|
|
protected string RootSuffix = "-Server";
|
2013-02-26 01:11:51 +00:00
|
|
|
|
|
|
|
|
|
public MainWindow()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var args = Environment.GetCommandLineArgs();
|
2013-03-13 14:00:49 +00:00
|
|
|
|
var product = args.Length > 1 ? args[1] : null;
|
|
|
|
|
if (product == null)
|
2013-03-02 15:01:38 +00:00
|
|
|
|
{
|
2013-03-13 14:00:49 +00:00
|
|
|
|
MessageBox.Show("Please use 'Programs and Features' to uninstall.");
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var callerId = args.Length > 2 ? args[2] : null;
|
|
|
|
|
if (callerId != null)
|
2013-03-02 15:01:38 +00:00
|
|
|
|
{
|
2013-03-13 14:00:49 +00:00
|
|
|
|
// Wait for our caller to exit
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var process = Process.GetProcessById(Convert.ToInt32(callerId));
|
|
|
|
|
process.WaitForExit();
|
|
|
|
|
}
|
|
|
|
|
catch (ArgumentException)
|
|
|
|
|
{
|
|
|
|
|
// wasn't running
|
|
|
|
|
}
|
2013-03-02 15:01:38 +00:00
|
|
|
|
}
|
2013-03-13 14:00:49 +00:00
|
|
|
|
else
|
2013-03-02 15:01:38 +00:00
|
|
|
|
{
|
2013-03-13 14:00:49 +00:00
|
|
|
|
// No caller - means we were called directly and need to move to temp file and execute there
|
|
|
|
|
//copy the real program to a temp location so we can delete everything here (including us)
|
|
|
|
|
var us = Assembly.GetExecutingAssembly().Location;
|
|
|
|
|
var tempExe = Path.Combine(Path.GetTempPath(), Path.GetFileName(us) ?? "Mediabrowser.Uninstaller.exe");
|
|
|
|
|
File.Copy(us,tempExe,true);
|
|
|
|
|
//get our pid to pass to the uninstaller so it can wait for us to exit
|
|
|
|
|
var pid = Process.GetCurrentProcess().Id;
|
|
|
|
|
//kick off the copy
|
|
|
|
|
Process.Start(tempExe, product + " " + pid);
|
|
|
|
|
//and shut down
|
|
|
|
|
Close();
|
2013-03-02 15:01:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-13 14:00:49 +00:00
|
|
|
|
InitializeComponent();
|
2013-02-26 01:11:51 +00:00
|
|
|
|
|
|
|
|
|
|
2013-03-13 14:00:49 +00:00
|
|
|
|
switch (product)
|
|
|
|
|
{
|
|
|
|
|
case "server":
|
|
|
|
|
Product = "Server";
|
|
|
|
|
RootSuffix = "-Server";
|
|
|
|
|
break;
|
2013-02-26 01:11:51 +00:00
|
|
|
|
|
2013-03-13 14:00:49 +00:00
|
|
|
|
case "mbt":
|
|
|
|
|
Product = "Theater";
|
|
|
|
|
RootSuffix = "-Theater";
|
|
|
|
|
break;
|
2013-02-26 01:11:51 +00:00
|
|
|
|
|
2013-03-13 14:00:49 +00:00
|
|
|
|
default:
|
|
|
|
|
MessageBox.Show("Please Use 'Programs and Features' to uninstall.");
|
|
|
|
|
Close();
|
|
|
|
|
break;
|
2013-02-26 01:11:51 +00:00
|
|
|
|
|
2013-03-13 14:00:49 +00:00
|
|
|
|
}
|
2013-02-26 01:11:51 +00:00
|
|
|
|
|
2013-03-13 14:00:49 +00:00
|
|
|
|
lblHeading.Content = this.Title = "Uninstall Media Browser " + Product;
|
|
|
|
|
|
|
|
|
|
}
|
2013-02-26 01:11:51 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnCancel_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cbxRemoveAll_Checked(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (cbxRemoveAll.IsChecked == true)
|
|
|
|
|
{
|
|
|
|
|
cbxRemoveCache.IsChecked = cbxRemoveConfig.IsChecked = cbxRemovePlugins.IsChecked = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cbxRemoveCache.IsEnabled = cbxRemoveConfig.IsEnabled = cbxRemovePlugins.IsEnabled = !cbxRemoveAll.IsChecked.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnUninstall_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// First remove our shortcuts
|
2013-02-26 14:13:49 +00:00
|
|
|
|
lblHeading.Content = "Removing Shortcuts...";
|
|
|
|
|
btnCancel.IsEnabled = btnUninstall.IsEnabled = false;
|
|
|
|
|
grdOptions.Visibility = Visibility.Hidden;
|
|
|
|
|
|
|
|
|
|
var startMenu = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Media Browser 3");
|
2013-02-26 01:11:51 +00:00
|
|
|
|
var linkName = "Media Browser " + Product + ".lnk";
|
2013-02-26 14:13:49 +00:00
|
|
|
|
RemoveShortcut(Path.Combine(startMenu, linkName));
|
2013-02-26 15:18:27 +00:00
|
|
|
|
RemoveShortcut(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup),linkName));
|
2013-02-26 14:13:49 +00:00
|
|
|
|
linkName = "Uninstall " + linkName;
|
|
|
|
|
RemoveShortcut(Path.Combine(startMenu, linkName));
|
|
|
|
|
if (Product == "Server")
|
2013-02-26 01:11:51 +00:00
|
|
|
|
{
|
2013-02-26 15:26:48 +00:00
|
|
|
|
RemoveShortcut(Path.Combine(startMenu, "MB Dashboard.lnk"));
|
2013-03-02 15:01:38 +00:00
|
|
|
|
var procs = Process.GetProcessesByName("mediabrowser.serverapplication");
|
|
|
|
|
var server = procs.Length > 0 ? procs[0] : null;
|
|
|
|
|
if (server != null)
|
2013-02-28 16:33:54 +00:00
|
|
|
|
{
|
2013-02-28 17:04:25 +00:00
|
|
|
|
using (var client = new WebClient())
|
2013-02-28 16:33:54 +00:00
|
|
|
|
{
|
2013-02-28 17:27:49 +00:00
|
|
|
|
lblHeading.Content = "Shutting Down Media Browser Server...";
|
2013-02-28 17:04:25 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
client.UploadString("http://localhost:8096/mediabrowser/system/shutdown", "");
|
2013-03-02 15:01:38 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
server.WaitForExit();
|
|
|
|
|
}
|
|
|
|
|
catch (ArgumentException)
|
|
|
|
|
{
|
|
|
|
|
// already gone
|
|
|
|
|
}
|
2013-02-28 17:04:25 +00:00
|
|
|
|
}
|
|
|
|
|
catch (WebException ex)
|
2013-02-28 16:33:54 +00:00
|
|
|
|
{
|
2013-02-28 17:04:25 +00:00
|
|
|
|
if (ex.Status != WebExceptionStatus.ConnectFailure && !ex.Message.StartsWith("Unable to connect", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Error shutting down server. Please be sure it is not running before hitting OK.\n\n" + ex.Status + "\n\n" + ex.Message);
|
|
|
|
|
}
|
2013-02-28 16:33:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-26 01:11:51 +00:00
|
|
|
|
}
|
2013-02-28 17:12:38 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Installing MBT - shut it down if it is running
|
|
|
|
|
var processes = Process.GetProcessesByName("mediabrowser.ui");
|
|
|
|
|
if (processes.Length > 0)
|
|
|
|
|
{
|
2013-02-28 17:27:49 +00:00
|
|
|
|
lblHeading.Content = "Shutting Down Media Browser Theater...";
|
2013-02-28 17:12:38 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2013-02-28 17:27:49 +00:00
|
|
|
|
processes[0].Kill();
|
2013-02-28 17:12:38 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Unable to shutdown Media Browser Theater. Please ensure it is not running before hitting OK.\n\n" + ex.Message, "Error");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-26 14:13:49 +00:00
|
|
|
|
// if the startmenu item is empty now - delete it too
|
|
|
|
|
if (Directory.GetFiles(startMenu).Length == 0)
|
2013-02-26 01:11:51 +00:00
|
|
|
|
{
|
2013-02-26 14:13:49 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Directory.Delete(startMenu);
|
|
|
|
|
}
|
|
|
|
|
catch (DirectoryNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(string.Format("Error attempting to remove shortcut folder {0}\n\n {1}", startMenu, ex.Message), "Error");
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-26 01:11:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-26 15:07:58 +00:00
|
|
|
|
var rootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MediaBrowser" + RootSuffix);
|
|
|
|
|
|
2013-02-28 16:33:54 +00:00
|
|
|
|
lblHeading.Content = "Removing System Files...";
|
2013-02-26 15:07:58 +00:00
|
|
|
|
if (cbxRemoveAll.IsChecked == true)
|
|
|
|
|
{
|
|
|
|
|
// Just remove our whole directory
|
|
|
|
|
RemovePath(rootPath);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// First remove the system
|
|
|
|
|
RemovePath(Path.Combine(rootPath, "System"));
|
2013-02-26 15:18:27 +00:00
|
|
|
|
RemovePath(Path.Combine(rootPath, "MediaTools"));
|
2013-02-26 15:07:58 +00:00
|
|
|
|
|
|
|
|
|
// And then the others specified
|
|
|
|
|
if (cbxRemoveCache.IsChecked == true)
|
|
|
|
|
{
|
|
|
|
|
lblHeading.Content = "Removing Cache and Data Files...";
|
|
|
|
|
RemovePath(Path.Combine(rootPath, "cache"));
|
|
|
|
|
RemovePath(Path.Combine(rootPath, "data"));
|
|
|
|
|
}
|
|
|
|
|
if (cbxRemoveConfig.IsChecked == true)
|
|
|
|
|
{
|
|
|
|
|
lblHeading.Content = "Removing Config Files...";
|
|
|
|
|
RemovePath(Path.Combine(rootPath, "config"));
|
2013-02-26 15:18:27 +00:00
|
|
|
|
RemovePath(Path.Combine(rootPath, "logs"));
|
2013-02-26 15:07:58 +00:00
|
|
|
|
}
|
|
|
|
|
if (cbxRemovePlugins.IsChecked == true)
|
|
|
|
|
{
|
|
|
|
|
lblHeading.Content = "Removing Plugin Files...";
|
|
|
|
|
RemovePath(Path.Combine(rootPath, "plugins"));
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-26 14:13:49 +00:00
|
|
|
|
|
2013-03-11 16:10:12 +00:00
|
|
|
|
// Remove reference to us
|
|
|
|
|
RemoveUninstall();
|
|
|
|
|
|
2013-03-12 18:56:46 +00:00
|
|
|
|
// Remove pismo
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
UnInstallPismo();
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// No biggie - maybe they uninstalled it themselves
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-26 14:13:49 +00:00
|
|
|
|
// and done
|
|
|
|
|
lblHeading.Content = string.Format("Media Browser {0} Uninstalled.", Product);
|
2013-02-26 15:07:58 +00:00
|
|
|
|
btnUninstall.Visibility = Visibility.Hidden;
|
|
|
|
|
btnFinished.Visibility = Visibility.Visible;
|
2013-02-26 14:13:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-12 18:56:46 +00:00
|
|
|
|
private void UnInstallPismo()
|
|
|
|
|
{
|
|
|
|
|
// Kick off the Pismo uninstaller and wait for it to end
|
|
|
|
|
var pismo = new Process();
|
|
|
|
|
pismo.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
|
|
|
|
pismo.StartInfo.FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "pfm.exe");
|
|
|
|
|
pismo.StartInfo.Arguments = "uninstall pfm-license-mediabrowser.txt";
|
|
|
|
|
pismo.Start();
|
|
|
|
|
pismo.WaitForExit();
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-11 16:10:12 +00:00
|
|
|
|
private void RemoveUninstall()
|
|
|
|
|
{
|
|
|
|
|
|
2013-03-12 00:43:44 +00:00
|
|
|
|
using (var parent = Registry.CurrentUser.OpenSubKey(
|
2013-03-11 16:10:12 +00:00
|
|
|
|
@"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)
|
2013-02-26 14:13:49 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
File.Delete(path);
|
|
|
|
|
}
|
|
|
|
|
catch (FileNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
} // we're trying to get rid of it anyway
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(string.Format("Error attempting to remove shortcut {0}\n\n {1}", path, ex.Message), "Error");
|
|
|
|
|
}
|
2013-02-26 15:07:58 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void RemovePath(string path)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Directory.Delete(path, true);
|
|
|
|
|
}
|
|
|
|
|
catch (DirectoryNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(string.Format("Error attempting to remove progam folder {0}\n\n {1}", path, ex.Message), "Error");
|
|
|
|
|
}
|
2013-02-26 14:13:49 +00:00
|
|
|
|
|
2013-02-26 01:11:51 +00:00
|
|
|
|
}
|
2013-02-26 15:07:58 +00:00
|
|
|
|
|
|
|
|
|
private void BtnFinished_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
2013-02-26 01:11:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|