ViewModelMain.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using PixiEditor.UpdateModule;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. namespace PixiEditor.UpdateInstaller
  12. {
  13. public class ViewModelMain : ViewModelBase
  14. {
  15. public ViewModelMain Current { get; private set; }
  16. public UpdateModule.UpdateInstaller Installer { get; set; }
  17. public string UpdateDirectory { get; private set; }
  18. private float _progressValue;
  19. public float ProgressValue
  20. {
  21. get => _progressValue;
  22. set
  23. {
  24. _progressValue = value;
  25. RaisePropertyChanged(nameof(ProgressValue));
  26. }
  27. }
  28. public ViewModelMain()
  29. {
  30. Current = this;
  31. string updateDirectory = Path.GetDirectoryName(Extensions.GetExecutablePath());
  32. #if DEBUG
  33. updateDirectory = Environment.GetCommandLineArgs()[1];
  34. #endif
  35. UpdateDirectory = updateDirectory;
  36. }
  37. public void InstallUpdate()
  38. {
  39. string[] files = Directory.GetFiles(UpdateDownloader.DownloadLocation, "update-*.zip");
  40. if (files.Length > 0)
  41. {
  42. Installer = new UpdateModule.UpdateInstaller(files[0], UpdateDirectory);
  43. Installer.ProgressChanged += Installer_ProgressChanged;
  44. Installer.Install();
  45. }
  46. else
  47. {
  48. ProgressValue = 100;
  49. }
  50. }
  51. private void Installer_ProgressChanged(object sender, UpdateProgressChangedEventArgs e)
  52. {
  53. ProgressValue = e.Progress;
  54. }
  55. }
  56. }