SupportUtils.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net.Http;
  6. using Comal.Classes;
  7. using InABox.Clients;
  8. using InABox.Core;
  9. using InABox.Wpf;
  10. using PRS.Shared;
  11. namespace PRSDesktop;
  12. public static class SupportUtils
  13. {
  14. public static void OpenSupportSession()
  15. {
  16. var helpwire = Path.Combine(CoreUtils.GetPath(), "helpwire.exe");
  17. if (!File.Exists(helpwire))
  18. {
  19. DownloadSupportAppWindow dl = new DownloadSupportAppWindow();
  20. dl.ShowDialog();
  21. }
  22. if (File.Exists(helpwire))
  23. {
  24. var startInfo = new ProcessStartInfo(helpwire);
  25. startInfo.Verb = "open";
  26. startInfo.UseShellExecute = true;
  27. startInfo.WindowStyle = ProcessWindowStyle.Hidden;
  28. try
  29. {
  30. Process.Start(startInfo);
  31. }
  32. catch (System.Exception e)
  33. {
  34. Logger.Send(LogType.Information,"",$"{e.Message}\n{e.StackTrace}");
  35. MessageWindow.ShowError("Unable to launch Support App", e, "Error");
  36. try
  37. {
  38. if (File.Exists(helpwire))
  39. File.Delete(helpwire);
  40. }
  41. catch (System.Exception e2)
  42. {
  43. Logger.Send(LogType.Information,"",$"{e2.Message}\n{e2.StackTrace}");
  44. }
  45. }
  46. }
  47. }
  48. public static string GetUpdateLocation()
  49. {
  50. if (App.DatabaseSettings.DatabaseType == DatabaseType.Networked)
  51. {
  52. if(ClientFactory.ClientType == typeof(RestClient<>))
  53. {
  54. string url = "";
  55. //var domain = App.DatabaseSettings.URL.Split(new[] { "://" }, StringSplitOptions.RemoveEmptyEntries).Last();
  56. //var port = App.DatabaseSettings.Port;
  57. var domain = ClientFactory.Parameters?.FirstOrDefault()?.ToString() ?? "";
  58. domain = domain.Split(new[] { "://" }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault() ?? "";
  59. if (!String.IsNullOrWhiteSpace(domain))
  60. {
  61. try
  62. {
  63. var client = new HttpClient { BaseAddress = new Uri($"https://{domain}") };
  64. client.GetAsync("operations").Wait();
  65. url = $"https://{domain}";
  66. }
  67. catch (Exception)
  68. {
  69. url = $"http://{domain}";
  70. }
  71. }
  72. return url;
  73. }
  74. else
  75. {
  76. return "";
  77. }
  78. }
  79. else
  80. return Path.Combine(CoreUtils.GetCommonAppData("PRSServer"), "update");
  81. }
  82. public static string GetLatestVersion(string location)
  83. {
  84. return Client.Version();
  85. }
  86. public static string GetReleaseNotes(string location)
  87. {
  88. return Client.ReleaseNotes();
  89. }
  90. public static byte[]? GetInstaller(string location)
  91. {
  92. return Client.Installer();
  93. }
  94. public static bool CheckForUpdates()
  95. {
  96. return Update.CheckForUpdates(
  97. GetUpdateLocation, GetLatestVersion, GetReleaseNotes, GetInstaller, null, App.AutoUpdateSettings.Elevated, "PRSDesktopSetup.exe");
  98. }
  99. public static void DownloadAndRunInstaller()
  100. {
  101. InABox.WPF.Progress.ShowModal("Retrieving Update", progress =>
  102. {
  103. Update.DownloadAndRunInstaller(GetInstaller, null, App.AutoUpdateSettings.Elevated, GetUpdateLocation(),
  104. "PRSDesktopSetup.exe", progress);
  105. });
  106. }
  107. }