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-02-26 01:11:51 +00:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Uninstaller.Execute
|
|
|
|
|
{
|
|
|
|
|
/// <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();
|
|
|
|
|
var product = args.Length > 1 ? args[1] : "server";
|
2013-03-02 15:01:38 +00:00
|
|
|
|
var callerId = args.Length > 2 ? args[2] : null;
|
|
|
|
|
if (callerId != null)
|
|
|
|
|
{
|
|
|
|
|
// Wait for our caller to exit
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var process = Process.GetProcessById(Convert.ToInt32(callerId));
|
|
|
|
|
process.WaitForExit();
|
|
|
|
|
}
|
|
|
|
|
catch (ArgumentException)
|
|
|
|
|
{
|
|
|
|
|
// wasn't running
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(1000); // crude method
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-26 01:11:51 +00:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (product)
|
|
|
|
|
{
|
|
|
|
|
case "server":
|
|
|
|
|
Product = "Server";
|
2013-02-26 15:07:58 +00:00
|
|
|
|
RootSuffix = "-Server";
|
2013-02-26 01:11:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "mbt":
|
|
|
|
|
Product = "Theater";
|
2013-03-09 15:11:22 +00:00
|
|
|
|
RootSuffix = "-Theater";
|
2013-02-26 01:11:51 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2013-02-26 02:34:11 +00:00
|
|
|
|
MessageBox.Show("Please specify which application to un-install (server or mbt)");
|
2013-02-26 01:11:51 +00:00
|
|
|
|
Close();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lblHeading.Content = this.Title = "Uninstall Media Browser " + Product;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void RemoveShortcut(string path)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|