Program.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  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. namespace MediaBrowser.Uninstaller
  11. {
  12. class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16. var product = args.Length > 1 ? args[1] : "server";
  17. //copy the real program to a temp location so we can delete everything here (including us)
  18. var tempExe = Path.Combine(Path.GetTempPath(), "MediaBrowser.Uninstaller.Execute.exe");
  19. var tempConfig = Path.Combine(Path.GetTempPath(), "MediaBrowser.Uninstaller.Execute.exe.config");
  20. //using (var file = File.Create(tempExe, 4096, FileOptions.DeleteOnClose))
  21. {
  22. //copy the real uninstaller to temp location
  23. var sourceDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "";
  24. File.WriteAllBytes(tempExe, File.ReadAllBytes(Path.Combine(sourceDir, "MediaBrowser.Uninstaller.Execute.exe")));
  25. File.Copy(Path.Combine(sourceDir, "MediaBrowser.Uninstaller.Execute.exe.config"), tempConfig, true);
  26. //get our pid to pass to the uninstaller so it can wait for us to exit
  27. var pid = Process.GetCurrentProcess().Id;
  28. //kick off the copy
  29. Process.Start(tempExe, product + " " + pid);
  30. //and shut down
  31. }
  32. }
  33. }
  34. }