123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- using System;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Net.Http;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.Wpf;
- using PRS.Shared;
- namespace PRSDesktop;
- public static class SupportUtils
- {
-
- public static void OpenSupportSession()
- {
- var helpwire = Path.Combine(CoreUtils.GetPath(), "helpwire.exe");
- if (!File.Exists(helpwire))
- {
- DownloadSupportAppWindow dl = new DownloadSupportAppWindow();
- dl.ShowDialog();
- }
- if (File.Exists(helpwire))
- {
- var startInfo = new ProcessStartInfo(helpwire);
- startInfo.Verb = "open";
- startInfo.UseShellExecute = true;
- startInfo.WindowStyle = ProcessWindowStyle.Hidden;
- try
- {
- Process.Start(startInfo);
- }
- catch (System.Exception e)
- {
- Logger.Send(LogType.Information,"",$"{e.Message}\n{e.StackTrace}");
- MessageWindow.ShowError("Unable to launch Support App", e, "Error");
- try
- {
- if (File.Exists(helpwire))
- File.Delete(helpwire);
- }
- catch (System.Exception e2)
- {
- Logger.Send(LogType.Information,"",$"{e2.Message}\n{e2.StackTrace}");
- }
- }
- }
- }
-
- public static string GetUpdateLocation()
- {
- if (App.DatabaseSettings.DatabaseType == DatabaseType.Networked)
- {
- if(ClientFactory.ClientType == typeof(RestClient<>))
- {
- string url = "";
- //var domain = App.DatabaseSettings.URL.Split(new[] { "://" }, StringSplitOptions.RemoveEmptyEntries).Last();
- //var port = App.DatabaseSettings.Port;
- var domain = ClientFactory.Parameters?.FirstOrDefault()?.ToString() ?? "";
- domain = domain.Split(new[] { "://" }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault() ?? "";
- if (!String.IsNullOrWhiteSpace(domain))
- {
-
- try
- {
- var client = new HttpClient { BaseAddress = new Uri($"https://{domain}") };
- client.GetAsync("operations").Wait();
- url = $"https://{domain}";
- }
- catch (Exception)
- {
- url = $"http://{domain}";
- }
- }
- return url;
- }
- else
- {
- return "";
- }
- }
- else
- return Path.Combine(CoreUtils.GetCommonAppData("PRSServer"), "update");
- }
-
- public static string GetLatestVersion(string location)
- {
- return Client.Version();
- }
-
- public static string GetReleaseNotes(string location)
- {
- return Client.ReleaseNotes();
- }
-
- public static byte[]? GetInstaller(string location)
- {
- return Client.Installer();
- }
-
- public static bool CheckForUpdates()
- {
- return Update.CheckForUpdates(
- GetUpdateLocation, GetLatestVersion, GetReleaseNotes, GetInstaller, null, App.AutoUpdateSettings.Elevated, "PRSDesktopSetup.exe");
- }
- public static void DownloadAndRunInstaller()
- {
- InABox.WPF.Progress.ShowModal("Retrieving Update", progress =>
- {
- Update.DownloadAndRunInstaller(GetInstaller, null, App.AutoUpdateSettings.Elevated, GetUpdateLocation(),
- "PRSDesktopSetup.exe", progress);
- });
- }
- }
|