Program.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System.Diagnostics;
  2. using System.Text;
  3. using PixiEditor.UpdateInstaller.ViewModels;
  4. UpdateController controller = new UpdateController();
  5. StringBuilder log = new StringBuilder();
  6. bool startAfterUpdate = false;
  7. foreach (string arg in args)
  8. {
  9. if (arg == "--startOnSuccess")
  10. {
  11. startAfterUpdate = true;
  12. log.AppendLine($"{DateTime.Now}: Found --startOnSuccess argument, will start PixiEditor after update.");
  13. break;
  14. }
  15. }
  16. try
  17. {
  18. log.AppendLine($"{DateTime.Now}: Starting update installation...");
  19. controller.InstallUpdate(log);
  20. }
  21. catch (Exception ex)
  22. {
  23. log.AppendLine($"{DateTime.Now}: Error during update installation: {ex.Message}");
  24. File.AppendAllText("ErrorLog.txt",
  25. $"Error PixiEditor.UpdateInstaller: {DateTime.Now}\n{ex.Message}\n{ex.StackTrace}\n-----\n");
  26. }
  27. finally
  28. {
  29. try
  30. {
  31. File.WriteAllText("UpdateLog.txt", log.ToString());
  32. }
  33. catch
  34. {
  35. // probably permissions or disk full, the best we can do is to ignore this
  36. }
  37. if (startAfterUpdate)
  38. {
  39. string binaryName = OperatingSystem.IsWindows() ? "PixiEditor.exe" : "PixiEditor";
  40. var files = Directory.GetFiles(controller.UpdateDirectory, binaryName);
  41. if (files.Length > 0)
  42. {
  43. string pixiEditorExecutablePath = files[0];
  44. Process.Start(pixiEditorExecutablePath);
  45. }
  46. else
  47. {
  48. binaryName = OperatingSystem.IsWindows() ? "PixiEditor.Desktop.exe" : "PixiEditor.Desktop";
  49. files = Directory.GetFiles(controller.UpdateDirectory, binaryName);
  50. if (files.Length > 0)
  51. {
  52. string pixiEditorExecutablePath = files[0];
  53. Process.Start(pixiEditorExecutablePath);
  54. }
  55. else
  56. {
  57. Console.WriteLine("PixiEditor executable not found.");
  58. }
  59. }
  60. }
  61. }