mekasu0124

Untitled

Jan 24th, 2024
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.14 KB | None | 0 0
  1. using ReactiveUI;
  2. using System;
  3. using System.Diagnostics;
  4. using System.Runtime.InteropServices;
  5. using Todo.Services;
  6.  
  7. namespace Todo.ViewModels;
  8.  
  9. public partial class UpdateAvailableViewModel : ViewModelBase
  10. {
  11.     public string _informationText;
  12.  
  13.     public UpdateAvailableViewModel(GithubVersionService gvs, GithubVersionService.VersionData version)
  14.     {
  15.         InformationText = $"There is an update. The apps current version {version.CurrentVersion} does not match the new version {version.LatestVersion}";
  16.     }
  17.  
  18.     public string InformationText
  19.     {
  20.         get => _informationText;
  21.         set => this.RaiseAndSetIfChanged(ref _informationText, value);
  22.     }
  23.  
  24.     SupportedOperatingSystem GetSupportedOs()
  25.     {
  26.         if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
  27.             return SupportedOperatingSystem.Windows;
  28.         if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
  29.             return SupportedOperatingSystem.Linux;
  30.         if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
  31.             return SupportedOperatingSystem.Mac;
  32.         throw new PlatformNotSupportedException();
  33.     }
  34.  
  35.     public void LaunchUpdate()
  36.     {
  37.         var userOs = GetSupportedOs();
  38.         try
  39.         {
  40.             switch (userOs)
  41.             {
  42.                 case SupportedOperatingSystem.Windows:
  43.                     var p = new Process();
  44.                     p.StartInfo.FileName = "/Executables/win/Installer.exe";
  45.                     p.Start();
  46.  
  47.                     Environment.Exit(0);
  48.                     break;
  49.  
  50.                 case SupportedOperatingSystem.Linux:
  51.                     // some code to launch installer on linux
  52.                     Environment.Exit(0);
  53.                     break;
  54.  
  55.                 case SupportedOperatingSystem.Mac:
  56.                     // some code to launch installer on Mac
  57.                     Environment.Exit(0);
  58.                     break;
  59.             }
  60.         }
  61.         catch (Exception ex)
  62.         {
  63.             InformationText = ex.Message;
  64.             return;
  65.         }
  66.     }
  67. }
  68. public enum SupportedOperatingSystem
  69. {
  70.     Windows,
  71.     Linux,
  72.     Mac
  73. }
Advertisement
Add Comment
Please, Sign In to add comment