MainWindow.xaml.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. using Path = System.IO.Path;
  20. namespace MediaBrowser.Uninstaller
  21. {
  22. /// <summary>
  23. /// Interaction logic for MainWindow.xaml
  24. /// </summary>
  25. public partial class MainWindow : Window
  26. {
  27. public MainWindow()
  28. {
  29. //All our work is behind the scenes
  30. var args = Environment.GetCommandLineArgs();
  31. var product = args.Length > 1 ? args[1] : "server";
  32. //copy the real program to a temp location so we can delete everything here (including us)
  33. var tempExe = Path.Combine(Path.GetTempPath(), "MediaBrowser.Uninstaller.Execute.exe");
  34. var tempConfig = Path.Combine(Path.GetTempPath(), "MediaBrowser.Uninstaller.Execute.exe.config");
  35. using (var file = File.Create(tempExe, 4096, FileOptions.DeleteOnClose))
  36. {
  37. //copy the real uninstaller to temp location
  38. var sourceDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) ?? "";
  39. File.WriteAllBytes(tempExe, File.ReadAllBytes(Path.Combine(sourceDir ,"MediaBrowser.Uninstaller.Execute.exe")));
  40. File.Copy(tempConfig, Path.Combine(sourceDir ,"MediaBrowser.Uninstaller.Execute.exe.config"));
  41. //kick off the copy
  42. MessageBox.Show("About to start " + tempExe);
  43. Process.Start(tempExe, product);
  44. //wait for it to start up
  45. Thread.Sleep(500);
  46. //and shut down
  47. Close();
  48. }
  49. //InitializeComponent();
  50. }
  51. }
  52. }